| File: | build/source/clang/include/clang/AST/ExprCXX.h |
| Warning: | line 4929, column 18 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | //===-- SemaCoroutine.cpp - Semantic Analysis for Coroutines --------------===// | ||||||
| 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 implements semantic analysis for C++ Coroutines. | ||||||
| 10 | // | ||||||
| 11 | // This file contains references to sections of the Coroutines TS, which | ||||||
| 12 | // can be found at http://wg21.link/coroutines. | ||||||
| 13 | // | ||||||
| 14 | //===----------------------------------------------------------------------===// | ||||||
| 15 | |||||||
| 16 | #include "CoroutineStmtBuilder.h" | ||||||
| 17 | #include "clang/AST/ASTLambda.h" | ||||||
| 18 | #include "clang/AST/Decl.h" | ||||||
| 19 | #include "clang/AST/ExprCXX.h" | ||||||
| 20 | #include "clang/AST/StmtCXX.h" | ||||||
| 21 | #include "clang/Basic/Builtins.h" | ||||||
| 22 | #include "clang/Lex/Preprocessor.h" | ||||||
| 23 | #include "clang/Sema/Initialization.h" | ||||||
| 24 | #include "clang/Sema/Overload.h" | ||||||
| 25 | #include "clang/Sema/ScopeInfo.h" | ||||||
| 26 | #include "clang/Sema/SemaInternal.h" | ||||||
| 27 | #include "llvm/ADT/SmallSet.h" | ||||||
| 28 | |||||||
| 29 | using namespace clang; | ||||||
| 30 | using namespace sema; | ||||||
| 31 | |||||||
| 32 | static LookupResult lookupMember(Sema &S, const char *Name, CXXRecordDecl *RD, | ||||||
| 33 | SourceLocation Loc, bool &Res) { | ||||||
| 34 | DeclarationName DN = S.PP.getIdentifierInfo(Name); | ||||||
| 35 | LookupResult LR(S, DN, Loc, Sema::LookupMemberName); | ||||||
| 36 | // Suppress diagnostics when a private member is selected. The same warnings | ||||||
| 37 | // will be produced again when building the call. | ||||||
| 38 | LR.suppressDiagnostics(); | ||||||
| 39 | Res = S.LookupQualifiedName(LR, RD); | ||||||
| 40 | return LR; | ||||||
| 41 | } | ||||||
| 42 | |||||||
| 43 | static bool lookupMember(Sema &S, const char *Name, CXXRecordDecl *RD, | ||||||
| 44 | SourceLocation Loc) { | ||||||
| 45 | bool Res; | ||||||
| 46 | lookupMember(S, Name, RD, Loc, Res); | ||||||
| 47 | return Res; | ||||||
| 48 | } | ||||||
| 49 | |||||||
| 50 | /// Look up the std::coroutine_traits<...>::promise_type for the given | ||||||
| 51 | /// function type. | ||||||
| 52 | static QualType lookupPromiseType(Sema &S, const FunctionDecl *FD, | ||||||
| 53 | SourceLocation KwLoc) { | ||||||
| 54 | const FunctionProtoType *FnType = FD->getType()->castAs<FunctionProtoType>(); | ||||||
| 55 | const SourceLocation FuncLoc = FD->getLocation(); | ||||||
| 56 | |||||||
| 57 | ClassTemplateDecl *CoroTraits = | ||||||
| 58 | S.lookupCoroutineTraits(KwLoc, FuncLoc); | ||||||
| 59 | if (!CoroTraits) | ||||||
| 60 | return QualType(); | ||||||
| 61 | |||||||
| 62 | // Form template argument list for coroutine_traits<R, P1, P2, ...> according | ||||||
| 63 | // to [dcl.fct.def.coroutine]3 | ||||||
| 64 | TemplateArgumentListInfo Args(KwLoc, KwLoc); | ||||||
| 65 | auto AddArg = [&](QualType T) { | ||||||
| 66 | Args.addArgument(TemplateArgumentLoc( | ||||||
| 67 | TemplateArgument(T), S.Context.getTrivialTypeSourceInfo(T, KwLoc))); | ||||||
| 68 | }; | ||||||
| 69 | AddArg(FnType->getReturnType()); | ||||||
| 70 | // If the function is a non-static member function, add the type | ||||||
| 71 | // of the implicit object parameter before the formal parameters. | ||||||
| 72 | if (auto *MD = dyn_cast<CXXMethodDecl>(FD)) { | ||||||
| 73 | if (MD->isInstance()) { | ||||||
| 74 | // [over.match.funcs]4 | ||||||
| 75 | // For non-static member functions, the type of the implicit object | ||||||
| 76 | // parameter is | ||||||
| 77 | // -- "lvalue reference to cv X" for functions declared without a | ||||||
| 78 | // ref-qualifier or with the & ref-qualifier | ||||||
| 79 | // -- "rvalue reference to cv X" for functions declared with the && | ||||||
| 80 | // ref-qualifier | ||||||
| 81 | QualType T = MD->getThisType()->castAs<PointerType>()->getPointeeType(); | ||||||
| 82 | T = FnType->getRefQualifier() == RQ_RValue | ||||||
| 83 | ? S.Context.getRValueReferenceType(T) | ||||||
| 84 | : S.Context.getLValueReferenceType(T, /*SpelledAsLValue*/ true); | ||||||
| 85 | AddArg(T); | ||||||
| 86 | } | ||||||
| 87 | } | ||||||
| 88 | for (QualType T : FnType->getParamTypes()) | ||||||
| 89 | AddArg(T); | ||||||
| 90 | |||||||
| 91 | // Build the template-id. | ||||||
| 92 | QualType CoroTrait = | ||||||
| 93 | S.CheckTemplateIdType(TemplateName(CoroTraits), KwLoc, Args); | ||||||
| 94 | if (CoroTrait.isNull()) | ||||||
| 95 | return QualType(); | ||||||
| 96 | if (S.RequireCompleteType(KwLoc, CoroTrait, | ||||||
| 97 | diag::err_coroutine_type_missing_specialization)) | ||||||
| 98 | return QualType(); | ||||||
| 99 | |||||||
| 100 | auto *RD = CoroTrait->getAsCXXRecordDecl(); | ||||||
| 101 | assert(RD && "specialization of class template is not a class?")(static_cast <bool> (RD && "specialization of class template is not a class?" ) ? void (0) : __assert_fail ("RD && \"specialization of class template is not a class?\"" , "clang/lib/Sema/SemaCoroutine.cpp", 101, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 102 | |||||||
| 103 | // Look up the ::promise_type member. | ||||||
| 104 | LookupResult R(S, &S.PP.getIdentifierTable().get("promise_type"), KwLoc, | ||||||
| 105 | Sema::LookupOrdinaryName); | ||||||
| 106 | S.LookupQualifiedName(R, RD); | ||||||
| 107 | auto *Promise = R.getAsSingle<TypeDecl>(); | ||||||
| 108 | if (!Promise) { | ||||||
| 109 | S.Diag(FuncLoc, | ||||||
| 110 | diag::err_implied_std_coroutine_traits_promise_type_not_found) | ||||||
| 111 | << RD; | ||||||
| 112 | return QualType(); | ||||||
| 113 | } | ||||||
| 114 | // The promise type is required to be a class type. | ||||||
| 115 | QualType PromiseType = S.Context.getTypeDeclType(Promise); | ||||||
| 116 | |||||||
| 117 | auto buildElaboratedType = [&]() { | ||||||
| 118 | auto *NNS = NestedNameSpecifier::Create(S.Context, nullptr, S.getStdNamespace()); | ||||||
| 119 | NNS = NestedNameSpecifier::Create(S.Context, NNS, false, | ||||||
| 120 | CoroTrait.getTypePtr()); | ||||||
| 121 | return S.Context.getElaboratedType(ETK_None, NNS, PromiseType); | ||||||
| 122 | }; | ||||||
| 123 | |||||||
| 124 | if (!PromiseType->getAsCXXRecordDecl()) { | ||||||
| 125 | S.Diag(FuncLoc, | ||||||
| 126 | diag::err_implied_std_coroutine_traits_promise_type_not_class) | ||||||
| 127 | << buildElaboratedType(); | ||||||
| 128 | return QualType(); | ||||||
| 129 | } | ||||||
| 130 | if (S.RequireCompleteType(FuncLoc, buildElaboratedType(), | ||||||
| 131 | diag::err_coroutine_promise_type_incomplete)) | ||||||
| 132 | return QualType(); | ||||||
| 133 | |||||||
| 134 | return PromiseType; | ||||||
| 135 | } | ||||||
| 136 | |||||||
| 137 | /// Look up the std::coroutine_handle<PromiseType>. | ||||||
| 138 | static QualType lookupCoroutineHandleType(Sema &S, QualType PromiseType, | ||||||
| 139 | SourceLocation Loc) { | ||||||
| 140 | if (PromiseType.isNull()) | ||||||
| 141 | return QualType(); | ||||||
| 142 | |||||||
| 143 | NamespaceDecl *CoroNamespace = S.getStdNamespace(); | ||||||
| 144 | assert(CoroNamespace && "Should already be diagnosed")(static_cast <bool> (CoroNamespace && "Should already be diagnosed" ) ? void (0) : __assert_fail ("CoroNamespace && \"Should already be diagnosed\"" , "clang/lib/Sema/SemaCoroutine.cpp", 144, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 145 | |||||||
| 146 | LookupResult Result(S, &S.PP.getIdentifierTable().get("coroutine_handle"), | ||||||
| 147 | Loc, Sema::LookupOrdinaryName); | ||||||
| 148 | if (!S.LookupQualifiedName(Result, CoroNamespace)) { | ||||||
| 149 | S.Diag(Loc, diag::err_implied_coroutine_type_not_found) | ||||||
| 150 | << "std::coroutine_handle"; | ||||||
| 151 | return QualType(); | ||||||
| 152 | } | ||||||
| 153 | |||||||
| 154 | ClassTemplateDecl *CoroHandle = Result.getAsSingle<ClassTemplateDecl>(); | ||||||
| 155 | if (!CoroHandle) { | ||||||
| 156 | Result.suppressDiagnostics(); | ||||||
| 157 | // We found something weird. Complain about the first thing we found. | ||||||
| 158 | NamedDecl *Found = *Result.begin(); | ||||||
| 159 | S.Diag(Found->getLocation(), diag::err_malformed_std_coroutine_handle); | ||||||
| 160 | return QualType(); | ||||||
| 161 | } | ||||||
| 162 | |||||||
| 163 | // Form template argument list for coroutine_handle<Promise>. | ||||||
| 164 | TemplateArgumentListInfo Args(Loc, Loc); | ||||||
| 165 | Args.addArgument(TemplateArgumentLoc( | ||||||
| 166 | TemplateArgument(PromiseType), | ||||||
| 167 | S.Context.getTrivialTypeSourceInfo(PromiseType, Loc))); | ||||||
| 168 | |||||||
| 169 | // Build the template-id. | ||||||
| 170 | QualType CoroHandleType = | ||||||
| 171 | S.CheckTemplateIdType(TemplateName(CoroHandle), Loc, Args); | ||||||
| 172 | if (CoroHandleType.isNull()) | ||||||
| 173 | return QualType(); | ||||||
| 174 | if (S.RequireCompleteType(Loc, CoroHandleType, | ||||||
| 175 | diag::err_coroutine_type_missing_specialization)) | ||||||
| 176 | return QualType(); | ||||||
| 177 | |||||||
| 178 | return CoroHandleType; | ||||||
| 179 | } | ||||||
| 180 | |||||||
| 181 | static bool isValidCoroutineContext(Sema &S, SourceLocation Loc, | ||||||
| 182 | StringRef Keyword) { | ||||||
| 183 | // [expr.await]p2 dictates that 'co_await' and 'co_yield' must be used within | ||||||
| 184 | // a function body. | ||||||
| 185 | // FIXME: This also covers [expr.await]p2: "An await-expression shall not | ||||||
| 186 | // appear in a default argument." But the diagnostic QoI here could be | ||||||
| 187 | // improved to inform the user that default arguments specifically are not | ||||||
| 188 | // allowed. | ||||||
| 189 | auto *FD = dyn_cast<FunctionDecl>(S.CurContext); | ||||||
| 190 | if (!FD) { | ||||||
| 191 | S.Diag(Loc, isa<ObjCMethodDecl>(S.CurContext) | ||||||
| 192 | ? diag::err_coroutine_objc_method | ||||||
| 193 | : diag::err_coroutine_outside_function) << Keyword; | ||||||
| 194 | return false; | ||||||
| 195 | } | ||||||
| 196 | |||||||
| 197 | // An enumeration for mapping the diagnostic type to the correct diagnostic | ||||||
| 198 | // selection index. | ||||||
| 199 | enum InvalidFuncDiag { | ||||||
| 200 | DiagCtor = 0, | ||||||
| 201 | DiagDtor, | ||||||
| 202 | DiagMain, | ||||||
| 203 | DiagConstexpr, | ||||||
| 204 | DiagAutoRet, | ||||||
| 205 | DiagVarargs, | ||||||
| 206 | DiagConsteval, | ||||||
| 207 | }; | ||||||
| 208 | bool Diagnosed = false; | ||||||
| 209 | auto DiagInvalid = [&](InvalidFuncDiag ID) { | ||||||
| 210 | S.Diag(Loc, diag::err_coroutine_invalid_func_context) << ID << Keyword; | ||||||
| 211 | Diagnosed = true; | ||||||
| 212 | return false; | ||||||
| 213 | }; | ||||||
| 214 | |||||||
| 215 | // Diagnose when a constructor, destructor | ||||||
| 216 | // or the function 'main' are declared as a coroutine. | ||||||
| 217 | auto *MD = dyn_cast<CXXMethodDecl>(FD); | ||||||
| 218 | // [class.ctor]p11: "A constructor shall not be a coroutine." | ||||||
| 219 | if (MD && isa<CXXConstructorDecl>(MD)) | ||||||
| 220 | return DiagInvalid(DiagCtor); | ||||||
| 221 | // [class.dtor]p17: "A destructor shall not be a coroutine." | ||||||
| 222 | else if (MD && isa<CXXDestructorDecl>(MD)) | ||||||
| 223 | return DiagInvalid(DiagDtor); | ||||||
| 224 | // [basic.start.main]p3: "The function main shall not be a coroutine." | ||||||
| 225 | else if (FD->isMain()) | ||||||
| 226 | return DiagInvalid(DiagMain); | ||||||
| 227 | |||||||
| 228 | // Emit a diagnostics for each of the following conditions which is not met. | ||||||
| 229 | // [expr.const]p2: "An expression e is a core constant expression unless the | ||||||
| 230 | // evaluation of e [...] would evaluate one of the following expressions: | ||||||
| 231 | // [...] an await-expression [...] a yield-expression." | ||||||
| 232 | if (FD->isConstexpr()) | ||||||
| 233 | DiagInvalid(FD->isConsteval() ? DiagConsteval : DiagConstexpr); | ||||||
| 234 | // [dcl.spec.auto]p15: "A function declared with a return type that uses a | ||||||
| 235 | // placeholder type shall not be a coroutine." | ||||||
| 236 | if (FD->getReturnType()->isUndeducedType()) | ||||||
| 237 | DiagInvalid(DiagAutoRet); | ||||||
| 238 | // [dcl.fct.def.coroutine]p1 | ||||||
| 239 | // The parameter-declaration-clause of the coroutine shall not terminate with | ||||||
| 240 | // an ellipsis that is not part of a parameter-declaration. | ||||||
| 241 | if (FD->isVariadic()) | ||||||
| 242 | DiagInvalid(DiagVarargs); | ||||||
| 243 | |||||||
| 244 | return !Diagnosed; | ||||||
| 245 | } | ||||||
| 246 | |||||||
| 247 | /// Build a call to 'operator co_await' if there is a suitable operator for | ||||||
| 248 | /// the given expression. | ||||||
| 249 | ExprResult Sema::BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, | ||||||
| 250 | UnresolvedLookupExpr *Lookup) { | ||||||
| 251 | UnresolvedSet<16> Functions; | ||||||
| 252 | Functions.append(Lookup->decls_begin(), Lookup->decls_end()); | ||||||
| 253 | return CreateOverloadedUnaryOp(Loc, UO_Coawait, Functions, E); | ||||||
| 254 | } | ||||||
| 255 | |||||||
| 256 | static ExprResult buildOperatorCoawaitCall(Sema &SemaRef, Scope *S, | ||||||
| 257 | SourceLocation Loc, Expr *E) { | ||||||
| 258 | ExprResult R = SemaRef.BuildOperatorCoawaitLookupExpr(S, Loc); | ||||||
| 259 | if (R.isInvalid()) | ||||||
| 260 | return ExprError(); | ||||||
| 261 | return SemaRef.BuildOperatorCoawaitCall(Loc, E, | ||||||
| 262 | cast<UnresolvedLookupExpr>(R.get())); | ||||||
| 263 | } | ||||||
| 264 | |||||||
| 265 | static ExprResult buildCoroutineHandle(Sema &S, QualType PromiseType, | ||||||
| 266 | SourceLocation Loc) { | ||||||
| 267 | QualType CoroHandleType = lookupCoroutineHandleType(S, PromiseType, Loc); | ||||||
| 268 | if (CoroHandleType.isNull()) | ||||||
| 269 | return ExprError(); | ||||||
| 270 | |||||||
| 271 | DeclContext *LookupCtx = S.computeDeclContext(CoroHandleType); | ||||||
| 272 | LookupResult Found(S, &S.PP.getIdentifierTable().get("from_address"), Loc, | ||||||
| 273 | Sema::LookupOrdinaryName); | ||||||
| 274 | if (!S.LookupQualifiedName(Found, LookupCtx)) { | ||||||
| 275 | S.Diag(Loc, diag::err_coroutine_handle_missing_member) | ||||||
| 276 | << "from_address"; | ||||||
| 277 | return ExprError(); | ||||||
| 278 | } | ||||||
| 279 | |||||||
| 280 | Expr *FramePtr = | ||||||
| 281 | S.BuildBuiltinCallExpr(Loc, Builtin::BI__builtin_coro_frame, {}); | ||||||
| 282 | |||||||
| 283 | CXXScopeSpec SS; | ||||||
| 284 | ExprResult FromAddr = | ||||||
| 285 | S.BuildDeclarationNameExpr(SS, Found, /*NeedsADL=*/false); | ||||||
| 286 | if (FromAddr.isInvalid()) | ||||||
| 287 | return ExprError(); | ||||||
| 288 | |||||||
| 289 | return S.BuildCallExpr(nullptr, FromAddr.get(), Loc, FramePtr, Loc); | ||||||
| 290 | } | ||||||
| 291 | |||||||
| 292 | struct ReadySuspendResumeResult { | ||||||
| 293 | enum AwaitCallType { ACT_Ready, ACT_Suspend, ACT_Resume }; | ||||||
| 294 | Expr *Results[3]; | ||||||
| 295 | OpaqueValueExpr *OpaqueValue; | ||||||
| 296 | bool IsInvalid; | ||||||
| 297 | }; | ||||||
| 298 | |||||||
| 299 | static ExprResult buildMemberCall(Sema &S, Expr *Base, SourceLocation Loc, | ||||||
| 300 | StringRef Name, MultiExprArg Args) { | ||||||
| 301 | DeclarationNameInfo NameInfo(&S.PP.getIdentifierTable().get(Name), Loc); | ||||||
| 302 | |||||||
| 303 | // FIXME: Fix BuildMemberReferenceExpr to take a const CXXScopeSpec&. | ||||||
| 304 | CXXScopeSpec SS; | ||||||
| 305 | ExprResult Result = S.BuildMemberReferenceExpr( | ||||||
| 306 | Base, Base->getType(), Loc, /*IsPtr=*/false, SS, | ||||||
| 307 | SourceLocation(), nullptr, NameInfo, /*TemplateArgs=*/nullptr, | ||||||
| 308 | /*Scope=*/nullptr); | ||||||
| 309 | if (Result.isInvalid()) | ||||||
| 310 | return ExprError(); | ||||||
| 311 | |||||||
| 312 | // We meant exactly what we asked for. No need for typo correction. | ||||||
| 313 | if (auto *TE = dyn_cast<TypoExpr>(Result.get())) { | ||||||
| 314 | S.clearDelayedTypo(TE); | ||||||
| 315 | S.Diag(Loc, diag::err_no_member) | ||||||
| 316 | << NameInfo.getName() << Base->getType()->getAsCXXRecordDecl() | ||||||
| 317 | << Base->getSourceRange(); | ||||||
| 318 | return ExprError(); | ||||||
| 319 | } | ||||||
| 320 | |||||||
| 321 | return S.BuildCallExpr(nullptr, Result.get(), Loc, Args, Loc, nullptr); | ||||||
| 322 | } | ||||||
| 323 | |||||||
| 324 | // See if return type is coroutine-handle and if so, invoke builtin coro-resume | ||||||
| 325 | // on its address. This is to enable the support for coroutine-handle | ||||||
| 326 | // returning await_suspend that results in a guaranteed tail call to the target | ||||||
| 327 | // coroutine. | ||||||
| 328 | static Expr *maybeTailCall(Sema &S, QualType RetType, Expr *E, | ||||||
| 329 | SourceLocation Loc) { | ||||||
| 330 | if (RetType->isReferenceType()) | ||||||
| 331 | return nullptr; | ||||||
| 332 | Type const *T = RetType.getTypePtr(); | ||||||
| 333 | if (!T->isClassType() && !T->isStructureType()) | ||||||
| 334 | return nullptr; | ||||||
| 335 | |||||||
| 336 | // FIXME: Add convertability check to coroutine_handle<>. Possibly via | ||||||
| 337 | // EvaluateBinaryTypeTrait(BTT_IsConvertible, ...) which is at the moment | ||||||
| 338 | // a private function in SemaExprCXX.cpp | ||||||
| 339 | |||||||
| 340 | ExprResult AddressExpr = buildMemberCall(S, E, Loc, "address", std::nullopt); | ||||||
| 341 | if (AddressExpr.isInvalid()) | ||||||
| 342 | return nullptr; | ||||||
| 343 | |||||||
| 344 | Expr *JustAddress = AddressExpr.get(); | ||||||
| 345 | |||||||
| 346 | // Check that the type of AddressExpr is void* | ||||||
| 347 | if (!JustAddress->getType().getTypePtr()->isVoidPointerType()) | ||||||
| 348 | S.Diag(cast<CallExpr>(JustAddress)->getCalleeDecl()->getLocation(), | ||||||
| 349 | diag::warn_coroutine_handle_address_invalid_return_type) | ||||||
| 350 | << JustAddress->getType(); | ||||||
| 351 | |||||||
| 352 | // Clean up temporary objects so that they don't live across suspension points | ||||||
| 353 | // unnecessarily. We choose to clean up before the call to | ||||||
| 354 | // __builtin_coro_resume so that the cleanup code are not inserted in-between | ||||||
| 355 | // the resume call and return instruction, which would interfere with the | ||||||
| 356 | // musttail call contract. | ||||||
| 357 | JustAddress = S.MaybeCreateExprWithCleanups(JustAddress); | ||||||
| 358 | return S.BuildBuiltinCallExpr(Loc, Builtin::BI__builtin_coro_resume, | ||||||
| 359 | JustAddress); | ||||||
| 360 | } | ||||||
| 361 | |||||||
| 362 | /// Build calls to await_ready, await_suspend, and await_resume for a co_await | ||||||
| 363 | /// expression. | ||||||
| 364 | /// The generated AST tries to clean up temporary objects as early as | ||||||
| 365 | /// possible so that they don't live across suspension points if possible. | ||||||
| 366 | /// Having temporary objects living across suspension points unnecessarily can | ||||||
| 367 | /// lead to large frame size, and also lead to memory corruptions if the | ||||||
| 368 | /// coroutine frame is destroyed after coming back from suspension. This is done | ||||||
| 369 | /// by wrapping both the await_ready call and the await_suspend call with | ||||||
| 370 | /// ExprWithCleanups. In the end of this function, we also need to explicitly | ||||||
| 371 | /// set cleanup state so that the CoawaitExpr is also wrapped with an | ||||||
| 372 | /// ExprWithCleanups to clean up the awaiter associated with the co_await | ||||||
| 373 | /// expression. | ||||||
| 374 | static ReadySuspendResumeResult buildCoawaitCalls(Sema &S, VarDecl *CoroPromise, | ||||||
| 375 | SourceLocation Loc, Expr *E) { | ||||||
| 376 | OpaqueValueExpr *Operand = new (S.Context) | ||||||
| 377 | OpaqueValueExpr(Loc, E->getType(), VK_LValue, E->getObjectKind(), E); | ||||||
| 378 | |||||||
| 379 | // Assume valid until we see otherwise. | ||||||
| 380 | // Further operations are responsible for setting IsInalid to true. | ||||||
| 381 | ReadySuspendResumeResult Calls = {{}, Operand, /*IsInvalid=*/false}; | ||||||
| 382 | |||||||
| 383 | using ACT = ReadySuspendResumeResult::AwaitCallType; | ||||||
| 384 | |||||||
| 385 | auto BuildSubExpr = [&](ACT CallType, StringRef Func, | ||||||
| 386 | MultiExprArg Arg) -> Expr * { | ||||||
| 387 | ExprResult Result = buildMemberCall(S, Operand, Loc, Func, Arg); | ||||||
| 388 | if (Result.isInvalid()) { | ||||||
| 389 | Calls.IsInvalid = true; | ||||||
| 390 | return nullptr; | ||||||
| 391 | } | ||||||
| 392 | Calls.Results[CallType] = Result.get(); | ||||||
| 393 | return Result.get(); | ||||||
| 394 | }; | ||||||
| 395 | |||||||
| 396 | CallExpr *AwaitReady = cast_or_null<CallExpr>( | ||||||
| 397 | BuildSubExpr(ACT::ACT_Ready, "await_ready", std::nullopt)); | ||||||
| 398 | if (!AwaitReady
| ||||||
| 399 | return Calls; | ||||||
| 400 | if (!AwaitReady->getType()->isDependentType()) { | ||||||
| 401 | // [expr.await]p3 [...] | ||||||
| 402 | // — await-ready is the expression e.await_ready(), contextually converted | ||||||
| 403 | // to bool. | ||||||
| 404 | ExprResult Conv = S.PerformContextuallyConvertToBool(AwaitReady); | ||||||
| 405 | if (Conv.isInvalid()) { | ||||||
| 406 | S.Diag(AwaitReady->getDirectCallee()->getBeginLoc(), | ||||||
| 407 | diag::note_await_ready_no_bool_conversion); | ||||||
| 408 | S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required) | ||||||
| 409 | << AwaitReady->getDirectCallee() << E->getSourceRange(); | ||||||
| 410 | Calls.IsInvalid = true; | ||||||
| 411 | } else | ||||||
| 412 | Calls.Results[ACT::ACT_Ready] = S.MaybeCreateExprWithCleanups(Conv.get()); | ||||||
| 413 | } | ||||||
| 414 | |||||||
| 415 | ExprResult CoroHandleRes = | ||||||
| 416 | buildCoroutineHandle(S, CoroPromise->getType(), Loc); | ||||||
| 417 | if (CoroHandleRes.isInvalid()) { | ||||||
| 418 | Calls.IsInvalid = true; | ||||||
| 419 | return Calls; | ||||||
| 420 | } | ||||||
| 421 | Expr *CoroHandle = CoroHandleRes.get(); | ||||||
| 422 | CallExpr *AwaitSuspend = cast_or_null<CallExpr>( | ||||||
| 423 | BuildSubExpr(ACT::ACT_Suspend, "await_suspend", CoroHandle)); | ||||||
| 424 | if (!AwaitSuspend) | ||||||
| 425 | return Calls; | ||||||
| 426 | if (!AwaitSuspend->getType()->isDependentType()) { | ||||||
| 427 | // [expr.await]p3 [...] | ||||||
| 428 | // - await-suspend is the expression e.await_suspend(h), which shall be | ||||||
| 429 | // a prvalue of type void, bool, or std::coroutine_handle<Z> for some | ||||||
| 430 | // type Z. | ||||||
| 431 | QualType RetType = AwaitSuspend->getCallReturnType(S.Context); | ||||||
| 432 | |||||||
| 433 | // Support for coroutine_handle returning await_suspend. | ||||||
| 434 | if (Expr *TailCallSuspend = | ||||||
| 435 | maybeTailCall(S, RetType, AwaitSuspend, Loc)) | ||||||
| 436 | // Note that we don't wrap the expression with ExprWithCleanups here | ||||||
| 437 | // because that might interfere with tailcall contract (e.g. inserting | ||||||
| 438 | // clean up instructions in-between tailcall and return). Instead | ||||||
| 439 | // ExprWithCleanups is wrapped within maybeTailCall() prior to the resume | ||||||
| 440 | // call. | ||||||
| 441 | Calls.Results[ACT::ACT_Suspend] = TailCallSuspend; | ||||||
| 442 | else { | ||||||
| 443 | // non-class prvalues always have cv-unqualified types | ||||||
| 444 | if (RetType->isReferenceType() || | ||||||
| 445 | (!RetType->isBooleanType() && !RetType->isVoidType())) { | ||||||
| 446 | S.Diag(AwaitSuspend->getCalleeDecl()->getLocation(), | ||||||
| 447 | diag::err_await_suspend_invalid_return_type) | ||||||
| 448 | << RetType; | ||||||
| 449 | S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required) | ||||||
| 450 | << AwaitSuspend->getDirectCallee(); | ||||||
| 451 | Calls.IsInvalid = true; | ||||||
| 452 | } else | ||||||
| 453 | Calls.Results[ACT::ACT_Suspend] = | ||||||
| 454 | S.MaybeCreateExprWithCleanups(AwaitSuspend); | ||||||
| 455 | } | ||||||
| 456 | } | ||||||
| 457 | |||||||
| 458 | BuildSubExpr(ACT::ACT_Resume, "await_resume", std::nullopt); | ||||||
| 459 | |||||||
| 460 | // Make sure the awaiter object gets a chance to be cleaned up. | ||||||
| 461 | S.Cleanup.setExprNeedsCleanups(true); | ||||||
| 462 | |||||||
| 463 | return Calls; | ||||||
| 464 | } | ||||||
| 465 | |||||||
| 466 | static ExprResult buildPromiseCall(Sema &S, VarDecl *Promise, | ||||||
| 467 | SourceLocation Loc, StringRef Name, | ||||||
| 468 | MultiExprArg Args) { | ||||||
| 469 | |||||||
| 470 | // Form a reference to the promise. | ||||||
| 471 | ExprResult PromiseRef = S.BuildDeclRefExpr( | ||||||
| 472 | Promise, Promise->getType().getNonReferenceType(), VK_LValue, Loc); | ||||||
| 473 | if (PromiseRef.isInvalid()) | ||||||
| 474 | return ExprError(); | ||||||
| 475 | |||||||
| 476 | return buildMemberCall(S, PromiseRef.get(), Loc, Name, Args); | ||||||
| 477 | } | ||||||
| 478 | |||||||
| 479 | VarDecl *Sema::buildCoroutinePromise(SourceLocation Loc) { | ||||||
| 480 | assert(isa<FunctionDecl>(CurContext) && "not in a function scope")(static_cast <bool> (isa<FunctionDecl>(CurContext ) && "not in a function scope") ? void (0) : __assert_fail ("isa<FunctionDecl>(CurContext) && \"not in a function scope\"" , "clang/lib/Sema/SemaCoroutine.cpp", 480, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 481 | auto *FD = cast<FunctionDecl>(CurContext); | ||||||
| 482 | bool IsThisDependentType = [&] { | ||||||
| 483 | if (auto *MD = dyn_cast_or_null<CXXMethodDecl>(FD)) | ||||||
| 484 | return MD->isInstance() && MD->getThisType()->isDependentType(); | ||||||
| 485 | else | ||||||
| 486 | return false; | ||||||
| 487 | }(); | ||||||
| 488 | |||||||
| 489 | QualType T = FD->getType()->isDependentType() || IsThisDependentType | ||||||
| 490 | ? Context.DependentTy | ||||||
| 491 | : lookupPromiseType(*this, FD, Loc); | ||||||
| 492 | if (T.isNull()) | ||||||
| 493 | return nullptr; | ||||||
| 494 | |||||||
| 495 | auto *VD = VarDecl::Create(Context, FD, FD->getLocation(), FD->getLocation(), | ||||||
| 496 | &PP.getIdentifierTable().get("__promise"), T, | ||||||
| 497 | Context.getTrivialTypeSourceInfo(T, Loc), SC_None); | ||||||
| 498 | VD->setImplicit(); | ||||||
| 499 | CheckVariableDeclarationType(VD); | ||||||
| 500 | if (VD->isInvalidDecl()) | ||||||
| 501 | return nullptr; | ||||||
| 502 | |||||||
| 503 | auto *ScopeInfo = getCurFunction(); | ||||||
| 504 | |||||||
| 505 | // Build a list of arguments, based on the coroutine function's arguments, | ||||||
| 506 | // that if present will be passed to the promise type's constructor. | ||||||
| 507 | llvm::SmallVector<Expr *, 4> CtorArgExprs; | ||||||
| 508 | |||||||
| 509 | // Add implicit object parameter. | ||||||
| 510 | if (auto *MD = dyn_cast<CXXMethodDecl>(FD)) { | ||||||
| 511 | if (MD->isInstance() && !isLambdaCallOperator(MD)) { | ||||||
| 512 | ExprResult ThisExpr = ActOnCXXThis(Loc); | ||||||
| 513 | if (ThisExpr.isInvalid()) | ||||||
| 514 | return nullptr; | ||||||
| 515 | ThisExpr = CreateBuiltinUnaryOp(Loc, UO_Deref, ThisExpr.get()); | ||||||
| 516 | if (ThisExpr.isInvalid()) | ||||||
| 517 | return nullptr; | ||||||
| 518 | CtorArgExprs.push_back(ThisExpr.get()); | ||||||
| 519 | } | ||||||
| 520 | } | ||||||
| 521 | |||||||
| 522 | // Add the coroutine function's parameters. | ||||||
| 523 | auto &Moves = ScopeInfo->CoroutineParameterMoves; | ||||||
| 524 | for (auto *PD : FD->parameters()) { | ||||||
| 525 | if (PD->getType()->isDependentType()) | ||||||
| 526 | continue; | ||||||
| 527 | |||||||
| 528 | auto RefExpr = ExprEmpty(); | ||||||
| 529 | auto Move = Moves.find(PD); | ||||||
| 530 | assert(Move != Moves.end() &&(static_cast <bool> (Move != Moves.end() && "Coroutine function parameter not inserted into move map" ) ? void (0) : __assert_fail ("Move != Moves.end() && \"Coroutine function parameter not inserted into move map\"" , "clang/lib/Sema/SemaCoroutine.cpp", 531, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 531 | "Coroutine function parameter not inserted into move map")(static_cast <bool> (Move != Moves.end() && "Coroutine function parameter not inserted into move map" ) ? void (0) : __assert_fail ("Move != Moves.end() && \"Coroutine function parameter not inserted into move map\"" , "clang/lib/Sema/SemaCoroutine.cpp", 531, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 532 | // If a reference to the function parameter exists in the coroutine | ||||||
| 533 | // frame, use that reference. | ||||||
| 534 | auto *MoveDecl = | ||||||
| 535 | cast<VarDecl>(cast<DeclStmt>(Move->second)->getSingleDecl()); | ||||||
| 536 | RefExpr = | ||||||
| 537 | BuildDeclRefExpr(MoveDecl, MoveDecl->getType().getNonReferenceType(), | ||||||
| 538 | ExprValueKind::VK_LValue, FD->getLocation()); | ||||||
| 539 | if (RefExpr.isInvalid()) | ||||||
| 540 | return nullptr; | ||||||
| 541 | CtorArgExprs.push_back(RefExpr.get()); | ||||||
| 542 | } | ||||||
| 543 | |||||||
| 544 | // If we have a non-zero number of constructor arguments, try to use them. | ||||||
| 545 | // Otherwise, fall back to the promise type's default constructor. | ||||||
| 546 | if (!CtorArgExprs.empty()) { | ||||||
| 547 | // Create an initialization sequence for the promise type using the | ||||||
| 548 | // constructor arguments, wrapped in a parenthesized list expression. | ||||||
| 549 | Expr *PLE = ParenListExpr::Create(Context, FD->getLocation(), | ||||||
| 550 | CtorArgExprs, FD->getLocation()); | ||||||
| 551 | InitializedEntity Entity = InitializedEntity::InitializeVariable(VD); | ||||||
| 552 | InitializationKind Kind = InitializationKind::CreateForInit( | ||||||
| 553 | VD->getLocation(), /*DirectInit=*/true, PLE); | ||||||
| 554 | InitializationSequence InitSeq(*this, Entity, Kind, CtorArgExprs, | ||||||
| 555 | /*TopLevelOfInitList=*/false, | ||||||
| 556 | /*TreatUnavailableAsInvalid=*/false); | ||||||
| 557 | |||||||
| 558 | // [dcl.fct.def.coroutine]5.7 | ||||||
| 559 | // promise-constructor-arguments is determined as follows: overload | ||||||
| 560 | // resolution is performed on a promise constructor call created by | ||||||
| 561 | // assembling an argument list q_1 ... q_n . If a viable constructor is | ||||||
| 562 | // found ([over.match.viable]), then promise-constructor-arguments is ( q_1 | ||||||
| 563 | // , ..., q_n ), otherwise promise-constructor-arguments is empty. | ||||||
| 564 | if (InitSeq) { | ||||||
| 565 | ExprResult Result = InitSeq.Perform(*this, Entity, Kind, CtorArgExprs); | ||||||
| 566 | if (Result.isInvalid()) { | ||||||
| 567 | VD->setInvalidDecl(); | ||||||
| 568 | } else if (Result.get()) { | ||||||
| 569 | VD->setInit(MaybeCreateExprWithCleanups(Result.get())); | ||||||
| 570 | VD->setInitStyle(VarDecl::CallInit); | ||||||
| 571 | CheckCompleteVariableDeclaration(VD); | ||||||
| 572 | } | ||||||
| 573 | } else | ||||||
| 574 | ActOnUninitializedDecl(VD); | ||||||
| 575 | } else | ||||||
| 576 | ActOnUninitializedDecl(VD); | ||||||
| 577 | |||||||
| 578 | FD->addDecl(VD); | ||||||
| 579 | return VD; | ||||||
| 580 | } | ||||||
| 581 | |||||||
| 582 | /// Check that this is a context in which a coroutine suspension can appear. | ||||||
| 583 | static FunctionScopeInfo *checkCoroutineContext(Sema &S, SourceLocation Loc, | ||||||
| 584 | StringRef Keyword, | ||||||
| 585 | bool IsImplicit = false) { | ||||||
| 586 | if (!isValidCoroutineContext(S, Loc, Keyword)) | ||||||
| 587 | return nullptr; | ||||||
| 588 | |||||||
| 589 | assert(isa<FunctionDecl>(S.CurContext) && "not in a function scope")(static_cast <bool> (isa<FunctionDecl>(S.CurContext ) && "not in a function scope") ? void (0) : __assert_fail ("isa<FunctionDecl>(S.CurContext) && \"not in a function scope\"" , "clang/lib/Sema/SemaCoroutine.cpp", 589, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 590 | |||||||
| 591 | auto *ScopeInfo = S.getCurFunction(); | ||||||
| 592 | assert(ScopeInfo && "missing function scope for function")(static_cast <bool> (ScopeInfo && "missing function scope for function" ) ? void (0) : __assert_fail ("ScopeInfo && \"missing function scope for function\"" , "clang/lib/Sema/SemaCoroutine.cpp", 592, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 593 | |||||||
| 594 | if (ScopeInfo->FirstCoroutineStmtLoc.isInvalid() && !IsImplicit) | ||||||
| 595 | ScopeInfo->setFirstCoroutineStmt(Loc, Keyword); | ||||||
| 596 | |||||||
| 597 | if (ScopeInfo->CoroutinePromise) | ||||||
| 598 | return ScopeInfo; | ||||||
| 599 | |||||||
| 600 | if (!S.buildCoroutineParameterMoves(Loc)) | ||||||
| 601 | return nullptr; | ||||||
| 602 | |||||||
| 603 | ScopeInfo->CoroutinePromise = S.buildCoroutinePromise(Loc); | ||||||
| 604 | if (!ScopeInfo->CoroutinePromise) | ||||||
| 605 | return nullptr; | ||||||
| 606 | |||||||
| 607 | return ScopeInfo; | ||||||
| 608 | } | ||||||
| 609 | |||||||
| 610 | /// Recursively check \p E and all its children to see if any call target | ||||||
| 611 | /// (including constructor call) is declared noexcept. Also any value returned | ||||||
| 612 | /// from the call has a noexcept destructor. | ||||||
| 613 | static void checkNoThrow(Sema &S, const Stmt *E, | ||||||
| 614 | llvm::SmallPtrSetImpl<const Decl *> &ThrowingDecls) { | ||||||
| 615 | auto checkDeclNoexcept = [&](const Decl *D, bool IsDtor = false) { | ||||||
| 616 | // In the case of dtor, the call to dtor is implicit and hence we should | ||||||
| 617 | // pass nullptr to canCalleeThrow. | ||||||
| 618 | if (Sema::canCalleeThrow(S, IsDtor ? nullptr : cast<Expr>(E), D)) { | ||||||
| 619 | if (const auto *FD = dyn_cast<FunctionDecl>(D)) { | ||||||
| 620 | // co_await promise.final_suspend() could end up calling | ||||||
| 621 | // __builtin_coro_resume for symmetric transfer if await_suspend() | ||||||
| 622 | // returns a handle. In that case, even __builtin_coro_resume is not | ||||||
| 623 | // declared as noexcept and may throw, it does not throw _into_ the | ||||||
| 624 | // coroutine that just suspended, but rather throws back out from | ||||||
| 625 | // whoever called coroutine_handle::resume(), hence we claim that | ||||||
| 626 | // logically it does not throw. | ||||||
| 627 | if (FD->getBuiltinID() == Builtin::BI__builtin_coro_resume) | ||||||
| 628 | return; | ||||||
| 629 | } | ||||||
| 630 | if (ThrowingDecls.empty()) { | ||||||
| 631 | // [dcl.fct.def.coroutine]p15 | ||||||
| 632 | // The expression co_await promise.final_suspend() shall not be | ||||||
| 633 | // potentially-throwing ([except.spec]). | ||||||
| 634 | // | ||||||
| 635 | // First time seeing an error, emit the error message. | ||||||
| 636 | S.Diag(cast<FunctionDecl>(S.CurContext)->getLocation(), | ||||||
| 637 | diag::err_coroutine_promise_final_suspend_requires_nothrow); | ||||||
| 638 | } | ||||||
| 639 | ThrowingDecls.insert(D); | ||||||
| 640 | } | ||||||
| 641 | }; | ||||||
| 642 | |||||||
| 643 | if (auto *CE = dyn_cast<CXXConstructExpr>(E)) { | ||||||
| 644 | CXXConstructorDecl *Ctor = CE->getConstructor(); | ||||||
| 645 | checkDeclNoexcept(Ctor); | ||||||
| 646 | // Check the corresponding destructor of the constructor. | ||||||
| 647 | checkDeclNoexcept(Ctor->getParent()->getDestructor(), /*IsDtor=*/true); | ||||||
| 648 | } else if (auto *CE = dyn_cast<CallExpr>(E)) { | ||||||
| 649 | if (CE->isTypeDependent()) | ||||||
| 650 | return; | ||||||
| 651 | |||||||
| 652 | checkDeclNoexcept(CE->getCalleeDecl()); | ||||||
| 653 | QualType ReturnType = CE->getCallReturnType(S.getASTContext()); | ||||||
| 654 | // Check the destructor of the call return type, if any. | ||||||
| 655 | if (ReturnType.isDestructedType() == | ||||||
| 656 | QualType::DestructionKind::DK_cxx_destructor) { | ||||||
| 657 | const auto *T = | ||||||
| 658 | cast<RecordType>(ReturnType.getCanonicalType().getTypePtr()); | ||||||
| 659 | checkDeclNoexcept(cast<CXXRecordDecl>(T->getDecl())->getDestructor(), | ||||||
| 660 | /*IsDtor=*/true); | ||||||
| 661 | } | ||||||
| 662 | } else | ||||||
| 663 | for (const auto *Child : E->children()) { | ||||||
| 664 | if (!Child) | ||||||
| 665 | continue; | ||||||
| 666 | checkNoThrow(S, Child, ThrowingDecls); | ||||||
| 667 | } | ||||||
| 668 | } | ||||||
| 669 | |||||||
| 670 | bool Sema::checkFinalSuspendNoThrow(const Stmt *FinalSuspend) { | ||||||
| 671 | llvm::SmallPtrSet<const Decl *, 4> ThrowingDecls; | ||||||
| 672 | // We first collect all declarations that should not throw but not declared | ||||||
| 673 | // with noexcept. We then sort them based on the location before printing. | ||||||
| 674 | // This is to avoid emitting the same note multiple times on the same | ||||||
| 675 | // declaration, and also provide a deterministic order for the messages. | ||||||
| 676 | checkNoThrow(*this, FinalSuspend, ThrowingDecls); | ||||||
| 677 | auto SortedDecls = llvm::SmallVector<const Decl *, 4>{ThrowingDecls.begin(), | ||||||
| 678 | ThrowingDecls.end()}; | ||||||
| 679 | sort(SortedDecls, [](const Decl *A, const Decl *B) { | ||||||
| 680 | return A->getEndLoc() < B->getEndLoc(); | ||||||
| 681 | }); | ||||||
| 682 | for (const auto *D : SortedDecls) { | ||||||
| 683 | Diag(D->getEndLoc(), diag::note_coroutine_function_declare_noexcept); | ||||||
| 684 | } | ||||||
| 685 | return ThrowingDecls.empty(); | ||||||
| 686 | } | ||||||
| 687 | |||||||
| 688 | bool Sema::ActOnCoroutineBodyStart(Scope *SC, SourceLocation KWLoc, | ||||||
| 689 | StringRef Keyword) { | ||||||
| 690 | if (!checkCoroutineContext(*this, KWLoc, Keyword)) | ||||||
| 691 | return false; | ||||||
| 692 | auto *ScopeInfo = getCurFunction(); | ||||||
| 693 | assert(ScopeInfo->CoroutinePromise)(static_cast <bool> (ScopeInfo->CoroutinePromise) ? void (0) : __assert_fail ("ScopeInfo->CoroutinePromise", "clang/lib/Sema/SemaCoroutine.cpp" , 693, __extension__ __PRETTY_FUNCTION__)); | ||||||
| 694 | |||||||
| 695 | // If we have existing coroutine statements then we have already built | ||||||
| 696 | // the initial and final suspend points. | ||||||
| 697 | if (!ScopeInfo->NeedsCoroutineSuspends) | ||||||
| 698 | return true; | ||||||
| 699 | |||||||
| 700 | ScopeInfo->setNeedsCoroutineSuspends(false); | ||||||
| 701 | |||||||
| 702 | auto *Fn = cast<FunctionDecl>(CurContext); | ||||||
| 703 | SourceLocation Loc = Fn->getLocation(); | ||||||
| 704 | // Build the initial suspend point | ||||||
| 705 | auto buildSuspends = [&](StringRef Name) mutable -> StmtResult { | ||||||
| 706 | ExprResult Operand = buildPromiseCall(*this, ScopeInfo->CoroutinePromise, | ||||||
| 707 | Loc, Name, std::nullopt); | ||||||
| 708 | if (Operand.isInvalid()) | ||||||
| 709 | return StmtError(); | ||||||
| 710 | ExprResult Suspend = | ||||||
| 711 | buildOperatorCoawaitCall(*this, SC, Loc, Operand.get()); | ||||||
| 712 | if (Suspend.isInvalid()) | ||||||
| 713 | return StmtError(); | ||||||
| 714 | Suspend = BuildResolvedCoawaitExpr(Loc, Operand.get(), Suspend.get(), | ||||||
| 715 | /*IsImplicit*/ true); | ||||||
| 716 | Suspend = ActOnFinishFullExpr(Suspend.get(), /*DiscardedValue*/ false); | ||||||
| 717 | if (Suspend.isInvalid()) { | ||||||
| 718 | Diag(Loc, diag::note_coroutine_promise_suspend_implicitly_required) | ||||||
| 719 | << ((Name == "initial_suspend") ? 0 : 1); | ||||||
| 720 | Diag(KWLoc, diag::note_declared_coroutine_here) << Keyword; | ||||||
| 721 | return StmtError(); | ||||||
| 722 | } | ||||||
| 723 | return cast<Stmt>(Suspend.get()); | ||||||
| 724 | }; | ||||||
| 725 | |||||||
| 726 | StmtResult InitSuspend = buildSuspends("initial_suspend"); | ||||||
| 727 | if (InitSuspend.isInvalid()) | ||||||
| 728 | return true; | ||||||
| 729 | |||||||
| 730 | StmtResult FinalSuspend = buildSuspends("final_suspend"); | ||||||
| 731 | if (FinalSuspend.isInvalid() || !checkFinalSuspendNoThrow(FinalSuspend.get())) | ||||||
| 732 | return true; | ||||||
| 733 | |||||||
| 734 | ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get()); | ||||||
| 735 | |||||||
| 736 | return true; | ||||||
| 737 | } | ||||||
| 738 | |||||||
| 739 | // Recursively walks up the scope hierarchy until either a 'catch' or a function | ||||||
| 740 | // scope is found, whichever comes first. | ||||||
| 741 | static bool isWithinCatchScope(Scope *S) { | ||||||
| 742 | // 'co_await' and 'co_yield' keywords are disallowed within catch blocks, but | ||||||
| 743 | // lambdas that use 'co_await' are allowed. The loop below ends when a | ||||||
| 744 | // function scope is found in order to ensure the following behavior: | ||||||
| 745 | // | ||||||
| 746 | // void foo() { // <- function scope | ||||||
| 747 | // try { // | ||||||
| 748 | // co_await x; // <- 'co_await' is OK within a function scope | ||||||
| 749 | // } catch { // <- catch scope | ||||||
| 750 | // co_await x; // <- 'co_await' is not OK within a catch scope | ||||||
| 751 | // []() { // <- function scope | ||||||
| 752 | // co_await x; // <- 'co_await' is OK within a function scope | ||||||
| 753 | // }(); | ||||||
| 754 | // } | ||||||
| 755 | // } | ||||||
| 756 | while (S && !S->isFunctionScope()) { | ||||||
| 757 | if (S->isCatchScope()) | ||||||
| 758 | return true; | ||||||
| 759 | S = S->getParent(); | ||||||
| 760 | } | ||||||
| 761 | return false; | ||||||
| 762 | } | ||||||
| 763 | |||||||
| 764 | // [expr.await]p2, emphasis added: "An await-expression shall appear only in | ||||||
| 765 | // a *potentially evaluated* expression within the compound-statement of a | ||||||
| 766 | // function-body *outside of a handler* [...] A context within a function | ||||||
| 767 | // where an await-expression can appear is called a suspension context of the | ||||||
| 768 | // function." | ||||||
| 769 | static bool checkSuspensionContext(Sema &S, SourceLocation Loc, | ||||||
| 770 | StringRef Keyword) { | ||||||
| 771 | // First emphasis of [expr.await]p2: must be a potentially evaluated context. | ||||||
| 772 | // That is, 'co_await' and 'co_yield' cannot appear in subexpressions of | ||||||
| 773 | // \c sizeof. | ||||||
| 774 | if (S.isUnevaluatedContext()) { | ||||||
| 775 | S.Diag(Loc, diag::err_coroutine_unevaluated_context) << Keyword; | ||||||
| 776 | return false; | ||||||
| 777 | } | ||||||
| 778 | |||||||
| 779 | // Second emphasis of [expr.await]p2: must be outside of an exception handler. | ||||||
| 780 | if (isWithinCatchScope(S.getCurScope())) { | ||||||
| 781 | S.Diag(Loc, diag::err_coroutine_within_handler) << Keyword; | ||||||
| 782 | return false; | ||||||
| 783 | } | ||||||
| 784 | |||||||
| 785 | return true; | ||||||
| 786 | } | ||||||
| 787 | |||||||
| 788 | ExprResult Sema::ActOnCoawaitExpr(Scope *S, SourceLocation Loc, Expr *E) { | ||||||
| 789 | if (!checkSuspensionContext(*this, Loc, "co_await")) | ||||||
| 790 | return ExprError(); | ||||||
| 791 | |||||||
| 792 | if (!ActOnCoroutineBodyStart(S, Loc, "co_await")) { | ||||||
| 793 | CorrectDelayedTyposInExpr(E); | ||||||
| 794 | return ExprError(); | ||||||
| 795 | } | ||||||
| 796 | |||||||
| 797 | if (E->hasPlaceholderType()) { | ||||||
| 798 | ExprResult R = CheckPlaceholderExpr(E); | ||||||
| 799 | if (R.isInvalid()) return ExprError(); | ||||||
| 800 | E = R.get(); | ||||||
| 801 | } | ||||||
| 802 | ExprResult Lookup = BuildOperatorCoawaitLookupExpr(S, Loc); | ||||||
| 803 | if (Lookup.isInvalid()) | ||||||
| 804 | return ExprError(); | ||||||
| 805 | return BuildUnresolvedCoawaitExpr(Loc, E, | ||||||
| 806 | cast<UnresolvedLookupExpr>(Lookup.get())); | ||||||
| 807 | } | ||||||
| 808 | |||||||
| 809 | ExprResult Sema::BuildOperatorCoawaitLookupExpr(Scope *S, SourceLocation Loc) { | ||||||
| 810 | DeclarationName OpName = | ||||||
| 811 | Context.DeclarationNames.getCXXOperatorName(OO_Coawait); | ||||||
| 812 | LookupResult Operators(*this, OpName, SourceLocation(), | ||||||
| 813 | Sema::LookupOperatorName); | ||||||
| 814 | LookupName(Operators, S); | ||||||
| 815 | |||||||
| 816 | assert(!Operators.isAmbiguous() && "Operator lookup cannot be ambiguous")(static_cast <bool> (!Operators.isAmbiguous() && "Operator lookup cannot be ambiguous") ? void (0) : __assert_fail ("!Operators.isAmbiguous() && \"Operator lookup cannot be ambiguous\"" , "clang/lib/Sema/SemaCoroutine.cpp", 816, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 817 | const auto &Functions = Operators.asUnresolvedSet(); | ||||||
| 818 | bool IsOverloaded = | ||||||
| 819 | Functions.size() > 1 || | ||||||
| 820 | (Functions.size() == 1 && isa<FunctionTemplateDecl>(*Functions.begin())); | ||||||
| 821 | Expr *CoawaitOp = UnresolvedLookupExpr::Create( | ||||||
| 822 | Context, /*NamingClass*/ nullptr, NestedNameSpecifierLoc(), | ||||||
| 823 | DeclarationNameInfo(OpName, Loc), /*RequiresADL*/ true, IsOverloaded, | ||||||
| 824 | Functions.begin(), Functions.end()); | ||||||
| 825 | assert(CoawaitOp)(static_cast <bool> (CoawaitOp) ? void (0) : __assert_fail ("CoawaitOp", "clang/lib/Sema/SemaCoroutine.cpp", 825, __extension__ __PRETTY_FUNCTION__)); | ||||||
| 826 | return CoawaitOp; | ||||||
| 827 | } | ||||||
| 828 | |||||||
| 829 | // Attempts to resolve and build a CoawaitExpr from "raw" inputs, bailing out to | ||||||
| 830 | // DependentCoawaitExpr if needed. | ||||||
| 831 | ExprResult Sema::BuildUnresolvedCoawaitExpr(SourceLocation Loc, Expr *Operand, | ||||||
| 832 | UnresolvedLookupExpr *Lookup) { | ||||||
| 833 | auto *FSI = checkCoroutineContext(*this, Loc, "co_await"); | ||||||
| 834 | if (!FSI) | ||||||
| 835 | return ExprError(); | ||||||
| 836 | |||||||
| 837 | if (Operand->hasPlaceholderType()) { | ||||||
| 838 | ExprResult R = CheckPlaceholderExpr(Operand); | ||||||
| 839 | if (R.isInvalid()) | ||||||
| 840 | return ExprError(); | ||||||
| 841 | Operand = R.get(); | ||||||
| 842 | } | ||||||
| 843 | |||||||
| 844 | auto *Promise = FSI->CoroutinePromise; | ||||||
| 845 | if (Promise->getType()->isDependentType()) { | ||||||
| 846 | Expr *Res = new (Context) | ||||||
| 847 | DependentCoawaitExpr(Loc, Context.DependentTy, Operand, Lookup); | ||||||
| 848 | return Res; | ||||||
| 849 | } | ||||||
| 850 | |||||||
| 851 | auto *RD = Promise->getType()->getAsCXXRecordDecl(); | ||||||
| 852 | auto *Transformed = Operand; | ||||||
| 853 | if (lookupMember(*this, "await_transform", RD, Loc)) { | ||||||
| 854 | ExprResult R = | ||||||
| 855 | buildPromiseCall(*this, Promise, Loc, "await_transform", Operand); | ||||||
| 856 | if (R.isInvalid()) { | ||||||
| 857 | Diag(Loc, | ||||||
| 858 | diag::note_coroutine_promise_implicit_await_transform_required_here) | ||||||
| 859 | << Operand->getSourceRange(); | ||||||
| 860 | return ExprError(); | ||||||
| 861 | } | ||||||
| 862 | Transformed = R.get(); | ||||||
| 863 | } | ||||||
| 864 | ExprResult Awaiter = BuildOperatorCoawaitCall(Loc, Transformed, Lookup); | ||||||
| 865 | if (Awaiter.isInvalid()) | ||||||
| 866 | return ExprError(); | ||||||
| 867 | |||||||
| 868 | return BuildResolvedCoawaitExpr(Loc, Operand, Awaiter.get()); | ||||||
| 869 | } | ||||||
| 870 | |||||||
| 871 | ExprResult Sema::BuildResolvedCoawaitExpr(SourceLocation Loc, Expr *Operand, | ||||||
| 872 | Expr *Awaiter, bool IsImplicit) { | ||||||
| 873 | auto *Coroutine = checkCoroutineContext(*this, Loc, "co_await", IsImplicit); | ||||||
| 874 | if (!Coroutine) | ||||||
| 875 | return ExprError(); | ||||||
| 876 | |||||||
| 877 | if (Awaiter->hasPlaceholderType()) { | ||||||
| 878 | ExprResult R = CheckPlaceholderExpr(Awaiter); | ||||||
| 879 | if (R.isInvalid()) return ExprError(); | ||||||
| 880 | Awaiter = R.get(); | ||||||
| 881 | } | ||||||
| 882 | |||||||
| 883 | if (Awaiter->getType()->isDependentType()) { | ||||||
| 884 | Expr *Res = new (Context) | ||||||
| 885 | CoawaitExpr(Loc, Context.DependentTy, Operand, Awaiter, IsImplicit); | ||||||
| 886 | return Res; | ||||||
| 887 | } | ||||||
| 888 | |||||||
| 889 | // If the expression is a temporary, materialize it as an lvalue so that we | ||||||
| 890 | // can use it multiple times. | ||||||
| 891 | if (Awaiter->isPRValue()) | ||||||
| 892 | Awaiter = CreateMaterializeTemporaryExpr(Awaiter->getType(), Awaiter, true); | ||||||
| 893 | |||||||
| 894 | // The location of the `co_await` token cannot be used when constructing | ||||||
| 895 | // the member call expressions since it's before the location of `Expr`, which | ||||||
| 896 | // is used as the start of the member call expression. | ||||||
| 897 | SourceLocation CallLoc = Awaiter->getExprLoc(); | ||||||
| 898 | |||||||
| 899 | // Build the await_ready, await_suspend, await_resume calls. | ||||||
| 900 | ReadySuspendResumeResult RSS = | ||||||
| 901 | buildCoawaitCalls(*this, Coroutine->CoroutinePromise, CallLoc, Awaiter); | ||||||
| 902 | if (RSS.IsInvalid) | ||||||
| 903 | return ExprError(); | ||||||
| 904 | |||||||
| 905 | Expr *Res = new (Context) | ||||||
| 906 | CoawaitExpr(Loc, Operand, Awaiter, RSS.Results[0], RSS.Results[1], | ||||||
| 907 | RSS.Results[2], RSS.OpaqueValue, IsImplicit); | ||||||
| 908 | |||||||
| 909 | return Res; | ||||||
| 910 | } | ||||||
| 911 | |||||||
| 912 | ExprResult Sema::ActOnCoyieldExpr(Scope *S, SourceLocation Loc, Expr *E) { | ||||||
| 913 | if (!checkSuspensionContext(*this, Loc, "co_yield")) | ||||||
| |||||||
| 914 | return ExprError(); | ||||||
| 915 | |||||||
| 916 | if (!ActOnCoroutineBodyStart(S, Loc, "co_yield")) { | ||||||
| 917 | CorrectDelayedTyposInExpr(E); | ||||||
| 918 | return ExprError(); | ||||||
| 919 | } | ||||||
| 920 | |||||||
| 921 | // Build yield_value call. | ||||||
| 922 | ExprResult Awaitable = buildPromiseCall( | ||||||
| 923 | *this, getCurFunction()->CoroutinePromise, Loc, "yield_value", E); | ||||||
| 924 | if (Awaitable.isInvalid()) | ||||||
| 925 | return ExprError(); | ||||||
| 926 | |||||||
| 927 | // Build 'operator co_await' call. | ||||||
| 928 | Awaitable = buildOperatorCoawaitCall(*this, S, Loc, Awaitable.get()); | ||||||
| 929 | if (Awaitable.isInvalid()) | ||||||
| 930 | return ExprError(); | ||||||
| 931 | |||||||
| 932 | return BuildCoyieldExpr(Loc, Awaitable.get()); | ||||||
| 933 | } | ||||||
| 934 | ExprResult Sema::BuildCoyieldExpr(SourceLocation Loc, Expr *E) { | ||||||
| 935 | auto *Coroutine = checkCoroutineContext(*this, Loc, "co_yield"); | ||||||
| 936 | if (!Coroutine
| ||||||
| 937 | return ExprError(); | ||||||
| 938 | |||||||
| 939 | if (E->hasPlaceholderType()) { | ||||||
| 940 | ExprResult R = CheckPlaceholderExpr(E); | ||||||
| 941 | if (R.isInvalid()) return ExprError(); | ||||||
| 942 | E = R.get(); | ||||||
| 943 | } | ||||||
| 944 | |||||||
| 945 | Expr *Operand = E; | ||||||
| 946 | |||||||
| 947 | if (E->getType()->isDependentType()) { | ||||||
| 948 | Expr *Res = new (Context) CoyieldExpr(Loc, Context.DependentTy, Operand, E); | ||||||
| 949 | return Res; | ||||||
| 950 | } | ||||||
| 951 | |||||||
| 952 | // If the expression is a temporary, materialize it as an lvalue so that we | ||||||
| 953 | // can use it multiple times. | ||||||
| 954 | if (E->isPRValue()) | ||||||
| 955 | E = CreateMaterializeTemporaryExpr(E->getType(), E, true); | ||||||
| 956 | |||||||
| 957 | // Build the await_ready, await_suspend, await_resume calls. | ||||||
| 958 | ReadySuspendResumeResult RSS = buildCoawaitCalls( | ||||||
| 959 | *this, Coroutine->CoroutinePromise, Loc, E); | ||||||
| 960 | if (RSS.IsInvalid
| ||||||
| 961 | return ExprError(); | ||||||
| 962 | |||||||
| 963 | Expr *Res = | ||||||
| 964 | new (Context) CoyieldExpr(Loc, Operand, E, RSS.Results[0], RSS.Results[1], | ||||||
| 965 | RSS.Results[2], RSS.OpaqueValue); | ||||||
| 966 | |||||||
| 967 | return Res; | ||||||
| 968 | } | ||||||
| 969 | |||||||
| 970 | StmtResult Sema::ActOnCoreturnStmt(Scope *S, SourceLocation Loc, Expr *E) { | ||||||
| 971 | if (!ActOnCoroutineBodyStart(S, Loc, "co_return")) { | ||||||
| 972 | CorrectDelayedTyposInExpr(E); | ||||||
| 973 | return StmtError(); | ||||||
| 974 | } | ||||||
| 975 | return BuildCoreturnStmt(Loc, E); | ||||||
| 976 | } | ||||||
| 977 | |||||||
| 978 | StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, Expr *E, | ||||||
| 979 | bool IsImplicit) { | ||||||
| 980 | auto *FSI = checkCoroutineContext(*this, Loc, "co_return", IsImplicit); | ||||||
| 981 | if (!FSI) | ||||||
| 982 | return StmtError(); | ||||||
| 983 | |||||||
| 984 | if (E && E->hasPlaceholderType() && | ||||||
| 985 | !E->hasPlaceholderType(BuiltinType::Overload)) { | ||||||
| 986 | ExprResult R = CheckPlaceholderExpr(E); | ||||||
| 987 | if (R.isInvalid()) return StmtError(); | ||||||
| 988 | E = R.get(); | ||||||
| 989 | } | ||||||
| 990 | |||||||
| 991 | VarDecl *Promise = FSI->CoroutinePromise; | ||||||
| 992 | ExprResult PC; | ||||||
| 993 | if (E && (isa<InitListExpr>(E) || !E->getType()->isVoidType())) { | ||||||
| 994 | getNamedReturnInfo(E, SimplerImplicitMoveMode::ForceOn); | ||||||
| 995 | PC = buildPromiseCall(*this, Promise, Loc, "return_value", E); | ||||||
| 996 | } else { | ||||||
| 997 | E = MakeFullDiscardedValueExpr(E).get(); | ||||||
| 998 | PC = buildPromiseCall(*this, Promise, Loc, "return_void", std::nullopt); | ||||||
| 999 | } | ||||||
| 1000 | if (PC.isInvalid()) | ||||||
| 1001 | return StmtError(); | ||||||
| 1002 | |||||||
| 1003 | Expr *PCE = ActOnFinishFullExpr(PC.get(), /*DiscardedValue*/ false).get(); | ||||||
| 1004 | |||||||
| 1005 | Stmt *Res = new (Context) CoreturnStmt(Loc, E, PCE, IsImplicit); | ||||||
| 1006 | return Res; | ||||||
| 1007 | } | ||||||
| 1008 | |||||||
| 1009 | /// Look up the std::nothrow object. | ||||||
| 1010 | static Expr *buildStdNoThrowDeclRef(Sema &S, SourceLocation Loc) { | ||||||
| 1011 | NamespaceDecl *Std = S.getStdNamespace(); | ||||||
| 1012 | assert(Std && "Should already be diagnosed")(static_cast <bool> (Std && "Should already be diagnosed" ) ? void (0) : __assert_fail ("Std && \"Should already be diagnosed\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1012, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1013 | |||||||
| 1014 | LookupResult Result(S, &S.PP.getIdentifierTable().get("nothrow"), Loc, | ||||||
| 1015 | Sema::LookupOrdinaryName); | ||||||
| 1016 | if (!S.LookupQualifiedName(Result, Std)) { | ||||||
| 1017 | // <coroutine> is not requred to include <new>, so we couldn't omit | ||||||
| 1018 | // the check here. | ||||||
| 1019 | S.Diag(Loc, diag::err_implicit_coroutine_std_nothrow_type_not_found); | ||||||
| 1020 | return nullptr; | ||||||
| 1021 | } | ||||||
| 1022 | |||||||
| 1023 | auto *VD = Result.getAsSingle<VarDecl>(); | ||||||
| 1024 | if (!VD) { | ||||||
| 1025 | Result.suppressDiagnostics(); | ||||||
| 1026 | // We found something weird. Complain about the first thing we found. | ||||||
| 1027 | NamedDecl *Found = *Result.begin(); | ||||||
| 1028 | S.Diag(Found->getLocation(), diag::err_malformed_std_nothrow); | ||||||
| 1029 | return nullptr; | ||||||
| 1030 | } | ||||||
| 1031 | |||||||
| 1032 | ExprResult DR = S.BuildDeclRefExpr(VD, VD->getType(), VK_LValue, Loc); | ||||||
| 1033 | if (DR.isInvalid()) | ||||||
| 1034 | return nullptr; | ||||||
| 1035 | |||||||
| 1036 | return DR.get(); | ||||||
| 1037 | } | ||||||
| 1038 | |||||||
| 1039 | static TypeSourceInfo *getTypeSourceInfoForStdAlignValT(Sema &S, | ||||||
| 1040 | SourceLocation Loc) { | ||||||
| 1041 | EnumDecl *StdAlignValT = S.getStdAlignValT(); | ||||||
| 1042 | QualType StdAlignValDecl = S.Context.getTypeDeclType(StdAlignValT); | ||||||
| 1043 | return S.Context.getTrivialTypeSourceInfo(StdAlignValDecl); | ||||||
| 1044 | } | ||||||
| 1045 | |||||||
| 1046 | // Find an appropriate delete for the promise. | ||||||
| 1047 | static bool findDeleteForPromise(Sema &S, SourceLocation Loc, QualType PromiseType, | ||||||
| 1048 | FunctionDecl *&OperatorDelete) { | ||||||
| 1049 | DeclarationName DeleteName = | ||||||
| 1050 | S.Context.DeclarationNames.getCXXOperatorName(OO_Delete); | ||||||
| 1051 | |||||||
| 1052 | auto *PointeeRD = PromiseType->getAsCXXRecordDecl(); | ||||||
| 1053 | assert(PointeeRD && "PromiseType must be a CxxRecordDecl type")(static_cast <bool> (PointeeRD && "PromiseType must be a CxxRecordDecl type" ) ? void (0) : __assert_fail ("PointeeRD && \"PromiseType must be a CxxRecordDecl type\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1053, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1054 | |||||||
| 1055 | const bool Overaligned = S.getLangOpts().CoroAlignedAllocation; | ||||||
| 1056 | |||||||
| 1057 | // [dcl.fct.def.coroutine]p12 | ||||||
| 1058 | // The deallocation function's name is looked up by searching for it in the | ||||||
| 1059 | // scope of the promise type. If nothing is found, a search is performed in | ||||||
| 1060 | // the global scope. | ||||||
| 1061 | if (S.FindDeallocationFunction(Loc, PointeeRD, DeleteName, OperatorDelete, | ||||||
| 1062 | /*Diagnose*/ true, /*WantSize*/ true, | ||||||
| 1063 | /*WantAligned*/ Overaligned)) | ||||||
| 1064 | return false; | ||||||
| 1065 | |||||||
| 1066 | // [dcl.fct.def.coroutine]p12 | ||||||
| 1067 | // If both a usual deallocation function with only a pointer parameter and a | ||||||
| 1068 | // usual deallocation function with both a pointer parameter and a size | ||||||
| 1069 | // parameter are found, then the selected deallocation function shall be the | ||||||
| 1070 | // one with two parameters. Otherwise, the selected deallocation function | ||||||
| 1071 | // shall be the function with one parameter. | ||||||
| 1072 | if (!OperatorDelete) { | ||||||
| 1073 | // Look for a global declaration. | ||||||
| 1074 | // Coroutines can always provide their required size. | ||||||
| 1075 | const bool CanProvideSize = true; | ||||||
| 1076 | // Sema::FindUsualDeallocationFunction will try to find the one with two | ||||||
| 1077 | // parameters first. It will return the deallocation function with one | ||||||
| 1078 | // parameter if failed. | ||||||
| 1079 | OperatorDelete = S.FindUsualDeallocationFunction(Loc, CanProvideSize, | ||||||
| 1080 | Overaligned, DeleteName); | ||||||
| 1081 | |||||||
| 1082 | if (!OperatorDelete) | ||||||
| 1083 | return false; | ||||||
| 1084 | } | ||||||
| 1085 | |||||||
| 1086 | S.MarkFunctionReferenced(Loc, OperatorDelete); | ||||||
| 1087 | return true; | ||||||
| 1088 | } | ||||||
| 1089 | |||||||
| 1090 | |||||||
| 1091 | void Sema::CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body) { | ||||||
| 1092 | FunctionScopeInfo *Fn = getCurFunction(); | ||||||
| 1093 | assert(Fn && Fn->isCoroutine() && "not a coroutine")(static_cast <bool> (Fn && Fn->isCoroutine() && "not a coroutine") ? void (0) : __assert_fail ("Fn && Fn->isCoroutine() && \"not a coroutine\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1093, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1094 | if (!Body) { | ||||||
| 1095 | assert(FD->isInvalidDecl() &&(static_cast <bool> (FD->isInvalidDecl() && "a null body is only allowed for invalid declarations" ) ? void (0) : __assert_fail ("FD->isInvalidDecl() && \"a null body is only allowed for invalid declarations\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1096, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1096 | "a null body is only allowed for invalid declarations")(static_cast <bool> (FD->isInvalidDecl() && "a null body is only allowed for invalid declarations" ) ? void (0) : __assert_fail ("FD->isInvalidDecl() && \"a null body is only allowed for invalid declarations\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1096, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1097 | return; | ||||||
| 1098 | } | ||||||
| 1099 | // We have a function that uses coroutine keywords, but we failed to build | ||||||
| 1100 | // the promise type. | ||||||
| 1101 | if (!Fn->CoroutinePromise) | ||||||
| 1102 | return FD->setInvalidDecl(); | ||||||
| 1103 | |||||||
| 1104 | if (isa<CoroutineBodyStmt>(Body)) { | ||||||
| 1105 | // Nothing todo. the body is already a transformed coroutine body statement. | ||||||
| 1106 | return; | ||||||
| 1107 | } | ||||||
| 1108 | |||||||
| 1109 | // The always_inline attribute doesn't reliably apply to a coroutine, | ||||||
| 1110 | // because the coroutine will be split into pieces and some pieces | ||||||
| 1111 | // might be called indirectly, as in a virtual call. Even the ramp | ||||||
| 1112 | // function cannot be inlined at -O0, due to pipeline ordering | ||||||
| 1113 | // problems (see https://llvm.org/PR53413). Tell the user about it. | ||||||
| 1114 | if (FD->hasAttr<AlwaysInlineAttr>()) | ||||||
| 1115 | Diag(FD->getLocation(), diag::warn_always_inline_coroutine); | ||||||
| 1116 | |||||||
| 1117 | // [stmt.return.coroutine]p1: | ||||||
| 1118 | // A coroutine shall not enclose a return statement ([stmt.return]). | ||||||
| 1119 | if (Fn->FirstReturnLoc.isValid()) { | ||||||
| 1120 | assert(Fn->FirstCoroutineStmtLoc.isValid() &&(static_cast <bool> (Fn->FirstCoroutineStmtLoc.isValid () && "first coroutine location not set") ? void (0) : __assert_fail ("Fn->FirstCoroutineStmtLoc.isValid() && \"first coroutine location not set\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1121, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1121 | "first coroutine location not set")(static_cast <bool> (Fn->FirstCoroutineStmtLoc.isValid () && "first coroutine location not set") ? void (0) : __assert_fail ("Fn->FirstCoroutineStmtLoc.isValid() && \"first coroutine location not set\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1121, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1122 | Diag(Fn->FirstReturnLoc, diag::err_return_in_coroutine); | ||||||
| 1123 | Diag(Fn->FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) | ||||||
| 1124 | << Fn->getFirstCoroutineStmtKeyword(); | ||||||
| 1125 | } | ||||||
| 1126 | |||||||
| 1127 | // Coroutines will get splitted into pieces. The GNU address of label | ||||||
| 1128 | // extension wouldn't be meaningful in coroutines. | ||||||
| 1129 | for (AddrLabelExpr *ALE : Fn->AddrLabels) | ||||||
| 1130 | Diag(ALE->getBeginLoc(), diag::err_coro_invalid_addr_of_label); | ||||||
| 1131 | |||||||
| 1132 | CoroutineStmtBuilder Builder(*this, *FD, *Fn, Body); | ||||||
| 1133 | if (Builder.isInvalid() || !Builder.buildStatements()) | ||||||
| 1134 | return FD->setInvalidDecl(); | ||||||
| 1135 | |||||||
| 1136 | // Build body for the coroutine wrapper statement. | ||||||
| 1137 | Body = CoroutineBodyStmt::Create(Context, Builder); | ||||||
| 1138 | } | ||||||
| 1139 | |||||||
| 1140 | static CompoundStmt *buildCoroutineBody(Stmt *Body, ASTContext &Context) { | ||||||
| 1141 | if (auto *CS = dyn_cast<CompoundStmt>(Body)) | ||||||
| 1142 | return CS; | ||||||
| 1143 | |||||||
| 1144 | // The body of the coroutine may be a try statement if it is in | ||||||
| 1145 | // 'function-try-block' syntax. Here we wrap it into a compound | ||||||
| 1146 | // statement for consistency. | ||||||
| 1147 | assert(isa<CXXTryStmt>(Body) && "Unimaged coroutine body type")(static_cast <bool> (isa<CXXTryStmt>(Body) && "Unimaged coroutine body type") ? void (0) : __assert_fail ( "isa<CXXTryStmt>(Body) && \"Unimaged coroutine body type\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1147, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1148 | return CompoundStmt::Create(Context, {Body}, FPOptionsOverride(), | ||||||
| 1149 | SourceLocation(), SourceLocation()); | ||||||
| 1150 | } | ||||||
| 1151 | |||||||
| 1152 | CoroutineStmtBuilder::CoroutineStmtBuilder(Sema &S, FunctionDecl &FD, | ||||||
| 1153 | sema::FunctionScopeInfo &Fn, | ||||||
| 1154 | Stmt *Body) | ||||||
| 1155 | : S(S), FD(FD), Fn(Fn), Loc(FD.getLocation()), | ||||||
| 1156 | IsPromiseDependentType( | ||||||
| 1157 | !Fn.CoroutinePromise || | ||||||
| 1158 | Fn.CoroutinePromise->getType()->isDependentType()) { | ||||||
| 1159 | this->Body = buildCoroutineBody(Body, S.getASTContext()); | ||||||
| 1160 | |||||||
| 1161 | for (auto KV : Fn.CoroutineParameterMoves) | ||||||
| 1162 | this->ParamMovesVector.push_back(KV.second); | ||||||
| 1163 | this->ParamMoves = this->ParamMovesVector; | ||||||
| 1164 | |||||||
| 1165 | if (!IsPromiseDependentType) { | ||||||
| 1166 | PromiseRecordDecl = Fn.CoroutinePromise->getType()->getAsCXXRecordDecl(); | ||||||
| 1167 | assert(PromiseRecordDecl && "Type should have already been checked")(static_cast <bool> (PromiseRecordDecl && "Type should have already been checked" ) ? void (0) : __assert_fail ("PromiseRecordDecl && \"Type should have already been checked\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1167, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1168 | } | ||||||
| 1169 | this->IsValid = makePromiseStmt() && makeInitialAndFinalSuspend(); | ||||||
| 1170 | } | ||||||
| 1171 | |||||||
| 1172 | bool CoroutineStmtBuilder::buildStatements() { | ||||||
| 1173 | assert(this->IsValid && "coroutine already invalid")(static_cast <bool> (this->IsValid && "coroutine already invalid" ) ? void (0) : __assert_fail ("this->IsValid && \"coroutine already invalid\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1173, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1174 | this->IsValid = makeReturnObject(); | ||||||
| 1175 | if (this->IsValid && !IsPromiseDependentType) | ||||||
| 1176 | buildDependentStatements(); | ||||||
| 1177 | return this->IsValid; | ||||||
| 1178 | } | ||||||
| 1179 | |||||||
| 1180 | bool CoroutineStmtBuilder::buildDependentStatements() { | ||||||
| 1181 | assert(this->IsValid && "coroutine already invalid")(static_cast <bool> (this->IsValid && "coroutine already invalid" ) ? void (0) : __assert_fail ("this->IsValid && \"coroutine already invalid\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1181, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1182 | assert(!this->IsPromiseDependentType &&(static_cast <bool> (!this->IsPromiseDependentType && "coroutine cannot have a dependent promise type") ? void (0) : __assert_fail ("!this->IsPromiseDependentType && \"coroutine cannot have a dependent promise type\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1183, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1183 | "coroutine cannot have a dependent promise type")(static_cast <bool> (!this->IsPromiseDependentType && "coroutine cannot have a dependent promise type") ? void (0) : __assert_fail ("!this->IsPromiseDependentType && \"coroutine cannot have a dependent promise type\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1183, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1184 | this->IsValid = makeOnException() && makeOnFallthrough() && | ||||||
| 1185 | makeGroDeclAndReturnStmt() && makeReturnOnAllocFailure() && | ||||||
| 1186 | makeNewAndDeleteExpr(); | ||||||
| 1187 | return this->IsValid; | ||||||
| 1188 | } | ||||||
| 1189 | |||||||
| 1190 | bool CoroutineStmtBuilder::makePromiseStmt() { | ||||||
| 1191 | // Form a declaration statement for the promise declaration, so that AST | ||||||
| 1192 | // visitors can more easily find it. | ||||||
| 1193 | StmtResult PromiseStmt = | ||||||
| 1194 | S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(Fn.CoroutinePromise), Loc, Loc); | ||||||
| 1195 | if (PromiseStmt.isInvalid()) | ||||||
| 1196 | return false; | ||||||
| 1197 | |||||||
| 1198 | this->Promise = PromiseStmt.get(); | ||||||
| 1199 | return true; | ||||||
| 1200 | } | ||||||
| 1201 | |||||||
| 1202 | bool CoroutineStmtBuilder::makeInitialAndFinalSuspend() { | ||||||
| 1203 | if (Fn.hasInvalidCoroutineSuspends()) | ||||||
| 1204 | return false; | ||||||
| 1205 | this->InitialSuspend = cast<Expr>(Fn.CoroutineSuspends.first); | ||||||
| 1206 | this->FinalSuspend = cast<Expr>(Fn.CoroutineSuspends.second); | ||||||
| 1207 | return true; | ||||||
| 1208 | } | ||||||
| 1209 | |||||||
| 1210 | static bool diagReturnOnAllocFailure(Sema &S, Expr *E, | ||||||
| 1211 | CXXRecordDecl *PromiseRecordDecl, | ||||||
| 1212 | FunctionScopeInfo &Fn) { | ||||||
| 1213 | auto Loc = E->getExprLoc(); | ||||||
| 1214 | if (auto *DeclRef = dyn_cast_or_null<DeclRefExpr>(E)) { | ||||||
| 1215 | auto *Decl = DeclRef->getDecl(); | ||||||
| 1216 | if (CXXMethodDecl *Method = dyn_cast_or_null<CXXMethodDecl>(Decl)) { | ||||||
| 1217 | if (Method->isStatic()) | ||||||
| 1218 | return true; | ||||||
| 1219 | else | ||||||
| 1220 | Loc = Decl->getLocation(); | ||||||
| 1221 | } | ||||||
| 1222 | } | ||||||
| 1223 | |||||||
| 1224 | S.Diag( | ||||||
| 1225 | Loc, | ||||||
| 1226 | diag::err_coroutine_promise_get_return_object_on_allocation_failure) | ||||||
| 1227 | << PromiseRecordDecl; | ||||||
| 1228 | S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) | ||||||
| 1229 | << Fn.getFirstCoroutineStmtKeyword(); | ||||||
| 1230 | return false; | ||||||
| 1231 | } | ||||||
| 1232 | |||||||
| 1233 | bool CoroutineStmtBuilder::makeReturnOnAllocFailure() { | ||||||
| 1234 | assert(!IsPromiseDependentType &&(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1235, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1235 | "cannot make statement while the promise type is dependent")(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1235, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1236 | |||||||
| 1237 | // [dcl.fct.def.coroutine]p10 | ||||||
| 1238 | // If a search for the name get_return_object_on_allocation_failure in | ||||||
| 1239 | // the scope of the promise type ([class.member.lookup]) finds any | ||||||
| 1240 | // declarations, then the result of a call to an allocation function used to | ||||||
| 1241 | // obtain storage for the coroutine state is assumed to return nullptr if it | ||||||
| 1242 | // fails to obtain storage, ... If the allocation function returns nullptr, | ||||||
| 1243 | // ... and the return value is obtained by a call to | ||||||
| 1244 | // T::get_return_object_on_allocation_failure(), where T is the | ||||||
| 1245 | // promise type. | ||||||
| 1246 | DeclarationName DN = | ||||||
| 1247 | S.PP.getIdentifierInfo("get_return_object_on_allocation_failure"); | ||||||
| 1248 | LookupResult Found(S, DN, Loc, Sema::LookupMemberName); | ||||||
| 1249 | if (!S.LookupQualifiedName(Found, PromiseRecordDecl)) | ||||||
| 1250 | return true; | ||||||
| 1251 | |||||||
| 1252 | CXXScopeSpec SS; | ||||||
| 1253 | ExprResult DeclNameExpr = | ||||||
| 1254 | S.BuildDeclarationNameExpr(SS, Found, /*NeedsADL=*/false); | ||||||
| 1255 | if (DeclNameExpr.isInvalid()) | ||||||
| 1256 | return false; | ||||||
| 1257 | |||||||
| 1258 | if (!diagReturnOnAllocFailure(S, DeclNameExpr.get(), PromiseRecordDecl, Fn)) | ||||||
| 1259 | return false; | ||||||
| 1260 | |||||||
| 1261 | ExprResult ReturnObjectOnAllocationFailure = | ||||||
| 1262 | S.BuildCallExpr(nullptr, DeclNameExpr.get(), Loc, {}, Loc); | ||||||
| 1263 | if (ReturnObjectOnAllocationFailure.isInvalid()) | ||||||
| 1264 | return false; | ||||||
| 1265 | |||||||
| 1266 | StmtResult ReturnStmt = | ||||||
| 1267 | S.BuildReturnStmt(Loc, ReturnObjectOnAllocationFailure.get()); | ||||||
| 1268 | if (ReturnStmt.isInvalid()) { | ||||||
| 1269 | S.Diag(Found.getFoundDecl()->getLocation(), diag::note_member_declared_here) | ||||||
| 1270 | << DN; | ||||||
| 1271 | S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) | ||||||
| 1272 | << Fn.getFirstCoroutineStmtKeyword(); | ||||||
| 1273 | return false; | ||||||
| 1274 | } | ||||||
| 1275 | |||||||
| 1276 | this->ReturnStmtOnAllocFailure = ReturnStmt.get(); | ||||||
| 1277 | return true; | ||||||
| 1278 | } | ||||||
| 1279 | |||||||
| 1280 | // Collect placement arguments for allocation function of coroutine FD. | ||||||
| 1281 | // Return true if we collect placement arguments succesfully. Return false, | ||||||
| 1282 | // otherwise. | ||||||
| 1283 | static bool collectPlacementArgs(Sema &S, FunctionDecl &FD, SourceLocation Loc, | ||||||
| 1284 | SmallVectorImpl<Expr *> &PlacementArgs) { | ||||||
| 1285 | if (auto *MD = dyn_cast<CXXMethodDecl>(&FD)) { | ||||||
| 1286 | if (MD->isInstance() && !isLambdaCallOperator(MD)) { | ||||||
| 1287 | ExprResult ThisExpr = S.ActOnCXXThis(Loc); | ||||||
| 1288 | if (ThisExpr.isInvalid()) | ||||||
| 1289 | return false; | ||||||
| 1290 | ThisExpr = S.CreateBuiltinUnaryOp(Loc, UO_Deref, ThisExpr.get()); | ||||||
| 1291 | if (ThisExpr.isInvalid()) | ||||||
| 1292 | return false; | ||||||
| 1293 | PlacementArgs.push_back(ThisExpr.get()); | ||||||
| 1294 | } | ||||||
| 1295 | } | ||||||
| 1296 | |||||||
| 1297 | for (auto *PD : FD.parameters()) { | ||||||
| 1298 | if (PD->getType()->isDependentType()) | ||||||
| 1299 | continue; | ||||||
| 1300 | |||||||
| 1301 | // Build a reference to the parameter. | ||||||
| 1302 | auto PDLoc = PD->getLocation(); | ||||||
| 1303 | ExprResult PDRefExpr = | ||||||
| 1304 | S.BuildDeclRefExpr(PD, PD->getOriginalType().getNonReferenceType(), | ||||||
| 1305 | ExprValueKind::VK_LValue, PDLoc); | ||||||
| 1306 | if (PDRefExpr.isInvalid()) | ||||||
| 1307 | return false; | ||||||
| 1308 | |||||||
| 1309 | PlacementArgs.push_back(PDRefExpr.get()); | ||||||
| 1310 | } | ||||||
| 1311 | |||||||
| 1312 | return true; | ||||||
| 1313 | } | ||||||
| 1314 | |||||||
| 1315 | bool CoroutineStmtBuilder::makeNewAndDeleteExpr() { | ||||||
| 1316 | // Form and check allocation and deallocation calls. | ||||||
| 1317 | assert(!IsPromiseDependentType &&(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1318, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1318 | "cannot make statement while the promise type is dependent")(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1318, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1319 | QualType PromiseType = Fn.CoroutinePromise->getType(); | ||||||
| 1320 | |||||||
| 1321 | if (S.RequireCompleteType(Loc, PromiseType, diag::err_incomplete_type)) | ||||||
| 1322 | return false; | ||||||
| 1323 | |||||||
| 1324 | const bool RequiresNoThrowAlloc = ReturnStmtOnAllocFailure != nullptr; | ||||||
| 1325 | |||||||
| 1326 | // According to [dcl.fct.def.coroutine]p9, Lookup allocation functions using a | ||||||
| 1327 | // parameter list composed of the requested size of the coroutine state being | ||||||
| 1328 | // allocated, followed by the coroutine function's arguments. If a matching | ||||||
| 1329 | // allocation function exists, use it. Otherwise, use an allocation function | ||||||
| 1330 | // that just takes the requested size. | ||||||
| 1331 | // | ||||||
| 1332 | // [dcl.fct.def.coroutine]p9 | ||||||
| 1333 | // An implementation may need to allocate additional storage for a | ||||||
| 1334 | // coroutine. | ||||||
| 1335 | // This storage is known as the coroutine state and is obtained by calling a | ||||||
| 1336 | // non-array allocation function ([basic.stc.dynamic.allocation]). The | ||||||
| 1337 | // allocation function's name is looked up by searching for it in the scope of | ||||||
| 1338 | // the promise type. | ||||||
| 1339 | // - If any declarations are found, overload resolution is performed on a | ||||||
| 1340 | // function call created by assembling an argument list. The first argument is | ||||||
| 1341 | // the amount of space requested, and has type std::size_t. The | ||||||
| 1342 | // lvalues p1 ... pn are the succeeding arguments. | ||||||
| 1343 | // | ||||||
| 1344 | // ...where "p1 ... pn" are defined earlier as: | ||||||
| 1345 | // | ||||||
| 1346 | // [dcl.fct.def.coroutine]p3 | ||||||
| 1347 | // The promise type of a coroutine is `std::coroutine_traits<R, P1, ..., | ||||||
| 1348 | // Pn>` | ||||||
| 1349 | // , where R is the return type of the function, and `P1, ..., Pn` are the | ||||||
| 1350 | // sequence of types of the non-object function parameters, preceded by the | ||||||
| 1351 | // type of the object parameter ([dcl.fct]) if the coroutine is a non-static | ||||||
| 1352 | // member function. [dcl.fct.def.coroutine]p4 In the following, p_i is an | ||||||
| 1353 | // lvalue of type P_i, where p1 denotes the object parameter and p_i+1 denotes | ||||||
| 1354 | // the i-th non-object function parameter for a non-static member function, | ||||||
| 1355 | // and p_i denotes the i-th function parameter otherwise. For a non-static | ||||||
| 1356 | // member function, q_1 is an lvalue that denotes *this; any other q_i is an | ||||||
| 1357 | // lvalue that denotes the parameter copy corresponding to p_i. | ||||||
| 1358 | |||||||
| 1359 | FunctionDecl *OperatorNew = nullptr; | ||||||
| 1360 | SmallVector<Expr *, 1> PlacementArgs; | ||||||
| 1361 | |||||||
| 1362 | const bool PromiseContainsNew = [this, &PromiseType]() -> bool { | ||||||
| 1363 | DeclarationName NewName = | ||||||
| 1364 | S.getASTContext().DeclarationNames.getCXXOperatorName(OO_New); | ||||||
| 1365 | LookupResult R(S, NewName, Loc, Sema::LookupOrdinaryName); | ||||||
| 1366 | |||||||
| 1367 | if (PromiseType->isRecordType()) | ||||||
| 1368 | S.LookupQualifiedName(R, PromiseType->getAsCXXRecordDecl()); | ||||||
| 1369 | |||||||
| 1370 | return !R.empty() && !R.isAmbiguous(); | ||||||
| 1371 | }(); | ||||||
| 1372 | |||||||
| 1373 | // Helper function to indicate whether the last lookup found the aligned | ||||||
| 1374 | // allocation function. | ||||||
| 1375 | bool PassAlignment = S.getLangOpts().CoroAlignedAllocation; | ||||||
| 1376 | auto LookupAllocationFunction = [&](Sema::AllocationFunctionScope NewScope = | ||||||
| 1377 | Sema::AFS_Both, | ||||||
| 1378 | bool WithoutPlacementArgs = false, | ||||||
| 1379 | bool ForceNonAligned = false) { | ||||||
| 1380 | // [dcl.fct.def.coroutine]p9 | ||||||
| 1381 | // The allocation function's name is looked up by searching for it in the | ||||||
| 1382 | // scope of the promise type. | ||||||
| 1383 | // - If any declarations are found, ... | ||||||
| 1384 | // - If no declarations are found in the scope of the promise type, a search | ||||||
| 1385 | // is performed in the global scope. | ||||||
| 1386 | if (NewScope == Sema::AFS_Both) | ||||||
| 1387 | NewScope = PromiseContainsNew ? Sema::AFS_Class : Sema::AFS_Global; | ||||||
| 1388 | |||||||
| 1389 | PassAlignment = !ForceNonAligned && S.getLangOpts().CoroAlignedAllocation; | ||||||
| 1390 | FunctionDecl *UnusedResult = nullptr; | ||||||
| 1391 | S.FindAllocationFunctions(Loc, SourceRange(), NewScope, | ||||||
| 1392 | /*DeleteScope*/ Sema::AFS_Both, PromiseType, | ||||||
| 1393 | /*isArray*/ false, PassAlignment, | ||||||
| 1394 | WithoutPlacementArgs ? MultiExprArg{} | ||||||
| 1395 | : PlacementArgs, | ||||||
| 1396 | OperatorNew, UnusedResult, /*Diagnose*/ false); | ||||||
| 1397 | }; | ||||||
| 1398 | |||||||
| 1399 | // We don't expect to call to global operator new with (size, p0, …, pn). | ||||||
| 1400 | // So if we choose to lookup the allocation function in global scope, we | ||||||
| 1401 | // shouldn't lookup placement arguments. | ||||||
| 1402 | if (PromiseContainsNew && !collectPlacementArgs(S, FD, Loc, PlacementArgs)) | ||||||
| 1403 | return false; | ||||||
| 1404 | |||||||
| 1405 | LookupAllocationFunction(); | ||||||
| 1406 | |||||||
| 1407 | if (PromiseContainsNew && !PlacementArgs.empty()) { | ||||||
| 1408 | // [dcl.fct.def.coroutine]p9 | ||||||
| 1409 | // If no viable function is found ([over.match.viable]), overload | ||||||
| 1410 | // resolution | ||||||
| 1411 | // is performed again on a function call created by passing just the amount | ||||||
| 1412 | // of space required as an argument of type std::size_t. | ||||||
| 1413 | // | ||||||
| 1414 | // Proposed Change of [dcl.fct.def.coroutine]p9 in P2014R0: | ||||||
| 1415 | // Otherwise, overload resolution is performed again on a function call | ||||||
| 1416 | // created | ||||||
| 1417 | // by passing the amount of space requested as an argument of type | ||||||
| 1418 | // std::size_t as the first argument, and the requested alignment as | ||||||
| 1419 | // an argument of type std:align_val_t as the second argument. | ||||||
| 1420 | if (!OperatorNew || | ||||||
| 1421 | (S.getLangOpts().CoroAlignedAllocation && !PassAlignment)) | ||||||
| 1422 | LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class, | ||||||
| 1423 | /*WithoutPlacementArgs*/ true); | ||||||
| 1424 | } | ||||||
| 1425 | |||||||
| 1426 | // Proposed Change of [dcl.fct.def.coroutine]p12 in P2014R0: | ||||||
| 1427 | // Otherwise, overload resolution is performed again on a function call | ||||||
| 1428 | // created | ||||||
| 1429 | // by passing the amount of space requested as an argument of type | ||||||
| 1430 | // std::size_t as the first argument, and the lvalues p1 ... pn as the | ||||||
| 1431 | // succeeding arguments. Otherwise, overload resolution is performed again | ||||||
| 1432 | // on a function call created by passing just the amount of space required as | ||||||
| 1433 | // an argument of type std::size_t. | ||||||
| 1434 | // | ||||||
| 1435 | // So within the proposed change in P2014RO, the priority order of aligned | ||||||
| 1436 | // allocation functions wiht promise_type is: | ||||||
| 1437 | // | ||||||
| 1438 | // void* operator new( std::size_t, std::align_val_t, placement_args... ); | ||||||
| 1439 | // void* operator new( std::size_t, std::align_val_t); | ||||||
| 1440 | // void* operator new( std::size_t, placement_args... ); | ||||||
| 1441 | // void* operator new( std::size_t); | ||||||
| 1442 | |||||||
| 1443 | // Helper variable to emit warnings. | ||||||
| 1444 | bool FoundNonAlignedInPromise = false; | ||||||
| 1445 | if (PromiseContainsNew && S.getLangOpts().CoroAlignedAllocation) | ||||||
| 1446 | if (!OperatorNew || !PassAlignment) { | ||||||
| 1447 | FoundNonAlignedInPromise = OperatorNew; | ||||||
| 1448 | |||||||
| 1449 | LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class, | ||||||
| 1450 | /*WithoutPlacementArgs*/ false, | ||||||
| 1451 | /*ForceNonAligned*/ true); | ||||||
| 1452 | |||||||
| 1453 | if (!OperatorNew && !PlacementArgs.empty()) | ||||||
| 1454 | LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class, | ||||||
| 1455 | /*WithoutPlacementArgs*/ true, | ||||||
| 1456 | /*ForceNonAligned*/ true); | ||||||
| 1457 | } | ||||||
| 1458 | |||||||
| 1459 | bool IsGlobalOverload = | ||||||
| 1460 | OperatorNew && !isa<CXXRecordDecl>(OperatorNew->getDeclContext()); | ||||||
| 1461 | // If we didn't find a class-local new declaration and non-throwing new | ||||||
| 1462 | // was is required then we need to lookup the non-throwing global operator | ||||||
| 1463 | // instead. | ||||||
| 1464 | if (RequiresNoThrowAlloc && (!OperatorNew || IsGlobalOverload)) { | ||||||
| 1465 | auto *StdNoThrow = buildStdNoThrowDeclRef(S, Loc); | ||||||
| 1466 | if (!StdNoThrow) | ||||||
| 1467 | return false; | ||||||
| 1468 | PlacementArgs = {StdNoThrow}; | ||||||
| 1469 | OperatorNew = nullptr; | ||||||
| 1470 | LookupAllocationFunction(Sema::AFS_Global); | ||||||
| 1471 | } | ||||||
| 1472 | |||||||
| 1473 | // If we found a non-aligned allocation function in the promise_type, | ||||||
| 1474 | // it indicates the user forgot to update the allocation function. Let's emit | ||||||
| 1475 | // a warning here. | ||||||
| 1476 | if (FoundNonAlignedInPromise) { | ||||||
| 1477 | S.Diag(OperatorNew->getLocation(), | ||||||
| 1478 | diag::warn_non_aligned_allocation_function) | ||||||
| 1479 | << &FD; | ||||||
| 1480 | } | ||||||
| 1481 | |||||||
| 1482 | if (!OperatorNew) { | ||||||
| 1483 | if (PromiseContainsNew) | ||||||
| 1484 | S.Diag(Loc, diag::err_coroutine_unusable_new) << PromiseType << &FD; | ||||||
| 1485 | else if (RequiresNoThrowAlloc) | ||||||
| 1486 | S.Diag(Loc, diag::err_coroutine_unfound_nothrow_new) | ||||||
| 1487 | << &FD << S.getLangOpts().CoroAlignedAllocation; | ||||||
| 1488 | |||||||
| 1489 | return false; | ||||||
| 1490 | } | ||||||
| 1491 | |||||||
| 1492 | if (RequiresNoThrowAlloc) { | ||||||
| 1493 | const auto *FT = OperatorNew->getType()->castAs<FunctionProtoType>(); | ||||||
| 1494 | if (!FT->isNothrow(/*ResultIfDependent*/ false)) { | ||||||
| 1495 | S.Diag(OperatorNew->getLocation(), | ||||||
| 1496 | diag::err_coroutine_promise_new_requires_nothrow) | ||||||
| 1497 | << OperatorNew; | ||||||
| 1498 | S.Diag(Loc, diag::note_coroutine_promise_call_implicitly_required) | ||||||
| 1499 | << OperatorNew; | ||||||
| 1500 | return false; | ||||||
| 1501 | } | ||||||
| 1502 | } | ||||||
| 1503 | |||||||
| 1504 | FunctionDecl *OperatorDelete = nullptr; | ||||||
| 1505 | if (!findDeleteForPromise(S, Loc, PromiseType, OperatorDelete)) { | ||||||
| 1506 | // FIXME: We should add an error here. According to: | ||||||
| 1507 | // [dcl.fct.def.coroutine]p12 | ||||||
| 1508 | // If no usual deallocation function is found, the program is ill-formed. | ||||||
| 1509 | return false; | ||||||
| 1510 | } | ||||||
| 1511 | |||||||
| 1512 | Expr *FramePtr = | ||||||
| 1513 | S.BuildBuiltinCallExpr(Loc, Builtin::BI__builtin_coro_frame, {}); | ||||||
| 1514 | |||||||
| 1515 | Expr *FrameSize = | ||||||
| 1516 | S.BuildBuiltinCallExpr(Loc, Builtin::BI__builtin_coro_size, {}); | ||||||
| 1517 | |||||||
| 1518 | Expr *FrameAlignment = nullptr; | ||||||
| 1519 | |||||||
| 1520 | if (S.getLangOpts().CoroAlignedAllocation) { | ||||||
| 1521 | FrameAlignment = | ||||||
| 1522 | S.BuildBuiltinCallExpr(Loc, Builtin::BI__builtin_coro_align, {}); | ||||||
| 1523 | |||||||
| 1524 | TypeSourceInfo *AlignValTy = getTypeSourceInfoForStdAlignValT(S, Loc); | ||||||
| 1525 | if (!AlignValTy) | ||||||
| 1526 | return false; | ||||||
| 1527 | |||||||
| 1528 | FrameAlignment = S.BuildCXXNamedCast(Loc, tok::kw_static_cast, AlignValTy, | ||||||
| 1529 | FrameAlignment, SourceRange(Loc, Loc), | ||||||
| 1530 | SourceRange(Loc, Loc)) | ||||||
| 1531 | .get(); | ||||||
| 1532 | } | ||||||
| 1533 | |||||||
| 1534 | // Make new call. | ||||||
| 1535 | ExprResult NewRef = | ||||||
| 1536 | S.BuildDeclRefExpr(OperatorNew, OperatorNew->getType(), VK_LValue, Loc); | ||||||
| 1537 | if (NewRef.isInvalid()) | ||||||
| 1538 | return false; | ||||||
| 1539 | |||||||
| 1540 | SmallVector<Expr *, 2> NewArgs(1, FrameSize); | ||||||
| 1541 | if (S.getLangOpts().CoroAlignedAllocation && PassAlignment) | ||||||
| 1542 | NewArgs.push_back(FrameAlignment); | ||||||
| 1543 | |||||||
| 1544 | if (OperatorNew->getNumParams() > NewArgs.size()) | ||||||
| 1545 | llvm::append_range(NewArgs, PlacementArgs); | ||||||
| 1546 | |||||||
| 1547 | ExprResult NewExpr = | ||||||
| 1548 | S.BuildCallExpr(S.getCurScope(), NewRef.get(), Loc, NewArgs, Loc); | ||||||
| 1549 | NewExpr = S.ActOnFinishFullExpr(NewExpr.get(), /*DiscardedValue*/ false); | ||||||
| 1550 | if (NewExpr.isInvalid()) | ||||||
| 1551 | return false; | ||||||
| 1552 | |||||||
| 1553 | // Make delete call. | ||||||
| 1554 | |||||||
| 1555 | QualType OpDeleteQualType = OperatorDelete->getType(); | ||||||
| 1556 | |||||||
| 1557 | ExprResult DeleteRef = | ||||||
| 1558 | S.BuildDeclRefExpr(OperatorDelete, OpDeleteQualType, VK_LValue, Loc); | ||||||
| 1559 | if (DeleteRef.isInvalid()) | ||||||
| 1560 | return false; | ||||||
| 1561 | |||||||
| 1562 | Expr *CoroFree = | ||||||
| 1563 | S.BuildBuiltinCallExpr(Loc, Builtin::BI__builtin_coro_free, {FramePtr}); | ||||||
| 1564 | |||||||
| 1565 | SmallVector<Expr *, 2> DeleteArgs{CoroFree}; | ||||||
| 1566 | |||||||
| 1567 | // [dcl.fct.def.coroutine]p12 | ||||||
| 1568 | // The selected deallocation function shall be called with the address of | ||||||
| 1569 | // the block of storage to be reclaimed as its first argument. If a | ||||||
| 1570 | // deallocation function with a parameter of type std::size_t is | ||||||
| 1571 | // used, the size of the block is passed as the corresponding argument. | ||||||
| 1572 | const auto *OpDeleteType = | ||||||
| 1573 | OpDeleteQualType.getTypePtr()->castAs<FunctionProtoType>(); | ||||||
| 1574 | if (OpDeleteType->getNumParams() > DeleteArgs.size() && | ||||||
| 1575 | S.getASTContext().hasSameUnqualifiedType( | ||||||
| 1576 | OpDeleteType->getParamType(DeleteArgs.size()), FrameSize->getType())) | ||||||
| 1577 | DeleteArgs.push_back(FrameSize); | ||||||
| 1578 | |||||||
| 1579 | // Proposed Change of [dcl.fct.def.coroutine]p12 in P2014R0: | ||||||
| 1580 | // If deallocation function lookup finds a usual deallocation function with | ||||||
| 1581 | // a pointer parameter, size parameter and alignment parameter then this | ||||||
| 1582 | // will be the selected deallocation function, otherwise if lookup finds a | ||||||
| 1583 | // usual deallocation function with both a pointer parameter and a size | ||||||
| 1584 | // parameter, then this will be the selected deallocation function. | ||||||
| 1585 | // Otherwise, if lookup finds a usual deallocation function with only a | ||||||
| 1586 | // pointer parameter, then this will be the selected deallocation | ||||||
| 1587 | // function. | ||||||
| 1588 | // | ||||||
| 1589 | // So we are not forced to pass alignment to the deallocation function. | ||||||
| 1590 | if (S.getLangOpts().CoroAlignedAllocation && | ||||||
| 1591 | OpDeleteType->getNumParams() > DeleteArgs.size() && | ||||||
| 1592 | S.getASTContext().hasSameUnqualifiedType( | ||||||
| 1593 | OpDeleteType->getParamType(DeleteArgs.size()), | ||||||
| 1594 | FrameAlignment->getType())) | ||||||
| 1595 | DeleteArgs.push_back(FrameAlignment); | ||||||
| 1596 | |||||||
| 1597 | ExprResult DeleteExpr = | ||||||
| 1598 | S.BuildCallExpr(S.getCurScope(), DeleteRef.get(), Loc, DeleteArgs, Loc); | ||||||
| 1599 | DeleteExpr = | ||||||
| 1600 | S.ActOnFinishFullExpr(DeleteExpr.get(), /*DiscardedValue*/ false); | ||||||
| 1601 | if (DeleteExpr.isInvalid()) | ||||||
| 1602 | return false; | ||||||
| 1603 | |||||||
| 1604 | this->Allocate = NewExpr.get(); | ||||||
| 1605 | this->Deallocate = DeleteExpr.get(); | ||||||
| 1606 | |||||||
| 1607 | return true; | ||||||
| 1608 | } | ||||||
| 1609 | |||||||
| 1610 | bool CoroutineStmtBuilder::makeOnFallthrough() { | ||||||
| 1611 | assert(!IsPromiseDependentType &&(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1612, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1612 | "cannot make statement while the promise type is dependent")(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1612, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1613 | |||||||
| 1614 | // [dcl.fct.def.coroutine]/p6 | ||||||
| 1615 | // If searches for the names return_void and return_value in the scope of | ||||||
| 1616 | // the promise type each find any declarations, the program is ill-formed. | ||||||
| 1617 | // [Note 1: If return_void is found, flowing off the end of a coroutine is | ||||||
| 1618 | // equivalent to a co_return with no operand. Otherwise, flowing off the end | ||||||
| 1619 | // of a coroutine results in undefined behavior ([stmt.return.coroutine]). — | ||||||
| 1620 | // end note] | ||||||
| 1621 | bool HasRVoid, HasRValue; | ||||||
| 1622 | LookupResult LRVoid = | ||||||
| 1623 | lookupMember(S, "return_void", PromiseRecordDecl, Loc, HasRVoid); | ||||||
| 1624 | LookupResult LRValue = | ||||||
| 1625 | lookupMember(S, "return_value", PromiseRecordDecl, Loc, HasRValue); | ||||||
| 1626 | |||||||
| 1627 | StmtResult Fallthrough; | ||||||
| 1628 | if (HasRVoid && HasRValue) { | ||||||
| 1629 | // FIXME Improve this diagnostic | ||||||
| 1630 | S.Diag(FD.getLocation(), | ||||||
| 1631 | diag::err_coroutine_promise_incompatible_return_functions) | ||||||
| 1632 | << PromiseRecordDecl; | ||||||
| 1633 | S.Diag(LRVoid.getRepresentativeDecl()->getLocation(), | ||||||
| 1634 | diag::note_member_first_declared_here) | ||||||
| 1635 | << LRVoid.getLookupName(); | ||||||
| 1636 | S.Diag(LRValue.getRepresentativeDecl()->getLocation(), | ||||||
| 1637 | diag::note_member_first_declared_here) | ||||||
| 1638 | << LRValue.getLookupName(); | ||||||
| 1639 | return false; | ||||||
| 1640 | } else if (!HasRVoid && !HasRValue) { | ||||||
| 1641 | // We need to set 'Fallthrough'. Otherwise the other analysis part might | ||||||
| 1642 | // think the coroutine has defined a return_value method. So it might emit | ||||||
| 1643 | // **false** positive warning. e.g., | ||||||
| 1644 | // | ||||||
| 1645 | // promise_without_return_func foo() { | ||||||
| 1646 | // co_await something(); | ||||||
| 1647 | // } | ||||||
| 1648 | // | ||||||
| 1649 | // Then AnalysisBasedWarning would emit a warning about `foo()` lacking a | ||||||
| 1650 | // co_return statements, which isn't correct. | ||||||
| 1651 | Fallthrough = S.ActOnNullStmt(PromiseRecordDecl->getLocation()); | ||||||
| 1652 | if (Fallthrough.isInvalid()) | ||||||
| 1653 | return false; | ||||||
| 1654 | } else if (HasRVoid) { | ||||||
| 1655 | Fallthrough = S.BuildCoreturnStmt(FD.getLocation(), nullptr, | ||||||
| 1656 | /*IsImplicit*/false); | ||||||
| 1657 | Fallthrough = S.ActOnFinishFullStmt(Fallthrough.get()); | ||||||
| 1658 | if (Fallthrough.isInvalid()) | ||||||
| 1659 | return false; | ||||||
| 1660 | } | ||||||
| 1661 | |||||||
| 1662 | this->OnFallthrough = Fallthrough.get(); | ||||||
| 1663 | return true; | ||||||
| 1664 | } | ||||||
| 1665 | |||||||
| 1666 | bool CoroutineStmtBuilder::makeOnException() { | ||||||
| 1667 | // Try to form 'p.unhandled_exception();' | ||||||
| 1668 | assert(!IsPromiseDependentType &&(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1669, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1669 | "cannot make statement while the promise type is dependent")(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1669, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1670 | |||||||
| 1671 | const bool RequireUnhandledException = S.getLangOpts().CXXExceptions; | ||||||
| 1672 | |||||||
| 1673 | if (!lookupMember(S, "unhandled_exception", PromiseRecordDecl, Loc)) { | ||||||
| 1674 | auto DiagID = | ||||||
| 1675 | RequireUnhandledException | ||||||
| 1676 | ? diag::err_coroutine_promise_unhandled_exception_required | ||||||
| 1677 | : diag:: | ||||||
| 1678 | warn_coroutine_promise_unhandled_exception_required_with_exceptions; | ||||||
| 1679 | S.Diag(Loc, DiagID) << PromiseRecordDecl; | ||||||
| 1680 | S.Diag(PromiseRecordDecl->getLocation(), diag::note_defined_here) | ||||||
| 1681 | << PromiseRecordDecl; | ||||||
| 1682 | return !RequireUnhandledException; | ||||||
| 1683 | } | ||||||
| 1684 | |||||||
| 1685 | // If exceptions are disabled, don't try to build OnException. | ||||||
| 1686 | if (!S.getLangOpts().CXXExceptions) | ||||||
| 1687 | return true; | ||||||
| 1688 | |||||||
| 1689 | ExprResult UnhandledException = buildPromiseCall( | ||||||
| 1690 | S, Fn.CoroutinePromise, Loc, "unhandled_exception", std::nullopt); | ||||||
| 1691 | UnhandledException = S.ActOnFinishFullExpr(UnhandledException.get(), Loc, | ||||||
| 1692 | /*DiscardedValue*/ false); | ||||||
| 1693 | if (UnhandledException.isInvalid()) | ||||||
| 1694 | return false; | ||||||
| 1695 | |||||||
| 1696 | // Since the body of the coroutine will be wrapped in try-catch, it will | ||||||
| 1697 | // be incompatible with SEH __try if present in a function. | ||||||
| 1698 | if (!S.getLangOpts().Borland && Fn.FirstSEHTryLoc.isValid()) { | ||||||
| 1699 | S.Diag(Fn.FirstSEHTryLoc, diag::err_seh_in_a_coroutine_with_cxx_exceptions); | ||||||
| 1700 | S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) | ||||||
| 1701 | << Fn.getFirstCoroutineStmtKeyword(); | ||||||
| 1702 | return false; | ||||||
| 1703 | } | ||||||
| 1704 | |||||||
| 1705 | this->OnException = UnhandledException.get(); | ||||||
| 1706 | return true; | ||||||
| 1707 | } | ||||||
| 1708 | |||||||
| 1709 | bool CoroutineStmtBuilder::makeReturnObject() { | ||||||
| 1710 | // [dcl.fct.def.coroutine]p7 | ||||||
| 1711 | // The expression promise.get_return_object() is used to initialize the | ||||||
| 1712 | // returned reference or prvalue result object of a call to a coroutine. | ||||||
| 1713 | ExprResult ReturnObject = buildPromiseCall(S, Fn.CoroutinePromise, Loc, | ||||||
| 1714 | "get_return_object", std::nullopt); | ||||||
| 1715 | if (ReturnObject.isInvalid()) | ||||||
| 1716 | return false; | ||||||
| 1717 | |||||||
| 1718 | this->ReturnValue = ReturnObject.get(); | ||||||
| 1719 | return true; | ||||||
| 1720 | } | ||||||
| 1721 | |||||||
| 1722 | static void noteMemberDeclaredHere(Sema &S, Expr *E, FunctionScopeInfo &Fn) { | ||||||
| 1723 | if (auto *MbrRef = dyn_cast<CXXMemberCallExpr>(E)) { | ||||||
| 1724 | auto *MethodDecl = MbrRef->getMethodDecl(); | ||||||
| 1725 | S.Diag(MethodDecl->getLocation(), diag::note_member_declared_here) | ||||||
| 1726 | << MethodDecl; | ||||||
| 1727 | } | ||||||
| 1728 | S.Diag(Fn.FirstCoroutineStmtLoc, diag::note_declared_coroutine_here) | ||||||
| 1729 | << Fn.getFirstCoroutineStmtKeyword(); | ||||||
| 1730 | } | ||||||
| 1731 | |||||||
| 1732 | bool CoroutineStmtBuilder::makeGroDeclAndReturnStmt() { | ||||||
| 1733 | assert(!IsPromiseDependentType &&(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1734, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1734 | "cannot make statement while the promise type is dependent")(static_cast <bool> (!IsPromiseDependentType && "cannot make statement while the promise type is dependent") ? void (0) : __assert_fail ("!IsPromiseDependentType && \"cannot make statement while the promise type is dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1734, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1735 | assert(this->ReturnValue && "ReturnValue must be already formed")(static_cast <bool> (this->ReturnValue && "ReturnValue must be already formed" ) ? void (0) : __assert_fail ("this->ReturnValue && \"ReturnValue must be already formed\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1735, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1736 | |||||||
| 1737 | QualType const GroType = this->ReturnValue->getType(); | ||||||
| 1738 | assert(!GroType->isDependentType() &&(static_cast <bool> (!GroType->isDependentType() && "get_return_object type must no longer be dependent") ? void (0) : __assert_fail ("!GroType->isDependentType() && \"get_return_object type must no longer be dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1739, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1739 | "get_return_object type must no longer be dependent")(static_cast <bool> (!GroType->isDependentType() && "get_return_object type must no longer be dependent") ? void (0) : __assert_fail ("!GroType->isDependentType() && \"get_return_object type must no longer be dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1739, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1740 | |||||||
| 1741 | QualType const FnRetType = FD.getReturnType(); | ||||||
| 1742 | assert(!FnRetType->isDependentType() &&(static_cast <bool> (!FnRetType->isDependentType() && "get_return_object type must no longer be dependent") ? void (0) : __assert_fail ("!FnRetType->isDependentType() && \"get_return_object type must no longer be dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1743, __extension__ __PRETTY_FUNCTION__ )) | ||||||
| 1743 | "get_return_object type must no longer be dependent")(static_cast <bool> (!FnRetType->isDependentType() && "get_return_object type must no longer be dependent") ? void (0) : __assert_fail ("!FnRetType->isDependentType() && \"get_return_object type must no longer be dependent\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1743, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1744 | |||||||
| 1745 | // The call to get_return_object is sequenced before the call to | ||||||
| 1746 | // initial_suspend and is invoked at most once, but there are caveats | ||||||
| 1747 | // regarding on whether the prvalue result object may be initialized | ||||||
| 1748 | // directly/eager or delayed, depending on the types involved. | ||||||
| 1749 | // | ||||||
| 1750 | // More info at https://github.com/cplusplus/papers/issues/1414 | ||||||
| 1751 | bool GroMatchesRetType = S.getASTContext().hasSameType(GroType, FnRetType); | ||||||
| 1752 | |||||||
| 1753 | if (FnRetType->isVoidType()) { | ||||||
| 1754 | ExprResult Res = | ||||||
| 1755 | S.ActOnFinishFullExpr(this->ReturnValue, Loc, /*DiscardedValue*/ false); | ||||||
| 1756 | if (Res.isInvalid()) | ||||||
| 1757 | return false; | ||||||
| 1758 | |||||||
| 1759 | if (!GroMatchesRetType) | ||||||
| 1760 | this->ResultDecl = Res.get(); | ||||||
| 1761 | return true; | ||||||
| 1762 | } | ||||||
| 1763 | |||||||
| 1764 | if (GroType->isVoidType()) { | ||||||
| 1765 | // Trigger a nice error message. | ||||||
| 1766 | InitializedEntity Entity = | ||||||
| 1767 | InitializedEntity::InitializeResult(Loc, FnRetType); | ||||||
| 1768 | S.PerformCopyInitialization(Entity, SourceLocation(), ReturnValue); | ||||||
| 1769 | noteMemberDeclaredHere(S, ReturnValue, Fn); | ||||||
| 1770 | return false; | ||||||
| 1771 | } | ||||||
| 1772 | |||||||
| 1773 | StmtResult ReturnStmt; | ||||||
| 1774 | clang::VarDecl *GroDecl = nullptr; | ||||||
| 1775 | if (GroMatchesRetType) { | ||||||
| 1776 | ReturnStmt = S.BuildReturnStmt(Loc, ReturnValue); | ||||||
| 1777 | } else { | ||||||
| 1778 | GroDecl = VarDecl::Create( | ||||||
| 1779 | S.Context, &FD, FD.getLocation(), FD.getLocation(), | ||||||
| 1780 | &S.PP.getIdentifierTable().get("__coro_gro"), GroType, | ||||||
| 1781 | S.Context.getTrivialTypeSourceInfo(GroType, Loc), SC_None); | ||||||
| 1782 | GroDecl->setImplicit(); | ||||||
| 1783 | |||||||
| 1784 | S.CheckVariableDeclarationType(GroDecl); | ||||||
| 1785 | if (GroDecl->isInvalidDecl()) | ||||||
| 1786 | return false; | ||||||
| 1787 | |||||||
| 1788 | InitializedEntity Entity = InitializedEntity::InitializeVariable(GroDecl); | ||||||
| 1789 | ExprResult Res = | ||||||
| 1790 | S.PerformCopyInitialization(Entity, SourceLocation(), ReturnValue); | ||||||
| 1791 | if (Res.isInvalid()) | ||||||
| 1792 | return false; | ||||||
| 1793 | |||||||
| 1794 | Res = S.ActOnFinishFullExpr(Res.get(), /*DiscardedValue*/ false); | ||||||
| 1795 | if (Res.isInvalid()) | ||||||
| 1796 | return false; | ||||||
| 1797 | |||||||
| 1798 | S.AddInitializerToDecl(GroDecl, Res.get(), | ||||||
| 1799 | /*DirectInit=*/false); | ||||||
| 1800 | |||||||
| 1801 | S.FinalizeDeclaration(GroDecl); | ||||||
| 1802 | |||||||
| 1803 | // Form a declaration statement for the return declaration, so that AST | ||||||
| 1804 | // visitors can more easily find it. | ||||||
| 1805 | StmtResult GroDeclStmt = | ||||||
| 1806 | S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(GroDecl), Loc, Loc); | ||||||
| 1807 | if (GroDeclStmt.isInvalid()) | ||||||
| 1808 | return false; | ||||||
| 1809 | |||||||
| 1810 | this->ResultDecl = GroDeclStmt.get(); | ||||||
| 1811 | |||||||
| 1812 | ExprResult declRef = S.BuildDeclRefExpr(GroDecl, GroType, VK_LValue, Loc); | ||||||
| 1813 | if (declRef.isInvalid()) | ||||||
| 1814 | return false; | ||||||
| 1815 | |||||||
| 1816 | ReturnStmt = S.BuildReturnStmt(Loc, declRef.get()); | ||||||
| 1817 | } | ||||||
| 1818 | |||||||
| 1819 | if (ReturnStmt.isInvalid()) { | ||||||
| 1820 | noteMemberDeclaredHere(S, ReturnValue, Fn); | ||||||
| 1821 | return false; | ||||||
| 1822 | } | ||||||
| 1823 | |||||||
| 1824 | if (!GroMatchesRetType && | ||||||
| 1825 | cast<clang::ReturnStmt>(ReturnStmt.get())->getNRVOCandidate() == GroDecl) | ||||||
| 1826 | GroDecl->setNRVOVariable(true); | ||||||
| 1827 | |||||||
| 1828 | this->ReturnStmt = ReturnStmt.get(); | ||||||
| 1829 | return true; | ||||||
| 1830 | } | ||||||
| 1831 | |||||||
| 1832 | // Create a static_cast\<T&&>(expr). | ||||||
| 1833 | static Expr *castForMoving(Sema &S, Expr *E, QualType T = QualType()) { | ||||||
| 1834 | if (T.isNull()) | ||||||
| 1835 | T = E->getType(); | ||||||
| 1836 | QualType TargetType = S.BuildReferenceType( | ||||||
| 1837 | T, /*SpelledAsLValue*/ false, SourceLocation(), DeclarationName()); | ||||||
| 1838 | SourceLocation ExprLoc = E->getBeginLoc(); | ||||||
| 1839 | TypeSourceInfo *TargetLoc = | ||||||
| 1840 | S.Context.getTrivialTypeSourceInfo(TargetType, ExprLoc); | ||||||
| 1841 | |||||||
| 1842 | return S | ||||||
| 1843 | .BuildCXXNamedCast(ExprLoc, tok::kw_static_cast, TargetLoc, E, | ||||||
| 1844 | SourceRange(ExprLoc, ExprLoc), E->getSourceRange()) | ||||||
| 1845 | .get(); | ||||||
| 1846 | } | ||||||
| 1847 | |||||||
| 1848 | /// Build a variable declaration for move parameter. | ||||||
| 1849 | static VarDecl *buildVarDecl(Sema &S, SourceLocation Loc, QualType Type, | ||||||
| 1850 | IdentifierInfo *II) { | ||||||
| 1851 | TypeSourceInfo *TInfo = S.Context.getTrivialTypeSourceInfo(Type, Loc); | ||||||
| 1852 | VarDecl *Decl = VarDecl::Create(S.Context, S.CurContext, Loc, Loc, II, Type, | ||||||
| 1853 | TInfo, SC_None); | ||||||
| 1854 | Decl->setImplicit(); | ||||||
| 1855 | return Decl; | ||||||
| 1856 | } | ||||||
| 1857 | |||||||
| 1858 | // Build statements that move coroutine function parameters to the coroutine | ||||||
| 1859 | // frame, and store them on the function scope info. | ||||||
| 1860 | bool Sema::buildCoroutineParameterMoves(SourceLocation Loc) { | ||||||
| 1861 | assert(isa<FunctionDecl>(CurContext) && "not in a function scope")(static_cast <bool> (isa<FunctionDecl>(CurContext ) && "not in a function scope") ? void (0) : __assert_fail ("isa<FunctionDecl>(CurContext) && \"not in a function scope\"" , "clang/lib/Sema/SemaCoroutine.cpp", 1861, __extension__ __PRETTY_FUNCTION__ )); | ||||||
| 1862 | auto *FD = cast<FunctionDecl>(CurContext); | ||||||
| 1863 | |||||||
| 1864 | auto *ScopeInfo = getCurFunction(); | ||||||
| 1865 | if (!ScopeInfo->CoroutineParameterMoves.empty()) | ||||||
| 1866 | return false; | ||||||
| 1867 | |||||||
| 1868 | // [dcl.fct.def.coroutine]p13 | ||||||
| 1869 | // When a coroutine is invoked, after initializing its parameters | ||||||
| 1870 | // ([expr.call]), a copy is created for each coroutine parameter. For a | ||||||
| 1871 | // parameter of type cv T, the copy is a variable of type cv T with | ||||||
| 1872 | // automatic storage duration that is direct-initialized from an xvalue of | ||||||
| 1873 | // type T referring to the parameter. | ||||||
| 1874 | for (auto *PD : FD->parameters()) { | ||||||
| 1875 | if (PD->getType()->isDependentType()) | ||||||
| 1876 | continue; | ||||||
| 1877 | |||||||
| 1878 | ExprResult PDRefExpr = | ||||||
| 1879 | BuildDeclRefExpr(PD, PD->getType().getNonReferenceType(), | ||||||
| 1880 | ExprValueKind::VK_LValue, Loc); // FIXME: scope? | ||||||
| 1881 | if (PDRefExpr.isInvalid()) | ||||||
| 1882 | return false; | ||||||
| 1883 | |||||||
| 1884 | Expr *CExpr = nullptr; | ||||||
| 1885 | if (PD->getType()->getAsCXXRecordDecl() || | ||||||
| 1886 | PD->getType()->isRValueReferenceType()) | ||||||
| 1887 | CExpr = castForMoving(*this, PDRefExpr.get()); | ||||||
| 1888 | else | ||||||
| 1889 | CExpr = PDRefExpr.get(); | ||||||
| 1890 | // [dcl.fct.def.coroutine]p13 | ||||||
| 1891 | // The initialization and destruction of each parameter copy occurs in the | ||||||
| 1892 | // context of the called coroutine. | ||||||
| 1893 | auto *D = buildVarDecl(*this, Loc, PD->getType(), PD->getIdentifier()); | ||||||
| 1894 | AddInitializerToDecl(D, CExpr, /*DirectInit=*/true); | ||||||
| 1895 | |||||||
| 1896 | // Convert decl to a statement. | ||||||
| 1897 | StmtResult Stmt = ActOnDeclStmt(ConvertDeclToDeclGroup(D), Loc, Loc); | ||||||
| 1898 | if (Stmt.isInvalid()) | ||||||
| 1899 | return false; | ||||||
| 1900 | |||||||
| 1901 | ScopeInfo->CoroutineParameterMoves.insert(std::make_pair(PD, Stmt.get())); | ||||||
| 1902 | } | ||||||
| 1903 | return true; | ||||||
| 1904 | } | ||||||
| 1905 | |||||||
| 1906 | StmtResult Sema::BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) { | ||||||
| 1907 | CoroutineBodyStmt *Res = CoroutineBodyStmt::Create(Context, Args); | ||||||
| 1908 | if (!Res) | ||||||
| 1909 | return StmtError(); | ||||||
| 1910 | return Res; | ||||||
| 1911 | } | ||||||
| 1912 | |||||||
| 1913 | ClassTemplateDecl *Sema::lookupCoroutineTraits(SourceLocation KwLoc, | ||||||
| 1914 | SourceLocation FuncLoc) { | ||||||
| 1915 | if (StdCoroutineTraitsCache) | ||||||
| 1916 | return StdCoroutineTraitsCache; | ||||||
| 1917 | |||||||
| 1918 | IdentifierInfo const &TraitIdent = | ||||||
| 1919 | PP.getIdentifierTable().get("coroutine_traits"); | ||||||
| 1920 | |||||||
| 1921 | NamespaceDecl *StdSpace = getStdNamespace(); | ||||||
| 1922 | LookupResult Result(*this, &TraitIdent, FuncLoc, LookupOrdinaryName); | ||||||
| 1923 | bool Found = StdSpace && LookupQualifiedName(Result, StdSpace); | ||||||
| 1924 | |||||||
| 1925 | if (!Found) { | ||||||
| 1926 | // The goggles, we found nothing! | ||||||
| 1927 | Diag(KwLoc, diag::err_implied_coroutine_type_not_found) | ||||||
| 1928 | << "std::coroutine_traits"; | ||||||
| 1929 | return nullptr; | ||||||
| 1930 | } | ||||||
| 1931 | |||||||
| 1932 | // coroutine_traits is required to be a class template. | ||||||
| 1933 | StdCoroutineTraitsCache = Result.getAsSingle<ClassTemplateDecl>(); | ||||||
| 1934 | if (!StdCoroutineTraitsCache) { | ||||||
| 1935 | Result.suppressDiagnostics(); | ||||||
| 1936 | NamedDecl *Found = *Result.begin(); | ||||||
| 1937 | Diag(Found->getLocation(), diag::err_malformed_std_coroutine_traits); | ||||||
| 1938 | return nullptr; | ||||||
| 1939 | } | ||||||
| 1940 | |||||||
| 1941 | return StdCoroutineTraitsCache; | ||||||
| 1942 | } |
| 1 | //===--- Sema.h - Semantic Analysis & AST Building --------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines the Sema class, which performs semantic analysis and |
| 10 | // builds ASTs. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CLANG_SEMA_SEMA_H |
| 15 | #define LLVM_CLANG_SEMA_SEMA_H |
| 16 | |
| 17 | #include "clang/AST/ASTConcept.h" |
| 18 | #include "clang/AST/ASTFwd.h" |
| 19 | #include "clang/AST/Attr.h" |
| 20 | #include "clang/AST/Availability.h" |
| 21 | #include "clang/AST/ComparisonCategories.h" |
| 22 | #include "clang/AST/DeclTemplate.h" |
| 23 | #include "clang/AST/DeclarationName.h" |
| 24 | #include "clang/AST/Expr.h" |
| 25 | #include "clang/AST/ExprCXX.h" |
| 26 | #include "clang/AST/ExprConcepts.h" |
| 27 | #include "clang/AST/ExprObjC.h" |
| 28 | #include "clang/AST/ExprOpenMP.h" |
| 29 | #include "clang/AST/ExternalASTSource.h" |
| 30 | #include "clang/AST/LocInfoType.h" |
| 31 | #include "clang/AST/MangleNumberingContext.h" |
| 32 | #include "clang/AST/NSAPI.h" |
| 33 | #include "clang/AST/PrettyPrinter.h" |
| 34 | #include "clang/AST/StmtCXX.h" |
| 35 | #include "clang/AST/StmtOpenMP.h" |
| 36 | #include "clang/AST/TypeLoc.h" |
| 37 | #include "clang/AST/TypeOrdering.h" |
| 38 | #include "clang/Basic/BitmaskEnum.h" |
| 39 | #include "clang/Basic/Builtins.h" |
| 40 | #include "clang/Basic/DarwinSDKInfo.h" |
| 41 | #include "clang/Basic/ExpressionTraits.h" |
| 42 | #include "clang/Basic/Module.h" |
| 43 | #include "clang/Basic/OpenCLOptions.h" |
| 44 | #include "clang/Basic/OpenMPKinds.h" |
| 45 | #include "clang/Basic/PragmaKinds.h" |
| 46 | #include "clang/Basic/Specifiers.h" |
| 47 | #include "clang/Basic/TemplateKinds.h" |
| 48 | #include "clang/Basic/TypeTraits.h" |
| 49 | #include "clang/Sema/AnalysisBasedWarnings.h" |
| 50 | #include "clang/Sema/CleanupInfo.h" |
| 51 | #include "clang/Sema/DeclSpec.h" |
| 52 | #include "clang/Sema/ExternalSemaSource.h" |
| 53 | #include "clang/Sema/IdentifierResolver.h" |
| 54 | #include "clang/Sema/ObjCMethodList.h" |
| 55 | #include "clang/Sema/Ownership.h" |
| 56 | #include "clang/Sema/Scope.h" |
| 57 | #include "clang/Sema/SemaConcept.h" |
| 58 | #include "clang/Sema/TypoCorrection.h" |
| 59 | #include "clang/Sema/Weak.h" |
| 60 | #include "llvm/ADT/ArrayRef.h" |
| 61 | #include "llvm/ADT/SetVector.h" |
| 62 | #include "llvm/ADT/SmallBitVector.h" |
| 63 | #include "llvm/ADT/SmallPtrSet.h" |
| 64 | #include "llvm/ADT/SmallSet.h" |
| 65 | #include "llvm/ADT/SmallVector.h" |
| 66 | #include "llvm/ADT/TinyPtrVector.h" |
| 67 | #include "llvm/Frontend/OpenMP/OMPConstants.h" |
| 68 | #include <deque> |
| 69 | #include <memory> |
| 70 | #include <optional> |
| 71 | #include <string> |
| 72 | #include <tuple> |
| 73 | #include <vector> |
| 74 | |
| 75 | namespace llvm { |
| 76 | class APSInt; |
| 77 | template <typename ValueT, typename ValueInfoT> class DenseSet; |
| 78 | class SmallBitVector; |
| 79 | struct InlineAsmIdentifierInfo; |
| 80 | } |
| 81 | |
| 82 | namespace clang { |
| 83 | class ADLResult; |
| 84 | class ASTConsumer; |
| 85 | class ASTContext; |
| 86 | class ASTMutationListener; |
| 87 | class ASTReader; |
| 88 | class ASTWriter; |
| 89 | class ArrayType; |
| 90 | class ParsedAttr; |
| 91 | class BindingDecl; |
| 92 | class BlockDecl; |
| 93 | class CapturedDecl; |
| 94 | class CXXBasePath; |
| 95 | class CXXBasePaths; |
| 96 | class CXXBindTemporaryExpr; |
| 97 | typedef SmallVector<CXXBaseSpecifier*, 4> CXXCastPath; |
| 98 | class CXXConstructorDecl; |
| 99 | class CXXConversionDecl; |
| 100 | class CXXDeleteExpr; |
| 101 | class CXXDestructorDecl; |
| 102 | class CXXFieldCollector; |
| 103 | class CXXMemberCallExpr; |
| 104 | class CXXMethodDecl; |
| 105 | class CXXScopeSpec; |
| 106 | class CXXTemporary; |
| 107 | class CXXTryStmt; |
| 108 | class CallExpr; |
| 109 | class ClassTemplateDecl; |
| 110 | class ClassTemplatePartialSpecializationDecl; |
| 111 | class ClassTemplateSpecializationDecl; |
| 112 | class VarTemplatePartialSpecializationDecl; |
| 113 | class CodeCompleteConsumer; |
| 114 | class CodeCompletionAllocator; |
| 115 | class CodeCompletionTUInfo; |
| 116 | class CodeCompletionResult; |
| 117 | class CoroutineBodyStmt; |
| 118 | class Decl; |
| 119 | class DeclAccessPair; |
| 120 | class DeclContext; |
| 121 | class DeclRefExpr; |
| 122 | class DeclaratorDecl; |
| 123 | class DeducedTemplateArgument; |
| 124 | class DependentDiagnostic; |
| 125 | class DesignatedInitExpr; |
| 126 | class Designation; |
| 127 | class EnableIfAttr; |
| 128 | class EnumConstantDecl; |
| 129 | class Expr; |
| 130 | class ExtVectorType; |
| 131 | class FormatAttr; |
| 132 | class FriendDecl; |
| 133 | class FunctionDecl; |
| 134 | class FunctionProtoType; |
| 135 | class FunctionTemplateDecl; |
| 136 | class ImplicitConversionSequence; |
| 137 | typedef MutableArrayRef<ImplicitConversionSequence> ConversionSequenceList; |
| 138 | class InitListExpr; |
| 139 | class InitializationKind; |
| 140 | class InitializationSequence; |
| 141 | class InitializedEntity; |
| 142 | class IntegerLiteral; |
| 143 | class LabelStmt; |
| 144 | class LambdaExpr; |
| 145 | class LangOptions; |
| 146 | class LocalInstantiationScope; |
| 147 | class LookupResult; |
| 148 | class MacroInfo; |
| 149 | typedef ArrayRef<std::pair<IdentifierInfo *, SourceLocation>> ModuleIdPath; |
| 150 | class ModuleLoader; |
| 151 | class MultiLevelTemplateArgumentList; |
| 152 | class NamedDecl; |
| 153 | class ObjCCategoryDecl; |
| 154 | class ObjCCategoryImplDecl; |
| 155 | class ObjCCompatibleAliasDecl; |
| 156 | class ObjCContainerDecl; |
| 157 | class ObjCImplDecl; |
| 158 | class ObjCImplementationDecl; |
| 159 | class ObjCInterfaceDecl; |
| 160 | class ObjCIvarDecl; |
| 161 | template <class T> class ObjCList; |
| 162 | class ObjCMessageExpr; |
| 163 | class ObjCMethodDecl; |
| 164 | class ObjCPropertyDecl; |
| 165 | class ObjCProtocolDecl; |
| 166 | class OMPThreadPrivateDecl; |
| 167 | class OMPRequiresDecl; |
| 168 | class OMPDeclareReductionDecl; |
| 169 | class OMPDeclareSimdDecl; |
| 170 | class OMPClause; |
| 171 | struct OMPVarListLocTy; |
| 172 | struct OverloadCandidate; |
| 173 | enum class OverloadCandidateParamOrder : char; |
| 174 | enum OverloadCandidateRewriteKind : unsigned; |
| 175 | class OverloadCandidateSet; |
| 176 | class OverloadExpr; |
| 177 | class ParenListExpr; |
| 178 | class ParmVarDecl; |
| 179 | class Preprocessor; |
| 180 | class PseudoDestructorTypeStorage; |
| 181 | class PseudoObjectExpr; |
| 182 | class QualType; |
| 183 | class StandardConversionSequence; |
| 184 | class Stmt; |
| 185 | class StringLiteral; |
| 186 | class SwitchStmt; |
| 187 | class TemplateArgument; |
| 188 | class TemplateArgumentList; |
| 189 | class TemplateArgumentLoc; |
| 190 | class TemplateDecl; |
| 191 | class TemplateInstantiationCallback; |
| 192 | class TemplateParameterList; |
| 193 | class TemplatePartialOrderingContext; |
| 194 | class TemplateTemplateParmDecl; |
| 195 | class Token; |
| 196 | class TypeAliasDecl; |
| 197 | class TypedefDecl; |
| 198 | class TypedefNameDecl; |
| 199 | class TypeLoc; |
| 200 | class TypoCorrectionConsumer; |
| 201 | class UnqualifiedId; |
| 202 | class UnresolvedLookupExpr; |
| 203 | class UnresolvedMemberExpr; |
| 204 | class UnresolvedSetImpl; |
| 205 | class UnresolvedSetIterator; |
| 206 | class UsingDecl; |
| 207 | class UsingShadowDecl; |
| 208 | class ValueDecl; |
| 209 | class VarDecl; |
| 210 | class VarTemplateSpecializationDecl; |
| 211 | class VisibilityAttr; |
| 212 | class VisibleDeclConsumer; |
| 213 | class IndirectFieldDecl; |
| 214 | struct DeductionFailureInfo; |
| 215 | class TemplateSpecCandidateSet; |
| 216 | |
| 217 | namespace sema { |
| 218 | class AccessedEntity; |
| 219 | class BlockScopeInfo; |
| 220 | class Capture; |
| 221 | class CapturedRegionScopeInfo; |
| 222 | class CapturingScopeInfo; |
| 223 | class CompoundScopeInfo; |
| 224 | class DelayedDiagnostic; |
| 225 | class DelayedDiagnosticPool; |
| 226 | class FunctionScopeInfo; |
| 227 | class LambdaScopeInfo; |
| 228 | class PossiblyUnreachableDiag; |
| 229 | class RISCVIntrinsicManager; |
| 230 | class SemaPPCallbacks; |
| 231 | class TemplateDeductionInfo; |
| 232 | } |
| 233 | |
| 234 | namespace threadSafety { |
| 235 | class BeforeSet; |
| 236 | void threadSafetyCleanup(BeforeSet* Cache); |
| 237 | } |
| 238 | |
| 239 | // FIXME: No way to easily map from TemplateTypeParmTypes to |
| 240 | // TemplateTypeParmDecls, so we have this horrible PointerUnion. |
| 241 | typedef std::pair<llvm::PointerUnion<const TemplateTypeParmType *, NamedDecl *>, |
| 242 | SourceLocation> |
| 243 | UnexpandedParameterPack; |
| 244 | |
| 245 | /// Describes whether we've seen any nullability information for the given |
| 246 | /// file. |
| 247 | struct FileNullability { |
| 248 | /// The first pointer declarator (of any pointer kind) in the file that does |
| 249 | /// not have a corresponding nullability annotation. |
| 250 | SourceLocation PointerLoc; |
| 251 | |
| 252 | /// The end location for the first pointer declarator in the file. Used for |
| 253 | /// placing fix-its. |
| 254 | SourceLocation PointerEndLoc; |
| 255 | |
| 256 | /// Which kind of pointer declarator we saw. |
| 257 | uint8_t PointerKind; |
| 258 | |
| 259 | /// Whether we saw any type nullability annotations in the given file. |
| 260 | bool SawTypeNullability = false; |
| 261 | }; |
| 262 | |
| 263 | /// A mapping from file IDs to a record of whether we've seen nullability |
| 264 | /// information in that file. |
| 265 | class FileNullabilityMap { |
| 266 | /// A mapping from file IDs to the nullability information for each file ID. |
| 267 | llvm::DenseMap<FileID, FileNullability> Map; |
| 268 | |
| 269 | /// A single-element cache based on the file ID. |
| 270 | struct { |
| 271 | FileID File; |
| 272 | FileNullability Nullability; |
| 273 | } Cache; |
| 274 | |
| 275 | public: |
| 276 | FileNullability &operator[](FileID file) { |
| 277 | // Check the single-element cache. |
| 278 | if (file == Cache.File) |
| 279 | return Cache.Nullability; |
| 280 | |
| 281 | // It's not in the single-element cache; flush the cache if we have one. |
| 282 | if (!Cache.File.isInvalid()) { |
| 283 | Map[Cache.File] = Cache.Nullability; |
| 284 | } |
| 285 | |
| 286 | // Pull this entry into the cache. |
| 287 | Cache.File = file; |
| 288 | Cache.Nullability = Map[file]; |
| 289 | return Cache.Nullability; |
| 290 | } |
| 291 | }; |
| 292 | |
| 293 | /// Tracks expected type during expression parsing, for use in code completion. |
| 294 | /// The type is tied to a particular token, all functions that update or consume |
| 295 | /// the type take a start location of the token they are looking at as a |
| 296 | /// parameter. This avoids updating the type on hot paths in the parser. |
| 297 | class PreferredTypeBuilder { |
| 298 | public: |
| 299 | PreferredTypeBuilder(bool Enabled) : Enabled(Enabled) {} |
| 300 | |
| 301 | void enterCondition(Sema &S, SourceLocation Tok); |
| 302 | void enterReturn(Sema &S, SourceLocation Tok); |
| 303 | void enterVariableInit(SourceLocation Tok, Decl *D); |
| 304 | /// Handles e.g. BaseType{ .D = Tok... |
| 305 | void enterDesignatedInitializer(SourceLocation Tok, QualType BaseType, |
| 306 | const Designation &D); |
| 307 | /// Computing a type for the function argument may require running |
| 308 | /// overloading, so we postpone its computation until it is actually needed. |
| 309 | /// |
| 310 | /// Clients should be very careful when using this function, as it stores a |
| 311 | /// function_ref, clients should make sure all calls to get() with the same |
| 312 | /// location happen while function_ref is alive. |
| 313 | /// |
| 314 | /// The callback should also emit signature help as a side-effect, but only |
| 315 | /// if the completion point has been reached. |
| 316 | void enterFunctionArgument(SourceLocation Tok, |
| 317 | llvm::function_ref<QualType()> ComputeType); |
| 318 | |
| 319 | void enterParenExpr(SourceLocation Tok, SourceLocation LParLoc); |
| 320 | void enterUnary(Sema &S, SourceLocation Tok, tok::TokenKind OpKind, |
| 321 | SourceLocation OpLoc); |
| 322 | void enterBinary(Sema &S, SourceLocation Tok, Expr *LHS, tok::TokenKind Op); |
| 323 | void enterMemAccess(Sema &S, SourceLocation Tok, Expr *Base); |
| 324 | void enterSubscript(Sema &S, SourceLocation Tok, Expr *LHS); |
| 325 | /// Handles all type casts, including C-style cast, C++ casts, etc. |
| 326 | void enterTypeCast(SourceLocation Tok, QualType CastType); |
| 327 | |
| 328 | /// Get the expected type associated with this location, if any. |
| 329 | /// |
| 330 | /// If the location is a function argument, determining the expected type |
| 331 | /// involves considering all function overloads and the arguments so far. |
| 332 | /// In this case, signature help for these function overloads will be reported |
| 333 | /// as a side-effect (only if the completion point has been reached). |
| 334 | QualType get(SourceLocation Tok) const { |
| 335 | if (!Enabled || Tok != ExpectedLoc) |
| 336 | return QualType(); |
| 337 | if (!Type.isNull()) |
| 338 | return Type; |
| 339 | if (ComputeType) |
| 340 | return ComputeType(); |
| 341 | return QualType(); |
| 342 | } |
| 343 | |
| 344 | private: |
| 345 | bool Enabled; |
| 346 | /// Start position of a token for which we store expected type. |
| 347 | SourceLocation ExpectedLoc; |
| 348 | /// Expected type for a token starting at ExpectedLoc. |
| 349 | QualType Type; |
| 350 | /// A function to compute expected type at ExpectedLoc. It is only considered |
| 351 | /// if Type is null. |
| 352 | llvm::function_ref<QualType()> ComputeType; |
| 353 | }; |
| 354 | |
| 355 | /// Sema - This implements semantic analysis and AST building for C. |
| 356 | class Sema final { |
| 357 | Sema(const Sema &) = delete; |
| 358 | void operator=(const Sema &) = delete; |
| 359 | |
| 360 | ///Source of additional semantic information. |
| 361 | IntrusiveRefCntPtr<ExternalSemaSource> ExternalSource; |
| 362 | |
| 363 | static bool mightHaveNonExternalLinkage(const DeclaratorDecl *FD); |
| 364 | |
| 365 | /// Determine whether two declarations should be linked together, given that |
| 366 | /// the old declaration might not be visible and the new declaration might |
| 367 | /// not have external linkage. |
| 368 | bool shouldLinkPossiblyHiddenDecl(const NamedDecl *Old, |
| 369 | const NamedDecl *New) { |
| 370 | if (isVisible(Old)) |
| 371 | return true; |
| 372 | // See comment in below overload for why it's safe to compute the linkage |
| 373 | // of the new declaration here. |
| 374 | if (New->isExternallyDeclarable()) { |
| 375 | assert(Old->isExternallyDeclarable() &&(static_cast <bool> (Old->isExternallyDeclarable() && "should not have found a non-externally-declarable previous decl" ) ? void (0) : __assert_fail ("Old->isExternallyDeclarable() && \"should not have found a non-externally-declarable previous decl\"" , "clang/include/clang/Sema/Sema.h", 376, __extension__ __PRETTY_FUNCTION__ )) |
| 376 | "should not have found a non-externally-declarable previous decl")(static_cast <bool> (Old->isExternallyDeclarable() && "should not have found a non-externally-declarable previous decl" ) ? void (0) : __assert_fail ("Old->isExternallyDeclarable() && \"should not have found a non-externally-declarable previous decl\"" , "clang/include/clang/Sema/Sema.h", 376, __extension__ __PRETTY_FUNCTION__ )); |
| 377 | return true; |
| 378 | } |
| 379 | return false; |
| 380 | } |
| 381 | bool shouldLinkPossiblyHiddenDecl(LookupResult &Old, const NamedDecl *New); |
| 382 | |
| 383 | void setupImplicitSpecialMemberType(CXXMethodDecl *SpecialMem, |
| 384 | QualType ResultTy, |
| 385 | ArrayRef<QualType> Args); |
| 386 | |
| 387 | public: |
| 388 | /// The maximum alignment, same as in llvm::Value. We duplicate them here |
| 389 | /// because that allows us not to duplicate the constants in clang code, |
| 390 | /// which we must to since we can't directly use the llvm constants. |
| 391 | /// The value is verified against llvm here: lib/CodeGen/CGDecl.cpp |
| 392 | /// |
| 393 | /// This is the greatest alignment value supported by load, store, and alloca |
| 394 | /// instructions, and global values. |
| 395 | static const unsigned MaxAlignmentExponent = 32; |
| 396 | static const uint64_t MaximumAlignment = 1ull << MaxAlignmentExponent; |
| 397 | |
| 398 | typedef OpaquePtr<DeclGroupRef> DeclGroupPtrTy; |
| 399 | typedef OpaquePtr<TemplateName> TemplateTy; |
| 400 | typedef OpaquePtr<QualType> TypeTy; |
| 401 | |
| 402 | OpenCLOptions OpenCLFeatures; |
| 403 | FPOptions CurFPFeatures; |
| 404 | |
| 405 | const LangOptions &LangOpts; |
| 406 | Preprocessor &PP; |
| 407 | ASTContext &Context; |
| 408 | ASTConsumer &Consumer; |
| 409 | DiagnosticsEngine &Diags; |
| 410 | SourceManager &SourceMgr; |
| 411 | |
| 412 | /// Flag indicating whether or not to collect detailed statistics. |
| 413 | bool CollectStats; |
| 414 | |
| 415 | /// Code-completion consumer. |
| 416 | CodeCompleteConsumer *CodeCompleter; |
| 417 | |
| 418 | /// CurContext - This is the current declaration context of parsing. |
| 419 | DeclContext *CurContext; |
| 420 | |
| 421 | /// Generally null except when we temporarily switch decl contexts, |
| 422 | /// like in \see ActOnObjCTemporaryExitContainerContext. |
| 423 | DeclContext *OriginalLexicalContext; |
| 424 | |
| 425 | /// VAListTagName - The declaration name corresponding to __va_list_tag. |
| 426 | /// This is used as part of a hack to omit that class from ADL results. |
| 427 | DeclarationName VAListTagName; |
| 428 | |
| 429 | bool MSStructPragmaOn; // True when \#pragma ms_struct on |
| 430 | |
| 431 | /// Controls member pointer representation format under the MS ABI. |
| 432 | LangOptions::PragmaMSPointersToMembersKind |
| 433 | MSPointerToMemberRepresentationMethod; |
| 434 | |
| 435 | /// Stack of active SEH __finally scopes. Can be empty. |
| 436 | SmallVector<Scope*, 2> CurrentSEHFinally; |
| 437 | |
| 438 | /// Source location for newly created implicit MSInheritanceAttrs |
| 439 | SourceLocation ImplicitMSInheritanceAttrLoc; |
| 440 | |
| 441 | /// Holds TypoExprs that are created from `createDelayedTypo`. This is used by |
| 442 | /// `TransformTypos` in order to keep track of any TypoExprs that are created |
| 443 | /// recursively during typo correction and wipe them away if the correction |
| 444 | /// fails. |
| 445 | llvm::SmallVector<TypoExpr *, 2> TypoExprs; |
| 446 | |
| 447 | /// pragma clang section kind |
| 448 | enum PragmaClangSectionKind { |
| 449 | PCSK_Invalid = 0, |
| 450 | PCSK_BSS = 1, |
| 451 | PCSK_Data = 2, |
| 452 | PCSK_Rodata = 3, |
| 453 | PCSK_Text = 4, |
| 454 | PCSK_Relro = 5 |
| 455 | }; |
| 456 | |
| 457 | enum PragmaClangSectionAction { |
| 458 | PCSA_Set = 0, |
| 459 | PCSA_Clear = 1 |
| 460 | }; |
| 461 | |
| 462 | struct PragmaClangSection { |
| 463 | std::string SectionName; |
| 464 | bool Valid = false; |
| 465 | SourceLocation PragmaLocation; |
| 466 | }; |
| 467 | |
| 468 | PragmaClangSection PragmaClangBSSSection; |
| 469 | PragmaClangSection PragmaClangDataSection; |
| 470 | PragmaClangSection PragmaClangRodataSection; |
| 471 | PragmaClangSection PragmaClangRelroSection; |
| 472 | PragmaClangSection PragmaClangTextSection; |
| 473 | |
| 474 | enum PragmaMsStackAction { |
| 475 | PSK_Reset = 0x0, // #pragma () |
| 476 | PSK_Set = 0x1, // #pragma (value) |
| 477 | PSK_Push = 0x2, // #pragma (push[, id]) |
| 478 | PSK_Pop = 0x4, // #pragma (pop[, id]) |
| 479 | PSK_Show = 0x8, // #pragma (show) -- only for "pack"! |
| 480 | PSK_Push_Set = PSK_Push | PSK_Set, // #pragma (push[, id], value) |
| 481 | PSK_Pop_Set = PSK_Pop | PSK_Set, // #pragma (pop[, id], value) |
| 482 | }; |
| 483 | |
| 484 | struct PragmaPackInfo { |
| 485 | PragmaMsStackAction Action; |
| 486 | StringRef SlotLabel; |
| 487 | Token Alignment; |
| 488 | }; |
| 489 | |
| 490 | // #pragma pack and align. |
| 491 | class AlignPackInfo { |
| 492 | public: |
| 493 | // `Native` represents default align mode, which may vary based on the |
| 494 | // platform. |
| 495 | enum Mode : unsigned char { Native, Natural, Packed, Mac68k }; |
| 496 | |
| 497 | // #pragma pack info constructor |
| 498 | AlignPackInfo(AlignPackInfo::Mode M, unsigned Num, bool IsXL) |
| 499 | : PackAttr(true), AlignMode(M), PackNumber(Num), XLStack(IsXL) { |
| 500 | assert(Num == PackNumber && "The pack number has been truncated.")(static_cast <bool> (Num == PackNumber && "The pack number has been truncated." ) ? void (0) : __assert_fail ("Num == PackNumber && \"The pack number has been truncated.\"" , "clang/include/clang/Sema/Sema.h", 500, __extension__ __PRETTY_FUNCTION__ )); |
| 501 | } |
| 502 | |
| 503 | // #pragma align info constructor |
| 504 | AlignPackInfo(AlignPackInfo::Mode M, bool IsXL) |
| 505 | : PackAttr(false), AlignMode(M), |
| 506 | PackNumber(M == Packed ? 1 : UninitPackVal), XLStack(IsXL) {} |
| 507 | |
| 508 | explicit AlignPackInfo(bool IsXL) : AlignPackInfo(Native, IsXL) {} |
| 509 | |
| 510 | AlignPackInfo() : AlignPackInfo(Native, false) {} |
| 511 | |
| 512 | // When a AlignPackInfo itself cannot be used, this returns an 32-bit |
| 513 | // integer encoding for it. This should only be passed to |
| 514 | // AlignPackInfo::getFromRawEncoding, it should not be inspected directly. |
| 515 | static uint32_t getRawEncoding(const AlignPackInfo &Info) { |
| 516 | std::uint32_t Encoding{}; |
| 517 | if (Info.IsXLStack()) |
| 518 | Encoding |= IsXLMask; |
| 519 | |
| 520 | Encoding |= static_cast<uint32_t>(Info.getAlignMode()) << 1; |
| 521 | |
| 522 | if (Info.IsPackAttr()) |
| 523 | Encoding |= PackAttrMask; |
| 524 | |
| 525 | Encoding |= static_cast<uint32_t>(Info.getPackNumber()) << 4; |
| 526 | |
| 527 | return Encoding; |
| 528 | } |
| 529 | |
| 530 | static AlignPackInfo getFromRawEncoding(unsigned Encoding) { |
| 531 | bool IsXL = static_cast<bool>(Encoding & IsXLMask); |
| 532 | AlignPackInfo::Mode M = |
| 533 | static_cast<AlignPackInfo::Mode>((Encoding & AlignModeMask) >> 1); |
| 534 | int PackNumber = (Encoding & PackNumMask) >> 4; |
| 535 | |
| 536 | if (Encoding & PackAttrMask) |
| 537 | return AlignPackInfo(M, PackNumber, IsXL); |
| 538 | |
| 539 | return AlignPackInfo(M, IsXL); |
| 540 | } |
| 541 | |
| 542 | bool IsPackAttr() const { return PackAttr; } |
| 543 | |
| 544 | bool IsAlignAttr() const { return !PackAttr; } |
| 545 | |
| 546 | Mode getAlignMode() const { return AlignMode; } |
| 547 | |
| 548 | unsigned getPackNumber() const { return PackNumber; } |
| 549 | |
| 550 | bool IsPackSet() const { |
| 551 | // #pragma align, #pragma pack(), and #pragma pack(0) do not set the pack |
| 552 | // attriute on a decl. |
| 553 | return PackNumber != UninitPackVal && PackNumber != 0; |
| 554 | } |
| 555 | |
| 556 | bool IsXLStack() const { return XLStack; } |
| 557 | |
| 558 | bool operator==(const AlignPackInfo &Info) const { |
| 559 | return std::tie(AlignMode, PackNumber, PackAttr, XLStack) == |
| 560 | std::tie(Info.AlignMode, Info.PackNumber, Info.PackAttr, |
| 561 | Info.XLStack); |
| 562 | } |
| 563 | |
| 564 | bool operator!=(const AlignPackInfo &Info) const { |
| 565 | return !(*this == Info); |
| 566 | } |
| 567 | |
| 568 | private: |
| 569 | /// \brief True if this is a pragma pack attribute, |
| 570 | /// not a pragma align attribute. |
| 571 | bool PackAttr; |
| 572 | |
| 573 | /// \brief The alignment mode that is in effect. |
| 574 | Mode AlignMode; |
| 575 | |
| 576 | /// \brief The pack number of the stack. |
| 577 | unsigned char PackNumber; |
| 578 | |
| 579 | /// \brief True if it is a XL #pragma align/pack stack. |
| 580 | bool XLStack; |
| 581 | |
| 582 | /// \brief Uninitialized pack value. |
| 583 | static constexpr unsigned char UninitPackVal = -1; |
| 584 | |
| 585 | // Masks to encode and decode an AlignPackInfo. |
| 586 | static constexpr uint32_t IsXLMask{0x0000'0001}; |
| 587 | static constexpr uint32_t AlignModeMask{0x0000'0006}; |
| 588 | static constexpr uint32_t PackAttrMask{0x00000'0008}; |
| 589 | static constexpr uint32_t PackNumMask{0x0000'01F0}; |
| 590 | }; |
| 591 | |
| 592 | template<typename ValueType> |
| 593 | struct PragmaStack { |
| 594 | struct Slot { |
| 595 | llvm::StringRef StackSlotLabel; |
| 596 | ValueType Value; |
| 597 | SourceLocation PragmaLocation; |
| 598 | SourceLocation PragmaPushLocation; |
| 599 | Slot(llvm::StringRef StackSlotLabel, ValueType Value, |
| 600 | SourceLocation PragmaLocation, SourceLocation PragmaPushLocation) |
| 601 | : StackSlotLabel(StackSlotLabel), Value(Value), |
| 602 | PragmaLocation(PragmaLocation), |
| 603 | PragmaPushLocation(PragmaPushLocation) {} |
| 604 | }; |
| 605 | |
| 606 | void Act(SourceLocation PragmaLocation, PragmaMsStackAction Action, |
| 607 | llvm::StringRef StackSlotLabel, ValueType Value) { |
| 608 | if (Action == PSK_Reset) { |
| 609 | CurrentValue = DefaultValue; |
| 610 | CurrentPragmaLocation = PragmaLocation; |
| 611 | return; |
| 612 | } |
| 613 | if (Action & PSK_Push) |
| 614 | Stack.emplace_back(StackSlotLabel, CurrentValue, CurrentPragmaLocation, |
| 615 | PragmaLocation); |
| 616 | else if (Action & PSK_Pop) { |
| 617 | if (!StackSlotLabel.empty()) { |
| 618 | // If we've got a label, try to find it and jump there. |
| 619 | auto I = llvm::find_if(llvm::reverse(Stack), [&](const Slot &x) { |
| 620 | return x.StackSlotLabel == StackSlotLabel; |
| 621 | }); |
| 622 | // If we found the label so pop from there. |
| 623 | if (I != Stack.rend()) { |
| 624 | CurrentValue = I->Value; |
| 625 | CurrentPragmaLocation = I->PragmaLocation; |
| 626 | Stack.erase(std::prev(I.base()), Stack.end()); |
| 627 | } |
| 628 | } else if (!Stack.empty()) { |
| 629 | // We do not have a label, just pop the last entry. |
| 630 | CurrentValue = Stack.back().Value; |
| 631 | CurrentPragmaLocation = Stack.back().PragmaLocation; |
| 632 | Stack.pop_back(); |
| 633 | } |
| 634 | } |
| 635 | if (Action & PSK_Set) { |
| 636 | CurrentValue = Value; |
| 637 | CurrentPragmaLocation = PragmaLocation; |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | // MSVC seems to add artificial slots to #pragma stacks on entering a C++ |
| 642 | // method body to restore the stacks on exit, so it works like this: |
| 643 | // |
| 644 | // struct S { |
| 645 | // #pragma <name>(push, InternalPragmaSlot, <current_pragma_value>) |
| 646 | // void Method {} |
| 647 | // #pragma <name>(pop, InternalPragmaSlot) |
| 648 | // }; |
| 649 | // |
| 650 | // It works even with #pragma vtordisp, although MSVC doesn't support |
| 651 | // #pragma vtordisp(push [, id], n) |
| 652 | // syntax. |
| 653 | // |
| 654 | // Push / pop a named sentinel slot. |
| 655 | void SentinelAction(PragmaMsStackAction Action, StringRef Label) { |
| 656 | assert((Action == PSK_Push || Action == PSK_Pop) &&(static_cast <bool> ((Action == PSK_Push || Action == PSK_Pop ) && "Can only push / pop #pragma stack sentinels!") ? void (0) : __assert_fail ("(Action == PSK_Push || Action == PSK_Pop) && \"Can only push / pop #pragma stack sentinels!\"" , "clang/include/clang/Sema/Sema.h", 657, __extension__ __PRETTY_FUNCTION__ )) |
| 657 | "Can only push / pop #pragma stack sentinels!")(static_cast <bool> ((Action == PSK_Push || Action == PSK_Pop ) && "Can only push / pop #pragma stack sentinels!") ? void (0) : __assert_fail ("(Action == PSK_Push || Action == PSK_Pop) && \"Can only push / pop #pragma stack sentinels!\"" , "clang/include/clang/Sema/Sema.h", 657, __extension__ __PRETTY_FUNCTION__ )); |
| 658 | Act(CurrentPragmaLocation, Action, Label, CurrentValue); |
| 659 | } |
| 660 | |
| 661 | // Constructors. |
| 662 | explicit PragmaStack(const ValueType &Default) |
| 663 | : DefaultValue(Default), CurrentValue(Default) {} |
| 664 | |
| 665 | bool hasValue() const { return CurrentValue != DefaultValue; } |
| 666 | |
| 667 | SmallVector<Slot, 2> Stack; |
| 668 | ValueType DefaultValue; // Value used for PSK_Reset action. |
| 669 | ValueType CurrentValue; |
| 670 | SourceLocation CurrentPragmaLocation; |
| 671 | }; |
| 672 | // FIXME: We should serialize / deserialize these if they occur in a PCH (but |
| 673 | // we shouldn't do so if they're in a module). |
| 674 | |
| 675 | /// Whether to insert vtordisps prior to virtual bases in the Microsoft |
| 676 | /// C++ ABI. Possible values are 0, 1, and 2, which mean: |
| 677 | /// |
| 678 | /// 0: Suppress all vtordisps |
| 679 | /// 1: Insert vtordisps in the presence of vbase overrides and non-trivial |
| 680 | /// structors |
| 681 | /// 2: Always insert vtordisps to support RTTI on partially constructed |
| 682 | /// objects |
| 683 | PragmaStack<MSVtorDispMode> VtorDispStack; |
| 684 | PragmaStack<AlignPackInfo> AlignPackStack; |
| 685 | // The current #pragma align/pack values and locations at each #include. |
| 686 | struct AlignPackIncludeState { |
| 687 | AlignPackInfo CurrentValue; |
| 688 | SourceLocation CurrentPragmaLocation; |
| 689 | bool HasNonDefaultValue, ShouldWarnOnInclude; |
| 690 | }; |
| 691 | SmallVector<AlignPackIncludeState, 8> AlignPackIncludeStack; |
| 692 | // Segment #pragmas. |
| 693 | PragmaStack<StringLiteral *> DataSegStack; |
| 694 | PragmaStack<StringLiteral *> BSSSegStack; |
| 695 | PragmaStack<StringLiteral *> ConstSegStack; |
| 696 | PragmaStack<StringLiteral *> CodeSegStack; |
| 697 | |
| 698 | // #pragma strict_gs_check. |
| 699 | PragmaStack<bool> StrictGuardStackCheckStack; |
| 700 | |
| 701 | // This stack tracks the current state of Sema.CurFPFeatures. |
| 702 | PragmaStack<FPOptionsOverride> FpPragmaStack; |
| 703 | FPOptionsOverride CurFPFeatureOverrides() { |
| 704 | FPOptionsOverride result; |
| 705 | if (!FpPragmaStack.hasValue()) { |
| 706 | result = FPOptionsOverride(); |
| 707 | } else { |
| 708 | result = FpPragmaStack.CurrentValue; |
| 709 | } |
| 710 | return result; |
| 711 | } |
| 712 | |
| 713 | // RAII object to push / pop sentinel slots for all MS #pragma stacks. |
| 714 | // Actions should be performed only if we enter / exit a C++ method body. |
| 715 | class PragmaStackSentinelRAII { |
| 716 | public: |
| 717 | PragmaStackSentinelRAII(Sema &S, StringRef SlotLabel, bool ShouldAct); |
| 718 | ~PragmaStackSentinelRAII(); |
| 719 | |
| 720 | private: |
| 721 | Sema &S; |
| 722 | StringRef SlotLabel; |
| 723 | bool ShouldAct; |
| 724 | }; |
| 725 | |
| 726 | /// A mapping that describes the nullability we've seen in each header file. |
| 727 | FileNullabilityMap NullabilityMap; |
| 728 | |
| 729 | /// Last section used with #pragma init_seg. |
| 730 | StringLiteral *CurInitSeg; |
| 731 | SourceLocation CurInitSegLoc; |
| 732 | |
| 733 | /// Sections used with #pragma alloc_text. |
| 734 | llvm::StringMap<std::tuple<StringRef, SourceLocation>> FunctionToSectionMap; |
| 735 | |
| 736 | /// VisContext - Manages the stack for \#pragma GCC visibility. |
| 737 | void *VisContext; // Really a "PragmaVisStack*" |
| 738 | |
| 739 | /// This an attribute introduced by \#pragma clang attribute. |
| 740 | struct PragmaAttributeEntry { |
| 741 | SourceLocation Loc; |
| 742 | ParsedAttr *Attribute; |
| 743 | SmallVector<attr::SubjectMatchRule, 4> MatchRules; |
| 744 | bool IsUsed; |
| 745 | }; |
| 746 | |
| 747 | /// A push'd group of PragmaAttributeEntries. |
| 748 | struct PragmaAttributeGroup { |
| 749 | /// The location of the push attribute. |
| 750 | SourceLocation Loc; |
| 751 | /// The namespace of this push group. |
| 752 | const IdentifierInfo *Namespace; |
| 753 | SmallVector<PragmaAttributeEntry, 2> Entries; |
| 754 | }; |
| 755 | |
| 756 | SmallVector<PragmaAttributeGroup, 2> PragmaAttributeStack; |
| 757 | |
| 758 | /// The declaration that is currently receiving an attribute from the |
| 759 | /// #pragma attribute stack. |
| 760 | const Decl *PragmaAttributeCurrentTargetDecl; |
| 761 | |
| 762 | /// This represents the last location of a "#pragma clang optimize off" |
| 763 | /// directive if such a directive has not been closed by an "on" yet. If |
| 764 | /// optimizations are currently "on", this is set to an invalid location. |
| 765 | SourceLocation OptimizeOffPragmaLocation; |
| 766 | |
| 767 | /// The "on" or "off" argument passed by \#pragma optimize, that denotes |
| 768 | /// whether the optimizations in the list passed to the pragma should be |
| 769 | /// turned off or on. This boolean is true by default because command line |
| 770 | /// options are honored when `#pragma optimize("", on)`. |
| 771 | /// (i.e. `ModifyFnAttributeMSPragmaOptimze()` does nothing) |
| 772 | bool MSPragmaOptimizeIsOn = true; |
| 773 | |
| 774 | /// Set of no-builtin functions listed by \#pragma function. |
| 775 | llvm::SmallSetVector<StringRef, 4> MSFunctionNoBuiltins; |
| 776 | |
| 777 | /// Flag indicating if Sema is building a recovery call expression. |
| 778 | /// |
| 779 | /// This flag is used to avoid building recovery call expressions |
| 780 | /// if Sema is already doing so, which would cause infinite recursions. |
| 781 | bool IsBuildingRecoveryCallExpr; |
| 782 | |
| 783 | /// Used to control the generation of ExprWithCleanups. |
| 784 | CleanupInfo Cleanup; |
| 785 | |
| 786 | /// ExprCleanupObjects - This is the stack of objects requiring |
| 787 | /// cleanup that are created by the current full expression. |
| 788 | SmallVector<ExprWithCleanups::CleanupObject, 8> ExprCleanupObjects; |
| 789 | |
| 790 | /// Store a set of either DeclRefExprs or MemberExprs that contain a reference |
| 791 | /// to a variable (constant) that may or may not be odr-used in this Expr, and |
| 792 | /// we won't know until all lvalue-to-rvalue and discarded value conversions |
| 793 | /// have been applied to all subexpressions of the enclosing full expression. |
| 794 | /// This is cleared at the end of each full expression. |
| 795 | using MaybeODRUseExprSet = llvm::SetVector<Expr *, SmallVector<Expr *, 4>, |
| 796 | llvm::SmallPtrSet<Expr *, 4>>; |
| 797 | MaybeODRUseExprSet MaybeODRUseExprs; |
| 798 | |
| 799 | std::unique_ptr<sema::FunctionScopeInfo> CachedFunctionScope; |
| 800 | |
| 801 | /// Stack containing information about each of the nested |
| 802 | /// function, block, and method scopes that are currently active. |
| 803 | SmallVector<sema::FunctionScopeInfo *, 4> FunctionScopes; |
| 804 | |
| 805 | /// The index of the first FunctionScope that corresponds to the current |
| 806 | /// context. |
| 807 | unsigned FunctionScopesStart = 0; |
| 808 | |
| 809 | /// Track the number of currently active capturing scopes. |
| 810 | unsigned CapturingFunctionScopes = 0; |
| 811 | |
| 812 | ArrayRef<sema::FunctionScopeInfo*> getFunctionScopes() const { |
| 813 | return llvm::ArrayRef(FunctionScopes.begin() + FunctionScopesStart, |
| 814 | FunctionScopes.end()); |
| 815 | } |
| 816 | |
| 817 | /// Stack containing information needed when in C++2a an 'auto' is encountered |
| 818 | /// in a function declaration parameter type specifier in order to invent a |
| 819 | /// corresponding template parameter in the enclosing abbreviated function |
| 820 | /// template. This information is also present in LambdaScopeInfo, stored in |
| 821 | /// the FunctionScopes stack. |
| 822 | SmallVector<InventedTemplateParameterInfo, 4> InventedParameterInfos; |
| 823 | |
| 824 | /// The index of the first InventedParameterInfo that refers to the current |
| 825 | /// context. |
| 826 | unsigned InventedParameterInfosStart = 0; |
| 827 | |
| 828 | ArrayRef<InventedTemplateParameterInfo> getInventedParameterInfos() const { |
| 829 | return llvm::ArrayRef(InventedParameterInfos.begin() + |
| 830 | InventedParameterInfosStart, |
| 831 | InventedParameterInfos.end()); |
| 832 | } |
| 833 | |
| 834 | typedef LazyVector<TypedefNameDecl *, ExternalSemaSource, |
| 835 | &ExternalSemaSource::ReadExtVectorDecls, 2, 2> |
| 836 | ExtVectorDeclsType; |
| 837 | |
| 838 | /// ExtVectorDecls - This is a list all the extended vector types. This allows |
| 839 | /// us to associate a raw vector type with one of the ext_vector type names. |
| 840 | /// This is only necessary for issuing pretty diagnostics. |
| 841 | ExtVectorDeclsType ExtVectorDecls; |
| 842 | |
| 843 | /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes. |
| 844 | std::unique_ptr<CXXFieldCollector> FieldCollector; |
| 845 | |
| 846 | typedef llvm::SmallSetVector<const NamedDecl *, 16> NamedDeclSetType; |
| 847 | |
| 848 | /// Set containing all declared private fields that are not used. |
| 849 | NamedDeclSetType UnusedPrivateFields; |
| 850 | |
| 851 | /// Set containing all typedefs that are likely unused. |
| 852 | llvm::SmallSetVector<const TypedefNameDecl *, 4> |
| 853 | UnusedLocalTypedefNameCandidates; |
| 854 | |
| 855 | /// Delete-expressions to be analyzed at the end of translation unit |
| 856 | /// |
| 857 | /// This list contains class members, and locations of delete-expressions |
| 858 | /// that could not be proven as to whether they mismatch with new-expression |
| 859 | /// used in initializer of the field. |
| 860 | typedef std::pair<SourceLocation, bool> DeleteExprLoc; |
| 861 | typedef llvm::SmallVector<DeleteExprLoc, 4> DeleteLocs; |
| 862 | llvm::MapVector<FieldDecl *, DeleteLocs> DeleteExprs; |
| 863 | |
| 864 | typedef llvm::SmallPtrSet<const CXXRecordDecl*, 8> RecordDeclSetTy; |
| 865 | |
| 866 | /// PureVirtualClassDiagSet - a set of class declarations which we have |
| 867 | /// emitted a list of pure virtual functions. Used to prevent emitting the |
| 868 | /// same list more than once. |
| 869 | std::unique_ptr<RecordDeclSetTy> PureVirtualClassDiagSet; |
| 870 | |
| 871 | /// ParsingInitForAutoVars - a set of declarations with auto types for which |
| 872 | /// we are currently parsing the initializer. |
| 873 | llvm::SmallPtrSet<const Decl*, 4> ParsingInitForAutoVars; |
| 874 | |
| 875 | /// Look for a locally scoped extern "C" declaration by the given name. |
| 876 | NamedDecl *findLocallyScopedExternCDecl(DeclarationName Name); |
| 877 | |
| 878 | typedef LazyVector<VarDecl *, ExternalSemaSource, |
| 879 | &ExternalSemaSource::ReadTentativeDefinitions, 2, 2> |
| 880 | TentativeDefinitionsType; |
| 881 | |
| 882 | /// All the tentative definitions encountered in the TU. |
| 883 | TentativeDefinitionsType TentativeDefinitions; |
| 884 | |
| 885 | /// All the external declarations encoutered and used in the TU. |
| 886 | SmallVector<VarDecl *, 4> ExternalDeclarations; |
| 887 | |
| 888 | typedef LazyVector<const DeclaratorDecl *, ExternalSemaSource, |
| 889 | &ExternalSemaSource::ReadUnusedFileScopedDecls, 2, 2> |
| 890 | UnusedFileScopedDeclsType; |
| 891 | |
| 892 | /// The set of file scoped decls seen so far that have not been used |
| 893 | /// and must warn if not used. Only contains the first declaration. |
| 894 | UnusedFileScopedDeclsType UnusedFileScopedDecls; |
| 895 | |
| 896 | typedef LazyVector<CXXConstructorDecl *, ExternalSemaSource, |
| 897 | &ExternalSemaSource::ReadDelegatingConstructors, 2, 2> |
| 898 | DelegatingCtorDeclsType; |
| 899 | |
| 900 | /// All the delegating constructors seen so far in the file, used for |
| 901 | /// cycle detection at the end of the TU. |
| 902 | DelegatingCtorDeclsType DelegatingCtorDecls; |
| 903 | |
| 904 | /// All the overriding functions seen during a class definition |
| 905 | /// that had their exception spec checks delayed, plus the overridden |
| 906 | /// function. |
| 907 | SmallVector<std::pair<const CXXMethodDecl*, const CXXMethodDecl*>, 2> |
| 908 | DelayedOverridingExceptionSpecChecks; |
| 909 | |
| 910 | /// All the function redeclarations seen during a class definition that had |
| 911 | /// their exception spec checks delayed, plus the prior declaration they |
| 912 | /// should be checked against. Except during error recovery, the new decl |
| 913 | /// should always be a friend declaration, as that's the only valid way to |
| 914 | /// redeclare a special member before its class is complete. |
| 915 | SmallVector<std::pair<FunctionDecl*, FunctionDecl*>, 2> |
| 916 | DelayedEquivalentExceptionSpecChecks; |
| 917 | |
| 918 | typedef llvm::MapVector<const FunctionDecl *, |
| 919 | std::unique_ptr<LateParsedTemplate>> |
| 920 | LateParsedTemplateMapT; |
| 921 | LateParsedTemplateMapT LateParsedTemplateMap; |
| 922 | |
| 923 | /// Callback to the parser to parse templated functions when needed. |
| 924 | typedef void LateTemplateParserCB(void *P, LateParsedTemplate &LPT); |
| 925 | typedef void LateTemplateParserCleanupCB(void *P); |
| 926 | LateTemplateParserCB *LateTemplateParser; |
| 927 | LateTemplateParserCleanupCB *LateTemplateParserCleanup; |
| 928 | void *OpaqueParser; |
| 929 | |
| 930 | void SetLateTemplateParser(LateTemplateParserCB *LTP, |
| 931 | LateTemplateParserCleanupCB *LTPCleanup, |
| 932 | void *P) { |
| 933 | LateTemplateParser = LTP; |
| 934 | LateTemplateParserCleanup = LTPCleanup; |
| 935 | OpaqueParser = P; |
| 936 | } |
| 937 | |
| 938 | class DelayedDiagnostics; |
| 939 | |
| 940 | class DelayedDiagnosticsState { |
| 941 | sema::DelayedDiagnosticPool *SavedPool; |
| 942 | friend class Sema::DelayedDiagnostics; |
| 943 | }; |
| 944 | typedef DelayedDiagnosticsState ParsingDeclState; |
| 945 | typedef DelayedDiagnosticsState ProcessingContextState; |
| 946 | |
| 947 | /// A class which encapsulates the logic for delaying diagnostics |
| 948 | /// during parsing and other processing. |
| 949 | class DelayedDiagnostics { |
| 950 | /// The current pool of diagnostics into which delayed |
| 951 | /// diagnostics should go. |
| 952 | sema::DelayedDiagnosticPool *CurPool = nullptr; |
| 953 | |
| 954 | public: |
| 955 | DelayedDiagnostics() = default; |
| 956 | |
| 957 | /// Adds a delayed diagnostic. |
| 958 | void add(const sema::DelayedDiagnostic &diag); // in DelayedDiagnostic.h |
| 959 | |
| 960 | /// Determines whether diagnostics should be delayed. |
| 961 | bool shouldDelayDiagnostics() { return CurPool != nullptr; } |
| 962 | |
| 963 | /// Returns the current delayed-diagnostics pool. |
| 964 | sema::DelayedDiagnosticPool *getCurrentPool() const { |
| 965 | return CurPool; |
| 966 | } |
| 967 | |
| 968 | /// Enter a new scope. Access and deprecation diagnostics will be |
| 969 | /// collected in this pool. |
| 970 | DelayedDiagnosticsState push(sema::DelayedDiagnosticPool &pool) { |
| 971 | DelayedDiagnosticsState state; |
| 972 | state.SavedPool = CurPool; |
| 973 | CurPool = &pool; |
| 974 | return state; |
| 975 | } |
| 976 | |
| 977 | /// Leave a delayed-diagnostic state that was previously pushed. |
| 978 | /// Do not emit any of the diagnostics. This is performed as part |
| 979 | /// of the bookkeeping of popping a pool "properly". |
| 980 | void popWithoutEmitting(DelayedDiagnosticsState state) { |
| 981 | CurPool = state.SavedPool; |
| 982 | } |
| 983 | |
| 984 | /// Enter a new scope where access and deprecation diagnostics are |
| 985 | /// not delayed. |
| 986 | DelayedDiagnosticsState pushUndelayed() { |
| 987 | DelayedDiagnosticsState state; |
| 988 | state.SavedPool = CurPool; |
| 989 | CurPool = nullptr; |
| 990 | return state; |
| 991 | } |
| 992 | |
| 993 | /// Undo a previous pushUndelayed(). |
| 994 | void popUndelayed(DelayedDiagnosticsState state) { |
| 995 | assert(CurPool == nullptr)(static_cast <bool> (CurPool == nullptr) ? void (0) : __assert_fail ("CurPool == nullptr", "clang/include/clang/Sema/Sema.h", 995 , __extension__ __PRETTY_FUNCTION__)); |
| 996 | CurPool = state.SavedPool; |
| 997 | } |
| 998 | } DelayedDiagnostics; |
| 999 | |
| 1000 | /// A RAII object to temporarily push a declaration context. |
| 1001 | class ContextRAII { |
| 1002 | private: |
| 1003 | Sema &S; |
| 1004 | DeclContext *SavedContext; |
| 1005 | ProcessingContextState SavedContextState; |
| 1006 | QualType SavedCXXThisTypeOverride; |
| 1007 | unsigned SavedFunctionScopesStart; |
| 1008 | unsigned SavedInventedParameterInfosStart; |
| 1009 | |
| 1010 | public: |
| 1011 | ContextRAII(Sema &S, DeclContext *ContextToPush, bool NewThisContext = true) |
| 1012 | : S(S), SavedContext(S.CurContext), |
| 1013 | SavedContextState(S.DelayedDiagnostics.pushUndelayed()), |
| 1014 | SavedCXXThisTypeOverride(S.CXXThisTypeOverride), |
| 1015 | SavedFunctionScopesStart(S.FunctionScopesStart), |
| 1016 | SavedInventedParameterInfosStart(S.InventedParameterInfosStart) |
| 1017 | { |
| 1018 | assert(ContextToPush && "pushing null context")(static_cast <bool> (ContextToPush && "pushing null context" ) ? void (0) : __assert_fail ("ContextToPush && \"pushing null context\"" , "clang/include/clang/Sema/Sema.h", 1018, __extension__ __PRETTY_FUNCTION__ )); |
| 1019 | S.CurContext = ContextToPush; |
| 1020 | if (NewThisContext) |
| 1021 | S.CXXThisTypeOverride = QualType(); |
| 1022 | // Any saved FunctionScopes do not refer to this context. |
| 1023 | S.FunctionScopesStart = S.FunctionScopes.size(); |
| 1024 | S.InventedParameterInfosStart = S.InventedParameterInfos.size(); |
| 1025 | } |
| 1026 | |
| 1027 | void pop() { |
| 1028 | if (!SavedContext) return; |
| 1029 | S.CurContext = SavedContext; |
| 1030 | S.DelayedDiagnostics.popUndelayed(SavedContextState); |
| 1031 | S.CXXThisTypeOverride = SavedCXXThisTypeOverride; |
| 1032 | S.FunctionScopesStart = SavedFunctionScopesStart; |
| 1033 | S.InventedParameterInfosStart = SavedInventedParameterInfosStart; |
| 1034 | SavedContext = nullptr; |
| 1035 | } |
| 1036 | |
| 1037 | ~ContextRAII() { |
| 1038 | pop(); |
| 1039 | } |
| 1040 | }; |
| 1041 | |
| 1042 | /// Whether the AST is currently being rebuilt to correct immediate |
| 1043 | /// invocations. Immediate invocation candidates and references to consteval |
| 1044 | /// functions aren't tracked when this is set. |
| 1045 | bool RebuildingImmediateInvocation = false; |
| 1046 | |
| 1047 | /// Used to change context to isConstantEvaluated without pushing a heavy |
| 1048 | /// ExpressionEvaluationContextRecord object. |
| 1049 | bool isConstantEvaluatedOverride; |
| 1050 | |
| 1051 | bool isConstantEvaluated() const { |
| 1052 | return ExprEvalContexts.back().isConstantEvaluated() || |
| 1053 | isConstantEvaluatedOverride; |
| 1054 | } |
| 1055 | |
| 1056 | /// RAII object to handle the state changes required to synthesize |
| 1057 | /// a function body. |
| 1058 | class SynthesizedFunctionScope { |
| 1059 | Sema &S; |
| 1060 | Sema::ContextRAII SavedContext; |
| 1061 | bool PushedCodeSynthesisContext = false; |
| 1062 | |
| 1063 | public: |
| 1064 | SynthesizedFunctionScope(Sema &S, DeclContext *DC) |
| 1065 | : S(S), SavedContext(S, DC) { |
| 1066 | S.PushFunctionScope(); |
| 1067 | S.PushExpressionEvaluationContext( |
| 1068 | Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| 1069 | if (auto *FD = dyn_cast<FunctionDecl>(DC)) |
| 1070 | FD->setWillHaveBody(true); |
| 1071 | else |
| 1072 | assert(isa<ObjCMethodDecl>(DC))(static_cast <bool> (isa<ObjCMethodDecl>(DC)) ? void (0) : __assert_fail ("isa<ObjCMethodDecl>(DC)", "clang/include/clang/Sema/Sema.h" , 1072, __extension__ __PRETTY_FUNCTION__)); |
| 1073 | } |
| 1074 | |
| 1075 | void addContextNote(SourceLocation UseLoc) { |
| 1076 | assert(!PushedCodeSynthesisContext)(static_cast <bool> (!PushedCodeSynthesisContext) ? void (0) : __assert_fail ("!PushedCodeSynthesisContext", "clang/include/clang/Sema/Sema.h" , 1076, __extension__ __PRETTY_FUNCTION__)); |
| 1077 | |
| 1078 | Sema::CodeSynthesisContext Ctx; |
| 1079 | Ctx.Kind = Sema::CodeSynthesisContext::DefiningSynthesizedFunction; |
| 1080 | Ctx.PointOfInstantiation = UseLoc; |
| 1081 | Ctx.Entity = cast<Decl>(S.CurContext); |
| 1082 | S.pushCodeSynthesisContext(Ctx); |
| 1083 | |
| 1084 | PushedCodeSynthesisContext = true; |
| 1085 | } |
| 1086 | |
| 1087 | ~SynthesizedFunctionScope() { |
| 1088 | if (PushedCodeSynthesisContext) |
| 1089 | S.popCodeSynthesisContext(); |
| 1090 | if (auto *FD = dyn_cast<FunctionDecl>(S.CurContext)) |
| 1091 | FD->setWillHaveBody(false); |
| 1092 | S.PopExpressionEvaluationContext(); |
| 1093 | S.PopFunctionScopeInfo(); |
| 1094 | } |
| 1095 | }; |
| 1096 | |
| 1097 | /// WeakUndeclaredIdentifiers - Identifiers contained in \#pragma weak before |
| 1098 | /// declared. Rare. May alias another identifier, declared or undeclared. |
| 1099 | /// |
| 1100 | /// For aliases, the target identifier is used as a key for eventual |
| 1101 | /// processing when the target is declared. For the single-identifier form, |
| 1102 | /// the sole identifier is used as the key. Each entry is a `SetVector` |
| 1103 | /// (ordered by parse order) of aliases (identified by the alias name) in case |
| 1104 | /// of multiple aliases to the same undeclared identifier. |
| 1105 | llvm::MapVector< |
| 1106 | IdentifierInfo *, |
| 1107 | llvm::SetVector< |
| 1108 | WeakInfo, llvm::SmallVector<WeakInfo, 1u>, |
| 1109 | llvm::SmallDenseSet<WeakInfo, 2u, WeakInfo::DenseMapInfoByAliasOnly>>> |
| 1110 | WeakUndeclaredIdentifiers; |
| 1111 | |
| 1112 | /// ExtnameUndeclaredIdentifiers - Identifiers contained in |
| 1113 | /// \#pragma redefine_extname before declared. Used in Solaris system headers |
| 1114 | /// to define functions that occur in multiple standards to call the version |
| 1115 | /// in the currently selected standard. |
| 1116 | llvm::DenseMap<IdentifierInfo*,AsmLabelAttr*> ExtnameUndeclaredIdentifiers; |
| 1117 | |
| 1118 | |
| 1119 | /// Load weak undeclared identifiers from the external source. |
| 1120 | void LoadExternalWeakUndeclaredIdentifiers(); |
| 1121 | |
| 1122 | /// WeakTopLevelDecl - Translation-unit scoped declarations generated by |
| 1123 | /// \#pragma weak during processing of other Decls. |
| 1124 | /// I couldn't figure out a clean way to generate these in-line, so |
| 1125 | /// we store them here and handle separately -- which is a hack. |
| 1126 | /// It would be best to refactor this. |
| 1127 | SmallVector<Decl*,2> WeakTopLevelDecl; |
| 1128 | |
| 1129 | IdentifierResolver IdResolver; |
| 1130 | |
| 1131 | /// Translation Unit Scope - useful to Objective-C actions that need |
| 1132 | /// to lookup file scope declarations in the "ordinary" C decl namespace. |
| 1133 | /// For example, user-defined classes, built-in "id" type, etc. |
| 1134 | Scope *TUScope; |
| 1135 | |
| 1136 | /// The C++ "std" namespace, where the standard library resides. |
| 1137 | LazyDeclPtr StdNamespace; |
| 1138 | |
| 1139 | /// The C++ "std::bad_alloc" class, which is defined by the C++ |
| 1140 | /// standard library. |
| 1141 | LazyDeclPtr StdBadAlloc; |
| 1142 | |
| 1143 | /// The C++ "std::align_val_t" enum class, which is defined by the C++ |
| 1144 | /// standard library. |
| 1145 | LazyDeclPtr StdAlignValT; |
| 1146 | |
| 1147 | /// The C++ "std::initializer_list" template, which is defined in |
| 1148 | /// \<initializer_list>. |
| 1149 | ClassTemplateDecl *StdInitializerList; |
| 1150 | |
| 1151 | /// The C++ "std::coroutine_traits" template, which is defined in |
| 1152 | /// \<coroutine_traits> |
| 1153 | ClassTemplateDecl *StdCoroutineTraitsCache; |
| 1154 | |
| 1155 | /// The C++ "type_info" declaration, which is defined in \<typeinfo>. |
| 1156 | RecordDecl *CXXTypeInfoDecl; |
| 1157 | |
| 1158 | /// The MSVC "_GUID" struct, which is defined in MSVC header files. |
| 1159 | RecordDecl *MSVCGuidDecl; |
| 1160 | |
| 1161 | /// The C++ "std::source_location::__impl" struct, defined in |
| 1162 | /// \<source_location>. |
| 1163 | RecordDecl *StdSourceLocationImplDecl; |
| 1164 | |
| 1165 | /// Caches identifiers/selectors for NSFoundation APIs. |
| 1166 | std::unique_ptr<NSAPI> NSAPIObj; |
| 1167 | |
| 1168 | /// The declaration of the Objective-C NSNumber class. |
| 1169 | ObjCInterfaceDecl *NSNumberDecl; |
| 1170 | |
| 1171 | /// The declaration of the Objective-C NSValue class. |
| 1172 | ObjCInterfaceDecl *NSValueDecl; |
| 1173 | |
| 1174 | /// Pointer to NSNumber type (NSNumber *). |
| 1175 | QualType NSNumberPointer; |
| 1176 | |
| 1177 | /// Pointer to NSValue type (NSValue *). |
| 1178 | QualType NSValuePointer; |
| 1179 | |
| 1180 | /// The Objective-C NSNumber methods used to create NSNumber literals. |
| 1181 | ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; |
| 1182 | |
| 1183 | /// The declaration of the Objective-C NSString class. |
| 1184 | ObjCInterfaceDecl *NSStringDecl; |
| 1185 | |
| 1186 | /// Pointer to NSString type (NSString *). |
| 1187 | QualType NSStringPointer; |
| 1188 | |
| 1189 | /// The declaration of the stringWithUTF8String: method. |
| 1190 | ObjCMethodDecl *StringWithUTF8StringMethod; |
| 1191 | |
| 1192 | /// The declaration of the valueWithBytes:objCType: method. |
| 1193 | ObjCMethodDecl *ValueWithBytesObjCTypeMethod; |
| 1194 | |
| 1195 | /// The declaration of the Objective-C NSArray class. |
| 1196 | ObjCInterfaceDecl *NSArrayDecl; |
| 1197 | |
| 1198 | /// The declaration of the arrayWithObjects:count: method. |
| 1199 | ObjCMethodDecl *ArrayWithObjectsMethod; |
| 1200 | |
| 1201 | /// The declaration of the Objective-C NSDictionary class. |
| 1202 | ObjCInterfaceDecl *NSDictionaryDecl; |
| 1203 | |
| 1204 | /// The declaration of the dictionaryWithObjects:forKeys:count: method. |
| 1205 | ObjCMethodDecl *DictionaryWithObjectsMethod; |
| 1206 | |
| 1207 | /// id<NSCopying> type. |
| 1208 | QualType QIDNSCopying; |
| 1209 | |
| 1210 | /// will hold 'respondsToSelector:' |
| 1211 | Selector RespondsToSelectorSel; |
| 1212 | |
| 1213 | /// A flag to remember whether the implicit forms of operator new and delete |
| 1214 | /// have been declared. |
| 1215 | bool GlobalNewDeleteDeclared; |
| 1216 | |
| 1217 | /// Describes how the expressions currently being parsed are |
| 1218 | /// evaluated at run-time, if at all. |
| 1219 | enum class ExpressionEvaluationContext { |
| 1220 | /// The current expression and its subexpressions occur within an |
| 1221 | /// unevaluated operand (C++11 [expr]p7), such as the subexpression of |
| 1222 | /// \c sizeof, where the type of the expression may be significant but |
| 1223 | /// no code will be generated to evaluate the value of the expression at |
| 1224 | /// run time. |
| 1225 | Unevaluated, |
| 1226 | |
| 1227 | /// The current expression occurs within a braced-init-list within |
| 1228 | /// an unevaluated operand. This is mostly like a regular unevaluated |
| 1229 | /// context, except that we still instantiate constexpr functions that are |
| 1230 | /// referenced here so that we can perform narrowing checks correctly. |
| 1231 | UnevaluatedList, |
| 1232 | |
| 1233 | /// The current expression occurs within a discarded statement. |
| 1234 | /// This behaves largely similarly to an unevaluated operand in preventing |
| 1235 | /// definitions from being required, but not in other ways. |
| 1236 | DiscardedStatement, |
| 1237 | |
| 1238 | /// The current expression occurs within an unevaluated |
| 1239 | /// operand that unconditionally permits abstract references to |
| 1240 | /// fields, such as a SIZE operator in MS-style inline assembly. |
| 1241 | UnevaluatedAbstract, |
| 1242 | |
| 1243 | /// The current context is "potentially evaluated" in C++11 terms, |
| 1244 | /// but the expression is evaluated at compile-time (like the values of |
| 1245 | /// cases in a switch statement). |
| 1246 | ConstantEvaluated, |
| 1247 | |
| 1248 | /// In addition of being constant evaluated, the current expression |
| 1249 | /// occurs in an immediate function context - either a consteval function |
| 1250 | /// or a consteval if function. |
| 1251 | ImmediateFunctionContext, |
| 1252 | |
| 1253 | /// The current expression is potentially evaluated at run time, |
| 1254 | /// which means that code may be generated to evaluate the value of the |
| 1255 | /// expression at run time. |
| 1256 | PotentiallyEvaluated, |
| 1257 | |
| 1258 | /// The current expression is potentially evaluated, but any |
| 1259 | /// declarations referenced inside that expression are only used if |
| 1260 | /// in fact the current expression is used. |
| 1261 | /// |
| 1262 | /// This value is used when parsing default function arguments, for which |
| 1263 | /// we would like to provide diagnostics (e.g., passing non-POD arguments |
| 1264 | /// through varargs) but do not want to mark declarations as "referenced" |
| 1265 | /// until the default argument is used. |
| 1266 | PotentiallyEvaluatedIfUsed |
| 1267 | }; |
| 1268 | |
| 1269 | using ImmediateInvocationCandidate = llvm::PointerIntPair<ConstantExpr *, 1>; |
| 1270 | |
| 1271 | /// Data structure used to record current or nested |
| 1272 | /// expression evaluation contexts. |
| 1273 | struct ExpressionEvaluationContextRecord { |
| 1274 | /// The expression evaluation context. |
| 1275 | ExpressionEvaluationContext Context; |
| 1276 | |
| 1277 | /// Whether the enclosing context needed a cleanup. |
| 1278 | CleanupInfo ParentCleanup; |
| 1279 | |
| 1280 | /// The number of active cleanup objects when we entered |
| 1281 | /// this expression evaluation context. |
| 1282 | unsigned NumCleanupObjects; |
| 1283 | |
| 1284 | /// The number of typos encountered during this expression evaluation |
| 1285 | /// context (i.e. the number of TypoExprs created). |
| 1286 | unsigned NumTypos; |
| 1287 | |
| 1288 | MaybeODRUseExprSet SavedMaybeODRUseExprs; |
| 1289 | |
| 1290 | /// The lambdas that are present within this context, if it |
| 1291 | /// is indeed an unevaluated context. |
| 1292 | SmallVector<LambdaExpr *, 2> Lambdas; |
| 1293 | |
| 1294 | /// The declaration that provides context for lambda expressions |
| 1295 | /// and block literals if the normal declaration context does not |
| 1296 | /// suffice, e.g., in a default function argument. |
| 1297 | Decl *ManglingContextDecl; |
| 1298 | |
| 1299 | /// If we are processing a decltype type, a set of call expressions |
| 1300 | /// for which we have deferred checking the completeness of the return type. |
| 1301 | SmallVector<CallExpr *, 8> DelayedDecltypeCalls; |
| 1302 | |
| 1303 | /// If we are processing a decltype type, a set of temporary binding |
| 1304 | /// expressions for which we have deferred checking the destructor. |
| 1305 | SmallVector<CXXBindTemporaryExpr *, 8> DelayedDecltypeBinds; |
| 1306 | |
| 1307 | llvm::SmallPtrSet<const Expr *, 8> PossibleDerefs; |
| 1308 | |
| 1309 | /// Expressions appearing as the LHS of a volatile assignment in this |
| 1310 | /// context. We produce a warning for these when popping the context if |
| 1311 | /// they are not discarded-value expressions nor unevaluated operands. |
| 1312 | SmallVector<Expr*, 2> VolatileAssignmentLHSs; |
| 1313 | |
| 1314 | /// Set of candidates for starting an immediate invocation. |
| 1315 | llvm::SmallVector<ImmediateInvocationCandidate, 4> ImmediateInvocationCandidates; |
| 1316 | |
| 1317 | /// Set of DeclRefExprs referencing a consteval function when used in a |
| 1318 | /// context not already known to be immediately invoked. |
| 1319 | llvm::SmallPtrSet<DeclRefExpr *, 4> ReferenceToConsteval; |
| 1320 | |
| 1321 | /// \brief Describes whether we are in an expression constext which we have |
| 1322 | /// to handle differently. |
| 1323 | enum ExpressionKind { |
| 1324 | EK_Decltype, EK_TemplateArgument, EK_Other |
| 1325 | } ExprContext; |
| 1326 | |
| 1327 | // A context can be nested in both a discarded statement context and |
| 1328 | // an immediate function context, so they need to be tracked independently. |
| 1329 | bool InDiscardedStatement; |
| 1330 | bool InImmediateFunctionContext; |
| 1331 | |
| 1332 | bool IsCurrentlyCheckingDefaultArgumentOrInitializer = false; |
| 1333 | |
| 1334 | // When evaluating immediate functions in the initializer of a default |
| 1335 | // argument or default member initializer, this is the declaration whose |
| 1336 | // default initializer is being evaluated and the location of the call |
| 1337 | // or constructor definition. |
| 1338 | struct InitializationContext { |
| 1339 | InitializationContext(SourceLocation Loc, ValueDecl *Decl, |
| 1340 | DeclContext *Context) |
| 1341 | : Loc(Loc), Decl(Decl), Context(Context) { |
| 1342 | assert(Decl && Context && "invalid initialization context")(static_cast <bool> (Decl && Context && "invalid initialization context") ? void (0) : __assert_fail ("Decl && Context && \"invalid initialization context\"" , "clang/include/clang/Sema/Sema.h", 1342, __extension__ __PRETTY_FUNCTION__ )); |
| 1343 | } |
| 1344 | |
| 1345 | SourceLocation Loc; |
| 1346 | ValueDecl *Decl = nullptr; |
| 1347 | DeclContext *Context = nullptr; |
| 1348 | }; |
| 1349 | std::optional<InitializationContext> DelayedDefaultInitializationContext; |
| 1350 | |
| 1351 | ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context, |
| 1352 | unsigned NumCleanupObjects, |
| 1353 | CleanupInfo ParentCleanup, |
| 1354 | Decl *ManglingContextDecl, |
| 1355 | ExpressionKind ExprContext) |
| 1356 | : Context(Context), ParentCleanup(ParentCleanup), |
| 1357 | NumCleanupObjects(NumCleanupObjects), NumTypos(0), |
| 1358 | ManglingContextDecl(ManglingContextDecl), ExprContext(ExprContext), |
| 1359 | InDiscardedStatement(false), InImmediateFunctionContext(false) {} |
| 1360 | |
| 1361 | bool isUnevaluated() const { |
| 1362 | return Context == ExpressionEvaluationContext::Unevaluated || |
| 1363 | Context == ExpressionEvaluationContext::UnevaluatedAbstract || |
| 1364 | Context == ExpressionEvaluationContext::UnevaluatedList; |
| 1365 | } |
| 1366 | |
| 1367 | bool isConstantEvaluated() const { |
| 1368 | return Context == ExpressionEvaluationContext::ConstantEvaluated || |
| 1369 | Context == ExpressionEvaluationContext::ImmediateFunctionContext; |
| 1370 | } |
| 1371 | |
| 1372 | bool isImmediateFunctionContext() const { |
| 1373 | return Context == ExpressionEvaluationContext::ImmediateFunctionContext || |
| 1374 | (Context == ExpressionEvaluationContext::DiscardedStatement && |
| 1375 | InImmediateFunctionContext) || |
| 1376 | // C++23 [expr.const]p14: |
| 1377 | // An expression or conversion is in an immediate function |
| 1378 | // context if it is potentially evaluated and either: |
| 1379 | // * its innermost enclosing non-block scope is a function |
| 1380 | // parameter scope of an immediate function, or |
| 1381 | // * its enclosing statement is enclosed by the compound- |
| 1382 | // statement of a consteval if statement. |
| 1383 | (Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
| 1384 | InImmediateFunctionContext); |
| 1385 | } |
| 1386 | |
| 1387 | bool isDiscardedStatementContext() const { |
| 1388 | return Context == ExpressionEvaluationContext::DiscardedStatement || |
| 1389 | (Context == |
| 1390 | ExpressionEvaluationContext::ImmediateFunctionContext && |
| 1391 | InDiscardedStatement); |
| 1392 | } |
| 1393 | }; |
| 1394 | |
| 1395 | /// A stack of expression evaluation contexts. |
| 1396 | SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts; |
| 1397 | |
| 1398 | // Set of failed immediate invocations to avoid double diagnosing. |
| 1399 | llvm::SmallPtrSet<ConstantExpr *, 4> FailedImmediateInvocations; |
| 1400 | |
| 1401 | /// Emit a warning for all pending noderef expressions that we recorded. |
| 1402 | void WarnOnPendingNoDerefs(ExpressionEvaluationContextRecord &Rec); |
| 1403 | |
| 1404 | /// Compute the mangling number context for a lambda expression or |
| 1405 | /// block literal. Also return the extra mangling decl if any. |
| 1406 | /// |
| 1407 | /// \param DC - The DeclContext containing the lambda expression or |
| 1408 | /// block literal. |
| 1409 | std::tuple<MangleNumberingContext *, Decl *> |
| 1410 | getCurrentMangleNumberContext(const DeclContext *DC); |
| 1411 | |
| 1412 | |
| 1413 | /// SpecialMemberOverloadResult - The overloading result for a special member |
| 1414 | /// function. |
| 1415 | /// |
| 1416 | /// This is basically a wrapper around PointerIntPair. The lowest bits of the |
| 1417 | /// integer are used to determine whether overload resolution succeeded. |
| 1418 | class SpecialMemberOverloadResult { |
| 1419 | public: |
| 1420 | enum Kind { |
| 1421 | NoMemberOrDeleted, |
| 1422 | Ambiguous, |
| 1423 | Success |
| 1424 | }; |
| 1425 | |
| 1426 | private: |
| 1427 | llvm::PointerIntPair<CXXMethodDecl *, 2> Pair; |
| 1428 | |
| 1429 | public: |
| 1430 | SpecialMemberOverloadResult() {} |
| 1431 | SpecialMemberOverloadResult(CXXMethodDecl *MD) |
| 1432 | : Pair(MD, MD->isDeleted() ? NoMemberOrDeleted : Success) {} |
| 1433 | |
| 1434 | CXXMethodDecl *getMethod() const { return Pair.getPointer(); } |
| 1435 | void setMethod(CXXMethodDecl *MD) { Pair.setPointer(MD); } |
| 1436 | |
| 1437 | Kind getKind() const { return static_cast<Kind>(Pair.getInt()); } |
| 1438 | void setKind(Kind K) { Pair.setInt(K); } |
| 1439 | }; |
| 1440 | |
| 1441 | class SpecialMemberOverloadResultEntry |
| 1442 | : public llvm::FastFoldingSetNode, |
| 1443 | public SpecialMemberOverloadResult { |
| 1444 | public: |
| 1445 | SpecialMemberOverloadResultEntry(const llvm::FoldingSetNodeID &ID) |
| 1446 | : FastFoldingSetNode(ID) |
| 1447 | {} |
| 1448 | }; |
| 1449 | |
| 1450 | /// A cache of special member function overload resolution results |
| 1451 | /// for C++ records. |
| 1452 | llvm::FoldingSet<SpecialMemberOverloadResultEntry> SpecialMemberCache; |
| 1453 | |
| 1454 | /// A cache of the flags available in enumerations with the flag_bits |
| 1455 | /// attribute. |
| 1456 | mutable llvm::DenseMap<const EnumDecl*, llvm::APInt> FlagBitsCache; |
| 1457 | |
| 1458 | /// The kind of translation unit we are processing. |
| 1459 | /// |
| 1460 | /// When we're processing a complete translation unit, Sema will perform |
| 1461 | /// end-of-translation-unit semantic tasks (such as creating |
| 1462 | /// initializers for tentative definitions in C) once parsing has |
| 1463 | /// completed. Modules and precompiled headers perform different kinds of |
| 1464 | /// checks. |
| 1465 | const TranslationUnitKind TUKind; |
| 1466 | |
| 1467 | llvm::BumpPtrAllocator BumpAlloc; |
| 1468 | |
| 1469 | /// The number of SFINAE diagnostics that have been trapped. |
| 1470 | unsigned NumSFINAEErrors; |
| 1471 | |
| 1472 | typedef llvm::DenseMap<ParmVarDecl *, llvm::TinyPtrVector<ParmVarDecl *>> |
| 1473 | UnparsedDefaultArgInstantiationsMap; |
| 1474 | |
| 1475 | /// A mapping from parameters with unparsed default arguments to the |
| 1476 | /// set of instantiations of each parameter. |
| 1477 | /// |
| 1478 | /// This mapping is a temporary data structure used when parsing |
| 1479 | /// nested class templates or nested classes of class templates, |
| 1480 | /// where we might end up instantiating an inner class before the |
| 1481 | /// default arguments of its methods have been parsed. |
| 1482 | UnparsedDefaultArgInstantiationsMap UnparsedDefaultArgInstantiations; |
| 1483 | |
| 1484 | // Contains the locations of the beginning of unparsed default |
| 1485 | // argument locations. |
| 1486 | llvm::DenseMap<ParmVarDecl *, SourceLocation> UnparsedDefaultArgLocs; |
| 1487 | |
| 1488 | /// UndefinedInternals - all the used, undefined objects which require a |
| 1489 | /// definition in this translation unit. |
| 1490 | llvm::MapVector<NamedDecl *, SourceLocation> UndefinedButUsed; |
| 1491 | |
| 1492 | /// Determine if VD, which must be a variable or function, is an external |
| 1493 | /// symbol that nonetheless can't be referenced from outside this translation |
| 1494 | /// unit because its type has no linkage and it's not extern "C". |
| 1495 | bool isExternalWithNoLinkageType(const ValueDecl *VD) const; |
| 1496 | |
| 1497 | /// Obtain a sorted list of functions that are undefined but ODR-used. |
| 1498 | void getUndefinedButUsed( |
| 1499 | SmallVectorImpl<std::pair<NamedDecl *, SourceLocation> > &Undefined); |
| 1500 | |
| 1501 | /// Retrieves list of suspicious delete-expressions that will be checked at |
| 1502 | /// the end of translation unit. |
| 1503 | const llvm::MapVector<FieldDecl *, DeleteLocs> & |
| 1504 | getMismatchingDeleteExpressions() const; |
| 1505 | |
| 1506 | class GlobalMethodPool { |
| 1507 | public: |
| 1508 | using Lists = std::pair<ObjCMethodList, ObjCMethodList>; |
| 1509 | using iterator = llvm::DenseMap<Selector, Lists>::iterator; |
| 1510 | iterator begin() { return Methods.begin(); } |
| 1511 | iterator end() { return Methods.end(); } |
| 1512 | iterator find(Selector Sel) { return Methods.find(Sel); } |
| 1513 | std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) { |
| 1514 | return Methods.insert(Val); |
| 1515 | } |
| 1516 | int count(Selector Sel) const { return Methods.count(Sel); } |
| 1517 | bool empty() const { return Methods.empty(); } |
| 1518 | |
| 1519 | private: |
| 1520 | llvm::DenseMap<Selector, Lists> Methods; |
| 1521 | }; |
| 1522 | |
| 1523 | /// Method Pool - allows efficient lookup when typechecking messages to "id". |
| 1524 | /// We need to maintain a list, since selectors can have differing signatures |
| 1525 | /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% |
| 1526 | /// of selectors are "overloaded"). |
| 1527 | /// At the head of the list it is recorded whether there were 0, 1, or >= 2 |
| 1528 | /// methods inside categories with a particular selector. |
| 1529 | GlobalMethodPool MethodPool; |
| 1530 | |
| 1531 | /// Method selectors used in a \@selector expression. Used for implementation |
| 1532 | /// of -Wselector. |
| 1533 | llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; |
| 1534 | |
| 1535 | /// List of SourceLocations where 'self' is implicitly retained inside a |
| 1536 | /// block. |
| 1537 | llvm::SmallVector<std::pair<SourceLocation, const BlockDecl *>, 1> |
| 1538 | ImplicitlyRetainedSelfLocs; |
| 1539 | |
| 1540 | /// Kinds of C++ special members. |
| 1541 | enum CXXSpecialMember { |
| 1542 | CXXDefaultConstructor, |
| 1543 | CXXCopyConstructor, |
| 1544 | CXXMoveConstructor, |
| 1545 | CXXCopyAssignment, |
| 1546 | CXXMoveAssignment, |
| 1547 | CXXDestructor, |
| 1548 | CXXInvalid |
| 1549 | }; |
| 1550 | |
| 1551 | typedef llvm::PointerIntPair<CXXRecordDecl *, 3, CXXSpecialMember> |
| 1552 | SpecialMemberDecl; |
| 1553 | |
| 1554 | /// The C++ special members which we are currently in the process of |
| 1555 | /// declaring. If this process recursively triggers the declaration of the |
| 1556 | /// same special member, we should act as if it is not yet declared. |
| 1557 | llvm::SmallPtrSet<SpecialMemberDecl, 4> SpecialMembersBeingDeclared; |
| 1558 | |
| 1559 | /// Kinds of defaulted comparison operator functions. |
| 1560 | enum class DefaultedComparisonKind : unsigned char { |
| 1561 | /// This is not a defaultable comparison operator. |
| 1562 | None, |
| 1563 | /// This is an operator== that should be implemented as a series of |
| 1564 | /// subobject comparisons. |
| 1565 | Equal, |
| 1566 | /// This is an operator<=> that should be implemented as a series of |
| 1567 | /// subobject comparisons. |
| 1568 | ThreeWay, |
| 1569 | /// This is an operator!= that should be implemented as a rewrite in terms |
| 1570 | /// of a == comparison. |
| 1571 | NotEqual, |
| 1572 | /// This is an <, <=, >, or >= that should be implemented as a rewrite in |
| 1573 | /// terms of a <=> comparison. |
| 1574 | Relational, |
| 1575 | }; |
| 1576 | |
| 1577 | /// The function definitions which were renamed as part of typo-correction |
| 1578 | /// to match their respective declarations. We want to keep track of them |
| 1579 | /// to ensure that we don't emit a "redefinition" error if we encounter a |
| 1580 | /// correctly named definition after the renamed definition. |
| 1581 | llvm::SmallPtrSet<const NamedDecl *, 4> TypoCorrectedFunctionDefinitions; |
| 1582 | |
| 1583 | /// Stack of types that correspond to the parameter entities that are |
| 1584 | /// currently being copy-initialized. Can be empty. |
| 1585 | llvm::SmallVector<QualType, 4> CurrentParameterCopyTypes; |
| 1586 | |
| 1587 | void ReadMethodPool(Selector Sel); |
| 1588 | void updateOutOfDateSelector(Selector Sel); |
| 1589 | |
| 1590 | /// Private Helper predicate to check for 'self'. |
| 1591 | bool isSelfExpr(Expr *RExpr); |
| 1592 | bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method); |
| 1593 | |
| 1594 | /// Cause the active diagnostic on the DiagosticsEngine to be |
| 1595 | /// emitted. This is closely coupled to the SemaDiagnosticBuilder class and |
| 1596 | /// should not be used elsewhere. |
| 1597 | void EmitCurrentDiagnostic(unsigned DiagID); |
| 1598 | |
| 1599 | /// Records and restores the CurFPFeatures state on entry/exit of compound |
| 1600 | /// statements. |
| 1601 | class FPFeaturesStateRAII { |
| 1602 | public: |
| 1603 | FPFeaturesStateRAII(Sema &S); |
| 1604 | ~FPFeaturesStateRAII(); |
| 1605 | FPOptionsOverride getOverrides() { return OldOverrides; } |
| 1606 | |
| 1607 | private: |
| 1608 | Sema& S; |
| 1609 | FPOptions OldFPFeaturesState; |
| 1610 | FPOptionsOverride OldOverrides; |
| 1611 | LangOptions::FPEvalMethodKind OldEvalMethod; |
| 1612 | SourceLocation OldFPPragmaLocation; |
| 1613 | }; |
| 1614 | |
| 1615 | void addImplicitTypedef(StringRef Name, QualType T); |
| 1616 | |
| 1617 | bool WarnedStackExhausted = false; |
| 1618 | |
| 1619 | /// Increment when we find a reference; decrement when we find an ignored |
| 1620 | /// assignment. Ultimately the value is 0 if every reference is an ignored |
| 1621 | /// assignment. |
| 1622 | llvm::DenseMap<const VarDecl *, int> RefsMinusAssignments; |
| 1623 | |
| 1624 | /// Indicate RISC-V vector builtin functions enabled or not. |
| 1625 | bool DeclareRISCVVBuiltins = false; |
| 1626 | |
| 1627 | /// Indicate RISC-V Sifive vector builtin functions enabled or not. |
| 1628 | bool DeclareRISCVVectorBuiltins = false; |
| 1629 | |
| 1630 | private: |
| 1631 | std::unique_ptr<sema::RISCVIntrinsicManager> RVIntrinsicManager; |
| 1632 | |
| 1633 | std::optional<std::unique_ptr<DarwinSDKInfo>> CachedDarwinSDKInfo; |
| 1634 | |
| 1635 | bool WarnedDarwinSDKInfoMissing = false; |
| 1636 | |
| 1637 | public: |
| 1638 | Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer, |
| 1639 | TranslationUnitKind TUKind = TU_Complete, |
| 1640 | CodeCompleteConsumer *CompletionConsumer = nullptr); |
| 1641 | ~Sema(); |
| 1642 | |
| 1643 | /// Perform initialization that occurs after the parser has been |
| 1644 | /// initialized but before it parses anything. |
| 1645 | void Initialize(); |
| 1646 | |
| 1647 | /// This virtual key function only exists to limit the emission of debug info |
| 1648 | /// describing the Sema class. GCC and Clang only emit debug info for a class |
| 1649 | /// with a vtable when the vtable is emitted. Sema is final and not |
| 1650 | /// polymorphic, but the debug info size savings are so significant that it is |
| 1651 | /// worth adding a vtable just to take advantage of this optimization. |
| 1652 | virtual void anchor(); |
| 1653 | |
| 1654 | const LangOptions &getLangOpts() const { return LangOpts; } |
| 1655 | OpenCLOptions &getOpenCLOptions() { return OpenCLFeatures; } |
| 1656 | FPOptions &getCurFPFeatures() { return CurFPFeatures; } |
| 1657 | |
| 1658 | DiagnosticsEngine &getDiagnostics() const { return Diags; } |
| 1659 | SourceManager &getSourceManager() const { return SourceMgr; } |
| 1660 | Preprocessor &getPreprocessor() const { return PP; } |
| 1661 | ASTContext &getASTContext() const { return Context; } |
| 1662 | ASTConsumer &getASTConsumer() const { return Consumer; } |
| 1663 | ASTMutationListener *getASTMutationListener() const; |
| 1664 | ExternalSemaSource *getExternalSource() const { return ExternalSource.get(); } |
| 1665 | |
| 1666 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(SourceLocation Loc, |
| 1667 | StringRef Platform); |
| 1668 | DarwinSDKInfo *getDarwinSDKInfoForAvailabilityChecking(); |
| 1669 | |
| 1670 | ///Registers an external source. If an external source already exists, |
| 1671 | /// creates a multiplex external source and appends to it. |
| 1672 | /// |
| 1673 | ///\param[in] E - A non-null external sema source. |
| 1674 | /// |
| 1675 | void addExternalSource(ExternalSemaSource *E); |
| 1676 | |
| 1677 | void PrintStats() const; |
| 1678 | |
| 1679 | /// Warn that the stack is nearly exhausted. |
| 1680 | void warnStackExhausted(SourceLocation Loc); |
| 1681 | |
| 1682 | /// Run some code with "sufficient" stack space. (Currently, at least 256K is |
| 1683 | /// guaranteed). Produces a warning if we're low on stack space and allocates |
| 1684 | /// more in that case. Use this in code that may recurse deeply (for example, |
| 1685 | /// in template instantiation) to avoid stack overflow. |
| 1686 | void runWithSufficientStackSpace(SourceLocation Loc, |
| 1687 | llvm::function_ref<void()> Fn); |
| 1688 | |
| 1689 | /// Helper class that creates diagnostics with optional |
| 1690 | /// template instantiation stacks. |
| 1691 | /// |
| 1692 | /// This class provides a wrapper around the basic DiagnosticBuilder |
| 1693 | /// class that emits diagnostics. ImmediateDiagBuilder is |
| 1694 | /// responsible for emitting the diagnostic (as DiagnosticBuilder |
| 1695 | /// does) and, if the diagnostic comes from inside a template |
| 1696 | /// instantiation, printing the template instantiation stack as |
| 1697 | /// well. |
| 1698 | class ImmediateDiagBuilder : public DiagnosticBuilder { |
| 1699 | Sema &SemaRef; |
| 1700 | unsigned DiagID; |
| 1701 | |
| 1702 | public: |
| 1703 | ImmediateDiagBuilder(DiagnosticBuilder &DB, Sema &SemaRef, unsigned DiagID) |
| 1704 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
| 1705 | ImmediateDiagBuilder(DiagnosticBuilder &&DB, Sema &SemaRef, unsigned DiagID) |
| 1706 | : DiagnosticBuilder(DB), SemaRef(SemaRef), DiagID(DiagID) {} |
| 1707 | |
| 1708 | // This is a cunning lie. DiagnosticBuilder actually performs move |
| 1709 | // construction in its copy constructor (but due to varied uses, it's not |
| 1710 | // possible to conveniently express this as actual move construction). So |
| 1711 | // the default copy ctor here is fine, because the base class disables the |
| 1712 | // source anyway, so the user-defined ~ImmediateDiagBuilder is a safe no-op |
| 1713 | // in that case anwyay. |
| 1714 | ImmediateDiagBuilder(const ImmediateDiagBuilder &) = default; |
| 1715 | |
| 1716 | ~ImmediateDiagBuilder() { |
| 1717 | // If we aren't active, there is nothing to do. |
| 1718 | if (!isActive()) return; |
| 1719 | |
| 1720 | // Otherwise, we need to emit the diagnostic. First clear the diagnostic |
| 1721 | // builder itself so it won't emit the diagnostic in its own destructor. |
| 1722 | // |
| 1723 | // This seems wasteful, in that as written the DiagnosticBuilder dtor will |
| 1724 | // do its own needless checks to see if the diagnostic needs to be |
| 1725 | // emitted. However, because we take care to ensure that the builder |
| 1726 | // objects never escape, a sufficiently smart compiler will be able to |
| 1727 | // eliminate that code. |
| 1728 | Clear(); |
| 1729 | |
| 1730 | // Dispatch to Sema to emit the diagnostic. |
| 1731 | SemaRef.EmitCurrentDiagnostic(DiagID); |
| 1732 | } |
| 1733 | |
| 1734 | /// Teach operator<< to produce an object of the correct type. |
| 1735 | template <typename T> |
| 1736 | friend const ImmediateDiagBuilder & |
| 1737 | operator<<(const ImmediateDiagBuilder &Diag, const T &Value) { |
| 1738 | const DiagnosticBuilder &BaseDiag = Diag; |
| 1739 | BaseDiag << Value; |
| 1740 | return Diag; |
| 1741 | } |
| 1742 | |
| 1743 | // It is necessary to limit this to rvalue reference to avoid calling this |
| 1744 | // function with a bitfield lvalue argument since non-const reference to |
| 1745 | // bitfield is not allowed. |
| 1746 | template <typename T, |
| 1747 | typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>> |
| 1748 | const ImmediateDiagBuilder &operator<<(T &&V) const { |
| 1749 | const DiagnosticBuilder &BaseDiag = *this; |
| 1750 | BaseDiag << std::move(V); |
| 1751 | return *this; |
| 1752 | } |
| 1753 | }; |
| 1754 | |
| 1755 | /// A generic diagnostic builder for errors which may or may not be deferred. |
| 1756 | /// |
| 1757 | /// In CUDA, there exist constructs (e.g. variable-length arrays, try/catch) |
| 1758 | /// which are not allowed to appear inside __device__ functions and are |
| 1759 | /// allowed to appear in __host__ __device__ functions only if the host+device |
| 1760 | /// function is never codegen'ed. |
| 1761 | /// |
| 1762 | /// To handle this, we use the notion of "deferred diagnostics", where we |
| 1763 | /// attach a diagnostic to a FunctionDecl that's emitted iff it's codegen'ed. |
| 1764 | /// |
| 1765 | /// This class lets you emit either a regular diagnostic, a deferred |
| 1766 | /// diagnostic, or no diagnostic at all, according to an argument you pass to |
| 1767 | /// its constructor, thus simplifying the process of creating these "maybe |
| 1768 | /// deferred" diagnostics. |
| 1769 | class SemaDiagnosticBuilder { |
| 1770 | public: |
| 1771 | enum Kind { |
| 1772 | /// Emit no diagnostics. |
| 1773 | K_Nop, |
| 1774 | /// Emit the diagnostic immediately (i.e., behave like Sema::Diag()). |
| 1775 | K_Immediate, |
| 1776 | /// Emit the diagnostic immediately, and, if it's a warning or error, also |
| 1777 | /// emit a call stack showing how this function can be reached by an a |
| 1778 | /// priori known-emitted function. |
| 1779 | K_ImmediateWithCallStack, |
| 1780 | /// Create a deferred diagnostic, which is emitted only if the function |
| 1781 | /// it's attached to is codegen'ed. Also emit a call stack as with |
| 1782 | /// K_ImmediateWithCallStack. |
| 1783 | K_Deferred |
| 1784 | }; |
| 1785 | |
| 1786 | SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID, |
| 1787 | const FunctionDecl *Fn, Sema &S); |
| 1788 | SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D); |
| 1789 | SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default; |
| 1790 | ~SemaDiagnosticBuilder(); |
| 1791 | |
| 1792 | bool isImmediate() const { return ImmediateDiag.has_value(); } |
| 1793 | |
| 1794 | /// Convertible to bool: True if we immediately emitted an error, false if |
| 1795 | /// we didn't emit an error or we created a deferred error. |
| 1796 | /// |
| 1797 | /// Example usage: |
| 1798 | /// |
| 1799 | /// if (SemaDiagnosticBuilder(...) << foo << bar) |
| 1800 | /// return ExprError(); |
| 1801 | /// |
| 1802 | /// But see CUDADiagIfDeviceCode() and CUDADiagIfHostCode() -- you probably |
| 1803 | /// want to use these instead of creating a SemaDiagnosticBuilder yourself. |
| 1804 | operator bool() const { return isImmediate(); } |
| 1805 | |
| 1806 | template <typename T> |
| 1807 | friend const SemaDiagnosticBuilder & |
| 1808 | operator<<(const SemaDiagnosticBuilder &Diag, const T &Value) { |
| 1809 | if (Diag.ImmediateDiag) |
| 1810 | *Diag.ImmediateDiag << Value; |
| 1811 | else if (Diag.PartialDiagId) |
| 1812 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second |
| 1813 | << Value; |
| 1814 | return Diag; |
| 1815 | } |
| 1816 | |
| 1817 | // It is necessary to limit this to rvalue reference to avoid calling this |
| 1818 | // function with a bitfield lvalue argument since non-const reference to |
| 1819 | // bitfield is not allowed. |
| 1820 | template <typename T, |
| 1821 | typename = std::enable_if_t<!std::is_lvalue_reference<T>::value>> |
| 1822 | const SemaDiagnosticBuilder &operator<<(T &&V) const { |
| 1823 | if (ImmediateDiag) |
| 1824 | *ImmediateDiag << std::move(V); |
| 1825 | else if (PartialDiagId) |
| 1826 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second << std::move(V); |
| 1827 | return *this; |
| 1828 | } |
| 1829 | |
| 1830 | friend const SemaDiagnosticBuilder & |
| 1831 | operator<<(const SemaDiagnosticBuilder &Diag, const PartialDiagnostic &PD) { |
| 1832 | if (Diag.ImmediateDiag) |
| 1833 | PD.Emit(*Diag.ImmediateDiag); |
| 1834 | else if (Diag.PartialDiagId) |
| 1835 | Diag.S.DeviceDeferredDiags[Diag.Fn][*Diag.PartialDiagId].second = PD; |
| 1836 | return Diag; |
| 1837 | } |
| 1838 | |
| 1839 | void AddFixItHint(const FixItHint &Hint) const { |
| 1840 | if (ImmediateDiag) |
| 1841 | ImmediateDiag->AddFixItHint(Hint); |
| 1842 | else if (PartialDiagId) |
| 1843 | S.DeviceDeferredDiags[Fn][*PartialDiagId].second.AddFixItHint(Hint); |
| 1844 | } |
| 1845 | |
| 1846 | friend ExprResult ExprError(const SemaDiagnosticBuilder &) { |
| 1847 | return ExprError(); |
| 1848 | } |
| 1849 | friend StmtResult StmtError(const SemaDiagnosticBuilder &) { |
| 1850 | return StmtError(); |
| 1851 | } |
| 1852 | operator ExprResult() const { return ExprError(); } |
| 1853 | operator StmtResult() const { return StmtError(); } |
| 1854 | operator TypeResult() const { return TypeError(); } |
| 1855 | operator DeclResult() const { return DeclResult(true); } |
| 1856 | operator MemInitResult() const { return MemInitResult(true); } |
| 1857 | |
| 1858 | private: |
| 1859 | Sema &S; |
| 1860 | SourceLocation Loc; |
| 1861 | unsigned DiagID; |
| 1862 | const FunctionDecl *Fn; |
| 1863 | bool ShowCallStack; |
| 1864 | |
| 1865 | // Invariant: At most one of these Optionals has a value. |
| 1866 | // FIXME: Switch these to a Variant once that exists. |
| 1867 | std::optional<ImmediateDiagBuilder> ImmediateDiag; |
| 1868 | std::optional<unsigned> PartialDiagId; |
| 1869 | }; |
| 1870 | |
| 1871 | /// Is the last error level diagnostic immediate. This is used to determined |
| 1872 | /// whether the next info diagnostic should be immediate. |
| 1873 | bool IsLastErrorImmediate = true; |
| 1874 | |
| 1875 | /// Emit a diagnostic. |
| 1876 | SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, |
| 1877 | bool DeferHint = false); |
| 1878 | |
| 1879 | /// Emit a partial diagnostic. |
| 1880 | SemaDiagnosticBuilder Diag(SourceLocation Loc, const PartialDiagnostic &PD, |
| 1881 | bool DeferHint = false); |
| 1882 | |
| 1883 | /// Build a partial diagnostic. |
| 1884 | PartialDiagnostic PDiag(unsigned DiagID = 0); // in SemaInternal.h |
| 1885 | |
| 1886 | /// Whether deferrable diagnostics should be deferred. |
| 1887 | bool DeferDiags = false; |
| 1888 | |
| 1889 | /// RAII class to control scope of DeferDiags. |
| 1890 | class DeferDiagsRAII { |
| 1891 | Sema &S; |
| 1892 | bool SavedDeferDiags = false; |
| 1893 | |
| 1894 | public: |
| 1895 | DeferDiagsRAII(Sema &S, bool DeferDiags) |
| 1896 | : S(S), SavedDeferDiags(S.DeferDiags) { |
| 1897 | S.DeferDiags = DeferDiags; |
| 1898 | } |
| 1899 | ~DeferDiagsRAII() { S.DeferDiags = SavedDeferDiags; } |
| 1900 | }; |
| 1901 | |
| 1902 | /// Whether uncompilable error has occurred. This includes error happens |
| 1903 | /// in deferred diagnostics. |
| 1904 | bool hasUncompilableErrorOccurred() const; |
| 1905 | |
| 1906 | bool findMacroSpelling(SourceLocation &loc, StringRef name); |
| 1907 | |
| 1908 | /// Get a string to suggest for zero-initialization of a type. |
| 1909 | std::string |
| 1910 | getFixItZeroInitializerForType(QualType T, SourceLocation Loc) const; |
| 1911 | std::string getFixItZeroLiteralForType(QualType T, SourceLocation Loc) const; |
| 1912 | |
| 1913 | /// Calls \c Lexer::getLocForEndOfToken() |
| 1914 | SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset = 0); |
| 1915 | |
| 1916 | /// Retrieve the module loader associated with the preprocessor. |
| 1917 | ModuleLoader &getModuleLoader() const; |
| 1918 | |
| 1919 | /// Invent a new identifier for parameters of abbreviated templates. |
| 1920 | IdentifierInfo * |
| 1921 | InventAbbreviatedTemplateParameterTypeName(IdentifierInfo *ParamName, |
| 1922 | unsigned Index); |
| 1923 | |
| 1924 | void emitAndClearUnusedLocalTypedefWarnings(); |
| 1925 | |
| 1926 | private: |
| 1927 | /// Function or variable declarations to be checked for whether the deferred |
| 1928 | /// diagnostics should be emitted. |
| 1929 | llvm::SmallSetVector<Decl *, 4> DeclsToCheckForDeferredDiags; |
| 1930 | |
| 1931 | public: |
| 1932 | // Emit all deferred diagnostics. |
| 1933 | void emitDeferredDiags(); |
| 1934 | |
| 1935 | enum TUFragmentKind { |
| 1936 | /// The global module fragment, between 'module;' and a module-declaration. |
| 1937 | Global, |
| 1938 | /// A normal translation unit fragment. For a non-module unit, this is the |
| 1939 | /// entire translation unit. Otherwise, it runs from the module-declaration |
| 1940 | /// to the private-module-fragment (if any) or the end of the TU (if not). |
| 1941 | Normal, |
| 1942 | /// The private module fragment, between 'module :private;' and the end of |
| 1943 | /// the translation unit. |
| 1944 | Private |
| 1945 | }; |
| 1946 | |
| 1947 | void ActOnStartOfTranslationUnit(); |
| 1948 | void ActOnEndOfTranslationUnit(); |
| 1949 | void ActOnEndOfTranslationUnitFragment(TUFragmentKind Kind); |
| 1950 | |
| 1951 | void CheckDelegatingCtorCycles(); |
| 1952 | |
| 1953 | Scope *getScopeForContext(DeclContext *Ctx); |
| 1954 | |
| 1955 | void PushFunctionScope(); |
| 1956 | void PushBlockScope(Scope *BlockScope, BlockDecl *Block); |
| 1957 | sema::LambdaScopeInfo *PushLambdaScope(); |
| 1958 | |
| 1959 | /// This is used to inform Sema what the current TemplateParameterDepth |
| 1960 | /// is during Parsing. Currently it is used to pass on the depth |
| 1961 | /// when parsing generic lambda 'auto' parameters. |
| 1962 | void RecordParsingTemplateParameterDepth(unsigned Depth); |
| 1963 | |
| 1964 | void PushCapturedRegionScope(Scope *RegionScope, CapturedDecl *CD, |
| 1965 | RecordDecl *RD, CapturedRegionKind K, |
| 1966 | unsigned OpenMPCaptureLevel = 0); |
| 1967 | |
| 1968 | /// Custom deleter to allow FunctionScopeInfos to be kept alive for a short |
| 1969 | /// time after they've been popped. |
| 1970 | class PoppedFunctionScopeDeleter { |
| 1971 | Sema *Self; |
| 1972 | |
| 1973 | public: |
| 1974 | explicit PoppedFunctionScopeDeleter(Sema *Self) : Self(Self) {} |
| 1975 | void operator()(sema::FunctionScopeInfo *Scope) const; |
| 1976 | }; |
| 1977 | |
| 1978 | using PoppedFunctionScopePtr = |
| 1979 | std::unique_ptr<sema::FunctionScopeInfo, PoppedFunctionScopeDeleter>; |
| 1980 | |
| 1981 | PoppedFunctionScopePtr |
| 1982 | PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, |
| 1983 | const Decl *D = nullptr, |
| 1984 | QualType BlockType = QualType()); |
| 1985 | |
| 1986 | sema::FunctionScopeInfo *getCurFunction() const { |
| 1987 | return FunctionScopes.empty() ? nullptr : FunctionScopes.back(); |
| 1988 | } |
| 1989 | |
| 1990 | sema::FunctionScopeInfo *getEnclosingFunction() const; |
| 1991 | |
| 1992 | void setFunctionHasBranchIntoScope(); |
| 1993 | void setFunctionHasBranchProtectedScope(); |
| 1994 | void setFunctionHasIndirectGoto(); |
| 1995 | void setFunctionHasMustTail(); |
| 1996 | |
| 1997 | void PushCompoundScope(bool IsStmtExpr); |
| 1998 | void PopCompoundScope(); |
| 1999 | |
| 2000 | sema::CompoundScopeInfo &getCurCompoundScope() const; |
| 2001 | |
| 2002 | bool hasAnyUnrecoverableErrorsInThisFunction() const; |
| 2003 | |
| 2004 | /// Retrieve the current block, if any. |
| 2005 | sema::BlockScopeInfo *getCurBlock(); |
| 2006 | |
| 2007 | /// Get the innermost lambda enclosing the current location, if any. This |
| 2008 | /// looks through intervening non-lambda scopes such as local functions and |
| 2009 | /// blocks. |
| 2010 | sema::LambdaScopeInfo *getEnclosingLambda() const; |
| 2011 | |
| 2012 | /// Retrieve the current lambda scope info, if any. |
| 2013 | /// \param IgnoreNonLambdaCapturingScope true if should find the top-most |
| 2014 | /// lambda scope info ignoring all inner capturing scopes that are not |
| 2015 | /// lambda scopes. |
| 2016 | sema::LambdaScopeInfo * |
| 2017 | getCurLambda(bool IgnoreNonLambdaCapturingScope = false); |
| 2018 | |
| 2019 | /// Retrieve the current generic lambda info, if any. |
| 2020 | sema::LambdaScopeInfo *getCurGenericLambda(); |
| 2021 | |
| 2022 | /// Retrieve the current captured region, if any. |
| 2023 | sema::CapturedRegionScopeInfo *getCurCapturedRegion(); |
| 2024 | |
| 2025 | /// Retrieve the current function, if any, that should be analyzed for |
| 2026 | /// potential availability violations. |
| 2027 | sema::FunctionScopeInfo *getCurFunctionAvailabilityContext(); |
| 2028 | |
| 2029 | /// WeakTopLevelDeclDecls - access to \#pragma weak-generated Decls |
| 2030 | SmallVectorImpl<Decl *> &WeakTopLevelDecls() { return WeakTopLevelDecl; } |
| 2031 | |
| 2032 | /// Called before parsing a function declarator belonging to a function |
| 2033 | /// declaration. |
| 2034 | void ActOnStartFunctionDeclarationDeclarator(Declarator &D, |
| 2035 | unsigned TemplateParameterDepth); |
| 2036 | |
| 2037 | /// Called after parsing a function declarator belonging to a function |
| 2038 | /// declaration. |
| 2039 | void ActOnFinishFunctionDeclarationDeclarator(Declarator &D); |
| 2040 | |
| 2041 | void ActOnComment(SourceRange Comment); |
| 2042 | |
| 2043 | //===--------------------------------------------------------------------===// |
| 2044 | // Type Analysis / Processing: SemaType.cpp. |
| 2045 | // |
| 2046 | |
| 2047 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, |
| 2048 | const DeclSpec *DS = nullptr); |
| 2049 | QualType BuildQualifiedType(QualType T, SourceLocation Loc, unsigned CVRA, |
| 2050 | const DeclSpec *DS = nullptr); |
| 2051 | QualType BuildPointerType(QualType T, |
| 2052 | SourceLocation Loc, DeclarationName Entity); |
| 2053 | QualType BuildReferenceType(QualType T, bool LValueRef, |
| 2054 | SourceLocation Loc, DeclarationName Entity); |
| 2055 | QualType BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM, |
| 2056 | Expr *ArraySize, unsigned Quals, |
| 2057 | SourceRange Brackets, DeclarationName Entity); |
| 2058 | QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc); |
| 2059 | QualType BuildExtVectorType(QualType T, Expr *ArraySize, |
| 2060 | SourceLocation AttrLoc); |
| 2061 | QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, |
| 2062 | SourceLocation AttrLoc); |
| 2063 | |
| 2064 | QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, |
| 2065 | SourceLocation AttrLoc); |
| 2066 | |
| 2067 | /// Same as above, but constructs the AddressSpace index if not provided. |
| 2068 | QualType BuildAddressSpaceAttr(QualType &T, Expr *AddrSpace, |
| 2069 | SourceLocation AttrLoc); |
| 2070 | |
| 2071 | bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc); |
| 2072 | |
| 2073 | bool CheckFunctionReturnType(QualType T, SourceLocation Loc); |
| 2074 | |
| 2075 | /// Build a function type. |
| 2076 | /// |
| 2077 | /// This routine checks the function type according to C++ rules and |
| 2078 | /// under the assumption that the result type and parameter types have |
| 2079 | /// just been instantiated from a template. It therefore duplicates |
| 2080 | /// some of the behavior of GetTypeForDeclarator, but in a much |
| 2081 | /// simpler form that is only suitable for this narrow use case. |
| 2082 | /// |
| 2083 | /// \param T The return type of the function. |
| 2084 | /// |
| 2085 | /// \param ParamTypes The parameter types of the function. This array |
| 2086 | /// will be modified to account for adjustments to the types of the |
| 2087 | /// function parameters. |
| 2088 | /// |
| 2089 | /// \param Loc The location of the entity whose type involves this |
| 2090 | /// function type or, if there is no such entity, the location of the |
| 2091 | /// type that will have function type. |
| 2092 | /// |
| 2093 | /// \param Entity The name of the entity that involves the function |
| 2094 | /// type, if known. |
| 2095 | /// |
| 2096 | /// \param EPI Extra information about the function type. Usually this will |
| 2097 | /// be taken from an existing function with the same prototype. |
| 2098 | /// |
| 2099 | /// \returns A suitable function type, if there are no errors. The |
| 2100 | /// unqualified type will always be a FunctionProtoType. |
| 2101 | /// Otherwise, returns a NULL type. |
| 2102 | QualType BuildFunctionType(QualType T, |
| 2103 | MutableArrayRef<QualType> ParamTypes, |
| 2104 | SourceLocation Loc, DeclarationName Entity, |
| 2105 | const FunctionProtoType::ExtProtoInfo &EPI); |
| 2106 | |
| 2107 | QualType BuildMemberPointerType(QualType T, QualType Class, |
| 2108 | SourceLocation Loc, |
| 2109 | DeclarationName Entity); |
| 2110 | QualType BuildBlockPointerType(QualType T, |
| 2111 | SourceLocation Loc, DeclarationName Entity); |
| 2112 | QualType BuildParenType(QualType T); |
| 2113 | QualType BuildAtomicType(QualType T, SourceLocation Loc); |
| 2114 | QualType BuildReadPipeType(QualType T, |
| 2115 | SourceLocation Loc); |
| 2116 | QualType BuildWritePipeType(QualType T, |
| 2117 | SourceLocation Loc); |
| 2118 | QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc); |
| 2119 | |
| 2120 | TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S); |
| 2121 | TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy); |
| 2122 | |
| 2123 | /// Package the given type and TSI into a ParsedType. |
| 2124 | ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo); |
| 2125 | DeclarationNameInfo GetNameForDeclarator(Declarator &D); |
| 2126 | DeclarationNameInfo GetNameFromUnqualifiedId(const UnqualifiedId &Name); |
| 2127 | static QualType GetTypeFromParser(ParsedType Ty, |
| 2128 | TypeSourceInfo **TInfo = nullptr); |
| 2129 | CanThrowResult canThrow(const Stmt *E); |
| 2130 | /// Determine whether the callee of a particular function call can throw. |
| 2131 | /// E, D and Loc are all optional. |
| 2132 | static CanThrowResult canCalleeThrow(Sema &S, const Expr *E, const Decl *D, |
| 2133 | SourceLocation Loc = SourceLocation()); |
| 2134 | const FunctionProtoType *ResolveExceptionSpec(SourceLocation Loc, |
| 2135 | const FunctionProtoType *FPT); |
| 2136 | void UpdateExceptionSpec(FunctionDecl *FD, |
| 2137 | const FunctionProtoType::ExceptionSpecInfo &ESI); |
| 2138 | bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range); |
| 2139 | bool CheckDistantExceptionSpec(QualType T); |
| 2140 | bool CheckEquivalentExceptionSpec(FunctionDecl *Old, FunctionDecl *New); |
| 2141 | bool CheckEquivalentExceptionSpec( |
| 2142 | const FunctionProtoType *Old, SourceLocation OldLoc, |
| 2143 | const FunctionProtoType *New, SourceLocation NewLoc); |
| 2144 | bool CheckEquivalentExceptionSpec( |
| 2145 | const PartialDiagnostic &DiagID, const PartialDiagnostic & NoteID, |
| 2146 | const FunctionProtoType *Old, SourceLocation OldLoc, |
| 2147 | const FunctionProtoType *New, SourceLocation NewLoc); |
| 2148 | bool handlerCanCatch(QualType HandlerType, QualType ExceptionType); |
| 2149 | bool CheckExceptionSpecSubset(const PartialDiagnostic &DiagID, |
| 2150 | const PartialDiagnostic &NestedDiagID, |
| 2151 | const PartialDiagnostic &NoteID, |
| 2152 | const PartialDiagnostic &NoThrowDiagID, |
| 2153 | const FunctionProtoType *Superset, |
| 2154 | SourceLocation SuperLoc, |
| 2155 | const FunctionProtoType *Subset, |
| 2156 | SourceLocation SubLoc); |
| 2157 | bool CheckParamExceptionSpec(const PartialDiagnostic &NestedDiagID, |
| 2158 | const PartialDiagnostic &NoteID, |
| 2159 | const FunctionProtoType *Target, |
| 2160 | SourceLocation TargetLoc, |
| 2161 | const FunctionProtoType *Source, |
| 2162 | SourceLocation SourceLoc); |
| 2163 | |
| 2164 | TypeResult ActOnTypeName(Scope *S, Declarator &D); |
| 2165 | |
| 2166 | /// The parser has parsed the context-sensitive type 'instancetype' |
| 2167 | /// in an Objective-C message declaration. Return the appropriate type. |
| 2168 | ParsedType ActOnObjCInstanceType(SourceLocation Loc); |
| 2169 | |
| 2170 | /// Abstract class used to diagnose incomplete types. |
| 2171 | struct TypeDiagnoser { |
| 2172 | TypeDiagnoser() {} |
| 2173 | |
| 2174 | virtual void diagnose(Sema &S, SourceLocation Loc, QualType T) = 0; |
| 2175 | virtual ~TypeDiagnoser() {} |
| 2176 | }; |
| 2177 | |
| 2178 | static int getPrintable(int I) { return I; } |
| 2179 | static unsigned getPrintable(unsigned I) { return I; } |
| 2180 | static bool getPrintable(bool B) { return B; } |
| 2181 | static const char * getPrintable(const char *S) { return S; } |
| 2182 | static StringRef getPrintable(StringRef S) { return S; } |
| 2183 | static const std::string &getPrintable(const std::string &S) { return S; } |
| 2184 | static const IdentifierInfo *getPrintable(const IdentifierInfo *II) { |
| 2185 | return II; |
| 2186 | } |
| 2187 | static DeclarationName getPrintable(DeclarationName N) { return N; } |
| 2188 | static QualType getPrintable(QualType T) { return T; } |
| 2189 | static SourceRange getPrintable(SourceRange R) { return R; } |
| 2190 | static SourceRange getPrintable(SourceLocation L) { return L; } |
| 2191 | static SourceRange getPrintable(const Expr *E) { return E->getSourceRange(); } |
| 2192 | static SourceRange getPrintable(TypeLoc TL) { return TL.getSourceRange();} |
| 2193 | |
| 2194 | template <typename... Ts> class BoundTypeDiagnoser : public TypeDiagnoser { |
| 2195 | protected: |
| 2196 | unsigned DiagID; |
| 2197 | std::tuple<const Ts &...> Args; |
| 2198 | |
| 2199 | template <std::size_t... Is> |
| 2200 | void emit(const SemaDiagnosticBuilder &DB, |
| 2201 | std::index_sequence<Is...>) const { |
| 2202 | // Apply all tuple elements to the builder in order. |
| 2203 | bool Dummy[] = {false, (DB << getPrintable(std::get<Is>(Args)))...}; |
| 2204 | (void)Dummy; |
| 2205 | } |
| 2206 | |
| 2207 | public: |
| 2208 | BoundTypeDiagnoser(unsigned DiagID, const Ts &...Args) |
| 2209 | : TypeDiagnoser(), DiagID(DiagID), Args(Args...) { |
| 2210 | assert(DiagID != 0 && "no diagnostic for type diagnoser")(static_cast <bool> (DiagID != 0 && "no diagnostic for type diagnoser" ) ? void (0) : __assert_fail ("DiagID != 0 && \"no diagnostic for type diagnoser\"" , "clang/include/clang/Sema/Sema.h", 2210, __extension__ __PRETTY_FUNCTION__ )); |
| 2211 | } |
| 2212 | |
| 2213 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
| 2214 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, DiagID); |
| 2215 | emit(DB, std::index_sequence_for<Ts...>()); |
| 2216 | DB << T; |
| 2217 | } |
| 2218 | }; |
| 2219 | |
| 2220 | /// Do a check to make sure \p Name looks like a legal argument for the |
| 2221 | /// swift_name attribute applied to decl \p D. Raise a diagnostic if the name |
| 2222 | /// is invalid for the given declaration. |
| 2223 | /// |
| 2224 | /// \p AL is used to provide caret diagnostics in case of a malformed name. |
| 2225 | /// |
| 2226 | /// \returns true if the name is a valid swift name for \p D, false otherwise. |
| 2227 | bool DiagnoseSwiftName(Decl *D, StringRef Name, SourceLocation Loc, |
| 2228 | const ParsedAttr &AL, bool IsAsync); |
| 2229 | |
| 2230 | /// A derivative of BoundTypeDiagnoser for which the diagnostic's type |
| 2231 | /// parameter is preceded by a 0/1 enum that is 1 if the type is sizeless. |
| 2232 | /// For example, a diagnostic with no other parameters would generally have |
| 2233 | /// the form "...%select{incomplete|sizeless}0 type %1...". |
| 2234 | template <typename... Ts> |
| 2235 | class SizelessTypeDiagnoser : public BoundTypeDiagnoser<Ts...> { |
| 2236 | public: |
| 2237 | SizelessTypeDiagnoser(unsigned DiagID, const Ts &... Args) |
| 2238 | : BoundTypeDiagnoser<Ts...>(DiagID, Args...) {} |
| 2239 | |
| 2240 | void diagnose(Sema &S, SourceLocation Loc, QualType T) override { |
| 2241 | const SemaDiagnosticBuilder &DB = S.Diag(Loc, this->DiagID); |
| 2242 | this->emit(DB, std::index_sequence_for<Ts...>()); |
| 2243 | DB << T->isSizelessType() << T; |
| 2244 | } |
| 2245 | }; |
| 2246 | |
| 2247 | enum class CompleteTypeKind { |
| 2248 | /// Apply the normal rules for complete types. In particular, |
| 2249 | /// treat all sizeless types as incomplete. |
| 2250 | Normal, |
| 2251 | |
| 2252 | /// Relax the normal rules for complete types so that they include |
| 2253 | /// sizeless built-in types. |
| 2254 | AcceptSizeless, |
| 2255 | |
| 2256 | // FIXME: Eventually we should flip the default to Normal and opt in |
| 2257 | // to AcceptSizeless rather than opt out of it. |
| 2258 | Default = AcceptSizeless |
| 2259 | }; |
| 2260 | |
| 2261 | enum class AcceptableKind { Visible, Reachable }; |
| 2262 | |
| 2263 | private: |
| 2264 | /// Methods for marking which expressions involve dereferencing a pointer |
| 2265 | /// marked with the 'noderef' attribute. Expressions are checked bottom up as |
| 2266 | /// they are parsed, meaning that a noderef pointer may not be accessed. For |
| 2267 | /// example, in `&*p` where `p` is a noderef pointer, we will first parse the |
| 2268 | /// `*p`, but need to check that `address of` is called on it. This requires |
| 2269 | /// keeping a container of all pending expressions and checking if the address |
| 2270 | /// of them are eventually taken. |
| 2271 | void CheckSubscriptAccessOfNoDeref(const ArraySubscriptExpr *E); |
| 2272 | void CheckAddressOfNoDeref(const Expr *E); |
| 2273 | void CheckMemberAccessOfNoDeref(const MemberExpr *E); |
| 2274 | |
| 2275 | bool RequireCompleteTypeImpl(SourceLocation Loc, QualType T, |
| 2276 | CompleteTypeKind Kind, TypeDiagnoser *Diagnoser); |
| 2277 | |
| 2278 | struct ModuleScope { |
| 2279 | SourceLocation BeginLoc; |
| 2280 | clang::Module *Module = nullptr; |
| 2281 | bool ModuleInterface = false; |
| 2282 | VisibleModuleSet OuterVisibleModules; |
| 2283 | }; |
| 2284 | /// The modules we're currently parsing. |
| 2285 | llvm::SmallVector<ModuleScope, 16> ModuleScopes; |
| 2286 | |
| 2287 | /// For an interface unit, this is the implicitly imported interface unit. |
| 2288 | clang::Module *ThePrimaryInterface = nullptr; |
| 2289 | |
| 2290 | /// The explicit global module fragment of the current translation unit. |
| 2291 | /// The explicit Global Module Fragment, as specified in C++ |
| 2292 | /// [module.global.frag]. |
| 2293 | clang::Module *TheGlobalModuleFragment = nullptr; |
| 2294 | |
| 2295 | /// The implicit global module fragments of the current translation unit. |
| 2296 | /// We would only create at most two implicit global module fragments to |
| 2297 | /// avoid performance penalties when there are many language linkage |
| 2298 | /// exports. |
| 2299 | /// |
| 2300 | /// The contents in the implicit global module fragment can't be discarded |
| 2301 | /// no matter if it is exported or not. |
| 2302 | clang::Module *TheImplicitGlobalModuleFragment = nullptr; |
| 2303 | clang::Module *TheExportedImplicitGlobalModuleFragment = nullptr; |
| 2304 | |
| 2305 | /// Namespace definitions that we will export when they finish. |
| 2306 | llvm::SmallPtrSet<const NamespaceDecl*, 8> DeferredExportedNamespaces; |
| 2307 | |
| 2308 | /// In a C++ standard module, inline declarations require a definition to be |
| 2309 | /// present at the end of a definition domain. This set holds the decls to |
| 2310 | /// be checked at the end of the TU. |
| 2311 | llvm::SmallPtrSet<const FunctionDecl *, 8> PendingInlineFuncDecls; |
| 2312 | |
| 2313 | /// Helper function to judge if we are in module purview. |
| 2314 | /// Return false if we are not in a module. |
| 2315 | bool isCurrentModulePurview() const { |
| 2316 | return getCurrentModule() ? getCurrentModule()->isModulePurview() : false; |
| 2317 | } |
| 2318 | |
| 2319 | /// Enter the scope of the explicit global module fragment. |
| 2320 | Module *PushGlobalModuleFragment(SourceLocation BeginLoc); |
| 2321 | /// Leave the scope of the explicit global module fragment. |
| 2322 | void PopGlobalModuleFragment(); |
| 2323 | |
| 2324 | /// Enter the scope of an implicit global module fragment. |
| 2325 | Module *PushImplicitGlobalModuleFragment(SourceLocation BeginLoc, |
| 2326 | bool IsExported); |
| 2327 | /// Leave the scope of an implicit global module fragment. |
| 2328 | void PopImplicitGlobalModuleFragment(); |
| 2329 | |
| 2330 | VisibleModuleSet VisibleModules; |
| 2331 | |
| 2332 | /// Cache for module units which is usable for current module. |
| 2333 | llvm::DenseSet<const Module *> UsableModuleUnitsCache; |
| 2334 | |
| 2335 | bool isUsableModule(const Module *M); |
| 2336 | |
| 2337 | bool isAcceptableSlow(const NamedDecl *D, AcceptableKind Kind); |
| 2338 | |
| 2339 | public: |
| 2340 | /// Get the module unit whose scope we are currently within. |
| 2341 | Module *getCurrentModule() const { |
| 2342 | return ModuleScopes.empty() ? nullptr : ModuleScopes.back().Module; |
| 2343 | } |
| 2344 | |
| 2345 | /// Is the module scope we are an interface? |
| 2346 | bool currentModuleIsInterface() const { |
| 2347 | return ModuleScopes.empty() ? false : ModuleScopes.back().ModuleInterface; |
| 2348 | } |
| 2349 | |
| 2350 | /// Is the module scope we are in a C++ Header Unit? |
| 2351 | bool currentModuleIsHeaderUnit() const { |
| 2352 | return ModuleScopes.empty() ? false |
| 2353 | : ModuleScopes.back().Module->isHeaderUnit(); |
| 2354 | } |
| 2355 | |
| 2356 | /// Get the module owning an entity. |
| 2357 | Module *getOwningModule(const Decl *Entity) { |
| 2358 | return Entity->getOwningModule(); |
| 2359 | } |
| 2360 | |
| 2361 | /// Make a merged definition of an existing hidden definition \p ND |
| 2362 | /// visible at the specified location. |
| 2363 | void makeMergedDefinitionVisible(NamedDecl *ND); |
| 2364 | |
| 2365 | bool isModuleVisible(const Module *M, bool ModulePrivate = false); |
| 2366 | |
| 2367 | // When loading a non-modular PCH files, this is used to restore module |
| 2368 | // visibility. |
| 2369 | void makeModuleVisible(Module *Mod, SourceLocation ImportLoc) { |
| 2370 | VisibleModules.setVisible(Mod, ImportLoc); |
| 2371 | } |
| 2372 | |
| 2373 | /// Determine whether a declaration is visible to name lookup. |
| 2374 | bool isVisible(const NamedDecl *D) { |
| 2375 | return D->isUnconditionallyVisible() || |
| 2376 | isAcceptableSlow(D, AcceptableKind::Visible); |
| 2377 | } |
| 2378 | |
| 2379 | /// Determine whether a declaration is reachable. |
| 2380 | bool isReachable(const NamedDecl *D) { |
| 2381 | // All visible declarations are reachable. |
| 2382 | return D->isUnconditionallyVisible() || |
| 2383 | isAcceptableSlow(D, AcceptableKind::Reachable); |
| 2384 | } |
| 2385 | |
| 2386 | /// Determine whether a declaration is acceptable (visible/reachable). |
| 2387 | bool isAcceptable(const NamedDecl *D, AcceptableKind Kind) { |
| 2388 | return Kind == AcceptableKind::Visible ? isVisible(D) : isReachable(D); |
| 2389 | } |
| 2390 | |
| 2391 | /// Determine whether any declaration of an entity is visible. |
| 2392 | bool |
| 2393 | hasVisibleDeclaration(const NamedDecl *D, |
| 2394 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
| 2395 | return isVisible(D) || hasVisibleDeclarationSlow(D, Modules); |
| 2396 | } |
| 2397 | |
| 2398 | bool hasVisibleDeclarationSlow(const NamedDecl *D, |
| 2399 | llvm::SmallVectorImpl<Module *> *Modules); |
| 2400 | /// Determine whether any declaration of an entity is reachable. |
| 2401 | bool |
| 2402 | hasReachableDeclaration(const NamedDecl *D, |
| 2403 | llvm::SmallVectorImpl<Module *> *Modules = nullptr) { |
| 2404 | return isReachable(D) || hasReachableDeclarationSlow(D, Modules); |
| 2405 | } |
| 2406 | bool hasReachableDeclarationSlow( |
| 2407 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 2408 | |
| 2409 | bool hasVisibleMergedDefinition(const NamedDecl *Def); |
| 2410 | bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def); |
| 2411 | |
| 2412 | /// Determine if \p D and \p Suggested have a structurally compatible |
| 2413 | /// layout as described in C11 6.2.7/1. |
| 2414 | bool hasStructuralCompatLayout(Decl *D, Decl *Suggested); |
| 2415 | |
| 2416 | /// Determine if \p D has a visible definition. If not, suggest a declaration |
| 2417 | /// that should be made visible to expose the definition. |
| 2418 | bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, |
| 2419 | bool OnlyNeedComplete = false); |
| 2420 | bool hasVisibleDefinition(const NamedDecl *D) { |
| 2421 | NamedDecl *Hidden; |
| 2422 | return hasVisibleDefinition(const_cast<NamedDecl*>(D), &Hidden); |
| 2423 | } |
| 2424 | |
| 2425 | /// Determine if \p D has a reachable definition. If not, suggest a |
| 2426 | /// declaration that should be made reachable to expose the definition. |
| 2427 | bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, |
| 2428 | bool OnlyNeedComplete = false); |
| 2429 | bool hasReachableDefinition(NamedDecl *D) { |
| 2430 | NamedDecl *Hidden; |
| 2431 | return hasReachableDefinition(D, &Hidden); |
| 2432 | } |
| 2433 | |
| 2434 | bool hasAcceptableDefinition(NamedDecl *D, NamedDecl **Suggested, |
| 2435 | AcceptableKind Kind, |
| 2436 | bool OnlyNeedComplete = false); |
| 2437 | bool hasAcceptableDefinition(NamedDecl *D, AcceptableKind Kind) { |
| 2438 | NamedDecl *Hidden; |
| 2439 | return hasAcceptableDefinition(D, &Hidden, Kind); |
| 2440 | } |
| 2441 | |
| 2442 | /// Determine if the template parameter \p D has a visible default argument. |
| 2443 | bool |
| 2444 | hasVisibleDefaultArgument(const NamedDecl *D, |
| 2445 | llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 2446 | /// Determine if the template parameter \p D has a reachable default argument. |
| 2447 | bool hasReachableDefaultArgument( |
| 2448 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 2449 | /// Determine if the template parameter \p D has a reachable default argument. |
| 2450 | bool hasAcceptableDefaultArgument(const NamedDecl *D, |
| 2451 | llvm::SmallVectorImpl<Module *> *Modules, |
| 2452 | Sema::AcceptableKind Kind); |
| 2453 | |
| 2454 | /// Determine if there is a visible declaration of \p D that is an explicit |
| 2455 | /// specialization declaration for a specialization of a template. (For a |
| 2456 | /// member specialization, use hasVisibleMemberSpecialization.) |
| 2457 | bool hasVisibleExplicitSpecialization( |
| 2458 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 2459 | /// Determine if there is a reachable declaration of \p D that is an explicit |
| 2460 | /// specialization declaration for a specialization of a template. (For a |
| 2461 | /// member specialization, use hasReachableMemberSpecialization.) |
| 2462 | bool hasReachableExplicitSpecialization( |
| 2463 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 2464 | |
| 2465 | /// Determine if there is a visible declaration of \p D that is a member |
| 2466 | /// specialization declaration (as opposed to an instantiated declaration). |
| 2467 | bool hasVisibleMemberSpecialization( |
| 2468 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 2469 | /// Determine if there is a reachable declaration of \p D that is a member |
| 2470 | /// specialization declaration (as opposed to an instantiated declaration). |
| 2471 | bool hasReachableMemberSpecialization( |
| 2472 | const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr); |
| 2473 | |
| 2474 | /// Determine if \p A and \p B are equivalent internal linkage declarations |
| 2475 | /// from different modules, and thus an ambiguity error can be downgraded to |
| 2476 | /// an extension warning. |
| 2477 | bool isEquivalentInternalLinkageDeclaration(const NamedDecl *A, |
| 2478 | const NamedDecl *B); |
| 2479 | void diagnoseEquivalentInternalLinkageDeclarations( |
| 2480 | SourceLocation Loc, const NamedDecl *D, |
| 2481 | ArrayRef<const NamedDecl *> Equiv); |
| 2482 | |
| 2483 | bool isUsualDeallocationFunction(const CXXMethodDecl *FD); |
| 2484 | |
| 2485 | // Check whether the size of array element of type \p EltTy is a multiple of |
| 2486 | // its alignment and return false if it isn't. |
| 2487 | bool checkArrayElementAlignment(QualType EltTy, SourceLocation Loc); |
| 2488 | |
| 2489 | bool isCompleteType(SourceLocation Loc, QualType T, |
| 2490 | CompleteTypeKind Kind = CompleteTypeKind::Default) { |
| 2491 | return !RequireCompleteTypeImpl(Loc, T, Kind, nullptr); |
| 2492 | } |
| 2493 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
| 2494 | CompleteTypeKind Kind, TypeDiagnoser &Diagnoser); |
| 2495 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
| 2496 | CompleteTypeKind Kind, unsigned DiagID); |
| 2497 | |
| 2498 | bool RequireCompleteType(SourceLocation Loc, QualType T, |
| 2499 | TypeDiagnoser &Diagnoser) { |
| 2500 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, Diagnoser); |
| 2501 | } |
| 2502 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID) { |
| 2503 | return RequireCompleteType(Loc, T, CompleteTypeKind::Default, DiagID); |
| 2504 | } |
| 2505 | |
| 2506 | template <typename... Ts> |
| 2507 | bool RequireCompleteType(SourceLocation Loc, QualType T, unsigned DiagID, |
| 2508 | const Ts &...Args) { |
| 2509 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 2510 | return RequireCompleteType(Loc, T, Diagnoser); |
| 2511 | } |
| 2512 | |
| 2513 | template <typename... Ts> |
| 2514 | bool RequireCompleteSizedType(SourceLocation Loc, QualType T, unsigned DiagID, |
| 2515 | const Ts &... Args) { |
| 2516 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 2517 | return RequireCompleteType(Loc, T, CompleteTypeKind::Normal, Diagnoser); |
| 2518 | } |
| 2519 | |
| 2520 | /// Get the type of expression E, triggering instantiation to complete the |
| 2521 | /// type if necessary -- that is, if the expression refers to a templated |
| 2522 | /// static data member of incomplete array type. |
| 2523 | /// |
| 2524 | /// May still return an incomplete type if instantiation was not possible or |
| 2525 | /// if the type is incomplete for a different reason. Use |
| 2526 | /// RequireCompleteExprType instead if a diagnostic is expected for an |
| 2527 | /// incomplete expression type. |
| 2528 | QualType getCompletedType(Expr *E); |
| 2529 | |
| 2530 | void completeExprArrayBound(Expr *E); |
| 2531 | bool RequireCompleteExprType(Expr *E, CompleteTypeKind Kind, |
| 2532 | TypeDiagnoser &Diagnoser); |
| 2533 | bool RequireCompleteExprType(Expr *E, unsigned DiagID); |
| 2534 | |
| 2535 | template <typename... Ts> |
| 2536 | bool RequireCompleteExprType(Expr *E, unsigned DiagID, const Ts &...Args) { |
| 2537 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 2538 | return RequireCompleteExprType(E, CompleteTypeKind::Default, Diagnoser); |
| 2539 | } |
| 2540 | |
| 2541 | template <typename... Ts> |
| 2542 | bool RequireCompleteSizedExprType(Expr *E, unsigned DiagID, |
| 2543 | const Ts &... Args) { |
| 2544 | SizelessTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 2545 | return RequireCompleteExprType(E, CompleteTypeKind::Normal, Diagnoser); |
| 2546 | } |
| 2547 | |
| 2548 | bool RequireLiteralType(SourceLocation Loc, QualType T, |
| 2549 | TypeDiagnoser &Diagnoser); |
| 2550 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID); |
| 2551 | |
| 2552 | template <typename... Ts> |
| 2553 | bool RequireLiteralType(SourceLocation Loc, QualType T, unsigned DiagID, |
| 2554 | const Ts &...Args) { |
| 2555 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 2556 | return RequireLiteralType(Loc, T, Diagnoser); |
| 2557 | } |
| 2558 | |
| 2559 | QualType getElaboratedType(ElaboratedTypeKeyword Keyword, |
| 2560 | const CXXScopeSpec &SS, QualType T, |
| 2561 | TagDecl *OwnedTagDecl = nullptr); |
| 2562 | |
| 2563 | // Returns the underlying type of a decltype with the given expression. |
| 2564 | QualType getDecltypeForExpr(Expr *E); |
| 2565 | |
| 2566 | QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind); |
| 2567 | /// If AsUnevaluated is false, E is treated as though it were an evaluated |
| 2568 | /// context, such as when building a type for decltype(auto). |
| 2569 | QualType BuildDecltypeType(Expr *E, bool AsUnevaluated = true); |
| 2570 | |
| 2571 | using UTTKind = UnaryTransformType::UTTKind; |
| 2572 | QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, |
| 2573 | SourceLocation Loc); |
| 2574 | QualType BuiltinEnumUnderlyingType(QualType BaseType, SourceLocation Loc); |
| 2575 | QualType BuiltinAddPointer(QualType BaseType, SourceLocation Loc); |
| 2576 | QualType BuiltinRemovePointer(QualType BaseType, SourceLocation Loc); |
| 2577 | QualType BuiltinDecay(QualType BaseType, SourceLocation Loc); |
| 2578 | QualType BuiltinAddReference(QualType BaseType, UTTKind UKind, |
| 2579 | SourceLocation Loc); |
| 2580 | QualType BuiltinRemoveExtent(QualType BaseType, UTTKind UKind, |
| 2581 | SourceLocation Loc); |
| 2582 | QualType BuiltinRemoveReference(QualType BaseType, UTTKind UKind, |
| 2583 | SourceLocation Loc); |
| 2584 | QualType BuiltinChangeCVRQualifiers(QualType BaseType, UTTKind UKind, |
| 2585 | SourceLocation Loc); |
| 2586 | QualType BuiltinChangeSignedness(QualType BaseType, UTTKind UKind, |
| 2587 | SourceLocation Loc); |
| 2588 | |
| 2589 | //===--------------------------------------------------------------------===// |
| 2590 | // Symbol table / Decl tracking callbacks: SemaDecl.cpp. |
| 2591 | // |
| 2592 | |
| 2593 | struct SkipBodyInfo { |
| 2594 | SkipBodyInfo() = default; |
| 2595 | bool ShouldSkip = false; |
| 2596 | bool CheckSameAsPrevious = false; |
| 2597 | NamedDecl *Previous = nullptr; |
| 2598 | NamedDecl *New = nullptr; |
| 2599 | }; |
| 2600 | |
| 2601 | DeclGroupPtrTy ConvertDeclToDeclGroup(Decl *Ptr, Decl *OwnedType = nullptr); |
| 2602 | |
| 2603 | void DiagnoseUseOfUnimplementedSelectors(); |
| 2604 | |
| 2605 | bool isSimpleTypeSpecifier(tok::TokenKind Kind) const; |
| 2606 | |
| 2607 | ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, |
| 2608 | Scope *S, CXXScopeSpec *SS = nullptr, |
| 2609 | bool isClassName = false, bool HasTrailingDot = false, |
| 2610 | ParsedType ObjectType = nullptr, |
| 2611 | bool IsCtorOrDtorName = false, |
| 2612 | bool WantNontrivialTypeSourceInfo = false, |
| 2613 | bool IsClassTemplateDeductionContext = true, |
| 2614 | ImplicitTypenameContext AllowImplicitTypename = |
| 2615 | ImplicitTypenameContext::No, |
| 2616 | IdentifierInfo **CorrectedII = nullptr); |
| 2617 | TypeSpecifierType isTagName(IdentifierInfo &II, Scope *S); |
| 2618 | bool isMicrosoftMissingTypename(const CXXScopeSpec *SS, Scope *S); |
| 2619 | void DiagnoseUnknownTypeName(IdentifierInfo *&II, |
| 2620 | SourceLocation IILoc, |
| 2621 | Scope *S, |
| 2622 | CXXScopeSpec *SS, |
| 2623 | ParsedType &SuggestedType, |
| 2624 | bool IsTemplateName = false); |
| 2625 | |
| 2626 | /// Attempt to behave like MSVC in situations where lookup of an unqualified |
| 2627 | /// type name has failed in a dependent context. In these situations, we |
| 2628 | /// automatically form a DependentTypeName that will retry lookup in a related |
| 2629 | /// scope during instantiation. |
| 2630 | ParsedType ActOnMSVCUnknownTypeName(const IdentifierInfo &II, |
| 2631 | SourceLocation NameLoc, |
| 2632 | bool IsTemplateTypeArg); |
| 2633 | |
| 2634 | /// Describes the result of the name lookup and resolution performed |
| 2635 | /// by \c ClassifyName(). |
| 2636 | enum NameClassificationKind { |
| 2637 | /// This name is not a type or template in this context, but might be |
| 2638 | /// something else. |
| 2639 | NC_Unknown, |
| 2640 | /// Classification failed; an error has been produced. |
| 2641 | NC_Error, |
| 2642 | /// The name has been typo-corrected to a keyword. |
| 2643 | NC_Keyword, |
| 2644 | /// The name was classified as a type. |
| 2645 | NC_Type, |
| 2646 | /// The name was classified as a specific non-type, non-template |
| 2647 | /// declaration. ActOnNameClassifiedAsNonType should be called to |
| 2648 | /// convert the declaration to an expression. |
| 2649 | NC_NonType, |
| 2650 | /// The name was classified as an ADL-only function name. |
| 2651 | /// ActOnNameClassifiedAsUndeclaredNonType should be called to convert the |
| 2652 | /// result to an expression. |
| 2653 | NC_UndeclaredNonType, |
| 2654 | /// The name denotes a member of a dependent type that could not be |
| 2655 | /// resolved. ActOnNameClassifiedAsDependentNonType should be called to |
| 2656 | /// convert the result to an expression. |
| 2657 | NC_DependentNonType, |
| 2658 | /// The name was classified as an overload set, and an expression |
| 2659 | /// representing that overload set has been formed. |
| 2660 | /// ActOnNameClassifiedAsOverloadSet should be called to form a suitable |
| 2661 | /// expression referencing the overload set. |
| 2662 | NC_OverloadSet, |
| 2663 | /// The name was classified as a template whose specializations are types. |
| 2664 | NC_TypeTemplate, |
| 2665 | /// The name was classified as a variable template name. |
| 2666 | NC_VarTemplate, |
| 2667 | /// The name was classified as a function template name. |
| 2668 | NC_FunctionTemplate, |
| 2669 | /// The name was classified as an ADL-only function template name. |
| 2670 | NC_UndeclaredTemplate, |
| 2671 | /// The name was classified as a concept name. |
| 2672 | NC_Concept, |
| 2673 | }; |
| 2674 | |
| 2675 | class NameClassification { |
| 2676 | NameClassificationKind Kind; |
| 2677 | union { |
| 2678 | ExprResult Expr; |
| 2679 | NamedDecl *NonTypeDecl; |
| 2680 | TemplateName Template; |
| 2681 | ParsedType Type; |
| 2682 | }; |
| 2683 | |
| 2684 | explicit NameClassification(NameClassificationKind Kind) : Kind(Kind) {} |
| 2685 | |
| 2686 | public: |
| 2687 | NameClassification(ParsedType Type) : Kind(NC_Type), Type(Type) {} |
| 2688 | |
| 2689 | NameClassification(const IdentifierInfo *Keyword) : Kind(NC_Keyword) {} |
| 2690 | |
| 2691 | static NameClassification Error() { |
| 2692 | return NameClassification(NC_Error); |
| 2693 | } |
| 2694 | |
| 2695 | static NameClassification Unknown() { |
| 2696 | return NameClassification(NC_Unknown); |
| 2697 | } |
| 2698 | |
| 2699 | static NameClassification OverloadSet(ExprResult E) { |
| 2700 | NameClassification Result(NC_OverloadSet); |
| 2701 | Result.Expr = E; |
| 2702 | return Result; |
| 2703 | } |
| 2704 | |
| 2705 | static NameClassification NonType(NamedDecl *D) { |
| 2706 | NameClassification Result(NC_NonType); |
| 2707 | Result.NonTypeDecl = D; |
| 2708 | return Result; |
| 2709 | } |
| 2710 | |
| 2711 | static NameClassification UndeclaredNonType() { |
| 2712 | return NameClassification(NC_UndeclaredNonType); |
| 2713 | } |
| 2714 | |
| 2715 | static NameClassification DependentNonType() { |
| 2716 | return NameClassification(NC_DependentNonType); |
| 2717 | } |
| 2718 | |
| 2719 | static NameClassification TypeTemplate(TemplateName Name) { |
| 2720 | NameClassification Result(NC_TypeTemplate); |
| 2721 | Result.Template = Name; |
| 2722 | return Result; |
| 2723 | } |
| 2724 | |
| 2725 | static NameClassification VarTemplate(TemplateName Name) { |
| 2726 | NameClassification Result(NC_VarTemplate); |
| 2727 | Result.Template = Name; |
| 2728 | return Result; |
| 2729 | } |
| 2730 | |
| 2731 | static NameClassification FunctionTemplate(TemplateName Name) { |
| 2732 | NameClassification Result(NC_FunctionTemplate); |
| 2733 | Result.Template = Name; |
| 2734 | return Result; |
| 2735 | } |
| 2736 | |
| 2737 | static NameClassification Concept(TemplateName Name) { |
| 2738 | NameClassification Result(NC_Concept); |
| 2739 | Result.Template = Name; |
| 2740 | return Result; |
| 2741 | } |
| 2742 | |
| 2743 | static NameClassification UndeclaredTemplate(TemplateName Name) { |
| 2744 | NameClassification Result(NC_UndeclaredTemplate); |
| 2745 | Result.Template = Name; |
| 2746 | return Result; |
| 2747 | } |
| 2748 | |
| 2749 | NameClassificationKind getKind() const { return Kind; } |
| 2750 | |
| 2751 | ExprResult getExpression() const { |
| 2752 | assert(Kind == NC_OverloadSet)(static_cast <bool> (Kind == NC_OverloadSet) ? void (0) : __assert_fail ("Kind == NC_OverloadSet", "clang/include/clang/Sema/Sema.h" , 2752, __extension__ __PRETTY_FUNCTION__)); |
| 2753 | return Expr; |
| 2754 | } |
| 2755 | |
| 2756 | ParsedType getType() const { |
| 2757 | assert(Kind == NC_Type)(static_cast <bool> (Kind == NC_Type) ? void (0) : __assert_fail ("Kind == NC_Type", "clang/include/clang/Sema/Sema.h", 2757, __extension__ __PRETTY_FUNCTION__)); |
| 2758 | return Type; |
| 2759 | } |
| 2760 | |
| 2761 | NamedDecl *getNonTypeDecl() const { |
| 2762 | assert(Kind == NC_NonType)(static_cast <bool> (Kind == NC_NonType) ? void (0) : __assert_fail ("Kind == NC_NonType", "clang/include/clang/Sema/Sema.h", 2762 , __extension__ __PRETTY_FUNCTION__)); |
| 2763 | return NonTypeDecl; |
| 2764 | } |
| 2765 | |
| 2766 | TemplateName getTemplateName() const { |
| 2767 | assert(Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate ||(static_cast <bool> (Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate) ? void (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate" , "clang/include/clang/Sema/Sema.h", 2769, __extension__ __PRETTY_FUNCTION__ )) |
| 2768 | Kind == NC_VarTemplate || Kind == NC_Concept ||(static_cast <bool> (Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate) ? void (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate" , "clang/include/clang/Sema/Sema.h", 2769, __extension__ __PRETTY_FUNCTION__ )) |
| 2769 | Kind == NC_UndeclaredTemplate)(static_cast <bool> (Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate) ? void (0) : __assert_fail ("Kind == NC_TypeTemplate || Kind == NC_FunctionTemplate || Kind == NC_VarTemplate || Kind == NC_Concept || Kind == NC_UndeclaredTemplate" , "clang/include/clang/Sema/Sema.h", 2769, __extension__ __PRETTY_FUNCTION__ )); |
| 2770 | return Template; |
| 2771 | } |
| 2772 | |
| 2773 | TemplateNameKind getTemplateNameKind() const { |
| 2774 | switch (Kind) { |
| 2775 | case NC_TypeTemplate: |
| 2776 | return TNK_Type_template; |
| 2777 | case NC_FunctionTemplate: |
| 2778 | return TNK_Function_template; |
| 2779 | case NC_VarTemplate: |
| 2780 | return TNK_Var_template; |
| 2781 | case NC_Concept: |
| 2782 | return TNK_Concept_template; |
| 2783 | case NC_UndeclaredTemplate: |
| 2784 | return TNK_Undeclared_template; |
| 2785 | default: |
| 2786 | llvm_unreachable("unsupported name classification.")::llvm::llvm_unreachable_internal("unsupported name classification." , "clang/include/clang/Sema/Sema.h", 2786); |
| 2787 | } |
| 2788 | } |
| 2789 | }; |
| 2790 | |
| 2791 | /// Perform name lookup on the given name, classifying it based on |
| 2792 | /// the results of name lookup and the following token. |
| 2793 | /// |
| 2794 | /// This routine is used by the parser to resolve identifiers and help direct |
| 2795 | /// parsing. When the identifier cannot be found, this routine will attempt |
| 2796 | /// to correct the typo and classify based on the resulting name. |
| 2797 | /// |
| 2798 | /// \param S The scope in which we're performing name lookup. |
| 2799 | /// |
| 2800 | /// \param SS The nested-name-specifier that precedes the name. |
| 2801 | /// |
| 2802 | /// \param Name The identifier. If typo correction finds an alternative name, |
| 2803 | /// this pointer parameter will be updated accordingly. |
| 2804 | /// |
| 2805 | /// \param NameLoc The location of the identifier. |
| 2806 | /// |
| 2807 | /// \param NextToken The token following the identifier. Used to help |
| 2808 | /// disambiguate the name. |
| 2809 | /// |
| 2810 | /// \param CCC The correction callback, if typo correction is desired. |
| 2811 | NameClassification ClassifyName(Scope *S, CXXScopeSpec &SS, |
| 2812 | IdentifierInfo *&Name, SourceLocation NameLoc, |
| 2813 | const Token &NextToken, |
| 2814 | CorrectionCandidateCallback *CCC = nullptr); |
| 2815 | |
| 2816 | /// Act on the result of classifying a name as an undeclared (ADL-only) |
| 2817 | /// non-type declaration. |
| 2818 | ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, |
| 2819 | SourceLocation NameLoc); |
| 2820 | /// Act on the result of classifying a name as an undeclared member of a |
| 2821 | /// dependent base class. |
| 2822 | ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, |
| 2823 | IdentifierInfo *Name, |
| 2824 | SourceLocation NameLoc, |
| 2825 | bool IsAddressOfOperand); |
| 2826 | /// Act on the result of classifying a name as a specific non-type |
| 2827 | /// declaration. |
| 2828 | ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, |
| 2829 | NamedDecl *Found, |
| 2830 | SourceLocation NameLoc, |
| 2831 | const Token &NextToken); |
| 2832 | /// Act on the result of classifying a name as an overload set. |
| 2833 | ExprResult ActOnNameClassifiedAsOverloadSet(Scope *S, Expr *OverloadSet); |
| 2834 | |
| 2835 | /// Describes the detailed kind of a template name. Used in diagnostics. |
| 2836 | enum class TemplateNameKindForDiagnostics { |
| 2837 | ClassTemplate, |
| 2838 | FunctionTemplate, |
| 2839 | VarTemplate, |
| 2840 | AliasTemplate, |
| 2841 | TemplateTemplateParam, |
| 2842 | Concept, |
| 2843 | DependentTemplate |
| 2844 | }; |
| 2845 | TemplateNameKindForDiagnostics |
| 2846 | getTemplateNameKindForDiagnostics(TemplateName Name); |
| 2847 | |
| 2848 | /// Determine whether it's plausible that E was intended to be a |
| 2849 | /// template-name. |
| 2850 | bool mightBeIntendedToBeTemplateName(ExprResult E, bool &Dependent) { |
| 2851 | if (!getLangOpts().CPlusPlus || E.isInvalid()) |
| 2852 | return false; |
| 2853 | Dependent = false; |
| 2854 | if (auto *DRE = dyn_cast<DeclRefExpr>(E.get())) |
| 2855 | return !DRE->hasExplicitTemplateArgs(); |
| 2856 | if (auto *ME = dyn_cast<MemberExpr>(E.get())) |
| 2857 | return !ME->hasExplicitTemplateArgs(); |
| 2858 | Dependent = true; |
| 2859 | if (auto *DSDRE = dyn_cast<DependentScopeDeclRefExpr>(E.get())) |
| 2860 | return !DSDRE->hasExplicitTemplateArgs(); |
| 2861 | if (auto *DSME = dyn_cast<CXXDependentScopeMemberExpr>(E.get())) |
| 2862 | return !DSME->hasExplicitTemplateArgs(); |
| 2863 | // Any additional cases recognized here should also be handled by |
| 2864 | // diagnoseExprIntendedAsTemplateName. |
| 2865 | return false; |
| 2866 | } |
| 2867 | void diagnoseExprIntendedAsTemplateName(Scope *S, ExprResult TemplateName, |
| 2868 | SourceLocation Less, |
| 2869 | SourceLocation Greater); |
| 2870 | |
| 2871 | void warnOnReservedIdentifier(const NamedDecl *D); |
| 2872 | |
| 2873 | Decl *ActOnDeclarator(Scope *S, Declarator &D); |
| 2874 | |
| 2875 | NamedDecl *HandleDeclarator(Scope *S, Declarator &D, |
| 2876 | MultiTemplateParamsArg TemplateParameterLists); |
| 2877 | bool tryToFixVariablyModifiedVarType(TypeSourceInfo *&TInfo, |
| 2878 | QualType &T, SourceLocation Loc, |
| 2879 | unsigned FailedFoldDiagID); |
| 2880 | void RegisterLocallyScopedExternCDecl(NamedDecl *ND, Scope *S); |
| 2881 | bool DiagnoseClassNameShadow(DeclContext *DC, DeclarationNameInfo Info); |
| 2882 | bool diagnoseQualifiedDeclaration(CXXScopeSpec &SS, DeclContext *DC, |
| 2883 | DeclarationName Name, SourceLocation Loc, |
| 2884 | bool IsTemplateId); |
| 2885 | void |
| 2886 | diagnoseIgnoredQualifiers(unsigned DiagID, unsigned Quals, |
| 2887 | SourceLocation FallbackLoc, |
| 2888 | SourceLocation ConstQualLoc = SourceLocation(), |
| 2889 | SourceLocation VolatileQualLoc = SourceLocation(), |
| 2890 | SourceLocation RestrictQualLoc = SourceLocation(), |
| 2891 | SourceLocation AtomicQualLoc = SourceLocation(), |
| 2892 | SourceLocation UnalignedQualLoc = SourceLocation()); |
| 2893 | |
| 2894 | static bool adjustContextForLocalExternDecl(DeclContext *&DC); |
| 2895 | void DiagnoseFunctionSpecifiers(const DeclSpec &DS); |
| 2896 | NamedDecl *getShadowedDeclaration(const TypedefNameDecl *D, |
| 2897 | const LookupResult &R); |
| 2898 | NamedDecl *getShadowedDeclaration(const VarDecl *D, const LookupResult &R); |
| 2899 | NamedDecl *getShadowedDeclaration(const BindingDecl *D, |
| 2900 | const LookupResult &R); |
| 2901 | void CheckShadow(NamedDecl *D, NamedDecl *ShadowedDecl, |
| 2902 | const LookupResult &R); |
| 2903 | void CheckShadow(Scope *S, VarDecl *D); |
| 2904 | |
| 2905 | /// Warn if 'E', which is an expression that is about to be modified, refers |
| 2906 | /// to a shadowing declaration. |
| 2907 | void CheckShadowingDeclModification(Expr *E, SourceLocation Loc); |
| 2908 | |
| 2909 | void DiagnoseShadowingLambdaDecls(const sema::LambdaScopeInfo *LSI); |
| 2910 | |
| 2911 | private: |
| 2912 | /// Map of current shadowing declarations to shadowed declarations. Warn if |
| 2913 | /// it looks like the user is trying to modify the shadowing declaration. |
| 2914 | llvm::DenseMap<const NamedDecl *, const NamedDecl *> ShadowingDecls; |
| 2915 | |
| 2916 | public: |
| 2917 | void CheckCastAlign(Expr *Op, QualType T, SourceRange TRange); |
| 2918 | void handleTagNumbering(const TagDecl *Tag, Scope *TagScope); |
| 2919 | void setTagNameForLinkagePurposes(TagDecl *TagFromDeclSpec, |
| 2920 | TypedefNameDecl *NewTD); |
| 2921 | void CheckTypedefForVariablyModifiedType(Scope *S, TypedefNameDecl *D); |
| 2922 | NamedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
| 2923 | TypeSourceInfo *TInfo, |
| 2924 | LookupResult &Previous); |
| 2925 | NamedDecl* ActOnTypedefNameDecl(Scope* S, DeclContext* DC, TypedefNameDecl *D, |
| 2926 | LookupResult &Previous, bool &Redeclaration); |
| 2927 | NamedDecl *ActOnVariableDeclarator( |
| 2928 | Scope *S, Declarator &D, DeclContext *DC, TypeSourceInfo *TInfo, |
| 2929 | LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, |
| 2930 | bool &AddToScope, ArrayRef<BindingDecl *> Bindings = std::nullopt); |
| 2931 | NamedDecl * |
| 2932 | ActOnDecompositionDeclarator(Scope *S, Declarator &D, |
| 2933 | MultiTemplateParamsArg TemplateParamLists); |
| 2934 | // Returns true if the variable declaration is a redeclaration |
| 2935 | bool CheckVariableDeclaration(VarDecl *NewVD, LookupResult &Previous); |
| 2936 | void CheckVariableDeclarationType(VarDecl *NewVD); |
| 2937 | bool DeduceVariableDeclarationType(VarDecl *VDecl, bool DirectInit, |
| 2938 | Expr *Init); |
| 2939 | void CheckCompleteVariableDeclaration(VarDecl *VD); |
| 2940 | void CheckCompleteDecompositionDeclaration(DecompositionDecl *DD); |
| 2941 | void MaybeSuggestAddingStaticToDecl(const FunctionDecl *D); |
| 2942 | |
| 2943 | NamedDecl* ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, |
| 2944 | TypeSourceInfo *TInfo, |
| 2945 | LookupResult &Previous, |
| 2946 | MultiTemplateParamsArg TemplateParamLists, |
| 2947 | bool &AddToScope); |
| 2948 | bool AddOverriddenMethods(CXXRecordDecl *DC, CXXMethodDecl *MD); |
| 2949 | |
| 2950 | enum class CheckConstexprKind { |
| 2951 | /// Diagnose issues that are non-constant or that are extensions. |
| 2952 | Diagnose, |
| 2953 | /// Identify whether this function satisfies the formal rules for constexpr |
| 2954 | /// functions in the current lanugage mode (with no extensions). |
| 2955 | CheckValid |
| 2956 | }; |
| 2957 | |
| 2958 | bool CheckConstexprFunctionDefinition(const FunctionDecl *FD, |
| 2959 | CheckConstexprKind Kind); |
| 2960 | |
| 2961 | void DiagnoseHiddenVirtualMethods(CXXMethodDecl *MD); |
| 2962 | void FindHiddenVirtualMethods(CXXMethodDecl *MD, |
| 2963 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
| 2964 | void NoteHiddenVirtualMethods(CXXMethodDecl *MD, |
| 2965 | SmallVectorImpl<CXXMethodDecl*> &OverloadedMethods); |
| 2966 | // Returns true if the function declaration is a redeclaration |
| 2967 | bool CheckFunctionDeclaration(Scope *S, |
| 2968 | FunctionDecl *NewFD, LookupResult &Previous, |
| 2969 | bool IsMemberSpecialization, bool DeclIsDefn); |
| 2970 | bool shouldLinkDependentDeclWithPrevious(Decl *D, Decl *OldDecl); |
| 2971 | bool canFullyTypeCheckRedeclaration(ValueDecl *NewD, ValueDecl *OldD, |
| 2972 | QualType NewT, QualType OldT); |
| 2973 | void CheckMain(FunctionDecl *FD, const DeclSpec &D); |
| 2974 | void CheckMSVCRTEntryPoint(FunctionDecl *FD); |
| 2975 | void CheckHLSLEntryPoint(FunctionDecl *FD); |
| 2976 | Attr *getImplicitCodeSegOrSectionAttrForFunction(const FunctionDecl *FD, |
| 2977 | bool IsDefinition); |
| 2978 | void CheckFunctionOrTemplateParamDeclarator(Scope *S, Declarator &D); |
| 2979 | Decl *ActOnParamDeclarator(Scope *S, Declarator &D); |
| 2980 | ParmVarDecl *BuildParmVarDeclForTypedef(DeclContext *DC, |
| 2981 | SourceLocation Loc, |
| 2982 | QualType T); |
| 2983 | ParmVarDecl *CheckParameter(DeclContext *DC, SourceLocation StartLoc, |
| 2984 | SourceLocation NameLoc, IdentifierInfo *Name, |
| 2985 | QualType T, TypeSourceInfo *TSInfo, |
| 2986 | StorageClass SC); |
| 2987 | void ActOnParamDefaultArgument(Decl *param, |
| 2988 | SourceLocation EqualLoc, |
| 2989 | Expr *defarg); |
| 2990 | void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, |
| 2991 | SourceLocation ArgLoc); |
| 2992 | void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc); |
| 2993 | ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
| 2994 | SourceLocation EqualLoc); |
| 2995 | void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, |
| 2996 | SourceLocation EqualLoc); |
| 2997 | |
| 2998 | // Contexts where using non-trivial C union types can be disallowed. This is |
| 2999 | // passed to err_non_trivial_c_union_in_invalid_context. |
| 3000 | enum NonTrivialCUnionContext { |
| 3001 | // Function parameter. |
| 3002 | NTCUC_FunctionParam, |
| 3003 | // Function return. |
| 3004 | NTCUC_FunctionReturn, |
| 3005 | // Default-initialized object. |
| 3006 | NTCUC_DefaultInitializedObject, |
| 3007 | // Variable with automatic storage duration. |
| 3008 | NTCUC_AutoVar, |
| 3009 | // Initializer expression that might copy from another object. |
| 3010 | NTCUC_CopyInit, |
| 3011 | // Assignment. |
| 3012 | NTCUC_Assignment, |
| 3013 | // Compound literal. |
| 3014 | NTCUC_CompoundLiteral, |
| 3015 | // Block capture. |
| 3016 | NTCUC_BlockCapture, |
| 3017 | // lvalue-to-rvalue conversion of volatile type. |
| 3018 | NTCUC_LValueToRValueVolatile, |
| 3019 | }; |
| 3020 | |
| 3021 | /// Emit diagnostics if the initializer or any of its explicit or |
| 3022 | /// implicitly-generated subexpressions require copying or |
| 3023 | /// default-initializing a type that is or contains a C union type that is |
| 3024 | /// non-trivial to copy or default-initialize. |
| 3025 | void checkNonTrivialCUnionInInitializer(const Expr *Init, SourceLocation Loc); |
| 3026 | |
| 3027 | // These flags are passed to checkNonTrivialCUnion. |
| 3028 | enum NonTrivialCUnionKind { |
| 3029 | NTCUK_Init = 0x1, |
| 3030 | NTCUK_Destruct = 0x2, |
| 3031 | NTCUK_Copy = 0x4, |
| 3032 | }; |
| 3033 | |
| 3034 | /// Emit diagnostics if a non-trivial C union type or a struct that contains |
| 3035 | /// a non-trivial C union is used in an invalid context. |
| 3036 | void checkNonTrivialCUnion(QualType QT, SourceLocation Loc, |
| 3037 | NonTrivialCUnionContext UseContext, |
| 3038 | unsigned NonTrivialKind); |
| 3039 | |
| 3040 | void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit); |
| 3041 | void ActOnUninitializedDecl(Decl *dcl); |
| 3042 | void ActOnInitializerError(Decl *Dcl); |
| 3043 | |
| 3044 | void ActOnPureSpecifier(Decl *D, SourceLocation PureSpecLoc); |
| 3045 | void ActOnCXXForRangeDecl(Decl *D); |
| 3046 | StmtResult ActOnCXXForRangeIdentifier(Scope *S, SourceLocation IdentLoc, |
| 3047 | IdentifierInfo *Ident, |
| 3048 | ParsedAttributes &Attrs); |
| 3049 | void SetDeclDeleted(Decl *dcl, SourceLocation DelLoc); |
| 3050 | void SetDeclDefaulted(Decl *dcl, SourceLocation DefaultLoc); |
| 3051 | void CheckStaticLocalForDllExport(VarDecl *VD); |
| 3052 | void CheckThreadLocalForLargeAlignment(VarDecl *VD); |
| 3053 | void FinalizeDeclaration(Decl *D); |
| 3054 | DeclGroupPtrTy FinalizeDeclaratorGroup(Scope *S, const DeclSpec &DS, |
| 3055 | ArrayRef<Decl *> Group); |
| 3056 | DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef<Decl *> Group); |
| 3057 | |
| 3058 | /// Should be called on all declarations that might have attached |
| 3059 | /// documentation comments. |
| 3060 | void ActOnDocumentableDecl(Decl *D); |
| 3061 | void ActOnDocumentableDecls(ArrayRef<Decl *> Group); |
| 3062 | |
| 3063 | enum class FnBodyKind { |
| 3064 | /// C++ [dcl.fct.def.general]p1 |
| 3065 | /// function-body: |
| 3066 | /// ctor-initializer[opt] compound-statement |
| 3067 | /// function-try-block |
| 3068 | Other, |
| 3069 | /// = default ; |
| 3070 | Default, |
| 3071 | /// = delete ; |
| 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 SetFunctionBodyKind(Decl *D, SourceLocation Loc, FnBodyKind BodyKind); |
| 3088 | void ActOnStartTrailingRequiresClause(Scope *S, Declarator &D); |
| 3089 | ExprResult ActOnFinishTrailingRequiresClause(ExprResult ConstraintExpr); |
| 3090 | ExprResult ActOnRequiresClause(ExprResult ConstraintExpr); |
| 3091 | void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); |
| 3092 | bool isObjCMethodDecl(Decl *D) { |
| 3093 | return D && isa<ObjCMethodDecl>(D); |
| 3094 | } |
| 3095 | |
| 3096 | /// Determine whether we can delay parsing the body of a function or |
| 3097 | /// function template until it is used, assuming we don't care about emitting |
| 3098 | /// code for that function. |
| 3099 | /// |
| 3100 | /// This will be \c false if we may need the body of the function in the |
| 3101 | /// middle of parsing an expression (where it's impractical to switch to |
| 3102 | /// parsing a different function), for instance, if it's constexpr in C++11 |
| 3103 | /// or has an 'auto' return type in C++14. These cases are essentially bugs. |
| 3104 | bool canDelayFunctionBody(const Declarator &D); |
| 3105 | |
| 3106 | /// Determine whether we can skip parsing the body of a function |
| 3107 | /// definition, assuming we don't care about analyzing its body or emitting |
| 3108 | /// code for that function. |
| 3109 | /// |
| 3110 | /// This will be \c false only if we may need the body of the function in |
| 3111 | /// order to parse the rest of the program (for instance, if it is |
| 3112 | /// \c constexpr in C++11 or has an 'auto' return type in C++14). |
| 3113 | bool canSkipFunctionBody(Decl *D); |
| 3114 | |
| 3115 | /// Determine whether \param D is function like (function or function |
| 3116 | /// template) for parsing. |
| 3117 | bool isDeclaratorFunctionLike(Declarator &D); |
| 3118 | |
| 3119 | void computeNRVO(Stmt *Body, sema::FunctionScopeInfo *Scope); |
| 3120 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body); |
| 3121 | Decl *ActOnFinishFunctionBody(Decl *Decl, Stmt *Body, bool IsInstantiation); |
| 3122 | Decl *ActOnSkippedFunctionBody(Decl *Decl); |
| 3123 | void ActOnFinishInlineFunctionDef(FunctionDecl *D); |
| 3124 | |
| 3125 | /// ActOnFinishDelayedAttribute - Invoked when we have finished parsing an |
| 3126 | /// attribute for which parsing is delayed. |
| 3127 | void ActOnFinishDelayedAttribute(Scope *S, Decl *D, ParsedAttributes &Attrs); |
| 3128 | |
| 3129 | /// Diagnose any unused parameters in the given sequence of |
| 3130 | /// ParmVarDecl pointers. |
| 3131 | void DiagnoseUnusedParameters(ArrayRef<ParmVarDecl *> Parameters); |
| 3132 | |
| 3133 | /// Diagnose whether the size of parameters or return value of a |
| 3134 | /// function or obj-c method definition is pass-by-value and larger than a |
| 3135 | /// specified threshold. |
| 3136 | void |
| 3137 | DiagnoseSizeOfParametersAndReturnValue(ArrayRef<ParmVarDecl *> Parameters, |
| 3138 | QualType ReturnTy, NamedDecl *D); |
| 3139 | |
| 3140 | void DiagnoseInvalidJumps(Stmt *Body); |
| 3141 | Decl *ActOnFileScopeAsmDecl(Expr *expr, |
| 3142 | SourceLocation AsmLoc, |
| 3143 | SourceLocation RParenLoc); |
| 3144 | |
| 3145 | Decl *ActOnTopLevelStmtDecl(Stmt *Statement); |
| 3146 | |
| 3147 | /// Handle a C++11 empty-declaration and attribute-declaration. |
| 3148 | Decl *ActOnEmptyDeclaration(Scope *S, const ParsedAttributesView &AttrList, |
| 3149 | SourceLocation SemiLoc); |
| 3150 | |
| 3151 | enum class ModuleDeclKind { |
| 3152 | Interface, ///< 'export module X;' |
| 3153 | Implementation, ///< 'module X;' |
| 3154 | PartitionInterface, ///< 'export module X:Y;' |
| 3155 | PartitionImplementation, ///< 'module X:Y;' |
| 3156 | }; |
| 3157 | |
| 3158 | /// An enumeration to represent the transition of states in parsing module |
| 3159 | /// fragments and imports. If we are not parsing a C++20 TU, or we find |
| 3160 | /// an error in state transition, the state is set to NotACXX20Module. |
| 3161 | enum class ModuleImportState { |
| 3162 | FirstDecl, ///< Parsing the first decl in a TU. |
| 3163 | GlobalFragment, ///< after 'module;' but before 'module X;' |
| 3164 | ImportAllowed, ///< after 'module X;' but before any non-import decl. |
| 3165 | ImportFinished, ///< after any non-import decl. |
| 3166 | PrivateFragmentImportAllowed, ///< after 'module :private;' but before any |
| 3167 | ///< non-import decl. |
| 3168 | PrivateFragmentImportFinished, ///< after 'module :private;' but a |
| 3169 | ///< non-import decl has already been seen. |
| 3170 | NotACXX20Module ///< Not a C++20 TU, or an invalid state was found. |
| 3171 | }; |
| 3172 | |
| 3173 | private: |
| 3174 | /// The parser has begun a translation unit to be compiled as a C++20 |
| 3175 | /// Header Unit, helper for ActOnStartOfTranslationUnit() only. |
| 3176 | void HandleStartOfHeaderUnit(); |
| 3177 | |
| 3178 | public: |
| 3179 | /// The parser has processed a module-declaration that begins the definition |
| 3180 | /// of a module interface or implementation. |
| 3181 | DeclGroupPtrTy ActOnModuleDecl(SourceLocation StartLoc, |
| 3182 | SourceLocation ModuleLoc, ModuleDeclKind MDK, |
| 3183 | ModuleIdPath Path, ModuleIdPath Partition, |
| 3184 | ModuleImportState &ImportState); |
| 3185 | |
| 3186 | /// The parser has processed a global-module-fragment declaration that begins |
| 3187 | /// the definition of the global module fragment of the current module unit. |
| 3188 | /// \param ModuleLoc The location of the 'module' keyword. |
| 3189 | DeclGroupPtrTy ActOnGlobalModuleFragmentDecl(SourceLocation ModuleLoc); |
| 3190 | |
| 3191 | /// The parser has processed a private-module-fragment declaration that begins |
| 3192 | /// the definition of the private module fragment of the current module unit. |
| 3193 | /// \param ModuleLoc The location of the 'module' keyword. |
| 3194 | /// \param PrivateLoc The location of the 'private' keyword. |
| 3195 | DeclGroupPtrTy ActOnPrivateModuleFragmentDecl(SourceLocation ModuleLoc, |
| 3196 | SourceLocation PrivateLoc); |
| 3197 | |
| 3198 | /// The parser has processed a module import declaration. |
| 3199 | /// |
| 3200 | /// \param StartLoc The location of the first token in the declaration. This |
| 3201 | /// could be the location of an '@', 'export', or 'import'. |
| 3202 | /// \param ExportLoc The location of the 'export' keyword, if any. |
| 3203 | /// \param ImportLoc The location of the 'import' keyword. |
| 3204 | /// \param Path The module toplevel name as an access path. |
| 3205 | /// \param IsPartition If the name is for a partition. |
| 3206 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
| 3207 | SourceLocation ExportLoc, |
| 3208 | SourceLocation ImportLoc, ModuleIdPath Path, |
| 3209 | bool IsPartition = false); |
| 3210 | DeclResult ActOnModuleImport(SourceLocation StartLoc, |
| 3211 | SourceLocation ExportLoc, |
| 3212 | SourceLocation ImportLoc, Module *M, |
| 3213 | ModuleIdPath Path = {}); |
| 3214 | |
| 3215 | /// The parser has processed a module import translated from a |
| 3216 | /// #include or similar preprocessing directive. |
| 3217 | void ActOnModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
| 3218 | void BuildModuleInclude(SourceLocation DirectiveLoc, Module *Mod); |
| 3219 | |
| 3220 | /// The parsed has entered a submodule. |
| 3221 | void ActOnModuleBegin(SourceLocation DirectiveLoc, Module *Mod); |
| 3222 | /// The parser has left a submodule. |
| 3223 | void ActOnModuleEnd(SourceLocation DirectiveLoc, Module *Mod); |
| 3224 | |
| 3225 | /// Create an implicit import of the given module at the given |
| 3226 | /// source location, for error recovery, if possible. |
| 3227 | /// |
| 3228 | /// This routine is typically used when an entity found by name lookup |
| 3229 | /// is actually hidden within a module that we know about but the user |
| 3230 | /// has forgotten to import. |
| 3231 | void createImplicitModuleImportForErrorRecovery(SourceLocation Loc, |
| 3232 | Module *Mod); |
| 3233 | |
| 3234 | /// Kinds of missing import. Note, the values of these enumerators correspond |
| 3235 | /// to %select values in diagnostics. |
| 3236 | enum class MissingImportKind { |
| 3237 | Declaration, |
| 3238 | Definition, |
| 3239 | DefaultArgument, |
| 3240 | ExplicitSpecialization, |
| 3241 | PartialSpecialization |
| 3242 | }; |
| 3243 | |
| 3244 | /// Diagnose that the specified declaration needs to be visible but |
| 3245 | /// isn't, and suggest a module import that would resolve the problem. |
| 3246 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
| 3247 | MissingImportKind MIK, bool Recover = true); |
| 3248 | void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, |
| 3249 | SourceLocation DeclLoc, ArrayRef<Module *> Modules, |
| 3250 | MissingImportKind MIK, bool Recover); |
| 3251 | |
| 3252 | Decl *ActOnStartExportDecl(Scope *S, SourceLocation ExportLoc, |
| 3253 | SourceLocation LBraceLoc); |
| 3254 | Decl *ActOnFinishExportDecl(Scope *S, Decl *ExportDecl, |
| 3255 | SourceLocation RBraceLoc); |
| 3256 | |
| 3257 | /// We've found a use of a templated declaration that would trigger an |
| 3258 | /// implicit instantiation. Check that any relevant explicit specializations |
| 3259 | /// and partial specializations are visible/reachable, and diagnose if not. |
| 3260 | void checkSpecializationVisibility(SourceLocation Loc, NamedDecl *Spec); |
| 3261 | void checkSpecializationReachability(SourceLocation Loc, NamedDecl *Spec); |
| 3262 | |
| 3263 | /// Retrieve a suitable printing policy for diagnostics. |
| 3264 | PrintingPolicy getPrintingPolicy() const { |
| 3265 | return getPrintingPolicy(Context, PP); |
| 3266 | } |
| 3267 | |
| 3268 | /// Retrieve a suitable printing policy for diagnostics. |
| 3269 | static PrintingPolicy getPrintingPolicy(const ASTContext &Ctx, |
| 3270 | const Preprocessor &PP); |
| 3271 | |
| 3272 | /// Scope actions. |
| 3273 | void ActOnPopScope(SourceLocation Loc, Scope *S); |
| 3274 | void ActOnTranslationUnitScope(Scope *S); |
| 3275 | |
| 3276 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
| 3277 | const ParsedAttributesView &DeclAttrs, |
| 3278 | RecordDecl *&AnonRecord); |
| 3279 | Decl *ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, |
| 3280 | const ParsedAttributesView &DeclAttrs, |
| 3281 | MultiTemplateParamsArg TemplateParams, |
| 3282 | bool IsExplicitInstantiation, |
| 3283 | RecordDecl *&AnonRecord); |
| 3284 | |
| 3285 | Decl *BuildAnonymousStructOrUnion(Scope *S, DeclSpec &DS, |
| 3286 | AccessSpecifier AS, |
| 3287 | RecordDecl *Record, |
| 3288 | const PrintingPolicy &Policy); |
| 3289 | |
| 3290 | Decl *BuildMicrosoftCAnonymousStruct(Scope *S, DeclSpec &DS, |
| 3291 | RecordDecl *Record); |
| 3292 | |
| 3293 | /// Common ways to introduce type names without a tag for use in diagnostics. |
| 3294 | /// Keep in sync with err_tag_reference_non_tag. |
| 3295 | enum NonTagKind { |
| 3296 | NTK_NonStruct, |
| 3297 | NTK_NonClass, |
| 3298 | NTK_NonUnion, |
| 3299 | NTK_NonEnum, |
| 3300 | NTK_Typedef, |
| 3301 | NTK_TypeAlias, |
| 3302 | NTK_Template, |
| 3303 | NTK_TypeAliasTemplate, |
| 3304 | NTK_TemplateTemplateArgument, |
| 3305 | }; |
| 3306 | |
| 3307 | /// Given a non-tag type declaration, returns an enum useful for indicating |
| 3308 | /// what kind of non-tag type this is. |
| 3309 | NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK); |
| 3310 | |
| 3311 | bool isAcceptableTagRedeclaration(const TagDecl *Previous, |
| 3312 | TagTypeKind NewTag, bool isDefinition, |
| 3313 | SourceLocation NewTagLoc, |
| 3314 | const IdentifierInfo *Name); |
| 3315 | |
| 3316 | enum TagUseKind { |
| 3317 | TUK_Reference, // Reference to a tag: 'struct foo *X;' |
| 3318 | TUK_Declaration, // Fwd decl of a tag: 'struct foo;' |
| 3319 | TUK_Definition, // Definition of a tag: 'struct foo { int X; } Y;' |
| 3320 | TUK_Friend // Friend declaration: 'friend struct foo;' |
| 3321 | }; |
| 3322 | |
| 3323 | enum OffsetOfKind { |
| 3324 | // Not parsing a type within __builtin_offsetof. |
| 3325 | OOK_Outside, |
| 3326 | // Parsing a type within __builtin_offsetof. |
| 3327 | OOK_Builtin, |
| 3328 | // Parsing a type within macro "offsetof", defined in __buitin_offsetof |
| 3329 | // To improve our diagnostic message. |
| 3330 | OOK_Macro, |
| 3331 | }; |
| 3332 | |
| 3333 | DeclResult ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, |
| 3334 | SourceLocation KWLoc, CXXScopeSpec &SS, |
| 3335 | IdentifierInfo *Name, SourceLocation NameLoc, |
| 3336 | const ParsedAttributesView &Attr, AccessSpecifier AS, |
| 3337 | SourceLocation ModulePrivateLoc, |
| 3338 | MultiTemplateParamsArg TemplateParameterLists, |
| 3339 | bool &OwnedDecl, bool &IsDependent, |
| 3340 | SourceLocation ScopedEnumKWLoc, |
| 3341 | bool ScopedEnumUsesClassTag, TypeResult UnderlyingType, |
| 3342 | bool IsTypeSpecifier, bool IsTemplateParamOrArg, |
| 3343 | OffsetOfKind OOK, SkipBodyInfo *SkipBody = nullptr); |
| 3344 | |
| 3345 | DeclResult ActOnTemplatedFriendTag(Scope *S, SourceLocation FriendLoc, |
| 3346 | unsigned TagSpec, SourceLocation TagLoc, |
| 3347 | CXXScopeSpec &SS, IdentifierInfo *Name, |
| 3348 | SourceLocation NameLoc, |
| 3349 | const ParsedAttributesView &Attr, |
| 3350 | MultiTemplateParamsArg TempParamLists); |
| 3351 | |
| 3352 | TypeResult ActOnDependentTag(Scope *S, |
| 3353 | unsigned TagSpec, |
| 3354 | TagUseKind TUK, |
| 3355 | const CXXScopeSpec &SS, |
| 3356 | IdentifierInfo *Name, |
| 3357 | SourceLocation TagLoc, |
| 3358 | SourceLocation NameLoc); |
| 3359 | |
| 3360 | void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, |
| 3361 | IdentifierInfo *ClassName, |
| 3362 | SmallVectorImpl<Decl *> &Decls); |
| 3363 | Decl *ActOnField(Scope *S, Decl *TagD, SourceLocation DeclStart, |
| 3364 | Declarator &D, Expr *BitfieldWidth); |
| 3365 | |
| 3366 | FieldDecl *HandleField(Scope *S, RecordDecl *TagD, SourceLocation DeclStart, |
| 3367 | Declarator &D, Expr *BitfieldWidth, |
| 3368 | InClassInitStyle InitStyle, |
| 3369 | AccessSpecifier AS); |
| 3370 | MSPropertyDecl *HandleMSProperty(Scope *S, RecordDecl *TagD, |
| 3371 | SourceLocation DeclStart, Declarator &D, |
| 3372 | Expr *BitfieldWidth, |
| 3373 | InClassInitStyle InitStyle, |
| 3374 | AccessSpecifier AS, |
| 3375 | const ParsedAttr &MSPropertyAttr); |
| 3376 | |
| 3377 | FieldDecl *CheckFieldDecl(DeclarationName Name, QualType T, |
| 3378 | TypeSourceInfo *TInfo, |
| 3379 | RecordDecl *Record, SourceLocation Loc, |
| 3380 | bool Mutable, Expr *BitfieldWidth, |
| 3381 | InClassInitStyle InitStyle, |
| 3382 | SourceLocation TSSL, |
| 3383 | AccessSpecifier AS, NamedDecl *PrevDecl, |
| 3384 | Declarator *D = nullptr); |
| 3385 | |
| 3386 | bool CheckNontrivialField(FieldDecl *FD); |
| 3387 | void DiagnoseNontrivial(const CXXRecordDecl *Record, CXXSpecialMember CSM); |
| 3388 | |
| 3389 | enum TrivialABIHandling { |
| 3390 | /// The triviality of a method unaffected by "trivial_abi". |
| 3391 | TAH_IgnoreTrivialABI, |
| 3392 | |
| 3393 | /// The triviality of a method affected by "trivial_abi". |
| 3394 | TAH_ConsiderTrivialABI |
| 3395 | }; |
| 3396 | |
| 3397 | bool SpecialMemberIsTrivial(CXXMethodDecl *MD, CXXSpecialMember CSM, |
| 3398 | TrivialABIHandling TAH = TAH_IgnoreTrivialABI, |
| 3399 | bool Diagnose = false); |
| 3400 | |
| 3401 | /// For a defaulted function, the kind of defaulted function that it is. |
| 3402 | class DefaultedFunctionKind { |
| 3403 | CXXSpecialMember SpecialMember : 8; |
| 3404 | DefaultedComparisonKind Comparison : 8; |
| 3405 | |
| 3406 | public: |
| 3407 | DefaultedFunctionKind() |
| 3408 | : SpecialMember(CXXInvalid), Comparison(DefaultedComparisonKind::None) { |
| 3409 | } |
| 3410 | DefaultedFunctionKind(CXXSpecialMember CSM) |
| 3411 | : SpecialMember(CSM), Comparison(DefaultedComparisonKind::None) {} |
| 3412 | DefaultedFunctionKind(DefaultedComparisonKind Comp) |
| 3413 | : SpecialMember(CXXInvalid), Comparison(Comp) {} |
| 3414 | |
| 3415 | bool isSpecialMember() const { return SpecialMember != CXXInvalid; } |
| 3416 | bool isComparison() const { |
| 3417 | return Comparison != DefaultedComparisonKind::None; |
| 3418 | } |
| 3419 | |
| 3420 | explicit operator bool() const { |
| 3421 | return isSpecialMember() || isComparison(); |
| 3422 | } |
| 3423 | |
| 3424 | CXXSpecialMember asSpecialMember() const { return SpecialMember; } |
| 3425 | DefaultedComparisonKind asComparison() const { return Comparison; } |
| 3426 | |
| 3427 | /// Get the index of this function kind for use in diagnostics. |
| 3428 | unsigned getDiagnosticIndex() const { |
| 3429 | static_assert(CXXInvalid > CXXDestructor, |
| 3430 | "invalid should have highest index"); |
| 3431 | static_assert((unsigned)DefaultedComparisonKind::None == 0, |
| 3432 | "none should be equal to zero"); |
| 3433 | return SpecialMember + (unsigned)Comparison; |
| 3434 | } |
| 3435 | }; |
| 3436 | |
| 3437 | DefaultedFunctionKind getDefaultedFunctionKind(const FunctionDecl *FD); |
| 3438 | |
| 3439 | CXXSpecialMember getSpecialMember(const CXXMethodDecl *MD) { |
| 3440 | return getDefaultedFunctionKind(MD).asSpecialMember(); |
| 3441 | } |
| 3442 | DefaultedComparisonKind getDefaultedComparisonKind(const FunctionDecl *FD) { |
| 3443 | return getDefaultedFunctionKind(FD).asComparison(); |
| 3444 | } |
| 3445 | |
| 3446 | void ActOnLastBitfield(SourceLocation DeclStart, |
| 3447 | SmallVectorImpl<Decl *> &AllIvarDecls); |
| 3448 | Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, |
| 3449 | Declarator &D, Expr *BitfieldWidth, |
| 3450 | tok::ObjCKeywordKind visibility); |
| 3451 | |
| 3452 | // This is used for both record definitions and ObjC interface declarations. |
| 3453 | void ActOnFields(Scope *S, SourceLocation RecLoc, Decl *TagDecl, |
| 3454 | ArrayRef<Decl *> Fields, SourceLocation LBrac, |
| 3455 | SourceLocation RBrac, const ParsedAttributesView &AttrList); |
| 3456 | |
| 3457 | /// ActOnTagStartDefinition - Invoked when we have entered the |
| 3458 | /// scope of a tag's definition (e.g., for an enumeration, class, |
| 3459 | /// struct, or union). |
| 3460 | void ActOnTagStartDefinition(Scope *S, Decl *TagDecl); |
| 3461 | |
| 3462 | /// Perform ODR-like check for C/ObjC when merging tag types from modules. |
| 3463 | /// Differently from C++, actually parse the body and reject / error out |
| 3464 | /// in case of a structural mismatch. |
| 3465 | bool ActOnDuplicateDefinition(Decl *Prev, SkipBodyInfo &SkipBody); |
| 3466 | |
| 3467 | /// Check ODR hashes for C/ObjC when merging types from modules. |
| 3468 | /// Differently from C++, actually parse the body and reject in case |
| 3469 | /// of a mismatch. |
| 3470 | template <typename T, |
| 3471 | typename = std::enable_if_t<std::is_base_of<NamedDecl, T>::value>> |
| 3472 | bool ActOnDuplicateODRHashDefinition(T *Duplicate, T *Previous) { |
| 3473 | if (Duplicate->getODRHash() != Previous->getODRHash()) |
| 3474 | return false; |
| 3475 | |
| 3476 | // Make the previous decl visible. |
| 3477 | makeMergedDefinitionVisible(Previous); |
| 3478 | return true; |
| 3479 | } |
| 3480 | |
| 3481 | typedef void *SkippedDefinitionContext; |
| 3482 | |
| 3483 | /// Invoked when we enter a tag definition that we're skipping. |
| 3484 | SkippedDefinitionContext ActOnTagStartSkippedDefinition(Scope *S, Decl *TD); |
| 3485 | |
| 3486 | void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl); |
| 3487 | |
| 3488 | /// ActOnStartCXXMemberDeclarations - Invoked when we have parsed a |
| 3489 | /// C++ record definition's base-specifiers clause and are starting its |
| 3490 | /// member declarations. |
| 3491 | void ActOnStartCXXMemberDeclarations(Scope *S, Decl *TagDecl, |
| 3492 | SourceLocation FinalLoc, |
| 3493 | bool IsFinalSpelledSealed, |
| 3494 | bool IsAbstract, |
| 3495 | SourceLocation LBraceLoc); |
| 3496 | |
| 3497 | /// ActOnTagFinishDefinition - Invoked once we have finished parsing |
| 3498 | /// the definition of a tag (enumeration, class, struct, or union). |
| 3499 | void ActOnTagFinishDefinition(Scope *S, Decl *TagDecl, |
| 3500 | SourceRange BraceRange); |
| 3501 | |
| 3502 | void ActOnTagFinishSkippedDefinition(SkippedDefinitionContext Context); |
| 3503 | |
| 3504 | void ActOnObjCContainerFinishDefinition(); |
| 3505 | |
| 3506 | /// Invoked when we must temporarily exit the objective-c container |
| 3507 | /// scope for parsing/looking-up C constructs. |
| 3508 | /// |
| 3509 | /// Must be followed by a call to \see ActOnObjCReenterContainerContext |
| 3510 | void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx); |
| 3511 | void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx); |
| 3512 | |
| 3513 | /// ActOnTagDefinitionError - Invoked when there was an unrecoverable |
| 3514 | /// error parsing the definition of a tag. |
| 3515 | void ActOnTagDefinitionError(Scope *S, Decl *TagDecl); |
| 3516 | |
| 3517 | EnumConstantDecl *CheckEnumConstant(EnumDecl *Enum, |
| 3518 | EnumConstantDecl *LastEnumConst, |
| 3519 | SourceLocation IdLoc, |
| 3520 | IdentifierInfo *Id, |
| 3521 | Expr *val); |
| 3522 | bool CheckEnumUnderlyingType(TypeSourceInfo *TI); |
| 3523 | bool CheckEnumRedeclaration(SourceLocation EnumLoc, bool IsScoped, |
| 3524 | QualType EnumUnderlyingTy, bool IsFixed, |
| 3525 | const EnumDecl *Prev); |
| 3526 | |
| 3527 | /// Determine whether the body of an anonymous enumeration should be skipped. |
| 3528 | /// \param II The name of the first enumerator. |
| 3529 | SkipBodyInfo shouldSkipAnonEnumBody(Scope *S, IdentifierInfo *II, |
| 3530 | SourceLocation IILoc); |
| 3531 | |
| 3532 | Decl *ActOnEnumConstant(Scope *S, Decl *EnumDecl, Decl *LastEnumConstant, |
| 3533 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 3534 | const ParsedAttributesView &Attrs, |
| 3535 | SourceLocation EqualLoc, Expr *Val); |
| 3536 | void ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange, |
| 3537 | Decl *EnumDecl, ArrayRef<Decl *> Elements, Scope *S, |
| 3538 | const ParsedAttributesView &Attr); |
| 3539 | |
| 3540 | /// Set the current declaration context until it gets popped. |
| 3541 | void PushDeclContext(Scope *S, DeclContext *DC); |
| 3542 | void PopDeclContext(); |
| 3543 | |
| 3544 | /// EnterDeclaratorContext - Used when we must lookup names in the context |
| 3545 | /// of a declarator's nested name specifier. |
| 3546 | void EnterDeclaratorContext(Scope *S, DeclContext *DC); |
| 3547 | void ExitDeclaratorContext(Scope *S); |
| 3548 | |
| 3549 | /// Enter a template parameter scope, after it's been associated with a particular |
| 3550 | /// DeclContext. Causes lookup within the scope to chain through enclosing contexts |
| 3551 | /// in the correct order. |
| 3552 | void EnterTemplatedContext(Scope *S, DeclContext *DC); |
| 3553 | |
| 3554 | /// Push the parameters of D, which must be a function, into scope. |
| 3555 | void ActOnReenterFunctionContext(Scope* S, Decl* D); |
| 3556 | void ActOnExitFunctionContext(); |
| 3557 | |
| 3558 | /// If \p AllowLambda is true, treat lambda as function. |
| 3559 | DeclContext *getFunctionLevelDeclContext(bool AllowLambda = false) const; |
| 3560 | |
| 3561 | /// Returns a pointer to the innermost enclosing function, or nullptr if the |
| 3562 | /// current context is not inside a function. If \p AllowLambda is true, |
| 3563 | /// this can return the call operator of an enclosing lambda, otherwise |
| 3564 | /// lambdas are skipped when looking for an enclosing function. |
| 3565 | FunctionDecl *getCurFunctionDecl(bool AllowLambda = false) const; |
| 3566 | |
| 3567 | /// getCurMethodDecl - If inside of a method body, this returns a pointer to |
| 3568 | /// the method decl for the method being parsed. If we're currently |
| 3569 | /// in a 'block', this returns the containing context. |
| 3570 | ObjCMethodDecl *getCurMethodDecl(); |
| 3571 | |
| 3572 | /// getCurFunctionOrMethodDecl - Return the Decl for the current ObjC method |
| 3573 | /// or C function we're in, otherwise return null. If we're currently |
| 3574 | /// in a 'block', this returns the containing context. |
| 3575 | NamedDecl *getCurFunctionOrMethodDecl() const; |
| 3576 | |
| 3577 | /// Add this decl to the scope shadowed decl chains. |
| 3578 | void PushOnScopeChains(NamedDecl *D, Scope *S, bool AddToContext = true); |
| 3579 | |
| 3580 | /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true |
| 3581 | /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns |
| 3582 | /// true if 'D' belongs to the given declaration context. |
| 3583 | /// |
| 3584 | /// \param AllowInlineNamespace If \c true, allow the declaration to be in the |
| 3585 | /// enclosing namespace set of the context, rather than contained |
| 3586 | /// directly within it. |
| 3587 | bool isDeclInScope(NamedDecl *D, DeclContext *Ctx, Scope *S = nullptr, |
| 3588 | bool AllowInlineNamespace = false) const; |
| 3589 | |
| 3590 | /// Finds the scope corresponding to the given decl context, if it |
| 3591 | /// happens to be an enclosing scope. Otherwise return NULL. |
| 3592 | static Scope *getScopeForDeclContext(Scope *S, DeclContext *DC); |
| 3593 | |
| 3594 | /// Subroutines of ActOnDeclarator(). |
| 3595 | TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T, |
| 3596 | TypeSourceInfo *TInfo); |
| 3597 | bool isIncompatibleTypedef(TypeDecl *Old, TypedefNameDecl *New); |
| 3598 | |
| 3599 | /// Describes the kind of merge to perform for availability |
| 3600 | /// attributes (including "deprecated", "unavailable", and "availability"). |
| 3601 | enum AvailabilityMergeKind { |
| 3602 | /// Don't merge availability attributes at all. |
| 3603 | AMK_None, |
| 3604 | /// Merge availability attributes for a redeclaration, which requires |
| 3605 | /// an exact match. |
| 3606 | AMK_Redeclaration, |
| 3607 | /// Merge availability attributes for an override, which requires |
| 3608 | /// an exact match or a weakening of constraints. |
| 3609 | AMK_Override, |
| 3610 | /// Merge availability attributes for an implementation of |
| 3611 | /// a protocol requirement. |
| 3612 | AMK_ProtocolImplementation, |
| 3613 | /// Merge availability attributes for an implementation of |
| 3614 | /// an optional protocol requirement. |
| 3615 | AMK_OptionalProtocolImplementation |
| 3616 | }; |
| 3617 | |
| 3618 | /// Describes the kind of priority given to an availability attribute. |
| 3619 | /// |
| 3620 | /// The sum of priorities deteremines the final priority of the attribute. |
| 3621 | /// The final priority determines how the attribute will be merged. |
| 3622 | /// An attribute with a lower priority will always remove higher priority |
| 3623 | /// attributes for the specified platform when it is being applied. An |
| 3624 | /// attribute with a higher priority will not be applied if the declaration |
| 3625 | /// already has an availability attribute with a lower priority for the |
| 3626 | /// specified platform. The final prirority values are not expected to match |
| 3627 | /// the values in this enumeration, but instead should be treated as a plain |
| 3628 | /// integer value. This enumeration just names the priority weights that are |
| 3629 | /// used to calculate that final vaue. |
| 3630 | enum AvailabilityPriority : int { |
| 3631 | /// The availability attribute was specified explicitly next to the |
| 3632 | /// declaration. |
| 3633 | AP_Explicit = 0, |
| 3634 | |
| 3635 | /// The availability attribute was applied using '#pragma clang attribute'. |
| 3636 | AP_PragmaClangAttribute = 1, |
| 3637 | |
| 3638 | /// The availability attribute for a specific platform was inferred from |
| 3639 | /// an availability attribute for another platform. |
| 3640 | AP_InferredFromOtherPlatform = 2 |
| 3641 | }; |
| 3642 | |
| 3643 | /// Attribute merging methods. Return true if a new attribute was added. |
| 3644 | AvailabilityAttr * |
| 3645 | mergeAvailabilityAttr(NamedDecl *D, const AttributeCommonInfo &CI, |
| 3646 | IdentifierInfo *Platform, bool Implicit, |
| 3647 | VersionTuple Introduced, VersionTuple Deprecated, |
| 3648 | VersionTuple Obsoleted, bool IsUnavailable, |
| 3649 | StringRef Message, bool IsStrict, StringRef Replacement, |
| 3650 | AvailabilityMergeKind AMK, int Priority); |
| 3651 | TypeVisibilityAttr * |
| 3652 | mergeTypeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
| 3653 | TypeVisibilityAttr::VisibilityType Vis); |
| 3654 | VisibilityAttr *mergeVisibilityAttr(Decl *D, const AttributeCommonInfo &CI, |
| 3655 | VisibilityAttr::VisibilityType Vis); |
| 3656 | UuidAttr *mergeUuidAttr(Decl *D, const AttributeCommonInfo &CI, |
| 3657 | StringRef UuidAsWritten, MSGuidDecl *GuidDecl); |
| 3658 | DLLImportAttr *mergeDLLImportAttr(Decl *D, const AttributeCommonInfo &CI); |
| 3659 | DLLExportAttr *mergeDLLExportAttr(Decl *D, const AttributeCommonInfo &CI); |
| 3660 | MSInheritanceAttr *mergeMSInheritanceAttr(Decl *D, |
| 3661 | const AttributeCommonInfo &CI, |
| 3662 | bool BestCase, |
| 3663 | MSInheritanceModel Model); |
| 3664 | ErrorAttr *mergeErrorAttr(Decl *D, const AttributeCommonInfo &CI, |
| 3665 | StringRef NewUserDiagnostic); |
| 3666 | FormatAttr *mergeFormatAttr(Decl *D, const AttributeCommonInfo &CI, |
| 3667 | IdentifierInfo *Format, int FormatIdx, |
| 3668 | int FirstArg); |
| 3669 | SectionAttr *mergeSectionAttr(Decl *D, const AttributeCommonInfo &CI, |
| 3670 | StringRef Name); |
| 3671 | CodeSegAttr *mergeCodeSegAttr(Decl *D, const AttributeCommonInfo &CI, |
| 3672 | StringRef Name); |
| 3673 | AlwaysInlineAttr *mergeAlwaysInlineAttr(Decl *D, |
| 3674 | const AttributeCommonInfo &CI, |
| 3675 | const IdentifierInfo *Ident); |
| 3676 | MinSizeAttr *mergeMinSizeAttr(Decl *D, const AttributeCommonInfo &CI); |
| 3677 | SwiftNameAttr *mergeSwiftNameAttr(Decl *D, const SwiftNameAttr &SNA, |
| 3678 | StringRef Name); |
| 3679 | OptimizeNoneAttr *mergeOptimizeNoneAttr(Decl *D, |
| 3680 | const AttributeCommonInfo &CI); |
| 3681 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, const ParsedAttr &AL); |
| 3682 | InternalLinkageAttr *mergeInternalLinkageAttr(Decl *D, |
| 3683 | const InternalLinkageAttr &AL); |
| 3684 | WebAssemblyImportNameAttr *mergeImportNameAttr( |
| 3685 | Decl *D, const WebAssemblyImportNameAttr &AL); |
| 3686 | WebAssemblyImportModuleAttr *mergeImportModuleAttr( |
| 3687 | Decl *D, const WebAssemblyImportModuleAttr &AL); |
| 3688 | EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL); |
| 3689 | EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D, |
| 3690 | const EnforceTCBLeafAttr &AL); |
| 3691 | BTFDeclTagAttr *mergeBTFDeclTagAttr(Decl *D, const BTFDeclTagAttr &AL); |
| 3692 | HLSLNumThreadsAttr *mergeHLSLNumThreadsAttr(Decl *D, |
| 3693 | const AttributeCommonInfo &AL, |
| 3694 | int X, int Y, int Z); |
| 3695 | HLSLShaderAttr *mergeHLSLShaderAttr(Decl *D, const AttributeCommonInfo &AL, |
| 3696 | HLSLShaderAttr::ShaderType ShaderType); |
| 3697 | |
| 3698 | void mergeDeclAttributes(NamedDecl *New, Decl *Old, |
| 3699 | AvailabilityMergeKind AMK = AMK_Redeclaration); |
| 3700 | void MergeTypedefNameDecl(Scope *S, TypedefNameDecl *New, |
| 3701 | LookupResult &OldDecls); |
| 3702 | bool MergeFunctionDecl(FunctionDecl *New, NamedDecl *&Old, Scope *S, |
| 3703 | bool MergeTypeWithOld, bool NewDeclIsDefn); |
| 3704 | bool MergeCompatibleFunctionDecls(FunctionDecl *New, FunctionDecl *Old, |
| 3705 | Scope *S, bool MergeTypeWithOld); |
| 3706 | void mergeObjCMethodDecls(ObjCMethodDecl *New, ObjCMethodDecl *Old); |
| 3707 | void MergeVarDecl(VarDecl *New, LookupResult &Previous); |
| 3708 | void MergeVarDeclTypes(VarDecl *New, VarDecl *Old, bool MergeTypeWithOld); |
| 3709 | void MergeVarDeclExceptionSpecs(VarDecl *New, VarDecl *Old); |
| 3710 | bool checkVarDeclRedefinition(VarDecl *OldDefn, VarDecl *NewDefn); |
| 3711 | void notePreviousDefinition(const NamedDecl *Old, SourceLocation New); |
| 3712 | bool MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old, Scope *S); |
| 3713 | |
| 3714 | // AssignmentAction - This is used by all the assignment diagnostic functions |
| 3715 | // to represent what is actually causing the operation |
| 3716 | enum AssignmentAction { |
| 3717 | AA_Assigning, |
| 3718 | AA_Passing, |
| 3719 | AA_Returning, |
| 3720 | AA_Converting, |
| 3721 | AA_Initializing, |
| 3722 | AA_Sending, |
| 3723 | AA_Casting, |
| 3724 | AA_Passing_CFAudited |
| 3725 | }; |
| 3726 | |
| 3727 | /// C++ Overloading. |
| 3728 | enum OverloadKind { |
| 3729 | /// This is a legitimate overload: the existing declarations are |
| 3730 | /// functions or function templates with different signatures. |
| 3731 | Ovl_Overload, |
| 3732 | |
| 3733 | /// This is not an overload because the signature exactly matches |
| 3734 | /// an existing declaration. |
| 3735 | Ovl_Match, |
| 3736 | |
| 3737 | /// This is not an overload because the lookup results contain a |
| 3738 | /// non-function. |
| 3739 | Ovl_NonFunction |
| 3740 | }; |
| 3741 | OverloadKind CheckOverload(Scope *S, |
| 3742 | FunctionDecl *New, |
| 3743 | const LookupResult &OldDecls, |
| 3744 | NamedDecl *&OldDecl, |
| 3745 | bool UseMemberUsingDeclRules); |
| 3746 | bool IsOverload(FunctionDecl *New, FunctionDecl *Old, |
| 3747 | bool UseMemberUsingDeclRules, bool ConsiderCudaAttrs = true, |
| 3748 | bool ConsiderRequiresClauses = true); |
| 3749 | |
| 3750 | // Calculates whether the expression Constraint depends on an enclosing |
| 3751 | // template, for the purposes of [temp.friend] p9. |
| 3752 | // TemplateDepth is the 'depth' of the friend function, which is used to |
| 3753 | // compare whether a declaration reference is referring to a containing |
| 3754 | // template, or just the current friend function. A 'lower' TemplateDepth in |
| 3755 | // the AST refers to a 'containing' template. As the constraint is |
| 3756 | // uninstantiated, this is relative to the 'top' of the TU. |
| 3757 | bool |
| 3758 | ConstraintExpressionDependsOnEnclosingTemplate(const FunctionDecl *Friend, |
| 3759 | unsigned TemplateDepth, |
| 3760 | const Expr *Constraint); |
| 3761 | |
| 3762 | // Calculates whether the friend function depends on an enclosing template for |
| 3763 | // the purposes of [temp.friend] p9. |
| 3764 | bool FriendConstraintsDependOnEnclosingTemplate(const FunctionDecl *FD); |
| 3765 | |
| 3766 | // Calculates whether two constraint expressions are equal irrespective of a |
| 3767 | // difference in 'depth'. This takes a pair of optional 'NamedDecl's 'Old' and |
| 3768 | // 'New', which are the "source" of the constraint, since this is necessary |
| 3769 | // for figuring out the relative 'depth' of the constraint. The depth of the |
| 3770 | // 'primary template' and the 'instantiated from' templates aren't necessarily |
| 3771 | // the same, such as a case when one is a 'friend' defined in a class. |
| 3772 | bool AreConstraintExpressionsEqual(const NamedDecl *Old, |
| 3773 | const Expr *OldConstr, |
| 3774 | const NamedDecl *New, |
| 3775 | const Expr *NewConstr); |
| 3776 | |
| 3777 | enum class AllowedExplicit { |
| 3778 | /// Allow no explicit functions to be used. |
| 3779 | None, |
| 3780 | /// Allow explicit conversion functions but not explicit constructors. |
| 3781 | Conversions, |
| 3782 | /// Allow both explicit conversion functions and explicit constructors. |
| 3783 | All |
| 3784 | }; |
| 3785 | |
| 3786 | ImplicitConversionSequence |
| 3787 | TryImplicitConversion(Expr *From, QualType ToType, |
| 3788 | bool SuppressUserConversions, |
| 3789 | AllowedExplicit AllowExplicit, |
| 3790 | bool InOverloadResolution, |
| 3791 | bool CStyle, |
| 3792 | bool AllowObjCWritebackConversion); |
| 3793 | |
| 3794 | bool IsIntegralPromotion(Expr *From, QualType FromType, QualType ToType); |
| 3795 | bool IsFloatingPointPromotion(QualType FromType, QualType ToType); |
| 3796 | bool IsComplexPromotion(QualType FromType, QualType ToType); |
| 3797 | bool IsPointerConversion(Expr *From, QualType FromType, QualType ToType, |
| 3798 | bool InOverloadResolution, |
| 3799 | QualType& ConvertedType, bool &IncompatibleObjC); |
| 3800 | bool isObjCPointerConversion(QualType FromType, QualType ToType, |
| 3801 | QualType& ConvertedType, bool &IncompatibleObjC); |
| 3802 | bool isObjCWritebackConversion(QualType FromType, QualType ToType, |
| 3803 | QualType &ConvertedType); |
| 3804 | bool IsBlockPointerConversion(QualType FromType, QualType ToType, |
| 3805 | QualType& ConvertedType); |
| 3806 | bool FunctionParamTypesAreEqual(const FunctionProtoType *OldType, |
| 3807 | const FunctionProtoType *NewType, |
| 3808 | unsigned *ArgPos = nullptr, |
| 3809 | bool Reversed = false); |
| 3810 | void HandleFunctionTypeMismatch(PartialDiagnostic &PDiag, |
| 3811 | QualType FromType, QualType ToType); |
| 3812 | |
| 3813 | void maybeExtendBlockObject(ExprResult &E); |
| 3814 | CastKind PrepareCastToObjCObjectPointer(ExprResult &E); |
| 3815 | bool CheckPointerConversion(Expr *From, QualType ToType, |
| 3816 | CastKind &Kind, |
| 3817 | CXXCastPath& BasePath, |
| 3818 | bool IgnoreBaseAccess, |
| 3819 | bool Diagnose = true); |
| 3820 | bool IsMemberPointerConversion(Expr *From, QualType FromType, QualType ToType, |
| 3821 | bool InOverloadResolution, |
| 3822 | QualType &ConvertedType); |
| 3823 | bool CheckMemberPointerConversion(Expr *From, QualType ToType, |
| 3824 | CastKind &Kind, |
| 3825 | CXXCastPath &BasePath, |
| 3826 | bool IgnoreBaseAccess); |
| 3827 | bool IsQualificationConversion(QualType FromType, QualType ToType, |
| 3828 | bool CStyle, bool &ObjCLifetimeConversion); |
| 3829 | bool IsFunctionConversion(QualType FromType, QualType ToType, |
| 3830 | QualType &ResultTy); |
| 3831 | bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType); |
| 3832 | bool isSameOrCompatibleFunctionType(QualType Param, QualType Arg); |
| 3833 | |
| 3834 | bool CanPerformAggregateInitializationForOverloadResolution( |
| 3835 | const InitializedEntity &Entity, InitListExpr *From); |
| 3836 | |
| 3837 | bool IsStringInit(Expr *Init, const ArrayType *AT); |
| 3838 | |
| 3839 | bool CanPerformCopyInitialization(const InitializedEntity &Entity, |
| 3840 | ExprResult Init); |
| 3841 | ExprResult PerformCopyInitialization(const InitializedEntity &Entity, |
| 3842 | SourceLocation EqualLoc, |
| 3843 | ExprResult Init, |
| 3844 | bool TopLevelOfInitList = false, |
| 3845 | bool AllowExplicit = false); |
| 3846 | ExprResult PerformObjectArgumentInitialization(Expr *From, |
| 3847 | NestedNameSpecifier *Qualifier, |
| 3848 | NamedDecl *FoundDecl, |
| 3849 | CXXMethodDecl *Method); |
| 3850 | |
| 3851 | /// Check that the lifetime of the initializer (and its subobjects) is |
| 3852 | /// sufficient for initializing the entity, and perform lifetime extension |
| 3853 | /// (when permitted) if not. |
| 3854 | void checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init); |
| 3855 | |
| 3856 | ExprResult PerformContextuallyConvertToBool(Expr *From); |
| 3857 | ExprResult PerformContextuallyConvertToObjCPointer(Expr *From); |
| 3858 | |
| 3859 | /// Contexts in which a converted constant expression is required. |
| 3860 | enum CCEKind { |
| 3861 | CCEK_CaseValue, ///< Expression in a case label. |
| 3862 | CCEK_Enumerator, ///< Enumerator value with fixed underlying type. |
| 3863 | CCEK_TemplateArg, ///< Value of a non-type template parameter. |
| 3864 | CCEK_ArrayBound, ///< Array bound in array declarator or new-expression. |
| 3865 | CCEK_ExplicitBool, ///< Condition in an explicit(bool) specifier. |
| 3866 | CCEK_Noexcept ///< Condition in a noexcept(bool) specifier. |
| 3867 | }; |
| 3868 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
| 3869 | llvm::APSInt &Value, CCEKind CCE); |
| 3870 | ExprResult CheckConvertedConstantExpression(Expr *From, QualType T, |
| 3871 | APValue &Value, CCEKind CCE, |
| 3872 | NamedDecl *Dest = nullptr); |
| 3873 | |
| 3874 | /// Abstract base class used to perform a contextual implicit |
| 3875 | /// conversion from an expression to any type passing a filter. |
| 3876 | class ContextualImplicitConverter { |
| 3877 | public: |
| 3878 | bool Suppress; |
| 3879 | bool SuppressConversion; |
| 3880 | |
| 3881 | ContextualImplicitConverter(bool Suppress = false, |
| 3882 | bool SuppressConversion = false) |
| 3883 | : Suppress(Suppress), SuppressConversion(SuppressConversion) {} |
| 3884 | |
| 3885 | /// Determine whether the specified type is a valid destination type |
| 3886 | /// for this conversion. |
| 3887 | virtual bool match(QualType T) = 0; |
| 3888 | |
| 3889 | /// Emits a diagnostic complaining that the expression does not have |
| 3890 | /// integral or enumeration type. |
| 3891 | virtual SemaDiagnosticBuilder |
| 3892 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) = 0; |
| 3893 | |
| 3894 | /// Emits a diagnostic when the expression has incomplete class type. |
| 3895 | virtual SemaDiagnosticBuilder |
| 3896 | diagnoseIncomplete(Sema &S, SourceLocation Loc, QualType T) = 0; |
| 3897 | |
| 3898 | /// Emits a diagnostic when the only matching conversion function |
| 3899 | /// is explicit. |
| 3900 | virtual SemaDiagnosticBuilder diagnoseExplicitConv( |
| 3901 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
| 3902 | |
| 3903 | /// Emits a note for the explicit conversion function. |
| 3904 | virtual SemaDiagnosticBuilder |
| 3905 | noteExplicitConv(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
| 3906 | |
| 3907 | /// Emits a diagnostic when there are multiple possible conversion |
| 3908 | /// functions. |
| 3909 | virtual SemaDiagnosticBuilder |
| 3910 | diagnoseAmbiguous(Sema &S, SourceLocation Loc, QualType T) = 0; |
| 3911 | |
| 3912 | /// Emits a note for one of the candidate conversions. |
| 3913 | virtual SemaDiagnosticBuilder |
| 3914 | noteAmbiguous(Sema &S, CXXConversionDecl *Conv, QualType ConvTy) = 0; |
| 3915 | |
| 3916 | /// Emits a diagnostic when we picked a conversion function |
| 3917 | /// (for cases when we are not allowed to pick a conversion function). |
| 3918 | virtual SemaDiagnosticBuilder diagnoseConversion( |
| 3919 | Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) = 0; |
| 3920 | |
| 3921 | virtual ~ContextualImplicitConverter() {} |
| 3922 | }; |
| 3923 | |
| 3924 | class ICEConvertDiagnoser : public ContextualImplicitConverter { |
| 3925 | bool AllowScopedEnumerations; |
| 3926 | |
| 3927 | public: |
| 3928 | ICEConvertDiagnoser(bool AllowScopedEnumerations, |
| 3929 | bool Suppress, bool SuppressConversion) |
| 3930 | : ContextualImplicitConverter(Suppress, SuppressConversion), |
| 3931 | AllowScopedEnumerations(AllowScopedEnumerations) {} |
| 3932 | |
| 3933 | /// Match an integral or (possibly scoped) enumeration type. |
| 3934 | bool match(QualType T) override; |
| 3935 | |
| 3936 | SemaDiagnosticBuilder |
| 3937 | diagnoseNoMatch(Sema &S, SourceLocation Loc, QualType T) override { |
| 3938 | return diagnoseNotInt(S, Loc, T); |
| 3939 | } |
| 3940 | |
| 3941 | /// Emits a diagnostic complaining that the expression does not have |
| 3942 | /// integral or enumeration type. |
| 3943 | virtual SemaDiagnosticBuilder |
| 3944 | diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) = 0; |
| 3945 | }; |
| 3946 | |
| 3947 | /// Perform a contextual implicit conversion. |
| 3948 | ExprResult PerformContextualImplicitConversion( |
| 3949 | SourceLocation Loc, Expr *FromE, ContextualImplicitConverter &Converter); |
| 3950 | |
| 3951 | |
| 3952 | enum ObjCSubscriptKind { |
| 3953 | OS_Array, |
| 3954 | OS_Dictionary, |
| 3955 | OS_Error |
| 3956 | }; |
| 3957 | ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); |
| 3958 | |
| 3959 | // Note that LK_String is intentionally after the other literals, as |
| 3960 | // this is used for diagnostics logic. |
| 3961 | enum ObjCLiteralKind { |
| 3962 | LK_Array, |
| 3963 | LK_Dictionary, |
| 3964 | LK_Numeric, |
| 3965 | LK_Boxed, |
| 3966 | LK_String, |
| 3967 | LK_Block, |
| 3968 | LK_None |
| 3969 | }; |
| 3970 | ObjCLiteralKind CheckLiteralKind(Expr *FromE); |
| 3971 | |
| 3972 | ExprResult PerformObjectMemberConversion(Expr *From, |
| 3973 | NestedNameSpecifier *Qualifier, |
| 3974 | NamedDecl *FoundDecl, |
| 3975 | NamedDecl *Member); |
| 3976 | |
| 3977 | // Members have to be NamespaceDecl* or TranslationUnitDecl*. |
| 3978 | // TODO: make this is a typesafe union. |
| 3979 | typedef llvm::SmallSetVector<DeclContext *, 16> AssociatedNamespaceSet; |
| 3980 | typedef llvm::SmallSetVector<CXXRecordDecl *, 16> AssociatedClassSet; |
| 3981 | |
| 3982 | using ADLCallKind = CallExpr::ADLCallKind; |
| 3983 | |
| 3984 | void AddOverloadCandidate( |
| 3985 | FunctionDecl *Function, DeclAccessPair FoundDecl, ArrayRef<Expr *> Args, |
| 3986 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
| 3987 | bool PartialOverloading = false, bool AllowExplicit = true, |
| 3988 | bool AllowExplicitConversion = false, |
| 3989 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
| 3990 | ConversionSequenceList EarlyConversions = std::nullopt, |
| 3991 | OverloadCandidateParamOrder PO = {}); |
| 3992 | void AddFunctionCandidates(const UnresolvedSetImpl &Functions, |
| 3993 | ArrayRef<Expr *> Args, |
| 3994 | OverloadCandidateSet &CandidateSet, |
| 3995 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
| 3996 | bool SuppressUserConversions = false, |
| 3997 | bool PartialOverloading = false, |
| 3998 | bool FirstArgumentIsBase = false); |
| 3999 | void AddMethodCandidate(DeclAccessPair FoundDecl, |
| 4000 | QualType ObjectType, |
| 4001 | Expr::Classification ObjectClassification, |
| 4002 | ArrayRef<Expr *> Args, |
| 4003 | OverloadCandidateSet& CandidateSet, |
| 4004 | bool SuppressUserConversion = false, |
| 4005 | OverloadCandidateParamOrder PO = {}); |
| 4006 | void |
| 4007 | AddMethodCandidate(CXXMethodDecl *Method, DeclAccessPair FoundDecl, |
| 4008 | CXXRecordDecl *ActingContext, QualType ObjectType, |
| 4009 | Expr::Classification ObjectClassification, |
| 4010 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
| 4011 | bool SuppressUserConversions = false, |
| 4012 | bool PartialOverloading = false, |
| 4013 | ConversionSequenceList EarlyConversions = std::nullopt, |
| 4014 | OverloadCandidateParamOrder PO = {}); |
| 4015 | void AddMethodTemplateCandidate(FunctionTemplateDecl *MethodTmpl, |
| 4016 | DeclAccessPair FoundDecl, |
| 4017 | CXXRecordDecl *ActingContext, |
| 4018 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 4019 | QualType ObjectType, |
| 4020 | Expr::Classification ObjectClassification, |
| 4021 | ArrayRef<Expr *> Args, |
| 4022 | OverloadCandidateSet& CandidateSet, |
| 4023 | bool SuppressUserConversions = false, |
| 4024 | bool PartialOverloading = false, |
| 4025 | OverloadCandidateParamOrder PO = {}); |
| 4026 | void AddTemplateOverloadCandidate( |
| 4027 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
| 4028 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
| 4029 | OverloadCandidateSet &CandidateSet, bool SuppressUserConversions = false, |
| 4030 | bool PartialOverloading = false, bool AllowExplicit = true, |
| 4031 | ADLCallKind IsADLCandidate = ADLCallKind::NotADL, |
| 4032 | OverloadCandidateParamOrder PO = {}); |
| 4033 | bool CheckNonDependentConversions( |
| 4034 | FunctionTemplateDecl *FunctionTemplate, ArrayRef<QualType> ParamTypes, |
| 4035 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet, |
| 4036 | ConversionSequenceList &Conversions, bool SuppressUserConversions, |
| 4037 | CXXRecordDecl *ActingContext = nullptr, QualType ObjectType = QualType(), |
| 4038 | Expr::Classification ObjectClassification = {}, |
| 4039 | OverloadCandidateParamOrder PO = {}); |
| 4040 | void AddConversionCandidate( |
| 4041 | CXXConversionDecl *Conversion, DeclAccessPair FoundDecl, |
| 4042 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
| 4043 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
| 4044 | bool AllowExplicit, bool AllowResultConversion = true); |
| 4045 | void AddTemplateConversionCandidate( |
| 4046 | FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl, |
| 4047 | CXXRecordDecl *ActingContext, Expr *From, QualType ToType, |
| 4048 | OverloadCandidateSet &CandidateSet, bool AllowObjCConversionOnExplicit, |
| 4049 | bool AllowExplicit, bool AllowResultConversion = true); |
| 4050 | void AddSurrogateCandidate(CXXConversionDecl *Conversion, |
| 4051 | DeclAccessPair FoundDecl, |
| 4052 | CXXRecordDecl *ActingContext, |
| 4053 | const FunctionProtoType *Proto, |
| 4054 | Expr *Object, ArrayRef<Expr *> Args, |
| 4055 | OverloadCandidateSet& CandidateSet); |
| 4056 | void AddNonMemberOperatorCandidates( |
| 4057 | const UnresolvedSetImpl &Functions, ArrayRef<Expr *> Args, |
| 4058 | OverloadCandidateSet &CandidateSet, |
| 4059 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
| 4060 | void AddMemberOperatorCandidates(OverloadedOperatorKind Op, |
| 4061 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
| 4062 | OverloadCandidateSet &CandidateSet, |
| 4063 | OverloadCandidateParamOrder PO = {}); |
| 4064 | void AddBuiltinCandidate(QualType *ParamTys, ArrayRef<Expr *> Args, |
| 4065 | OverloadCandidateSet& CandidateSet, |
| 4066 | bool IsAssignmentOperator = false, |
| 4067 | unsigned NumContextualBoolArguments = 0); |
| 4068 | void AddBuiltinOperatorCandidates(OverloadedOperatorKind Op, |
| 4069 | SourceLocation OpLoc, ArrayRef<Expr *> Args, |
| 4070 | OverloadCandidateSet& CandidateSet); |
| 4071 | void AddArgumentDependentLookupCandidates(DeclarationName Name, |
| 4072 | SourceLocation Loc, |
| 4073 | ArrayRef<Expr *> Args, |
| 4074 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 4075 | OverloadCandidateSet& CandidateSet, |
| 4076 | bool PartialOverloading = false); |
| 4077 | |
| 4078 | // Emit as a 'note' the specific overload candidate |
| 4079 | void NoteOverloadCandidate( |
| 4080 | const NamedDecl *Found, const FunctionDecl *Fn, |
| 4081 | OverloadCandidateRewriteKind RewriteKind = OverloadCandidateRewriteKind(), |
| 4082 | QualType DestType = QualType(), bool TakingAddress = false); |
| 4083 | |
| 4084 | // Emit as a series of 'note's all template and non-templates identified by |
| 4085 | // the expression Expr |
| 4086 | void NoteAllOverloadCandidates(Expr *E, QualType DestType = QualType(), |
| 4087 | bool TakingAddress = false); |
| 4088 | |
| 4089 | /// Check the enable_if expressions on the given function. Returns the first |
| 4090 | /// failing attribute, or NULL if they were all successful. |
| 4091 | EnableIfAttr *CheckEnableIf(FunctionDecl *Function, SourceLocation CallLoc, |
| 4092 | ArrayRef<Expr *> Args, |
| 4093 | bool MissingImplicitThis = false); |
| 4094 | |
| 4095 | /// Find the failed Boolean condition within a given Boolean |
| 4096 | /// constant expression, and describe it with a string. |
| 4097 | std::pair<Expr *, std::string> findFailedBooleanCondition(Expr *Cond); |
| 4098 | |
| 4099 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
| 4100 | /// non-ArgDependent DiagnoseIfAttrs. |
| 4101 | /// |
| 4102 | /// Argument-dependent diagnose_if attributes should be checked each time a |
| 4103 | /// function is used as a direct callee of a function call. |
| 4104 | /// |
| 4105 | /// Returns true if any errors were emitted. |
| 4106 | bool diagnoseArgDependentDiagnoseIfAttrs(const FunctionDecl *Function, |
| 4107 | const Expr *ThisArg, |
| 4108 | ArrayRef<const Expr *> Args, |
| 4109 | SourceLocation Loc); |
| 4110 | |
| 4111 | /// Emit diagnostics for the diagnose_if attributes on Function, ignoring any |
| 4112 | /// ArgDependent DiagnoseIfAttrs. |
| 4113 | /// |
| 4114 | /// Argument-independent diagnose_if attributes should be checked on every use |
| 4115 | /// of a function. |
| 4116 | /// |
| 4117 | /// Returns true if any errors were emitted. |
| 4118 | bool diagnoseArgIndependentDiagnoseIfAttrs(const NamedDecl *ND, |
| 4119 | SourceLocation Loc); |
| 4120 | |
| 4121 | /// Returns whether the given function's address can be taken or not, |
| 4122 | /// optionally emitting a diagnostic if the address can't be taken. |
| 4123 | /// |
| 4124 | /// Returns false if taking the address of the function is illegal. |
| 4125 | bool checkAddressOfFunctionIsAvailable(const FunctionDecl *Function, |
| 4126 | bool Complain = false, |
| 4127 | SourceLocation Loc = SourceLocation()); |
| 4128 | |
| 4129 | // [PossiblyAFunctionType] --> [Return] |
| 4130 | // NonFunctionType --> NonFunctionType |
| 4131 | // R (A) --> R(A) |
| 4132 | // R (*)(A) --> R (A) |
| 4133 | // R (&)(A) --> R (A) |
| 4134 | // R (S::*)(A) --> R (A) |
| 4135 | QualType ExtractUnqualifiedFunctionType(QualType PossiblyAFunctionType); |
| 4136 | |
| 4137 | FunctionDecl * |
| 4138 | ResolveAddressOfOverloadedFunction(Expr *AddressOfExpr, |
| 4139 | QualType TargetType, |
| 4140 | bool Complain, |
| 4141 | DeclAccessPair &Found, |
| 4142 | bool *pHadMultipleCandidates = nullptr); |
| 4143 | |
| 4144 | FunctionDecl * |
| 4145 | resolveAddressOfSingleOverloadCandidate(Expr *E, DeclAccessPair &FoundResult); |
| 4146 | |
| 4147 | bool resolveAndFixAddressOfSingleOverloadCandidate( |
| 4148 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false); |
| 4149 | |
| 4150 | FunctionDecl * |
| 4151 | ResolveSingleFunctionTemplateSpecialization(OverloadExpr *ovl, |
| 4152 | bool Complain = false, |
| 4153 | DeclAccessPair *Found = nullptr); |
| 4154 | |
| 4155 | bool ResolveAndFixSingleFunctionTemplateSpecialization( |
| 4156 | ExprResult &SrcExpr, bool DoFunctionPointerConversion = false, |
| 4157 | bool Complain = false, SourceRange OpRangeForComplaining = SourceRange(), |
| 4158 | QualType DestTypeForComplaining = QualType(), |
| 4159 | unsigned DiagIDForComplaining = 0); |
| 4160 | |
| 4161 | Expr *FixOverloadedFunctionReference(Expr *E, |
| 4162 | DeclAccessPair FoundDecl, |
| 4163 | FunctionDecl *Fn); |
| 4164 | ExprResult FixOverloadedFunctionReference(ExprResult, |
| 4165 | DeclAccessPair FoundDecl, |
| 4166 | FunctionDecl *Fn); |
| 4167 | |
| 4168 | void AddOverloadedCallCandidates(UnresolvedLookupExpr *ULE, |
| 4169 | ArrayRef<Expr *> Args, |
| 4170 | OverloadCandidateSet &CandidateSet, |
| 4171 | bool PartialOverloading = false); |
| 4172 | void AddOverloadedCallCandidates( |
| 4173 | LookupResult &R, TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 4174 | ArrayRef<Expr *> Args, OverloadCandidateSet &CandidateSet); |
| 4175 | |
| 4176 | // An enum used to represent the different possible results of building a |
| 4177 | // range-based for loop. |
| 4178 | enum ForRangeStatus { |
| 4179 | FRS_Success, |
| 4180 | FRS_NoViableFunction, |
| 4181 | FRS_DiagnosticIssued |
| 4182 | }; |
| 4183 | |
| 4184 | ForRangeStatus BuildForRangeBeginEndCall(SourceLocation Loc, |
| 4185 | SourceLocation RangeLoc, |
| 4186 | const DeclarationNameInfo &NameInfo, |
| 4187 | LookupResult &MemberLookup, |
| 4188 | OverloadCandidateSet *CandidateSet, |
| 4189 | Expr *Range, ExprResult *CallExpr); |
| 4190 | |
| 4191 | ExprResult BuildOverloadedCallExpr(Scope *S, Expr *Fn, |
| 4192 | UnresolvedLookupExpr *ULE, |
| 4193 | SourceLocation LParenLoc, |
| 4194 | MultiExprArg Args, |
| 4195 | SourceLocation RParenLoc, |
| 4196 | Expr *ExecConfig, |
| 4197 | bool AllowTypoCorrection=true, |
| 4198 | bool CalleesAddressIsTaken=false); |
| 4199 | |
| 4200 | bool buildOverloadedCallSet(Scope *S, Expr *Fn, UnresolvedLookupExpr *ULE, |
| 4201 | MultiExprArg Args, SourceLocation RParenLoc, |
| 4202 | OverloadCandidateSet *CandidateSet, |
| 4203 | ExprResult *Result); |
| 4204 | |
| 4205 | ExprResult CreateUnresolvedLookupExpr(CXXRecordDecl *NamingClass, |
| 4206 | NestedNameSpecifierLoc NNSLoc, |
| 4207 | DeclarationNameInfo DNI, |
| 4208 | const UnresolvedSetImpl &Fns, |
| 4209 | bool PerformADL = true); |
| 4210 | |
| 4211 | ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, |
| 4212 | UnaryOperatorKind Opc, |
| 4213 | const UnresolvedSetImpl &Fns, |
| 4214 | Expr *input, bool RequiresADL = true); |
| 4215 | |
| 4216 | void LookupOverloadedBinOp(OverloadCandidateSet &CandidateSet, |
| 4217 | OverloadedOperatorKind Op, |
| 4218 | const UnresolvedSetImpl &Fns, |
| 4219 | ArrayRef<Expr *> Args, bool RequiresADL = true); |
| 4220 | ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, |
| 4221 | BinaryOperatorKind Opc, |
| 4222 | const UnresolvedSetImpl &Fns, |
| 4223 | Expr *LHS, Expr *RHS, |
| 4224 | bool RequiresADL = true, |
| 4225 | bool AllowRewrittenCandidates = true, |
| 4226 | FunctionDecl *DefaultedFn = nullptr); |
| 4227 | ExprResult BuildSynthesizedThreeWayComparison(SourceLocation OpLoc, |
| 4228 | const UnresolvedSetImpl &Fns, |
| 4229 | Expr *LHS, Expr *RHS, |
| 4230 | FunctionDecl *DefaultedFn); |
| 4231 | |
| 4232 | ExprResult CreateOverloadedArraySubscriptExpr(SourceLocation LLoc, |
| 4233 | SourceLocation RLoc, Expr *Base, |
| 4234 | MultiExprArg Args); |
| 4235 | |
| 4236 | ExprResult BuildCallToMemberFunction(Scope *S, Expr *MemExpr, |
| 4237 | SourceLocation LParenLoc, |
| 4238 | MultiExprArg Args, |
| 4239 | SourceLocation RParenLoc, |
| 4240 | Expr *ExecConfig = nullptr, |
| 4241 | bool IsExecConfig = false, |
| 4242 | bool AllowRecovery = false); |
| 4243 | ExprResult |
| 4244 | BuildCallToObjectOfClassType(Scope *S, Expr *Object, SourceLocation LParenLoc, |
| 4245 | MultiExprArg Args, |
| 4246 | SourceLocation RParenLoc); |
| 4247 | |
| 4248 | ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, |
| 4249 | SourceLocation OpLoc, |
| 4250 | bool *NoArrowOperatorFound = nullptr); |
| 4251 | |
| 4252 | /// CheckCallReturnType - Checks that a call expression's return type is |
| 4253 | /// complete. Returns true on failure. The location passed in is the location |
| 4254 | /// that best represents the call. |
| 4255 | bool CheckCallReturnType(QualType ReturnType, SourceLocation Loc, |
| 4256 | CallExpr *CE, FunctionDecl *FD); |
| 4257 | |
| 4258 | /// Helpers for dealing with blocks and functions. |
| 4259 | bool CheckParmsForFunctionDef(ArrayRef<ParmVarDecl *> Parameters, |
| 4260 | bool CheckParameterNames); |
| 4261 | void CheckCXXDefaultArguments(FunctionDecl *FD); |
| 4262 | void CheckExtraCXXDefaultArguments(Declarator &D); |
| 4263 | Scope *getNonFieldDeclScope(Scope *S); |
| 4264 | |
| 4265 | /// \name Name lookup |
| 4266 | /// |
| 4267 | /// These routines provide name lookup that is used during semantic |
| 4268 | /// analysis to resolve the various kinds of names (identifiers, |
| 4269 | /// overloaded operator names, constructor names, etc.) into zero or |
| 4270 | /// more declarations within a particular scope. The major entry |
| 4271 | /// points are LookupName, which performs unqualified name lookup, |
| 4272 | /// and LookupQualifiedName, which performs qualified name lookup. |
| 4273 | /// |
| 4274 | /// All name lookup is performed based on some specific criteria, |
| 4275 | /// which specify what names will be visible to name lookup and how |
| 4276 | /// far name lookup should work. These criteria are important both |
| 4277 | /// for capturing language semantics (certain lookups will ignore |
| 4278 | /// certain names, for example) and for performance, since name |
| 4279 | /// lookup is often a bottleneck in the compilation of C++. Name |
| 4280 | /// lookup criteria is specified via the LookupCriteria enumeration. |
| 4281 | /// |
| 4282 | /// The results of name lookup can vary based on the kind of name |
| 4283 | /// lookup performed, the current language, and the translation |
| 4284 | /// unit. In C, for example, name lookup will either return nothing |
| 4285 | /// (no entity found) or a single declaration. In C++, name lookup |
| 4286 | /// can additionally refer to a set of overloaded functions or |
| 4287 | /// result in an ambiguity. All of the possible results of name |
| 4288 | /// lookup are captured by the LookupResult class, which provides |
| 4289 | /// the ability to distinguish among them. |
| 4290 | //@{ |
| 4291 | |
| 4292 | /// Describes the kind of name lookup to perform. |
| 4293 | enum LookupNameKind { |
| 4294 | /// Ordinary name lookup, which finds ordinary names (functions, |
| 4295 | /// variables, typedefs, etc.) in C and most kinds of names |
| 4296 | /// (functions, variables, members, types, etc.) in C++. |
| 4297 | LookupOrdinaryName = 0, |
| 4298 | /// Tag name lookup, which finds the names of enums, classes, |
| 4299 | /// structs, and unions. |
| 4300 | LookupTagName, |
| 4301 | /// Label name lookup. |
| 4302 | LookupLabel, |
| 4303 | /// Member name lookup, which finds the names of |
| 4304 | /// class/struct/union members. |
| 4305 | LookupMemberName, |
| 4306 | /// Look up of an operator name (e.g., operator+) for use with |
| 4307 | /// operator overloading. This lookup is similar to ordinary name |
| 4308 | /// lookup, but will ignore any declarations that are class members. |
| 4309 | LookupOperatorName, |
| 4310 | /// Look up a name following ~ in a destructor name. This is an ordinary |
| 4311 | /// lookup, but prefers tags to typedefs. |
| 4312 | LookupDestructorName, |
| 4313 | /// Look up of a name that precedes the '::' scope resolution |
| 4314 | /// operator in C++. This lookup completely ignores operator, object, |
| 4315 | /// function, and enumerator names (C++ [basic.lookup.qual]p1). |
| 4316 | LookupNestedNameSpecifierName, |
| 4317 | /// Look up a namespace name within a C++ using directive or |
| 4318 | /// namespace alias definition, ignoring non-namespace names (C++ |
| 4319 | /// [basic.lookup.udir]p1). |
| 4320 | LookupNamespaceName, |
| 4321 | /// Look up all declarations in a scope with the given name, |
| 4322 | /// including resolved using declarations. This is appropriate |
| 4323 | /// for checking redeclarations for a using declaration. |
| 4324 | LookupUsingDeclName, |
| 4325 | /// Look up an ordinary name that is going to be redeclared as a |
| 4326 | /// name with linkage. This lookup ignores any declarations that |
| 4327 | /// are outside of the current scope unless they have linkage. See |
| 4328 | /// C99 6.2.2p4-5 and C++ [basic.link]p6. |
| 4329 | LookupRedeclarationWithLinkage, |
| 4330 | /// Look up a friend of a local class. This lookup does not look |
| 4331 | /// outside the innermost non-class scope. See C++11 [class.friend]p11. |
| 4332 | LookupLocalFriendName, |
| 4333 | /// Look up the name of an Objective-C protocol. |
| 4334 | LookupObjCProtocolName, |
| 4335 | /// Look up implicit 'self' parameter of an objective-c method. |
| 4336 | LookupObjCImplicitSelfParam, |
| 4337 | /// Look up the name of an OpenMP user-defined reduction operation. |
| 4338 | LookupOMPReductionName, |
| 4339 | /// Look up the name of an OpenMP user-defined mapper. |
| 4340 | LookupOMPMapperName, |
| 4341 | /// Look up any declaration with any name. |
| 4342 | LookupAnyName |
| 4343 | }; |
| 4344 | |
| 4345 | /// Specifies whether (or how) name lookup is being performed for a |
| 4346 | /// redeclaration (vs. a reference). |
| 4347 | enum RedeclarationKind { |
| 4348 | /// The lookup is a reference to this name that is not for the |
| 4349 | /// purpose of redeclaring the name. |
| 4350 | NotForRedeclaration = 0, |
| 4351 | /// The lookup results will be used for redeclaration of a name, |
| 4352 | /// if an entity by that name already exists and is visible. |
| 4353 | ForVisibleRedeclaration, |
| 4354 | /// The lookup results will be used for redeclaration of a name |
| 4355 | /// with external linkage; non-visible lookup results with external linkage |
| 4356 | /// may also be found. |
| 4357 | ForExternalRedeclaration |
| 4358 | }; |
| 4359 | |
| 4360 | RedeclarationKind forRedeclarationInCurContext() const { |
| 4361 | // A declaration with an owning module for linkage can never link against |
| 4362 | // anything that is not visible. We don't need to check linkage here; if |
| 4363 | // the context has internal linkage, redeclaration lookup won't find things |
| 4364 | // from other TUs, and we can't safely compute linkage yet in general. |
| 4365 | if (cast<Decl>(CurContext) |
| 4366 | ->getOwningModuleForLinkage(/*IgnoreLinkage*/true)) |
| 4367 | return ForVisibleRedeclaration; |
| 4368 | return ForExternalRedeclaration; |
| 4369 | } |
| 4370 | |
| 4371 | /// The possible outcomes of name lookup for a literal operator. |
| 4372 | enum LiteralOperatorLookupResult { |
| 4373 | /// The lookup resulted in an error. |
| 4374 | LOLR_Error, |
| 4375 | /// The lookup found no match but no diagnostic was issued. |
| 4376 | LOLR_ErrorNoDiagnostic, |
| 4377 | /// The lookup found a single 'cooked' literal operator, which |
| 4378 | /// expects a normal literal to be built and passed to it. |
| 4379 | LOLR_Cooked, |
| 4380 | /// The lookup found a single 'raw' literal operator, which expects |
| 4381 | /// a string literal containing the spelling of the literal token. |
| 4382 | LOLR_Raw, |
| 4383 | /// The lookup found an overload set of literal operator templates, |
| 4384 | /// which expect the characters of the spelling of the literal token to be |
| 4385 | /// passed as a non-type template argument pack. |
| 4386 | LOLR_Template, |
| 4387 | /// The lookup found an overload set of literal operator templates, |
| 4388 | /// which expect the character type and characters of the spelling of the |
| 4389 | /// string literal token to be passed as template arguments. |
| 4390 | LOLR_StringTemplatePack, |
| 4391 | }; |
| 4392 | |
| 4393 | SpecialMemberOverloadResult LookupSpecialMember(CXXRecordDecl *D, |
| 4394 | CXXSpecialMember SM, |
| 4395 | bool ConstArg, |
| 4396 | bool VolatileArg, |
| 4397 | bool RValueThis, |
| 4398 | bool ConstThis, |
| 4399 | bool VolatileThis); |
| 4400 | |
| 4401 | typedef std::function<void(const TypoCorrection &)> TypoDiagnosticGenerator; |
| 4402 | typedef std::function<ExprResult(Sema &, TypoExpr *, TypoCorrection)> |
| 4403 | TypoRecoveryCallback; |
| 4404 | |
| 4405 | private: |
| 4406 | bool CppLookupName(LookupResult &R, Scope *S); |
| 4407 | |
| 4408 | struct TypoExprState { |
| 4409 | std::unique_ptr<TypoCorrectionConsumer> Consumer; |
| 4410 | TypoDiagnosticGenerator DiagHandler; |
| 4411 | TypoRecoveryCallback RecoveryHandler; |
| 4412 | TypoExprState(); |
| 4413 | TypoExprState(TypoExprState &&other) noexcept; |
| 4414 | TypoExprState &operator=(TypoExprState &&other) noexcept; |
| 4415 | }; |
| 4416 | |
| 4417 | /// The set of unhandled TypoExprs and their associated state. |
| 4418 | llvm::MapVector<TypoExpr *, TypoExprState> DelayedTypos; |
| 4419 | |
| 4420 | /// Creates a new TypoExpr AST node. |
| 4421 | TypoExpr *createDelayedTypo(std::unique_ptr<TypoCorrectionConsumer> TCC, |
| 4422 | TypoDiagnosticGenerator TDG, |
| 4423 | TypoRecoveryCallback TRC, SourceLocation TypoLoc); |
| 4424 | |
| 4425 | // The set of known/encountered (unique, canonicalized) NamespaceDecls. |
| 4426 | // |
| 4427 | // The boolean value will be true to indicate that the namespace was loaded |
| 4428 | // from an AST/PCH file, or false otherwise. |
| 4429 | llvm::MapVector<NamespaceDecl*, bool> KnownNamespaces; |
| 4430 | |
| 4431 | /// Whether we have already loaded known namespaces from an extenal |
| 4432 | /// source. |
| 4433 | bool LoadedExternalKnownNamespaces; |
| 4434 | |
| 4435 | /// Helper for CorrectTypo and CorrectTypoDelayed used to create and |
| 4436 | /// populate a new TypoCorrectionConsumer. Returns nullptr if typo correction |
| 4437 | /// should be skipped entirely. |
| 4438 | std::unique_ptr<TypoCorrectionConsumer> |
| 4439 | makeTypoCorrectionConsumer(const DeclarationNameInfo &Typo, |
| 4440 | Sema::LookupNameKind LookupKind, Scope *S, |
| 4441 | CXXScopeSpec *SS, |
| 4442 | CorrectionCandidateCallback &CCC, |
| 4443 | DeclContext *MemberContext, bool EnteringContext, |
| 4444 | const ObjCObjectPointerType *OPT, |
| 4445 | bool ErrorRecovery); |
| 4446 | |
| 4447 | public: |
| 4448 | const TypoExprState &getTypoExprState(TypoExpr *TE) const; |
| 4449 | |
| 4450 | /// Clears the state of the given TypoExpr. |
| 4451 | void clearDelayedTypo(TypoExpr *TE); |
| 4452 | |
| 4453 | /// Look up a name, looking for a single declaration. Return |
| 4454 | /// null if the results were absent, ambiguous, or overloaded. |
| 4455 | /// |
| 4456 | /// It is preferable to use the elaborated form and explicitly handle |
| 4457 | /// ambiguity and overloaded. |
| 4458 | NamedDecl *LookupSingleName(Scope *S, DeclarationName Name, |
| 4459 | SourceLocation Loc, |
| 4460 | LookupNameKind NameKind, |
| 4461 | RedeclarationKind Redecl |
| 4462 | = NotForRedeclaration); |
| 4463 | bool LookupBuiltin(LookupResult &R); |
| 4464 | void LookupNecessaryTypesForBuiltin(Scope *S, unsigned ID); |
| 4465 | bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation = false, |
| 4466 | bool ForceNoCPlusPlus = false); |
| 4467 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
| 4468 | bool InUnqualifiedLookup = false); |
| 4469 | bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, |
| 4470 | CXXScopeSpec &SS); |
| 4471 | bool LookupParsedName(LookupResult &R, Scope *S, CXXScopeSpec *SS, |
| 4472 | bool AllowBuiltinCreation = false, |
| 4473 | bool EnteringContext = false); |
| 4474 | ObjCProtocolDecl *LookupProtocol(IdentifierInfo *II, SourceLocation IdLoc, |
| 4475 | RedeclarationKind Redecl |
| 4476 | = NotForRedeclaration); |
| 4477 | bool LookupInSuper(LookupResult &R, CXXRecordDecl *Class); |
| 4478 | |
| 4479 | void LookupOverloadedOperatorName(OverloadedOperatorKind Op, Scope *S, |
| 4480 | UnresolvedSetImpl &Functions); |
| 4481 | |
| 4482 | LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc, |
| 4483 | SourceLocation GnuLabelLoc = SourceLocation()); |
| 4484 | |
| 4485 | DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class); |
| 4486 | CXXConstructorDecl *LookupDefaultConstructor(CXXRecordDecl *Class); |
| 4487 | CXXConstructorDecl *LookupCopyingConstructor(CXXRecordDecl *Class, |
| 4488 | unsigned Quals); |
| 4489 | CXXMethodDecl *LookupCopyingAssignment(CXXRecordDecl *Class, unsigned Quals, |
| 4490 | bool RValueThis, unsigned ThisQuals); |
| 4491 | CXXConstructorDecl *LookupMovingConstructor(CXXRecordDecl *Class, |
| 4492 | unsigned Quals); |
| 4493 | CXXMethodDecl *LookupMovingAssignment(CXXRecordDecl *Class, unsigned Quals, |
| 4494 | bool RValueThis, unsigned ThisQuals); |
| 4495 | CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class); |
| 4496 | |
| 4497 | bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id, |
| 4498 | bool IsUDSuffix); |
| 4499 | LiteralOperatorLookupResult |
| 4500 | LookupLiteralOperator(Scope *S, LookupResult &R, ArrayRef<QualType> ArgTys, |
| 4501 | bool AllowRaw, bool AllowTemplate, |
| 4502 | bool AllowStringTemplate, bool DiagnoseMissing, |
| 4503 | StringLiteral *StringLit = nullptr); |
| 4504 | bool isKnownName(StringRef name); |
| 4505 | |
| 4506 | /// Status of the function emission on the CUDA/HIP/OpenMP host/device attrs. |
| 4507 | enum class FunctionEmissionStatus { |
| 4508 | Emitted, |
| 4509 | CUDADiscarded, // Discarded due to CUDA/HIP hostness |
| 4510 | OMPDiscarded, // Discarded due to OpenMP hostness |
| 4511 | TemplateDiscarded, // Discarded due to uninstantiated templates |
| 4512 | Unknown, |
| 4513 | }; |
| 4514 | FunctionEmissionStatus getEmissionStatus(const FunctionDecl *Decl, |
| 4515 | bool Final = false); |
| 4516 | |
| 4517 | // Whether the callee should be ignored in CUDA/HIP/OpenMP host/device check. |
| 4518 | bool shouldIgnoreInHostDeviceCheck(FunctionDecl *Callee); |
| 4519 | |
| 4520 | void ArgumentDependentLookup(DeclarationName Name, SourceLocation Loc, |
| 4521 | ArrayRef<Expr *> Args, ADLResult &Functions); |
| 4522 | |
| 4523 | void LookupVisibleDecls(Scope *S, LookupNameKind Kind, |
| 4524 | VisibleDeclConsumer &Consumer, |
| 4525 | bool IncludeGlobalScope = true, |
| 4526 | bool LoadExternal = true); |
| 4527 | void LookupVisibleDecls(DeclContext *Ctx, LookupNameKind Kind, |
| 4528 | VisibleDeclConsumer &Consumer, |
| 4529 | bool IncludeGlobalScope = true, |
| 4530 | bool IncludeDependentBases = false, |
| 4531 | bool LoadExternal = true); |
| 4532 | |
| 4533 | enum CorrectTypoKind { |
| 4534 | CTK_NonError, // CorrectTypo used in a non error recovery situation. |
| 4535 | CTK_ErrorRecovery // CorrectTypo used in normal error recovery. |
| 4536 | }; |
| 4537 | |
| 4538 | TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, |
| 4539 | Sema::LookupNameKind LookupKind, |
| 4540 | Scope *S, CXXScopeSpec *SS, |
| 4541 | CorrectionCandidateCallback &CCC, |
| 4542 | CorrectTypoKind Mode, |
| 4543 | DeclContext *MemberContext = nullptr, |
| 4544 | bool EnteringContext = false, |
| 4545 | const ObjCObjectPointerType *OPT = nullptr, |
| 4546 | bool RecordFailure = true); |
| 4547 | |
| 4548 | TypoExpr *CorrectTypoDelayed(const DeclarationNameInfo &Typo, |
| 4549 | Sema::LookupNameKind LookupKind, Scope *S, |
| 4550 | CXXScopeSpec *SS, |
| 4551 | CorrectionCandidateCallback &CCC, |
| 4552 | TypoDiagnosticGenerator TDG, |
| 4553 | TypoRecoveryCallback TRC, CorrectTypoKind Mode, |
| 4554 | DeclContext *MemberContext = nullptr, |
| 4555 | bool EnteringContext = false, |
| 4556 | const ObjCObjectPointerType *OPT = nullptr); |
| 4557 | |
| 4558 | /// Process any TypoExprs in the given Expr and its children, |
| 4559 | /// generating diagnostics as appropriate and returning a new Expr if there |
| 4560 | /// were typos that were all successfully corrected and ExprError if one or |
| 4561 | /// more typos could not be corrected. |
| 4562 | /// |
| 4563 | /// \param E The Expr to check for TypoExprs. |
| 4564 | /// |
| 4565 | /// \param InitDecl A VarDecl to avoid because the Expr being corrected is its |
| 4566 | /// initializer. |
| 4567 | /// |
| 4568 | /// \param RecoverUncorrectedTypos If true, when typo correction fails, it |
| 4569 | /// will rebuild the given Expr with all TypoExprs degraded to RecoveryExprs. |
| 4570 | /// |
| 4571 | /// \param Filter A function applied to a newly rebuilt Expr to determine if |
| 4572 | /// it is an acceptable/usable result from a single combination of typo |
| 4573 | /// corrections. As long as the filter returns ExprError, different |
| 4574 | /// combinations of corrections will be tried until all are exhausted. |
| 4575 | ExprResult CorrectDelayedTyposInExpr( |
| 4576 | Expr *E, VarDecl *InitDecl = nullptr, |
| 4577 | bool RecoverUncorrectedTypos = false, |
| 4578 | llvm::function_ref<ExprResult(Expr *)> Filter = |
| 4579 | [](Expr *E) -> ExprResult { return E; }); |
| 4580 | |
| 4581 | ExprResult CorrectDelayedTyposInExpr( |
| 4582 | ExprResult ER, VarDecl *InitDecl = nullptr, |
| 4583 | bool RecoverUncorrectedTypos = false, |
| 4584 | llvm::function_ref<ExprResult(Expr *)> Filter = |
| 4585 | [](Expr *E) -> ExprResult { return E; }) { |
| 4586 | return ER.isInvalid() |
| 4587 | ? ER |
| 4588 | : CorrectDelayedTyposInExpr(ER.get(), InitDecl, |
| 4589 | RecoverUncorrectedTypos, Filter); |
| 4590 | } |
| 4591 | |
| 4592 | void diagnoseTypo(const TypoCorrection &Correction, |
| 4593 | const PartialDiagnostic &TypoDiag, |
| 4594 | bool ErrorRecovery = true); |
| 4595 | |
| 4596 | void diagnoseTypo(const TypoCorrection &Correction, |
| 4597 | const PartialDiagnostic &TypoDiag, |
| 4598 | const PartialDiagnostic &PrevNote, |
| 4599 | bool ErrorRecovery = true); |
| 4600 | |
| 4601 | void MarkTypoCorrectedFunctionDefinition(const NamedDecl *F); |
| 4602 | |
| 4603 | void FindAssociatedClassesAndNamespaces(SourceLocation InstantiationLoc, |
| 4604 | ArrayRef<Expr *> Args, |
| 4605 | AssociatedNamespaceSet &AssociatedNamespaces, |
| 4606 | AssociatedClassSet &AssociatedClasses); |
| 4607 | |
| 4608 | void FilterLookupForScope(LookupResult &R, DeclContext *Ctx, Scope *S, |
| 4609 | bool ConsiderLinkage, bool AllowInlineNamespace); |
| 4610 | |
| 4611 | bool CheckRedeclarationModuleOwnership(NamedDecl *New, NamedDecl *Old); |
| 4612 | bool CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old); |
| 4613 | bool CheckRedeclarationInModule(NamedDecl *New, NamedDecl *Old); |
| 4614 | bool IsRedefinitionInModule(const NamedDecl *New, |
| 4615 | const NamedDecl *Old) const; |
| 4616 | |
| 4617 | void DiagnoseAmbiguousLookup(LookupResult &Result); |
| 4618 | //@} |
| 4619 | |
| 4620 | /// Attempts to produce a RecoveryExpr after some AST node cannot be created. |
| 4621 | ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, |
| 4622 | ArrayRef<Expr *> SubExprs, |
| 4623 | QualType T = QualType()); |
| 4624 | |
| 4625 | ObjCInterfaceDecl *getObjCInterfaceDecl(IdentifierInfo *&Id, |
| 4626 | SourceLocation IdLoc, |
| 4627 | bool TypoCorrection = false); |
| 4628 | FunctionDecl *CreateBuiltin(IdentifierInfo *II, QualType Type, unsigned ID, |
| 4629 | SourceLocation Loc); |
| 4630 | NamedDecl *LazilyCreateBuiltin(IdentifierInfo *II, unsigned ID, |
| 4631 | Scope *S, bool ForRedeclaration, |
| 4632 | SourceLocation Loc); |
| 4633 | NamedDecl *ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II, |
| 4634 | Scope *S); |
| 4635 | void AddKnownFunctionAttributesForReplaceableGlobalAllocationFunction( |
| 4636 | FunctionDecl *FD); |
| 4637 | void AddKnownFunctionAttributes(FunctionDecl *FD); |
| 4638 | |
| 4639 | // More parsing and symbol table subroutines. |
| 4640 | |
| 4641 | void ProcessPragmaWeak(Scope *S, Decl *D); |
| 4642 | // Decl attributes - this routine is the top level dispatcher. |
| 4643 | void ProcessDeclAttributes(Scope *S, Decl *D, const Declarator &PD); |
| 4644 | // Helper for delayed processing of attributes. |
| 4645 | void ProcessDeclAttributeDelayed(Decl *D, |
| 4646 | const ParsedAttributesView &AttrList); |
| 4647 | |
| 4648 | // Options for ProcessDeclAttributeList(). |
| 4649 | struct ProcessDeclAttributeOptions { |
| 4650 | ProcessDeclAttributeOptions() |
| 4651 | : IncludeCXX11Attributes(true), IgnoreTypeAttributes(false) {} |
| 4652 | |
| 4653 | ProcessDeclAttributeOptions WithIncludeCXX11Attributes(bool Val) { |
| 4654 | ProcessDeclAttributeOptions Result = *this; |
| 4655 | Result.IncludeCXX11Attributes = Val; |
| 4656 | return Result; |
| 4657 | } |
| 4658 | |
| 4659 | ProcessDeclAttributeOptions WithIgnoreTypeAttributes(bool Val) { |
| 4660 | ProcessDeclAttributeOptions Result = *this; |
| 4661 | Result.IgnoreTypeAttributes = Val; |
| 4662 | return Result; |
| 4663 | } |
| 4664 | |
| 4665 | // Should C++11 attributes be processed? |
| 4666 | bool IncludeCXX11Attributes; |
| 4667 | |
| 4668 | // Should any type attributes encountered be ignored? |
| 4669 | // If this option is false, a diagnostic will be emitted for any type |
| 4670 | // attributes of a kind that does not "slide" from the declaration to |
| 4671 | // the decl-specifier-seq. |
| 4672 | bool IgnoreTypeAttributes; |
| 4673 | }; |
| 4674 | |
| 4675 | void ProcessDeclAttributeList(Scope *S, Decl *D, |
| 4676 | const ParsedAttributesView &AttrList, |
| 4677 | const ProcessDeclAttributeOptions &Options = |
| 4678 | ProcessDeclAttributeOptions()); |
| 4679 | bool ProcessAccessDeclAttributeList(AccessSpecDecl *ASDecl, |
| 4680 | const ParsedAttributesView &AttrList); |
| 4681 | |
| 4682 | void checkUnusedDeclAttributes(Declarator &D); |
| 4683 | |
| 4684 | /// Handles semantic checking for features that are common to all attributes, |
| 4685 | /// such as checking whether a parameter was properly specified, or the |
| 4686 | /// correct number of arguments were passed, etc. Returns true if the |
| 4687 | /// attribute has been diagnosed. |
| 4688 | bool checkCommonAttributeFeatures(const Decl *D, const ParsedAttr &A, |
| 4689 | bool SkipArgCountCheck = false); |
| 4690 | bool checkCommonAttributeFeatures(const Stmt *S, const ParsedAttr &A, |
| 4691 | bool SkipArgCountCheck = false); |
| 4692 | |
| 4693 | /// Determine if type T is a valid subject for a nonnull and similar |
| 4694 | /// attributes. By default, we look through references (the behavior used by |
| 4695 | /// nonnull), but if the second parameter is true, then we treat a reference |
| 4696 | /// type as valid. |
| 4697 | bool isValidPointerAttrType(QualType T, bool RefOkay = false); |
| 4698 | |
| 4699 | bool CheckRegparmAttr(const ParsedAttr &attr, unsigned &value); |
| 4700 | bool CheckCallingConvAttr(const ParsedAttr &attr, CallingConv &CC, |
| 4701 | const FunctionDecl *FD = nullptr); |
| 4702 | bool CheckAttrTarget(const ParsedAttr &CurrAttr); |
| 4703 | bool CheckAttrNoArgs(const ParsedAttr &CurrAttr); |
| 4704 | bool checkStringLiteralArgumentAttr(const AttributeCommonInfo &CI, |
| 4705 | const Expr *E, StringRef &Str, |
| 4706 | SourceLocation *ArgLocation = nullptr); |
| 4707 | bool checkStringLiteralArgumentAttr(const ParsedAttr &Attr, unsigned ArgNum, |
| 4708 | StringRef &Str, |
| 4709 | SourceLocation *ArgLocation = nullptr); |
| 4710 | llvm::Error isValidSectionSpecifier(StringRef Str); |
| 4711 | bool checkSectionName(SourceLocation LiteralLoc, StringRef Str); |
| 4712 | bool checkTargetAttr(SourceLocation LiteralLoc, StringRef Str); |
| 4713 | bool checkTargetVersionAttr(SourceLocation LiteralLoc, StringRef &Str, |
| 4714 | bool &isDefault); |
| 4715 | bool |
| 4716 | checkTargetClonesAttrString(SourceLocation LiteralLoc, StringRef Str, |
| 4717 | const StringLiteral *Literal, bool &HasDefault, |
| 4718 | bool &HasCommas, bool &HasNotDefault, |
| 4719 | SmallVectorImpl<SmallString<64>> &StringsBuffer); |
| 4720 | bool checkMSInheritanceAttrOnDefinition( |
| 4721 | CXXRecordDecl *RD, SourceRange Range, bool BestCase, |
| 4722 | MSInheritanceModel SemanticSpelling); |
| 4723 | |
| 4724 | void CheckAlignasUnderalignment(Decl *D); |
| 4725 | |
| 4726 | bool CheckNoInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
| 4727 | const AttributeCommonInfo &A); |
| 4728 | bool CheckAlwaysInlineAttr(const Stmt *OrigSt, const Stmt *CurSt, |
| 4729 | const AttributeCommonInfo &A); |
| 4730 | |
| 4731 | /// Adjust the calling convention of a method to be the ABI default if it |
| 4732 | /// wasn't specified explicitly. This handles method types formed from |
| 4733 | /// function type typedefs and typename template arguments. |
| 4734 | void adjustMemberFunctionCC(QualType &T, bool IsStatic, bool IsCtorOrDtor, |
| 4735 | SourceLocation Loc); |
| 4736 | |
| 4737 | // Check if there is an explicit attribute, but only look through parens. |
| 4738 | // The intent is to look for an attribute on the current declarator, but not |
| 4739 | // one that came from a typedef. |
| 4740 | bool hasExplicitCallingConv(QualType T); |
| 4741 | |
| 4742 | /// Get the outermost AttributedType node that sets a calling convention. |
| 4743 | /// Valid types should not have multiple attributes with different CCs. |
| 4744 | const AttributedType *getCallingConvAttributedType(QualType T) const; |
| 4745 | |
| 4746 | /// Process the attributes before creating an attributed statement. Returns |
| 4747 | /// the semantic attributes that have been processed. |
| 4748 | void ProcessStmtAttributes(Stmt *Stmt, const ParsedAttributes &InAttrs, |
| 4749 | SmallVectorImpl<const Attr *> &OutAttrs); |
| 4750 | |
| 4751 | void WarnConflictingTypedMethods(ObjCMethodDecl *Method, |
| 4752 | ObjCMethodDecl *MethodDecl, |
| 4753 | bool IsProtocolMethodDecl); |
| 4754 | |
| 4755 | void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, |
| 4756 | ObjCMethodDecl *Overridden, |
| 4757 | bool IsProtocolMethodDecl); |
| 4758 | |
| 4759 | /// WarnExactTypedMethods - This routine issues a warning if method |
| 4760 | /// implementation declaration matches exactly that of its declaration. |
| 4761 | void WarnExactTypedMethods(ObjCMethodDecl *Method, |
| 4762 | ObjCMethodDecl *MethodDecl, |
| 4763 | bool IsProtocolMethodDecl); |
| 4764 | |
| 4765 | typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; |
| 4766 | |
| 4767 | /// CheckImplementationIvars - This routine checks if the instance variables |
| 4768 | /// listed in the implelementation match those listed in the interface. |
| 4769 | void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, |
| 4770 | ObjCIvarDecl **Fields, unsigned nIvars, |
| 4771 | SourceLocation Loc); |
| 4772 | |
| 4773 | /// ImplMethodsVsClassMethods - This is main routine to warn if any method |
| 4774 | /// remains unimplemented in the class or category \@implementation. |
| 4775 | void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl* IMPDecl, |
| 4776 | ObjCContainerDecl* IDecl, |
| 4777 | bool IncompleteImpl = false); |
| 4778 | |
| 4779 | /// DiagnoseUnimplementedProperties - This routine warns on those properties |
| 4780 | /// which must be implemented by this implementation. |
| 4781 | void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl* IMPDecl, |
| 4782 | ObjCContainerDecl *CDecl, |
| 4783 | bool SynthesizeProperties); |
| 4784 | |
| 4785 | /// Diagnose any null-resettable synthesized setters. |
| 4786 | void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl); |
| 4787 | |
| 4788 | /// DefaultSynthesizeProperties - This routine default synthesizes all |
| 4789 | /// properties which must be synthesized in the class's \@implementation. |
| 4790 | void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, |
| 4791 | ObjCInterfaceDecl *IDecl, |
| 4792 | SourceLocation AtEnd); |
| 4793 | void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); |
| 4794 | |
| 4795 | /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is |
| 4796 | /// an ivar synthesized for 'Method' and 'Method' is a property accessor |
| 4797 | /// declared in class 'IFace'. |
| 4798 | bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, |
| 4799 | ObjCMethodDecl *Method, ObjCIvarDecl *IV); |
| 4800 | |
| 4801 | /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar which |
| 4802 | /// backs the property is not used in the property's accessor. |
| 4803 | void DiagnoseUnusedBackingIvarInAccessor(Scope *S, |
| 4804 | const ObjCImplementationDecl *ImplD); |
| 4805 | |
| 4806 | /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and |
| 4807 | /// it property has a backing ivar, returns this ivar; otherwise, returns NULL. |
| 4808 | /// It also returns ivar's property on success. |
| 4809 | ObjCIvarDecl *GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, |
| 4810 | const ObjCPropertyDecl *&PDecl) const; |
| 4811 | |
| 4812 | /// Called by ActOnProperty to handle \@property declarations in |
| 4813 | /// class extensions. |
| 4814 | ObjCPropertyDecl *HandlePropertyInClassExtension(Scope *S, |
| 4815 | SourceLocation AtLoc, |
| 4816 | SourceLocation LParenLoc, |
| 4817 | FieldDeclarator &FD, |
| 4818 | Selector GetterSel, |
| 4819 | SourceLocation GetterNameLoc, |
| 4820 | Selector SetterSel, |
| 4821 | SourceLocation SetterNameLoc, |
| 4822 | const bool isReadWrite, |
| 4823 | unsigned &Attributes, |
| 4824 | const unsigned AttributesAsWritten, |
| 4825 | QualType T, |
| 4826 | TypeSourceInfo *TSI, |
| 4827 | tok::ObjCKeywordKind MethodImplKind); |
| 4828 | |
| 4829 | /// Called by ActOnProperty and HandlePropertyInClassExtension to |
| 4830 | /// handle creating the ObjcPropertyDecl for a category or \@interface. |
| 4831 | ObjCPropertyDecl *CreatePropertyDecl(Scope *S, |
| 4832 | ObjCContainerDecl *CDecl, |
| 4833 | SourceLocation AtLoc, |
| 4834 | SourceLocation LParenLoc, |
| 4835 | FieldDeclarator &FD, |
| 4836 | Selector GetterSel, |
| 4837 | SourceLocation GetterNameLoc, |
| 4838 | Selector SetterSel, |
| 4839 | SourceLocation SetterNameLoc, |
| 4840 | const bool isReadWrite, |
| 4841 | const unsigned Attributes, |
| 4842 | const unsigned AttributesAsWritten, |
| 4843 | QualType T, |
| 4844 | TypeSourceInfo *TSI, |
| 4845 | tok::ObjCKeywordKind MethodImplKind, |
| 4846 | DeclContext *lexicalDC = nullptr); |
| 4847 | |
| 4848 | /// AtomicPropertySetterGetterRules - This routine enforces the rule (via |
| 4849 | /// warning) when atomic property has one but not the other user-declared |
| 4850 | /// setter or getter. |
| 4851 | void AtomicPropertySetterGetterRules(ObjCImplDecl* IMPDecl, |
| 4852 | ObjCInterfaceDecl* IDecl); |
| 4853 | |
| 4854 | void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); |
| 4855 | |
| 4856 | void DiagnoseMissingDesignatedInitOverrides( |
| 4857 | const ObjCImplementationDecl *ImplD, |
| 4858 | const ObjCInterfaceDecl *IFD); |
| 4859 | |
| 4860 | void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); |
| 4861 | |
| 4862 | enum MethodMatchStrategy { |
| 4863 | MMS_loose, |
| 4864 | MMS_strict |
| 4865 | }; |
| 4866 | |
| 4867 | /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns |
| 4868 | /// true, or false, accordingly. |
| 4869 | bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, |
| 4870 | const ObjCMethodDecl *PrevMethod, |
| 4871 | MethodMatchStrategy strategy = MMS_strict); |
| 4872 | |
| 4873 | /// MatchAllMethodDeclarations - Check methods declaraed in interface or |
| 4874 | /// or protocol against those declared in their implementations. |
| 4875 | void MatchAllMethodDeclarations(const SelectorSet &InsMap, |
| 4876 | const SelectorSet &ClsMap, |
| 4877 | SelectorSet &InsMapSeen, |
| 4878 | SelectorSet &ClsMapSeen, |
| 4879 | ObjCImplDecl* IMPDecl, |
| 4880 | ObjCContainerDecl* IDecl, |
| 4881 | bool &IncompleteImpl, |
| 4882 | bool ImmediateClass, |
| 4883 | bool WarnCategoryMethodImpl=false); |
| 4884 | |
| 4885 | /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in |
| 4886 | /// category matches with those implemented in its primary class and |
| 4887 | /// warns each time an exact match is found. |
| 4888 | void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); |
| 4889 | |
| 4890 | /// Add the given method to the list of globally-known methods. |
| 4891 | void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); |
| 4892 | |
| 4893 | /// Returns default addr space for method qualifiers. |
| 4894 | LangAS getDefaultCXXMethodAddrSpace() const; |
| 4895 | |
| 4896 | private: |
| 4897 | /// AddMethodToGlobalPool - Add an instance or factory method to the global |
| 4898 | /// pool. See descriptoin of AddInstanceMethodToGlobalPool. |
| 4899 | void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); |
| 4900 | |
| 4901 | /// LookupMethodInGlobalPool - Returns the instance or factory method and |
| 4902 | /// optionally warns if there are multiple signatures. |
| 4903 | ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, |
| 4904 | bool receiverIdOrClass, |
| 4905 | bool instance); |
| 4906 | |
| 4907 | public: |
| 4908 | /// - Returns instance or factory methods in global method pool for |
| 4909 | /// given selector. It checks the desired kind first, if none is found, and |
| 4910 | /// parameter checkTheOther is set, it then checks the other kind. If no such |
| 4911 | /// method or only one method is found, function returns false; otherwise, it |
| 4912 | /// returns true. |
| 4913 | bool |
| 4914 | CollectMultipleMethodsInGlobalPool(Selector Sel, |
| 4915 | SmallVectorImpl<ObjCMethodDecl*>& Methods, |
| 4916 | bool InstanceFirst, bool CheckTheOther, |
| 4917 | const ObjCObjectType *TypeBound = nullptr); |
| 4918 | |
| 4919 | bool |
| 4920 | AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, |
| 4921 | SourceRange R, bool receiverIdOrClass, |
| 4922 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
| 4923 | |
| 4924 | void |
| 4925 | DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl*> &Methods, |
| 4926 | Selector Sel, SourceRange R, |
| 4927 | bool receiverIdOrClass); |
| 4928 | |
| 4929 | private: |
| 4930 | /// - Returns a selector which best matches given argument list or |
| 4931 | /// nullptr if none could be found |
| 4932 | ObjCMethodDecl *SelectBestMethod(Selector Sel, MultiExprArg Args, |
| 4933 | bool IsInstance, |
| 4934 | SmallVectorImpl<ObjCMethodDecl*>& Methods); |
| 4935 | |
| 4936 | |
| 4937 | /// Record the typo correction failure and return an empty correction. |
| 4938 | TypoCorrection FailedCorrection(IdentifierInfo *Typo, SourceLocation TypoLoc, |
| 4939 | bool RecordFailure = true) { |
| 4940 | if (RecordFailure) |
| 4941 | TypoCorrectionFailures[Typo].insert(TypoLoc); |
| 4942 | return TypoCorrection(); |
| 4943 | } |
| 4944 | |
| 4945 | public: |
| 4946 | /// AddInstanceMethodToGlobalPool - All instance methods in a translation |
| 4947 | /// unit are added to a global pool. This allows us to efficiently associate |
| 4948 | /// a selector with a method declaraation for purposes of typechecking |
| 4949 | /// messages sent to "id" (where the class of the object is unknown). |
| 4950 | void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
| 4951 | AddMethodToGlobalPool(Method, impl, /*instance*/true); |
| 4952 | } |
| 4953 | |
| 4954 | /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. |
| 4955 | void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl=false) { |
| 4956 | AddMethodToGlobalPool(Method, impl, /*instance*/false); |
| 4957 | } |
| 4958 | |
| 4959 | /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global |
| 4960 | /// pool. |
| 4961 | void AddAnyMethodToGlobalPool(Decl *D); |
| 4962 | |
| 4963 | /// LookupInstanceMethodInGlobalPool - Returns the method and warns if |
| 4964 | /// there are multiple signatures. |
| 4965 | ObjCMethodDecl *LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, |
| 4966 | bool receiverIdOrClass=false) { |
| 4967 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
| 4968 | /*instance*/true); |
| 4969 | } |
| 4970 | |
| 4971 | /// LookupFactoryMethodInGlobalPool - Returns the method and warns if |
| 4972 | /// there are multiple signatures. |
| 4973 | ObjCMethodDecl *LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, |
| 4974 | bool receiverIdOrClass=false) { |
| 4975 | return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, |
| 4976 | /*instance*/false); |
| 4977 | } |
| 4978 | |
| 4979 | const ObjCMethodDecl *SelectorsForTypoCorrection(Selector Sel, |
| 4980 | QualType ObjectType=QualType()); |
| 4981 | /// LookupImplementedMethodInGlobalPool - Returns the method which has an |
| 4982 | /// implementation. |
| 4983 | ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); |
| 4984 | |
| 4985 | /// CollectIvarsToConstructOrDestruct - Collect those ivars which require |
| 4986 | /// initialization. |
| 4987 | void CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, |
| 4988 | SmallVectorImpl<ObjCIvarDecl*> &Ivars); |
| 4989 | |
| 4990 | //===--------------------------------------------------------------------===// |
| 4991 | // Statement Parsing Callbacks: SemaStmt.cpp. |
| 4992 | public: |
| 4993 | class FullExprArg { |
| 4994 | public: |
| 4995 | FullExprArg() : E(nullptr) { } |
| 4996 | FullExprArg(Sema &actions) : E(nullptr) { } |
| 4997 | |
| 4998 | ExprResult release() { |
| 4999 | return E; |
| 5000 | } |
| 5001 | |
| 5002 | Expr *get() const { return E; } |
| 5003 | |
| 5004 | Expr *operator->() { |
| 5005 | return E; |
| 5006 | } |
| 5007 | |
| 5008 | private: |
| 5009 | // FIXME: No need to make the entire Sema class a friend when it's just |
| 5010 | // Sema::MakeFullExpr that needs access to the constructor below. |
| 5011 | friend class Sema; |
| 5012 | |
| 5013 | explicit FullExprArg(Expr *expr) : E(expr) {} |
| 5014 | |
| 5015 | Expr *E; |
| 5016 | }; |
| 5017 | |
| 5018 | FullExprArg MakeFullExpr(Expr *Arg) { |
| 5019 | return MakeFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation()); |
| 5020 | } |
| 5021 | FullExprArg MakeFullExpr(Expr *Arg, SourceLocation CC) { |
| 5022 | return FullExprArg( |
| 5023 | ActOnFinishFullExpr(Arg, CC, /*DiscardedValue*/ false).get()); |
| 5024 | } |
| 5025 | FullExprArg MakeFullDiscardedValueExpr(Expr *Arg) { |
| 5026 | ExprResult FE = |
| 5027 | ActOnFinishFullExpr(Arg, Arg ? Arg->getExprLoc() : SourceLocation(), |
| 5028 | /*DiscardedValue*/ true); |
| 5029 | return FullExprArg(FE.get()); |
| 5030 | } |
| 5031 | |
| 5032 | StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue = true); |
| 5033 | StmtResult ActOnExprStmtError(); |
| 5034 | |
| 5035 | StmtResult ActOnNullStmt(SourceLocation SemiLoc, |
| 5036 | bool HasLeadingEmptyMacro = false); |
| 5037 | |
| 5038 | void ActOnStartOfCompoundStmt(bool IsStmtExpr); |
| 5039 | void ActOnAfterCompoundStatementLeadingPragmas(); |
| 5040 | void ActOnFinishOfCompoundStmt(); |
| 5041 | StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, |
| 5042 | ArrayRef<Stmt *> Elts, bool isStmtExpr); |
| 5043 | |
| 5044 | /// A RAII object to enter scope of a compound statement. |
| 5045 | class CompoundScopeRAII { |
| 5046 | public: |
| 5047 | CompoundScopeRAII(Sema &S, bool IsStmtExpr = false) : S(S) { |
| 5048 | S.ActOnStartOfCompoundStmt(IsStmtExpr); |
| 5049 | } |
| 5050 | |
| 5051 | ~CompoundScopeRAII() { |
| 5052 | S.ActOnFinishOfCompoundStmt(); |
| 5053 | } |
| 5054 | |
| 5055 | private: |
| 5056 | Sema &S; |
| 5057 | }; |
| 5058 | |
| 5059 | /// An RAII helper that pops function a function scope on exit. |
| 5060 | struct FunctionScopeRAII { |
| 5061 | Sema &S; |
| 5062 | bool Active; |
| 5063 | FunctionScopeRAII(Sema &S) : S(S), Active(true) {} |
| 5064 | ~FunctionScopeRAII() { |
| 5065 | if (Active) |
| 5066 | S.PopFunctionScopeInfo(); |
| 5067 | } |
| 5068 | void disable() { Active = false; } |
| 5069 | }; |
| 5070 | |
| 5071 | StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, |
| 5072 | SourceLocation StartLoc, |
| 5073 | SourceLocation EndLoc); |
| 5074 | void ActOnForEachDeclStmt(DeclGroupPtrTy Decl); |
| 5075 | StmtResult ActOnForEachLValueExpr(Expr *E); |
| 5076 | ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val); |
| 5077 | StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, |
| 5078 | SourceLocation DotDotDotLoc, ExprResult RHS, |
| 5079 | SourceLocation ColonLoc); |
| 5080 | void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt); |
| 5081 | |
| 5082 | StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, |
| 5083 | SourceLocation ColonLoc, |
| 5084 | Stmt *SubStmt, Scope *CurScope); |
| 5085 | StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, |
| 5086 | SourceLocation ColonLoc, Stmt *SubStmt); |
| 5087 | |
| 5088 | StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, |
| 5089 | ArrayRef<const Attr *> Attrs, Stmt *SubStmt); |
| 5090 | StmtResult ActOnAttributedStmt(const ParsedAttributes &AttrList, |
| 5091 | Stmt *SubStmt); |
| 5092 | |
| 5093 | class ConditionResult; |
| 5094 | |
| 5095 | StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
| 5096 | SourceLocation LParenLoc, Stmt *InitStmt, |
| 5097 | ConditionResult Cond, SourceLocation RParenLoc, |
| 5098 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
| 5099 | StmtResult BuildIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, |
| 5100 | SourceLocation LParenLoc, Stmt *InitStmt, |
| 5101 | ConditionResult Cond, SourceLocation RParenLoc, |
| 5102 | Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal); |
| 5103 | StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, |
| 5104 | SourceLocation LParenLoc, Stmt *InitStmt, |
| 5105 | ConditionResult Cond, |
| 5106 | SourceLocation RParenLoc); |
| 5107 | StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, |
| 5108 | Stmt *Switch, Stmt *Body); |
| 5109 | StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 5110 | ConditionResult Cond, SourceLocation RParenLoc, |
| 5111 | Stmt *Body); |
| 5112 | StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, |
| 5113 | SourceLocation WhileLoc, SourceLocation CondLParen, |
| 5114 | Expr *Cond, SourceLocation CondRParen); |
| 5115 | |
| 5116 | StmtResult ActOnForStmt(SourceLocation ForLoc, |
| 5117 | SourceLocation LParenLoc, |
| 5118 | Stmt *First, |
| 5119 | ConditionResult Second, |
| 5120 | FullExprArg Third, |
| 5121 | SourceLocation RParenLoc, |
| 5122 | Stmt *Body); |
| 5123 | ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, |
| 5124 | Expr *collection); |
| 5125 | StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, |
| 5126 | Stmt *First, Expr *collection, |
| 5127 | SourceLocation RParenLoc); |
| 5128 | StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); |
| 5129 | |
| 5130 | enum BuildForRangeKind { |
| 5131 | /// Initial building of a for-range statement. |
| 5132 | BFRK_Build, |
| 5133 | /// Instantiation or recovery rebuild of a for-range statement. Don't |
| 5134 | /// attempt any typo-correction. |
| 5135 | BFRK_Rebuild, |
| 5136 | /// Determining whether a for-range statement could be built. Avoid any |
| 5137 | /// unnecessary or irreversible actions. |
| 5138 | BFRK_Check |
| 5139 | }; |
| 5140 | |
| 5141 | StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc, |
| 5142 | SourceLocation CoawaitLoc, |
| 5143 | Stmt *InitStmt, |
| 5144 | Stmt *LoopVar, |
| 5145 | SourceLocation ColonLoc, Expr *Collection, |
| 5146 | SourceLocation RParenLoc, |
| 5147 | BuildForRangeKind Kind); |
| 5148 | StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, |
| 5149 | SourceLocation CoawaitLoc, |
| 5150 | Stmt *InitStmt, |
| 5151 | SourceLocation ColonLoc, |
| 5152 | Stmt *RangeDecl, Stmt *Begin, Stmt *End, |
| 5153 | Expr *Cond, Expr *Inc, |
| 5154 | Stmt *LoopVarDecl, |
| 5155 | SourceLocation RParenLoc, |
| 5156 | BuildForRangeKind Kind); |
| 5157 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body); |
| 5158 | |
| 5159 | StmtResult ActOnGotoStmt(SourceLocation GotoLoc, |
| 5160 | SourceLocation LabelLoc, |
| 5161 | LabelDecl *TheDecl); |
| 5162 | StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, |
| 5163 | SourceLocation StarLoc, |
| 5164 | Expr *DestExp); |
| 5165 | StmtResult ActOnContinueStmt(SourceLocation ContinueLoc, Scope *CurScope); |
| 5166 | StmtResult ActOnBreakStmt(SourceLocation BreakLoc, Scope *CurScope); |
| 5167 | |
| 5168 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
| 5169 | CapturedRegionKind Kind, unsigned NumParams); |
| 5170 | typedef std::pair<StringRef, QualType> CapturedParamNameType; |
| 5171 | void ActOnCapturedRegionStart(SourceLocation Loc, Scope *CurScope, |
| 5172 | CapturedRegionKind Kind, |
| 5173 | ArrayRef<CapturedParamNameType> Params, |
| 5174 | unsigned OpenMPCaptureLevel = 0); |
| 5175 | StmtResult ActOnCapturedRegionEnd(Stmt *S); |
| 5176 | void ActOnCapturedRegionError(); |
| 5177 | RecordDecl *CreateCapturedStmtRecordDecl(CapturedDecl *&CD, |
| 5178 | SourceLocation Loc, |
| 5179 | unsigned NumParams); |
| 5180 | |
| 5181 | struct NamedReturnInfo { |
| 5182 | const VarDecl *Candidate; |
| 5183 | |
| 5184 | enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable }; |
| 5185 | Status S; |
| 5186 | |
| 5187 | bool isMoveEligible() const { return S != None; }; |
| 5188 | bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; } |
| 5189 | }; |
| 5190 | enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn }; |
| 5191 | NamedReturnInfo getNamedReturnInfo( |
| 5192 | Expr *&E, SimplerImplicitMoveMode Mode = SimplerImplicitMoveMode::Normal); |
| 5193 | NamedReturnInfo getNamedReturnInfo(const VarDecl *VD); |
| 5194 | const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info, |
| 5195 | QualType ReturnType); |
| 5196 | |
| 5197 | ExprResult |
| 5198 | PerformMoveOrCopyInitialization(const InitializedEntity &Entity, |
| 5199 | const NamedReturnInfo &NRInfo, Expr *Value, |
| 5200 | bool SupressSimplerImplicitMoves = false); |
| 5201 | |
| 5202 | StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
| 5203 | Scope *CurScope); |
| 5204 | StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
| 5205 | bool AllowRecovery = false); |
| 5206 | StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, |
| 5207 | NamedReturnInfo &NRInfo, |
| 5208 | bool SupressSimplerImplicitMoves); |
| 5209 | |
| 5210 | StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 5211 | bool IsVolatile, unsigned NumOutputs, |
| 5212 | unsigned NumInputs, IdentifierInfo **Names, |
| 5213 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 5214 | Expr *AsmString, MultiExprArg Clobbers, |
| 5215 | unsigned NumLabels, |
| 5216 | SourceLocation RParenLoc); |
| 5217 | |
| 5218 | void FillInlineAsmIdentifierInfo(Expr *Res, |
| 5219 | llvm::InlineAsmIdentifierInfo &Info); |
| 5220 | ExprResult LookupInlineAsmIdentifier(CXXScopeSpec &SS, |
| 5221 | SourceLocation TemplateKWLoc, |
| 5222 | UnqualifiedId &Id, |
| 5223 | bool IsUnevaluatedContext); |
| 5224 | bool LookupInlineAsmField(StringRef Base, StringRef Member, |
| 5225 | unsigned &Offset, SourceLocation AsmLoc); |
| 5226 | ExprResult LookupInlineAsmVarDeclField(Expr *RefExpr, StringRef Member, |
| 5227 | SourceLocation AsmLoc); |
| 5228 | StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
| 5229 | ArrayRef<Token> AsmToks, |
| 5230 | StringRef AsmString, |
| 5231 | unsigned NumOutputs, unsigned NumInputs, |
| 5232 | ArrayRef<StringRef> Constraints, |
| 5233 | ArrayRef<StringRef> Clobbers, |
| 5234 | ArrayRef<Expr*> Exprs, |
| 5235 | SourceLocation EndLoc); |
| 5236 | LabelDecl *GetOrCreateMSAsmLabel(StringRef ExternalLabelName, |
| 5237 | SourceLocation Location, |
| 5238 | bool AlwaysCreate); |
| 5239 | |
| 5240 | VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, |
| 5241 | SourceLocation StartLoc, |
| 5242 | SourceLocation IdLoc, IdentifierInfo *Id, |
| 5243 | bool Invalid = false); |
| 5244 | |
| 5245 | Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); |
| 5246 | |
| 5247 | StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, |
| 5248 | Decl *Parm, Stmt *Body); |
| 5249 | |
| 5250 | StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); |
| 5251 | |
| 5252 | StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, |
| 5253 | MultiStmtArg Catch, Stmt *Finally); |
| 5254 | |
| 5255 | StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); |
| 5256 | StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, |
| 5257 | Scope *CurScope); |
| 5258 | ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 5259 | Expr *operand); |
| 5260 | StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 5261 | Expr *SynchExpr, |
| 5262 | Stmt *SynchBody); |
| 5263 | |
| 5264 | StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); |
| 5265 | |
| 5266 | VarDecl *BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, |
| 5267 | SourceLocation StartLoc, |
| 5268 | SourceLocation IdLoc, |
| 5269 | IdentifierInfo *Id); |
| 5270 | |
| 5271 | Decl *ActOnExceptionDeclarator(Scope *S, Declarator &D); |
| 5272 | |
| 5273 | StmtResult ActOnCXXCatchBlock(SourceLocation CatchLoc, |
| 5274 | Decl *ExDecl, Stmt *HandlerBlock); |
| 5275 | StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, |
| 5276 | ArrayRef<Stmt *> Handlers); |
| 5277 | |
| 5278 | StmtResult ActOnSEHTryBlock(bool IsCXXTry, // try (true) or __try (false) ? |
| 5279 | SourceLocation TryLoc, Stmt *TryBlock, |
| 5280 | Stmt *Handler); |
| 5281 | StmtResult ActOnSEHExceptBlock(SourceLocation Loc, |
| 5282 | Expr *FilterExpr, |
| 5283 | Stmt *Block); |
| 5284 | void ActOnStartSEHFinallyBlock(); |
| 5285 | void ActOnAbortSEHFinallyBlock(); |
| 5286 | StmtResult ActOnFinishSEHFinallyBlock(SourceLocation Loc, Stmt *Block); |
| 5287 | StmtResult ActOnSEHLeaveStmt(SourceLocation Loc, Scope *CurScope); |
| 5288 | |
| 5289 | void DiagnoseReturnInConstructorExceptionHandler(CXXTryStmt *TryBlock); |
| 5290 | |
| 5291 | bool ShouldWarnIfUnusedFileScopedDecl(const DeclaratorDecl *D) const; |
| 5292 | |
| 5293 | /// If it's a file scoped decl that must warn if not used, keep track |
| 5294 | /// of it. |
| 5295 | void MarkUnusedFileScopedDecl(const DeclaratorDecl *D); |
| 5296 | |
| 5297 | typedef llvm::function_ref<void(SourceLocation Loc, PartialDiagnostic PD)> |
| 5298 | DiagReceiverTy; |
| 5299 | |
| 5300 | /// DiagnoseUnusedExprResult - If the statement passed in is an expression |
| 5301 | /// whose result is unused, warn. |
| 5302 | void DiagnoseUnusedExprResult(const Stmt *S, unsigned DiagID); |
| 5303 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D); |
| 5304 | void DiagnoseUnusedNestedTypedefs(const RecordDecl *D, |
| 5305 | DiagReceiverTy DiagReceiver); |
| 5306 | void DiagnoseUnusedDecl(const NamedDecl *ND); |
| 5307 | void DiagnoseUnusedDecl(const NamedDecl *ND, DiagReceiverTy DiagReceiver); |
| 5308 | |
| 5309 | /// If VD is set but not otherwise used, diagnose, for a parameter or a |
| 5310 | /// variable. |
| 5311 | void DiagnoseUnusedButSetDecl(const VarDecl *VD, DiagReceiverTy DiagReceiver); |
| 5312 | |
| 5313 | /// Emit \p DiagID if statement located on \p StmtLoc has a suspicious null |
| 5314 | /// statement as a \p Body, and it is located on the same line. |
| 5315 | /// |
| 5316 | /// This helps prevent bugs due to typos, such as: |
| 5317 | /// if (condition); |
| 5318 | /// do_stuff(); |
| 5319 | void DiagnoseEmptyStmtBody(SourceLocation StmtLoc, |
| 5320 | const Stmt *Body, |
| 5321 | unsigned DiagID); |
| 5322 | |
| 5323 | /// Warn if a for/while loop statement \p S, which is followed by |
| 5324 | /// \p PossibleBody, has a suspicious null statement as a body. |
| 5325 | void DiagnoseEmptyLoopBody(const Stmt *S, |
| 5326 | const Stmt *PossibleBody); |
| 5327 | |
| 5328 | /// Warn if a value is moved to itself. |
| 5329 | void DiagnoseSelfMove(const Expr *LHSExpr, const Expr *RHSExpr, |
| 5330 | SourceLocation OpLoc); |
| 5331 | |
| 5332 | /// Returns a field in a CXXRecordDecl that has the same name as the decl \p |
| 5333 | /// SelfAssigned when inside a CXXMethodDecl. |
| 5334 | const FieldDecl * |
| 5335 | getSelfAssignmentClassMemberCandidate(const ValueDecl *SelfAssigned); |
| 5336 | |
| 5337 | /// Warn if we're implicitly casting from a _Nullable pointer type to a |
| 5338 | /// _Nonnull one. |
| 5339 | void diagnoseNullableToNonnullConversion(QualType DstType, QualType SrcType, |
| 5340 | SourceLocation Loc); |
| 5341 | |
| 5342 | /// Warn when implicitly casting 0 to nullptr. |
| 5343 | void diagnoseZeroToNullptrConversion(CastKind Kind, const Expr *E); |
| 5344 | |
| 5345 | ParsingDeclState PushParsingDeclaration(sema::DelayedDiagnosticPool &pool) { |
| 5346 | return DelayedDiagnostics.push(pool); |
| 5347 | } |
| 5348 | void PopParsingDeclaration(ParsingDeclState state, Decl *decl); |
| 5349 | |
| 5350 | typedef ProcessingContextState ParsingClassState; |
| 5351 | ParsingClassState PushParsingClass() { |
| 5352 | ParsingClassDepth++; |
| 5353 | return DelayedDiagnostics.pushUndelayed(); |
| 5354 | } |
| 5355 | void PopParsingClass(ParsingClassState state) { |
| 5356 | ParsingClassDepth--; |
| 5357 | DelayedDiagnostics.popUndelayed(state); |
| 5358 | } |
| 5359 | |
| 5360 | void redelayDiagnostics(sema::DelayedDiagnosticPool &pool); |
| 5361 | |
| 5362 | void DiagnoseAvailabilityOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
| 5363 | const ObjCInterfaceDecl *UnknownObjCClass, |
| 5364 | bool ObjCPropertyAccess, |
| 5365 | bool AvoidPartialAvailabilityChecks = false, |
| 5366 | ObjCInterfaceDecl *ClassReceiver = nullptr); |
| 5367 | |
| 5368 | bool makeUnavailableInSystemHeader(SourceLocation loc, |
| 5369 | UnavailableAttr::ImplicitReason reason); |
| 5370 | |
| 5371 | /// Issue any -Wunguarded-availability warnings in \c FD |
| 5372 | void DiagnoseUnguardedAvailabilityViolations(Decl *FD); |
| 5373 | |
| 5374 | void handleDelayedAvailabilityCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
| 5375 | |
| 5376 | //===--------------------------------------------------------------------===// |
| 5377 | // Expression Parsing Callbacks: SemaExpr.cpp. |
| 5378 | |
| 5379 | bool CanUseDecl(NamedDecl *D, bool TreatUnavailableAsInvalid); |
| 5380 | // A version of DiagnoseUseOfDecl that should be used if overload resolution |
| 5381 | // has been used to find this declaration, which means we don't have to bother |
| 5382 | // checking the trailing requires clause. |
| 5383 | bool DiagnoseUseOfOverloadedDecl(NamedDecl *D, SourceLocation Loc) { |
| 5384 | return DiagnoseUseOfDecl( |
| 5385 | D, Loc, /*UnknownObjCClass=*/nullptr, /*ObjCPropertyAccess=*/false, |
| 5386 | /*AvoidPartialAvailabilityChecks=*/false, /*ClassReceiver=*/nullptr, |
| 5387 | /*SkipTrailingRequiresClause=*/true); |
| 5388 | } |
| 5389 | |
| 5390 | bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef<SourceLocation> Locs, |
| 5391 | const ObjCInterfaceDecl *UnknownObjCClass = nullptr, |
| 5392 | bool ObjCPropertyAccess = false, |
| 5393 | bool AvoidPartialAvailabilityChecks = false, |
| 5394 | ObjCInterfaceDecl *ClassReciever = nullptr, |
| 5395 | bool SkipTrailingRequiresClause = false); |
| 5396 | void NoteDeletedFunction(FunctionDecl *FD); |
| 5397 | void NoteDeletedInheritingConstructor(CXXConstructorDecl *CD); |
| 5398 | bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, |
| 5399 | ObjCMethodDecl *Getter, |
| 5400 | SourceLocation Loc); |
| 5401 | void DiagnoseSentinelCalls(NamedDecl *D, SourceLocation Loc, |
| 5402 | ArrayRef<Expr *> Args); |
| 5403 | |
| 5404 | void PushExpressionEvaluationContext( |
| 5405 | ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl = nullptr, |
| 5406 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
| 5407 | ExpressionEvaluationContextRecord::EK_Other); |
| 5408 | enum ReuseLambdaContextDecl_t { ReuseLambdaContextDecl }; |
| 5409 | void PushExpressionEvaluationContext( |
| 5410 | ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t, |
| 5411 | ExpressionEvaluationContextRecord::ExpressionKind Type = |
| 5412 | ExpressionEvaluationContextRecord::EK_Other); |
| 5413 | void PopExpressionEvaluationContext(); |
| 5414 | |
| 5415 | void DiscardCleanupsInEvaluationContext(); |
| 5416 | |
| 5417 | ExprResult TransformToPotentiallyEvaluated(Expr *E); |
| 5418 | TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo); |
| 5419 | ExprResult HandleExprEvaluationContextForTypeof(Expr *E); |
| 5420 | |
| 5421 | ExprResult CheckUnevaluatedOperand(Expr *E); |
| 5422 | void CheckUnusedVolatileAssignment(Expr *E); |
| 5423 | |
| 5424 | ExprResult ActOnConstantExpression(ExprResult Res); |
| 5425 | |
| 5426 | // Functions for marking a declaration referenced. These functions also |
| 5427 | // contain the relevant logic for marking if a reference to a function or |
| 5428 | // variable is an odr-use (in the C++11 sense). There are separate variants |
| 5429 | // for expressions referring to a decl; these exist because odr-use marking |
| 5430 | // needs to be delayed for some constant variables when we build one of the |
| 5431 | // named expressions. |
| 5432 | // |
| 5433 | // MightBeOdrUse indicates whether the use could possibly be an odr-use, and |
| 5434 | // should usually be true. This only needs to be set to false if the lack of |
| 5435 | // odr-use cannot be determined from the current context (for instance, |
| 5436 | // because the name denotes a virtual function and was written without an |
| 5437 | // explicit nested-name-specifier). |
| 5438 | void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse); |
| 5439 | void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, |
| 5440 | bool MightBeOdrUse = true); |
| 5441 | void MarkVariableReferenced(SourceLocation Loc, VarDecl *Var); |
| 5442 | void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base = nullptr); |
| 5443 | void MarkMemberReferenced(MemberExpr *E); |
| 5444 | void MarkFunctionParmPackReferenced(FunctionParmPackExpr *E); |
| 5445 | void MarkCaptureUsedInEnclosingContext(ValueDecl *Capture, SourceLocation Loc, |
| 5446 | unsigned CapturingScopeIndex); |
| 5447 | |
| 5448 | ExprResult CheckLValueToRValueConversionOperand(Expr *E); |
| 5449 | void CleanupVarDeclMarking(); |
| 5450 | |
| 5451 | enum TryCaptureKind { |
| 5452 | TryCapture_Implicit, TryCapture_ExplicitByVal, TryCapture_ExplicitByRef |
| 5453 | }; |
| 5454 | |
| 5455 | /// Try to capture the given variable. |
| 5456 | /// |
| 5457 | /// \param Var The variable to capture. |
| 5458 | /// |
| 5459 | /// \param Loc The location at which the capture occurs. |
| 5460 | /// |
| 5461 | /// \param Kind The kind of capture, which may be implicit (for either a |
| 5462 | /// block or a lambda), or explicit by-value or by-reference (for a lambda). |
| 5463 | /// |
| 5464 | /// \param EllipsisLoc The location of the ellipsis, if one is provided in |
| 5465 | /// an explicit lambda capture. |
| 5466 | /// |
| 5467 | /// \param BuildAndDiagnose Whether we are actually supposed to add the |
| 5468 | /// captures or diagnose errors. If false, this routine merely check whether |
| 5469 | /// the capture can occur without performing the capture itself or complaining |
| 5470 | /// if the variable cannot be captured. |
| 5471 | /// |
| 5472 | /// \param CaptureType Will be set to the type of the field used to capture |
| 5473 | /// this variable in the innermost block or lambda. Only valid when the |
| 5474 | /// variable can be captured. |
| 5475 | /// |
| 5476 | /// \param DeclRefType Will be set to the type of a reference to the capture |
| 5477 | /// from within the current scope. Only valid when the variable can be |
| 5478 | /// captured. |
| 5479 | /// |
| 5480 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
| 5481 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
| 5482 | /// This is useful when enclosing lambdas must speculatively capture |
| 5483 | /// variables that may or may not be used in certain specializations of |
| 5484 | /// a nested generic lambda. |
| 5485 | /// |
| 5486 | /// \returns true if an error occurred (i.e., the variable cannot be |
| 5487 | /// captured) and false if the capture succeeded. |
| 5488 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
| 5489 | TryCaptureKind Kind, SourceLocation EllipsisLoc, |
| 5490 | bool BuildAndDiagnose, QualType &CaptureType, |
| 5491 | QualType &DeclRefType, |
| 5492 | const unsigned *const FunctionScopeIndexToStopAt); |
| 5493 | |
| 5494 | /// Try to capture the given variable. |
| 5495 | bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc, |
| 5496 | TryCaptureKind Kind = TryCapture_Implicit, |
| 5497 | SourceLocation EllipsisLoc = SourceLocation()); |
| 5498 | |
| 5499 | /// Checks if the variable must be captured. |
| 5500 | bool NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc); |
| 5501 | |
| 5502 | /// Given a variable, determine the type that a reference to that |
| 5503 | /// variable will have in the given scope. |
| 5504 | QualType getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc); |
| 5505 | |
| 5506 | /// Mark all of the declarations referenced within a particular AST node as |
| 5507 | /// referenced. Used when template instantiation instantiates a non-dependent |
| 5508 | /// type -- entities referenced by the type are now referenced. |
| 5509 | void MarkDeclarationsReferencedInType(SourceLocation Loc, QualType T); |
| 5510 | void MarkDeclarationsReferencedInExpr( |
| 5511 | Expr *E, bool SkipLocalVariables = false, |
| 5512 | ArrayRef<const Expr *> StopAt = std::nullopt); |
| 5513 | |
| 5514 | /// Try to recover by turning the given expression into a |
| 5515 | /// call. Returns true if recovery was attempted or an error was |
| 5516 | /// emitted; this may also leave the ExprResult invalid. |
| 5517 | bool tryToRecoverWithCall(ExprResult &E, const PartialDiagnostic &PD, |
| 5518 | bool ForceComplain = false, |
| 5519 | bool (*IsPlausibleResult)(QualType) = nullptr); |
| 5520 | |
| 5521 | /// Figure out if an expression could be turned into a call. |
| 5522 | bool tryExprAsCall(Expr &E, QualType &ZeroArgCallReturnTy, |
| 5523 | UnresolvedSetImpl &NonTemplateOverloads); |
| 5524 | |
| 5525 | /// Try to convert an expression \p E to type \p Ty. Returns the result of the |
| 5526 | /// conversion. |
| 5527 | ExprResult tryConvertExprToType(Expr *E, QualType Ty); |
| 5528 | |
| 5529 | /// Conditionally issue a diagnostic based on the statements's reachability |
| 5530 | /// analysis. |
| 5531 | /// |
| 5532 | /// \param Stmts If Stmts is non-empty, delay reporting the diagnostic until |
| 5533 | /// the function body is parsed, and then do a basic reachability analysis to |
| 5534 | /// determine if the statement is reachable. If it is unreachable, the |
| 5535 | /// diagnostic will not be emitted. |
| 5536 | bool DiagIfReachable(SourceLocation Loc, ArrayRef<const Stmt *> Stmts, |
| 5537 | const PartialDiagnostic &PD); |
| 5538 | |
| 5539 | /// Conditionally issue a diagnostic based on the current |
| 5540 | /// evaluation context. |
| 5541 | /// |
| 5542 | /// \param Statement If Statement is non-null, delay reporting the |
| 5543 | /// diagnostic until the function body is parsed, and then do a basic |
| 5544 | /// reachability analysis to determine if the statement is reachable. |
| 5545 | /// If it is unreachable, the diagnostic will not be emitted. |
| 5546 | bool DiagRuntimeBehavior(SourceLocation Loc, const Stmt *Statement, |
| 5547 | const PartialDiagnostic &PD); |
| 5548 | /// Similar, but diagnostic is only produced if all the specified statements |
| 5549 | /// are reachable. |
| 5550 | bool DiagRuntimeBehavior(SourceLocation Loc, ArrayRef<const Stmt*> Stmts, |
| 5551 | const PartialDiagnostic &PD); |
| 5552 | |
| 5553 | // Primary Expressions. |
| 5554 | SourceRange getExprRange(Expr *E) const; |
| 5555 | |
| 5556 | ExprResult ActOnIdExpression( |
| 5557 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 5558 | UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, |
| 5559 | CorrectionCandidateCallback *CCC = nullptr, |
| 5560 | bool IsInlineAsmIdentifier = false, Token *KeywordReplacement = nullptr); |
| 5561 | |
| 5562 | void DecomposeUnqualifiedId(const UnqualifiedId &Id, |
| 5563 | TemplateArgumentListInfo &Buffer, |
| 5564 | DeclarationNameInfo &NameInfo, |
| 5565 | const TemplateArgumentListInfo *&TemplateArgs); |
| 5566 | |
| 5567 | bool DiagnoseDependentMemberLookup(const LookupResult &R); |
| 5568 | |
| 5569 | bool |
| 5570 | DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, |
| 5571 | CorrectionCandidateCallback &CCC, |
| 5572 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr, |
| 5573 | ArrayRef<Expr *> Args = std::nullopt, |
| 5574 | TypoExpr **Out = nullptr); |
| 5575 | |
| 5576 | DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S, |
| 5577 | IdentifierInfo *II); |
| 5578 | ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV); |
| 5579 | |
| 5580 | ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, |
| 5581 | IdentifierInfo *II, |
| 5582 | bool AllowBuiltinCreation=false); |
| 5583 | |
| 5584 | ExprResult ActOnDependentIdExpression(const CXXScopeSpec &SS, |
| 5585 | SourceLocation TemplateKWLoc, |
| 5586 | const DeclarationNameInfo &NameInfo, |
| 5587 | bool isAddressOfOperand, |
| 5588 | const TemplateArgumentListInfo *TemplateArgs); |
| 5589 | |
| 5590 | /// If \p D cannot be odr-used in the current expression evaluation context, |
| 5591 | /// return a reason explaining why. Otherwise, return NOUR_None. |
| 5592 | NonOdrUseReason getNonOdrUseReasonInCurrentContext(ValueDecl *D); |
| 5593 | |
| 5594 | DeclRefExpr *BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
| 5595 | SourceLocation Loc, |
| 5596 | const CXXScopeSpec *SS = nullptr); |
| 5597 | DeclRefExpr * |
| 5598 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
| 5599 | const DeclarationNameInfo &NameInfo, |
| 5600 | const CXXScopeSpec *SS = nullptr, |
| 5601 | NamedDecl *FoundD = nullptr, |
| 5602 | SourceLocation TemplateKWLoc = SourceLocation(), |
| 5603 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
| 5604 | DeclRefExpr * |
| 5605 | BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, |
| 5606 | const DeclarationNameInfo &NameInfo, |
| 5607 | NestedNameSpecifierLoc NNS, |
| 5608 | NamedDecl *FoundD = nullptr, |
| 5609 | SourceLocation TemplateKWLoc = SourceLocation(), |
| 5610 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
| 5611 | |
| 5612 | ExprResult |
| 5613 | BuildAnonymousStructUnionMemberReference( |
| 5614 | const CXXScopeSpec &SS, |
| 5615 | SourceLocation nameLoc, |
| 5616 | IndirectFieldDecl *indirectField, |
| 5617 | DeclAccessPair FoundDecl = DeclAccessPair::make(nullptr, AS_none), |
| 5618 | Expr *baseObjectExpr = nullptr, |
| 5619 | SourceLocation opLoc = SourceLocation()); |
| 5620 | |
| 5621 | ExprResult BuildPossibleImplicitMemberExpr( |
| 5622 | const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, |
| 5623 | const TemplateArgumentListInfo *TemplateArgs, const Scope *S, |
| 5624 | UnresolvedLookupExpr *AsULE = nullptr); |
| 5625 | ExprResult BuildImplicitMemberExpr(const CXXScopeSpec &SS, |
| 5626 | SourceLocation TemplateKWLoc, |
| 5627 | LookupResult &R, |
| 5628 | const TemplateArgumentListInfo *TemplateArgs, |
| 5629 | bool IsDefiniteInstance, |
| 5630 | const Scope *S); |
| 5631 | bool UseArgumentDependentLookup(const CXXScopeSpec &SS, |
| 5632 | const LookupResult &R, |
| 5633 | bool HasTrailingLParen); |
| 5634 | |
| 5635 | ExprResult |
| 5636 | BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, |
| 5637 | const DeclarationNameInfo &NameInfo, |
| 5638 | bool IsAddressOfOperand, const Scope *S, |
| 5639 | TypeSourceInfo **RecoveryTSI = nullptr); |
| 5640 | |
| 5641 | ExprResult BuildDependentDeclRefExpr(const CXXScopeSpec &SS, |
| 5642 | SourceLocation TemplateKWLoc, |
| 5643 | const DeclarationNameInfo &NameInfo, |
| 5644 | const TemplateArgumentListInfo *TemplateArgs); |
| 5645 | |
| 5646 | ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 5647 | LookupResult &R, |
| 5648 | bool NeedsADL, |
| 5649 | bool AcceptInvalidDecl = false); |
| 5650 | ExprResult BuildDeclarationNameExpr( |
| 5651 | const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, |
| 5652 | NamedDecl *FoundD = nullptr, |
| 5653 | const TemplateArgumentListInfo *TemplateArgs = nullptr, |
| 5654 | bool AcceptInvalidDecl = false); |
| 5655 | |
| 5656 | ExprResult BuildLiteralOperatorCall(LookupResult &R, |
| 5657 | DeclarationNameInfo &SuffixInfo, |
| 5658 | ArrayRef<Expr *> Args, |
| 5659 | SourceLocation LitEndLoc, |
| 5660 | TemplateArgumentListInfo *ExplicitTemplateArgs = nullptr); |
| 5661 | |
| 5662 | ExprResult BuildPredefinedExpr(SourceLocation Loc, |
| 5663 | PredefinedExpr::IdentKind IK); |
| 5664 | ExprResult ActOnPredefinedExpr(SourceLocation Loc, tok::TokenKind Kind); |
| 5665 | ExprResult ActOnIntegerConstant(SourceLocation Loc, uint64_t Val); |
| 5666 | |
| 5667 | ExprResult BuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
| 5668 | SourceLocation LParen, |
| 5669 | SourceLocation RParen, |
| 5670 | TypeSourceInfo *TSI); |
| 5671 | ExprResult ActOnSYCLUniqueStableNameExpr(SourceLocation OpLoc, |
| 5672 | SourceLocation LParen, |
| 5673 | SourceLocation RParen, |
| 5674 | ParsedType ParsedTy); |
| 5675 | |
| 5676 | bool CheckLoopHintExpr(Expr *E, SourceLocation Loc); |
| 5677 | |
| 5678 | ExprResult ActOnNumericConstant(const Token &Tok, Scope *UDLScope = nullptr); |
| 5679 | ExprResult ActOnCharacterConstant(const Token &Tok, |
| 5680 | Scope *UDLScope = nullptr); |
| 5681 | ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E); |
| 5682 | ExprResult ActOnParenListExpr(SourceLocation L, |
| 5683 | SourceLocation R, |
| 5684 | MultiExprArg Val); |
| 5685 | |
| 5686 | /// ActOnStringLiteral - The specified tokens were lexed as pasted string |
| 5687 | /// fragments (e.g. "foo" "bar" L"baz"). |
| 5688 | ExprResult ActOnStringLiteral(ArrayRef<Token> StringToks, |
| 5689 | Scope *UDLScope = nullptr); |
| 5690 | |
| 5691 | ExprResult ActOnGenericSelectionExpr(SourceLocation KeyLoc, |
| 5692 | SourceLocation DefaultLoc, |
| 5693 | SourceLocation RParenLoc, |
| 5694 | Expr *ControllingExpr, |
| 5695 | ArrayRef<ParsedType> ArgTypes, |
| 5696 | ArrayRef<Expr *> ArgExprs); |
| 5697 | ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, |
| 5698 | SourceLocation DefaultLoc, |
| 5699 | SourceLocation RParenLoc, |
| 5700 | Expr *ControllingExpr, |
| 5701 | ArrayRef<TypeSourceInfo *> Types, |
| 5702 | ArrayRef<Expr *> Exprs); |
| 5703 | |
| 5704 | // Binary/Unary Operators. 'Tok' is the token for the operator. |
| 5705 | ExprResult CreateBuiltinUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, |
| 5706 | Expr *InputExpr, bool IsAfterAmp = false); |
| 5707 | ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, |
| 5708 | Expr *Input, bool IsAfterAmp = false); |
| 5709 | ExprResult ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, |
| 5710 | Expr *Input, bool IsAfterAmp = false); |
| 5711 | |
| 5712 | bool isQualifiedMemberAccess(Expr *E); |
| 5713 | QualType CheckAddressOfOperand(ExprResult &Operand, SourceLocation OpLoc); |
| 5714 | |
| 5715 | bool CheckTypeTraitArity(unsigned Arity, SourceLocation Loc, size_t N); |
| 5716 | |
| 5717 | ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, |
| 5718 | SourceLocation OpLoc, |
| 5719 | UnaryExprOrTypeTrait ExprKind, |
| 5720 | SourceRange R); |
| 5721 | ExprResult CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, |
| 5722 | UnaryExprOrTypeTrait ExprKind); |
| 5723 | ExprResult |
| 5724 | ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, |
| 5725 | UnaryExprOrTypeTrait ExprKind, |
| 5726 | bool IsType, void *TyOrEx, |
| 5727 | SourceRange ArgRange); |
| 5728 | |
| 5729 | ExprResult CheckPlaceholderExpr(Expr *E); |
| 5730 | bool CheckVecStepExpr(Expr *E); |
| 5731 | |
| 5732 | bool CheckUnaryExprOrTypeTraitOperand(Expr *E, UnaryExprOrTypeTrait ExprKind); |
| 5733 | bool CheckUnaryExprOrTypeTraitOperand(QualType ExprType, SourceLocation OpLoc, |
| 5734 | SourceRange ExprRange, |
| 5735 | UnaryExprOrTypeTrait ExprKind); |
| 5736 | ExprResult ActOnSizeofParameterPackExpr(Scope *S, |
| 5737 | SourceLocation OpLoc, |
| 5738 | IdentifierInfo &Name, |
| 5739 | SourceLocation NameLoc, |
| 5740 | SourceLocation RParenLoc); |
| 5741 | ExprResult ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, |
| 5742 | tok::TokenKind Kind, Expr *Input); |
| 5743 | |
| 5744 | ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, |
| 5745 | MultiExprArg ArgExprs, |
| 5746 | SourceLocation RLoc); |
| 5747 | ExprResult CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, |
| 5748 | Expr *Idx, SourceLocation RLoc); |
| 5749 | |
| 5750 | ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
| 5751 | Expr *ColumnIdx, |
| 5752 | SourceLocation RBLoc); |
| 5753 | |
| 5754 | ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, |
| 5755 | Expr *LowerBound, |
| 5756 | SourceLocation ColonLocFirst, |
| 5757 | SourceLocation ColonLocSecond, |
| 5758 | Expr *Length, Expr *Stride, |
| 5759 | SourceLocation RBLoc); |
| 5760 | ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, |
| 5761 | SourceLocation RParenLoc, |
| 5762 | ArrayRef<Expr *> Dims, |
| 5763 | ArrayRef<SourceRange> Brackets); |
| 5764 | |
| 5765 | /// Data structure for iterator expression. |
| 5766 | struct OMPIteratorData { |
| 5767 | IdentifierInfo *DeclIdent = nullptr; |
| 5768 | SourceLocation DeclIdentLoc; |
| 5769 | ParsedType Type; |
| 5770 | OMPIteratorExpr::IteratorRange Range; |
| 5771 | SourceLocation AssignLoc; |
| 5772 | SourceLocation ColonLoc; |
| 5773 | SourceLocation SecColonLoc; |
| 5774 | }; |
| 5775 | |
| 5776 | ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, |
| 5777 | SourceLocation LLoc, SourceLocation RLoc, |
| 5778 | ArrayRef<OMPIteratorData> Data); |
| 5779 | |
| 5780 | // This struct is for use by ActOnMemberAccess to allow |
| 5781 | // BuildMemberReferenceExpr to be able to reinvoke ActOnMemberAccess after |
| 5782 | // changing the access operator from a '.' to a '->' (to see if that is the |
| 5783 | // change needed to fix an error about an unknown member, e.g. when the class |
| 5784 | // defines a custom operator->). |
| 5785 | struct ActOnMemberAccessExtraArgs { |
| 5786 | Scope *S; |
| 5787 | UnqualifiedId &Id; |
| 5788 | Decl *ObjCImpDecl; |
| 5789 | }; |
| 5790 | |
| 5791 | ExprResult BuildMemberReferenceExpr( |
| 5792 | Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, |
| 5793 | CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 5794 | NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, |
| 5795 | const TemplateArgumentListInfo *TemplateArgs, |
| 5796 | const Scope *S, |
| 5797 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
| 5798 | |
| 5799 | ExprResult |
| 5800 | BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, |
| 5801 | bool IsArrow, const CXXScopeSpec &SS, |
| 5802 | SourceLocation TemplateKWLoc, |
| 5803 | NamedDecl *FirstQualifierInScope, LookupResult &R, |
| 5804 | const TemplateArgumentListInfo *TemplateArgs, |
| 5805 | const Scope *S, |
| 5806 | bool SuppressQualifierCheck = false, |
| 5807 | ActOnMemberAccessExtraArgs *ExtraArgs = nullptr); |
| 5808 | |
| 5809 | ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, |
| 5810 | SourceLocation OpLoc, |
| 5811 | const CXXScopeSpec &SS, FieldDecl *Field, |
| 5812 | DeclAccessPair FoundDecl, |
| 5813 | const DeclarationNameInfo &MemberNameInfo); |
| 5814 | |
| 5815 | ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow); |
| 5816 | |
| 5817 | bool CheckQualifiedMemberReference(Expr *BaseExpr, QualType BaseType, |
| 5818 | const CXXScopeSpec &SS, |
| 5819 | const LookupResult &R); |
| 5820 | |
| 5821 | ExprResult ActOnDependentMemberExpr(Expr *Base, QualType BaseType, |
| 5822 | bool IsArrow, SourceLocation OpLoc, |
| 5823 | const CXXScopeSpec &SS, |
| 5824 | SourceLocation TemplateKWLoc, |
| 5825 | NamedDecl *FirstQualifierInScope, |
| 5826 | const DeclarationNameInfo &NameInfo, |
| 5827 | const TemplateArgumentListInfo *TemplateArgs); |
| 5828 | |
| 5829 | ExprResult ActOnMemberAccessExpr(Scope *S, Expr *Base, |
| 5830 | SourceLocation OpLoc, |
| 5831 | tok::TokenKind OpKind, |
| 5832 | CXXScopeSpec &SS, |
| 5833 | SourceLocation TemplateKWLoc, |
| 5834 | UnqualifiedId &Member, |
| 5835 | Decl *ObjCImpDecl); |
| 5836 | |
| 5837 | MemberExpr * |
| 5838 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
| 5839 | const CXXScopeSpec *SS, SourceLocation TemplateKWLoc, |
| 5840 | ValueDecl *Member, DeclAccessPair FoundDecl, |
| 5841 | bool HadMultipleCandidates, |
| 5842 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
| 5843 | ExprValueKind VK, ExprObjectKind OK, |
| 5844 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
| 5845 | MemberExpr * |
| 5846 | BuildMemberExpr(Expr *Base, bool IsArrow, SourceLocation OpLoc, |
| 5847 | NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, |
| 5848 | ValueDecl *Member, DeclAccessPair FoundDecl, |
| 5849 | bool HadMultipleCandidates, |
| 5850 | const DeclarationNameInfo &MemberNameInfo, QualType Ty, |
| 5851 | ExprValueKind VK, ExprObjectKind OK, |
| 5852 | const TemplateArgumentListInfo *TemplateArgs = nullptr); |
| 5853 | |
| 5854 | void ActOnDefaultCtorInitializers(Decl *CDtorDecl); |
| 5855 | bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, |
| 5856 | FunctionDecl *FDecl, |
| 5857 | const FunctionProtoType *Proto, |
| 5858 | ArrayRef<Expr *> Args, |
| 5859 | SourceLocation RParenLoc, |
| 5860 | bool ExecConfig = false); |
| 5861 | void CheckStaticArrayArgument(SourceLocation CallLoc, |
| 5862 | ParmVarDecl *Param, |
| 5863 | const Expr *ArgExpr); |
| 5864 | |
| 5865 | /// ActOnCallExpr - Handle a call to Fn with the specified array of arguments. |
| 5866 | /// This provides the location of the left/right parens and a list of comma |
| 5867 | /// locations. |
| 5868 | ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
| 5869 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
| 5870 | Expr *ExecConfig = nullptr); |
| 5871 | ExprResult BuildCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, |
| 5872 | MultiExprArg ArgExprs, SourceLocation RParenLoc, |
| 5873 | Expr *ExecConfig = nullptr, |
| 5874 | bool IsExecConfig = false, |
| 5875 | bool AllowRecovery = false); |
| 5876 | Expr *BuildBuiltinCallExpr(SourceLocation Loc, Builtin::ID Id, |
| 5877 | MultiExprArg CallArgs); |
| 5878 | enum class AtomicArgumentOrder { API, AST }; |
| 5879 | ExprResult |
| 5880 | BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, |
| 5881 | SourceLocation RParenLoc, MultiExprArg Args, |
| 5882 | AtomicExpr::AtomicOp Op, |
| 5883 | AtomicArgumentOrder ArgOrder = AtomicArgumentOrder::API); |
| 5884 | ExprResult |
| 5885 | BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, SourceLocation LParenLoc, |
| 5886 | ArrayRef<Expr *> Arg, SourceLocation RParenLoc, |
| 5887 | Expr *Config = nullptr, bool IsExecConfig = false, |
| 5888 | ADLCallKind UsesADL = ADLCallKind::NotADL); |
| 5889 | |
| 5890 | ExprResult ActOnCUDAExecConfigExpr(Scope *S, SourceLocation LLLLoc, |
| 5891 | MultiExprArg ExecConfig, |
| 5892 | SourceLocation GGGLoc); |
| 5893 | |
| 5894 | ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, |
| 5895 | Declarator &D, ParsedType &Ty, |
| 5896 | SourceLocation RParenLoc, Expr *CastExpr); |
| 5897 | ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, |
| 5898 | TypeSourceInfo *Ty, |
| 5899 | SourceLocation RParenLoc, |
| 5900 | Expr *Op); |
| 5901 | CastKind PrepareScalarCast(ExprResult &src, QualType destType); |
| 5902 | |
| 5903 | /// Build an altivec or OpenCL literal. |
| 5904 | ExprResult BuildVectorLiteral(SourceLocation LParenLoc, |
| 5905 | SourceLocation RParenLoc, Expr *E, |
| 5906 | TypeSourceInfo *TInfo); |
| 5907 | |
| 5908 | ExprResult MaybeConvertParenListExprToParenExpr(Scope *S, Expr *ME); |
| 5909 | |
| 5910 | ExprResult ActOnCompoundLiteral(SourceLocation LParenLoc, |
| 5911 | ParsedType Ty, |
| 5912 | SourceLocation RParenLoc, |
| 5913 | Expr *InitExpr); |
| 5914 | |
| 5915 | ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 5916 | TypeSourceInfo *TInfo, |
| 5917 | SourceLocation RParenLoc, |
| 5918 | Expr *LiteralExpr); |
| 5919 | |
| 5920 | ExprResult ActOnInitList(SourceLocation LBraceLoc, |
| 5921 | MultiExprArg InitArgList, |
| 5922 | SourceLocation RBraceLoc); |
| 5923 | |
| 5924 | ExprResult BuildInitList(SourceLocation LBraceLoc, |
| 5925 | MultiExprArg InitArgList, |
| 5926 | SourceLocation RBraceLoc); |
| 5927 | |
| 5928 | ExprResult ActOnDesignatedInitializer(Designation &Desig, |
| 5929 | SourceLocation EqualOrColonLoc, |
| 5930 | bool GNUSyntax, |
| 5931 | ExprResult Init); |
| 5932 | |
| 5933 | private: |
| 5934 | static BinaryOperatorKind ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind); |
| 5935 | |
| 5936 | public: |
| 5937 | ExprResult ActOnBinOp(Scope *S, SourceLocation TokLoc, |
| 5938 | tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr); |
| 5939 | ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, |
| 5940 | BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr); |
| 5941 | ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, |
| 5942 | Expr *LHSExpr, Expr *RHSExpr); |
| 5943 | void LookupBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, |
| 5944 | UnresolvedSetImpl &Functions); |
| 5945 | |
| 5946 | void DiagnoseCommaOperator(const Expr *LHS, SourceLocation Loc); |
| 5947 | |
| 5948 | /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null |
| 5949 | /// in the case of a the GNU conditional expr extension. |
| 5950 | ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, |
| 5951 | SourceLocation ColonLoc, |
| 5952 | Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr); |
| 5953 | |
| 5954 | /// ActOnAddrLabel - Parse the GNU address of label extension: "&&foo". |
| 5955 | ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, |
| 5956 | LabelDecl *TheDecl); |
| 5957 | |
| 5958 | void ActOnStartStmtExpr(); |
| 5959 | ExprResult ActOnStmtExpr(Scope *S, SourceLocation LPLoc, Stmt *SubStmt, |
| 5960 | SourceLocation RPLoc); |
| 5961 | ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, |
| 5962 | SourceLocation RPLoc, unsigned TemplateDepth); |
| 5963 | // Handle the final expression in a statement expression. |
| 5964 | ExprResult ActOnStmtExprResult(ExprResult E); |
| 5965 | void ActOnStmtExprError(); |
| 5966 | |
| 5967 | // __builtin_offsetof(type, identifier(.identifier|[expr])*) |
| 5968 | struct OffsetOfComponent { |
| 5969 | SourceLocation LocStart, LocEnd; |
| 5970 | bool isBrackets; // true if [expr], false if .ident |
| 5971 | union { |
| 5972 | IdentifierInfo *IdentInfo; |
| 5973 | Expr *E; |
| 5974 | } U; |
| 5975 | }; |
| 5976 | |
| 5977 | /// __builtin_offsetof(type, a.b[123][456].c) |
| 5978 | ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, |
| 5979 | TypeSourceInfo *TInfo, |
| 5980 | ArrayRef<OffsetOfComponent> Components, |
| 5981 | SourceLocation RParenLoc); |
| 5982 | ExprResult ActOnBuiltinOffsetOf(Scope *S, |
| 5983 | SourceLocation BuiltinLoc, |
| 5984 | SourceLocation TypeLoc, |
| 5985 | ParsedType ParsedArgTy, |
| 5986 | ArrayRef<OffsetOfComponent> Components, |
| 5987 | SourceLocation RParenLoc); |
| 5988 | |
| 5989 | // __builtin_choose_expr(constExpr, expr1, expr2) |
| 5990 | ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, |
| 5991 | Expr *CondExpr, Expr *LHSExpr, |
| 5992 | Expr *RHSExpr, SourceLocation RPLoc); |
| 5993 | |
| 5994 | // __builtin_va_arg(expr, type) |
| 5995 | ExprResult ActOnVAArg(SourceLocation BuiltinLoc, Expr *E, ParsedType Ty, |
| 5996 | SourceLocation RPLoc); |
| 5997 | ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, |
| 5998 | TypeSourceInfo *TInfo, SourceLocation RPLoc); |
| 5999 | |
| 6000 | // __builtin_LINE(), __builtin_FUNCTION(), __builtin_FILE(), |
| 6001 | // __builtin_COLUMN(), __builtin_source_location() |
| 6002 | ExprResult ActOnSourceLocExpr(SourceLocExpr::IdentKind Kind, |
| 6003 | SourceLocation BuiltinLoc, |
| 6004 | SourceLocation RPLoc); |
| 6005 | |
| 6006 | // Build a potentially resolved SourceLocExpr. |
| 6007 | ExprResult BuildSourceLocExpr(SourceLocExpr::IdentKind Kind, |
| 6008 | QualType ResultTy, SourceLocation BuiltinLoc, |
| 6009 | SourceLocation RPLoc, |
| 6010 | DeclContext *ParentContext); |
| 6011 | |
| 6012 | // __null |
| 6013 | ExprResult ActOnGNUNullExpr(SourceLocation TokenLoc); |
| 6014 | |
| 6015 | bool CheckCaseExpression(Expr *E); |
| 6016 | |
| 6017 | /// Describes the result of an "if-exists" condition check. |
| 6018 | enum IfExistsResult { |
| 6019 | /// The symbol exists. |
| 6020 | IER_Exists, |
| 6021 | |
| 6022 | /// The symbol does not exist. |
| 6023 | IER_DoesNotExist, |
| 6024 | |
| 6025 | /// The name is a dependent name, so the results will differ |
| 6026 | /// from one instantiation to the next. |
| 6027 | IER_Dependent, |
| 6028 | |
| 6029 | /// An error occurred. |
| 6030 | IER_Error |
| 6031 | }; |
| 6032 | |
| 6033 | IfExistsResult |
| 6034 | CheckMicrosoftIfExistsSymbol(Scope *S, CXXScopeSpec &SS, |
| 6035 | const DeclarationNameInfo &TargetNameInfo); |
| 6036 | |
| 6037 | IfExistsResult |
| 6038 | CheckMicrosoftIfExistsSymbol(Scope *S, SourceLocation KeywordLoc, |
| 6039 | bool IsIfExists, CXXScopeSpec &SS, |
| 6040 | UnqualifiedId &Name); |
| 6041 | |
| 6042 | StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
| 6043 | bool IsIfExists, |
| 6044 | NestedNameSpecifierLoc QualifierLoc, |
| 6045 | DeclarationNameInfo NameInfo, |
| 6046 | Stmt *Nested); |
| 6047 | StmtResult ActOnMSDependentExistsStmt(SourceLocation KeywordLoc, |
| 6048 | bool IsIfExists, |
| 6049 | CXXScopeSpec &SS, UnqualifiedId &Name, |
| 6050 | Stmt *Nested); |
| 6051 | |
| 6052 | //===------------------------- "Block" Extension ------------------------===// |
| 6053 | |
| 6054 | /// ActOnBlockStart - This callback is invoked when a block literal is |
| 6055 | /// started. |
| 6056 | void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope); |
| 6057 | |
| 6058 | /// ActOnBlockArguments - This callback allows processing of block arguments. |
| 6059 | /// If there are no arguments, this is still invoked. |
| 6060 | void ActOnBlockArguments(SourceLocation CaretLoc, Declarator &ParamInfo, |
| 6061 | Scope *CurScope); |
| 6062 | |
| 6063 | /// ActOnBlockError - If there is an error parsing a block, this callback |
| 6064 | /// is invoked to pop the information about the block from the action impl. |
| 6065 | void ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope); |
| 6066 | |
| 6067 | /// ActOnBlockStmtExpr - This is called when the body of a block statement |
| 6068 | /// literal was successfully completed. ^(int x){...} |
| 6069 | ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, |
| 6070 | Scope *CurScope); |
| 6071 | |
| 6072 | //===---------------------------- Clang Extensions ----------------------===// |
| 6073 | |
| 6074 | /// __builtin_convertvector(...) |
| 6075 | ExprResult ActOnConvertVectorExpr(Expr *E, ParsedType ParsedDestTy, |
| 6076 | SourceLocation BuiltinLoc, |
| 6077 | SourceLocation RParenLoc); |
| 6078 | |
| 6079 | //===---------------------------- OpenCL Features -----------------------===// |
| 6080 | |
| 6081 | /// __builtin_astype(...) |
| 6082 | ExprResult ActOnAsTypeExpr(Expr *E, ParsedType ParsedDestTy, |
| 6083 | SourceLocation BuiltinLoc, |
| 6084 | SourceLocation RParenLoc); |
| 6085 | ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, |
| 6086 | SourceLocation BuiltinLoc, |
| 6087 | SourceLocation RParenLoc); |
| 6088 | |
| 6089 | //===---------------------------- HLSL Features -------------------------===// |
| 6090 | Decl *ActOnStartHLSLBuffer(Scope *BufferScope, bool CBuffer, |
| 6091 | SourceLocation KwLoc, IdentifierInfo *Ident, |
| 6092 | SourceLocation IdentLoc, SourceLocation LBrace); |
| 6093 | void ActOnFinishHLSLBuffer(Decl *Dcl, SourceLocation RBrace); |
| 6094 | |
| 6095 | //===---------------------------- C++ Features --------------------------===// |
| 6096 | |
| 6097 | // Act on C++ namespaces |
| 6098 | Decl *ActOnStartNamespaceDef(Scope *S, SourceLocation InlineLoc, |
| 6099 | SourceLocation NamespaceLoc, |
| 6100 | SourceLocation IdentLoc, IdentifierInfo *Ident, |
| 6101 | SourceLocation LBrace, |
| 6102 | const ParsedAttributesView &AttrList, |
| 6103 | UsingDirectiveDecl *&UsingDecl, bool IsNested); |
| 6104 | void ActOnFinishNamespaceDef(Decl *Dcl, SourceLocation RBrace); |
| 6105 | |
| 6106 | NamespaceDecl *getStdNamespace() const; |
| 6107 | NamespaceDecl *getOrCreateStdNamespace(); |
| 6108 | |
| 6109 | CXXRecordDecl *getStdBadAlloc() const; |
| 6110 | EnumDecl *getStdAlignValT() const; |
| 6111 | |
| 6112 | private: |
| 6113 | // A cache representing if we've fully checked the various comparison category |
| 6114 | // types stored in ASTContext. The bit-index corresponds to the integer value |
| 6115 | // of a ComparisonCategoryType enumerator. |
| 6116 | llvm::SmallBitVector FullyCheckedComparisonCategories; |
| 6117 | |
| 6118 | ValueDecl *tryLookupCtorInitMemberDecl(CXXRecordDecl *ClassDecl, |
| 6119 | CXXScopeSpec &SS, |
| 6120 | ParsedType TemplateTypeTy, |
| 6121 | IdentifierInfo *MemberOrBase); |
| 6122 | |
| 6123 | public: |
| 6124 | enum class ComparisonCategoryUsage { |
| 6125 | /// The '<=>' operator was used in an expression and a builtin operator |
| 6126 | /// was selected. |
| 6127 | OperatorInExpression, |
| 6128 | /// A defaulted 'operator<=>' needed the comparison category. This |
| 6129 | /// typically only applies to 'std::strong_ordering', due to the implicit |
| 6130 | /// fallback return value. |
| 6131 | DefaultedOperator, |
| 6132 | }; |
| 6133 | |
| 6134 | /// Lookup the specified comparison category types in the standard |
| 6135 | /// library, an check the VarDecls possibly returned by the operator<=> |
| 6136 | /// builtins for that type. |
| 6137 | /// |
| 6138 | /// \return The type of the comparison category type corresponding to the |
| 6139 | /// specified Kind, or a null type if an error occurs |
| 6140 | QualType CheckComparisonCategoryType(ComparisonCategoryType Kind, |
| 6141 | SourceLocation Loc, |
| 6142 | ComparisonCategoryUsage Usage); |
| 6143 | |
| 6144 | /// Tests whether Ty is an instance of std::initializer_list and, if |
| 6145 | /// it is and Element is not NULL, assigns the element type to Element. |
| 6146 | bool isStdInitializerList(QualType Ty, QualType *Element); |
| 6147 | |
| 6148 | /// Looks for the std::initializer_list template and instantiates it |
| 6149 | /// with Element, or emits an error if it's not found. |
| 6150 | /// |
| 6151 | /// \returns The instantiated template, or null on error. |
| 6152 | QualType BuildStdInitializerList(QualType Element, SourceLocation Loc); |
| 6153 | |
| 6154 | /// Determine whether Ctor is an initializer-list constructor, as |
| 6155 | /// defined in [dcl.init.list]p2. |
| 6156 | bool isInitListConstructor(const FunctionDecl *Ctor); |
| 6157 | |
| 6158 | Decl *ActOnUsingDirective(Scope *CurScope, SourceLocation UsingLoc, |
| 6159 | SourceLocation NamespcLoc, CXXScopeSpec &SS, |
| 6160 | SourceLocation IdentLoc, |
| 6161 | IdentifierInfo *NamespcName, |
| 6162 | const ParsedAttributesView &AttrList); |
| 6163 | |
| 6164 | void PushUsingDirective(Scope *S, UsingDirectiveDecl *UDir); |
| 6165 | |
| 6166 | Decl *ActOnNamespaceAliasDef(Scope *CurScope, |
| 6167 | SourceLocation NamespaceLoc, |
| 6168 | SourceLocation AliasLoc, |
| 6169 | IdentifierInfo *Alias, |
| 6170 | CXXScopeSpec &SS, |
| 6171 | SourceLocation IdentLoc, |
| 6172 | IdentifierInfo *Ident); |
| 6173 | |
| 6174 | void FilterUsingLookup(Scope *S, LookupResult &lookup); |
| 6175 | void HideUsingShadowDecl(Scope *S, UsingShadowDecl *Shadow); |
| 6176 | bool CheckUsingShadowDecl(BaseUsingDecl *BUD, NamedDecl *Target, |
| 6177 | const LookupResult &PreviousDecls, |
| 6178 | UsingShadowDecl *&PrevShadow); |
| 6179 | UsingShadowDecl *BuildUsingShadowDecl(Scope *S, BaseUsingDecl *BUD, |
| 6180 | NamedDecl *Target, |
| 6181 | UsingShadowDecl *PrevDecl); |
| 6182 | |
| 6183 | bool CheckUsingDeclRedeclaration(SourceLocation UsingLoc, |
| 6184 | bool HasTypenameKeyword, |
| 6185 | const CXXScopeSpec &SS, |
| 6186 | SourceLocation NameLoc, |
| 6187 | const LookupResult &Previous); |
| 6188 | bool CheckUsingDeclQualifier(SourceLocation UsingLoc, bool HasTypename, |
| 6189 | const CXXScopeSpec &SS, |
| 6190 | const DeclarationNameInfo &NameInfo, |
| 6191 | SourceLocation NameLoc, |
| 6192 | const LookupResult *R = nullptr, |
| 6193 | const UsingDecl *UD = nullptr); |
| 6194 | |
| 6195 | NamedDecl *BuildUsingDeclaration( |
| 6196 | Scope *S, AccessSpecifier AS, SourceLocation UsingLoc, |
| 6197 | bool HasTypenameKeyword, SourceLocation TypenameLoc, CXXScopeSpec &SS, |
| 6198 | DeclarationNameInfo NameInfo, SourceLocation EllipsisLoc, |
| 6199 | const ParsedAttributesView &AttrList, bool IsInstantiation, |
| 6200 | bool IsUsingIfExists); |
| 6201 | NamedDecl *BuildUsingEnumDeclaration(Scope *S, AccessSpecifier AS, |
| 6202 | SourceLocation UsingLoc, |
| 6203 | SourceLocation EnumLoc, |
| 6204 | SourceLocation NameLoc, |
| 6205 | TypeSourceInfo *EnumType, EnumDecl *ED); |
| 6206 | NamedDecl *BuildUsingPackDecl(NamedDecl *InstantiatedFrom, |
| 6207 | ArrayRef<NamedDecl *> Expansions); |
| 6208 | |
| 6209 | bool CheckInheritingConstructorUsingDecl(UsingDecl *UD); |
| 6210 | |
| 6211 | /// Given a derived-class using shadow declaration for a constructor and the |
| 6212 | /// correspnding base class constructor, find or create the implicit |
| 6213 | /// synthesized derived class constructor to use for this initialization. |
| 6214 | CXXConstructorDecl * |
| 6215 | findInheritingConstructor(SourceLocation Loc, CXXConstructorDecl *BaseCtor, |
| 6216 | ConstructorUsingShadowDecl *DerivedShadow); |
| 6217 | |
| 6218 | Decl *ActOnUsingDeclaration(Scope *CurScope, AccessSpecifier AS, |
| 6219 | SourceLocation UsingLoc, |
| 6220 | SourceLocation TypenameLoc, CXXScopeSpec &SS, |
| 6221 | UnqualifiedId &Name, SourceLocation EllipsisLoc, |
| 6222 | const ParsedAttributesView &AttrList); |
| 6223 | Decl *ActOnUsingEnumDeclaration(Scope *CurScope, AccessSpecifier AS, |
| 6224 | SourceLocation UsingLoc, |
| 6225 | SourceLocation EnumLoc, |
| 6226 | SourceLocation IdentLoc, IdentifierInfo &II, |
| 6227 | CXXScopeSpec *SS = nullptr); |
| 6228 | Decl *ActOnAliasDeclaration(Scope *CurScope, AccessSpecifier AS, |
| 6229 | MultiTemplateParamsArg TemplateParams, |
| 6230 | SourceLocation UsingLoc, UnqualifiedId &Name, |
| 6231 | const ParsedAttributesView &AttrList, |
| 6232 | TypeResult Type, Decl *DeclFromDeclSpec); |
| 6233 | |
| 6234 | /// BuildCXXConstructExpr - Creates a complete call to a constructor, |
| 6235 | /// including handling of its default argument expressions. |
| 6236 | /// |
| 6237 | /// \param ConstructKind - a CXXConstructExpr::ConstructionKind |
| 6238 | ExprResult |
| 6239 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
| 6240 | NamedDecl *FoundDecl, |
| 6241 | CXXConstructorDecl *Constructor, MultiExprArg Exprs, |
| 6242 | bool HadMultipleCandidates, bool IsListInitialization, |
| 6243 | bool IsStdInitListInitialization, |
| 6244 | bool RequiresZeroInit, unsigned ConstructKind, |
| 6245 | SourceRange ParenRange); |
| 6246 | |
| 6247 | /// Build a CXXConstructExpr whose constructor has already been resolved if |
| 6248 | /// it denotes an inherited constructor. |
| 6249 | ExprResult |
| 6250 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
| 6251 | CXXConstructorDecl *Constructor, bool Elidable, |
| 6252 | MultiExprArg Exprs, |
| 6253 | bool HadMultipleCandidates, bool IsListInitialization, |
| 6254 | bool IsStdInitListInitialization, |
| 6255 | bool RequiresZeroInit, unsigned ConstructKind, |
| 6256 | SourceRange ParenRange); |
| 6257 | |
| 6258 | // FIXME: Can we remove this and have the above BuildCXXConstructExpr check if |
| 6259 | // the constructor can be elidable? |
| 6260 | ExprResult |
| 6261 | BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, |
| 6262 | NamedDecl *FoundDecl, |
| 6263 | CXXConstructorDecl *Constructor, bool Elidable, |
| 6264 | MultiExprArg Exprs, bool HadMultipleCandidates, |
| 6265 | bool IsListInitialization, |
| 6266 | bool IsStdInitListInitialization, bool RequiresZeroInit, |
| 6267 | unsigned ConstructKind, SourceRange ParenRange); |
| 6268 | |
| 6269 | ExprResult ConvertMemberDefaultInitExpression(FieldDecl *FD, Expr *InitExpr, |
| 6270 | SourceLocation InitLoc); |
| 6271 | |
| 6272 | ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field); |
| 6273 | |
| 6274 | |
| 6275 | /// Instantiate or parse a C++ default argument expression as necessary. |
| 6276 | /// Return true on error. |
| 6277 | bool CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
| 6278 | ParmVarDecl *Param, Expr *Init = nullptr, |
| 6279 | bool SkipImmediateInvocations = true); |
| 6280 | |
| 6281 | /// BuildCXXDefaultArgExpr - Creates a CXXDefaultArgExpr, instantiating |
| 6282 | /// the default expr if needed. |
| 6283 | ExprResult BuildCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, |
| 6284 | ParmVarDecl *Param, Expr *Init = nullptr); |
| 6285 | |
| 6286 | /// FinalizeVarWithDestructor - Prepare for calling destructor on the |
| 6287 | /// constructed variable. |
| 6288 | void FinalizeVarWithDestructor(VarDecl *VD, const RecordType *DeclInitType); |
| 6289 | |
| 6290 | /// Helper class that collects exception specifications for |
| 6291 | /// implicitly-declared special member functions. |
| 6292 | class ImplicitExceptionSpecification { |
| 6293 | // Pointer to allow copying |
| 6294 | Sema *Self; |
| 6295 | // We order exception specifications thus: |
| 6296 | // noexcept is the most restrictive, but is only used in C++11. |
| 6297 | // throw() comes next. |
| 6298 | // Then a throw(collected exceptions) |
| 6299 | // Finally no specification, which is expressed as noexcept(false). |
| 6300 | // throw(...) is used instead if any called function uses it. |
| 6301 | ExceptionSpecificationType ComputedEST; |
| 6302 | llvm::SmallPtrSet<CanQualType, 4> ExceptionsSeen; |
| 6303 | SmallVector<QualType, 4> Exceptions; |
| 6304 | |
| 6305 | void ClearExceptions() { |
| 6306 | ExceptionsSeen.clear(); |
| 6307 | Exceptions.clear(); |
| 6308 | } |
| 6309 | |
| 6310 | public: |
| 6311 | explicit ImplicitExceptionSpecification(Sema &Self) |
| 6312 | : Self(&Self), ComputedEST(EST_BasicNoexcept) { |
| 6313 | if (!Self.getLangOpts().CPlusPlus11) |
| 6314 | ComputedEST = EST_DynamicNone; |
| 6315 | } |
| 6316 | |
| 6317 | /// Get the computed exception specification type. |
| 6318 | ExceptionSpecificationType getExceptionSpecType() const { |
| 6319 | assert(!isComputedNoexcept(ComputedEST) &&(static_cast <bool> (!isComputedNoexcept(ComputedEST) && "noexcept(expr) should not be a possible result") ? void (0) : __assert_fail ("!isComputedNoexcept(ComputedEST) && \"noexcept(expr) should not be a possible result\"" , "clang/include/clang/Sema/Sema.h", 6320, __extension__ __PRETTY_FUNCTION__ )) |
| 6320 | "noexcept(expr) should not be a possible result")(static_cast <bool> (!isComputedNoexcept(ComputedEST) && "noexcept(expr) should not be a possible result") ? void (0) : __assert_fail ("!isComputedNoexcept(ComputedEST) && \"noexcept(expr) should not be a possible result\"" , "clang/include/clang/Sema/Sema.h", 6320, __extension__ __PRETTY_FUNCTION__ )); |
| 6321 | return ComputedEST; |
| 6322 | } |
| 6323 | |
| 6324 | /// The number of exceptions in the exception specification. |
| 6325 | unsigned size() const { return Exceptions.size(); } |
| 6326 | |
| 6327 | /// The set of exceptions in the exception specification. |
| 6328 | const QualType *data() const { return Exceptions.data(); } |
| 6329 | |
| 6330 | /// Integrate another called method into the collected data. |
| 6331 | void CalledDecl(SourceLocation CallLoc, const CXXMethodDecl *Method); |
| 6332 | |
| 6333 | /// Integrate an invoked expression into the collected data. |
| 6334 | void CalledExpr(Expr *E) { CalledStmt(E); } |
| 6335 | |
| 6336 | /// Integrate an invoked statement into the collected data. |
| 6337 | void CalledStmt(Stmt *S); |
| 6338 | |
| 6339 | /// Overwrite an EPI's exception specification with this |
| 6340 | /// computed exception specification. |
| 6341 | FunctionProtoType::ExceptionSpecInfo getExceptionSpec() const { |
| 6342 | FunctionProtoType::ExceptionSpecInfo ESI; |
| 6343 | ESI.Type = getExceptionSpecType(); |
| 6344 | if (ESI.Type == EST_Dynamic) { |
| 6345 | ESI.Exceptions = Exceptions; |
| 6346 | } else if (ESI.Type == EST_None) { |
| 6347 | /// C++11 [except.spec]p14: |
| 6348 | /// The exception-specification is noexcept(false) if the set of |
| 6349 | /// potential exceptions of the special member function contains "any" |
| 6350 | ESI.Type = EST_NoexceptFalse; |
| 6351 | ESI.NoexceptExpr = Self->ActOnCXXBoolLiteral(SourceLocation(), |
| 6352 | tok::kw_false).get(); |
| 6353 | } |
| 6354 | return ESI; |
| 6355 | } |
| 6356 | }; |
| 6357 | |
| 6358 | /// Evaluate the implicit exception specification for a defaulted |
| 6359 | /// special member function. |
| 6360 | void EvaluateImplicitExceptionSpec(SourceLocation Loc, FunctionDecl *FD); |
| 6361 | |
| 6362 | /// Check the given noexcept-specifier, convert its expression, and compute |
| 6363 | /// the appropriate ExceptionSpecificationType. |
| 6364 | ExprResult ActOnNoexceptSpec(Expr *NoexceptExpr, |
| 6365 | ExceptionSpecificationType &EST); |
| 6366 | |
| 6367 | /// Check the given exception-specification and update the |
| 6368 | /// exception specification information with the results. |
| 6369 | void checkExceptionSpecification(bool IsTopLevel, |
| 6370 | ExceptionSpecificationType EST, |
| 6371 | ArrayRef<ParsedType> DynamicExceptions, |
| 6372 | ArrayRef<SourceRange> DynamicExceptionRanges, |
| 6373 | Expr *NoexceptExpr, |
| 6374 | SmallVectorImpl<QualType> &Exceptions, |
| 6375 | FunctionProtoType::ExceptionSpecInfo &ESI); |
| 6376 | |
| 6377 | /// Determine if we're in a case where we need to (incorrectly) eagerly |
| 6378 | /// parse an exception specification to work around a libstdc++ bug. |
| 6379 | bool isLibstdcxxEagerExceptionSpecHack(const Declarator &D); |
| 6380 | |
| 6381 | /// Add an exception-specification to the given member function |
| 6382 | /// (or member function template). The exception-specification was parsed |
| 6383 | /// after the method itself was declared. |
| 6384 | void actOnDelayedExceptionSpecification(Decl *Method, |
| 6385 | ExceptionSpecificationType EST, |
| 6386 | SourceRange SpecificationRange, |
| 6387 | ArrayRef<ParsedType> DynamicExceptions, |
| 6388 | ArrayRef<SourceRange> DynamicExceptionRanges, |
| 6389 | Expr *NoexceptExpr); |
| 6390 | |
| 6391 | class InheritedConstructorInfo; |
| 6392 | |
| 6393 | /// Determine if a special member function should have a deleted |
| 6394 | /// definition when it is defaulted. |
| 6395 | bool ShouldDeleteSpecialMember(CXXMethodDecl *MD, CXXSpecialMember CSM, |
| 6396 | InheritedConstructorInfo *ICI = nullptr, |
| 6397 | bool Diagnose = false); |
| 6398 | |
| 6399 | /// Produce notes explaining why a defaulted function was defined as deleted. |
| 6400 | void DiagnoseDeletedDefaultedFunction(FunctionDecl *FD); |
| 6401 | |
| 6402 | /// Declare the implicit default constructor for the given class. |
| 6403 | /// |
| 6404 | /// \param ClassDecl The class declaration into which the implicit |
| 6405 | /// default constructor will be added. |
| 6406 | /// |
| 6407 | /// \returns The implicitly-declared default constructor. |
| 6408 | CXXConstructorDecl *DeclareImplicitDefaultConstructor( |
| 6409 | CXXRecordDecl *ClassDecl); |
| 6410 | |
| 6411 | /// DefineImplicitDefaultConstructor - Checks for feasibility of |
| 6412 | /// defining this constructor as the default constructor. |
| 6413 | void DefineImplicitDefaultConstructor(SourceLocation CurrentLocation, |
| 6414 | CXXConstructorDecl *Constructor); |
| 6415 | |
| 6416 | /// Declare the implicit destructor for the given class. |
| 6417 | /// |
| 6418 | /// \param ClassDecl The class declaration into which the implicit |
| 6419 | /// destructor will be added. |
| 6420 | /// |
| 6421 | /// \returns The implicitly-declared destructor. |
| 6422 | CXXDestructorDecl *DeclareImplicitDestructor(CXXRecordDecl *ClassDecl); |
| 6423 | |
| 6424 | /// DefineImplicitDestructor - Checks for feasibility of |
| 6425 | /// defining this destructor as the default destructor. |
| 6426 | void DefineImplicitDestructor(SourceLocation CurrentLocation, |
| 6427 | CXXDestructorDecl *Destructor); |
| 6428 | |
| 6429 | /// Build an exception spec for destructors that don't have one. |
| 6430 | /// |
| 6431 | /// C++11 says that user-defined destructors with no exception spec get one |
| 6432 | /// that looks as if the destructor was implicitly declared. |
| 6433 | void AdjustDestructorExceptionSpec(CXXDestructorDecl *Destructor); |
| 6434 | |
| 6435 | /// Define the specified inheriting constructor. |
| 6436 | void DefineInheritingConstructor(SourceLocation UseLoc, |
| 6437 | CXXConstructorDecl *Constructor); |
| 6438 | |
| 6439 | /// Declare the implicit copy constructor for the given class. |
| 6440 | /// |
| 6441 | /// \param ClassDecl The class declaration into which the implicit |
| 6442 | /// copy constructor will be added. |
| 6443 | /// |
| 6444 | /// \returns The implicitly-declared copy constructor. |
| 6445 | CXXConstructorDecl *DeclareImplicitCopyConstructor(CXXRecordDecl *ClassDecl); |
| 6446 | |
| 6447 | /// DefineImplicitCopyConstructor - Checks for feasibility of |
| 6448 | /// defining this constructor as the copy constructor. |
| 6449 | void DefineImplicitCopyConstructor(SourceLocation CurrentLocation, |
| 6450 | CXXConstructorDecl *Constructor); |
| 6451 | |
| 6452 | /// Declare the implicit move constructor for the given class. |
| 6453 | /// |
| 6454 | /// \param ClassDecl The Class declaration into which the implicit |
| 6455 | /// move constructor will be added. |
| 6456 | /// |
| 6457 | /// \returns The implicitly-declared move constructor, or NULL if it wasn't |
| 6458 | /// declared. |
| 6459 | CXXConstructorDecl *DeclareImplicitMoveConstructor(CXXRecordDecl *ClassDecl); |
| 6460 | |
| 6461 | /// DefineImplicitMoveConstructor - Checks for feasibility of |
| 6462 | /// defining this constructor as the move constructor. |
| 6463 | void DefineImplicitMoveConstructor(SourceLocation CurrentLocation, |
| 6464 | CXXConstructorDecl *Constructor); |
| 6465 | |
| 6466 | /// Declare the implicit copy assignment operator for the given class. |
| 6467 | /// |
| 6468 | /// \param ClassDecl The class declaration into which the implicit |
| 6469 | /// copy assignment operator will be added. |
| 6470 | /// |
| 6471 | /// \returns The implicitly-declared copy assignment operator. |
| 6472 | CXXMethodDecl *DeclareImplicitCopyAssignment(CXXRecordDecl *ClassDecl); |
| 6473 | |
| 6474 | /// Defines an implicitly-declared copy assignment operator. |
| 6475 | void DefineImplicitCopyAssignment(SourceLocation CurrentLocation, |
| 6476 | CXXMethodDecl *MethodDecl); |
| 6477 | |
| 6478 | /// Declare the implicit move assignment operator for the given class. |
| 6479 | /// |
| 6480 | /// \param ClassDecl The Class declaration into which the implicit |
| 6481 | /// move assignment operator will be added. |
| 6482 | /// |
| 6483 | /// \returns The implicitly-declared move assignment operator, or NULL if it |
| 6484 | /// wasn't declared. |
| 6485 | CXXMethodDecl *DeclareImplicitMoveAssignment(CXXRecordDecl *ClassDecl); |
| 6486 | |
| 6487 | /// Defines an implicitly-declared move assignment operator. |
| 6488 | void DefineImplicitMoveAssignment(SourceLocation CurrentLocation, |
| 6489 | CXXMethodDecl *MethodDecl); |
| 6490 | |
| 6491 | /// Force the declaration of any implicitly-declared members of this |
| 6492 | /// class. |
| 6493 | void ForceDeclarationOfImplicitMembers(CXXRecordDecl *Class); |
| 6494 | |
| 6495 | /// Check a completed declaration of an implicit special member. |
| 6496 | void CheckImplicitSpecialMemberDeclaration(Scope *S, FunctionDecl *FD); |
| 6497 | |
| 6498 | /// Determine whether the given function is an implicitly-deleted |
| 6499 | /// special member function. |
| 6500 | bool isImplicitlyDeleted(FunctionDecl *FD); |
| 6501 | |
| 6502 | /// Check whether 'this' shows up in the type of a static member |
| 6503 | /// function after the (naturally empty) cv-qualifier-seq would be. |
| 6504 | /// |
| 6505 | /// \returns true if an error occurred. |
| 6506 | bool checkThisInStaticMemberFunctionType(CXXMethodDecl *Method); |
| 6507 | |
| 6508 | /// Whether this' shows up in the exception specification of a static |
| 6509 | /// member function. |
| 6510 | bool checkThisInStaticMemberFunctionExceptionSpec(CXXMethodDecl *Method); |
| 6511 | |
| 6512 | /// Check whether 'this' shows up in the attributes of the given |
| 6513 | /// static member function. |
| 6514 | /// |
| 6515 | /// \returns true if an error occurred. |
| 6516 | bool checkThisInStaticMemberFunctionAttributes(CXXMethodDecl *Method); |
| 6517 | |
| 6518 | /// MaybeBindToTemporary - If the passed in expression has a record type with |
| 6519 | /// a non-trivial destructor, this will return CXXBindTemporaryExpr. Otherwise |
| 6520 | /// it simply returns the passed in expression. |
| 6521 | ExprResult MaybeBindToTemporary(Expr *E); |
| 6522 | |
| 6523 | /// Wrap the expression in a ConstantExpr if it is a potential immediate |
| 6524 | /// invocation. |
| 6525 | ExprResult CheckForImmediateInvocation(ExprResult E, FunctionDecl *Decl); |
| 6526 | |
| 6527 | bool CompleteConstructorCall(CXXConstructorDecl *Constructor, |
| 6528 | QualType DeclInitType, MultiExprArg ArgsPtr, |
| 6529 | SourceLocation Loc, |
| 6530 | SmallVectorImpl<Expr *> &ConvertedArgs, |
| 6531 | bool AllowExplicit = false, |
| 6532 | bool IsListInitialization = false); |
| 6533 | |
| 6534 | ParsedType getInheritingConstructorName(CXXScopeSpec &SS, |
| 6535 | SourceLocation NameLoc, |
| 6536 | IdentifierInfo &Name); |
| 6537 | |
| 6538 | ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, |
| 6539 | Scope *S, CXXScopeSpec &SS, |
| 6540 | bool EnteringContext); |
| 6541 | ParsedType getDestructorName(SourceLocation TildeLoc, |
| 6542 | IdentifierInfo &II, SourceLocation NameLoc, |
| 6543 | Scope *S, CXXScopeSpec &SS, |
| 6544 | ParsedType ObjectType, |
| 6545 | bool EnteringContext); |
| 6546 | |
| 6547 | ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, |
| 6548 | ParsedType ObjectType); |
| 6549 | |
| 6550 | // Checks that reinterpret casts don't have undefined behavior. |
| 6551 | void CheckCompatibleReinterpretCast(QualType SrcType, QualType DestType, |
| 6552 | bool IsDereference, SourceRange Range); |
| 6553 | |
| 6554 | // Checks that the vector type should be initialized from a scalar |
| 6555 | // by splatting the value rather than populating a single element. |
| 6556 | // This is the case for AltiVecVector types as well as with |
| 6557 | // AltiVecPixel and AltiVecBool when -faltivec-src-compat=xl is specified. |
| 6558 | bool ShouldSplatAltivecScalarInCast(const VectorType *VecTy); |
| 6559 | |
| 6560 | // Checks if the -faltivec-src-compat=gcc option is specified. |
| 6561 | // If so, AltiVecVector, AltiVecBool and AltiVecPixel types are |
| 6562 | // treated the same way as they are when trying to initialize |
| 6563 | // these vectors on gcc (an error is emitted). |
| 6564 | bool CheckAltivecInitFromScalar(SourceRange R, QualType VecTy, |
| 6565 | QualType SrcTy); |
| 6566 | |
| 6567 | /// ActOnCXXNamedCast - Parse |
| 6568 | /// {dynamic,static,reinterpret,const,addrspace}_cast's. |
| 6569 | ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, |
| 6570 | tok::TokenKind Kind, |
| 6571 | SourceLocation LAngleBracketLoc, |
| 6572 | Declarator &D, |
| 6573 | SourceLocation RAngleBracketLoc, |
| 6574 | SourceLocation LParenLoc, |
| 6575 | Expr *E, |
| 6576 | SourceLocation RParenLoc); |
| 6577 | |
| 6578 | ExprResult BuildCXXNamedCast(SourceLocation OpLoc, |
| 6579 | tok::TokenKind Kind, |
| 6580 | TypeSourceInfo *Ty, |
| 6581 | Expr *E, |
| 6582 | SourceRange AngleBrackets, |
| 6583 | SourceRange Parens); |
| 6584 | |
| 6585 | ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, |
| 6586 | ExprResult Operand, |
| 6587 | SourceLocation RParenLoc); |
| 6588 | |
| 6589 | ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, |
| 6590 | Expr *Operand, SourceLocation RParenLoc); |
| 6591 | |
| 6592 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
| 6593 | SourceLocation TypeidLoc, |
| 6594 | TypeSourceInfo *Operand, |
| 6595 | SourceLocation RParenLoc); |
| 6596 | ExprResult BuildCXXTypeId(QualType TypeInfoType, |
| 6597 | SourceLocation TypeidLoc, |
| 6598 | Expr *Operand, |
| 6599 | SourceLocation RParenLoc); |
| 6600 | |
| 6601 | /// ActOnCXXTypeid - Parse typeid( something ). |
| 6602 | ExprResult ActOnCXXTypeid(SourceLocation OpLoc, |
| 6603 | SourceLocation LParenLoc, bool isType, |
| 6604 | void *TyOrExpr, |
| 6605 | SourceLocation RParenLoc); |
| 6606 | |
| 6607 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
| 6608 | SourceLocation TypeidLoc, |
| 6609 | TypeSourceInfo *Operand, |
| 6610 | SourceLocation RParenLoc); |
| 6611 | ExprResult BuildCXXUuidof(QualType TypeInfoType, |
| 6612 | SourceLocation TypeidLoc, |
| 6613 | Expr *Operand, |
| 6614 | SourceLocation RParenLoc); |
| 6615 | |
| 6616 | /// ActOnCXXUuidof - Parse __uuidof( something ). |
| 6617 | ExprResult ActOnCXXUuidof(SourceLocation OpLoc, |
| 6618 | SourceLocation LParenLoc, bool isType, |
| 6619 | void *TyOrExpr, |
| 6620 | SourceLocation RParenLoc); |
| 6621 | |
| 6622 | /// Handle a C++1z fold-expression: ( expr op ... op expr ). |
| 6623 | ExprResult ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS, |
| 6624 | tok::TokenKind Operator, |
| 6625 | SourceLocation EllipsisLoc, Expr *RHS, |
| 6626 | SourceLocation RParenLoc); |
| 6627 | ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, |
| 6628 | SourceLocation LParenLoc, Expr *LHS, |
| 6629 | BinaryOperatorKind Operator, |
| 6630 | SourceLocation EllipsisLoc, Expr *RHS, |
| 6631 | SourceLocation RParenLoc, |
| 6632 | std::optional<unsigned> NumExpansions); |
| 6633 | ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 6634 | BinaryOperatorKind Operator); |
| 6635 | |
| 6636 | //// ActOnCXXThis - Parse 'this' pointer. |
| 6637 | ExprResult ActOnCXXThis(SourceLocation loc); |
| 6638 | |
| 6639 | /// Build a CXXThisExpr and mark it referenced in the current context. |
| 6640 | Expr *BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit); |
| 6641 | void MarkThisReferenced(CXXThisExpr *This); |
| 6642 | |
| 6643 | /// Try to retrieve the type of the 'this' pointer. |
| 6644 | /// |
| 6645 | /// \returns The type of 'this', if possible. Otherwise, returns a NULL type. |
| 6646 | QualType getCurrentThisType(); |
| 6647 | |
| 6648 | /// When non-NULL, the C++ 'this' expression is allowed despite the |
| 6649 | /// current context not being a non-static member function. In such cases, |
| 6650 | /// this provides the type used for 'this'. |
| 6651 | QualType CXXThisTypeOverride; |
| 6652 | |
| 6653 | /// RAII object used to temporarily allow the C++ 'this' expression |
| 6654 | /// to be used, with the given qualifiers on the current class type. |
| 6655 | class CXXThisScopeRAII { |
| 6656 | Sema &S; |
| 6657 | QualType OldCXXThisTypeOverride; |
| 6658 | bool Enabled; |
| 6659 | |
| 6660 | public: |
| 6661 | /// Introduce a new scope where 'this' may be allowed (when enabled), |
| 6662 | /// using the given declaration (which is either a class template or a |
| 6663 | /// class) along with the given qualifiers. |
| 6664 | /// along with the qualifiers placed on '*this'. |
| 6665 | CXXThisScopeRAII(Sema &S, Decl *ContextDecl, Qualifiers CXXThisTypeQuals, |
| 6666 | bool Enabled = true); |
| 6667 | |
| 6668 | ~CXXThisScopeRAII(); |
| 6669 | }; |
| 6670 | |
| 6671 | /// Make sure the value of 'this' is actually available in the current |
| 6672 | /// context, if it is a potentially evaluated context. |
| 6673 | /// |
| 6674 | /// \param Loc The location at which the capture of 'this' occurs. |
| 6675 | /// |
| 6676 | /// \param Explicit Whether 'this' is explicitly captured in a lambda |
| 6677 | /// capture list. |
| 6678 | /// |
| 6679 | /// \param FunctionScopeIndexToStopAt If non-null, it points to the index |
| 6680 | /// of the FunctionScopeInfo stack beyond which we do not attempt to capture. |
| 6681 | /// This is useful when enclosing lambdas must speculatively capture |
| 6682 | /// 'this' that may or may not be used in certain specializations of |
| 6683 | /// a nested generic lambda (depending on whether the name resolves to |
| 6684 | /// a non-static member function or a static function). |
| 6685 | /// \return returns 'true' if failed, 'false' if success. |
| 6686 | bool CheckCXXThisCapture(SourceLocation Loc, bool Explicit = false, |
| 6687 | bool BuildAndDiagnose = true, |
| 6688 | const unsigned *const FunctionScopeIndexToStopAt = nullptr, |
| 6689 | bool ByCopy = false); |
| 6690 | |
| 6691 | /// Determine whether the given type is the type of *this that is used |
| 6692 | /// outside of the body of a member function for a type that is currently |
| 6693 | /// being defined. |
| 6694 | bool isThisOutsideMemberFunctionBody(QualType BaseType); |
| 6695 | |
| 6696 | /// ActOnCXXBoolLiteral - Parse {true,false} literals. |
| 6697 | ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
| 6698 | |
| 6699 | |
| 6700 | /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. |
| 6701 | ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); |
| 6702 | |
| 6703 | ExprResult |
| 6704 | ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs, |
| 6705 | SourceLocation AtLoc, SourceLocation RParen); |
| 6706 | |
| 6707 | /// ActOnCXXNullPtrLiteral - Parse 'nullptr'. |
| 6708 | ExprResult ActOnCXXNullPtrLiteral(SourceLocation Loc); |
| 6709 | |
| 6710 | //// ActOnCXXThrow - Parse throw expressions. |
| 6711 | ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr); |
| 6712 | ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, |
| 6713 | bool IsThrownVarInScope); |
| 6714 | bool CheckCXXThrowOperand(SourceLocation ThrowLoc, QualType ThrowTy, Expr *E); |
| 6715 | |
| 6716 | /// ActOnCXXTypeConstructExpr - Parse construction of a specified type. |
| 6717 | /// Can be interpreted either as function-style casting ("int(x)") |
| 6718 | /// or class type construction ("ClassType(x,y,z)") |
| 6719 | /// or creation of a value-initialized type ("int()"). |
| 6720 | ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, |
| 6721 | SourceLocation LParenOrBraceLoc, |
| 6722 | MultiExprArg Exprs, |
| 6723 | SourceLocation RParenOrBraceLoc, |
| 6724 | bool ListInitialization); |
| 6725 | |
| 6726 | ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, |
| 6727 | SourceLocation LParenLoc, |
| 6728 | MultiExprArg Exprs, |
| 6729 | SourceLocation RParenLoc, |
| 6730 | bool ListInitialization); |
| 6731 | |
| 6732 | /// ActOnCXXNew - Parsed a C++ 'new' expression. |
| 6733 | ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, |
| 6734 | SourceLocation PlacementLParen, |
| 6735 | MultiExprArg PlacementArgs, |
| 6736 | SourceLocation PlacementRParen, |
| 6737 | SourceRange TypeIdParens, Declarator &D, |
| 6738 | Expr *Initializer); |
| 6739 | ExprResult |
| 6740 | BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, |
| 6741 | MultiExprArg PlacementArgs, SourceLocation PlacementRParen, |
| 6742 | SourceRange TypeIdParens, QualType AllocType, |
| 6743 | TypeSourceInfo *AllocTypeInfo, std::optional<Expr *> ArraySize, |
| 6744 | SourceRange DirectInitRange, Expr *Initializer); |
| 6745 | |
| 6746 | /// Determine whether \p FD is an aligned allocation or deallocation |
| 6747 | /// function that is unavailable. |
| 6748 | bool isUnavailableAlignedAllocationFunction(const FunctionDecl &FD) const; |
| 6749 | |
| 6750 | /// Produce diagnostics if \p FD is an aligned allocation or deallocation |
| 6751 | /// function that is unavailable. |
| 6752 | void diagnoseUnavailableAlignedAllocation(const FunctionDecl &FD, |
| 6753 | SourceLocation Loc); |
| 6754 | |
| 6755 | bool CheckAllocatedType(QualType AllocType, SourceLocation Loc, |
| 6756 | SourceRange R); |
| 6757 | |
| 6758 | /// The scope in which to find allocation functions. |
| 6759 | enum AllocationFunctionScope { |
| 6760 | /// Only look for allocation functions in the global scope. |
| 6761 | AFS_Global, |
| 6762 | /// Only look for allocation functions in the scope of the |
| 6763 | /// allocated class. |
| 6764 | AFS_Class, |
| 6765 | /// Look for allocation functions in both the global scope |
| 6766 | /// and in the scope of the allocated class. |
| 6767 | AFS_Both |
| 6768 | }; |
| 6769 | |
| 6770 | /// Finds the overloads of operator new and delete that are appropriate |
| 6771 | /// for the allocation. |
| 6772 | bool FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range, |
| 6773 | AllocationFunctionScope NewScope, |
| 6774 | AllocationFunctionScope DeleteScope, |
| 6775 | QualType AllocType, bool IsArray, |
| 6776 | bool &PassAlignment, MultiExprArg PlaceArgs, |
| 6777 | FunctionDecl *&OperatorNew, |
| 6778 | FunctionDecl *&OperatorDelete, |
| 6779 | bool Diagnose = true); |
| 6780 | void DeclareGlobalNewDelete(); |
| 6781 | void DeclareGlobalAllocationFunction(DeclarationName Name, QualType Return, |
| 6782 | ArrayRef<QualType> Params); |
| 6783 | |
| 6784 | bool FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD, |
| 6785 | DeclarationName Name, FunctionDecl *&Operator, |
| 6786 | bool Diagnose = true, bool WantSize = false, |
| 6787 | bool WantAligned = false); |
| 6788 | FunctionDecl *FindUsualDeallocationFunction(SourceLocation StartLoc, |
| 6789 | bool CanProvideSize, |
| 6790 | bool Overaligned, |
| 6791 | DeclarationName Name); |
| 6792 | FunctionDecl *FindDeallocationFunctionForDestructor(SourceLocation StartLoc, |
| 6793 | CXXRecordDecl *RD); |
| 6794 | |
| 6795 | /// ActOnCXXDelete - Parsed a C++ 'delete' expression |
| 6796 | ExprResult ActOnCXXDelete(SourceLocation StartLoc, |
| 6797 | bool UseGlobal, bool ArrayForm, |
| 6798 | Expr *Operand); |
| 6799 | void CheckVirtualDtorCall(CXXDestructorDecl *dtor, SourceLocation Loc, |
| 6800 | bool IsDelete, bool CallCanBeVirtual, |
| 6801 | bool WarnOnNonAbstractTypes, |
| 6802 | SourceLocation DtorLoc); |
| 6803 | |
| 6804 | ExprResult ActOnNoexceptExpr(SourceLocation KeyLoc, SourceLocation LParen, |
| 6805 | Expr *Operand, SourceLocation RParen); |
| 6806 | ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, |
| 6807 | SourceLocation RParen); |
| 6808 | |
| 6809 | /// Parsed one of the type trait support pseudo-functions. |
| 6810 | ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
| 6811 | ArrayRef<ParsedType> Args, |
| 6812 | SourceLocation RParenLoc); |
| 6813 | ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, |
| 6814 | ArrayRef<TypeSourceInfo *> Args, |
| 6815 | SourceLocation RParenLoc); |
| 6816 | |
| 6817 | /// ActOnArrayTypeTrait - Parsed one of the binary type trait support |
| 6818 | /// pseudo-functions. |
| 6819 | ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, |
| 6820 | SourceLocation KWLoc, |
| 6821 | ParsedType LhsTy, |
| 6822 | Expr *DimExpr, |
| 6823 | SourceLocation RParen); |
| 6824 | |
| 6825 | ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, |
| 6826 | SourceLocation KWLoc, |
| 6827 | TypeSourceInfo *TSInfo, |
| 6828 | Expr *DimExpr, |
| 6829 | SourceLocation RParen); |
| 6830 | |
| 6831 | /// ActOnExpressionTrait - Parsed one of the unary type trait support |
| 6832 | /// pseudo-functions. |
| 6833 | ExprResult ActOnExpressionTrait(ExpressionTrait OET, |
| 6834 | SourceLocation KWLoc, |
| 6835 | Expr *Queried, |
| 6836 | SourceLocation RParen); |
| 6837 | |
| 6838 | ExprResult BuildExpressionTrait(ExpressionTrait OET, |
| 6839 | SourceLocation KWLoc, |
| 6840 | Expr *Queried, |
| 6841 | SourceLocation RParen); |
| 6842 | |
| 6843 | ExprResult ActOnStartCXXMemberReference(Scope *S, |
| 6844 | Expr *Base, |
| 6845 | SourceLocation OpLoc, |
| 6846 | tok::TokenKind OpKind, |
| 6847 | ParsedType &ObjectType, |
| 6848 | bool &MayBePseudoDestructor); |
| 6849 | |
| 6850 | ExprResult BuildPseudoDestructorExpr(Expr *Base, |
| 6851 | SourceLocation OpLoc, |
| 6852 | tok::TokenKind OpKind, |
| 6853 | const CXXScopeSpec &SS, |
| 6854 | TypeSourceInfo *ScopeType, |
| 6855 | SourceLocation CCLoc, |
| 6856 | SourceLocation TildeLoc, |
| 6857 | PseudoDestructorTypeStorage DestroyedType); |
| 6858 | |
| 6859 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
| 6860 | SourceLocation OpLoc, |
| 6861 | tok::TokenKind OpKind, |
| 6862 | CXXScopeSpec &SS, |
| 6863 | UnqualifiedId &FirstTypeName, |
| 6864 | SourceLocation CCLoc, |
| 6865 | SourceLocation TildeLoc, |
| 6866 | UnqualifiedId &SecondTypeName); |
| 6867 | |
| 6868 | ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, |
| 6869 | SourceLocation OpLoc, |
| 6870 | tok::TokenKind OpKind, |
| 6871 | SourceLocation TildeLoc, |
| 6872 | const DeclSpec& DS); |
| 6873 | |
| 6874 | /// MaybeCreateExprWithCleanups - If the current full-expression |
| 6875 | /// requires any cleanups, surround it with a ExprWithCleanups node. |
| 6876 | /// Otherwise, just returns the passed-in expression. |
| 6877 | Expr *MaybeCreateExprWithCleanups(Expr *SubExpr); |
| 6878 | Stmt *MaybeCreateStmtWithCleanups(Stmt *SubStmt); |
| 6879 | ExprResult MaybeCreateExprWithCleanups(ExprResult SubExpr); |
| 6880 | |
| 6881 | MaterializeTemporaryExpr * |
| 6882 | CreateMaterializeTemporaryExpr(QualType T, Expr *Temporary, |
| 6883 | bool BoundToLvalueReference); |
| 6884 | |
| 6885 | ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue) { |
| 6886 | return ActOnFinishFullExpr( |
| 6887 | Expr, Expr ? Expr->getExprLoc() : SourceLocation(), DiscardedValue); |
| 6888 | } |
| 6889 | ExprResult ActOnFinishFullExpr(Expr *Expr, SourceLocation CC, |
| 6890 | bool DiscardedValue, bool IsConstexpr = false, |
| 6891 | bool IsTemplateArgument = false); |
| 6892 | StmtResult ActOnFinishFullStmt(Stmt *Stmt); |
| 6893 | |
| 6894 | // Marks SS invalid if it represents an incomplete type. |
| 6895 | bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC); |
| 6896 | // Complete an enum decl, maybe without a scope spec. |
| 6897 | bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L, |
| 6898 | CXXScopeSpec *SS = nullptr); |
| 6899 | |
| 6900 | DeclContext *computeDeclContext(QualType T); |
| 6901 | DeclContext *computeDeclContext(const CXXScopeSpec &SS, |
| 6902 | bool EnteringContext = false); |
| 6903 | bool isDependentScopeSpecifier(const CXXScopeSpec &SS); |
| 6904 | CXXRecordDecl *getCurrentInstantiationOf(NestedNameSpecifier *NNS); |
| 6905 | |
| 6906 | /// The parser has parsed a global nested-name-specifier '::'. |
| 6907 | /// |
| 6908 | /// \param CCLoc The location of the '::'. |
| 6909 | /// |
| 6910 | /// \param SS The nested-name-specifier, which will be updated in-place |
| 6911 | /// to reflect the parsed nested-name-specifier. |
| 6912 | /// |
| 6913 | /// \returns true if an error occurred, false otherwise. |
| 6914 | bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS); |
| 6915 | |
| 6916 | /// The parser has parsed a '__super' nested-name-specifier. |
| 6917 | /// |
| 6918 | /// \param SuperLoc The location of the '__super' keyword. |
| 6919 | /// |
| 6920 | /// \param ColonColonLoc The location of the '::'. |
| 6921 | /// |
| 6922 | /// \param SS The nested-name-specifier, which will be updated in-place |
| 6923 | /// to reflect the parsed nested-name-specifier. |
| 6924 | /// |
| 6925 | /// \returns true if an error occurred, false otherwise. |
| 6926 | bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, |
| 6927 | SourceLocation ColonColonLoc, CXXScopeSpec &SS); |
| 6928 | |
| 6929 | bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, |
| 6930 | bool *CanCorrect = nullptr); |
| 6931 | NamedDecl *FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS); |
| 6932 | |
| 6933 | /// Keeps information about an identifier in a nested-name-spec. |
| 6934 | /// |
| 6935 | struct NestedNameSpecInfo { |
| 6936 | /// The type of the object, if we're parsing nested-name-specifier in |
| 6937 | /// a member access expression. |
| 6938 | ParsedType ObjectType; |
| 6939 | |
| 6940 | /// The identifier preceding the '::'. |
| 6941 | IdentifierInfo *Identifier; |
| 6942 | |
| 6943 | /// The location of the identifier. |
| 6944 | SourceLocation IdentifierLoc; |
| 6945 | |
| 6946 | /// The location of the '::'. |
| 6947 | SourceLocation CCLoc; |
| 6948 | |
| 6949 | /// Creates info object for the most typical case. |
| 6950 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
| 6951 | SourceLocation ColonColonLoc, ParsedType ObjectType = ParsedType()) |
| 6952 | : ObjectType(ObjectType), Identifier(II), IdentifierLoc(IdLoc), |
| 6953 | CCLoc(ColonColonLoc) { |
| 6954 | } |
| 6955 | |
| 6956 | NestedNameSpecInfo(IdentifierInfo *II, SourceLocation IdLoc, |
| 6957 | SourceLocation ColonColonLoc, QualType ObjectType) |
| 6958 | : ObjectType(ParsedType::make(ObjectType)), Identifier(II), |
| 6959 | IdentifierLoc(IdLoc), CCLoc(ColonColonLoc) { |
| 6960 | } |
| 6961 | }; |
| 6962 | |
| 6963 | bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, |
| 6964 | NestedNameSpecInfo &IdInfo); |
| 6965 | |
| 6966 | bool BuildCXXNestedNameSpecifier(Scope *S, |
| 6967 | NestedNameSpecInfo &IdInfo, |
| 6968 | bool EnteringContext, |
| 6969 | CXXScopeSpec &SS, |
| 6970 | NamedDecl *ScopeLookupResult, |
| 6971 | bool ErrorRecoveryLookup, |
| 6972 | bool *IsCorrectedToColon = nullptr, |
| 6973 | bool OnlyNamespace = false); |
| 6974 | |
| 6975 | /// The parser has parsed a nested-name-specifier 'identifier::'. |
| 6976 | /// |
| 6977 | /// \param S The scope in which this nested-name-specifier occurs. |
| 6978 | /// |
| 6979 | /// \param IdInfo Parser information about an identifier in the |
| 6980 | /// nested-name-spec. |
| 6981 | /// |
| 6982 | /// \param EnteringContext Whether we're entering the context nominated by |
| 6983 | /// this nested-name-specifier. |
| 6984 | /// |
| 6985 | /// \param SS The nested-name-specifier, which is both an input |
| 6986 | /// parameter (the nested-name-specifier before this type) and an |
| 6987 | /// output parameter (containing the full nested-name-specifier, |
| 6988 | /// including this new type). |
| 6989 | /// |
| 6990 | /// \param IsCorrectedToColon If not null, suggestions to replace '::' -> ':' |
| 6991 | /// are allowed. The bool value pointed by this parameter is set to 'true' |
| 6992 | /// if the identifier is treated as if it was followed by ':', not '::'. |
| 6993 | /// |
| 6994 | /// \param OnlyNamespace If true, only considers namespaces in lookup. |
| 6995 | /// |
| 6996 | /// \returns true if an error occurred, false otherwise. |
| 6997 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
| 6998 | NestedNameSpecInfo &IdInfo, |
| 6999 | bool EnteringContext, |
| 7000 | CXXScopeSpec &SS, |
| 7001 | bool *IsCorrectedToColon = nullptr, |
| 7002 | bool OnlyNamespace = false); |
| 7003 | |
| 7004 | ExprResult ActOnDecltypeExpression(Expr *E); |
| 7005 | |
| 7006 | bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, |
| 7007 | const DeclSpec &DS, |
| 7008 | SourceLocation ColonColonLoc); |
| 7009 | |
| 7010 | bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, |
| 7011 | NestedNameSpecInfo &IdInfo, |
| 7012 | bool EnteringContext); |
| 7013 | |
| 7014 | /// The parser has parsed a nested-name-specifier |
| 7015 | /// 'template[opt] template-name < template-args >::'. |
| 7016 | /// |
| 7017 | /// \param S The scope in which this nested-name-specifier occurs. |
| 7018 | /// |
| 7019 | /// \param SS The nested-name-specifier, which is both an input |
| 7020 | /// parameter (the nested-name-specifier before this type) and an |
| 7021 | /// output parameter (containing the full nested-name-specifier, |
| 7022 | /// including this new type). |
| 7023 | /// |
| 7024 | /// \param TemplateKWLoc the location of the 'template' keyword, if any. |
| 7025 | /// \param TemplateName the template name. |
| 7026 | /// \param TemplateNameLoc The location of the template name. |
| 7027 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
| 7028 | /// \param TemplateArgs The template arguments. |
| 7029 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
| 7030 | /// \param CCLoc The location of the '::'. |
| 7031 | /// |
| 7032 | /// \param EnteringContext Whether we're entering the context of the |
| 7033 | /// nested-name-specifier. |
| 7034 | /// |
| 7035 | /// |
| 7036 | /// \returns true if an error occurred, false otherwise. |
| 7037 | bool ActOnCXXNestedNameSpecifier(Scope *S, |
| 7038 | CXXScopeSpec &SS, |
| 7039 | SourceLocation TemplateKWLoc, |
| 7040 | TemplateTy TemplateName, |
| 7041 | SourceLocation TemplateNameLoc, |
| 7042 | SourceLocation LAngleLoc, |
| 7043 | ASTTemplateArgsPtr TemplateArgs, |
| 7044 | SourceLocation RAngleLoc, |
| 7045 | SourceLocation CCLoc, |
| 7046 | bool EnteringContext); |
| 7047 | |
| 7048 | /// Given a C++ nested-name-specifier, produce an annotation value |
| 7049 | /// that the parser can use later to reconstruct the given |
| 7050 | /// nested-name-specifier. |
| 7051 | /// |
| 7052 | /// \param SS A nested-name-specifier. |
| 7053 | /// |
| 7054 | /// \returns A pointer containing all of the information in the |
| 7055 | /// nested-name-specifier \p SS. |
| 7056 | void *SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS); |
| 7057 | |
| 7058 | /// Given an annotation pointer for a nested-name-specifier, restore |
| 7059 | /// the nested-name-specifier structure. |
| 7060 | /// |
| 7061 | /// \param Annotation The annotation pointer, produced by |
| 7062 | /// \c SaveNestedNameSpecifierAnnotation(). |
| 7063 | /// |
| 7064 | /// \param AnnotationRange The source range corresponding to the annotation. |
| 7065 | /// |
| 7066 | /// \param SS The nested-name-specifier that will be updated with the contents |
| 7067 | /// of the annotation pointer. |
| 7068 | void RestoreNestedNameSpecifierAnnotation(void *Annotation, |
| 7069 | SourceRange AnnotationRange, |
| 7070 | CXXScopeSpec &SS); |
| 7071 | |
| 7072 | bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
| 7073 | |
| 7074 | /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global |
| 7075 | /// scope or nested-name-specifier) is parsed, part of a declarator-id. |
| 7076 | /// After this method is called, according to [C++ 3.4.3p3], names should be |
| 7077 | /// looked up in the declarator-id's scope, until the declarator is parsed and |
| 7078 | /// ActOnCXXExitDeclaratorScope is called. |
| 7079 | /// The 'SS' should be a non-empty valid CXXScopeSpec. |
| 7080 | bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS); |
| 7081 | |
| 7082 | /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously |
| 7083 | /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same |
| 7084 | /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well. |
| 7085 | /// Used to indicate that names should revert to being looked up in the |
| 7086 | /// defining scope. |
| 7087 | void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS); |
| 7088 | |
| 7089 | /// ActOnCXXEnterDeclInitializer - Invoked when we are about to parse an |
| 7090 | /// initializer for the declaration 'Dcl'. |
| 7091 | /// After this method is called, according to [C++ 3.4.1p13], if 'Dcl' is a |
| 7092 | /// static data member of class X, names should be looked up in the scope of |
| 7093 | /// class X. |
| 7094 | void ActOnCXXEnterDeclInitializer(Scope *S, Decl *Dcl); |
| 7095 | |
| 7096 | /// ActOnCXXExitDeclInitializer - Invoked after we are finished parsing an |
| 7097 | /// initializer for the declaration 'Dcl'. |
| 7098 | void ActOnCXXExitDeclInitializer(Scope *S, Decl *Dcl); |
| 7099 | |
| 7100 | /// Create a new lambda closure type. |
| 7101 | CXXRecordDecl *createLambdaClosureType(SourceRange IntroducerRange, |
| 7102 | TypeSourceInfo *Info, |
| 7103 | unsigned LambdaDependencyKind, |
| 7104 | LambdaCaptureDefault CaptureDefault); |
| 7105 | |
| 7106 | /// Start the definition of a lambda expression. |
| 7107 | CXXMethodDecl * |
| 7108 | startLambdaDefinition(CXXRecordDecl *Class, SourceRange IntroducerRange, |
| 7109 | TypeSourceInfo *MethodType, SourceLocation EndLoc, |
| 7110 | ArrayRef<ParmVarDecl *> Params, |
| 7111 | ConstexprSpecKind ConstexprKind, StorageClass SC, |
| 7112 | Expr *TrailingRequiresClause); |
| 7113 | |
| 7114 | /// Number lambda for linkage purposes if necessary. |
| 7115 | void handleLambdaNumbering(CXXRecordDecl *Class, CXXMethodDecl *Method, |
| 7116 | std::optional<CXXRecordDecl::LambdaNumbering> |
| 7117 | NumberingOverride = std::nullopt); |
| 7118 | |
| 7119 | /// Endow the lambda scope info with the relevant properties. |
| 7120 | void buildLambdaScope(sema::LambdaScopeInfo *LSI, CXXMethodDecl *CallOperator, |
| 7121 | SourceRange IntroducerRange, |
| 7122 | LambdaCaptureDefault CaptureDefault, |
| 7123 | SourceLocation CaptureDefaultLoc, bool ExplicitParams, |
| 7124 | bool Mutable); |
| 7125 | |
| 7126 | CXXMethodDecl *CreateLambdaCallOperator(SourceRange IntroducerRange, |
| 7127 | CXXRecordDecl *Class); |
| 7128 | void CompleteLambdaCallOperator( |
| 7129 | CXXMethodDecl *Method, SourceLocation LambdaLoc, |
| 7130 | SourceLocation CallOperatorLoc, Expr *TrailingRequiresClause, |
| 7131 | TypeSourceInfo *MethodTyInfo, ConstexprSpecKind ConstexprKind, |
| 7132 | StorageClass SC, ArrayRef<ParmVarDecl *> Params, |
| 7133 | bool HasExplicitResultType); |
| 7134 | |
| 7135 | /// Perform initialization analysis of the init-capture and perform |
| 7136 | /// any implicit conversions such as an lvalue-to-rvalue conversion if |
| 7137 | /// not being used to initialize a reference. |
| 7138 | ParsedType actOnLambdaInitCaptureInitialization( |
| 7139 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
| 7140 | IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init) { |
| 7141 | return ParsedType::make(buildLambdaInitCaptureInitialization( |
| 7142 | Loc, ByRef, EllipsisLoc, std::nullopt, Id, |
| 7143 | InitKind != LambdaCaptureInitKind::CopyInit, Init)); |
| 7144 | } |
| 7145 | QualType buildLambdaInitCaptureInitialization( |
| 7146 | SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, |
| 7147 | std::optional<unsigned> NumExpansions, IdentifierInfo *Id, |
| 7148 | bool DirectInit, Expr *&Init); |
| 7149 | |
| 7150 | /// Create a dummy variable within the declcontext of the lambda's |
| 7151 | /// call operator, for name lookup purposes for a lambda init capture. |
| 7152 | /// |
| 7153 | /// CodeGen handles emission of lambda captures, ignoring these dummy |
| 7154 | /// variables appropriately. |
| 7155 | VarDecl *createLambdaInitCaptureVarDecl( |
| 7156 | SourceLocation Loc, QualType InitCaptureType, SourceLocation EllipsisLoc, |
| 7157 | IdentifierInfo *Id, unsigned InitStyle, Expr *Init, DeclContext *DeclCtx); |
| 7158 | |
| 7159 | /// Add an init-capture to a lambda scope. |
| 7160 | void addInitCapture(sema::LambdaScopeInfo *LSI, VarDecl *Var, |
| 7161 | bool isReferenceType); |
| 7162 | |
| 7163 | /// Note that we have finished the explicit captures for the |
| 7164 | /// given lambda. |
| 7165 | void finishLambdaExplicitCaptures(sema::LambdaScopeInfo *LSI); |
| 7166 | |
| 7167 | /// Deduce a block or lambda's return type based on the return |
| 7168 | /// statements present in the body. |
| 7169 | void deduceClosureReturnType(sema::CapturingScopeInfo &CSI); |
| 7170 | |
| 7171 | /// Once the Lambdas capture are known, we can start to create the closure, |
| 7172 | /// call operator method, and keep track of the captures. |
| 7173 | /// We do the capture lookup here, but they are not actually captured until |
| 7174 | /// after we know what the qualifiers of the call operator are. |
| 7175 | void ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro, |
| 7176 | Scope *CurContext); |
| 7177 | |
| 7178 | /// This is called after parsing the explicit template parameter list |
| 7179 | /// on a lambda (if it exists) in C++2a. |
| 7180 | void ActOnLambdaExplicitTemplateParameterList(LambdaIntroducer &Intro, |
| 7181 | SourceLocation LAngleLoc, |
| 7182 | ArrayRef<NamedDecl *> TParams, |
| 7183 | SourceLocation RAngleLoc, |
| 7184 | ExprResult RequiresClause); |
| 7185 | |
| 7186 | void ActOnLambdaClosureQualifiers(LambdaIntroducer &Intro, |
| 7187 | SourceLocation MutableLoc); |
| 7188 | |
| 7189 | void ActOnLambdaClosureParameters( |
| 7190 | Scope *LambdaScope, |
| 7191 | MutableArrayRef<DeclaratorChunk::ParamInfo> ParamInfo); |
| 7192 | |
| 7193 | /// ActOnStartOfLambdaDefinition - This is called just before we start |
| 7194 | /// parsing the body of a lambda; it analyzes the explicit captures and |
| 7195 | /// arguments, and sets up various data-structures for the body of the |
| 7196 | /// lambda. |
| 7197 | void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, |
| 7198 | Declarator &ParamInfo, const DeclSpec &DS); |
| 7199 | |
| 7200 | /// ActOnLambdaError - If there is an error parsing a lambda, this callback |
| 7201 | /// is invoked to pop the information about the lambda. |
| 7202 | void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, |
| 7203 | bool IsInstantiation = false); |
| 7204 | |
| 7205 | /// ActOnLambdaExpr - This is called when the body of a lambda expression |
| 7206 | /// was successfully completed. |
| 7207 | ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, |
| 7208 | Scope *CurScope); |
| 7209 | |
| 7210 | /// Does copying/destroying the captured variable have side effects? |
| 7211 | bool CaptureHasSideEffects(const sema::Capture &From); |
| 7212 | |
| 7213 | /// Diagnose if an explicit lambda capture is unused. Returns true if a |
| 7214 | /// diagnostic is emitted. |
| 7215 | bool DiagnoseUnusedLambdaCapture(SourceRange CaptureRange, |
| 7216 | const sema::Capture &From); |
| 7217 | |
| 7218 | /// Build a FieldDecl suitable to hold the given capture. |
| 7219 | FieldDecl *BuildCaptureField(RecordDecl *RD, const sema::Capture &Capture); |
| 7220 | |
| 7221 | /// Initialize the given capture with a suitable expression. |
| 7222 | ExprResult BuildCaptureInit(const sema::Capture &Capture, |
| 7223 | SourceLocation ImplicitCaptureLoc, |
| 7224 | bool IsOpenMPMapping = false); |
| 7225 | |
| 7226 | /// Complete a lambda-expression having processed and attached the |
| 7227 | /// lambda body. |
| 7228 | ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, |
| 7229 | sema::LambdaScopeInfo *LSI); |
| 7230 | |
| 7231 | /// Get the return type to use for a lambda's conversion function(s) to |
| 7232 | /// function pointer type, given the type of the call operator. |
| 7233 | QualType |
| 7234 | getLambdaConversionFunctionResultType(const FunctionProtoType *CallOpType, |
| 7235 | CallingConv CC); |
| 7236 | |
| 7237 | /// Define the "body" of the conversion from a lambda object to a |
| 7238 | /// function pointer. |
| 7239 | /// |
| 7240 | /// This routine doesn't actually define a sensible body; rather, it fills |
| 7241 | /// in the initialization expression needed to copy the lambda object into |
| 7242 | /// the block, and IR generation actually generates the real body of the |
| 7243 | /// block pointer conversion. |
| 7244 | void DefineImplicitLambdaToFunctionPointerConversion( |
| 7245 | SourceLocation CurrentLoc, CXXConversionDecl *Conv); |
| 7246 | |
| 7247 | /// Define the "body" of the conversion from a lambda object to a |
| 7248 | /// block pointer. |
| 7249 | /// |
| 7250 | /// This routine doesn't actually define a sensible body; rather, it fills |
| 7251 | /// in the initialization expression needed to copy the lambda object into |
| 7252 | /// the block, and IR generation actually generates the real body of the |
| 7253 | /// block pointer conversion. |
| 7254 | void DefineImplicitLambdaToBlockPointerConversion(SourceLocation CurrentLoc, |
| 7255 | CXXConversionDecl *Conv); |
| 7256 | |
| 7257 | ExprResult BuildBlockForLambdaConversion(SourceLocation CurrentLocation, |
| 7258 | SourceLocation ConvLocation, |
| 7259 | CXXConversionDecl *Conv, |
| 7260 | Expr *Src); |
| 7261 | |
| 7262 | /// Check whether the given expression is a valid constraint expression. |
| 7263 | /// A diagnostic is emitted if it is not, false is returned, and |
| 7264 | /// PossibleNonPrimary will be set to true if the failure might be due to a |
| 7265 | /// non-primary expression being used as an atomic constraint. |
| 7266 | bool CheckConstraintExpression(const Expr *CE, Token NextToken = Token(), |
| 7267 | bool *PossibleNonPrimary = nullptr, |
| 7268 | bool IsTrailingRequiresClause = false); |
| 7269 | |
| 7270 | private: |
| 7271 | /// Caches pairs of template-like decls whose associated constraints were |
| 7272 | /// checked for subsumption and whether or not the first's constraints did in |
| 7273 | /// fact subsume the second's. |
| 7274 | llvm::DenseMap<std::pair<NamedDecl *, NamedDecl *>, bool> SubsumptionCache; |
| 7275 | /// Caches the normalized associated constraints of declarations (concepts or |
| 7276 | /// constrained declarations). If an error occurred while normalizing the |
| 7277 | /// associated constraints of the template or concept, nullptr will be cached |
| 7278 | /// here. |
| 7279 | llvm::DenseMap<NamedDecl *, NormalizedConstraint *> |
| 7280 | NormalizationCache; |
| 7281 | |
| 7282 | llvm::ContextualFoldingSet<ConstraintSatisfaction, const ASTContext &> |
| 7283 | SatisfactionCache; |
| 7284 | |
| 7285 | /// Introduce the instantiated function parameters into the local |
| 7286 | /// instantiation scope, and set the parameter names to those used |
| 7287 | /// in the template. |
| 7288 | bool addInstantiatedParametersToScope( |
| 7289 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
| 7290 | LocalInstantiationScope &Scope, |
| 7291 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 7292 | |
| 7293 | /// Introduce the instantiated captures of the lambda into the local |
| 7294 | /// instantiation scope. |
| 7295 | bool addInstantiatedCapturesToScope( |
| 7296 | FunctionDecl *Function, const FunctionDecl *PatternDecl, |
| 7297 | LocalInstantiationScope &Scope, |
| 7298 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 7299 | |
| 7300 | /// used by SetupConstraintCheckingTemplateArgumentsAndScope to recursively(in |
| 7301 | /// the case of lambdas) set up the LocalInstantiationScope of the current |
| 7302 | /// function. |
| 7303 | bool SetupConstraintScope( |
| 7304 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
| 7305 | MultiLevelTemplateArgumentList MLTAL, LocalInstantiationScope &Scope); |
| 7306 | |
| 7307 | /// Used during constraint checking, sets up the constraint template argument |
| 7308 | /// lists, and calls SetupConstraintScope to set up the |
| 7309 | /// LocalInstantiationScope to have the proper set of ParVarDecls configured. |
| 7310 | std::optional<MultiLevelTemplateArgumentList> |
| 7311 | SetupConstraintCheckingTemplateArgumentsAndScope( |
| 7312 | FunctionDecl *FD, std::optional<ArrayRef<TemplateArgument>> TemplateArgs, |
| 7313 | LocalInstantiationScope &Scope); |
| 7314 | |
| 7315 | private: |
| 7316 | // The current stack of constraint satisfactions, so we can exit-early. |
| 7317 | using SatisfactionStackEntryTy = |
| 7318 | std::pair<const NamedDecl *, llvm::FoldingSetNodeID>; |
| 7319 | llvm::SmallVector<SatisfactionStackEntryTy, 10> |
| 7320 | SatisfactionStack; |
| 7321 | |
| 7322 | public: |
| 7323 | void PushSatisfactionStackEntry(const NamedDecl *D, |
| 7324 | const llvm::FoldingSetNodeID &ID) { |
| 7325 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
| 7326 | SatisfactionStack.emplace_back(Can, ID); |
| 7327 | } |
| 7328 | |
| 7329 | void PopSatisfactionStackEntry() { SatisfactionStack.pop_back(); } |
| 7330 | |
| 7331 | bool SatisfactionStackContains(const NamedDecl *D, |
| 7332 | const llvm::FoldingSetNodeID &ID) const { |
| 7333 | const NamedDecl *Can = cast<NamedDecl>(D->getCanonicalDecl()); |
| 7334 | return llvm::find(SatisfactionStack, |
| 7335 | SatisfactionStackEntryTy{Can, ID}) != |
| 7336 | SatisfactionStack.end(); |
| 7337 | } |
| 7338 | |
| 7339 | // Resets the current SatisfactionStack for cases where we are instantiating |
| 7340 | // constraints as a 'side effect' of normal instantiation in a way that is not |
| 7341 | // indicative of recursive definition. |
| 7342 | class SatisfactionStackResetRAII { |
| 7343 | llvm::SmallVector<SatisfactionStackEntryTy, 10> |
| 7344 | BackupSatisfactionStack; |
| 7345 | Sema &SemaRef; |
| 7346 | |
| 7347 | public: |
| 7348 | SatisfactionStackResetRAII(Sema &S) : SemaRef(S) { |
| 7349 | SemaRef.SwapSatisfactionStack(BackupSatisfactionStack); |
| 7350 | } |
| 7351 | |
| 7352 | ~SatisfactionStackResetRAII() { |
| 7353 | SemaRef.SwapSatisfactionStack(BackupSatisfactionStack); |
| 7354 | } |
| 7355 | }; |
| 7356 | |
| 7357 | void SwapSatisfactionStack( |
| 7358 | llvm::SmallVectorImpl<SatisfactionStackEntryTy> &NewSS) { |
| 7359 | SatisfactionStack.swap(NewSS); |
| 7360 | } |
| 7361 | |
| 7362 | const NormalizedConstraint * |
| 7363 | getNormalizedAssociatedConstraints( |
| 7364 | NamedDecl *ConstrainedDecl, ArrayRef<const Expr *> AssociatedConstraints); |
| 7365 | |
| 7366 | /// \brief Check whether the given declaration's associated constraints are |
| 7367 | /// at least as constrained than another declaration's according to the |
| 7368 | /// partial ordering of constraints. |
| 7369 | /// |
| 7370 | /// \param Result If no error occurred, receives the result of true if D1 is |
| 7371 | /// at least constrained than D2, and false otherwise. |
| 7372 | /// |
| 7373 | /// \returns true if an error occurred, false otherwise. |
| 7374 | bool IsAtLeastAsConstrained(NamedDecl *D1, MutableArrayRef<const Expr *> AC1, |
| 7375 | NamedDecl *D2, MutableArrayRef<const Expr *> AC2, |
| 7376 | bool &Result); |
| 7377 | |
| 7378 | /// If D1 was not at least as constrained as D2, but would've been if a pair |
| 7379 | /// of atomic constraints involved had been declared in a concept and not |
| 7380 | /// repeated in two separate places in code. |
| 7381 | /// \returns true if such a diagnostic was emitted, false otherwise. |
| 7382 | bool MaybeEmitAmbiguousAtomicConstraintsDiagnostic(NamedDecl *D1, |
| 7383 | ArrayRef<const Expr *> AC1, NamedDecl *D2, ArrayRef<const Expr *> AC2); |
| 7384 | |
| 7385 | /// \brief Check whether the given list of constraint expressions are |
| 7386 | /// satisfied (as if in a 'conjunction') given template arguments. |
| 7387 | /// \param Template the template-like entity that triggered the constraints |
| 7388 | /// check (either a concept or a constrained entity). |
| 7389 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
| 7390 | /// they were 'AND'ed together. |
| 7391 | /// \param TemplateArgLists the list of template arguments to substitute into |
| 7392 | /// the constraint expression. |
| 7393 | /// \param TemplateIDRange The source range of the template id that |
| 7394 | /// caused the constraints check. |
| 7395 | /// \param Satisfaction if true is returned, will contain details of the |
| 7396 | /// satisfaction, with enough information to diagnose an unsatisfied |
| 7397 | /// expression. |
| 7398 | /// \returns true if an error occurred and satisfaction could not be checked, |
| 7399 | /// false otherwise. |
| 7400 | bool CheckConstraintSatisfaction( |
| 7401 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
| 7402 | const MultiLevelTemplateArgumentList &TemplateArgLists, |
| 7403 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction) { |
| 7404 | llvm::SmallVector<Expr *, 4> Converted; |
| 7405 | return CheckConstraintSatisfaction(Template, ConstraintExprs, Converted, |
| 7406 | TemplateArgLists, TemplateIDRange, |
| 7407 | Satisfaction); |
| 7408 | } |
| 7409 | |
| 7410 | /// \brief Check whether the given list of constraint expressions are |
| 7411 | /// satisfied (as if in a 'conjunction') given template arguments. |
| 7412 | /// Additionally, takes an empty list of Expressions which is populated with |
| 7413 | /// the instantiated versions of the ConstraintExprs. |
| 7414 | /// \param Template the template-like entity that triggered the constraints |
| 7415 | /// check (either a concept or a constrained entity). |
| 7416 | /// \param ConstraintExprs a list of constraint expressions, treated as if |
| 7417 | /// they were 'AND'ed together. |
| 7418 | /// \param ConvertedConstraints a out parameter that will get populated with |
| 7419 | /// the instantiated version of the ConstraintExprs if we successfully checked |
| 7420 | /// satisfaction. |
| 7421 | /// \param TemplateArgList the multi-level list of template arguments to |
| 7422 | /// substitute into the constraint expression. This should be relative to the |
| 7423 | /// top-level (hence multi-level), since we need to instantiate fully at the |
| 7424 | /// time of checking. |
| 7425 | /// \param TemplateIDRange The source range of the template id that |
| 7426 | /// caused the constraints check. |
| 7427 | /// \param Satisfaction if true is returned, will contain details of the |
| 7428 | /// satisfaction, with enough information to diagnose an unsatisfied |
| 7429 | /// expression. |
| 7430 | /// \returns true if an error occurred and satisfaction could not be checked, |
| 7431 | /// false otherwise. |
| 7432 | bool CheckConstraintSatisfaction( |
| 7433 | const NamedDecl *Template, ArrayRef<const Expr *> ConstraintExprs, |
| 7434 | llvm::SmallVectorImpl<Expr *> &ConvertedConstraints, |
| 7435 | const MultiLevelTemplateArgumentList &TemplateArgList, |
| 7436 | SourceRange TemplateIDRange, ConstraintSatisfaction &Satisfaction); |
| 7437 | |
| 7438 | /// \brief Check whether the given non-dependent constraint expression is |
| 7439 | /// satisfied. Returns false and updates Satisfaction with the satisfaction |
| 7440 | /// verdict if successful, emits a diagnostic and returns true if an error |
| 7441 | /// occurred and satisfaction could not be determined. |
| 7442 | /// |
| 7443 | /// \returns true if an error occurred, false otherwise. |
| 7444 | bool CheckConstraintSatisfaction(const Expr *ConstraintExpr, |
| 7445 | ConstraintSatisfaction &Satisfaction); |
| 7446 | |
| 7447 | /// Check whether the given function decl's trailing requires clause is |
| 7448 | /// satisfied, if any. Returns false and updates Satisfaction with the |
| 7449 | /// satisfaction verdict if successful, emits a diagnostic and returns true if |
| 7450 | /// an error occurred and satisfaction could not be determined. |
| 7451 | /// |
| 7452 | /// \returns true if an error occurred, false otherwise. |
| 7453 | bool CheckFunctionConstraints(const FunctionDecl *FD, |
| 7454 | ConstraintSatisfaction &Satisfaction, |
| 7455 | SourceLocation UsageLoc = SourceLocation(), |
| 7456 | bool ForOverloadResolution = false); |
| 7457 | |
| 7458 | /// \brief Ensure that the given template arguments satisfy the constraints |
| 7459 | /// associated with the given template, emitting a diagnostic if they do not. |
| 7460 | /// |
| 7461 | /// \param Template The template to which the template arguments are being |
| 7462 | /// provided. |
| 7463 | /// |
| 7464 | /// \param TemplateArgs The converted, canonicalized template arguments. |
| 7465 | /// |
| 7466 | /// \param TemplateIDRange The source range of the template id that |
| 7467 | /// caused the constraints check. |
| 7468 | /// |
| 7469 | /// \returns true if the constrains are not satisfied or could not be checked |
| 7470 | /// for satisfaction, false if the constraints are satisfied. |
| 7471 | bool EnsureTemplateArgumentListConstraints( |
| 7472 | TemplateDecl *Template, |
| 7473 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 7474 | SourceRange TemplateIDRange); |
| 7475 | |
| 7476 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
| 7477 | /// unsatisfied. |
| 7478 | /// \param First whether this is the first time an unsatisfied constraint is |
| 7479 | /// diagnosed for this error. |
| 7480 | void |
| 7481 | DiagnoseUnsatisfiedConstraint(const ConstraintSatisfaction &Satisfaction, |
| 7482 | bool First = true); |
| 7483 | |
| 7484 | /// \brief Emit diagnostics explaining why a constraint expression was deemed |
| 7485 | /// unsatisfied. |
| 7486 | void |
| 7487 | DiagnoseUnsatisfiedConstraint(const ASTConstraintSatisfaction &Satisfaction, |
| 7488 | bool First = true); |
| 7489 | |
| 7490 | // ParseObjCStringLiteral - Parse Objective-C string literals. |
| 7491 | ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, |
| 7492 | ArrayRef<Expr *> Strings); |
| 7493 | |
| 7494 | ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); |
| 7495 | |
| 7496 | /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the |
| 7497 | /// numeric literal expression. Type of the expression will be "NSNumber *" |
| 7498 | /// or "id" if NSNumber is unavailable. |
| 7499 | ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); |
| 7500 | ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, |
| 7501 | bool Value); |
| 7502 | ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); |
| 7503 | |
| 7504 | /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the |
| 7505 | /// '@' prefixed parenthesized expression. The type of the expression will |
| 7506 | /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type |
| 7507 | /// of ValueType, which is allowed to be a built-in numeric type, "char *", |
| 7508 | /// "const char *" or C structure with attribute 'objc_boxable'. |
| 7509 | ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); |
| 7510 | |
| 7511 | ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, |
| 7512 | Expr *IndexExpr, |
| 7513 | ObjCMethodDecl *getterMethod, |
| 7514 | ObjCMethodDecl *setterMethod); |
| 7515 | |
| 7516 | ExprResult BuildObjCDictionaryLiteral(SourceRange SR, |
| 7517 | MutableArrayRef<ObjCDictionaryElement> Elements); |
| 7518 | |
| 7519 | ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, |
| 7520 | TypeSourceInfo *EncodedTypeInfo, |
| 7521 | SourceLocation RParenLoc); |
| 7522 | ExprResult BuildCXXMemberCallExpr(Expr *Exp, NamedDecl *FoundDecl, |
| 7523 | CXXConversionDecl *Method, |
| 7524 | bool HadMultipleCandidates); |
| 7525 | |
| 7526 | ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, |
| 7527 | SourceLocation EncodeLoc, |
| 7528 | SourceLocation LParenLoc, |
| 7529 | ParsedType Ty, |
| 7530 | SourceLocation RParenLoc); |
| 7531 | |
| 7532 | /// ParseObjCSelectorExpression - Build selector expression for \@selector |
| 7533 | ExprResult ParseObjCSelectorExpression(Selector Sel, |
| 7534 | SourceLocation AtLoc, |
| 7535 | SourceLocation SelLoc, |
| 7536 | SourceLocation LParenLoc, |
| 7537 | SourceLocation RParenLoc, |
| 7538 | bool WarnMultipleSelectors); |
| 7539 | |
| 7540 | /// ParseObjCProtocolExpression - Build protocol expression for \@protocol |
| 7541 | ExprResult ParseObjCProtocolExpression(IdentifierInfo * ProtocolName, |
| 7542 | SourceLocation AtLoc, |
| 7543 | SourceLocation ProtoLoc, |
| 7544 | SourceLocation LParenLoc, |
| 7545 | SourceLocation ProtoIdLoc, |
| 7546 | SourceLocation RParenLoc); |
| 7547 | |
| 7548 | //===--------------------------------------------------------------------===// |
| 7549 | // C++ Declarations |
| 7550 | // |
| 7551 | Decl *ActOnStartLinkageSpecification(Scope *S, |
| 7552 | SourceLocation ExternLoc, |
| 7553 | Expr *LangStr, |
| 7554 | SourceLocation LBraceLoc); |
| 7555 | Decl *ActOnFinishLinkageSpecification(Scope *S, |
| 7556 | Decl *LinkageSpec, |
| 7557 | SourceLocation RBraceLoc); |
| 7558 | |
| 7559 | |
| 7560 | //===--------------------------------------------------------------------===// |
| 7561 | // C++ Classes |
| 7562 | // |
| 7563 | CXXRecordDecl *getCurrentClass(Scope *S, const CXXScopeSpec *SS); |
| 7564 | bool isCurrentClassName(const IdentifierInfo &II, Scope *S, |
| 7565 | const CXXScopeSpec *SS = nullptr); |
| 7566 | bool isCurrentClassNameTypo(IdentifierInfo *&II, const CXXScopeSpec *SS); |
| 7567 | |
| 7568 | bool ActOnAccessSpecifier(AccessSpecifier Access, SourceLocation ASLoc, |
| 7569 | SourceLocation ColonLoc, |
| 7570 | const ParsedAttributesView &Attrs); |
| 7571 | |
| 7572 | NamedDecl *ActOnCXXMemberDeclarator(Scope *S, AccessSpecifier AS, |
| 7573 | Declarator &D, |
| 7574 | MultiTemplateParamsArg TemplateParameterLists, |
| 7575 | Expr *BitfieldWidth, const VirtSpecifiers &VS, |
| 7576 | InClassInitStyle InitStyle); |
| 7577 | |
| 7578 | void ActOnStartCXXInClassMemberInitializer(); |
| 7579 | void ActOnFinishCXXInClassMemberInitializer(Decl *VarDecl, |
| 7580 | SourceLocation EqualLoc, |
| 7581 | Expr *Init); |
| 7582 | |
| 7583 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
| 7584 | Scope *S, |
| 7585 | CXXScopeSpec &SS, |
| 7586 | IdentifierInfo *MemberOrBase, |
| 7587 | ParsedType TemplateTypeTy, |
| 7588 | const DeclSpec &DS, |
| 7589 | SourceLocation IdLoc, |
| 7590 | SourceLocation LParenLoc, |
| 7591 | ArrayRef<Expr *> Args, |
| 7592 | SourceLocation RParenLoc, |
| 7593 | SourceLocation EllipsisLoc); |
| 7594 | |
| 7595 | MemInitResult ActOnMemInitializer(Decl *ConstructorD, |
| 7596 | Scope *S, |
| 7597 | CXXScopeSpec &SS, |
| 7598 | IdentifierInfo *MemberOrBase, |
| 7599 | ParsedType TemplateTypeTy, |
| 7600 | const DeclSpec &DS, |
| 7601 | SourceLocation IdLoc, |
| 7602 | Expr *InitList, |
| 7603 | SourceLocation EllipsisLoc); |
| 7604 | |
| 7605 | MemInitResult BuildMemInitializer(Decl *ConstructorD, |
| 7606 | Scope *S, |
| 7607 | CXXScopeSpec &SS, |
| 7608 | IdentifierInfo *MemberOrBase, |
| 7609 | ParsedType TemplateTypeTy, |
| 7610 | const DeclSpec &DS, |
| 7611 | SourceLocation IdLoc, |
| 7612 | Expr *Init, |
| 7613 | SourceLocation EllipsisLoc); |
| 7614 | |
| 7615 | MemInitResult BuildMemberInitializer(ValueDecl *Member, |
| 7616 | Expr *Init, |
| 7617 | SourceLocation IdLoc); |
| 7618 | |
| 7619 | MemInitResult BuildBaseInitializer(QualType BaseType, |
| 7620 | TypeSourceInfo *BaseTInfo, |
| 7621 | Expr *Init, |
| 7622 | CXXRecordDecl *ClassDecl, |
| 7623 | SourceLocation EllipsisLoc); |
| 7624 | |
| 7625 | MemInitResult BuildDelegatingInitializer(TypeSourceInfo *TInfo, |
| 7626 | Expr *Init, |
| 7627 | CXXRecordDecl *ClassDecl); |
| 7628 | |
| 7629 | bool SetDelegatingInitializer(CXXConstructorDecl *Constructor, |
| 7630 | CXXCtorInitializer *Initializer); |
| 7631 | |
| 7632 | bool SetCtorInitializers( |
| 7633 | CXXConstructorDecl *Constructor, bool AnyErrors, |
| 7634 | ArrayRef<CXXCtorInitializer *> Initializers = std::nullopt); |
| 7635 | |
| 7636 | void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); |
| 7637 | |
| 7638 | |
| 7639 | /// MarkBaseAndMemberDestructorsReferenced - Given a record decl, |
| 7640 | /// mark all the non-trivial destructors of its members and bases as |
| 7641 | /// referenced. |
| 7642 | void MarkBaseAndMemberDestructorsReferenced(SourceLocation Loc, |
| 7643 | CXXRecordDecl *Record); |
| 7644 | |
| 7645 | /// Mark destructors of virtual bases of this class referenced. In the Itanium |
| 7646 | /// C++ ABI, this is done when emitting a destructor for any non-abstract |
| 7647 | /// class. In the Microsoft C++ ABI, this is done any time a class's |
| 7648 | /// destructor is referenced. |
| 7649 | void MarkVirtualBaseDestructorsReferenced( |
| 7650 | SourceLocation Location, CXXRecordDecl *ClassDecl, |
| 7651 | llvm::SmallPtrSetImpl<const RecordType *> *DirectVirtualBases = nullptr); |
| 7652 | |
| 7653 | /// Do semantic checks to allow the complete destructor variant to be emitted |
| 7654 | /// when the destructor is defined in another translation unit. In the Itanium |
| 7655 | /// C++ ABI, destructor variants are emitted together. In the MS C++ ABI, they |
| 7656 | /// can be emitted in separate TUs. To emit the complete variant, run a subset |
| 7657 | /// of the checks performed when emitting a regular destructor. |
| 7658 | void CheckCompleteDestructorVariant(SourceLocation CurrentLocation, |
| 7659 | CXXDestructorDecl *Dtor); |
| 7660 | |
| 7661 | /// The list of classes whose vtables have been used within |
| 7662 | /// this translation unit, and the source locations at which the |
| 7663 | /// first use occurred. |
| 7664 | typedef std::pair<CXXRecordDecl*, SourceLocation> VTableUse; |
| 7665 | |
| 7666 | /// The list of vtables that are required but have not yet been |
| 7667 | /// materialized. |
| 7668 | SmallVector<VTableUse, 16> VTableUses; |
| 7669 | |
| 7670 | /// The set of classes whose vtables have been used within |
| 7671 | /// this translation unit, and a bit that will be true if the vtable is |
| 7672 | /// required to be emitted (otherwise, it should be emitted only if needed |
| 7673 | /// by code generation). |
| 7674 | llvm::DenseMap<CXXRecordDecl *, bool> VTablesUsed; |
| 7675 | |
| 7676 | /// Load any externally-stored vtable uses. |
| 7677 | void LoadExternalVTableUses(); |
| 7678 | |
| 7679 | /// Note that the vtable for the given class was used at the |
| 7680 | /// given location. |
| 7681 | void MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, |
| 7682 | bool DefinitionRequired = false); |
| 7683 | |
| 7684 | /// Mark the exception specifications of all virtual member functions |
| 7685 | /// in the given class as needed. |
| 7686 | void MarkVirtualMemberExceptionSpecsNeeded(SourceLocation Loc, |
| 7687 | const CXXRecordDecl *RD); |
| 7688 | |
| 7689 | /// MarkVirtualMembersReferenced - Will mark all members of the given |
| 7690 | /// CXXRecordDecl referenced. |
| 7691 | void MarkVirtualMembersReferenced(SourceLocation Loc, const CXXRecordDecl *RD, |
| 7692 | bool ConstexprOnly = false); |
| 7693 | |
| 7694 | /// Define all of the vtables that have been used in this |
| 7695 | /// translation unit and reference any virtual members used by those |
| 7696 | /// vtables. |
| 7697 | /// |
| 7698 | /// \returns true if any work was done, false otherwise. |
| 7699 | bool DefineUsedVTables(); |
| 7700 | |
| 7701 | void AddImplicitlyDeclaredMembersToClass(CXXRecordDecl *ClassDecl); |
| 7702 | |
| 7703 | void ActOnMemInitializers(Decl *ConstructorDecl, |
| 7704 | SourceLocation ColonLoc, |
| 7705 | ArrayRef<CXXCtorInitializer*> MemInits, |
| 7706 | bool AnyErrors); |
| 7707 | |
| 7708 | /// Check class-level dllimport/dllexport attribute. The caller must |
| 7709 | /// ensure that referenceDLLExportedClassMethods is called some point later |
| 7710 | /// when all outer classes of Class are complete. |
| 7711 | void checkClassLevelDLLAttribute(CXXRecordDecl *Class); |
| 7712 | void checkClassLevelCodeSegAttribute(CXXRecordDecl *Class); |
| 7713 | |
| 7714 | void referenceDLLExportedClassMethods(); |
| 7715 | |
| 7716 | void propagateDLLAttrToBaseClassTemplate( |
| 7717 | CXXRecordDecl *Class, Attr *ClassAttr, |
| 7718 | ClassTemplateSpecializationDecl *BaseTemplateSpec, |
| 7719 | SourceLocation BaseLoc); |
| 7720 | |
| 7721 | /// Add gsl::Pointer attribute to std::container::iterator |
| 7722 | /// \param ND The declaration that introduces the name |
| 7723 | /// std::container::iterator. \param UnderlyingRecord The record named by ND. |
| 7724 | void inferGslPointerAttribute(NamedDecl *ND, CXXRecordDecl *UnderlyingRecord); |
| 7725 | |
| 7726 | /// Add [[gsl::Owner]] and [[gsl::Pointer]] attributes for std:: types. |
| 7727 | void inferGslOwnerPointerAttribute(CXXRecordDecl *Record); |
| 7728 | |
| 7729 | /// Add [[gsl::Pointer]] attributes for std:: types. |
| 7730 | void inferGslPointerAttribute(TypedefNameDecl *TD); |
| 7731 | |
| 7732 | void CheckCompletedCXXClass(Scope *S, CXXRecordDecl *Record); |
| 7733 | |
| 7734 | /// Check that the C++ class annoated with "trivial_abi" satisfies all the |
| 7735 | /// conditions that are needed for the attribute to have an effect. |
| 7736 | void checkIllFormedTrivialABIStruct(CXXRecordDecl &RD); |
| 7737 | |
| 7738 | void ActOnFinishCXXMemberSpecification(Scope *S, SourceLocation RLoc, |
| 7739 | Decl *TagDecl, SourceLocation LBrac, |
| 7740 | SourceLocation RBrac, |
| 7741 | const ParsedAttributesView &AttrList); |
| 7742 | void ActOnFinishCXXMemberDecls(); |
| 7743 | void ActOnFinishCXXNonNestedClass(); |
| 7744 | |
| 7745 | void ActOnReenterCXXMethodParameter(Scope *S, ParmVarDecl *Param); |
| 7746 | unsigned ActOnReenterTemplateScope(Decl *Template, |
| 7747 | llvm::function_ref<Scope *()> EnterScope); |
| 7748 | void ActOnStartDelayedMemberDeclarations(Scope *S, Decl *Record); |
| 7749 | void ActOnStartDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
| 7750 | void ActOnDelayedCXXMethodParameter(Scope *S, Decl *Param); |
| 7751 | void ActOnFinishDelayedMemberDeclarations(Scope *S, Decl *Record); |
| 7752 | void ActOnFinishDelayedCXXMethodDeclaration(Scope *S, Decl *Method); |
| 7753 | void ActOnFinishDelayedMemberInitializers(Decl *Record); |
| 7754 | void MarkAsLateParsedTemplate(FunctionDecl *FD, Decl *FnD, |
| 7755 | CachedTokens &Toks); |
| 7756 | void UnmarkAsLateParsedTemplate(FunctionDecl *FD); |
| 7757 | bool IsInsideALocalClassWithinATemplateFunction(); |
| 7758 | |
| 7759 | Decl *ActOnStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
| 7760 | Expr *AssertExpr, |
| 7761 | Expr *AssertMessageExpr, |
| 7762 | SourceLocation RParenLoc); |
| 7763 | Decl *BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc, |
| 7764 | Expr *AssertExpr, |
| 7765 | StringLiteral *AssertMessageExpr, |
| 7766 | SourceLocation RParenLoc, |
| 7767 | bool Failed); |
| 7768 | void DiagnoseStaticAssertDetails(const Expr *E); |
| 7769 | |
| 7770 | FriendDecl *CheckFriendTypeDecl(SourceLocation LocStart, |
| 7771 | SourceLocation FriendLoc, |
| 7772 | TypeSourceInfo *TSInfo); |
| 7773 | Decl *ActOnFriendTypeDecl(Scope *S, const DeclSpec &DS, |
| 7774 | MultiTemplateParamsArg TemplateParams); |
| 7775 | NamedDecl *ActOnFriendFunctionDecl(Scope *S, Declarator &D, |
| 7776 | MultiTemplateParamsArg TemplateParams); |
| 7777 | |
| 7778 | QualType CheckConstructorDeclarator(Declarator &D, QualType R, |
| 7779 | StorageClass& SC); |
| 7780 | void CheckConstructor(CXXConstructorDecl *Constructor); |
| 7781 | QualType CheckDestructorDeclarator(Declarator &D, QualType R, |
| 7782 | StorageClass& SC); |
| 7783 | bool CheckDestructor(CXXDestructorDecl *Destructor); |
| 7784 | void CheckConversionDeclarator(Declarator &D, QualType &R, |
| 7785 | StorageClass& SC); |
| 7786 | Decl *ActOnConversionDeclarator(CXXConversionDecl *Conversion); |
| 7787 | void CheckDeductionGuideDeclarator(Declarator &D, QualType &R, |
| 7788 | StorageClass &SC); |
| 7789 | void CheckDeductionGuideTemplate(FunctionTemplateDecl *TD); |
| 7790 | |
| 7791 | void CheckExplicitlyDefaultedFunction(Scope *S, FunctionDecl *MD); |
| 7792 | |
| 7793 | bool CheckExplicitlyDefaultedSpecialMember(CXXMethodDecl *MD, |
| 7794 | CXXSpecialMember CSM, |
| 7795 | SourceLocation DefaultLoc); |
| 7796 | void CheckDelayedMemberExceptionSpecs(); |
| 7797 | |
| 7798 | bool CheckExplicitlyDefaultedComparison(Scope *S, FunctionDecl *MD, |
| 7799 | DefaultedComparisonKind DCK); |
| 7800 | void DeclareImplicitEqualityComparison(CXXRecordDecl *RD, |
| 7801 | FunctionDecl *Spaceship); |
| 7802 | void DefineDefaultedComparison(SourceLocation Loc, FunctionDecl *FD, |
| 7803 | DefaultedComparisonKind DCK); |
| 7804 | |
| 7805 | //===--------------------------------------------------------------------===// |
| 7806 | // C++ Derived Classes |
| 7807 | // |
| 7808 | |
| 7809 | /// ActOnBaseSpecifier - Parsed a base specifier |
| 7810 | CXXBaseSpecifier *CheckBaseSpecifier(CXXRecordDecl *Class, |
| 7811 | SourceRange SpecifierRange, |
| 7812 | bool Virtual, AccessSpecifier Access, |
| 7813 | TypeSourceInfo *TInfo, |
| 7814 | SourceLocation EllipsisLoc); |
| 7815 | |
| 7816 | BaseResult ActOnBaseSpecifier(Decl *classdecl, SourceRange SpecifierRange, |
| 7817 | const ParsedAttributesView &Attrs, bool Virtual, |
| 7818 | AccessSpecifier Access, ParsedType basetype, |
| 7819 | SourceLocation BaseLoc, |
| 7820 | SourceLocation EllipsisLoc); |
| 7821 | |
| 7822 | bool AttachBaseSpecifiers(CXXRecordDecl *Class, |
| 7823 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
| 7824 | void ActOnBaseSpecifiers(Decl *ClassDecl, |
| 7825 | MutableArrayRef<CXXBaseSpecifier *> Bases); |
| 7826 | |
| 7827 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base); |
| 7828 | bool IsDerivedFrom(SourceLocation Loc, QualType Derived, QualType Base, |
| 7829 | CXXBasePaths &Paths); |
| 7830 | |
| 7831 | // FIXME: I don't like this name. |
| 7832 | void BuildBasePathArray(const CXXBasePaths &Paths, CXXCastPath &BasePath); |
| 7833 | |
| 7834 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
| 7835 | SourceLocation Loc, SourceRange Range, |
| 7836 | CXXCastPath *BasePath = nullptr, |
| 7837 | bool IgnoreAccess = false); |
| 7838 | bool CheckDerivedToBaseConversion(QualType Derived, QualType Base, |
| 7839 | unsigned InaccessibleBaseID, |
| 7840 | unsigned AmbiguousBaseConvID, |
| 7841 | SourceLocation Loc, SourceRange Range, |
| 7842 | DeclarationName Name, |
| 7843 | CXXCastPath *BasePath, |
| 7844 | bool IgnoreAccess = false); |
| 7845 | |
| 7846 | std::string getAmbiguousPathsDisplayString(CXXBasePaths &Paths); |
| 7847 | |
| 7848 | bool CheckOverridingFunctionAttributes(const CXXMethodDecl *New, |
| 7849 | const CXXMethodDecl *Old); |
| 7850 | |
| 7851 | /// CheckOverridingFunctionReturnType - Checks whether the return types are |
| 7852 | /// covariant, according to C++ [class.virtual]p5. |
| 7853 | bool CheckOverridingFunctionReturnType(const CXXMethodDecl *New, |
| 7854 | const CXXMethodDecl *Old); |
| 7855 | |
| 7856 | /// CheckOverridingFunctionExceptionSpec - Checks whether the exception |
| 7857 | /// spec is a subset of base spec. |
| 7858 | bool CheckOverridingFunctionExceptionSpec(const CXXMethodDecl *New, |
| 7859 | const CXXMethodDecl *Old); |
| 7860 | |
| 7861 | bool CheckPureMethod(CXXMethodDecl *Method, SourceRange InitRange); |
| 7862 | |
| 7863 | /// CheckOverrideControl - Check C++11 override control semantics. |
| 7864 | void CheckOverrideControl(NamedDecl *D); |
| 7865 | |
| 7866 | /// DiagnoseAbsenceOfOverrideControl - Diagnose if 'override' keyword was |
| 7867 | /// not used in the declaration of an overriding method. |
| 7868 | void DiagnoseAbsenceOfOverrideControl(NamedDecl *D, bool Inconsistent); |
| 7869 | |
| 7870 | /// CheckForFunctionMarkedFinal - Checks whether a virtual member function |
| 7871 | /// overrides a virtual member function marked 'final', according to |
| 7872 | /// C++11 [class.virtual]p4. |
| 7873 | bool CheckIfOverriddenFunctionIsMarkedFinal(const CXXMethodDecl *New, |
| 7874 | const CXXMethodDecl *Old); |
| 7875 | |
| 7876 | |
| 7877 | //===--------------------------------------------------------------------===// |
| 7878 | // C++ Access Control |
| 7879 | // |
| 7880 | |
| 7881 | enum AccessResult { |
| 7882 | AR_accessible, |
| 7883 | AR_inaccessible, |
| 7884 | AR_dependent, |
| 7885 | AR_delayed |
| 7886 | }; |
| 7887 | |
| 7888 | bool SetMemberAccessSpecifier(NamedDecl *MemberDecl, |
| 7889 | NamedDecl *PrevMemberDecl, |
| 7890 | AccessSpecifier LexicalAS); |
| 7891 | |
| 7892 | AccessResult CheckUnresolvedMemberAccess(UnresolvedMemberExpr *E, |
| 7893 | DeclAccessPair FoundDecl); |
| 7894 | AccessResult CheckUnresolvedLookupAccess(UnresolvedLookupExpr *E, |
| 7895 | DeclAccessPair FoundDecl); |
| 7896 | AccessResult CheckAllocationAccess(SourceLocation OperatorLoc, |
| 7897 | SourceRange PlacementRange, |
| 7898 | CXXRecordDecl *NamingClass, |
| 7899 | DeclAccessPair FoundDecl, |
| 7900 | bool Diagnose = true); |
| 7901 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
| 7902 | CXXConstructorDecl *D, |
| 7903 | DeclAccessPair FoundDecl, |
| 7904 | const InitializedEntity &Entity, |
| 7905 | bool IsCopyBindingRefToTemp = false); |
| 7906 | AccessResult CheckConstructorAccess(SourceLocation Loc, |
| 7907 | CXXConstructorDecl *D, |
| 7908 | DeclAccessPair FoundDecl, |
| 7909 | const InitializedEntity &Entity, |
| 7910 | const PartialDiagnostic &PDiag); |
| 7911 | AccessResult CheckDestructorAccess(SourceLocation Loc, |
| 7912 | CXXDestructorDecl *Dtor, |
| 7913 | const PartialDiagnostic &PDiag, |
| 7914 | QualType objectType = QualType()); |
| 7915 | AccessResult CheckFriendAccess(NamedDecl *D); |
| 7916 | AccessResult CheckMemberAccess(SourceLocation UseLoc, |
| 7917 | CXXRecordDecl *NamingClass, |
| 7918 | DeclAccessPair Found); |
| 7919 | AccessResult |
| 7920 | CheckStructuredBindingMemberAccess(SourceLocation UseLoc, |
| 7921 | CXXRecordDecl *DecomposedClass, |
| 7922 | DeclAccessPair Field); |
| 7923 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
| 7924 | const SourceRange &, |
| 7925 | DeclAccessPair FoundDecl); |
| 7926 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, |
| 7927 | Expr *ObjectExpr, |
| 7928 | Expr *ArgExpr, |
| 7929 | DeclAccessPair FoundDecl); |
| 7930 | AccessResult CheckMemberOperatorAccess(SourceLocation Loc, Expr *ObjectExpr, |
| 7931 | ArrayRef<Expr *> ArgExprs, |
| 7932 | DeclAccessPair FoundDecl); |
| 7933 | AccessResult CheckAddressOfMemberAccess(Expr *OvlExpr, |
| 7934 | DeclAccessPair FoundDecl); |
| 7935 | AccessResult CheckBaseClassAccess(SourceLocation AccessLoc, |
| 7936 | QualType Base, QualType Derived, |
| 7937 | const CXXBasePath &Path, |
| 7938 | unsigned DiagID, |
| 7939 | bool ForceCheck = false, |
| 7940 | bool ForceUnprivileged = false); |
| 7941 | void CheckLookupAccess(const LookupResult &R); |
| 7942 | bool IsSimplyAccessible(NamedDecl *Decl, CXXRecordDecl *NamingClass, |
| 7943 | QualType BaseType); |
| 7944 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
| 7945 | DeclAccessPair Found, QualType ObjectType, |
| 7946 | SourceLocation Loc, |
| 7947 | const PartialDiagnostic &Diag); |
| 7948 | bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass, |
| 7949 | DeclAccessPair Found, |
| 7950 | QualType ObjectType) { |
| 7951 | return isMemberAccessibleForDeletion(NamingClass, Found, ObjectType, |
| 7952 | SourceLocation(), PDiag()); |
| 7953 | } |
| 7954 | |
| 7955 | void HandleDependentAccessCheck(const DependentDiagnostic &DD, |
| 7956 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 7957 | void PerformDependentDiagnostics(const DeclContext *Pattern, |
| 7958 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 7959 | |
| 7960 | void HandleDelayedAccessCheck(sema::DelayedDiagnostic &DD, Decl *Ctx); |
| 7961 | |
| 7962 | /// When true, access checking violations are treated as SFINAE |
| 7963 | /// failures rather than hard errors. |
| 7964 | bool AccessCheckingSFINAE; |
| 7965 | |
| 7966 | enum AbstractDiagSelID { |
| 7967 | AbstractNone = -1, |
| 7968 | AbstractReturnType, |
| 7969 | AbstractParamType, |
| 7970 | AbstractVariableType, |
| 7971 | AbstractFieldType, |
| 7972 | AbstractIvarType, |
| 7973 | AbstractSynthesizedIvarType, |
| 7974 | AbstractArrayType |
| 7975 | }; |
| 7976 | |
| 7977 | bool isAbstractType(SourceLocation Loc, QualType T); |
| 7978 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, |
| 7979 | TypeDiagnoser &Diagnoser); |
| 7980 | template <typename... Ts> |
| 7981 | bool RequireNonAbstractType(SourceLocation Loc, QualType T, unsigned DiagID, |
| 7982 | const Ts &...Args) { |
| 7983 | BoundTypeDiagnoser<Ts...> Diagnoser(DiagID, Args...); |
| 7984 | return RequireNonAbstractType(Loc, T, Diagnoser); |
| 7985 | } |
| 7986 | |
| 7987 | void DiagnoseAbstractType(const CXXRecordDecl *RD); |
| 7988 | |
| 7989 | //===--------------------------------------------------------------------===// |
| 7990 | // C++ Overloaded Operators [C++ 13.5] |
| 7991 | // |
| 7992 | |
| 7993 | bool CheckOverloadedOperatorDeclaration(FunctionDecl *FnDecl); |
| 7994 | |
| 7995 | bool CheckLiteralOperatorDeclaration(FunctionDecl *FnDecl); |
| 7996 | |
| 7997 | //===--------------------------------------------------------------------===// |
| 7998 | // C++ Templates [C++ 14] |
| 7999 | // |
| 8000 | void FilterAcceptableTemplateNames(LookupResult &R, |
| 8001 | bool AllowFunctionTemplates = true, |
| 8002 | bool AllowDependent = true); |
| 8003 | bool hasAnyAcceptableTemplateNames(LookupResult &R, |
| 8004 | bool AllowFunctionTemplates = true, |
| 8005 | bool AllowDependent = true, |
| 8006 | bool AllowNonTemplateFunctions = false); |
| 8007 | /// Try to interpret the lookup result D as a template-name. |
| 8008 | /// |
| 8009 | /// \param D A declaration found by name lookup. |
| 8010 | /// \param AllowFunctionTemplates Whether function templates should be |
| 8011 | /// considered valid results. |
| 8012 | /// \param AllowDependent Whether unresolved using declarations (that might |
| 8013 | /// name templates) should be considered valid results. |
| 8014 | static NamedDecl *getAsTemplateNameDecl(NamedDecl *D, |
| 8015 | bool AllowFunctionTemplates = true, |
| 8016 | bool AllowDependent = true); |
| 8017 | |
| 8018 | enum TemplateNameIsRequiredTag { TemplateNameIsRequired }; |
| 8019 | /// Whether and why a template name is required in this lookup. |
| 8020 | class RequiredTemplateKind { |
| 8021 | public: |
| 8022 | /// Template name is required if TemplateKWLoc is valid. |
| 8023 | RequiredTemplateKind(SourceLocation TemplateKWLoc = SourceLocation()) |
| 8024 | : TemplateKW(TemplateKWLoc) {} |
| 8025 | /// Template name is unconditionally required. |
| 8026 | RequiredTemplateKind(TemplateNameIsRequiredTag) {} |
| 8027 | |
| 8028 | SourceLocation getTemplateKeywordLoc() const { |
| 8029 | return TemplateKW.value_or(SourceLocation()); |
| 8030 | } |
| 8031 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } |
| 8032 | bool isRequired() const { return TemplateKW != SourceLocation(); } |
| 8033 | explicit operator bool() const { return isRequired(); } |
| 8034 | |
| 8035 | private: |
| 8036 | std::optional<SourceLocation> TemplateKW; |
| 8037 | }; |
| 8038 | |
| 8039 | enum class AssumedTemplateKind { |
| 8040 | /// This is not assumed to be a template name. |
| 8041 | None, |
| 8042 | /// This is assumed to be a template name because lookup found nothing. |
| 8043 | FoundNothing, |
| 8044 | /// This is assumed to be a template name because lookup found one or more |
| 8045 | /// functions (but no function templates). |
| 8046 | FoundFunctions, |
| 8047 | }; |
| 8048 | bool LookupTemplateName( |
| 8049 | LookupResult &R, Scope *S, CXXScopeSpec &SS, QualType ObjectType, |
| 8050 | bool EnteringContext, bool &MemberOfUnknownSpecialization, |
| 8051 | RequiredTemplateKind RequiredTemplate = SourceLocation(), |
| 8052 | AssumedTemplateKind *ATK = nullptr, bool AllowTypoCorrection = true); |
| 8053 | |
| 8054 | TemplateNameKind isTemplateName(Scope *S, |
| 8055 | CXXScopeSpec &SS, |
| 8056 | bool hasTemplateKeyword, |
| 8057 | const UnqualifiedId &Name, |
| 8058 | ParsedType ObjectType, |
| 8059 | bool EnteringContext, |
| 8060 | TemplateTy &Template, |
| 8061 | bool &MemberOfUnknownSpecialization, |
| 8062 | bool Disambiguation = false); |
| 8063 | |
| 8064 | /// Try to resolve an undeclared template name as a type template. |
| 8065 | /// |
| 8066 | /// Sets II to the identifier corresponding to the template name, and updates |
| 8067 | /// Name to a corresponding (typo-corrected) type template name and TNK to |
| 8068 | /// the corresponding kind, if possible. |
| 8069 | void ActOnUndeclaredTypeTemplateName(Scope *S, TemplateTy &Name, |
| 8070 | TemplateNameKind &TNK, |
| 8071 | SourceLocation NameLoc, |
| 8072 | IdentifierInfo *&II); |
| 8073 | |
| 8074 | bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, |
| 8075 | SourceLocation NameLoc, |
| 8076 | bool Diagnose = true); |
| 8077 | |
| 8078 | /// Determine whether a particular identifier might be the name in a C++1z |
| 8079 | /// deduction-guide declaration. |
| 8080 | bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, |
| 8081 | SourceLocation NameLoc, CXXScopeSpec &SS, |
| 8082 | ParsedTemplateTy *Template = nullptr); |
| 8083 | |
| 8084 | bool DiagnoseUnknownTemplateName(const IdentifierInfo &II, |
| 8085 | SourceLocation IILoc, |
| 8086 | Scope *S, |
| 8087 | const CXXScopeSpec *SS, |
| 8088 | TemplateTy &SuggestedTemplate, |
| 8089 | TemplateNameKind &SuggestedKind); |
| 8090 | |
| 8091 | bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation, |
| 8092 | NamedDecl *Instantiation, |
| 8093 | bool InstantiatedFromMember, |
| 8094 | const NamedDecl *Pattern, |
| 8095 | const NamedDecl *PatternDef, |
| 8096 | TemplateSpecializationKind TSK, |
| 8097 | bool Complain = true); |
| 8098 | |
| 8099 | void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl); |
| 8100 | TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl); |
| 8101 | |
| 8102 | NamedDecl *ActOnTypeParameter(Scope *S, bool Typename, |
| 8103 | SourceLocation EllipsisLoc, |
| 8104 | SourceLocation KeyLoc, |
| 8105 | IdentifierInfo *ParamName, |
| 8106 | SourceLocation ParamNameLoc, |
| 8107 | unsigned Depth, unsigned Position, |
| 8108 | SourceLocation EqualLoc, |
| 8109 | ParsedType DefaultArg, bool HasTypeConstraint); |
| 8110 | |
| 8111 | bool CheckTypeConstraint(TemplateIdAnnotation *TypeConstraint); |
| 8112 | |
| 8113 | bool ActOnTypeConstraint(const CXXScopeSpec &SS, |
| 8114 | TemplateIdAnnotation *TypeConstraint, |
| 8115 | TemplateTypeParmDecl *ConstrainedParameter, |
| 8116 | SourceLocation EllipsisLoc); |
| 8117 | bool BuildTypeConstraint(const CXXScopeSpec &SS, |
| 8118 | TemplateIdAnnotation *TypeConstraint, |
| 8119 | TemplateTypeParmDecl *ConstrainedParameter, |
| 8120 | SourceLocation EllipsisLoc, |
| 8121 | bool AllowUnexpandedPack); |
| 8122 | |
| 8123 | bool AttachTypeConstraint(NestedNameSpecifierLoc NS, |
| 8124 | DeclarationNameInfo NameInfo, |
| 8125 | ConceptDecl *NamedConcept, |
| 8126 | const TemplateArgumentListInfo *TemplateArgs, |
| 8127 | TemplateTypeParmDecl *ConstrainedParameter, |
| 8128 | SourceLocation EllipsisLoc); |
| 8129 | |
| 8130 | bool AttachTypeConstraint(AutoTypeLoc TL, |
| 8131 | NonTypeTemplateParmDecl *NewConstrainedParm, |
| 8132 | NonTypeTemplateParmDecl *OrigConstrainedParm, |
| 8133 | SourceLocation EllipsisLoc); |
| 8134 | |
| 8135 | bool RequireStructuralType(QualType T, SourceLocation Loc); |
| 8136 | |
| 8137 | QualType CheckNonTypeTemplateParameterType(TypeSourceInfo *&TSI, |
| 8138 | SourceLocation Loc); |
| 8139 | QualType CheckNonTypeTemplateParameterType(QualType T, SourceLocation Loc); |
| 8140 | |
| 8141 | NamedDecl *ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, |
| 8142 | unsigned Depth, |
| 8143 | unsigned Position, |
| 8144 | SourceLocation EqualLoc, |
| 8145 | Expr *DefaultArg); |
| 8146 | NamedDecl *ActOnTemplateTemplateParameter(Scope *S, |
| 8147 | SourceLocation TmpLoc, |
| 8148 | TemplateParameterList *Params, |
| 8149 | SourceLocation EllipsisLoc, |
| 8150 | IdentifierInfo *ParamName, |
| 8151 | SourceLocation ParamNameLoc, |
| 8152 | unsigned Depth, |
| 8153 | unsigned Position, |
| 8154 | SourceLocation EqualLoc, |
| 8155 | ParsedTemplateArgument DefaultArg); |
| 8156 | |
| 8157 | TemplateParameterList * |
| 8158 | ActOnTemplateParameterList(unsigned Depth, |
| 8159 | SourceLocation ExportLoc, |
| 8160 | SourceLocation TemplateLoc, |
| 8161 | SourceLocation LAngleLoc, |
| 8162 | ArrayRef<NamedDecl *> Params, |
| 8163 | SourceLocation RAngleLoc, |
| 8164 | Expr *RequiresClause); |
| 8165 | |
| 8166 | /// The context in which we are checking a template parameter list. |
| 8167 | enum TemplateParamListContext { |
| 8168 | TPC_ClassTemplate, |
| 8169 | TPC_VarTemplate, |
| 8170 | TPC_FunctionTemplate, |
| 8171 | TPC_ClassTemplateMember, |
| 8172 | TPC_FriendClassTemplate, |
| 8173 | TPC_FriendFunctionTemplate, |
| 8174 | TPC_FriendFunctionTemplateDefinition, |
| 8175 | TPC_TypeAliasTemplate |
| 8176 | }; |
| 8177 | |
| 8178 | bool CheckTemplateParameterList(TemplateParameterList *NewParams, |
| 8179 | TemplateParameterList *OldParams, |
| 8180 | TemplateParamListContext TPC, |
| 8181 | SkipBodyInfo *SkipBody = nullptr); |
| 8182 | TemplateParameterList *MatchTemplateParametersToScopeSpecifier( |
| 8183 | SourceLocation DeclStartLoc, SourceLocation DeclLoc, |
| 8184 | const CXXScopeSpec &SS, TemplateIdAnnotation *TemplateId, |
| 8185 | ArrayRef<TemplateParameterList *> ParamLists, |
| 8186 | bool IsFriend, bool &IsMemberSpecialization, bool &Invalid, |
| 8187 | bool SuppressDiagnostic = false); |
| 8188 | |
| 8189 | DeclResult CheckClassTemplate( |
| 8190 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
| 8191 | CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, |
| 8192 | const ParsedAttributesView &Attr, TemplateParameterList *TemplateParams, |
| 8193 | AccessSpecifier AS, SourceLocation ModulePrivateLoc, |
| 8194 | SourceLocation FriendLoc, unsigned NumOuterTemplateParamLists, |
| 8195 | TemplateParameterList **OuterTemplateParamLists, |
| 8196 | SkipBodyInfo *SkipBody = nullptr); |
| 8197 | |
| 8198 | TemplateArgumentLoc getTrivialTemplateArgumentLoc(const TemplateArgument &Arg, |
| 8199 | QualType NTTPType, |
| 8200 | SourceLocation Loc); |
| 8201 | |
| 8202 | /// Get a template argument mapping the given template parameter to itself, |
| 8203 | /// e.g. for X in \c template<int X>, this would return an expression template |
| 8204 | /// argument referencing X. |
| 8205 | TemplateArgumentLoc getIdentityTemplateArgumentLoc(NamedDecl *Param, |
| 8206 | SourceLocation Location); |
| 8207 | |
| 8208 | void translateTemplateArguments(const ASTTemplateArgsPtr &In, |
| 8209 | TemplateArgumentListInfo &Out); |
| 8210 | |
| 8211 | ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType); |
| 8212 | |
| 8213 | void NoteAllFoundTemplates(TemplateName Name); |
| 8214 | |
| 8215 | QualType CheckTemplateIdType(TemplateName Template, |
| 8216 | SourceLocation TemplateLoc, |
| 8217 | TemplateArgumentListInfo &TemplateArgs); |
| 8218 | |
| 8219 | TypeResult |
| 8220 | ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 8221 | TemplateTy Template, IdentifierInfo *TemplateII, |
| 8222 | SourceLocation TemplateIILoc, SourceLocation LAngleLoc, |
| 8223 | ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, |
| 8224 | bool IsCtorOrDtorName = false, bool IsClassName = false, |
| 8225 | ImplicitTypenameContext AllowImplicitTypename = |
| 8226 | ImplicitTypenameContext::No); |
| 8227 | |
| 8228 | /// Parsed an elaborated-type-specifier that refers to a template-id, |
| 8229 | /// such as \c class T::template apply<U>. |
| 8230 | TypeResult ActOnTagTemplateIdType(TagUseKind TUK, |
| 8231 | TypeSpecifierType TagSpec, |
| 8232 | SourceLocation TagLoc, |
| 8233 | CXXScopeSpec &SS, |
| 8234 | SourceLocation TemplateKWLoc, |
| 8235 | TemplateTy TemplateD, |
| 8236 | SourceLocation TemplateLoc, |
| 8237 | SourceLocation LAngleLoc, |
| 8238 | ASTTemplateArgsPtr TemplateArgsIn, |
| 8239 | SourceLocation RAngleLoc); |
| 8240 | |
| 8241 | DeclResult ActOnVarTemplateSpecialization( |
| 8242 | Scope *S, Declarator &D, TypeSourceInfo *DI, |
| 8243 | SourceLocation TemplateKWLoc, TemplateParameterList *TemplateParams, |
| 8244 | StorageClass SC, bool IsPartialSpecialization); |
| 8245 | |
| 8246 | /// Get the specialization of the given variable template corresponding to |
| 8247 | /// the specified argument list, or a null-but-valid result if the arguments |
| 8248 | /// are dependent. |
| 8249 | DeclResult CheckVarTemplateId(VarTemplateDecl *Template, |
| 8250 | SourceLocation TemplateLoc, |
| 8251 | SourceLocation TemplateNameLoc, |
| 8252 | const TemplateArgumentListInfo &TemplateArgs); |
| 8253 | |
| 8254 | /// Form a reference to the specialization of the given variable template |
| 8255 | /// corresponding to the specified argument list, or a null-but-valid result |
| 8256 | /// if the arguments are dependent. |
| 8257 | ExprResult CheckVarTemplateId(const CXXScopeSpec &SS, |
| 8258 | const DeclarationNameInfo &NameInfo, |
| 8259 | VarTemplateDecl *Template, |
| 8260 | SourceLocation TemplateLoc, |
| 8261 | const TemplateArgumentListInfo *TemplateArgs); |
| 8262 | |
| 8263 | ExprResult |
| 8264 | CheckConceptTemplateId(const CXXScopeSpec &SS, |
| 8265 | SourceLocation TemplateKWLoc, |
| 8266 | const DeclarationNameInfo &ConceptNameInfo, |
| 8267 | NamedDecl *FoundDecl, ConceptDecl *NamedConcept, |
| 8268 | const TemplateArgumentListInfo *TemplateArgs); |
| 8269 | |
| 8270 | void diagnoseMissingTemplateArguments(TemplateName Name, SourceLocation Loc); |
| 8271 | |
| 8272 | ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 8273 | SourceLocation TemplateKWLoc, |
| 8274 | LookupResult &R, |
| 8275 | bool RequiresADL, |
| 8276 | const TemplateArgumentListInfo *TemplateArgs); |
| 8277 | |
| 8278 | ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, |
| 8279 | SourceLocation TemplateKWLoc, |
| 8280 | const DeclarationNameInfo &NameInfo, |
| 8281 | const TemplateArgumentListInfo *TemplateArgs); |
| 8282 | |
| 8283 | TemplateNameKind ActOnTemplateName( |
| 8284 | Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, |
| 8285 | const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, |
| 8286 | TemplateTy &Template, bool AllowInjectedClassName = false); |
| 8287 | |
| 8288 | DeclResult ActOnClassTemplateSpecialization( |
| 8289 | Scope *S, unsigned TagSpec, TagUseKind TUK, SourceLocation KWLoc, |
| 8290 | SourceLocation ModulePrivateLoc, CXXScopeSpec &SS, |
| 8291 | TemplateIdAnnotation &TemplateId, const ParsedAttributesView &Attr, |
| 8292 | MultiTemplateParamsArg TemplateParameterLists, |
| 8293 | SkipBodyInfo *SkipBody = nullptr); |
| 8294 | |
| 8295 | bool CheckTemplatePartialSpecializationArgs(SourceLocation Loc, |
| 8296 | TemplateDecl *PrimaryTemplate, |
| 8297 | unsigned NumExplicitArgs, |
| 8298 | ArrayRef<TemplateArgument> Args); |
| 8299 | void CheckTemplatePartialSpecialization( |
| 8300 | ClassTemplatePartialSpecializationDecl *Partial); |
| 8301 | void CheckTemplatePartialSpecialization( |
| 8302 | VarTemplatePartialSpecializationDecl *Partial); |
| 8303 | |
| 8304 | Decl *ActOnTemplateDeclarator(Scope *S, |
| 8305 | MultiTemplateParamsArg TemplateParameterLists, |
| 8306 | Declarator &D); |
| 8307 | |
| 8308 | bool |
| 8309 | CheckSpecializationInstantiationRedecl(SourceLocation NewLoc, |
| 8310 | TemplateSpecializationKind NewTSK, |
| 8311 | NamedDecl *PrevDecl, |
| 8312 | TemplateSpecializationKind PrevTSK, |
| 8313 | SourceLocation PrevPtOfInstantiation, |
| 8314 | bool &SuppressNew); |
| 8315 | |
| 8316 | bool CheckDependentFunctionTemplateSpecialization(FunctionDecl *FD, |
| 8317 | const TemplateArgumentListInfo &ExplicitTemplateArgs, |
| 8318 | LookupResult &Previous); |
| 8319 | |
| 8320 | bool CheckFunctionTemplateSpecialization( |
| 8321 | FunctionDecl *FD, TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 8322 | LookupResult &Previous, bool QualifiedFriend = false); |
| 8323 | bool CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
| 8324 | void CompleteMemberSpecialization(NamedDecl *Member, LookupResult &Previous); |
| 8325 | |
| 8326 | DeclResult ActOnExplicitInstantiation( |
| 8327 | Scope *S, SourceLocation ExternLoc, SourceLocation TemplateLoc, |
| 8328 | unsigned TagSpec, SourceLocation KWLoc, const CXXScopeSpec &SS, |
| 8329 | TemplateTy Template, SourceLocation TemplateNameLoc, |
| 8330 | SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, |
| 8331 | SourceLocation RAngleLoc, const ParsedAttributesView &Attr); |
| 8332 | |
| 8333 | DeclResult ActOnExplicitInstantiation(Scope *S, SourceLocation ExternLoc, |
| 8334 | SourceLocation TemplateLoc, |
| 8335 | unsigned TagSpec, SourceLocation KWLoc, |
| 8336 | CXXScopeSpec &SS, IdentifierInfo *Name, |
| 8337 | SourceLocation NameLoc, |
| 8338 | const ParsedAttributesView &Attr); |
| 8339 | |
| 8340 | DeclResult ActOnExplicitInstantiation(Scope *S, |
| 8341 | SourceLocation ExternLoc, |
| 8342 | SourceLocation TemplateLoc, |
| 8343 | Declarator &D); |
| 8344 | |
| 8345 | TemplateArgumentLoc SubstDefaultTemplateArgumentIfAvailable( |
| 8346 | TemplateDecl *Template, SourceLocation TemplateLoc, |
| 8347 | SourceLocation RAngleLoc, Decl *Param, |
| 8348 | ArrayRef<TemplateArgument> SugaredConverted, |
| 8349 | ArrayRef<TemplateArgument> CanonicalConverted, bool &HasDefaultArg); |
| 8350 | |
| 8351 | /// Specifies the context in which a particular template |
| 8352 | /// argument is being checked. |
| 8353 | enum CheckTemplateArgumentKind { |
| 8354 | /// The template argument was specified in the code or was |
| 8355 | /// instantiated with some deduced template arguments. |
| 8356 | CTAK_Specified, |
| 8357 | |
| 8358 | /// The template argument was deduced via template argument |
| 8359 | /// deduction. |
| 8360 | CTAK_Deduced, |
| 8361 | |
| 8362 | /// The template argument was deduced from an array bound |
| 8363 | /// via template argument deduction. |
| 8364 | CTAK_DeducedFromArrayBound |
| 8365 | }; |
| 8366 | |
| 8367 | bool |
| 8368 | CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, |
| 8369 | NamedDecl *Template, SourceLocation TemplateLoc, |
| 8370 | SourceLocation RAngleLoc, unsigned ArgumentPackIndex, |
| 8371 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
| 8372 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
| 8373 | CheckTemplateArgumentKind CTAK); |
| 8374 | |
| 8375 | /// Check that the given template arguments can be provided to |
| 8376 | /// the given template, converting the arguments along the way. |
| 8377 | /// |
| 8378 | /// \param Template The template to which the template arguments are being |
| 8379 | /// provided. |
| 8380 | /// |
| 8381 | /// \param TemplateLoc The location of the template name in the source. |
| 8382 | /// |
| 8383 | /// \param TemplateArgs The list of template arguments. If the template is |
| 8384 | /// a template template parameter, this function may extend the set of |
| 8385 | /// template arguments to also include substituted, defaulted template |
| 8386 | /// arguments. |
| 8387 | /// |
| 8388 | /// \param PartialTemplateArgs True if the list of template arguments is |
| 8389 | /// intentionally partial, e.g., because we're checking just the initial |
| 8390 | /// set of template arguments. |
| 8391 | /// |
| 8392 | /// \param Converted Will receive the converted, canonicalized template |
| 8393 | /// arguments. |
| 8394 | /// |
| 8395 | /// \param UpdateArgsWithConversions If \c true, update \p TemplateArgs to |
| 8396 | /// contain the converted forms of the template arguments as written. |
| 8397 | /// Otherwise, \p TemplateArgs will not be modified. |
| 8398 | /// |
| 8399 | /// \param ConstraintsNotSatisfied If provided, and an error occurred, will |
| 8400 | /// receive true if the cause for the error is the associated constraints of |
| 8401 | /// the template not being satisfied by the template arguments. |
| 8402 | /// |
| 8403 | /// \returns true if an error occurred, false otherwise. |
| 8404 | bool CheckTemplateArgumentList( |
| 8405 | TemplateDecl *Template, SourceLocation TemplateLoc, |
| 8406 | TemplateArgumentListInfo &TemplateArgs, bool PartialTemplateArgs, |
| 8407 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
| 8408 | SmallVectorImpl<TemplateArgument> &CanonicalConverted, |
| 8409 | bool UpdateArgsWithConversions = true, |
| 8410 | bool *ConstraintsNotSatisfied = nullptr); |
| 8411 | |
| 8412 | bool CheckTemplateTypeArgument( |
| 8413 | TemplateTypeParmDecl *Param, TemplateArgumentLoc &Arg, |
| 8414 | SmallVectorImpl<TemplateArgument> &SugaredConverted, |
| 8415 | SmallVectorImpl<TemplateArgument> &CanonicalConverted); |
| 8416 | |
| 8417 | bool CheckTemplateArgument(TypeSourceInfo *Arg); |
| 8418 | ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param, |
| 8419 | QualType InstantiatedParamType, Expr *Arg, |
| 8420 | TemplateArgument &SugaredConverted, |
| 8421 | TemplateArgument &CanonicalConverted, |
| 8422 | CheckTemplateArgumentKind CTAK); |
| 8423 | bool CheckTemplateTemplateArgument(TemplateTemplateParmDecl *Param, |
| 8424 | TemplateParameterList *Params, |
| 8425 | TemplateArgumentLoc &Arg); |
| 8426 | |
| 8427 | ExprResult |
| 8428 | BuildExpressionFromDeclTemplateArgument(const TemplateArgument &Arg, |
| 8429 | QualType ParamType, |
| 8430 | SourceLocation Loc); |
| 8431 | ExprResult |
| 8432 | BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, |
| 8433 | SourceLocation Loc); |
| 8434 | |
| 8435 | /// Enumeration describing how template parameter lists are compared |
| 8436 | /// for equality. |
| 8437 | enum TemplateParameterListEqualKind { |
| 8438 | /// We are matching the template parameter lists of two templates |
| 8439 | /// that might be redeclarations. |
| 8440 | /// |
| 8441 | /// \code |
| 8442 | /// template<typename T> struct X; |
| 8443 | /// template<typename T> struct X; |
| 8444 | /// \endcode |
| 8445 | TPL_TemplateMatch, |
| 8446 | |
| 8447 | /// We are matching the template parameter lists of two template |
| 8448 | /// template parameters as part of matching the template parameter lists |
| 8449 | /// of two templates that might be redeclarations. |
| 8450 | /// |
| 8451 | /// \code |
| 8452 | /// template<template<int I> class TT> struct X; |
| 8453 | /// template<template<int Value> class Other> struct X; |
| 8454 | /// \endcode |
| 8455 | TPL_TemplateTemplateParmMatch, |
| 8456 | |
| 8457 | /// We are matching the template parameter lists of a template |
| 8458 | /// template argument against the template parameter lists of a template |
| 8459 | /// template parameter. |
| 8460 | /// |
| 8461 | /// \code |
| 8462 | /// template<template<int Value> class Metafun> struct X; |
| 8463 | /// template<int Value> struct integer_c; |
| 8464 | /// X<integer_c> xic; |
| 8465 | /// \endcode |
| 8466 | TPL_TemplateTemplateArgumentMatch, |
| 8467 | |
| 8468 | /// We are determining whether the template-parameters are equivalent |
| 8469 | /// according to C++ [temp.over.link]/6. This comparison does not consider |
| 8470 | /// constraints. |
| 8471 | /// |
| 8472 | /// \code |
| 8473 | /// template<C1 T> void f(T); |
| 8474 | /// template<C2 T> void f(T); |
| 8475 | /// \endcode |
| 8476 | TPL_TemplateParamsEquivalent, |
| 8477 | }; |
| 8478 | |
| 8479 | bool TemplateParameterListsAreEqual( |
| 8480 | const NamedDecl *NewInstFrom, TemplateParameterList *New, |
| 8481 | const NamedDecl *OldInstFrom, TemplateParameterList *Old, bool Complain, |
| 8482 | TemplateParameterListEqualKind Kind, |
| 8483 | SourceLocation TemplateArgLoc = SourceLocation()); |
| 8484 | |
| 8485 | bool TemplateParameterListsAreEqual( |
| 8486 | TemplateParameterList *New, TemplateParameterList *Old, bool Complain, |
| 8487 | TemplateParameterListEqualKind Kind, |
| 8488 | SourceLocation TemplateArgLoc = SourceLocation()) { |
| 8489 | return TemplateParameterListsAreEqual(nullptr, New, nullptr, Old, Complain, |
| 8490 | Kind, TemplateArgLoc); |
| 8491 | } |
| 8492 | |
| 8493 | bool CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams); |
| 8494 | |
| 8495 | /// Called when the parser has parsed a C++ typename |
| 8496 | /// specifier, e.g., "typename T::type". |
| 8497 | /// |
| 8498 | /// \param S The scope in which this typename type occurs. |
| 8499 | /// \param TypenameLoc the location of the 'typename' keyword |
| 8500 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
| 8501 | /// \param II the identifier we're retrieving (e.g., 'type' in the example). |
| 8502 | /// \param IdLoc the location of the identifier. |
| 8503 | /// \param IsImplicitTypename context where T::type refers to a type. |
| 8504 | TypeResult ActOnTypenameType( |
| 8505 | Scope *S, SourceLocation TypenameLoc, const CXXScopeSpec &SS, |
| 8506 | const IdentifierInfo &II, SourceLocation IdLoc, |
| 8507 | ImplicitTypenameContext IsImplicitTypename = ImplicitTypenameContext::No); |
| 8508 | |
| 8509 | /// Called when the parser has parsed a C++ typename |
| 8510 | /// specifier that ends in a template-id, e.g., |
| 8511 | /// "typename MetaFun::template apply<T1, T2>". |
| 8512 | /// |
| 8513 | /// \param S The scope in which this typename type occurs. |
| 8514 | /// \param TypenameLoc the location of the 'typename' keyword |
| 8515 | /// \param SS the nested-name-specifier following the typename (e.g., 'T::'). |
| 8516 | /// \param TemplateLoc the location of the 'template' keyword, if any. |
| 8517 | /// \param TemplateName The template name. |
| 8518 | /// \param TemplateII The identifier used to name the template. |
| 8519 | /// \param TemplateIILoc The location of the template name. |
| 8520 | /// \param LAngleLoc The location of the opening angle bracket ('<'). |
| 8521 | /// \param TemplateArgs The template arguments. |
| 8522 | /// \param RAngleLoc The location of the closing angle bracket ('>'). |
| 8523 | TypeResult |
| 8524 | ActOnTypenameType(Scope *S, SourceLocation TypenameLoc, |
| 8525 | const CXXScopeSpec &SS, |
| 8526 | SourceLocation TemplateLoc, |
| 8527 | TemplateTy TemplateName, |
| 8528 | IdentifierInfo *TemplateII, |
| 8529 | SourceLocation TemplateIILoc, |
| 8530 | SourceLocation LAngleLoc, |
| 8531 | ASTTemplateArgsPtr TemplateArgs, |
| 8532 | SourceLocation RAngleLoc); |
| 8533 | |
| 8534 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
| 8535 | SourceLocation KeywordLoc, |
| 8536 | NestedNameSpecifierLoc QualifierLoc, |
| 8537 | const IdentifierInfo &II, |
| 8538 | SourceLocation IILoc, |
| 8539 | TypeSourceInfo **TSI, |
| 8540 | bool DeducedTSTContext); |
| 8541 | |
| 8542 | QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, |
| 8543 | SourceLocation KeywordLoc, |
| 8544 | NestedNameSpecifierLoc QualifierLoc, |
| 8545 | const IdentifierInfo &II, |
| 8546 | SourceLocation IILoc, |
| 8547 | bool DeducedTSTContext = true); |
| 8548 | |
| 8549 | |
| 8550 | TypeSourceInfo *RebuildTypeInCurrentInstantiation(TypeSourceInfo *T, |
| 8551 | SourceLocation Loc, |
| 8552 | DeclarationName Name); |
| 8553 | bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS); |
| 8554 | |
| 8555 | ExprResult RebuildExprInCurrentInstantiation(Expr *E); |
| 8556 | bool RebuildTemplateParamsInCurrentInstantiation( |
| 8557 | TemplateParameterList *Params); |
| 8558 | |
| 8559 | std::string |
| 8560 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
| 8561 | const TemplateArgumentList &Args); |
| 8562 | |
| 8563 | std::string |
| 8564 | getTemplateArgumentBindingsText(const TemplateParameterList *Params, |
| 8565 | const TemplateArgument *Args, |
| 8566 | unsigned NumArgs); |
| 8567 | |
| 8568 | //===--------------------------------------------------------------------===// |
| 8569 | // C++ Concepts |
| 8570 | //===--------------------------------------------------------------------===// |
| 8571 | Decl *ActOnConceptDefinition( |
| 8572 | Scope *S, MultiTemplateParamsArg TemplateParameterLists, |
| 8573 | IdentifierInfo *Name, SourceLocation NameLoc, Expr *ConstraintExpr); |
| 8574 | |
| 8575 | void CheckConceptRedefinition(ConceptDecl *NewDecl, LookupResult &Previous, |
| 8576 | bool &AddToScope); |
| 8577 | |
| 8578 | RequiresExprBodyDecl * |
| 8579 | ActOnStartRequiresExpr(SourceLocation RequiresKWLoc, |
| 8580 | ArrayRef<ParmVarDecl *> LocalParameters, |
| 8581 | Scope *BodyScope); |
| 8582 | void ActOnFinishRequiresExpr(); |
| 8583 | concepts::Requirement *ActOnSimpleRequirement(Expr *E); |
| 8584 | concepts::Requirement *ActOnTypeRequirement( |
| 8585 | SourceLocation TypenameKWLoc, CXXScopeSpec &SS, SourceLocation NameLoc, |
| 8586 | IdentifierInfo *TypeName, TemplateIdAnnotation *TemplateId); |
| 8587 | concepts::Requirement *ActOnCompoundRequirement(Expr *E, |
| 8588 | SourceLocation NoexceptLoc); |
| 8589 | concepts::Requirement * |
| 8590 | ActOnCompoundRequirement( |
| 8591 | Expr *E, SourceLocation NoexceptLoc, CXXScopeSpec &SS, |
| 8592 | TemplateIdAnnotation *TypeConstraint, unsigned Depth); |
| 8593 | concepts::Requirement *ActOnNestedRequirement(Expr *Constraint); |
| 8594 | concepts::ExprRequirement * |
| 8595 | BuildExprRequirement( |
| 8596 | Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, |
| 8597 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
| 8598 | concepts::ExprRequirement * |
| 8599 | BuildExprRequirement( |
| 8600 | concepts::Requirement::SubstitutionDiagnostic *ExprSubstDiag, |
| 8601 | bool IsSatisfied, SourceLocation NoexceptLoc, |
| 8602 | concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement); |
| 8603 | concepts::TypeRequirement *BuildTypeRequirement(TypeSourceInfo *Type); |
| 8604 | concepts::TypeRequirement * |
| 8605 | BuildTypeRequirement( |
| 8606 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag); |
| 8607 | concepts::NestedRequirement *BuildNestedRequirement(Expr *E); |
| 8608 | concepts::NestedRequirement * |
| 8609 | BuildNestedRequirement(StringRef InvalidConstraintEntity, |
| 8610 | const ASTConstraintSatisfaction &Satisfaction); |
| 8611 | ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc, |
| 8612 | RequiresExprBodyDecl *Body, |
| 8613 | ArrayRef<ParmVarDecl *> LocalParameters, |
| 8614 | ArrayRef<concepts::Requirement *> Requirements, |
| 8615 | SourceLocation ClosingBraceLoc); |
| 8616 | |
| 8617 | //===--------------------------------------------------------------------===// |
| 8618 | // C++ Variadic Templates (C++0x [temp.variadic]) |
| 8619 | //===--------------------------------------------------------------------===// |
| 8620 | |
| 8621 | /// Determine whether an unexpanded parameter pack might be permitted in this |
| 8622 | /// location. Useful for error recovery. |
| 8623 | bool isUnexpandedParameterPackPermitted(); |
| 8624 | |
| 8625 | /// The context in which an unexpanded parameter pack is |
| 8626 | /// being diagnosed. |
| 8627 | /// |
| 8628 | /// Note that the values of this enumeration line up with the first |
| 8629 | /// argument to the \c err_unexpanded_parameter_pack diagnostic. |
| 8630 | enum UnexpandedParameterPackContext { |
| 8631 | /// An arbitrary expression. |
| 8632 | UPPC_Expression = 0, |
| 8633 | |
| 8634 | /// The base type of a class type. |
| 8635 | UPPC_BaseType, |
| 8636 | |
| 8637 | /// The type of an arbitrary declaration. |
| 8638 | UPPC_DeclarationType, |
| 8639 | |
| 8640 | /// The type of a data member. |
| 8641 | UPPC_DataMemberType, |
| 8642 | |
| 8643 | /// The size of a bit-field. |
| 8644 | UPPC_BitFieldWidth, |
| 8645 | |
| 8646 | /// The expression in a static assertion. |
| 8647 | UPPC_StaticAssertExpression, |
| 8648 | |
| 8649 | /// The fixed underlying type of an enumeration. |
| 8650 | UPPC_FixedUnderlyingType, |
| 8651 | |
| 8652 | /// The enumerator value. |
| 8653 | UPPC_EnumeratorValue, |
| 8654 | |
| 8655 | /// A using declaration. |
| 8656 | UPPC_UsingDeclaration, |
| 8657 | |
| 8658 | /// A friend declaration. |
| 8659 | UPPC_FriendDeclaration, |
| 8660 | |
| 8661 | /// A declaration qualifier. |
| 8662 | UPPC_DeclarationQualifier, |
| 8663 | |
| 8664 | /// An initializer. |
| 8665 | UPPC_Initializer, |
| 8666 | |
| 8667 | /// A default argument. |
| 8668 | UPPC_DefaultArgument, |
| 8669 | |
| 8670 | /// The type of a non-type template parameter. |
| 8671 | UPPC_NonTypeTemplateParameterType, |
| 8672 | |
| 8673 | /// The type of an exception. |
| 8674 | UPPC_ExceptionType, |
| 8675 | |
| 8676 | /// Partial specialization. |
| 8677 | UPPC_PartialSpecialization, |
| 8678 | |
| 8679 | /// Microsoft __if_exists. |
| 8680 | UPPC_IfExists, |
| 8681 | |
| 8682 | /// Microsoft __if_not_exists. |
| 8683 | UPPC_IfNotExists, |
| 8684 | |
| 8685 | /// Lambda expression. |
| 8686 | UPPC_Lambda, |
| 8687 | |
| 8688 | /// Block expression. |
| 8689 | UPPC_Block, |
| 8690 | |
| 8691 | /// A type constraint. |
| 8692 | UPPC_TypeConstraint, |
| 8693 | |
| 8694 | // A requirement in a requires-expression. |
| 8695 | UPPC_Requirement, |
| 8696 | |
| 8697 | // A requires-clause. |
| 8698 | UPPC_RequiresClause, |
| 8699 | }; |
| 8700 | |
| 8701 | /// Diagnose unexpanded parameter packs. |
| 8702 | /// |
| 8703 | /// \param Loc The location at which we should emit the diagnostic. |
| 8704 | /// |
| 8705 | /// \param UPPC The context in which we are diagnosing unexpanded |
| 8706 | /// parameter packs. |
| 8707 | /// |
| 8708 | /// \param Unexpanded the set of unexpanded parameter packs. |
| 8709 | /// |
| 8710 | /// \returns true if an error occurred, false otherwise. |
| 8711 | bool DiagnoseUnexpandedParameterPacks(SourceLocation Loc, |
| 8712 | UnexpandedParameterPackContext UPPC, |
| 8713 | ArrayRef<UnexpandedParameterPack> Unexpanded); |
| 8714 | |
| 8715 | /// If the given type contains an unexpanded parameter pack, |
| 8716 | /// diagnose the error. |
| 8717 | /// |
| 8718 | /// \param Loc The source location where a diagnostc should be emitted. |
| 8719 | /// |
| 8720 | /// \param T The type that is being checked for unexpanded parameter |
| 8721 | /// packs. |
| 8722 | /// |
| 8723 | /// \returns true if an error occurred, false otherwise. |
| 8724 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, TypeSourceInfo *T, |
| 8725 | UnexpandedParameterPackContext UPPC); |
| 8726 | |
| 8727 | /// If the given expression contains an unexpanded parameter |
| 8728 | /// pack, diagnose the error. |
| 8729 | /// |
| 8730 | /// \param E The expression that is being checked for unexpanded |
| 8731 | /// parameter packs. |
| 8732 | /// |
| 8733 | /// \returns true if an error occurred, false otherwise. |
| 8734 | bool DiagnoseUnexpandedParameterPack(Expr *E, |
| 8735 | UnexpandedParameterPackContext UPPC = UPPC_Expression); |
| 8736 | |
| 8737 | /// If the given requirees-expression contains an unexpanded reference to one |
| 8738 | /// of its own parameter packs, diagnose the error. |
| 8739 | /// |
| 8740 | /// \param RE The requiress-expression that is being checked for unexpanded |
| 8741 | /// parameter packs. |
| 8742 | /// |
| 8743 | /// \returns true if an error occurred, false otherwise. |
| 8744 | bool DiagnoseUnexpandedParameterPackInRequiresExpr(RequiresExpr *RE); |
| 8745 | |
| 8746 | /// If the given nested-name-specifier contains an unexpanded |
| 8747 | /// parameter pack, diagnose the error. |
| 8748 | /// |
| 8749 | /// \param SS The nested-name-specifier that is being checked for |
| 8750 | /// unexpanded parameter packs. |
| 8751 | /// |
| 8752 | /// \returns true if an error occurred, false otherwise. |
| 8753 | bool DiagnoseUnexpandedParameterPack(const CXXScopeSpec &SS, |
| 8754 | UnexpandedParameterPackContext UPPC); |
| 8755 | |
| 8756 | /// If the given name contains an unexpanded parameter pack, |
| 8757 | /// diagnose the error. |
| 8758 | /// |
| 8759 | /// \param NameInfo The name (with source location information) that |
| 8760 | /// is being checked for unexpanded parameter packs. |
| 8761 | /// |
| 8762 | /// \returns true if an error occurred, false otherwise. |
| 8763 | bool DiagnoseUnexpandedParameterPack(const DeclarationNameInfo &NameInfo, |
| 8764 | UnexpandedParameterPackContext UPPC); |
| 8765 | |
| 8766 | /// If the given template name contains an unexpanded parameter pack, |
| 8767 | /// diagnose the error. |
| 8768 | /// |
| 8769 | /// \param Loc The location of the template name. |
| 8770 | /// |
| 8771 | /// \param Template The template name that is being checked for unexpanded |
| 8772 | /// parameter packs. |
| 8773 | /// |
| 8774 | /// \returns true if an error occurred, false otherwise. |
| 8775 | bool DiagnoseUnexpandedParameterPack(SourceLocation Loc, |
| 8776 | TemplateName Template, |
| 8777 | UnexpandedParameterPackContext UPPC); |
| 8778 | |
| 8779 | /// If the given template argument contains an unexpanded parameter |
| 8780 | /// pack, diagnose the error. |
| 8781 | /// |
| 8782 | /// \param Arg The template argument that is being checked for unexpanded |
| 8783 | /// parameter packs. |
| 8784 | /// |
| 8785 | /// \returns true if an error occurred, false otherwise. |
| 8786 | bool DiagnoseUnexpandedParameterPack(TemplateArgumentLoc Arg, |
| 8787 | UnexpandedParameterPackContext UPPC); |
| 8788 | |
| 8789 | /// Collect the set of unexpanded parameter packs within the given |
| 8790 | /// template argument. |
| 8791 | /// |
| 8792 | /// \param Arg The template argument that will be traversed to find |
| 8793 | /// unexpanded parameter packs. |
| 8794 | void collectUnexpandedParameterPacks(TemplateArgument Arg, |
| 8795 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 8796 | |
| 8797 | /// Collect the set of unexpanded parameter packs within the given |
| 8798 | /// template argument. |
| 8799 | /// |
| 8800 | /// \param Arg The template argument that will be traversed to find |
| 8801 | /// unexpanded parameter packs. |
| 8802 | void collectUnexpandedParameterPacks(TemplateArgumentLoc Arg, |
| 8803 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 8804 | |
| 8805 | /// Collect the set of unexpanded parameter packs within the given |
| 8806 | /// type. |
| 8807 | /// |
| 8808 | /// \param T The type that will be traversed to find |
| 8809 | /// unexpanded parameter packs. |
| 8810 | void collectUnexpandedParameterPacks(QualType T, |
| 8811 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 8812 | |
| 8813 | /// Collect the set of unexpanded parameter packs within the given |
| 8814 | /// type. |
| 8815 | /// |
| 8816 | /// \param TL The type that will be traversed to find |
| 8817 | /// unexpanded parameter packs. |
| 8818 | void collectUnexpandedParameterPacks(TypeLoc TL, |
| 8819 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 8820 | |
| 8821 | /// Collect the set of unexpanded parameter packs within the given |
| 8822 | /// nested-name-specifier. |
| 8823 | /// |
| 8824 | /// \param NNS The nested-name-specifier that will be traversed to find |
| 8825 | /// unexpanded parameter packs. |
| 8826 | void collectUnexpandedParameterPacks(NestedNameSpecifierLoc NNS, |
| 8827 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 8828 | |
| 8829 | /// Collect the set of unexpanded parameter packs within the given |
| 8830 | /// name. |
| 8831 | /// |
| 8832 | /// \param NameInfo The name that will be traversed to find |
| 8833 | /// unexpanded parameter packs. |
| 8834 | void collectUnexpandedParameterPacks(const DeclarationNameInfo &NameInfo, |
| 8835 | SmallVectorImpl<UnexpandedParameterPack> &Unexpanded); |
| 8836 | |
| 8837 | /// Invoked when parsing a template argument followed by an |
| 8838 | /// ellipsis, which creates a pack expansion. |
| 8839 | /// |
| 8840 | /// \param Arg The template argument preceding the ellipsis, which |
| 8841 | /// may already be invalid. |
| 8842 | /// |
| 8843 | /// \param EllipsisLoc The location of the ellipsis. |
| 8844 | ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, |
| 8845 | SourceLocation EllipsisLoc); |
| 8846 | |
| 8847 | /// Invoked when parsing a type followed by an ellipsis, which |
| 8848 | /// creates a pack expansion. |
| 8849 | /// |
| 8850 | /// \param Type The type preceding the ellipsis, which will become |
| 8851 | /// the pattern of the pack expansion. |
| 8852 | /// |
| 8853 | /// \param EllipsisLoc The location of the ellipsis. |
| 8854 | TypeResult ActOnPackExpansion(ParsedType Type, SourceLocation EllipsisLoc); |
| 8855 | |
| 8856 | /// Construct a pack expansion type from the pattern of the pack |
| 8857 | /// expansion. |
| 8858 | TypeSourceInfo *CheckPackExpansion(TypeSourceInfo *Pattern, |
| 8859 | SourceLocation EllipsisLoc, |
| 8860 | std::optional<unsigned> NumExpansions); |
| 8861 | |
| 8862 | /// Construct a pack expansion type from the pattern of the pack |
| 8863 | /// expansion. |
| 8864 | QualType CheckPackExpansion(QualType Pattern, SourceRange PatternRange, |
| 8865 | SourceLocation EllipsisLoc, |
| 8866 | std::optional<unsigned> NumExpansions); |
| 8867 | |
| 8868 | /// Invoked when parsing an expression followed by an ellipsis, which |
| 8869 | /// creates a pack expansion. |
| 8870 | /// |
| 8871 | /// \param Pattern The expression preceding the ellipsis, which will become |
| 8872 | /// the pattern of the pack expansion. |
| 8873 | /// |
| 8874 | /// \param EllipsisLoc The location of the ellipsis. |
| 8875 | ExprResult ActOnPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc); |
| 8876 | |
| 8877 | /// Invoked when parsing an expression followed by an ellipsis, which |
| 8878 | /// creates a pack expansion. |
| 8879 | /// |
| 8880 | /// \param Pattern The expression preceding the ellipsis, which will become |
| 8881 | /// the pattern of the pack expansion. |
| 8882 | /// |
| 8883 | /// \param EllipsisLoc The location of the ellipsis. |
| 8884 | ExprResult CheckPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 8885 | std::optional<unsigned> NumExpansions); |
| 8886 | |
| 8887 | /// Determine whether we could expand a pack expansion with the |
| 8888 | /// given set of parameter packs into separate arguments by repeatedly |
| 8889 | /// transforming the pattern. |
| 8890 | /// |
| 8891 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 8892 | /// pack expansion. |
| 8893 | /// |
| 8894 | /// \param PatternRange The source range that covers the entire pattern of |
| 8895 | /// the pack expansion. |
| 8896 | /// |
| 8897 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 8898 | /// pattern. |
| 8899 | /// |
| 8900 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 8901 | /// expand the corresponding pack expansions into separate arguments. When |
| 8902 | /// set, \c NumExpansions must also be set. |
| 8903 | /// |
| 8904 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 8905 | /// pack expansion after all of the expanded arguments. This is used |
| 8906 | /// when extending explicitly-specified template argument packs per |
| 8907 | /// C++0x [temp.arg.explicit]p9. |
| 8908 | /// |
| 8909 | /// \param NumExpansions The number of separate arguments that will be in |
| 8910 | /// the expanded form of the corresponding pack expansion. This is both an |
| 8911 | /// input and an output parameter, which can be set by the caller if the |
| 8912 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 8913 | /// and will be set by the callee when the number of expansions is known. |
| 8914 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 8915 | /// set this value in other cases. |
| 8916 | /// |
| 8917 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 8918 | /// are to be instantiated with arguments of different lengths), false |
| 8919 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 8920 | /// must be set. |
| 8921 | bool CheckParameterPacksForExpansion( |
| 8922 | SourceLocation EllipsisLoc, SourceRange PatternRange, |
| 8923 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
| 8924 | const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand, |
| 8925 | bool &RetainExpansion, std::optional<unsigned> &NumExpansions); |
| 8926 | |
| 8927 | /// Determine the number of arguments in the given pack expansion |
| 8928 | /// type. |
| 8929 | /// |
| 8930 | /// This routine assumes that the number of arguments in the expansion is |
| 8931 | /// consistent across all of the unexpanded parameter packs in its pattern. |
| 8932 | /// |
| 8933 | /// Returns an empty Optional if the type can't be expanded. |
| 8934 | std::optional<unsigned> getNumArgumentsInExpansion( |
| 8935 | QualType T, const MultiLevelTemplateArgumentList &TemplateArgs); |
| 8936 | |
| 8937 | /// Determine whether the given declarator contains any unexpanded |
| 8938 | /// parameter packs. |
| 8939 | /// |
| 8940 | /// This routine is used by the parser to disambiguate function declarators |
| 8941 | /// with an ellipsis prior to the ')', e.g., |
| 8942 | /// |
| 8943 | /// \code |
| 8944 | /// void f(T...); |
| 8945 | /// \endcode |
| 8946 | /// |
| 8947 | /// To determine whether we have an (unnamed) function parameter pack or |
| 8948 | /// a variadic function. |
| 8949 | /// |
| 8950 | /// \returns true if the declarator contains any unexpanded parameter packs, |
| 8951 | /// false otherwise. |
| 8952 | bool containsUnexpandedParameterPacks(Declarator &D); |
| 8953 | |
| 8954 | /// Returns the pattern of the pack expansion for a template argument. |
| 8955 | /// |
| 8956 | /// \param OrigLoc The template argument to expand. |
| 8957 | /// |
| 8958 | /// \param Ellipsis Will be set to the location of the ellipsis. |
| 8959 | /// |
| 8960 | /// \param NumExpansions Will be set to the number of expansions that will |
| 8961 | /// be generated from this pack expansion, if known a priori. |
| 8962 | TemplateArgumentLoc getTemplateArgumentPackExpansionPattern( |
| 8963 | TemplateArgumentLoc OrigLoc, SourceLocation &Ellipsis, |
| 8964 | std::optional<unsigned> &NumExpansions) const; |
| 8965 | |
| 8966 | /// Given a template argument that contains an unexpanded parameter pack, but |
| 8967 | /// which has already been substituted, attempt to determine the number of |
| 8968 | /// elements that will be produced once this argument is fully-expanded. |
| 8969 | /// |
| 8970 | /// This is intended for use when transforming 'sizeof...(Arg)' in order to |
| 8971 | /// avoid actually expanding the pack where possible. |
| 8972 | std::optional<unsigned> getFullyPackExpandedSize(TemplateArgument Arg); |
| 8973 | |
| 8974 | //===--------------------------------------------------------------------===// |
| 8975 | // C++ Template Argument Deduction (C++ [temp.deduct]) |
| 8976 | //===--------------------------------------------------------------------===// |
| 8977 | |
| 8978 | /// Adjust the type \p ArgFunctionType to match the calling convention, |
| 8979 | /// noreturn, and optionally the exception specification of \p FunctionType. |
| 8980 | /// Deduction often wants to ignore these properties when matching function |
| 8981 | /// types. |
| 8982 | QualType adjustCCAndNoReturn(QualType ArgFunctionType, QualType FunctionType, |
| 8983 | bool AdjustExceptionSpec = false); |
| 8984 | |
| 8985 | /// Describes the result of template argument deduction. |
| 8986 | /// |
| 8987 | /// The TemplateDeductionResult enumeration describes the result of |
| 8988 | /// template argument deduction, as returned from |
| 8989 | /// DeduceTemplateArguments(). The separate TemplateDeductionInfo |
| 8990 | /// structure provides additional information about the results of |
| 8991 | /// template argument deduction, e.g., the deduced template argument |
| 8992 | /// list (if successful) or the specific template parameters or |
| 8993 | /// deduced arguments that were involved in the failure. |
| 8994 | enum TemplateDeductionResult { |
| 8995 | /// Template argument deduction was successful. |
| 8996 | TDK_Success = 0, |
| 8997 | /// The declaration was invalid; do nothing. |
| 8998 | TDK_Invalid, |
| 8999 | /// Template argument deduction exceeded the maximum template |
| 9000 | /// instantiation depth (which has already been diagnosed). |
| 9001 | TDK_InstantiationDepth, |
| 9002 | /// Template argument deduction did not deduce a value |
| 9003 | /// for every template parameter. |
| 9004 | TDK_Incomplete, |
| 9005 | /// Template argument deduction did not deduce a value for every |
| 9006 | /// expansion of an expanded template parameter pack. |
| 9007 | TDK_IncompletePack, |
| 9008 | /// Template argument deduction produced inconsistent |
| 9009 | /// deduced values for the given template parameter. |
| 9010 | TDK_Inconsistent, |
| 9011 | /// Template argument deduction failed due to inconsistent |
| 9012 | /// cv-qualifiers on a template parameter type that would |
| 9013 | /// otherwise be deduced, e.g., we tried to deduce T in "const T" |
| 9014 | /// but were given a non-const "X". |
| 9015 | TDK_Underqualified, |
| 9016 | /// Substitution of the deduced template argument values |
| 9017 | /// resulted in an error. |
| 9018 | TDK_SubstitutionFailure, |
| 9019 | /// After substituting deduced template arguments, a dependent |
| 9020 | /// parameter type did not match the corresponding argument. |
| 9021 | TDK_DeducedMismatch, |
| 9022 | /// After substituting deduced template arguments, an element of |
| 9023 | /// a dependent parameter type did not match the corresponding element |
| 9024 | /// of the corresponding argument (when deducing from an initializer list). |
| 9025 | TDK_DeducedMismatchNested, |
| 9026 | /// A non-depnedent component of the parameter did not match the |
| 9027 | /// corresponding component of the argument. |
| 9028 | TDK_NonDeducedMismatch, |
| 9029 | /// When performing template argument deduction for a function |
| 9030 | /// template, there were too many call arguments. |
| 9031 | TDK_TooManyArguments, |
| 9032 | /// When performing template argument deduction for a function |
| 9033 | /// template, there were too few call arguments. |
| 9034 | TDK_TooFewArguments, |
| 9035 | /// The explicitly-specified template arguments were not valid |
| 9036 | /// template arguments for the given template. |
| 9037 | TDK_InvalidExplicitArguments, |
| 9038 | /// Checking non-dependent argument conversions failed. |
| 9039 | TDK_NonDependentConversionFailure, |
| 9040 | /// The deduced arguments did not satisfy the constraints associated |
| 9041 | /// with the template. |
| 9042 | TDK_ConstraintsNotSatisfied, |
| 9043 | /// Deduction failed; that's all we know. |
| 9044 | TDK_MiscellaneousDeductionFailure, |
| 9045 | /// CUDA Target attributes do not match. |
| 9046 | TDK_CUDATargetMismatch, |
| 9047 | /// Some error which was already diagnosed. |
| 9048 | TDK_AlreadyDiagnosed |
| 9049 | }; |
| 9050 | |
| 9051 | TemplateDeductionResult |
| 9052 | DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial, |
| 9053 | const TemplateArgumentList &TemplateArgs, |
| 9054 | sema::TemplateDeductionInfo &Info); |
| 9055 | |
| 9056 | TemplateDeductionResult |
| 9057 | DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial, |
| 9058 | const TemplateArgumentList &TemplateArgs, |
| 9059 | sema::TemplateDeductionInfo &Info); |
| 9060 | |
| 9061 | TemplateDeductionResult SubstituteExplicitTemplateArguments( |
| 9062 | FunctionTemplateDecl *FunctionTemplate, |
| 9063 | TemplateArgumentListInfo &ExplicitTemplateArgs, |
| 9064 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
| 9065 | SmallVectorImpl<QualType> &ParamTypes, QualType *FunctionType, |
| 9066 | sema::TemplateDeductionInfo &Info); |
| 9067 | |
| 9068 | /// brief A function argument from which we performed template argument |
| 9069 | // deduction for a call. |
| 9070 | struct OriginalCallArg { |
| 9071 | OriginalCallArg(QualType OriginalParamType, bool DecomposedParam, |
| 9072 | unsigned ArgIdx, QualType OriginalArgType) |
| 9073 | : OriginalParamType(OriginalParamType), |
| 9074 | DecomposedParam(DecomposedParam), ArgIdx(ArgIdx), |
| 9075 | OriginalArgType(OriginalArgType) {} |
| 9076 | |
| 9077 | QualType OriginalParamType; |
| 9078 | bool DecomposedParam; |
| 9079 | unsigned ArgIdx; |
| 9080 | QualType OriginalArgType; |
| 9081 | }; |
| 9082 | |
| 9083 | TemplateDeductionResult FinishTemplateArgumentDeduction( |
| 9084 | FunctionTemplateDecl *FunctionTemplate, |
| 9085 | SmallVectorImpl<DeducedTemplateArgument> &Deduced, |
| 9086 | unsigned NumExplicitlySpecified, FunctionDecl *&Specialization, |
| 9087 | sema::TemplateDeductionInfo &Info, |
| 9088 | SmallVectorImpl<OriginalCallArg> const *OriginalCallArgs = nullptr, |
| 9089 | bool PartialOverloading = false, |
| 9090 | llvm::function_ref<bool()> CheckNonDependent = []{ return false; }); |
| 9091 | |
| 9092 | TemplateDeductionResult DeduceTemplateArguments( |
| 9093 | FunctionTemplateDecl *FunctionTemplate, |
| 9094 | TemplateArgumentListInfo *ExplicitTemplateArgs, ArrayRef<Expr *> Args, |
| 9095 | FunctionDecl *&Specialization, sema::TemplateDeductionInfo &Info, |
| 9096 | bool PartialOverloading, |
| 9097 | llvm::function_ref<bool(ArrayRef<QualType>)> CheckNonDependent); |
| 9098 | |
| 9099 | TemplateDeductionResult |
| 9100 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
| 9101 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 9102 | QualType ArgFunctionType, |
| 9103 | FunctionDecl *&Specialization, |
| 9104 | sema::TemplateDeductionInfo &Info, |
| 9105 | bool IsAddressOfFunction = false); |
| 9106 | |
| 9107 | TemplateDeductionResult |
| 9108 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
| 9109 | QualType ToType, |
| 9110 | CXXConversionDecl *&Specialization, |
| 9111 | sema::TemplateDeductionInfo &Info); |
| 9112 | |
| 9113 | TemplateDeductionResult |
| 9114 | DeduceTemplateArguments(FunctionTemplateDecl *FunctionTemplate, |
| 9115 | TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 9116 | FunctionDecl *&Specialization, |
| 9117 | sema::TemplateDeductionInfo &Info, |
| 9118 | bool IsAddressOfFunction = false); |
| 9119 | |
| 9120 | /// Substitute Replacement for \p auto in \p TypeWithAuto |
| 9121 | QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement); |
| 9122 | /// Substitute Replacement for auto in TypeWithAuto |
| 9123 | TypeSourceInfo* SubstAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
| 9124 | QualType Replacement); |
| 9125 | |
| 9126 | // Substitute auto in TypeWithAuto for a Dependent auto type |
| 9127 | QualType SubstAutoTypeDependent(QualType TypeWithAuto); |
| 9128 | |
| 9129 | // Substitute auto in TypeWithAuto for a Dependent auto type |
| 9130 | TypeSourceInfo * |
| 9131 | SubstAutoTypeSourceInfoDependent(TypeSourceInfo *TypeWithAuto); |
| 9132 | |
| 9133 | /// Completely replace the \c auto in \p TypeWithAuto by |
| 9134 | /// \p Replacement. This does not retain any \c auto type sugar. |
| 9135 | QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement); |
| 9136 | TypeSourceInfo *ReplaceAutoTypeSourceInfo(TypeSourceInfo *TypeWithAuto, |
| 9137 | QualType Replacement); |
| 9138 | |
| 9139 | TemplateDeductionResult DeduceAutoType(TypeLoc AutoTypeLoc, Expr *Initializer, |
| 9140 | QualType &Result, |
| 9141 | sema::TemplateDeductionInfo &Info, |
| 9142 | bool DependentDeduction = false, |
| 9143 | bool IgnoreConstraints = false); |
| 9144 | void DiagnoseAutoDeductionFailure(VarDecl *VDecl, Expr *Init); |
| 9145 | bool DeduceReturnType(FunctionDecl *FD, SourceLocation Loc, |
| 9146 | bool Diagnose = true); |
| 9147 | |
| 9148 | /// Declare implicit deduction guides for a class template if we've |
| 9149 | /// not already done so. |
| 9150 | void DeclareImplicitDeductionGuides(TemplateDecl *Template, |
| 9151 | SourceLocation Loc); |
| 9152 | |
| 9153 | QualType DeduceTemplateSpecializationFromInitializer( |
| 9154 | TypeSourceInfo *TInfo, const InitializedEntity &Entity, |
| 9155 | const InitializationKind &Kind, MultiExprArg Init); |
| 9156 | |
| 9157 | QualType deduceVarTypeFromInitializer(VarDecl *VDecl, DeclarationName Name, |
| 9158 | QualType Type, TypeSourceInfo *TSI, |
| 9159 | SourceRange Range, bool DirectInit, |
| 9160 | Expr *Init); |
| 9161 | |
| 9162 | TypeLoc getReturnTypeLoc(FunctionDecl *FD) const; |
| 9163 | |
| 9164 | bool DeduceFunctionTypeFromReturnExpr(FunctionDecl *FD, |
| 9165 | SourceLocation ReturnLoc, Expr *RetExpr, |
| 9166 | const AutoType *AT); |
| 9167 | |
| 9168 | FunctionTemplateDecl *getMoreSpecializedTemplate( |
| 9169 | FunctionTemplateDecl *FT1, FunctionTemplateDecl *FT2, SourceLocation Loc, |
| 9170 | TemplatePartialOrderingContext TPOC, unsigned NumCallArguments1, |
| 9171 | unsigned NumCallArguments2, bool Reversed = false); |
| 9172 | UnresolvedSetIterator |
| 9173 | getMostSpecialized(UnresolvedSetIterator SBegin, UnresolvedSetIterator SEnd, |
| 9174 | TemplateSpecCandidateSet &FailedCandidates, |
| 9175 | SourceLocation Loc, |
| 9176 | const PartialDiagnostic &NoneDiag, |
| 9177 | const PartialDiagnostic &AmbigDiag, |
| 9178 | const PartialDiagnostic &CandidateDiag, |
| 9179 | bool Complain = true, QualType TargetType = QualType()); |
| 9180 | |
| 9181 | ClassTemplatePartialSpecializationDecl * |
| 9182 | getMoreSpecializedPartialSpecialization( |
| 9183 | ClassTemplatePartialSpecializationDecl *PS1, |
| 9184 | ClassTemplatePartialSpecializationDecl *PS2, |
| 9185 | SourceLocation Loc); |
| 9186 | |
| 9187 | bool isMoreSpecializedThanPrimary(ClassTemplatePartialSpecializationDecl *T, |
| 9188 | sema::TemplateDeductionInfo &Info); |
| 9189 | |
| 9190 | VarTemplatePartialSpecializationDecl *getMoreSpecializedPartialSpecialization( |
| 9191 | VarTemplatePartialSpecializationDecl *PS1, |
| 9192 | VarTemplatePartialSpecializationDecl *PS2, SourceLocation Loc); |
| 9193 | |
| 9194 | bool isMoreSpecializedThanPrimary(VarTemplatePartialSpecializationDecl *T, |
| 9195 | sema::TemplateDeductionInfo &Info); |
| 9196 | |
| 9197 | bool isTemplateTemplateParameterAtLeastAsSpecializedAs( |
| 9198 | TemplateParameterList *PParam, TemplateDecl *AArg, SourceLocation Loc); |
| 9199 | |
| 9200 | void MarkUsedTemplateParameters(const Expr *E, bool OnlyDeduced, |
| 9201 | unsigned Depth, llvm::SmallBitVector &Used); |
| 9202 | |
| 9203 | void MarkUsedTemplateParameters(const TemplateArgumentList &TemplateArgs, |
| 9204 | bool OnlyDeduced, |
| 9205 | unsigned Depth, |
| 9206 | llvm::SmallBitVector &Used); |
| 9207 | void MarkDeducedTemplateParameters( |
| 9208 | const FunctionTemplateDecl *FunctionTemplate, |
| 9209 | llvm::SmallBitVector &Deduced) { |
| 9210 | return MarkDeducedTemplateParameters(Context, FunctionTemplate, Deduced); |
| 9211 | } |
| 9212 | static void MarkDeducedTemplateParameters(ASTContext &Ctx, |
| 9213 | const FunctionTemplateDecl *FunctionTemplate, |
| 9214 | llvm::SmallBitVector &Deduced); |
| 9215 | |
| 9216 | //===--------------------------------------------------------------------===// |
| 9217 | // C++ Template Instantiation |
| 9218 | // |
| 9219 | |
| 9220 | MultiLevelTemplateArgumentList |
| 9221 | getTemplateInstantiationArgs(const NamedDecl *D, bool Final = false, |
| 9222 | const TemplateArgumentList *Innermost = nullptr, |
| 9223 | bool RelativeToPrimary = false, |
| 9224 | const FunctionDecl *Pattern = nullptr, |
| 9225 | bool ForConstraintInstantiation = false, |
| 9226 | bool SkipForSpecialization = false); |
| 9227 | |
| 9228 | /// A context in which code is being synthesized (where a source location |
| 9229 | /// alone is not sufficient to identify the context). This covers template |
| 9230 | /// instantiation and various forms of implicitly-generated functions. |
| 9231 | struct CodeSynthesisContext { |
| 9232 | /// The kind of template instantiation we are performing |
| 9233 | enum SynthesisKind { |
| 9234 | /// We are instantiating a template declaration. The entity is |
| 9235 | /// the declaration we're instantiating (e.g., a CXXRecordDecl). |
| 9236 | TemplateInstantiation, |
| 9237 | |
| 9238 | /// We are instantiating a default argument for a template |
| 9239 | /// parameter. The Entity is the template parameter whose argument is |
| 9240 | /// being instantiated, the Template is the template, and the |
| 9241 | /// TemplateArgs/NumTemplateArguments provide the template arguments as |
| 9242 | /// specified. |
| 9243 | DefaultTemplateArgumentInstantiation, |
| 9244 | |
| 9245 | /// We are instantiating a default argument for a function. |
| 9246 | /// The Entity is the ParmVarDecl, and TemplateArgs/NumTemplateArgs |
| 9247 | /// provides the template arguments as specified. |
| 9248 | DefaultFunctionArgumentInstantiation, |
| 9249 | |
| 9250 | /// We are substituting explicit template arguments provided for |
| 9251 | /// a function template. The entity is a FunctionTemplateDecl. |
| 9252 | ExplicitTemplateArgumentSubstitution, |
| 9253 | |
| 9254 | /// We are substituting template argument determined as part of |
| 9255 | /// template argument deduction for either a class template |
| 9256 | /// partial specialization or a function template. The |
| 9257 | /// Entity is either a {Class|Var}TemplatePartialSpecializationDecl or |
| 9258 | /// a TemplateDecl. |
| 9259 | DeducedTemplateArgumentSubstitution, |
| 9260 | |
| 9261 | /// We are substituting into a lambda expression. |
| 9262 | LambdaExpressionSubstitution, |
| 9263 | |
| 9264 | /// We are substituting prior template arguments into a new |
| 9265 | /// template parameter. The template parameter itself is either a |
| 9266 | /// NonTypeTemplateParmDecl or a TemplateTemplateParmDecl. |
| 9267 | PriorTemplateArgumentSubstitution, |
| 9268 | |
| 9269 | /// We are checking the validity of a default template argument that |
| 9270 | /// has been used when naming a template-id. |
| 9271 | DefaultTemplateArgumentChecking, |
| 9272 | |
| 9273 | /// We are computing the exception specification for a defaulted special |
| 9274 | /// member function. |
| 9275 | ExceptionSpecEvaluation, |
| 9276 | |
| 9277 | /// We are instantiating the exception specification for a function |
| 9278 | /// template which was deferred until it was needed. |
| 9279 | ExceptionSpecInstantiation, |
| 9280 | |
| 9281 | /// We are instantiating a requirement of a requires expression. |
| 9282 | RequirementInstantiation, |
| 9283 | |
| 9284 | /// We are checking the satisfaction of a nested requirement of a requires |
| 9285 | /// expression. |
| 9286 | NestedRequirementConstraintsCheck, |
| 9287 | |
| 9288 | /// We are declaring an implicit special member function. |
| 9289 | DeclaringSpecialMember, |
| 9290 | |
| 9291 | /// We are declaring an implicit 'operator==' for a defaulted |
| 9292 | /// 'operator<=>'. |
| 9293 | DeclaringImplicitEqualityComparison, |
| 9294 | |
| 9295 | /// We are defining a synthesized function (such as a defaulted special |
| 9296 | /// member). |
| 9297 | DefiningSynthesizedFunction, |
| 9298 | |
| 9299 | // We are checking the constraints associated with a constrained entity or |
| 9300 | // the constraint expression of a concept. This includes the checks that |
| 9301 | // atomic constraints have the type 'bool' and that they can be constant |
| 9302 | // evaluated. |
| 9303 | ConstraintsCheck, |
| 9304 | |
| 9305 | // We are substituting template arguments into a constraint expression. |
| 9306 | ConstraintSubstitution, |
| 9307 | |
| 9308 | // We are normalizing a constraint expression. |
| 9309 | ConstraintNormalization, |
| 9310 | |
| 9311 | // Instantiating a Requires Expression parameter clause. |
| 9312 | RequirementParameterInstantiation, |
| 9313 | |
| 9314 | // We are substituting into the parameter mapping of an atomic constraint |
| 9315 | // during normalization. |
| 9316 | ParameterMappingSubstitution, |
| 9317 | |
| 9318 | /// We are rewriting a comparison operator in terms of an operator<=>. |
| 9319 | RewritingOperatorAsSpaceship, |
| 9320 | |
| 9321 | /// We are initializing a structured binding. |
| 9322 | InitializingStructuredBinding, |
| 9323 | |
| 9324 | /// We are marking a class as __dllexport. |
| 9325 | MarkingClassDllexported, |
| 9326 | |
| 9327 | /// We are building an implied call from __builtin_dump_struct. The |
| 9328 | /// arguments are in CallArgs. |
| 9329 | BuildingBuiltinDumpStructCall, |
| 9330 | |
| 9331 | /// Added for Template instantiation observation. |
| 9332 | /// Memoization means we are _not_ instantiating a template because |
| 9333 | /// it is already instantiated (but we entered a context where we |
| 9334 | /// would have had to if it was not already instantiated). |
| 9335 | Memoization |
| 9336 | } Kind; |
| 9337 | |
| 9338 | /// Was the enclosing context a non-instantiation SFINAE context? |
| 9339 | bool SavedInNonInstantiationSFINAEContext; |
| 9340 | |
| 9341 | /// The point of instantiation or synthesis within the source code. |
| 9342 | SourceLocation PointOfInstantiation; |
| 9343 | |
| 9344 | /// The entity that is being synthesized. |
| 9345 | Decl *Entity; |
| 9346 | |
| 9347 | /// The template (or partial specialization) in which we are |
| 9348 | /// performing the instantiation, for substitutions of prior template |
| 9349 | /// arguments. |
| 9350 | NamedDecl *Template; |
| 9351 | |
| 9352 | union { |
| 9353 | /// The list of template arguments we are substituting, if they |
| 9354 | /// are not part of the entity. |
| 9355 | const TemplateArgument *TemplateArgs; |
| 9356 | |
| 9357 | /// The list of argument expressions in a synthesized call. |
| 9358 | const Expr *const *CallArgs; |
| 9359 | }; |
| 9360 | |
| 9361 | // FIXME: Wrap this union around more members, or perhaps store the |
| 9362 | // kind-specific members in the RAII object owning the context. |
| 9363 | union { |
| 9364 | /// The number of template arguments in TemplateArgs. |
| 9365 | unsigned NumTemplateArgs; |
| 9366 | |
| 9367 | /// The number of expressions in CallArgs. |
| 9368 | unsigned NumCallArgs; |
| 9369 | |
| 9370 | /// The special member being declared or defined. |
| 9371 | CXXSpecialMember SpecialMember; |
| 9372 | }; |
| 9373 | |
| 9374 | ArrayRef<TemplateArgument> template_arguments() const { |
| 9375 | assert(Kind != DeclaringSpecialMember)(static_cast <bool> (Kind != DeclaringSpecialMember) ? void (0) : __assert_fail ("Kind != DeclaringSpecialMember", "clang/include/clang/Sema/Sema.h" , 9375, __extension__ __PRETTY_FUNCTION__)); |
| 9376 | return {TemplateArgs, NumTemplateArgs}; |
| 9377 | } |
| 9378 | |
| 9379 | /// The template deduction info object associated with the |
| 9380 | /// substitution or checking of explicit or deduced template arguments. |
| 9381 | sema::TemplateDeductionInfo *DeductionInfo; |
| 9382 | |
| 9383 | /// The source range that covers the construct that cause |
| 9384 | /// the instantiation, e.g., the template-id that causes a class |
| 9385 | /// template instantiation. |
| 9386 | SourceRange InstantiationRange; |
| 9387 | |
| 9388 | CodeSynthesisContext() |
| 9389 | : Kind(TemplateInstantiation), |
| 9390 | SavedInNonInstantiationSFINAEContext(false), Entity(nullptr), |
| 9391 | Template(nullptr), TemplateArgs(nullptr), NumTemplateArgs(0), |
| 9392 | DeductionInfo(nullptr) {} |
| 9393 | |
| 9394 | /// Determines whether this template is an actual instantiation |
| 9395 | /// that should be counted toward the maximum instantiation depth. |
| 9396 | bool isInstantiationRecord() const; |
| 9397 | }; |
| 9398 | |
| 9399 | /// List of active code synthesis contexts. |
| 9400 | /// |
| 9401 | /// This vector is treated as a stack. As synthesis of one entity requires |
| 9402 | /// synthesis of another, additional contexts are pushed onto the stack. |
| 9403 | SmallVector<CodeSynthesisContext, 16> CodeSynthesisContexts; |
| 9404 | |
| 9405 | /// Specializations whose definitions are currently being instantiated. |
| 9406 | llvm::DenseSet<std::pair<Decl *, unsigned>> InstantiatingSpecializations; |
| 9407 | |
| 9408 | /// Non-dependent types used in templates that have already been instantiated |
| 9409 | /// by some template instantiation. |
| 9410 | llvm::DenseSet<QualType> InstantiatedNonDependentTypes; |
| 9411 | |
| 9412 | /// Extra modules inspected when performing a lookup during a template |
| 9413 | /// instantiation. Computed lazily. |
| 9414 | SmallVector<Module*, 16> CodeSynthesisContextLookupModules; |
| 9415 | |
| 9416 | /// Cache of additional modules that should be used for name lookup |
| 9417 | /// within the current template instantiation. Computed lazily; use |
| 9418 | /// getLookupModules() to get a complete set. |
| 9419 | llvm::DenseSet<Module*> LookupModulesCache; |
| 9420 | |
| 9421 | /// Get the set of additional modules that should be checked during |
| 9422 | /// name lookup. A module and its imports become visible when instanting a |
| 9423 | /// template defined within it. |
| 9424 | llvm::DenseSet<Module*> &getLookupModules(); |
| 9425 | |
| 9426 | /// Map from the most recent declaration of a namespace to the most |
| 9427 | /// recent visible declaration of that namespace. |
| 9428 | llvm::DenseMap<NamedDecl*, NamedDecl*> VisibleNamespaceCache; |
| 9429 | |
| 9430 | /// Whether we are in a SFINAE context that is not associated with |
| 9431 | /// template instantiation. |
| 9432 | /// |
| 9433 | /// This is used when setting up a SFINAE trap (\c see SFINAETrap) outside |
| 9434 | /// of a template instantiation or template argument deduction. |
| 9435 | bool InNonInstantiationSFINAEContext; |
| 9436 | |
| 9437 | /// The number of \p CodeSynthesisContexts that are not template |
| 9438 | /// instantiations and, therefore, should not be counted as part of the |
| 9439 | /// instantiation depth. |
| 9440 | /// |
| 9441 | /// When the instantiation depth reaches the user-configurable limit |
| 9442 | /// \p LangOptions::InstantiationDepth we will abort instantiation. |
| 9443 | // FIXME: Should we have a similar limit for other forms of synthesis? |
| 9444 | unsigned NonInstantiationEntries; |
| 9445 | |
| 9446 | /// The depth of the context stack at the point when the most recent |
| 9447 | /// error or warning was produced. |
| 9448 | /// |
| 9449 | /// This value is used to suppress printing of redundant context stacks |
| 9450 | /// when there are multiple errors or warnings in the same instantiation. |
| 9451 | // FIXME: Does this belong in Sema? It's tough to implement it anywhere else. |
| 9452 | unsigned LastEmittedCodeSynthesisContextDepth = 0; |
| 9453 | |
| 9454 | /// The template instantiation callbacks to trace or track |
| 9455 | /// instantiations (objects can be chained). |
| 9456 | /// |
| 9457 | /// This callbacks is used to print, trace or track template |
| 9458 | /// instantiations as they are being constructed. |
| 9459 | std::vector<std::unique_ptr<TemplateInstantiationCallback>> |
| 9460 | TemplateInstCallbacks; |
| 9461 | |
| 9462 | /// The current index into pack expansion arguments that will be |
| 9463 | /// used for substitution of parameter packs. |
| 9464 | /// |
| 9465 | /// The pack expansion index will be -1 to indicate that parameter packs |
| 9466 | /// should be instantiated as themselves. Otherwise, the index specifies |
| 9467 | /// which argument within the parameter pack will be used for substitution. |
| 9468 | int ArgumentPackSubstitutionIndex; |
| 9469 | |
| 9470 | /// RAII object used to change the argument pack substitution index |
| 9471 | /// within a \c Sema object. |
| 9472 | /// |
| 9473 | /// See \c ArgumentPackSubstitutionIndex for more information. |
| 9474 | class ArgumentPackSubstitutionIndexRAII { |
| 9475 | Sema &Self; |
| 9476 | int OldSubstitutionIndex; |
| 9477 | |
| 9478 | public: |
| 9479 | ArgumentPackSubstitutionIndexRAII(Sema &Self, int NewSubstitutionIndex) |
| 9480 | : Self(Self), OldSubstitutionIndex(Self.ArgumentPackSubstitutionIndex) { |
| 9481 | Self.ArgumentPackSubstitutionIndex = NewSubstitutionIndex; |
| 9482 | } |
| 9483 | |
| 9484 | ~ArgumentPackSubstitutionIndexRAII() { |
| 9485 | Self.ArgumentPackSubstitutionIndex = OldSubstitutionIndex; |
| 9486 | } |
| 9487 | }; |
| 9488 | |
| 9489 | friend class ArgumentPackSubstitutionRAII; |
| 9490 | |
| 9491 | /// For each declaration that involved template argument deduction, the |
| 9492 | /// set of diagnostics that were suppressed during that template argument |
| 9493 | /// deduction. |
| 9494 | /// |
| 9495 | /// FIXME: Serialize this structure to the AST file. |
| 9496 | typedef llvm::DenseMap<Decl *, SmallVector<PartialDiagnosticAt, 1> > |
| 9497 | SuppressedDiagnosticsMap; |
| 9498 | SuppressedDiagnosticsMap SuppressedDiagnostics; |
| 9499 | |
| 9500 | /// A stack object to be created when performing template |
| 9501 | /// instantiation. |
| 9502 | /// |
| 9503 | /// Construction of an object of type \c InstantiatingTemplate |
| 9504 | /// pushes the current instantiation onto the stack of active |
| 9505 | /// instantiations. If the size of this stack exceeds the maximum |
| 9506 | /// number of recursive template instantiations, construction |
| 9507 | /// produces an error and evaluates true. |
| 9508 | /// |
| 9509 | /// Destruction of this object will pop the named instantiation off |
| 9510 | /// the stack. |
| 9511 | struct InstantiatingTemplate { |
| 9512 | /// Note that we are instantiating a class template, |
| 9513 | /// function template, variable template, alias template, |
| 9514 | /// or a member thereof. |
| 9515 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9516 | Decl *Entity, |
| 9517 | SourceRange InstantiationRange = SourceRange()); |
| 9518 | |
| 9519 | struct ExceptionSpecification {}; |
| 9520 | /// Note that we are instantiating an exception specification |
| 9521 | /// of a function template. |
| 9522 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9523 | FunctionDecl *Entity, ExceptionSpecification, |
| 9524 | SourceRange InstantiationRange = SourceRange()); |
| 9525 | |
| 9526 | /// Note that we are instantiating a default argument in a |
| 9527 | /// template-id. |
| 9528 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9529 | TemplateParameter Param, TemplateDecl *Template, |
| 9530 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9531 | SourceRange InstantiationRange = SourceRange()); |
| 9532 | |
| 9533 | /// Note that we are substituting either explicitly-specified or |
| 9534 | /// deduced template arguments during function template argument deduction. |
| 9535 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9536 | FunctionTemplateDecl *FunctionTemplate, |
| 9537 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9538 | CodeSynthesisContext::SynthesisKind Kind, |
| 9539 | sema::TemplateDeductionInfo &DeductionInfo, |
| 9540 | SourceRange InstantiationRange = SourceRange()); |
| 9541 | |
| 9542 | /// Note that we are instantiating as part of template |
| 9543 | /// argument deduction for a class template declaration. |
| 9544 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9545 | TemplateDecl *Template, |
| 9546 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9547 | sema::TemplateDeductionInfo &DeductionInfo, |
| 9548 | SourceRange InstantiationRange = SourceRange()); |
| 9549 | |
| 9550 | /// Note that we are instantiating as part of template |
| 9551 | /// argument deduction for a class template partial |
| 9552 | /// specialization. |
| 9553 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9554 | ClassTemplatePartialSpecializationDecl *PartialSpec, |
| 9555 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9556 | sema::TemplateDeductionInfo &DeductionInfo, |
| 9557 | SourceRange InstantiationRange = SourceRange()); |
| 9558 | |
| 9559 | /// Note that we are instantiating as part of template |
| 9560 | /// argument deduction for a variable template partial |
| 9561 | /// specialization. |
| 9562 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9563 | VarTemplatePartialSpecializationDecl *PartialSpec, |
| 9564 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9565 | sema::TemplateDeductionInfo &DeductionInfo, |
| 9566 | SourceRange InstantiationRange = SourceRange()); |
| 9567 | |
| 9568 | /// Note that we are instantiating a default argument for a function |
| 9569 | /// parameter. |
| 9570 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9571 | ParmVarDecl *Param, |
| 9572 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9573 | SourceRange InstantiationRange = SourceRange()); |
| 9574 | |
| 9575 | /// Note that we are substituting prior template arguments into a |
| 9576 | /// non-type parameter. |
| 9577 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9578 | NamedDecl *Template, |
| 9579 | NonTypeTemplateParmDecl *Param, |
| 9580 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9581 | SourceRange InstantiationRange); |
| 9582 | |
| 9583 | /// Note that we are substituting prior template arguments into a |
| 9584 | /// template template parameter. |
| 9585 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9586 | NamedDecl *Template, |
| 9587 | TemplateTemplateParmDecl *Param, |
| 9588 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9589 | SourceRange InstantiationRange); |
| 9590 | |
| 9591 | /// Note that we are checking the default template argument |
| 9592 | /// against the template parameter for a given template-id. |
| 9593 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9594 | TemplateDecl *Template, |
| 9595 | NamedDecl *Param, |
| 9596 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9597 | SourceRange InstantiationRange); |
| 9598 | |
| 9599 | struct ConstraintsCheck {}; |
| 9600 | /// \brief Note that we are checking the constraints associated with some |
| 9601 | /// constrained entity (a concept declaration or a template with associated |
| 9602 | /// constraints). |
| 9603 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9604 | ConstraintsCheck, NamedDecl *Template, |
| 9605 | ArrayRef<TemplateArgument> TemplateArgs, |
| 9606 | SourceRange InstantiationRange); |
| 9607 | |
| 9608 | struct ConstraintSubstitution {}; |
| 9609 | /// \brief Note that we are checking a constraint expression associated |
| 9610 | /// with a template declaration or as part of the satisfaction check of a |
| 9611 | /// concept. |
| 9612 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9613 | ConstraintSubstitution, NamedDecl *Template, |
| 9614 | sema::TemplateDeductionInfo &DeductionInfo, |
| 9615 | SourceRange InstantiationRange); |
| 9616 | |
| 9617 | struct ConstraintNormalization {}; |
| 9618 | /// \brief Note that we are normalizing a constraint expression. |
| 9619 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9620 | ConstraintNormalization, NamedDecl *Template, |
| 9621 | SourceRange InstantiationRange); |
| 9622 | |
| 9623 | struct ParameterMappingSubstitution {}; |
| 9624 | /// \brief Note that we are subtituting into the parameter mapping of an |
| 9625 | /// atomic constraint during constraint normalization. |
| 9626 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9627 | ParameterMappingSubstitution, NamedDecl *Template, |
| 9628 | SourceRange InstantiationRange); |
| 9629 | |
| 9630 | /// \brief Note that we are substituting template arguments into a part of |
| 9631 | /// a requirement of a requires expression. |
| 9632 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9633 | concepts::Requirement *Req, |
| 9634 | sema::TemplateDeductionInfo &DeductionInfo, |
| 9635 | SourceRange InstantiationRange = SourceRange()); |
| 9636 | |
| 9637 | /// \brief Note that we are checking the satisfaction of the constraint |
| 9638 | /// expression inside of a nested requirement. |
| 9639 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9640 | concepts::NestedRequirement *Req, ConstraintsCheck, |
| 9641 | SourceRange InstantiationRange = SourceRange()); |
| 9642 | |
| 9643 | /// \brief Note that we are checking a requires clause. |
| 9644 | InstantiatingTemplate(Sema &SemaRef, SourceLocation PointOfInstantiation, |
| 9645 | const RequiresExpr *E, |
| 9646 | sema::TemplateDeductionInfo &DeductionInfo, |
| 9647 | SourceRange InstantiationRange); |
| 9648 | /// Note that we have finished instantiating this template. |
| 9649 | void Clear(); |
| 9650 | |
| 9651 | ~InstantiatingTemplate() { Clear(); } |
| 9652 | |
| 9653 | /// Determines whether we have exceeded the maximum |
| 9654 | /// recursive template instantiations. |
| 9655 | bool isInvalid() const { return Invalid; } |
| 9656 | |
| 9657 | /// Determine whether we are already instantiating this |
| 9658 | /// specialization in some surrounding active instantiation. |
| 9659 | bool isAlreadyInstantiating() const { return AlreadyInstantiating; } |
| 9660 | |
| 9661 | private: |
| 9662 | Sema &SemaRef; |
| 9663 | bool Invalid; |
| 9664 | bool AlreadyInstantiating; |
| 9665 | bool CheckInstantiationDepth(SourceLocation PointOfInstantiation, |
| 9666 | SourceRange InstantiationRange); |
| 9667 | |
| 9668 | InstantiatingTemplate( |
| 9669 | Sema &SemaRef, CodeSynthesisContext::SynthesisKind Kind, |
| 9670 | SourceLocation PointOfInstantiation, SourceRange InstantiationRange, |
| 9671 | Decl *Entity, NamedDecl *Template = nullptr, |
| 9672 | ArrayRef<TemplateArgument> TemplateArgs = std::nullopt, |
| 9673 | sema::TemplateDeductionInfo *DeductionInfo = nullptr); |
| 9674 | |
| 9675 | InstantiatingTemplate(const InstantiatingTemplate&) = delete; |
| 9676 | |
| 9677 | InstantiatingTemplate& |
| 9678 | operator=(const InstantiatingTemplate&) = delete; |
| 9679 | }; |
| 9680 | |
| 9681 | void pushCodeSynthesisContext(CodeSynthesisContext Ctx); |
| 9682 | void popCodeSynthesisContext(); |
| 9683 | |
| 9684 | /// Determine whether we are currently performing template instantiation. |
| 9685 | bool inTemplateInstantiation() const { |
| 9686 | return CodeSynthesisContexts.size() > NonInstantiationEntries; |
| 9687 | } |
| 9688 | |
| 9689 | void PrintContextStack() { |
| 9690 | if (!CodeSynthesisContexts.empty() && |
| 9691 | CodeSynthesisContexts.size() != LastEmittedCodeSynthesisContextDepth) { |
| 9692 | PrintInstantiationStack(); |
| 9693 | LastEmittedCodeSynthesisContextDepth = CodeSynthesisContexts.size(); |
| 9694 | } |
| 9695 | if (PragmaAttributeCurrentTargetDecl) |
| 9696 | PrintPragmaAttributeInstantiationPoint(); |
| 9697 | } |
| 9698 | void PrintInstantiationStack(); |
| 9699 | |
| 9700 | void PrintPragmaAttributeInstantiationPoint(); |
| 9701 | |
| 9702 | /// Determines whether we are currently in a context where |
| 9703 | /// template argument substitution failures are not considered |
| 9704 | /// errors. |
| 9705 | /// |
| 9706 | /// \returns An empty \c Optional if we're not in a SFINAE context. |
| 9707 | /// Otherwise, contains a pointer that, if non-NULL, contains the nearest |
| 9708 | /// template-deduction context object, which can be used to capture |
| 9709 | /// diagnostics that will be suppressed. |
| 9710 | std::optional<sema::TemplateDeductionInfo *> isSFINAEContext() const; |
| 9711 | |
| 9712 | /// Determines whether we are currently in a context that |
| 9713 | /// is not evaluated as per C++ [expr] p5. |
| 9714 | bool isUnevaluatedContext() const { |
| 9715 | assert(!ExprEvalContexts.empty() &&(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9716, __extension__ __PRETTY_FUNCTION__ )) |
| 9716 | "Must be in an expression evaluation context")(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9716, __extension__ __PRETTY_FUNCTION__ )); |
| 9717 | return ExprEvalContexts.back().isUnevaluated(); |
| 9718 | } |
| 9719 | |
| 9720 | bool isConstantEvaluatedContext() const { |
| 9721 | assert(!ExprEvalContexts.empty() &&(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9722, __extension__ __PRETTY_FUNCTION__ )) |
| 9722 | "Must be in an expression evaluation context")(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9722, __extension__ __PRETTY_FUNCTION__ )); |
| 9723 | return ExprEvalContexts.back().isConstantEvaluated(); |
| 9724 | } |
| 9725 | |
| 9726 | bool isImmediateFunctionContext() const { |
| 9727 | assert(!ExprEvalContexts.empty() &&(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9728, __extension__ __PRETTY_FUNCTION__ )) |
| 9728 | "Must be in an expression evaluation context")(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9728, __extension__ __PRETTY_FUNCTION__ )); |
| 9729 | return ExprEvalContexts.back().isImmediateFunctionContext(); |
| 9730 | } |
| 9731 | |
| 9732 | bool isCheckingDefaultArgumentOrInitializer() const { |
| 9733 | assert(!ExprEvalContexts.empty() &&(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9734, __extension__ __PRETTY_FUNCTION__ )) |
| 9734 | "Must be in an expression evaluation context")(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9734, __extension__ __PRETTY_FUNCTION__ )); |
| 9735 | const ExpressionEvaluationContextRecord &Ctx = ExprEvalContexts.back(); |
| 9736 | return (Ctx.Context == |
| 9737 | ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed) || |
| 9738 | Ctx.IsCurrentlyCheckingDefaultArgumentOrInitializer; |
| 9739 | } |
| 9740 | |
| 9741 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
| 9742 | InnermostDeclarationWithDelayedImmediateInvocations() const { |
| 9743 | assert(!ExprEvalContexts.empty() &&(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9744, __extension__ __PRETTY_FUNCTION__ )) |
| 9744 | "Must be in an expression evaluation context")(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9744, __extension__ __PRETTY_FUNCTION__ )); |
| 9745 | for (const auto &Ctx : llvm::reverse(ExprEvalContexts)) { |
| 9746 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
| 9747 | Ctx.DelayedDefaultInitializationContext) |
| 9748 | return Ctx.DelayedDefaultInitializationContext; |
| 9749 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
| 9750 | Ctx.isUnevaluated()) |
| 9751 | break; |
| 9752 | } |
| 9753 | return std::nullopt; |
| 9754 | } |
| 9755 | |
| 9756 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> |
| 9757 | OutermostDeclarationWithDelayedImmediateInvocations() const { |
| 9758 | assert(!ExprEvalContexts.empty() &&(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9759, __extension__ __PRETTY_FUNCTION__ )) |
| 9759 | "Must be in an expression evaluation context")(static_cast <bool> (!ExprEvalContexts.empty() && "Must be in an expression evaluation context") ? void (0) : __assert_fail ("!ExprEvalContexts.empty() && \"Must be in an expression evaluation context\"" , "clang/include/clang/Sema/Sema.h", 9759, __extension__ __PRETTY_FUNCTION__ )); |
| 9760 | std::optional<ExpressionEvaluationContextRecord::InitializationContext> Res; |
| 9761 | for (auto &Ctx : llvm::reverse(ExprEvalContexts)) { |
| 9762 | if (Ctx.Context == ExpressionEvaluationContext::PotentiallyEvaluated && |
| 9763 | !Ctx.DelayedDefaultInitializationContext && Res) |
| 9764 | break; |
| 9765 | if (Ctx.isConstantEvaluated() || Ctx.isImmediateFunctionContext() || |
| 9766 | Ctx.isUnevaluated()) |
| 9767 | break; |
| 9768 | Res = Ctx.DelayedDefaultInitializationContext; |
| 9769 | } |
| 9770 | return Res; |
| 9771 | } |
| 9772 | |
| 9773 | /// RAII class used to determine whether SFINAE has |
| 9774 | /// trapped any errors that occur during template argument |
| 9775 | /// deduction. |
| 9776 | class SFINAETrap { |
| 9777 | Sema &SemaRef; |
| 9778 | unsigned PrevSFINAEErrors; |
| 9779 | bool PrevInNonInstantiationSFINAEContext; |
| 9780 | bool PrevAccessCheckingSFINAE; |
| 9781 | bool PrevLastDiagnosticIgnored; |
| 9782 | |
| 9783 | public: |
| 9784 | explicit SFINAETrap(Sema &SemaRef, bool AccessCheckingSFINAE = false) |
| 9785 | : SemaRef(SemaRef), PrevSFINAEErrors(SemaRef.NumSFINAEErrors), |
| 9786 | PrevInNonInstantiationSFINAEContext( |
| 9787 | SemaRef.InNonInstantiationSFINAEContext), |
| 9788 | PrevAccessCheckingSFINAE(SemaRef.AccessCheckingSFINAE), |
| 9789 | PrevLastDiagnosticIgnored( |
| 9790 | SemaRef.getDiagnostics().isLastDiagnosticIgnored()) |
| 9791 | { |
| 9792 | if (!SemaRef.isSFINAEContext()) |
| 9793 | SemaRef.InNonInstantiationSFINAEContext = true; |
| 9794 | SemaRef.AccessCheckingSFINAE = AccessCheckingSFINAE; |
| 9795 | } |
| 9796 | |
| 9797 | ~SFINAETrap() { |
| 9798 | SemaRef.NumSFINAEErrors = PrevSFINAEErrors; |
| 9799 | SemaRef.InNonInstantiationSFINAEContext |
| 9800 | = PrevInNonInstantiationSFINAEContext; |
| 9801 | SemaRef.AccessCheckingSFINAE = PrevAccessCheckingSFINAE; |
| 9802 | SemaRef.getDiagnostics().setLastDiagnosticIgnored( |
| 9803 | PrevLastDiagnosticIgnored); |
| 9804 | } |
| 9805 | |
| 9806 | /// Determine whether any SFINAE errors have been trapped. |
| 9807 | bool hasErrorOccurred() const { |
| 9808 | return SemaRef.NumSFINAEErrors > PrevSFINAEErrors; |
| 9809 | } |
| 9810 | }; |
| 9811 | |
| 9812 | /// RAII class used to indicate that we are performing provisional |
| 9813 | /// semantic analysis to determine the validity of a construct, so |
| 9814 | /// typo-correction and diagnostics in the immediate context (not within |
| 9815 | /// implicitly-instantiated templates) should be suppressed. |
| 9816 | class TentativeAnalysisScope { |
| 9817 | Sema &SemaRef; |
| 9818 | // FIXME: Using a SFINAETrap for this is a hack. |
| 9819 | SFINAETrap Trap; |
| 9820 | bool PrevDisableTypoCorrection; |
| 9821 | public: |
| 9822 | explicit TentativeAnalysisScope(Sema &SemaRef) |
| 9823 | : SemaRef(SemaRef), Trap(SemaRef, true), |
| 9824 | PrevDisableTypoCorrection(SemaRef.DisableTypoCorrection) { |
| 9825 | SemaRef.DisableTypoCorrection = true; |
| 9826 | } |
| 9827 | ~TentativeAnalysisScope() { |
| 9828 | SemaRef.DisableTypoCorrection = PrevDisableTypoCorrection; |
| 9829 | } |
| 9830 | }; |
| 9831 | |
| 9832 | /// The current instantiation scope used to store local |
| 9833 | /// variables. |
| 9834 | LocalInstantiationScope *CurrentInstantiationScope; |
| 9835 | |
| 9836 | /// Tracks whether we are in a context where typo correction is |
| 9837 | /// disabled. |
| 9838 | bool DisableTypoCorrection; |
| 9839 | |
| 9840 | /// The number of typos corrected by CorrectTypo. |
| 9841 | unsigned TyposCorrected; |
| 9842 | |
| 9843 | typedef llvm::SmallSet<SourceLocation, 2> SrcLocSet; |
| 9844 | typedef llvm::DenseMap<IdentifierInfo *, SrcLocSet> IdentifierSourceLocations; |
| 9845 | |
| 9846 | /// A cache containing identifiers for which typo correction failed and |
| 9847 | /// their locations, so that repeated attempts to correct an identifier in a |
| 9848 | /// given location are ignored if typo correction already failed for it. |
| 9849 | IdentifierSourceLocations TypoCorrectionFailures; |
| 9850 | |
| 9851 | /// Worker object for performing CFG-based warnings. |
| 9852 | sema::AnalysisBasedWarnings AnalysisWarnings; |
| 9853 | threadSafety::BeforeSet *ThreadSafetyDeclCache; |
| 9854 | |
| 9855 | /// An entity for which implicit template instantiation is required. |
| 9856 | /// |
| 9857 | /// The source location associated with the declaration is the first place in |
| 9858 | /// the source code where the declaration was "used". It is not necessarily |
| 9859 | /// the point of instantiation (which will be either before or after the |
| 9860 | /// namespace-scope declaration that triggered this implicit instantiation), |
| 9861 | /// However, it is the location that diagnostics should generally refer to, |
| 9862 | /// because users will need to know what code triggered the instantiation. |
| 9863 | typedef std::pair<ValueDecl *, SourceLocation> PendingImplicitInstantiation; |
| 9864 | |
| 9865 | /// The queue of implicit template instantiations that are required |
| 9866 | /// but have not yet been performed. |
| 9867 | std::deque<PendingImplicitInstantiation> PendingInstantiations; |
| 9868 | |
| 9869 | /// Queue of implicit template instantiations that cannot be performed |
| 9870 | /// eagerly. |
| 9871 | SmallVector<PendingImplicitInstantiation, 1> LateParsedInstantiations; |
| 9872 | |
| 9873 | SmallVector<SmallVector<VTableUse, 16>, 8> SavedVTableUses; |
| 9874 | SmallVector<std::deque<PendingImplicitInstantiation>, 8> |
| 9875 | SavedPendingInstantiations; |
| 9876 | |
| 9877 | class GlobalEagerInstantiationScope { |
| 9878 | public: |
| 9879 | GlobalEagerInstantiationScope(Sema &S, bool Enabled) |
| 9880 | : S(S), Enabled(Enabled) { |
| 9881 | if (!Enabled) return; |
| 9882 | |
| 9883 | S.SavedPendingInstantiations.emplace_back(); |
| 9884 | S.SavedPendingInstantiations.back().swap(S.PendingInstantiations); |
| 9885 | |
| 9886 | S.SavedVTableUses.emplace_back(); |
| 9887 | S.SavedVTableUses.back().swap(S.VTableUses); |
| 9888 | } |
| 9889 | |
| 9890 | void perform() { |
| 9891 | if (Enabled) { |
| 9892 | S.DefineUsedVTables(); |
| 9893 | S.PerformPendingInstantiations(); |
| 9894 | } |
| 9895 | } |
| 9896 | |
| 9897 | ~GlobalEagerInstantiationScope() { |
| 9898 | if (!Enabled) return; |
| 9899 | |
| 9900 | // Restore the set of pending vtables. |
| 9901 | assert(S.VTableUses.empty() &&(static_cast <bool> (S.VTableUses.empty() && "VTableUses should be empty before it is discarded." ) ? void (0) : __assert_fail ("S.VTableUses.empty() && \"VTableUses should be empty before it is discarded.\"" , "clang/include/clang/Sema/Sema.h", 9902, __extension__ __PRETTY_FUNCTION__ )) |
| 9902 | "VTableUses should be empty before it is discarded.")(static_cast <bool> (S.VTableUses.empty() && "VTableUses should be empty before it is discarded." ) ? void (0) : __assert_fail ("S.VTableUses.empty() && \"VTableUses should be empty before it is discarded.\"" , "clang/include/clang/Sema/Sema.h", 9902, __extension__ __PRETTY_FUNCTION__ )); |
| 9903 | S.VTableUses.swap(S.SavedVTableUses.back()); |
| 9904 | S.SavedVTableUses.pop_back(); |
| 9905 | |
| 9906 | // Restore the set of pending implicit instantiations. |
| 9907 | if (S.TUKind != TU_Prefix || !S.LangOpts.PCHInstantiateTemplates) { |
| 9908 | assert(S.PendingInstantiations.empty() &&(static_cast <bool> (S.PendingInstantiations.empty() && "PendingInstantiations should be empty before it is discarded." ) ? void (0) : __assert_fail ("S.PendingInstantiations.empty() && \"PendingInstantiations should be empty before it is discarded.\"" , "clang/include/clang/Sema/Sema.h", 9909, __extension__ __PRETTY_FUNCTION__ )) |
| 9909 | "PendingInstantiations should be empty before it is discarded.")(static_cast <bool> (S.PendingInstantiations.empty() && "PendingInstantiations should be empty before it is discarded." ) ? void (0) : __assert_fail ("S.PendingInstantiations.empty() && \"PendingInstantiations should be empty before it is discarded.\"" , "clang/include/clang/Sema/Sema.h", 9909, __extension__ __PRETTY_FUNCTION__ )); |
| 9910 | S.PendingInstantiations.swap(S.SavedPendingInstantiations.back()); |
| 9911 | S.SavedPendingInstantiations.pop_back(); |
| 9912 | } else { |
| 9913 | // Template instantiations in the PCH may be delayed until the TU. |
| 9914 | S.PendingInstantiations.swap(S.SavedPendingInstantiations.back()); |
| 9915 | S.PendingInstantiations.insert( |
| 9916 | S.PendingInstantiations.end(), |
| 9917 | S.SavedPendingInstantiations.back().begin(), |
| 9918 | S.SavedPendingInstantiations.back().end()); |
| 9919 | S.SavedPendingInstantiations.pop_back(); |
| 9920 | } |
| 9921 | } |
| 9922 | |
| 9923 | private: |
| 9924 | Sema &S; |
| 9925 | bool Enabled; |
| 9926 | }; |
| 9927 | |
| 9928 | /// The queue of implicit template instantiations that are required |
| 9929 | /// and must be performed within the current local scope. |
| 9930 | /// |
| 9931 | /// This queue is only used for member functions of local classes in |
| 9932 | /// templates, which must be instantiated in the same scope as their |
| 9933 | /// enclosing function, so that they can reference function-local |
| 9934 | /// types, static variables, enumerators, etc. |
| 9935 | std::deque<PendingImplicitInstantiation> PendingLocalImplicitInstantiations; |
| 9936 | |
| 9937 | class LocalEagerInstantiationScope { |
| 9938 | public: |
| 9939 | LocalEagerInstantiationScope(Sema &S) : S(S) { |
| 9940 | SavedPendingLocalImplicitInstantiations.swap( |
| 9941 | S.PendingLocalImplicitInstantiations); |
| 9942 | } |
| 9943 | |
| 9944 | void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); } |
| 9945 | |
| 9946 | ~LocalEagerInstantiationScope() { |
| 9947 | assert(S.PendingLocalImplicitInstantiations.empty() &&(static_cast <bool> (S.PendingLocalImplicitInstantiations .empty() && "there shouldn't be any pending local implicit instantiations" ) ? void (0) : __assert_fail ("S.PendingLocalImplicitInstantiations.empty() && \"there shouldn't be any pending local implicit instantiations\"" , "clang/include/clang/Sema/Sema.h", 9948, __extension__ __PRETTY_FUNCTION__ )) |
| 9948 | "there shouldn't be any pending local implicit instantiations")(static_cast <bool> (S.PendingLocalImplicitInstantiations .empty() && "there shouldn't be any pending local implicit instantiations" ) ? void (0) : __assert_fail ("S.PendingLocalImplicitInstantiations.empty() && \"there shouldn't be any pending local implicit instantiations\"" , "clang/include/clang/Sema/Sema.h", 9948, __extension__ __PRETTY_FUNCTION__ )); |
| 9949 | SavedPendingLocalImplicitInstantiations.swap( |
| 9950 | S.PendingLocalImplicitInstantiations); |
| 9951 | } |
| 9952 | |
| 9953 | private: |
| 9954 | Sema &S; |
| 9955 | std::deque<PendingImplicitInstantiation> |
| 9956 | SavedPendingLocalImplicitInstantiations; |
| 9957 | }; |
| 9958 | |
| 9959 | /// A helper class for building up ExtParameterInfos. |
| 9960 | class ExtParameterInfoBuilder { |
| 9961 | SmallVector<FunctionProtoType::ExtParameterInfo, 16> Infos; |
| 9962 | bool HasInteresting = false; |
| 9963 | |
| 9964 | public: |
| 9965 | /// Set the ExtParameterInfo for the parameter at the given index, |
| 9966 | /// |
| 9967 | void set(unsigned index, FunctionProtoType::ExtParameterInfo info) { |
| 9968 | assert(Infos.size() <= index)(static_cast <bool> (Infos.size() <= index) ? void ( 0) : __assert_fail ("Infos.size() <= index", "clang/include/clang/Sema/Sema.h" , 9968, __extension__ __PRETTY_FUNCTION__)); |
| 9969 | Infos.resize(index); |
| 9970 | Infos.push_back(info); |
| 9971 | |
| 9972 | if (!HasInteresting) |
| 9973 | HasInteresting = (info != FunctionProtoType::ExtParameterInfo()); |
| 9974 | } |
| 9975 | |
| 9976 | /// Return a pointer (suitable for setting in an ExtProtoInfo) to the |
| 9977 | /// ExtParameterInfo array we've built up. |
| 9978 | const FunctionProtoType::ExtParameterInfo * |
| 9979 | getPointerOrNull(unsigned numParams) { |
| 9980 | if (!HasInteresting) return nullptr; |
| 9981 | Infos.resize(numParams); |
| 9982 | return Infos.data(); |
| 9983 | } |
| 9984 | }; |
| 9985 | |
| 9986 | void PerformPendingInstantiations(bool LocalOnly = false); |
| 9987 | |
| 9988 | TypeSourceInfo *SubstType(TypeSourceInfo *T, |
| 9989 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 9990 | SourceLocation Loc, DeclarationName Entity, |
| 9991 | bool AllowDeducedTST = false); |
| 9992 | |
| 9993 | QualType SubstType(QualType T, |
| 9994 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 9995 | SourceLocation Loc, DeclarationName Entity); |
| 9996 | |
| 9997 | TypeSourceInfo *SubstType(TypeLoc TL, |
| 9998 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 9999 | SourceLocation Loc, DeclarationName Entity); |
| 10000 | |
| 10001 | TypeSourceInfo *SubstFunctionDeclType( |
| 10002 | TypeSourceInfo *T, const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10003 | SourceLocation Loc, DeclarationName Entity, CXXRecordDecl *ThisContext, |
| 10004 | Qualifiers ThisTypeQuals, bool EvaluateConstraints = true); |
| 10005 | void SubstExceptionSpec(FunctionDecl *New, const FunctionProtoType *Proto, |
| 10006 | const MultiLevelTemplateArgumentList &Args); |
| 10007 | bool SubstExceptionSpec(SourceLocation Loc, |
| 10008 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| 10009 | SmallVectorImpl<QualType> &ExceptionStorage, |
| 10010 | const MultiLevelTemplateArgumentList &Args); |
| 10011 | ParmVarDecl * |
| 10012 | SubstParmVarDecl(ParmVarDecl *D, |
| 10013 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10014 | int indexAdjustment, std::optional<unsigned> NumExpansions, |
| 10015 | bool ExpectParameterPack, bool EvaluateConstraints = true); |
| 10016 | bool SubstParmTypes(SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 10017 | const FunctionProtoType::ExtParameterInfo *ExtParamInfos, |
| 10018 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10019 | SmallVectorImpl<QualType> &ParamTypes, |
| 10020 | SmallVectorImpl<ParmVarDecl *> *OutParams, |
| 10021 | ExtParameterInfoBuilder &ParamInfos); |
| 10022 | bool SubstDefaultArgument(SourceLocation Loc, ParmVarDecl *Param, |
| 10023 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10024 | bool ForCallExpr = false); |
| 10025 | ExprResult SubstExpr(Expr *E, |
| 10026 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10027 | |
| 10028 | // A RAII type used by the TemplateDeclInstantiator and TemplateInstantiator |
| 10029 | // to disable constraint evaluation, then restore the state. |
| 10030 | template <typename InstTy> struct ConstraintEvalRAII { |
| 10031 | InstTy &TI; |
| 10032 | bool OldValue; |
| 10033 | |
| 10034 | ConstraintEvalRAII(InstTy &TI) |
| 10035 | : TI(TI), OldValue(TI.getEvaluateConstraints()) { |
| 10036 | TI.setEvaluateConstraints(false); |
| 10037 | } |
| 10038 | ~ConstraintEvalRAII() { TI.setEvaluateConstraints(OldValue); } |
| 10039 | }; |
| 10040 | |
| 10041 | // Unlike the above, this evaluates constraints, which should only happen at |
| 10042 | // 'constraint checking' time. |
| 10043 | ExprResult |
| 10044 | SubstConstraintExpr(Expr *E, |
| 10045 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10046 | |
| 10047 | /// Substitute the given template arguments into a list of |
| 10048 | /// expressions, expanding pack expansions if required. |
| 10049 | /// |
| 10050 | /// \param Exprs The list of expressions to substitute into. |
| 10051 | /// |
| 10052 | /// \param IsCall Whether this is some form of call, in which case |
| 10053 | /// default arguments will be dropped. |
| 10054 | /// |
| 10055 | /// \param TemplateArgs The set of template arguments to substitute. |
| 10056 | /// |
| 10057 | /// \param Outputs Will receive all of the substituted arguments. |
| 10058 | /// |
| 10059 | /// \returns true if an error occurred, false otherwise. |
| 10060 | bool SubstExprs(ArrayRef<Expr *> Exprs, bool IsCall, |
| 10061 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10062 | SmallVectorImpl<Expr *> &Outputs); |
| 10063 | |
| 10064 | StmtResult SubstStmt(Stmt *S, |
| 10065 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10066 | |
| 10067 | TemplateParameterList * |
| 10068 | SubstTemplateParams(TemplateParameterList *Params, DeclContext *Owner, |
| 10069 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10070 | bool EvaluateConstraints = true); |
| 10071 | |
| 10072 | bool |
| 10073 | SubstTemplateArguments(ArrayRef<TemplateArgumentLoc> Args, |
| 10074 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10075 | TemplateArgumentListInfo &Outputs); |
| 10076 | |
| 10077 | Decl *SubstDecl(Decl *D, DeclContext *Owner, |
| 10078 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10079 | |
| 10080 | /// Substitute the name and return type of a defaulted 'operator<=>' to form |
| 10081 | /// an implicit 'operator=='. |
| 10082 | FunctionDecl *SubstSpaceshipAsEqualEqual(CXXRecordDecl *RD, |
| 10083 | FunctionDecl *Spaceship); |
| 10084 | |
| 10085 | ExprResult SubstInitializer(Expr *E, |
| 10086 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10087 | bool CXXDirectInit); |
| 10088 | |
| 10089 | bool |
| 10090 | SubstBaseSpecifiers(CXXRecordDecl *Instantiation, |
| 10091 | CXXRecordDecl *Pattern, |
| 10092 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10093 | |
| 10094 | bool |
| 10095 | InstantiateClass(SourceLocation PointOfInstantiation, |
| 10096 | CXXRecordDecl *Instantiation, CXXRecordDecl *Pattern, |
| 10097 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10098 | TemplateSpecializationKind TSK, |
| 10099 | bool Complain = true); |
| 10100 | |
| 10101 | bool InstantiateEnum(SourceLocation PointOfInstantiation, |
| 10102 | EnumDecl *Instantiation, EnumDecl *Pattern, |
| 10103 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10104 | TemplateSpecializationKind TSK); |
| 10105 | |
| 10106 | bool InstantiateInClassInitializer( |
| 10107 | SourceLocation PointOfInstantiation, FieldDecl *Instantiation, |
| 10108 | FieldDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10109 | |
| 10110 | struct LateInstantiatedAttribute { |
| 10111 | const Attr *TmplAttr; |
| 10112 | LocalInstantiationScope *Scope; |
| 10113 | Decl *NewDecl; |
| 10114 | |
| 10115 | LateInstantiatedAttribute(const Attr *A, LocalInstantiationScope *S, |
| 10116 | Decl *D) |
| 10117 | : TmplAttr(A), Scope(S), NewDecl(D) |
| 10118 | { } |
| 10119 | }; |
| 10120 | typedef SmallVector<LateInstantiatedAttribute, 16> LateInstantiatedAttrVec; |
| 10121 | |
| 10122 | void InstantiateAttrs(const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10123 | const Decl *Pattern, Decl *Inst, |
| 10124 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
| 10125 | LocalInstantiationScope *OuterMostScope = nullptr); |
| 10126 | void updateAttrsForLateParsedTemplate(const Decl *Pattern, Decl *Inst); |
| 10127 | |
| 10128 | void |
| 10129 | InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10130 | const Decl *Pattern, Decl *Inst, |
| 10131 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
| 10132 | LocalInstantiationScope *OuterMostScope = nullptr); |
| 10133 | |
| 10134 | void InstantiateDefaultCtorDefaultArgs(CXXConstructorDecl *Ctor); |
| 10135 | |
| 10136 | bool usesPartialOrExplicitSpecialization( |
| 10137 | SourceLocation Loc, ClassTemplateSpecializationDecl *ClassTemplateSpec); |
| 10138 | |
| 10139 | bool |
| 10140 | InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation, |
| 10141 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 10142 | TemplateSpecializationKind TSK, |
| 10143 | bool Complain = true); |
| 10144 | |
| 10145 | void InstantiateClassMembers(SourceLocation PointOfInstantiation, |
| 10146 | CXXRecordDecl *Instantiation, |
| 10147 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10148 | TemplateSpecializationKind TSK); |
| 10149 | |
| 10150 | void InstantiateClassTemplateSpecializationMembers( |
| 10151 | SourceLocation PointOfInstantiation, |
| 10152 | ClassTemplateSpecializationDecl *ClassTemplateSpec, |
| 10153 | TemplateSpecializationKind TSK); |
| 10154 | |
| 10155 | NestedNameSpecifierLoc |
| 10156 | SubstNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 10157 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10158 | |
| 10159 | DeclarationNameInfo |
| 10160 | SubstDeclarationNameInfo(const DeclarationNameInfo &NameInfo, |
| 10161 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10162 | TemplateName |
| 10163 | SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name, |
| 10164 | SourceLocation Loc, |
| 10165 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10166 | |
| 10167 | bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint *TC, |
| 10168 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10169 | bool EvaluateConstraint); |
| 10170 | |
| 10171 | bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD, |
| 10172 | ParmVarDecl *Param); |
| 10173 | void InstantiateExceptionSpec(SourceLocation PointOfInstantiation, |
| 10174 | FunctionDecl *Function); |
| 10175 | bool CheckInstantiatedFunctionTemplateConstraints( |
| 10176 | SourceLocation PointOfInstantiation, FunctionDecl *Decl, |
| 10177 | ArrayRef<TemplateArgument> TemplateArgs, |
| 10178 | ConstraintSatisfaction &Satisfaction); |
| 10179 | FunctionDecl *InstantiateFunctionDeclaration(FunctionTemplateDecl *FTD, |
| 10180 | const TemplateArgumentList *Args, |
| 10181 | SourceLocation Loc); |
| 10182 | void InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, |
| 10183 | FunctionDecl *Function, |
| 10184 | bool Recursive = false, |
| 10185 | bool DefinitionRequired = false, |
| 10186 | bool AtEndOfTU = false); |
| 10187 | VarTemplateSpecializationDecl *BuildVarTemplateInstantiation( |
| 10188 | VarTemplateDecl *VarTemplate, VarDecl *FromVar, |
| 10189 | const TemplateArgumentList &TemplateArgList, |
| 10190 | const TemplateArgumentListInfo &TemplateArgsInfo, |
| 10191 | SmallVectorImpl<TemplateArgument> &Converted, |
| 10192 | SourceLocation PointOfInstantiation, |
| 10193 | LateInstantiatedAttrVec *LateAttrs = nullptr, |
| 10194 | LocalInstantiationScope *StartingScope = nullptr); |
| 10195 | VarTemplateSpecializationDecl *CompleteVarTemplateSpecializationDecl( |
| 10196 | VarTemplateSpecializationDecl *VarSpec, VarDecl *PatternDecl, |
| 10197 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10198 | void |
| 10199 | BuildVariableInstantiation(VarDecl *NewVar, VarDecl *OldVar, |
| 10200 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10201 | LateInstantiatedAttrVec *LateAttrs, |
| 10202 | DeclContext *Owner, |
| 10203 | LocalInstantiationScope *StartingScope, |
| 10204 | bool InstantiatingVarTemplate = false, |
| 10205 | VarTemplateSpecializationDecl *PrevVTSD = nullptr); |
| 10206 | |
| 10207 | void InstantiateVariableInitializer( |
| 10208 | VarDecl *Var, VarDecl *OldVar, |
| 10209 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10210 | void InstantiateVariableDefinition(SourceLocation PointOfInstantiation, |
| 10211 | VarDecl *Var, bool Recursive = false, |
| 10212 | bool DefinitionRequired = false, |
| 10213 | bool AtEndOfTU = false); |
| 10214 | |
| 10215 | void InstantiateMemInitializers(CXXConstructorDecl *New, |
| 10216 | const CXXConstructorDecl *Tmpl, |
| 10217 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10218 | |
| 10219 | NamedDecl *FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D, |
| 10220 | const MultiLevelTemplateArgumentList &TemplateArgs, |
| 10221 | bool FindingInstantiatedContext = false); |
| 10222 | DeclContext *FindInstantiatedContext(SourceLocation Loc, DeclContext *DC, |
| 10223 | const MultiLevelTemplateArgumentList &TemplateArgs); |
| 10224 | |
| 10225 | // Objective-C declarations. |
| 10226 | enum ObjCContainerKind { |
| 10227 | OCK_None = -1, |
| 10228 | OCK_Interface = 0, |
| 10229 | OCK_Protocol, |
| 10230 | OCK_Category, |
| 10231 | OCK_ClassExtension, |
| 10232 | OCK_Implementation, |
| 10233 | OCK_CategoryImplementation |
| 10234 | }; |
| 10235 | ObjCContainerKind getObjCContainerKind() const; |
| 10236 | |
| 10237 | DeclResult actOnObjCTypeParam(Scope *S, |
| 10238 | ObjCTypeParamVariance variance, |
| 10239 | SourceLocation varianceLoc, |
| 10240 | unsigned index, |
| 10241 | IdentifierInfo *paramName, |
| 10242 | SourceLocation paramLoc, |
| 10243 | SourceLocation colonLoc, |
| 10244 | ParsedType typeBound); |
| 10245 | |
| 10246 | ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc, |
| 10247 | ArrayRef<Decl *> typeParams, |
| 10248 | SourceLocation rAngleLoc); |
| 10249 | void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList); |
| 10250 | |
| 10251 | ObjCInterfaceDecl *ActOnStartClassInterface( |
| 10252 | Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
| 10253 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
| 10254 | IdentifierInfo *SuperName, SourceLocation SuperLoc, |
| 10255 | ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange, |
| 10256 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
| 10257 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
| 10258 | const ParsedAttributesView &AttrList, SkipBodyInfo *SkipBody); |
| 10259 | |
| 10260 | void ActOnSuperClassOfClassInterface(Scope *S, |
| 10261 | SourceLocation AtInterfaceLoc, |
| 10262 | ObjCInterfaceDecl *IDecl, |
| 10263 | IdentifierInfo *ClassName, |
| 10264 | SourceLocation ClassLoc, |
| 10265 | IdentifierInfo *SuperName, |
| 10266 | SourceLocation SuperLoc, |
| 10267 | ArrayRef<ParsedType> SuperTypeArgs, |
| 10268 | SourceRange SuperTypeArgsRange); |
| 10269 | |
| 10270 | void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs, |
| 10271 | SmallVectorImpl<SourceLocation> &ProtocolLocs, |
| 10272 | IdentifierInfo *SuperName, |
| 10273 | SourceLocation SuperLoc); |
| 10274 | |
| 10275 | Decl *ActOnCompatibilityAlias( |
| 10276 | SourceLocation AtCompatibilityAliasLoc, |
| 10277 | IdentifierInfo *AliasName, SourceLocation AliasLocation, |
| 10278 | IdentifierInfo *ClassName, SourceLocation ClassLocation); |
| 10279 | |
| 10280 | bool CheckForwardProtocolDeclarationForCircularDependency( |
| 10281 | IdentifierInfo *PName, |
| 10282 | SourceLocation &PLoc, SourceLocation PrevLoc, |
| 10283 | const ObjCList<ObjCProtocolDecl> &PList); |
| 10284 | |
| 10285 | ObjCProtocolDecl *ActOnStartProtocolInterface( |
| 10286 | SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, |
| 10287 | SourceLocation ProtocolLoc, Decl *const *ProtoRefNames, |
| 10288 | unsigned NumProtoRefs, const SourceLocation *ProtoLocs, |
| 10289 | SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList, |
| 10290 | SkipBodyInfo *SkipBody); |
| 10291 | |
| 10292 | ObjCCategoryDecl *ActOnStartCategoryInterface( |
| 10293 | SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, |
| 10294 | SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, |
| 10295 | IdentifierInfo *CategoryName, SourceLocation CategoryLoc, |
| 10296 | Decl *const *ProtoRefs, unsigned NumProtoRefs, |
| 10297 | const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, |
| 10298 | const ParsedAttributesView &AttrList); |
| 10299 | |
| 10300 | ObjCImplementationDecl *ActOnStartClassImplementation( |
| 10301 | SourceLocation AtClassImplLoc, IdentifierInfo *ClassName, |
| 10302 | SourceLocation ClassLoc, IdentifierInfo *SuperClassname, |
| 10303 | SourceLocation SuperClassLoc, const ParsedAttributesView &AttrList); |
| 10304 | |
| 10305 | ObjCCategoryImplDecl *ActOnStartCategoryImplementation( |
| 10306 | SourceLocation AtCatImplLoc, IdentifierInfo *ClassName, |
| 10307 | SourceLocation ClassLoc, IdentifierInfo *CatName, SourceLocation CatLoc, |
| 10308 | const ParsedAttributesView &AttrList); |
| 10309 | |
| 10310 | DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, |
| 10311 | ArrayRef<Decl *> Decls); |
| 10312 | |
| 10313 | DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, |
| 10314 | IdentifierInfo **IdentList, |
| 10315 | SourceLocation *IdentLocs, |
| 10316 | ArrayRef<ObjCTypeParamList *> TypeParamLists, |
| 10317 | unsigned NumElts); |
| 10318 | |
| 10319 | DeclGroupPtrTy |
| 10320 | ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, |
| 10321 | ArrayRef<IdentifierLocPair> IdentList, |
| 10322 | const ParsedAttributesView &attrList); |
| 10323 | |
| 10324 | void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, |
| 10325 | ArrayRef<IdentifierLocPair> ProtocolId, |
| 10326 | SmallVectorImpl<Decl *> &Protocols); |
| 10327 | |
| 10328 | void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId, |
| 10329 | SourceLocation ProtocolLoc, |
| 10330 | IdentifierInfo *TypeArgId, |
| 10331 | SourceLocation TypeArgLoc, |
| 10332 | bool SelectProtocolFirst = false); |
| 10333 | |
| 10334 | /// Given a list of identifiers (and their locations), resolve the |
| 10335 | /// names to either Objective-C protocol qualifiers or type |
| 10336 | /// arguments, as appropriate. |
| 10337 | void actOnObjCTypeArgsOrProtocolQualifiers( |
| 10338 | Scope *S, |
| 10339 | ParsedType baseType, |
| 10340 | SourceLocation lAngleLoc, |
| 10341 | ArrayRef<IdentifierInfo *> identifiers, |
| 10342 | ArrayRef<SourceLocation> identifierLocs, |
| 10343 | SourceLocation rAngleLoc, |
| 10344 | SourceLocation &typeArgsLAngleLoc, |
| 10345 | SmallVectorImpl<ParsedType> &typeArgs, |
| 10346 | SourceLocation &typeArgsRAngleLoc, |
| 10347 | SourceLocation &protocolLAngleLoc, |
| 10348 | SmallVectorImpl<Decl *> &protocols, |
| 10349 | SourceLocation &protocolRAngleLoc, |
| 10350 | bool warnOnIncompleteProtocols); |
| 10351 | |
| 10352 | /// Build a an Objective-C protocol-qualified 'id' type where no |
| 10353 | /// base type was specified. |
| 10354 | TypeResult actOnObjCProtocolQualifierType( |
| 10355 | SourceLocation lAngleLoc, |
| 10356 | ArrayRef<Decl *> protocols, |
| 10357 | ArrayRef<SourceLocation> protocolLocs, |
| 10358 | SourceLocation rAngleLoc); |
| 10359 | |
| 10360 | /// Build a specialized and/or protocol-qualified Objective-C type. |
| 10361 | TypeResult actOnObjCTypeArgsAndProtocolQualifiers( |
| 10362 | Scope *S, |
| 10363 | SourceLocation Loc, |
| 10364 | ParsedType BaseType, |
| 10365 | SourceLocation TypeArgsLAngleLoc, |
| 10366 | ArrayRef<ParsedType> TypeArgs, |
| 10367 | SourceLocation TypeArgsRAngleLoc, |
| 10368 | SourceLocation ProtocolLAngleLoc, |
| 10369 | ArrayRef<Decl *> Protocols, |
| 10370 | ArrayRef<SourceLocation> ProtocolLocs, |
| 10371 | SourceLocation ProtocolRAngleLoc); |
| 10372 | |
| 10373 | /// Build an Objective-C type parameter type. |
| 10374 | QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
| 10375 | SourceLocation ProtocolLAngleLoc, |
| 10376 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 10377 | ArrayRef<SourceLocation> ProtocolLocs, |
| 10378 | SourceLocation ProtocolRAngleLoc, |
| 10379 | bool FailOnError = false); |
| 10380 | |
| 10381 | /// Build an Objective-C object pointer type. |
| 10382 | QualType BuildObjCObjectType( |
| 10383 | QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, |
| 10384 | ArrayRef<TypeSourceInfo *> TypeArgs, SourceLocation TypeArgsRAngleLoc, |
| 10385 | SourceLocation ProtocolLAngleLoc, ArrayRef<ObjCProtocolDecl *> Protocols, |
| 10386 | ArrayRef<SourceLocation> ProtocolLocs, SourceLocation ProtocolRAngleLoc, |
| 10387 | bool FailOnError, bool Rebuilding); |
| 10388 | |
| 10389 | /// Ensure attributes are consistent with type. |
| 10390 | /// \param [in, out] Attributes The attributes to check; they will |
| 10391 | /// be modified to be consistent with \p PropertyTy. |
| 10392 | void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, |
| 10393 | SourceLocation Loc, |
| 10394 | unsigned &Attributes, |
| 10395 | bool propertyInPrimaryClass); |
| 10396 | |
| 10397 | /// Process the specified property declaration and create decls for the |
| 10398 | /// setters and getters as needed. |
| 10399 | /// \param property The property declaration being processed |
| 10400 | void ProcessPropertyDecl(ObjCPropertyDecl *property); |
| 10401 | |
| 10402 | |
| 10403 | void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, |
| 10404 | ObjCPropertyDecl *SuperProperty, |
| 10405 | const IdentifierInfo *Name, |
| 10406 | bool OverridingProtocolProperty); |
| 10407 | |
| 10408 | void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, |
| 10409 | ObjCInterfaceDecl *ID); |
| 10410 | |
| 10411 | Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, |
| 10412 | ArrayRef<Decl *> allMethods = std::nullopt, |
| 10413 | ArrayRef<DeclGroupPtrTy> allTUVars = std::nullopt); |
| 10414 | |
| 10415 | Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, |
| 10416 | SourceLocation LParenLoc, |
| 10417 | FieldDeclarator &FD, ObjCDeclSpec &ODS, |
| 10418 | Selector GetterSel, Selector SetterSel, |
| 10419 | tok::ObjCKeywordKind MethodImplKind, |
| 10420 | DeclContext *lexicalDC = nullptr); |
| 10421 | |
| 10422 | Decl *ActOnPropertyImplDecl(Scope *S, |
| 10423 | SourceLocation AtLoc, |
| 10424 | SourceLocation PropertyLoc, |
| 10425 | bool ImplKind, |
| 10426 | IdentifierInfo *PropertyId, |
| 10427 | IdentifierInfo *PropertyIvar, |
| 10428 | SourceLocation PropertyIvarLoc, |
| 10429 | ObjCPropertyQueryKind QueryKind); |
| 10430 | |
| 10431 | enum ObjCSpecialMethodKind { |
| 10432 | OSMK_None, |
| 10433 | OSMK_Alloc, |
| 10434 | OSMK_New, |
| 10435 | OSMK_Copy, |
| 10436 | OSMK_RetainingInit, |
| 10437 | OSMK_NonRetainingInit |
| 10438 | }; |
| 10439 | |
| 10440 | struct ObjCArgInfo { |
| 10441 | IdentifierInfo *Name; |
| 10442 | SourceLocation NameLoc; |
| 10443 | // The Type is null if no type was specified, and the DeclSpec is invalid |
| 10444 | // in this case. |
| 10445 | ParsedType Type; |
| 10446 | ObjCDeclSpec DeclSpec; |
| 10447 | |
| 10448 | /// ArgAttrs - Attribute list for this argument. |
| 10449 | ParsedAttributesView ArgAttrs; |
| 10450 | }; |
| 10451 | |
| 10452 | Decl *ActOnMethodDeclaration( |
| 10453 | Scope *S, |
| 10454 | SourceLocation BeginLoc, // location of the + or -. |
| 10455 | SourceLocation EndLoc, // location of the ; or {. |
| 10456 | tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, |
| 10457 | ArrayRef<SourceLocation> SelectorLocs, Selector Sel, |
| 10458 | // optional arguments. The number of types/arguments is obtained |
| 10459 | // from the Sel.getNumArgs(). |
| 10460 | ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo, |
| 10461 | unsigned CNumArgs, // c-style args |
| 10462 | const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind, |
| 10463 | bool isVariadic, bool MethodDefinition); |
| 10464 | |
| 10465 | ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, |
| 10466 | const ObjCObjectPointerType *OPT, |
| 10467 | bool IsInstance); |
| 10468 | ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, |
| 10469 | bool IsInstance); |
| 10470 | |
| 10471 | bool CheckARCMethodDecl(ObjCMethodDecl *method); |
| 10472 | bool inferObjCARCLifetime(ValueDecl *decl); |
| 10473 | |
| 10474 | void deduceOpenCLAddressSpace(ValueDecl *decl); |
| 10475 | |
| 10476 | ExprResult |
| 10477 | HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, |
| 10478 | Expr *BaseExpr, |
| 10479 | SourceLocation OpLoc, |
| 10480 | DeclarationName MemberName, |
| 10481 | SourceLocation MemberLoc, |
| 10482 | SourceLocation SuperLoc, QualType SuperType, |
| 10483 | bool Super); |
| 10484 | |
| 10485 | ExprResult |
| 10486 | ActOnClassPropertyRefExpr(IdentifierInfo &receiverName, |
| 10487 | IdentifierInfo &propertyName, |
| 10488 | SourceLocation receiverNameLoc, |
| 10489 | SourceLocation propertyNameLoc); |
| 10490 | |
| 10491 | ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); |
| 10492 | |
| 10493 | /// Describes the kind of message expression indicated by a message |
| 10494 | /// send that starts with an identifier. |
| 10495 | enum ObjCMessageKind { |
| 10496 | /// The message is sent to 'super'. |
| 10497 | ObjCSuperMessage, |
| 10498 | /// The message is an instance message. |
| 10499 | ObjCInstanceMessage, |
| 10500 | /// The message is a class message, and the identifier is a type |
| 10501 | /// name. |
| 10502 | ObjCClassMessage |
| 10503 | }; |
| 10504 | |
| 10505 | ObjCMessageKind getObjCMessageKind(Scope *S, |
| 10506 | IdentifierInfo *Name, |
| 10507 | SourceLocation NameLoc, |
| 10508 | bool IsSuper, |
| 10509 | bool HasTrailingDot, |
| 10510 | ParsedType &ReceiverType); |
| 10511 | |
| 10512 | ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, |
| 10513 | Selector Sel, |
| 10514 | SourceLocation LBracLoc, |
| 10515 | ArrayRef<SourceLocation> SelectorLocs, |
| 10516 | SourceLocation RBracLoc, |
| 10517 | MultiExprArg Args); |
| 10518 | |
| 10519 | ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, |
| 10520 | QualType ReceiverType, |
| 10521 | SourceLocation SuperLoc, |
| 10522 | Selector Sel, |
| 10523 | ObjCMethodDecl *Method, |
| 10524 | SourceLocation LBracLoc, |
| 10525 | ArrayRef<SourceLocation> SelectorLocs, |
| 10526 | SourceLocation RBracLoc, |
| 10527 | MultiExprArg Args, |
| 10528 | bool isImplicit = false); |
| 10529 | |
| 10530 | ExprResult BuildClassMessageImplicit(QualType ReceiverType, |
| 10531 | bool isSuperReceiver, |
| 10532 | SourceLocation Loc, |
| 10533 | Selector Sel, |
| 10534 | ObjCMethodDecl *Method, |
| 10535 | MultiExprArg Args); |
| 10536 | |
| 10537 | ExprResult ActOnClassMessage(Scope *S, |
| 10538 | ParsedType Receiver, |
| 10539 | Selector Sel, |
| 10540 | SourceLocation LBracLoc, |
| 10541 | ArrayRef<SourceLocation> SelectorLocs, |
| 10542 | SourceLocation RBracLoc, |
| 10543 | MultiExprArg Args); |
| 10544 | |
| 10545 | ExprResult BuildInstanceMessage(Expr *Receiver, |
| 10546 | QualType ReceiverType, |
| 10547 | SourceLocation SuperLoc, |
| 10548 | Selector Sel, |
| 10549 | ObjCMethodDecl *Method, |
| 10550 | SourceLocation LBracLoc, |
| 10551 | ArrayRef<SourceLocation> SelectorLocs, |
| 10552 | SourceLocation RBracLoc, |
| 10553 | MultiExprArg Args, |
| 10554 | bool isImplicit = false); |
| 10555 | |
| 10556 | ExprResult BuildInstanceMessageImplicit(Expr *Receiver, |
| 10557 | QualType ReceiverType, |
| 10558 | SourceLocation Loc, |
| 10559 | Selector Sel, |
| 10560 | ObjCMethodDecl *Method, |
| 10561 | MultiExprArg Args); |
| 10562 | |
| 10563 | ExprResult ActOnInstanceMessage(Scope *S, |
| 10564 | Expr *Receiver, |
| 10565 | Selector Sel, |
| 10566 | SourceLocation LBracLoc, |
| 10567 | ArrayRef<SourceLocation> SelectorLocs, |
| 10568 | SourceLocation RBracLoc, |
| 10569 | MultiExprArg Args); |
| 10570 | |
| 10571 | ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, |
| 10572 | ObjCBridgeCastKind Kind, |
| 10573 | SourceLocation BridgeKeywordLoc, |
| 10574 | TypeSourceInfo *TSInfo, |
| 10575 | Expr *SubExpr); |
| 10576 | |
| 10577 | ExprResult ActOnObjCBridgedCast(Scope *S, |
| 10578 | SourceLocation LParenLoc, |
| 10579 | ObjCBridgeCastKind Kind, |
| 10580 | SourceLocation BridgeKeywordLoc, |
| 10581 | ParsedType Type, |
| 10582 | SourceLocation RParenLoc, |
| 10583 | Expr *SubExpr); |
| 10584 | |
| 10585 | void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr); |
| 10586 | |
| 10587 | void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr); |
| 10588 | |
| 10589 | bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, |
| 10590 | CastKind &Kind); |
| 10591 | |
| 10592 | bool checkObjCBridgeRelatedComponents(SourceLocation Loc, |
| 10593 | QualType DestType, QualType SrcType, |
| 10594 | ObjCInterfaceDecl *&RelatedClass, |
| 10595 | ObjCMethodDecl *&ClassMethod, |
| 10596 | ObjCMethodDecl *&InstanceMethod, |
| 10597 | TypedefNameDecl *&TDNDecl, |
| 10598 | bool CfToNs, bool Diagnose = true); |
| 10599 | |
| 10600 | bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, |
| 10601 | QualType DestType, QualType SrcType, |
| 10602 | Expr *&SrcExpr, bool Diagnose = true); |
| 10603 | |
| 10604 | bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr, |
| 10605 | bool Diagnose = true); |
| 10606 | |
| 10607 | bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); |
| 10608 | |
| 10609 | /// Check whether the given new method is a valid override of the |
| 10610 | /// given overridden method, and set any properties that should be inherited. |
| 10611 | void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, |
| 10612 | const ObjCMethodDecl *Overridden); |
| 10613 | |
| 10614 | /// Describes the compatibility of a result type with its method. |
| 10615 | enum ResultTypeCompatibilityKind { |
| 10616 | RTC_Compatible, |
| 10617 | RTC_Incompatible, |
| 10618 | RTC_Unknown |
| 10619 | }; |
| 10620 | |
| 10621 | void CheckObjCMethodDirectOverrides(ObjCMethodDecl *method, |
| 10622 | ObjCMethodDecl *overridden); |
| 10623 | |
| 10624 | void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, |
| 10625 | ObjCInterfaceDecl *CurrentClass, |
| 10626 | ResultTypeCompatibilityKind RTC); |
| 10627 | |
| 10628 | enum PragmaOptionsAlignKind { |
| 10629 | POAK_Native, // #pragma options align=native |
| 10630 | POAK_Natural, // #pragma options align=natural |
| 10631 | POAK_Packed, // #pragma options align=packed |
| 10632 | POAK_Power, // #pragma options align=power |
| 10633 | POAK_Mac68k, // #pragma options align=mac68k |
| 10634 | POAK_Reset // #pragma options align=reset |
| 10635 | }; |
| 10636 | |
| 10637 | /// ActOnPragmaClangSection - Called on well formed \#pragma clang section |
| 10638 | void ActOnPragmaClangSection(SourceLocation PragmaLoc, |
| 10639 | PragmaClangSectionAction Action, |
| 10640 | PragmaClangSectionKind SecKind, StringRef SecName); |
| 10641 | |
| 10642 | /// ActOnPragmaOptionsAlign - Called on well formed \#pragma options align. |
| 10643 | void ActOnPragmaOptionsAlign(PragmaOptionsAlignKind Kind, |
| 10644 | SourceLocation PragmaLoc); |
| 10645 | |
| 10646 | /// ActOnPragmaPack - Called on well formed \#pragma pack(...). |
| 10647 | void ActOnPragmaPack(SourceLocation PragmaLoc, PragmaMsStackAction Action, |
| 10648 | StringRef SlotLabel, Expr *Alignment); |
| 10649 | |
| 10650 | enum class PragmaAlignPackDiagnoseKind { |
| 10651 | NonDefaultStateAtInclude, |
| 10652 | ChangedStateAtExit |
| 10653 | }; |
| 10654 | |
| 10655 | void DiagnoseNonDefaultPragmaAlignPack(PragmaAlignPackDiagnoseKind Kind, |
| 10656 | SourceLocation IncludeLoc); |
| 10657 | void DiagnoseUnterminatedPragmaAlignPack(); |
| 10658 | |
| 10659 | /// ActOnPragmaMSStrictGuardStackCheck - Called on well formed \#pragma |
| 10660 | /// strict_gs_check. |
| 10661 | void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation, |
| 10662 | PragmaMsStackAction Action, |
| 10663 | bool Value); |
| 10664 | |
| 10665 | /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off]. |
| 10666 | void ActOnPragmaMSStruct(PragmaMSStructKind Kind); |
| 10667 | |
| 10668 | /// ActOnPragmaMSComment - Called on well formed |
| 10669 | /// \#pragma comment(kind, "arg"). |
| 10670 | void ActOnPragmaMSComment(SourceLocation CommentLoc, PragmaMSCommentKind Kind, |
| 10671 | StringRef Arg); |
| 10672 | |
| 10673 | /// ActOnPragmaMSPointersToMembers - called on well formed \#pragma |
| 10674 | /// pointers_to_members(representation method[, general purpose |
| 10675 | /// representation]). |
| 10676 | void ActOnPragmaMSPointersToMembers( |
| 10677 | LangOptions::PragmaMSPointersToMembersKind Kind, |
| 10678 | SourceLocation PragmaLoc); |
| 10679 | |
| 10680 | /// Called on well formed \#pragma vtordisp(). |
| 10681 | void ActOnPragmaMSVtorDisp(PragmaMsStackAction Action, |
| 10682 | SourceLocation PragmaLoc, |
| 10683 | MSVtorDispMode Value); |
| 10684 | |
| 10685 | enum PragmaSectionKind { |
| 10686 | PSK_DataSeg, |
| 10687 | PSK_BSSSeg, |
| 10688 | PSK_ConstSeg, |
| 10689 | PSK_CodeSeg, |
| 10690 | }; |
| 10691 | |
| 10692 | bool UnifySection(StringRef SectionName, int SectionFlags, |
| 10693 | NamedDecl *TheDecl); |
| 10694 | bool UnifySection(StringRef SectionName, |
| 10695 | int SectionFlags, |
| 10696 | SourceLocation PragmaSectionLocation); |
| 10697 | |
| 10698 | /// Called on well formed \#pragma bss_seg/data_seg/const_seg/code_seg. |
| 10699 | void ActOnPragmaMSSeg(SourceLocation PragmaLocation, |
| 10700 | PragmaMsStackAction Action, |
| 10701 | llvm::StringRef StackSlotLabel, |
| 10702 | StringLiteral *SegmentName, |
| 10703 | llvm::StringRef PragmaName); |
| 10704 | |
| 10705 | /// Called on well formed \#pragma section(). |
| 10706 | void ActOnPragmaMSSection(SourceLocation PragmaLocation, |
| 10707 | int SectionFlags, StringLiteral *SegmentName); |
| 10708 | |
| 10709 | /// Called on well-formed \#pragma init_seg(). |
| 10710 | void ActOnPragmaMSInitSeg(SourceLocation PragmaLocation, |
| 10711 | StringLiteral *SegmentName); |
| 10712 | |
| 10713 | /// Called on well-formed \#pragma alloc_text(). |
| 10714 | void ActOnPragmaMSAllocText( |
| 10715 | SourceLocation PragmaLocation, StringRef Section, |
| 10716 | const SmallVector<std::tuple<IdentifierInfo *, SourceLocation>> |
| 10717 | &Functions); |
| 10718 | |
| 10719 | /// Called on #pragma clang __debug dump II |
| 10720 | void ActOnPragmaDump(Scope *S, SourceLocation Loc, IdentifierInfo *II); |
| 10721 | |
| 10722 | /// Called on #pragma clang __debug dump E |
| 10723 | void ActOnPragmaDump(Expr *E); |
| 10724 | |
| 10725 | /// ActOnPragmaDetectMismatch - Call on well-formed \#pragma detect_mismatch |
| 10726 | void ActOnPragmaDetectMismatch(SourceLocation Loc, StringRef Name, |
| 10727 | StringRef Value); |
| 10728 | |
| 10729 | /// Are precise floating point semantics currently enabled? |
| 10730 | bool isPreciseFPEnabled() { |
| 10731 | return !CurFPFeatures.getAllowFPReassociate() && |
| 10732 | !CurFPFeatures.getNoSignedZero() && |
| 10733 | !CurFPFeatures.getAllowReciprocal() && |
| 10734 | !CurFPFeatures.getAllowApproxFunc(); |
| 10735 | } |
| 10736 | |
| 10737 | void ActOnPragmaFPEvalMethod(SourceLocation Loc, |
| 10738 | LangOptions::FPEvalMethodKind Value); |
| 10739 | |
| 10740 | /// ActOnPragmaFloatControl - Call on well-formed \#pragma float_control |
| 10741 | void ActOnPragmaFloatControl(SourceLocation Loc, PragmaMsStackAction Action, |
| 10742 | PragmaFloatControlKind Value); |
| 10743 | |
| 10744 | /// ActOnPragmaUnused - Called on well-formed '\#pragma unused'. |
| 10745 | void ActOnPragmaUnused(const Token &Identifier, |
| 10746 | Scope *curScope, |
| 10747 | SourceLocation PragmaLoc); |
| 10748 | |
| 10749 | /// ActOnPragmaVisibility - Called on well formed \#pragma GCC visibility... . |
| 10750 | void ActOnPragmaVisibility(const IdentifierInfo* VisType, |
| 10751 | SourceLocation PragmaLoc); |
| 10752 | |
| 10753 | NamedDecl *DeclClonePragmaWeak(NamedDecl *ND, const IdentifierInfo *II, |
| 10754 | SourceLocation Loc); |
| 10755 | void DeclApplyPragmaWeak(Scope *S, NamedDecl *ND, const WeakInfo &W); |
| 10756 | |
| 10757 | /// ActOnPragmaWeakID - Called on well formed \#pragma weak ident. |
| 10758 | void ActOnPragmaWeakID(IdentifierInfo* WeakName, |
| 10759 | SourceLocation PragmaLoc, |
| 10760 | SourceLocation WeakNameLoc); |
| 10761 | |
| 10762 | /// ActOnPragmaRedefineExtname - Called on well formed |
| 10763 | /// \#pragma redefine_extname oldname newname. |
| 10764 | void ActOnPragmaRedefineExtname(IdentifierInfo* WeakName, |
| 10765 | IdentifierInfo* AliasName, |
| 10766 | SourceLocation PragmaLoc, |
| 10767 | SourceLocation WeakNameLoc, |
| 10768 | SourceLocation AliasNameLoc); |
| 10769 | |
| 10770 | /// ActOnPragmaWeakAlias - Called on well formed \#pragma weak ident = ident. |
| 10771 | void ActOnPragmaWeakAlias(IdentifierInfo* WeakName, |
| 10772 | IdentifierInfo* AliasName, |
| 10773 | SourceLocation PragmaLoc, |
| 10774 | SourceLocation WeakNameLoc, |
| 10775 | SourceLocation AliasNameLoc); |
| 10776 | |
| 10777 | /// ActOnPragmaFPContract - Called on well formed |
| 10778 | /// \#pragma {STDC,OPENCL} FP_CONTRACT and |
| 10779 | /// \#pragma clang fp contract |
| 10780 | void ActOnPragmaFPContract(SourceLocation Loc, LangOptions::FPModeKind FPC); |
| 10781 | |
| 10782 | /// Called on well formed |
| 10783 | /// \#pragma clang fp reassociate |
| 10784 | void ActOnPragmaFPReassociate(SourceLocation Loc, bool IsEnabled); |
| 10785 | |
| 10786 | /// ActOnPragmaFenvAccess - Called on well formed |
| 10787 | /// \#pragma STDC FENV_ACCESS |
| 10788 | void ActOnPragmaFEnvAccess(SourceLocation Loc, bool IsEnabled); |
| 10789 | |
| 10790 | /// Called on well formed '\#pragma clang fp' that has option 'exceptions'. |
| 10791 | void ActOnPragmaFPExceptions(SourceLocation Loc, |
| 10792 | LangOptions::FPExceptionModeKind); |
| 10793 | |
| 10794 | /// Called to set constant rounding mode for floating point operations. |
| 10795 | void ActOnPragmaFEnvRound(SourceLocation Loc, llvm::RoundingMode); |
| 10796 | |
| 10797 | /// Called to set exception behavior for floating point operations. |
| 10798 | void setExceptionMode(SourceLocation Loc, LangOptions::FPExceptionModeKind); |
| 10799 | |
| 10800 | /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to |
| 10801 | /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'. |
| 10802 | void AddAlignmentAttributesForRecord(RecordDecl *RD); |
| 10803 | |
| 10804 | /// AddMsStructLayoutForRecord - Adds ms_struct layout attribute to record. |
| 10805 | void AddMsStructLayoutForRecord(RecordDecl *RD); |
| 10806 | |
| 10807 | /// PushNamespaceVisibilityAttr - Note that we've entered a |
| 10808 | /// namespace with a visibility attribute. |
| 10809 | void PushNamespaceVisibilityAttr(const VisibilityAttr *Attr, |
| 10810 | SourceLocation Loc); |
| 10811 | |
| 10812 | /// AddPushedVisibilityAttribute - If '\#pragma GCC visibility' was used, |
| 10813 | /// add an appropriate visibility attribute. |
| 10814 | void AddPushedVisibilityAttribute(Decl *RD); |
| 10815 | |
| 10816 | /// PopPragmaVisibility - Pop the top element of the visibility stack; used |
| 10817 | /// for '\#pragma GCC visibility' and visibility attributes on namespaces. |
| 10818 | void PopPragmaVisibility(bool IsNamespaceEnd, SourceLocation EndLoc); |
| 10819 | |
| 10820 | /// FreeVisContext - Deallocate and null out VisContext. |
| 10821 | void FreeVisContext(); |
| 10822 | |
| 10823 | /// AddCFAuditedAttribute - Check whether we're currently within |
| 10824 | /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding |
| 10825 | /// the appropriate attribute. |
| 10826 | void AddCFAuditedAttribute(Decl *D); |
| 10827 | |
| 10828 | void ActOnPragmaAttributeAttribute(ParsedAttr &Attribute, |
| 10829 | SourceLocation PragmaLoc, |
| 10830 | attr::ParsedSubjectMatchRuleSet Rules); |
| 10831 | void ActOnPragmaAttributeEmptyPush(SourceLocation PragmaLoc, |
| 10832 | const IdentifierInfo *Namespace); |
| 10833 | |
| 10834 | /// Called on well-formed '\#pragma clang attribute pop'. |
| 10835 | void ActOnPragmaAttributePop(SourceLocation PragmaLoc, |
| 10836 | const IdentifierInfo *Namespace); |
| 10837 | |
| 10838 | /// Adds the attributes that have been specified using the |
| 10839 | /// '\#pragma clang attribute push' directives to the given declaration. |
| 10840 | void AddPragmaAttributes(Scope *S, Decl *D); |
| 10841 | |
| 10842 | void DiagnoseUnterminatedPragmaAttribute(); |
| 10843 | |
| 10844 | /// Called on well formed \#pragma clang optimize. |
| 10845 | void ActOnPragmaOptimize(bool On, SourceLocation PragmaLoc); |
| 10846 | |
| 10847 | /// #pragma optimize("[optimization-list]", on | off). |
| 10848 | void ActOnPragmaMSOptimize(SourceLocation Loc, bool IsOn); |
| 10849 | |
| 10850 | /// Call on well formed \#pragma function. |
| 10851 | void |
| 10852 | ActOnPragmaMSFunction(SourceLocation Loc, |
| 10853 | const llvm::SmallVectorImpl<StringRef> &NoBuiltins); |
| 10854 | |
| 10855 | /// Get the location for the currently active "\#pragma clang optimize |
| 10856 | /// off". If this location is invalid, then the state of the pragma is "on". |
| 10857 | SourceLocation getOptimizeOffPragmaLocation() const { |
| 10858 | return OptimizeOffPragmaLocation; |
| 10859 | } |
| 10860 | |
| 10861 | /// Only called on function definitions; if there is a pragma in scope |
| 10862 | /// with the effect of a range-based optnone, consider marking the function |
| 10863 | /// with attribute optnone. |
| 10864 | void AddRangeBasedOptnone(FunctionDecl *FD); |
| 10865 | |
| 10866 | /// Only called on function definitions; if there is a `#pragma alloc_text` |
| 10867 | /// that decides which code section the function should be in, add |
| 10868 | /// attribute section to the function. |
| 10869 | void AddSectionMSAllocText(FunctionDecl *FD); |
| 10870 | |
| 10871 | /// Adds the 'optnone' attribute to the function declaration if there |
| 10872 | /// are no conflicts; Loc represents the location causing the 'optnone' |
| 10873 | /// attribute to be added (usually because of a pragma). |
| 10874 | void AddOptnoneAttributeIfNoConflicts(FunctionDecl *FD, SourceLocation Loc); |
| 10875 | |
| 10876 | /// Only called on function definitions; if there is a MSVC #pragma optimize |
| 10877 | /// in scope, consider changing the function's attributes based on the |
| 10878 | /// optimization list passed to the pragma. |
| 10879 | void ModifyFnAttributesMSPragmaOptimize(FunctionDecl *FD); |
| 10880 | |
| 10881 | /// Only called on function definitions; if there is a pragma in scope |
| 10882 | /// with the effect of a range-based no_builtin, consider marking the function |
| 10883 | /// with attribute no_builtin. |
| 10884 | void AddImplicitMSFunctionNoBuiltinAttr(FunctionDecl *FD); |
| 10885 | |
| 10886 | /// AddAlignedAttr - Adds an aligned attribute to a particular declaration. |
| 10887 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
| 10888 | bool IsPackExpansion); |
| 10889 | void AddAlignedAttr(Decl *D, const AttributeCommonInfo &CI, TypeSourceInfo *T, |
| 10890 | bool IsPackExpansion); |
| 10891 | |
| 10892 | /// AddAssumeAlignedAttr - Adds an assume_aligned attribute to a particular |
| 10893 | /// declaration. |
| 10894 | void AddAssumeAlignedAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E, |
| 10895 | Expr *OE); |
| 10896 | |
| 10897 | /// AddAllocAlignAttr - Adds an alloc_align attribute to a particular |
| 10898 | /// declaration. |
| 10899 | void AddAllocAlignAttr(Decl *D, const AttributeCommonInfo &CI, |
| 10900 | Expr *ParamExpr); |
| 10901 | |
| 10902 | /// AddAlignValueAttr - Adds an align_value attribute to a particular |
| 10903 | /// declaration. |
| 10904 | void AddAlignValueAttr(Decl *D, const AttributeCommonInfo &CI, Expr *E); |
| 10905 | |
| 10906 | /// AddAnnotationAttr - Adds an annotation Annot with Args arguments to D. |
| 10907 | void AddAnnotationAttr(Decl *D, const AttributeCommonInfo &CI, |
| 10908 | StringRef Annot, MutableArrayRef<Expr *> Args); |
| 10909 | |
| 10910 | /// ConstantFoldAttrArgs - Folds attribute arguments into ConstantExprs |
| 10911 | /// (unless they are value dependent or type dependent). Returns false |
| 10912 | /// and emits a diagnostic if one or more of the arguments could not be |
| 10913 | /// folded into a constant. |
| 10914 | bool ConstantFoldAttrArgs(const AttributeCommonInfo &CI, |
| 10915 | MutableArrayRef<Expr *> Args); |
| 10916 | |
| 10917 | /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular |
| 10918 | /// declaration. |
| 10919 | void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI, |
| 10920 | Expr *MaxThreads, Expr *MinBlocks); |
| 10921 | |
| 10922 | /// AddModeAttr - Adds a mode attribute to a particular declaration. |
| 10923 | void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo *Name, |
| 10924 | bool InInstantiation = false); |
| 10925 | |
| 10926 | void AddParameterABIAttr(Decl *D, const AttributeCommonInfo &CI, |
| 10927 | ParameterABI ABI); |
| 10928 | |
| 10929 | enum class RetainOwnershipKind {NS, CF, OS}; |
| 10930 | void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, |
| 10931 | RetainOwnershipKind K, bool IsTemplateInstantiation); |
| 10932 | |
| 10933 | /// addAMDGPUFlatWorkGroupSizeAttr - Adds an amdgpu_flat_work_group_size |
| 10934 | /// attribute to a particular declaration. |
| 10935 | void addAMDGPUFlatWorkGroupSizeAttr(Decl *D, const AttributeCommonInfo &CI, |
| 10936 | Expr *Min, Expr *Max); |
| 10937 | |
| 10938 | /// addAMDGPUWavePersEUAttr - Adds an amdgpu_waves_per_eu attribute to a |
| 10939 | /// particular declaration. |
| 10940 | void addAMDGPUWavesPerEUAttr(Decl *D, const AttributeCommonInfo &CI, |
| 10941 | Expr *Min, Expr *Max); |
| 10942 | |
| 10943 | bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type); |
| 10944 | |
| 10945 | //===--------------------------------------------------------------------===// |
| 10946 | // C++ Coroutines |
| 10947 | // |
| 10948 | bool ActOnCoroutineBodyStart(Scope *S, SourceLocation KwLoc, |
| 10949 | StringRef Keyword); |
| 10950 | ExprResult ActOnCoawaitExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
| 10951 | ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E); |
| 10952 | StmtResult ActOnCoreturnStmt(Scope *S, SourceLocation KwLoc, Expr *E); |
| 10953 | |
| 10954 | ExprResult BuildOperatorCoawaitLookupExpr(Scope *S, SourceLocation Loc); |
| 10955 | ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, |
| 10956 | UnresolvedLookupExpr *Lookup); |
| 10957 | ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
| 10958 | Expr *Awaiter, bool IsImplicit = false); |
| 10959 | ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, |
| 10960 | UnresolvedLookupExpr *Lookup); |
| 10961 | ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E); |
| 10962 | StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, |
| 10963 | bool IsImplicit = false); |
| 10964 | StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs); |
| 10965 | bool buildCoroutineParameterMoves(SourceLocation Loc); |
| 10966 | VarDecl *buildCoroutinePromise(SourceLocation Loc); |
| 10967 | void CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *&Body); |
| 10968 | /// Lookup 'coroutine_traits' in std namespace and std::experimental |
| 10969 | /// namespace. The namespace found is recorded in Namespace. |
| 10970 | ClassTemplateDecl *lookupCoroutineTraits(SourceLocation KwLoc, |
| 10971 | SourceLocation FuncLoc); |
| 10972 | /// Check that the expression co_await promise.final_suspend() shall not be |
| 10973 | /// potentially-throwing. |
| 10974 | bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend); |
| 10975 | |
| 10976 | //===--------------------------------------------------------------------===// |
| 10977 | // OpenMP directives and clauses. |
| 10978 | // |
| 10979 | private: |
| 10980 | void *VarDataSharingAttributesStack; |
| 10981 | |
| 10982 | struct DeclareTargetContextInfo { |
| 10983 | struct MapInfo { |
| 10984 | OMPDeclareTargetDeclAttr::MapTypeTy MT; |
| 10985 | SourceLocation Loc; |
| 10986 | }; |
| 10987 | /// Explicitly listed variables and functions in a 'to' or 'link' clause. |
| 10988 | llvm::DenseMap<NamedDecl *, MapInfo> ExplicitlyMapped; |
| 10989 | |
| 10990 | /// The 'device_type' as parsed from the clause. |
| 10991 | OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any; |
| 10992 | |
| 10993 | /// The directive kind, `begin declare target` or `declare target`. |
| 10994 | OpenMPDirectiveKind Kind; |
| 10995 | |
| 10996 | /// The directive with indirect clause. |
| 10997 | std::optional<Expr *> Indirect; |
| 10998 | |
| 10999 | /// The directive location. |
| 11000 | SourceLocation Loc; |
| 11001 | |
| 11002 | DeclareTargetContextInfo(OpenMPDirectiveKind Kind, SourceLocation Loc) |
| 11003 | : Kind(Kind), Loc(Loc) {} |
| 11004 | }; |
| 11005 | |
| 11006 | /// Number of nested '#pragma omp declare target' directives. |
| 11007 | SmallVector<DeclareTargetContextInfo, 4> DeclareTargetNesting; |
| 11008 | |
| 11009 | /// Initialization of data-sharing attributes stack. |
| 11010 | void InitDataSharingAttributesStack(); |
| 11011 | void DestroyDataSharingAttributesStack(); |
| 11012 | ExprResult |
| 11013 | VerifyPositiveIntegerConstantInClause(Expr *Op, OpenMPClauseKind CKind, |
| 11014 | bool StrictlyPositive = true, |
| 11015 | bool SuppressExprDiags = false); |
| 11016 | /// Returns OpenMP nesting level for current directive. |
| 11017 | unsigned getOpenMPNestingLevel() const; |
| 11018 | |
| 11019 | /// Adjusts the function scopes index for the target-based regions. |
| 11020 | void adjustOpenMPTargetScopeIndex(unsigned &FunctionScopesIndex, |
| 11021 | unsigned Level) const; |
| 11022 | |
| 11023 | /// Returns the number of scopes associated with the construct on the given |
| 11024 | /// OpenMP level. |
| 11025 | int getNumberOfConstructScopes(unsigned Level) const; |
| 11026 | |
| 11027 | /// Push new OpenMP function region for non-capturing function. |
| 11028 | void pushOpenMPFunctionRegion(); |
| 11029 | |
| 11030 | /// Pop OpenMP function region for non-capturing function. |
| 11031 | void popOpenMPFunctionRegion(const sema::FunctionScopeInfo *OldFSI); |
| 11032 | |
| 11033 | /// Analyzes and checks a loop nest for use by a loop transformation. |
| 11034 | /// |
| 11035 | /// \param Kind The loop transformation directive kind. |
| 11036 | /// \param NumLoops How many nested loops the directive is expecting. |
| 11037 | /// \param AStmt Associated statement of the transformation directive. |
| 11038 | /// \param LoopHelpers [out] The loop analysis result. |
| 11039 | /// \param Body [out] The body code nested in \p NumLoops loop. |
| 11040 | /// \param OriginalInits [out] Collection of statements and declarations that |
| 11041 | /// must have been executed/declared before entering the |
| 11042 | /// loop. |
| 11043 | /// |
| 11044 | /// \return Whether there was any error. |
| 11045 | bool checkTransformableLoopNest( |
| 11046 | OpenMPDirectiveKind Kind, Stmt *AStmt, int NumLoops, |
| 11047 | SmallVectorImpl<OMPLoopBasedDirective::HelperExprs> &LoopHelpers, |
| 11048 | Stmt *&Body, |
| 11049 | SmallVectorImpl<SmallVector<llvm::PointerUnion<Stmt *, Decl *>, 0>> |
| 11050 | &OriginalInits); |
| 11051 | |
| 11052 | /// Helper to keep information about the current `omp begin/end declare |
| 11053 | /// variant` nesting. |
| 11054 | struct OMPDeclareVariantScope { |
| 11055 | /// The associated OpenMP context selector. |
| 11056 | OMPTraitInfo *TI; |
| 11057 | |
| 11058 | /// The associated OpenMP context selector mangling. |
| 11059 | std::string NameSuffix; |
| 11060 | |
| 11061 | OMPDeclareVariantScope(OMPTraitInfo &TI); |
| 11062 | }; |
| 11063 | |
| 11064 | /// Return the OMPTraitInfo for the surrounding scope, if any. |
| 11065 | OMPTraitInfo *getOMPTraitInfoForSurroundingScope() { |
| 11066 | return OMPDeclareVariantScopes.empty() ? nullptr |
| 11067 | : OMPDeclareVariantScopes.back().TI; |
| 11068 | } |
| 11069 | |
| 11070 | /// The current `omp begin/end declare variant` scopes. |
| 11071 | SmallVector<OMPDeclareVariantScope, 4> OMPDeclareVariantScopes; |
| 11072 | |
| 11073 | /// The current `omp begin/end assumes` scopes. |
| 11074 | SmallVector<AssumptionAttr *, 4> OMPAssumeScoped; |
| 11075 | |
| 11076 | /// All `omp assumes` we encountered so far. |
| 11077 | SmallVector<AssumptionAttr *, 4> OMPAssumeGlobal; |
| 11078 | |
| 11079 | public: |
| 11080 | /// The declarator \p D defines a function in the scope \p S which is nested |
| 11081 | /// in an `omp begin/end declare variant` scope. In this method we create a |
| 11082 | /// declaration for \p D and rename \p D according to the OpenMP context |
| 11083 | /// selector of the surrounding scope. Return all base functions in \p Bases. |
| 11084 | void ActOnStartOfFunctionDefinitionInOpenMPDeclareVariantScope( |
| 11085 | Scope *S, Declarator &D, MultiTemplateParamsArg TemplateParameterLists, |
| 11086 | SmallVectorImpl<FunctionDecl *> &Bases); |
| 11087 | |
| 11088 | /// Register \p D as specialization of all base functions in \p Bases in the |
| 11089 | /// current `omp begin/end declare variant` scope. |
| 11090 | void ActOnFinishedFunctionDefinitionInOpenMPDeclareVariantScope( |
| 11091 | Decl *D, SmallVectorImpl<FunctionDecl *> &Bases); |
| 11092 | |
| 11093 | /// Act on \p D, a function definition inside of an `omp [begin/end] assumes`. |
| 11094 | void ActOnFinishedFunctionDefinitionInOpenMPAssumeScope(Decl *D); |
| 11095 | |
| 11096 | /// Can we exit an OpenMP declare variant scope at the moment. |
| 11097 | bool isInOpenMPDeclareVariantScope() const { |
| 11098 | return !OMPDeclareVariantScopes.empty(); |
| 11099 | } |
| 11100 | |
| 11101 | /// Given the potential call expression \p Call, determine if there is a |
| 11102 | /// specialization via the OpenMP declare variant mechanism available. If |
| 11103 | /// there is, return the specialized call expression, otherwise return the |
| 11104 | /// original \p Call. |
| 11105 | ExprResult ActOnOpenMPCall(ExprResult Call, Scope *Scope, |
| 11106 | SourceLocation LParenLoc, MultiExprArg ArgExprs, |
| 11107 | SourceLocation RParenLoc, Expr *ExecConfig); |
| 11108 | |
| 11109 | /// Handle a `omp begin declare variant`. |
| 11110 | void ActOnOpenMPBeginDeclareVariant(SourceLocation Loc, OMPTraitInfo &TI); |
| 11111 | |
| 11112 | /// Handle a `omp end declare variant`. |
| 11113 | void ActOnOpenMPEndDeclareVariant(); |
| 11114 | |
| 11115 | /// Checks if the variant/multiversion functions are compatible. |
| 11116 | bool areMultiversionVariantFunctionsCompatible( |
| 11117 | const FunctionDecl *OldFD, const FunctionDecl *NewFD, |
| 11118 | const PartialDiagnostic &NoProtoDiagID, |
| 11119 | const PartialDiagnosticAt &NoteCausedDiagIDAt, |
| 11120 | const PartialDiagnosticAt &NoSupportDiagIDAt, |
| 11121 | const PartialDiagnosticAt &DiffDiagIDAt, bool TemplatesSupported, |
| 11122 | bool ConstexprSupported, bool CLinkageMayDiffer); |
| 11123 | |
| 11124 | /// Function tries to capture lambda's captured variables in the OpenMP region |
| 11125 | /// before the original lambda is captured. |
| 11126 | void tryCaptureOpenMPLambdas(ValueDecl *V); |
| 11127 | |
| 11128 | /// Return true if the provided declaration \a VD should be captured by |
| 11129 | /// reference. |
| 11130 | /// \param Level Relative level of nested OpenMP construct for that the check |
| 11131 | /// is performed. |
| 11132 | /// \param OpenMPCaptureLevel Capture level within an OpenMP construct. |
| 11133 | bool isOpenMPCapturedByRef(const ValueDecl *D, unsigned Level, |
| 11134 | unsigned OpenMPCaptureLevel) const; |
| 11135 | |
| 11136 | /// Check if the specified variable is used in one of the private |
| 11137 | /// clauses (private, firstprivate, lastprivate, reduction etc.) in OpenMP |
| 11138 | /// constructs. |
| 11139 | VarDecl *isOpenMPCapturedDecl(ValueDecl *D, bool CheckScopeInfo = false, |
| 11140 | unsigned StopAt = 0); |
| 11141 | |
| 11142 | /// The member expression(this->fd) needs to be rebuilt in the template |
| 11143 | /// instantiation to generate private copy for OpenMP when default |
| 11144 | /// clause is used. The function will return true if default |
| 11145 | /// cluse is used. |
| 11146 | bool isOpenMPRebuildMemberExpr(ValueDecl *D); |
| 11147 | |
| 11148 | ExprResult getOpenMPCapturedExpr(VarDecl *Capture, ExprValueKind VK, |
| 11149 | ExprObjectKind OK, SourceLocation Loc); |
| 11150 | |
| 11151 | /// If the current region is a loop-based region, mark the start of the loop |
| 11152 | /// construct. |
| 11153 | void startOpenMPLoop(); |
| 11154 | |
| 11155 | /// If the current region is a range loop-based region, mark the start of the |
| 11156 | /// loop construct. |
| 11157 | void startOpenMPCXXRangeFor(); |
| 11158 | |
| 11159 | /// Check if the specified variable is used in 'private' clause. |
| 11160 | /// \param Level Relative level of nested OpenMP construct for that the check |
| 11161 | /// is performed. |
| 11162 | OpenMPClauseKind isOpenMPPrivateDecl(ValueDecl *D, unsigned Level, |
| 11163 | unsigned CapLevel) const; |
| 11164 | |
| 11165 | /// Sets OpenMP capture kind (OMPC_private, OMPC_firstprivate, OMPC_map etc.) |
| 11166 | /// for \p FD based on DSA for the provided corresponding captured declaration |
| 11167 | /// \p D. |
| 11168 | void setOpenMPCaptureKind(FieldDecl *FD, const ValueDecl *D, unsigned Level); |
| 11169 | |
| 11170 | /// Check if the specified variable is captured by 'target' directive. |
| 11171 | /// \param Level Relative level of nested OpenMP construct for that the check |
| 11172 | /// is performed. |
| 11173 | bool isOpenMPTargetCapturedDecl(const ValueDecl *D, unsigned Level, |
| 11174 | unsigned CaptureLevel) const; |
| 11175 | |
| 11176 | /// Check if the specified global variable must be captured by outer capture |
| 11177 | /// regions. |
| 11178 | /// \param Level Relative level of nested OpenMP construct for that |
| 11179 | /// the check is performed. |
| 11180 | bool isOpenMPGlobalCapturedDecl(ValueDecl *D, unsigned Level, |
| 11181 | unsigned CaptureLevel) const; |
| 11182 | |
| 11183 | ExprResult PerformOpenMPImplicitIntegerConversion(SourceLocation OpLoc, |
| 11184 | Expr *Op); |
| 11185 | /// Called on start of new data sharing attribute block. |
| 11186 | void StartOpenMPDSABlock(OpenMPDirectiveKind K, |
| 11187 | const DeclarationNameInfo &DirName, Scope *CurScope, |
| 11188 | SourceLocation Loc); |
| 11189 | /// Start analysis of clauses. |
| 11190 | void StartOpenMPClause(OpenMPClauseKind K); |
| 11191 | /// End analysis of clauses. |
| 11192 | void EndOpenMPClause(); |
| 11193 | /// Called on end of data sharing attribute block. |
| 11194 | void EndOpenMPDSABlock(Stmt *CurDirective); |
| 11195 | |
| 11196 | /// Check if the current region is an OpenMP loop region and if it is, |
| 11197 | /// mark loop control variable, used in \p Init for loop initialization, as |
| 11198 | /// private by default. |
| 11199 | /// \param Init First part of the for loop. |
| 11200 | void ActOnOpenMPLoopInitialization(SourceLocation ForLoc, Stmt *Init); |
| 11201 | |
| 11202 | /// Called on well-formed '\#pragma omp metadirective' after parsing |
| 11203 | /// of the associated statement. |
| 11204 | StmtResult ActOnOpenMPMetaDirective(ArrayRef<OMPClause *> Clauses, |
| 11205 | Stmt *AStmt, SourceLocation StartLoc, |
| 11206 | SourceLocation EndLoc); |
| 11207 | |
| 11208 | // OpenMP directives and clauses. |
| 11209 | /// Called on correct id-expression from the '#pragma omp |
| 11210 | /// threadprivate'. |
| 11211 | ExprResult ActOnOpenMPIdExpression(Scope *CurScope, CXXScopeSpec &ScopeSpec, |
| 11212 | const DeclarationNameInfo &Id, |
| 11213 | OpenMPDirectiveKind Kind); |
| 11214 | /// Called on well-formed '#pragma omp threadprivate'. |
| 11215 | DeclGroupPtrTy ActOnOpenMPThreadprivateDirective( |
| 11216 | SourceLocation Loc, |
| 11217 | ArrayRef<Expr *> VarList); |
| 11218 | /// Builds a new OpenMPThreadPrivateDecl and checks its correctness. |
| 11219 | OMPThreadPrivateDecl *CheckOMPThreadPrivateDecl(SourceLocation Loc, |
| 11220 | ArrayRef<Expr *> VarList); |
| 11221 | /// Called on well-formed '#pragma omp allocate'. |
| 11222 | DeclGroupPtrTy ActOnOpenMPAllocateDirective(SourceLocation Loc, |
| 11223 | ArrayRef<Expr *> VarList, |
| 11224 | ArrayRef<OMPClause *> Clauses, |
| 11225 | DeclContext *Owner = nullptr); |
| 11226 | |
| 11227 | /// Called on well-formed '#pragma omp [begin] assume[s]'. |
| 11228 | void ActOnOpenMPAssumesDirective(SourceLocation Loc, |
| 11229 | OpenMPDirectiveKind DKind, |
| 11230 | ArrayRef<std::string> Assumptions, |
| 11231 | bool SkippedClauses); |
| 11232 | |
| 11233 | /// Check if there is an active global `omp begin assumes` directive. |
| 11234 | bool isInOpenMPAssumeScope() const { return !OMPAssumeScoped.empty(); } |
| 11235 | |
| 11236 | /// Check if there is an active global `omp assumes` directive. |
| 11237 | bool hasGlobalOpenMPAssumes() const { return !OMPAssumeGlobal.empty(); } |
| 11238 | |
| 11239 | /// Called on well-formed '#pragma omp end assumes'. |
| 11240 | void ActOnOpenMPEndAssumesDirective(); |
| 11241 | |
| 11242 | /// Called on well-formed '#pragma omp requires'. |
| 11243 | DeclGroupPtrTy ActOnOpenMPRequiresDirective(SourceLocation Loc, |
| 11244 | ArrayRef<OMPClause *> ClauseList); |
| 11245 | /// Check restrictions on Requires directive |
| 11246 | OMPRequiresDecl *CheckOMPRequiresDecl(SourceLocation Loc, |
| 11247 | ArrayRef<OMPClause *> Clauses); |
| 11248 | /// Check if the specified type is allowed to be used in 'omp declare |
| 11249 | /// reduction' construct. |
| 11250 | QualType ActOnOpenMPDeclareReductionType(SourceLocation TyLoc, |
| 11251 | TypeResult ParsedType); |
| 11252 | /// Called on start of '#pragma omp declare reduction'. |
| 11253 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveStart( |
| 11254 | Scope *S, DeclContext *DC, DeclarationName Name, |
| 11255 | ArrayRef<std::pair<QualType, SourceLocation>> ReductionTypes, |
| 11256 | AccessSpecifier AS, Decl *PrevDeclInScope = nullptr); |
| 11257 | /// Initialize declare reduction construct initializer. |
| 11258 | void ActOnOpenMPDeclareReductionCombinerStart(Scope *S, Decl *D); |
| 11259 | /// Finish current declare reduction construct initializer. |
| 11260 | void ActOnOpenMPDeclareReductionCombinerEnd(Decl *D, Expr *Combiner); |
| 11261 | /// Initialize declare reduction construct initializer. |
| 11262 | /// \return omp_priv variable. |
| 11263 | VarDecl *ActOnOpenMPDeclareReductionInitializerStart(Scope *S, Decl *D); |
| 11264 | /// Finish current declare reduction construct initializer. |
| 11265 | void ActOnOpenMPDeclareReductionInitializerEnd(Decl *D, Expr *Initializer, |
| 11266 | VarDecl *OmpPrivParm); |
| 11267 | /// Called at the end of '#pragma omp declare reduction'. |
| 11268 | DeclGroupPtrTy ActOnOpenMPDeclareReductionDirectiveEnd( |
| 11269 | Scope *S, DeclGroupPtrTy DeclReductions, bool IsValid); |
| 11270 | |
| 11271 | /// Check variable declaration in 'omp declare mapper' construct. |
| 11272 | TypeResult ActOnOpenMPDeclareMapperVarDecl(Scope *S, Declarator &D); |
| 11273 | /// Check if the specified type is allowed to be used in 'omp declare |
| 11274 | /// mapper' construct. |
| 11275 | QualType ActOnOpenMPDeclareMapperType(SourceLocation TyLoc, |
| 11276 | TypeResult ParsedType); |
| 11277 | /// Called on start of '#pragma omp declare mapper'. |
| 11278 | DeclGroupPtrTy ActOnOpenMPDeclareMapperDirective( |
| 11279 | Scope *S, DeclContext *DC, DeclarationName Name, QualType MapperType, |
| 11280 | SourceLocation StartLoc, DeclarationName VN, AccessSpecifier AS, |
| 11281 | Expr *MapperVarRef, ArrayRef<OMPClause *> Clauses, |
| 11282 | Decl *PrevDeclInScope = nullptr); |
| 11283 | /// Build the mapper variable of '#pragma omp declare mapper'. |
| 11284 | ExprResult ActOnOpenMPDeclareMapperDirectiveVarDecl(Scope *S, |
| 11285 | QualType MapperType, |
| 11286 | SourceLocation StartLoc, |
| 11287 | DeclarationName VN); |
| 11288 | void ActOnOpenMPIteratorVarDecl(VarDecl *VD); |
| 11289 | bool isOpenMPDeclareMapperVarDeclAllowed(const VarDecl *VD) const; |
| 11290 | const ValueDecl *getOpenMPDeclareMapperVarName() const; |
| 11291 | |
| 11292 | /// Called on the start of target region i.e. '#pragma omp declare target'. |
| 11293 | bool ActOnStartOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
| 11294 | |
| 11295 | /// Called at the end of target region i.e. '#pragma omp end declare target'. |
| 11296 | const DeclareTargetContextInfo ActOnOpenMPEndDeclareTargetDirective(); |
| 11297 | |
| 11298 | /// Called once a target context is completed, that can be when a |
| 11299 | /// '#pragma omp end declare target' was encountered or when a |
| 11300 | /// '#pragma omp declare target' without declaration-definition-seq was |
| 11301 | /// encountered. |
| 11302 | void ActOnFinishedOpenMPDeclareTargetContext(DeclareTargetContextInfo &DTCI); |
| 11303 | |
| 11304 | /// Report unterminated 'omp declare target' or 'omp begin declare target' at |
| 11305 | /// the end of a compilation unit. |
| 11306 | void DiagnoseUnterminatedOpenMPDeclareTarget(); |
| 11307 | |
| 11308 | /// Searches for the provided declaration name for OpenMP declare target |
| 11309 | /// directive. |
| 11310 | NamedDecl *lookupOpenMPDeclareTargetName(Scope *CurScope, |
| 11311 | CXXScopeSpec &ScopeSpec, |
| 11312 | const DeclarationNameInfo &Id); |
| 11313 | |
| 11314 | /// Called on correct id-expression from the '#pragma omp declare target'. |
| 11315 | void ActOnOpenMPDeclareTargetName(NamedDecl *ND, SourceLocation Loc, |
| 11316 | OMPDeclareTargetDeclAttr::MapTypeTy MT, |
| 11317 | DeclareTargetContextInfo &DTCI); |
| 11318 | |
| 11319 | /// Check declaration inside target region. |
| 11320 | void |
| 11321 | checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, |
| 11322 | SourceLocation IdLoc = SourceLocation()); |
| 11323 | /// Finishes analysis of the deferred functions calls that may be declared as |
| 11324 | /// host/nohost during device/host compilation. |
| 11325 | void finalizeOpenMPDelayedAnalysis(const FunctionDecl *Caller, |
| 11326 | const FunctionDecl *Callee, |
| 11327 | SourceLocation Loc); |
| 11328 | |
| 11329 | /// Return true if currently in OpenMP task with untied clause context. |
| 11330 | bool isInOpenMPTaskUntiedContext() const; |
| 11331 | |
| 11332 | /// Return true inside OpenMP declare target region. |
| 11333 | bool isInOpenMPDeclareTargetContext() const { |
| 11334 | return !DeclareTargetNesting.empty(); |
| 11335 | } |
| 11336 | /// Return true inside OpenMP target region. |
| 11337 | bool isInOpenMPTargetExecutionDirective() const; |
| 11338 | |
| 11339 | /// Return the number of captured regions created for an OpenMP directive. |
| 11340 | static int getOpenMPCaptureLevels(OpenMPDirectiveKind Kind); |
| 11341 | |
| 11342 | /// Initialization of captured region for OpenMP region. |
| 11343 | void ActOnOpenMPRegionStart(OpenMPDirectiveKind DKind, Scope *CurScope); |
| 11344 | |
| 11345 | /// Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to |
| 11346 | /// an OpenMP loop directive. |
| 11347 | StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt); |
| 11348 | |
| 11349 | /// Process a canonical OpenMP loop nest that can either be a canonical |
| 11350 | /// literal loop (ForStmt or CXXForRangeStmt), or the generated loop of an |
| 11351 | /// OpenMP loop transformation construct. |
| 11352 | StmtResult ActOnOpenMPLoopnest(Stmt *AStmt); |
| 11353 | |
| 11354 | /// End of OpenMP region. |
| 11355 | /// |
| 11356 | /// \param S Statement associated with the current OpenMP region. |
| 11357 | /// \param Clauses List of clauses for the current OpenMP region. |
| 11358 | /// |
| 11359 | /// \returns Statement for finished OpenMP region. |
| 11360 | StmtResult ActOnOpenMPRegionEnd(StmtResult S, ArrayRef<OMPClause *> Clauses); |
| 11361 | StmtResult ActOnOpenMPExecutableDirective( |
| 11362 | OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, |
| 11363 | OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses, |
| 11364 | Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc); |
| 11365 | /// Called on well-formed '\#pragma omp parallel' after parsing |
| 11366 | /// of the associated statement. |
| 11367 | StmtResult ActOnOpenMPParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 11368 | Stmt *AStmt, |
| 11369 | SourceLocation StartLoc, |
| 11370 | SourceLocation EndLoc); |
| 11371 | using VarsWithInheritedDSAType = |
| 11372 | llvm::SmallDenseMap<const ValueDecl *, const Expr *, 4>; |
| 11373 | /// Called on well-formed '\#pragma omp simd' after parsing |
| 11374 | /// of the associated statement. |
| 11375 | StmtResult |
| 11376 | ActOnOpenMPSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 11377 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 11378 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11379 | /// Called on well-formed '#pragma omp tile' after parsing of its clauses and |
| 11380 | /// the associated statement. |
| 11381 | StmtResult ActOnOpenMPTileDirective(ArrayRef<OMPClause *> Clauses, |
| 11382 | Stmt *AStmt, SourceLocation StartLoc, |
| 11383 | SourceLocation EndLoc); |
| 11384 | /// Called on well-formed '#pragma omp unroll' after parsing of its clauses |
| 11385 | /// and the associated statement. |
| 11386 | StmtResult ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses, |
| 11387 | Stmt *AStmt, SourceLocation StartLoc, |
| 11388 | SourceLocation EndLoc); |
| 11389 | /// Called on well-formed '\#pragma omp for' after parsing |
| 11390 | /// of the associated statement. |
| 11391 | StmtResult |
| 11392 | ActOnOpenMPForDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 11393 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 11394 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11395 | /// Called on well-formed '\#pragma omp for simd' after parsing |
| 11396 | /// of the associated statement. |
| 11397 | StmtResult |
| 11398 | ActOnOpenMPForSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 11399 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 11400 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11401 | /// Called on well-formed '\#pragma omp sections' after parsing |
| 11402 | /// of the associated statement. |
| 11403 | StmtResult ActOnOpenMPSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 11404 | Stmt *AStmt, SourceLocation StartLoc, |
| 11405 | SourceLocation EndLoc); |
| 11406 | /// Called on well-formed '\#pragma omp section' after parsing of the |
| 11407 | /// associated statement. |
| 11408 | StmtResult ActOnOpenMPSectionDirective(Stmt *AStmt, SourceLocation StartLoc, |
| 11409 | SourceLocation EndLoc); |
| 11410 | /// Called on well-formed '\#pragma omp single' after parsing of the |
| 11411 | /// associated statement. |
| 11412 | StmtResult ActOnOpenMPSingleDirective(ArrayRef<OMPClause *> Clauses, |
| 11413 | Stmt *AStmt, SourceLocation StartLoc, |
| 11414 | SourceLocation EndLoc); |
| 11415 | /// Called on well-formed '\#pragma omp master' after parsing of the |
| 11416 | /// associated statement. |
| 11417 | StmtResult ActOnOpenMPMasterDirective(Stmt *AStmt, SourceLocation StartLoc, |
| 11418 | SourceLocation EndLoc); |
| 11419 | /// Called on well-formed '\#pragma omp critical' after parsing of the |
| 11420 | /// associated statement. |
| 11421 | StmtResult ActOnOpenMPCriticalDirective(const DeclarationNameInfo &DirName, |
| 11422 | ArrayRef<OMPClause *> Clauses, |
| 11423 | Stmt *AStmt, SourceLocation StartLoc, |
| 11424 | SourceLocation EndLoc); |
| 11425 | /// Called on well-formed '\#pragma omp parallel for' after parsing |
| 11426 | /// of the associated statement. |
| 11427 | StmtResult ActOnOpenMPParallelForDirective( |
| 11428 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11429 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11430 | /// Called on well-formed '\#pragma omp parallel for simd' after |
| 11431 | /// parsing of the associated statement. |
| 11432 | StmtResult ActOnOpenMPParallelForSimdDirective( |
| 11433 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11434 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11435 | /// Called on well-formed '\#pragma omp parallel master' after |
| 11436 | /// parsing of the associated statement. |
| 11437 | StmtResult ActOnOpenMPParallelMasterDirective(ArrayRef<OMPClause *> Clauses, |
| 11438 | Stmt *AStmt, |
| 11439 | SourceLocation StartLoc, |
| 11440 | SourceLocation EndLoc); |
| 11441 | /// Called on well-formed '\#pragma omp parallel masked' after |
| 11442 | /// parsing of the associated statement. |
| 11443 | StmtResult ActOnOpenMPParallelMaskedDirective(ArrayRef<OMPClause *> Clauses, |
| 11444 | Stmt *AStmt, |
| 11445 | SourceLocation StartLoc, |
| 11446 | SourceLocation EndLoc); |
| 11447 | /// Called on well-formed '\#pragma omp parallel sections' after |
| 11448 | /// parsing of the associated statement. |
| 11449 | StmtResult ActOnOpenMPParallelSectionsDirective(ArrayRef<OMPClause *> Clauses, |
| 11450 | Stmt *AStmt, |
| 11451 | SourceLocation StartLoc, |
| 11452 | SourceLocation EndLoc); |
| 11453 | /// Called on well-formed '\#pragma omp task' after parsing of the |
| 11454 | /// associated statement. |
| 11455 | StmtResult ActOnOpenMPTaskDirective(ArrayRef<OMPClause *> Clauses, |
| 11456 | Stmt *AStmt, SourceLocation StartLoc, |
| 11457 | SourceLocation EndLoc); |
| 11458 | /// Called on well-formed '\#pragma omp taskyield'. |
| 11459 | StmtResult ActOnOpenMPTaskyieldDirective(SourceLocation StartLoc, |
| 11460 | SourceLocation EndLoc); |
| 11461 | /// Called on well-formed '\#pragma omp error'. |
| 11462 | /// Error direcitive is allowed in both declared and excutable contexts. |
| 11463 | /// Adding InExContext to identify which context is called from. |
| 11464 | StmtResult ActOnOpenMPErrorDirective(ArrayRef<OMPClause *> Clauses, |
| 11465 | SourceLocation StartLoc, |
| 11466 | SourceLocation EndLoc, |
| 11467 | bool InExContext = true); |
| 11468 | /// Called on well-formed '\#pragma omp barrier'. |
| 11469 | StmtResult ActOnOpenMPBarrierDirective(SourceLocation StartLoc, |
| 11470 | SourceLocation EndLoc); |
| 11471 | /// Called on well-formed '\#pragma omp taskwait'. |
| 11472 | StmtResult ActOnOpenMPTaskwaitDirective(ArrayRef<OMPClause *> Clauses, |
| 11473 | SourceLocation StartLoc, |
| 11474 | SourceLocation EndLoc); |
| 11475 | /// Called on well-formed '\#pragma omp taskgroup'. |
| 11476 | StmtResult ActOnOpenMPTaskgroupDirective(ArrayRef<OMPClause *> Clauses, |
| 11477 | Stmt *AStmt, SourceLocation StartLoc, |
| 11478 | SourceLocation EndLoc); |
| 11479 | /// Called on well-formed '\#pragma omp flush'. |
| 11480 | StmtResult ActOnOpenMPFlushDirective(ArrayRef<OMPClause *> Clauses, |
| 11481 | SourceLocation StartLoc, |
| 11482 | SourceLocation EndLoc); |
| 11483 | /// Called on well-formed '\#pragma omp depobj'. |
| 11484 | StmtResult ActOnOpenMPDepobjDirective(ArrayRef<OMPClause *> Clauses, |
| 11485 | SourceLocation StartLoc, |
| 11486 | SourceLocation EndLoc); |
| 11487 | /// Called on well-formed '\#pragma omp scan'. |
| 11488 | StmtResult ActOnOpenMPScanDirective(ArrayRef<OMPClause *> Clauses, |
| 11489 | SourceLocation StartLoc, |
| 11490 | SourceLocation EndLoc); |
| 11491 | /// Called on well-formed '\#pragma omp ordered' after parsing of the |
| 11492 | /// associated statement. |
| 11493 | StmtResult ActOnOpenMPOrderedDirective(ArrayRef<OMPClause *> Clauses, |
| 11494 | Stmt *AStmt, SourceLocation StartLoc, |
| 11495 | SourceLocation EndLoc); |
| 11496 | /// Called on well-formed '\#pragma omp atomic' after parsing of the |
| 11497 | /// associated statement. |
| 11498 | StmtResult ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses, |
| 11499 | Stmt *AStmt, SourceLocation StartLoc, |
| 11500 | SourceLocation EndLoc); |
| 11501 | /// Called on well-formed '\#pragma omp target' after parsing of the |
| 11502 | /// associated statement. |
| 11503 | StmtResult ActOnOpenMPTargetDirective(ArrayRef<OMPClause *> Clauses, |
| 11504 | Stmt *AStmt, SourceLocation StartLoc, |
| 11505 | SourceLocation EndLoc); |
| 11506 | /// Called on well-formed '\#pragma omp target data' after parsing of |
| 11507 | /// the associated statement. |
| 11508 | StmtResult ActOnOpenMPTargetDataDirective(ArrayRef<OMPClause *> Clauses, |
| 11509 | Stmt *AStmt, SourceLocation StartLoc, |
| 11510 | SourceLocation EndLoc); |
| 11511 | /// Called on well-formed '\#pragma omp target enter data' after |
| 11512 | /// parsing of the associated statement. |
| 11513 | StmtResult ActOnOpenMPTargetEnterDataDirective(ArrayRef<OMPClause *> Clauses, |
| 11514 | SourceLocation StartLoc, |
| 11515 | SourceLocation EndLoc, |
| 11516 | Stmt *AStmt); |
| 11517 | /// Called on well-formed '\#pragma omp target exit data' after |
| 11518 | /// parsing of the associated statement. |
| 11519 | StmtResult ActOnOpenMPTargetExitDataDirective(ArrayRef<OMPClause *> Clauses, |
| 11520 | SourceLocation StartLoc, |
| 11521 | SourceLocation EndLoc, |
| 11522 | Stmt *AStmt); |
| 11523 | /// Called on well-formed '\#pragma omp target parallel' after |
| 11524 | /// parsing of the associated statement. |
| 11525 | StmtResult ActOnOpenMPTargetParallelDirective(ArrayRef<OMPClause *> Clauses, |
| 11526 | Stmt *AStmt, |
| 11527 | SourceLocation StartLoc, |
| 11528 | SourceLocation EndLoc); |
| 11529 | /// Called on well-formed '\#pragma omp target parallel for' after |
| 11530 | /// parsing of the associated statement. |
| 11531 | StmtResult ActOnOpenMPTargetParallelForDirective( |
| 11532 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11533 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11534 | /// Called on well-formed '\#pragma omp teams' after parsing of the |
| 11535 | /// associated statement. |
| 11536 | StmtResult ActOnOpenMPTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 11537 | Stmt *AStmt, SourceLocation StartLoc, |
| 11538 | SourceLocation EndLoc); |
| 11539 | /// Called on well-formed '\#pragma omp teams loop' after parsing of the |
| 11540 | /// associated statement. |
| 11541 | StmtResult ActOnOpenMPTeamsGenericLoopDirective( |
| 11542 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11543 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11544 | /// Called on well-formed '\#pragma omp target teams loop' after parsing of |
| 11545 | /// the associated statement. |
| 11546 | StmtResult ActOnOpenMPTargetTeamsGenericLoopDirective( |
| 11547 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11548 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11549 | /// Called on well-formed '\#pragma omp parallel loop' after parsing of the |
| 11550 | /// associated statement. |
| 11551 | StmtResult ActOnOpenMPParallelGenericLoopDirective( |
| 11552 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11553 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11554 | /// Called on well-formed '\#pragma omp target parallel loop' after parsing |
| 11555 | /// of the associated statement. |
| 11556 | StmtResult ActOnOpenMPTargetParallelGenericLoopDirective( |
| 11557 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11558 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11559 | /// Called on well-formed '\#pragma omp cancellation point'. |
| 11560 | StmtResult |
| 11561 | ActOnOpenMPCancellationPointDirective(SourceLocation StartLoc, |
| 11562 | SourceLocation EndLoc, |
| 11563 | OpenMPDirectiveKind CancelRegion); |
| 11564 | /// Called on well-formed '\#pragma omp cancel'. |
| 11565 | StmtResult ActOnOpenMPCancelDirective(ArrayRef<OMPClause *> Clauses, |
| 11566 | SourceLocation StartLoc, |
| 11567 | SourceLocation EndLoc, |
| 11568 | OpenMPDirectiveKind CancelRegion); |
| 11569 | /// Called on well-formed '\#pragma omp taskloop' after parsing of the |
| 11570 | /// associated statement. |
| 11571 | StmtResult |
| 11572 | ActOnOpenMPTaskLoopDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 11573 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 11574 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11575 | /// Called on well-formed '\#pragma omp taskloop simd' after parsing of |
| 11576 | /// the associated statement. |
| 11577 | StmtResult ActOnOpenMPTaskLoopSimdDirective( |
| 11578 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11579 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11580 | /// Called on well-formed '\#pragma omp master taskloop' after parsing of the |
| 11581 | /// associated statement. |
| 11582 | StmtResult ActOnOpenMPMasterTaskLoopDirective( |
| 11583 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11584 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11585 | /// Called on well-formed '\#pragma omp master taskloop simd' after parsing of |
| 11586 | /// the associated statement. |
| 11587 | StmtResult ActOnOpenMPMasterTaskLoopSimdDirective( |
| 11588 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11589 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11590 | /// Called on well-formed '\#pragma omp parallel master taskloop' after |
| 11591 | /// parsing of the associated statement. |
| 11592 | StmtResult ActOnOpenMPParallelMasterTaskLoopDirective( |
| 11593 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11594 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11595 | /// Called on well-formed '\#pragma omp parallel master taskloop simd' after |
| 11596 | /// parsing of the associated statement. |
| 11597 | StmtResult ActOnOpenMPParallelMasterTaskLoopSimdDirective( |
| 11598 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11599 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11600 | /// Called on well-formed '\#pragma omp masked taskloop' after parsing of the |
| 11601 | /// associated statement. |
| 11602 | StmtResult ActOnOpenMPMaskedTaskLoopDirective( |
| 11603 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11604 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11605 | /// Called on well-formed '\#pragma omp masked taskloop simd' after parsing of |
| 11606 | /// the associated statement. |
| 11607 | StmtResult ActOnOpenMPMaskedTaskLoopSimdDirective( |
| 11608 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11609 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11610 | /// Called on well-formed '\#pragma omp parallel masked taskloop' after |
| 11611 | /// parsing of the associated statement. |
| 11612 | StmtResult ActOnOpenMPParallelMaskedTaskLoopDirective( |
| 11613 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11614 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11615 | /// Called on well-formed '\#pragma omp parallel masked taskloop simd' after |
| 11616 | /// parsing of the associated statement. |
| 11617 | StmtResult ActOnOpenMPParallelMaskedTaskLoopSimdDirective( |
| 11618 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11619 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11620 | /// Called on well-formed '\#pragma omp distribute' after parsing |
| 11621 | /// of the associated statement. |
| 11622 | StmtResult |
| 11623 | ActOnOpenMPDistributeDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 11624 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 11625 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11626 | /// Called on well-formed '\#pragma omp target update'. |
| 11627 | StmtResult ActOnOpenMPTargetUpdateDirective(ArrayRef<OMPClause *> Clauses, |
| 11628 | SourceLocation StartLoc, |
| 11629 | SourceLocation EndLoc, |
| 11630 | Stmt *AStmt); |
| 11631 | /// Called on well-formed '\#pragma omp distribute parallel for' after |
| 11632 | /// parsing of the associated statement. |
| 11633 | StmtResult ActOnOpenMPDistributeParallelForDirective( |
| 11634 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11635 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11636 | /// Called on well-formed '\#pragma omp distribute parallel for simd' |
| 11637 | /// after parsing of the associated statement. |
| 11638 | StmtResult ActOnOpenMPDistributeParallelForSimdDirective( |
| 11639 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11640 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11641 | /// Called on well-formed '\#pragma omp distribute simd' after |
| 11642 | /// parsing of the associated statement. |
| 11643 | StmtResult ActOnOpenMPDistributeSimdDirective( |
| 11644 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11645 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11646 | /// Called on well-formed '\#pragma omp target parallel for simd' after |
| 11647 | /// parsing of the associated statement. |
| 11648 | StmtResult ActOnOpenMPTargetParallelForSimdDirective( |
| 11649 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11650 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11651 | /// Called on well-formed '\#pragma omp target simd' after parsing of |
| 11652 | /// the associated statement. |
| 11653 | StmtResult |
| 11654 | ActOnOpenMPTargetSimdDirective(ArrayRef<OMPClause *> Clauses, Stmt *AStmt, |
| 11655 | SourceLocation StartLoc, SourceLocation EndLoc, |
| 11656 | VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11657 | /// Called on well-formed '\#pragma omp teams distribute' after parsing of |
| 11658 | /// the associated statement. |
| 11659 | StmtResult ActOnOpenMPTeamsDistributeDirective( |
| 11660 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11661 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11662 | /// Called on well-formed '\#pragma omp teams distribute simd' after parsing |
| 11663 | /// of the associated statement. |
| 11664 | StmtResult ActOnOpenMPTeamsDistributeSimdDirective( |
| 11665 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11666 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11667 | /// Called on well-formed '\#pragma omp teams distribute parallel for simd' |
| 11668 | /// after parsing of the associated statement. |
| 11669 | StmtResult ActOnOpenMPTeamsDistributeParallelForSimdDirective( |
| 11670 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11671 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11672 | /// Called on well-formed '\#pragma omp teams distribute parallel for' |
| 11673 | /// after parsing of the associated statement. |
| 11674 | StmtResult ActOnOpenMPTeamsDistributeParallelForDirective( |
| 11675 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11676 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11677 | /// Called on well-formed '\#pragma omp target teams' after parsing of the |
| 11678 | /// associated statement. |
| 11679 | StmtResult ActOnOpenMPTargetTeamsDirective(ArrayRef<OMPClause *> Clauses, |
| 11680 | Stmt *AStmt, |
| 11681 | SourceLocation StartLoc, |
| 11682 | SourceLocation EndLoc); |
| 11683 | /// Called on well-formed '\#pragma omp target teams distribute' after parsing |
| 11684 | /// of the associated statement. |
| 11685 | StmtResult ActOnOpenMPTargetTeamsDistributeDirective( |
| 11686 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11687 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11688 | /// Called on well-formed '\#pragma omp target teams distribute parallel for' |
| 11689 | /// after parsing of the associated statement. |
| 11690 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForDirective( |
| 11691 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11692 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11693 | /// Called on well-formed '\#pragma omp target teams distribute parallel for |
| 11694 | /// simd' after parsing of the associated statement. |
| 11695 | StmtResult ActOnOpenMPTargetTeamsDistributeParallelForSimdDirective( |
| 11696 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11697 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11698 | /// Called on well-formed '\#pragma omp target teams distribute simd' after |
| 11699 | /// parsing of the associated statement. |
| 11700 | StmtResult ActOnOpenMPTargetTeamsDistributeSimdDirective( |
| 11701 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11702 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11703 | /// Called on well-formed '\#pragma omp interop'. |
| 11704 | StmtResult ActOnOpenMPInteropDirective(ArrayRef<OMPClause *> Clauses, |
| 11705 | SourceLocation StartLoc, |
| 11706 | SourceLocation EndLoc); |
| 11707 | /// Called on well-formed '\#pragma omp dispatch' after parsing of the |
| 11708 | // /associated statement. |
| 11709 | StmtResult ActOnOpenMPDispatchDirective(ArrayRef<OMPClause *> Clauses, |
| 11710 | Stmt *AStmt, SourceLocation StartLoc, |
| 11711 | SourceLocation EndLoc); |
| 11712 | /// Called on well-formed '\#pragma omp masked' after parsing of the |
| 11713 | // /associated statement. |
| 11714 | StmtResult ActOnOpenMPMaskedDirective(ArrayRef<OMPClause *> Clauses, |
| 11715 | Stmt *AStmt, SourceLocation StartLoc, |
| 11716 | SourceLocation EndLoc); |
| 11717 | |
| 11718 | /// Called on well-formed '\#pragma omp loop' after parsing of the |
| 11719 | /// associated statement. |
| 11720 | StmtResult ActOnOpenMPGenericLoopDirective( |
| 11721 | ArrayRef<OMPClause *> Clauses, Stmt *AStmt, SourceLocation StartLoc, |
| 11722 | SourceLocation EndLoc, VarsWithInheritedDSAType &VarsWithImplicitDSA); |
| 11723 | |
| 11724 | /// Checks correctness of linear modifiers. |
| 11725 | bool CheckOpenMPLinearModifier(OpenMPLinearClauseKind LinKind, |
| 11726 | SourceLocation LinLoc); |
| 11727 | /// Checks that the specified declaration matches requirements for the linear |
| 11728 | /// decls. |
| 11729 | bool CheckOpenMPLinearDecl(const ValueDecl *D, SourceLocation ELoc, |
| 11730 | OpenMPLinearClauseKind LinKind, QualType Type, |
| 11731 | bool IsDeclareSimd = false); |
| 11732 | |
| 11733 | /// Called on well-formed '\#pragma omp declare simd' after parsing of |
| 11734 | /// the associated method/function. |
| 11735 | DeclGroupPtrTy ActOnOpenMPDeclareSimdDirective( |
| 11736 | DeclGroupPtrTy DG, OMPDeclareSimdDeclAttr::BranchStateTy BS, |
| 11737 | Expr *Simdlen, ArrayRef<Expr *> Uniforms, ArrayRef<Expr *> Aligneds, |
| 11738 | ArrayRef<Expr *> Alignments, ArrayRef<Expr *> Linears, |
| 11739 | ArrayRef<unsigned> LinModifiers, ArrayRef<Expr *> Steps, SourceRange SR); |
| 11740 | |
| 11741 | /// Checks '\#pragma omp declare variant' variant function and original |
| 11742 | /// functions after parsing of the associated method/function. |
| 11743 | /// \param DG Function declaration to which declare variant directive is |
| 11744 | /// applied to. |
| 11745 | /// \param VariantRef Expression that references the variant function, which |
| 11746 | /// must be used instead of the original one, specified in \p DG. |
| 11747 | /// \param TI The trait info object representing the match clause. |
| 11748 | /// \param NumAppendArgs The number of omp_interop_t arguments to account for |
| 11749 | /// in checking. |
| 11750 | /// \returns std::nullopt, if the function/variant function are not compatible |
| 11751 | /// with the pragma, pair of original function/variant ref expression |
| 11752 | /// otherwise. |
| 11753 | std::optional<std::pair<FunctionDecl *, Expr *>> |
| 11754 | checkOpenMPDeclareVariantFunction(DeclGroupPtrTy DG, Expr *VariantRef, |
| 11755 | OMPTraitInfo &TI, unsigned NumAppendArgs, |
| 11756 | SourceRange SR); |
| 11757 | |
| 11758 | /// Called on well-formed '\#pragma omp declare variant' after parsing of |
| 11759 | /// the associated method/function. |
| 11760 | /// \param FD Function declaration to which declare variant directive is |
| 11761 | /// applied to. |
| 11762 | /// \param VariantRef Expression that references the variant function, which |
| 11763 | /// must be used instead of the original one, specified in \p DG. |
| 11764 | /// \param TI The context traits associated with the function variant. |
| 11765 | /// \param AdjustArgsNothing The list of 'nothing' arguments. |
| 11766 | /// \param AdjustArgsNeedDevicePtr The list of 'need_device_ptr' arguments. |
| 11767 | /// \param AppendArgs The list of 'append_args' arguments. |
| 11768 | /// \param AdjustArgsLoc The Location of an 'adjust_args' clause. |
| 11769 | /// \param AppendArgsLoc The Location of an 'append_args' clause. |
| 11770 | /// \param SR The SourceRange of the 'declare variant' directive. |
| 11771 | void ActOnOpenMPDeclareVariantDirective( |
| 11772 | FunctionDecl *FD, Expr *VariantRef, OMPTraitInfo &TI, |
| 11773 | ArrayRef<Expr *> AdjustArgsNothing, |
| 11774 | ArrayRef<Expr *> AdjustArgsNeedDevicePtr, |
| 11775 | ArrayRef<OMPInteropInfo> AppendArgs, SourceLocation AdjustArgsLoc, |
| 11776 | SourceLocation AppendArgsLoc, SourceRange SR); |
| 11777 | |
| 11778 | OMPClause *ActOnOpenMPSingleExprClause(OpenMPClauseKind Kind, |
| 11779 | Expr *Expr, |
| 11780 | SourceLocation StartLoc, |
| 11781 | SourceLocation LParenLoc, |
| 11782 | SourceLocation EndLoc); |
| 11783 | /// Called on well-formed 'allocator' clause. |
| 11784 | OMPClause *ActOnOpenMPAllocatorClause(Expr *Allocator, |
| 11785 | SourceLocation StartLoc, |
| 11786 | SourceLocation LParenLoc, |
| 11787 | SourceLocation EndLoc); |
| 11788 | /// Called on well-formed 'if' clause. |
| 11789 | OMPClause *ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, |
| 11790 | Expr *Condition, SourceLocation StartLoc, |
| 11791 | SourceLocation LParenLoc, |
| 11792 | SourceLocation NameModifierLoc, |
| 11793 | SourceLocation ColonLoc, |
| 11794 | SourceLocation EndLoc); |
| 11795 | /// Called on well-formed 'final' clause. |
| 11796 | OMPClause *ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 11797 | SourceLocation LParenLoc, |
| 11798 | SourceLocation EndLoc); |
| 11799 | /// Called on well-formed 'num_threads' clause. |
| 11800 | OMPClause *ActOnOpenMPNumThreadsClause(Expr *NumThreads, |
| 11801 | SourceLocation StartLoc, |
| 11802 | SourceLocation LParenLoc, |
| 11803 | SourceLocation EndLoc); |
| 11804 | /// Called on well-formed 'align' clause. |
| 11805 | OMPClause *ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, |
| 11806 | SourceLocation LParenLoc, |
| 11807 | SourceLocation EndLoc); |
| 11808 | /// Called on well-formed 'safelen' clause. |
| 11809 | OMPClause *ActOnOpenMPSafelenClause(Expr *Length, |
| 11810 | SourceLocation StartLoc, |
| 11811 | SourceLocation LParenLoc, |
| 11812 | SourceLocation EndLoc); |
| 11813 | /// Called on well-formed 'simdlen' clause. |
| 11814 | OMPClause *ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, |
| 11815 | SourceLocation LParenLoc, |
| 11816 | SourceLocation EndLoc); |
| 11817 | /// Called on well-form 'sizes' clause. |
| 11818 | OMPClause *ActOnOpenMPSizesClause(ArrayRef<Expr *> SizeExprs, |
| 11819 | SourceLocation StartLoc, |
| 11820 | SourceLocation LParenLoc, |
| 11821 | SourceLocation EndLoc); |
| 11822 | /// Called on well-form 'full' clauses. |
| 11823 | OMPClause *ActOnOpenMPFullClause(SourceLocation StartLoc, |
| 11824 | SourceLocation EndLoc); |
| 11825 | /// Called on well-form 'partial' clauses. |
| 11826 | OMPClause *ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, |
| 11827 | SourceLocation LParenLoc, |
| 11828 | SourceLocation EndLoc); |
| 11829 | /// Called on well-formed 'collapse' clause. |
| 11830 | OMPClause *ActOnOpenMPCollapseClause(Expr *NumForLoops, |
| 11831 | SourceLocation StartLoc, |
| 11832 | SourceLocation LParenLoc, |
| 11833 | SourceLocation EndLoc); |
| 11834 | /// Called on well-formed 'ordered' clause. |
| 11835 | OMPClause * |
| 11836 | ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, |
| 11837 | SourceLocation LParenLoc = SourceLocation(), |
| 11838 | Expr *NumForLoops = nullptr); |
| 11839 | /// Called on well-formed 'grainsize' clause. |
| 11840 | OMPClause *ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, |
| 11841 | Expr *Size, SourceLocation StartLoc, |
| 11842 | SourceLocation LParenLoc, |
| 11843 | SourceLocation ModifierLoc, |
| 11844 | SourceLocation EndLoc); |
| 11845 | /// Called on well-formed 'num_tasks' clause. |
| 11846 | OMPClause *ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, |
| 11847 | Expr *NumTasks, SourceLocation StartLoc, |
| 11848 | SourceLocation LParenLoc, |
| 11849 | SourceLocation ModifierLoc, |
| 11850 | SourceLocation EndLoc); |
| 11851 | /// Called on well-formed 'hint' clause. |
| 11852 | OMPClause *ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 11853 | SourceLocation LParenLoc, |
| 11854 | SourceLocation EndLoc); |
| 11855 | /// Called on well-formed 'detach' clause. |
| 11856 | OMPClause *ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, |
| 11857 | SourceLocation LParenLoc, |
| 11858 | SourceLocation EndLoc); |
| 11859 | |
| 11860 | OMPClause *ActOnOpenMPSimpleClause(OpenMPClauseKind Kind, |
| 11861 | unsigned Argument, |
| 11862 | SourceLocation ArgumentLoc, |
| 11863 | SourceLocation StartLoc, |
| 11864 | SourceLocation LParenLoc, |
| 11865 | SourceLocation EndLoc); |
| 11866 | /// Called on well-formed 'when' clause. |
| 11867 | OMPClause *ActOnOpenMPWhenClause(OMPTraitInfo &TI, SourceLocation StartLoc, |
| 11868 | SourceLocation LParenLoc, |
| 11869 | SourceLocation EndLoc); |
| 11870 | /// Called on well-formed 'default' clause. |
| 11871 | OMPClause *ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, |
| 11872 | SourceLocation KindLoc, |
| 11873 | SourceLocation StartLoc, |
| 11874 | SourceLocation LParenLoc, |
| 11875 | SourceLocation EndLoc); |
| 11876 | /// Called on well-formed 'proc_bind' clause. |
| 11877 | OMPClause *ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, |
| 11878 | SourceLocation KindLoc, |
| 11879 | SourceLocation StartLoc, |
| 11880 | SourceLocation LParenLoc, |
| 11881 | SourceLocation EndLoc); |
| 11882 | /// Called on well-formed 'order' clause. |
| 11883 | OMPClause *ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, |
| 11884 | OpenMPOrderClauseKind Kind, |
| 11885 | SourceLocation StartLoc, |
| 11886 | SourceLocation LParenLoc, |
| 11887 | SourceLocation MLoc, SourceLocation KindLoc, |
| 11888 | SourceLocation EndLoc); |
| 11889 | /// Called on well-formed 'update' clause. |
| 11890 | OMPClause *ActOnOpenMPUpdateClause(OpenMPDependClauseKind Kind, |
| 11891 | SourceLocation KindLoc, |
| 11892 | SourceLocation StartLoc, |
| 11893 | SourceLocation LParenLoc, |
| 11894 | SourceLocation EndLoc); |
| 11895 | |
| 11896 | OMPClause *ActOnOpenMPSingleExprWithArgClause( |
| 11897 | OpenMPClauseKind Kind, ArrayRef<unsigned> Arguments, Expr *Expr, |
| 11898 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 11899 | ArrayRef<SourceLocation> ArgumentsLoc, SourceLocation DelimLoc, |
| 11900 | SourceLocation EndLoc); |
| 11901 | /// Called on well-formed 'schedule' clause. |
| 11902 | OMPClause *ActOnOpenMPScheduleClause( |
| 11903 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
| 11904 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 11905 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 11906 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc); |
| 11907 | |
| 11908 | OMPClause *ActOnOpenMPClause(OpenMPClauseKind Kind, SourceLocation StartLoc, |
| 11909 | SourceLocation EndLoc); |
| 11910 | /// Called on well-formed 'nowait' clause. |
| 11911 | OMPClause *ActOnOpenMPNowaitClause(SourceLocation StartLoc, |
| 11912 | SourceLocation EndLoc); |
| 11913 | /// Called on well-formed 'untied' clause. |
| 11914 | OMPClause *ActOnOpenMPUntiedClause(SourceLocation StartLoc, |
| 11915 | SourceLocation EndLoc); |
| 11916 | /// Called on well-formed 'mergeable' clause. |
| 11917 | OMPClause *ActOnOpenMPMergeableClause(SourceLocation StartLoc, |
| 11918 | SourceLocation EndLoc); |
| 11919 | /// Called on well-formed 'read' clause. |
| 11920 | OMPClause *ActOnOpenMPReadClause(SourceLocation StartLoc, |
| 11921 | SourceLocation EndLoc); |
| 11922 | /// Called on well-formed 'write' clause. |
| 11923 | OMPClause *ActOnOpenMPWriteClause(SourceLocation StartLoc, |
| 11924 | SourceLocation EndLoc); |
| 11925 | /// Called on well-formed 'update' clause. |
| 11926 | OMPClause *ActOnOpenMPUpdateClause(SourceLocation StartLoc, |
| 11927 | SourceLocation EndLoc); |
| 11928 | /// Called on well-formed 'capture' clause. |
| 11929 | OMPClause *ActOnOpenMPCaptureClause(SourceLocation StartLoc, |
| 11930 | SourceLocation EndLoc); |
| 11931 | /// Called on well-formed 'compare' clause. |
| 11932 | OMPClause *ActOnOpenMPCompareClause(SourceLocation StartLoc, |
| 11933 | SourceLocation EndLoc); |
| 11934 | /// Called on well-formed 'seq_cst' clause. |
| 11935 | OMPClause *ActOnOpenMPSeqCstClause(SourceLocation StartLoc, |
| 11936 | SourceLocation EndLoc); |
| 11937 | /// Called on well-formed 'acq_rel' clause. |
| 11938 | OMPClause *ActOnOpenMPAcqRelClause(SourceLocation StartLoc, |
| 11939 | SourceLocation EndLoc); |
| 11940 | /// Called on well-formed 'acquire' clause. |
| 11941 | OMPClause *ActOnOpenMPAcquireClause(SourceLocation StartLoc, |
| 11942 | SourceLocation EndLoc); |
| 11943 | /// Called on well-formed 'release' clause. |
| 11944 | OMPClause *ActOnOpenMPReleaseClause(SourceLocation StartLoc, |
| 11945 | SourceLocation EndLoc); |
| 11946 | /// Called on well-formed 'relaxed' clause. |
| 11947 | OMPClause *ActOnOpenMPRelaxedClause(SourceLocation StartLoc, |
| 11948 | SourceLocation EndLoc); |
| 11949 | |
| 11950 | /// Called on well-formed 'init' clause. |
| 11951 | OMPClause * |
| 11952 | ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, |
| 11953 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 11954 | SourceLocation VarLoc, SourceLocation EndLoc); |
| 11955 | |
| 11956 | /// Called on well-formed 'use' clause. |
| 11957 | OMPClause *ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, |
| 11958 | SourceLocation LParenLoc, |
| 11959 | SourceLocation VarLoc, SourceLocation EndLoc); |
| 11960 | |
| 11961 | /// Called on well-formed 'destroy' clause. |
| 11962 | OMPClause *ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, |
| 11963 | SourceLocation LParenLoc, |
| 11964 | SourceLocation VarLoc, |
| 11965 | SourceLocation EndLoc); |
| 11966 | /// Called on well-formed 'novariants' clause. |
| 11967 | OMPClause *ActOnOpenMPNovariantsClause(Expr *Condition, |
| 11968 | SourceLocation StartLoc, |
| 11969 | SourceLocation LParenLoc, |
| 11970 | SourceLocation EndLoc); |
| 11971 | /// Called on well-formed 'nocontext' clause. |
| 11972 | OMPClause *ActOnOpenMPNocontextClause(Expr *Condition, |
| 11973 | SourceLocation StartLoc, |
| 11974 | SourceLocation LParenLoc, |
| 11975 | SourceLocation EndLoc); |
| 11976 | /// Called on well-formed 'filter' clause. |
| 11977 | OMPClause *ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, |
| 11978 | SourceLocation LParenLoc, |
| 11979 | SourceLocation EndLoc); |
| 11980 | /// Called on well-formed 'threads' clause. |
| 11981 | OMPClause *ActOnOpenMPThreadsClause(SourceLocation StartLoc, |
| 11982 | SourceLocation EndLoc); |
| 11983 | /// Called on well-formed 'simd' clause. |
| 11984 | OMPClause *ActOnOpenMPSIMDClause(SourceLocation StartLoc, |
| 11985 | SourceLocation EndLoc); |
| 11986 | /// Called on well-formed 'nogroup' clause. |
| 11987 | OMPClause *ActOnOpenMPNogroupClause(SourceLocation StartLoc, |
| 11988 | SourceLocation EndLoc); |
| 11989 | /// Called on well-formed 'unified_address' clause. |
| 11990 | OMPClause *ActOnOpenMPUnifiedAddressClause(SourceLocation StartLoc, |
| 11991 | SourceLocation EndLoc); |
| 11992 | |
| 11993 | /// Called on well-formed 'unified_address' clause. |
| 11994 | OMPClause *ActOnOpenMPUnifiedSharedMemoryClause(SourceLocation StartLoc, |
| 11995 | SourceLocation EndLoc); |
| 11996 | |
| 11997 | /// Called on well-formed 'reverse_offload' clause. |
| 11998 | OMPClause *ActOnOpenMPReverseOffloadClause(SourceLocation StartLoc, |
| 11999 | SourceLocation EndLoc); |
| 12000 | |
| 12001 | /// Called on well-formed 'dynamic_allocators' clause. |
| 12002 | OMPClause *ActOnOpenMPDynamicAllocatorsClause(SourceLocation StartLoc, |
| 12003 | SourceLocation EndLoc); |
| 12004 | |
| 12005 | /// Called on well-formed 'atomic_default_mem_order' clause. |
| 12006 | OMPClause *ActOnOpenMPAtomicDefaultMemOrderClause( |
| 12007 | OpenMPAtomicDefaultMemOrderClauseKind Kind, SourceLocation KindLoc, |
| 12008 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
| 12009 | |
| 12010 | /// Called on well-formed 'at' clause. |
| 12011 | OMPClause *ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, |
| 12012 | SourceLocation KindLoc, |
| 12013 | SourceLocation StartLoc, |
| 12014 | SourceLocation LParenLoc, |
| 12015 | SourceLocation EndLoc); |
| 12016 | |
| 12017 | /// Called on well-formed 'severity' clause. |
| 12018 | OMPClause *ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, |
| 12019 | SourceLocation KindLoc, |
| 12020 | SourceLocation StartLoc, |
| 12021 | SourceLocation LParenLoc, |
| 12022 | SourceLocation EndLoc); |
| 12023 | |
| 12024 | /// Called on well-formed 'message' clause. |
| 12025 | /// passing string for message. |
| 12026 | OMPClause *ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, |
| 12027 | SourceLocation LParenLoc, |
| 12028 | SourceLocation EndLoc); |
| 12029 | |
| 12030 | /// Data used for processing a list of variables in OpenMP clauses. |
| 12031 | struct OpenMPVarListDataTy final { |
| 12032 | Expr *DepModOrTailExpr = nullptr; |
| 12033 | Expr *IteratorExpr = nullptr; |
| 12034 | SourceLocation ColonLoc; |
| 12035 | SourceLocation RLoc; |
| 12036 | CXXScopeSpec ReductionOrMapperIdScopeSpec; |
| 12037 | DeclarationNameInfo ReductionOrMapperId; |
| 12038 | int ExtraModifier = -1; ///< Additional modifier for linear, map, depend or |
| 12039 | ///< lastprivate clause. |
| 12040 | SmallVector<OpenMPMapModifierKind, NumberOfOMPMapClauseModifiers> |
| 12041 | MapTypeModifiers; |
| 12042 | SmallVector<SourceLocation, NumberOfOMPMapClauseModifiers> |
| 12043 | MapTypeModifiersLoc; |
| 12044 | SmallVector<OpenMPMotionModifierKind, NumberOfOMPMotionModifiers> |
| 12045 | MotionModifiers; |
| 12046 | SmallVector<SourceLocation, NumberOfOMPMotionModifiers> MotionModifiersLoc; |
| 12047 | bool IsMapTypeImplicit = false; |
| 12048 | SourceLocation ExtraModifierLoc; |
| 12049 | SourceLocation OmpAllMemoryLoc; |
| 12050 | }; |
| 12051 | |
| 12052 | OMPClause *ActOnOpenMPVarListClause(OpenMPClauseKind Kind, |
| 12053 | ArrayRef<Expr *> Vars, |
| 12054 | const OMPVarListLocTy &Locs, |
| 12055 | OpenMPVarListDataTy &Data); |
| 12056 | /// Called on well-formed 'inclusive' clause. |
| 12057 | OMPClause *ActOnOpenMPInclusiveClause(ArrayRef<Expr *> VarList, |
| 12058 | SourceLocation StartLoc, |
| 12059 | SourceLocation LParenLoc, |
| 12060 | SourceLocation EndLoc); |
| 12061 | /// Called on well-formed 'exclusive' clause. |
| 12062 | OMPClause *ActOnOpenMPExclusiveClause(ArrayRef<Expr *> VarList, |
| 12063 | SourceLocation StartLoc, |
| 12064 | SourceLocation LParenLoc, |
| 12065 | SourceLocation EndLoc); |
| 12066 | /// Called on well-formed 'allocate' clause. |
| 12067 | OMPClause * |
| 12068 | ActOnOpenMPAllocateClause(Expr *Allocator, ArrayRef<Expr *> VarList, |
| 12069 | SourceLocation StartLoc, SourceLocation ColonLoc, |
| 12070 | SourceLocation LParenLoc, SourceLocation EndLoc); |
| 12071 | /// Called on well-formed 'private' clause. |
| 12072 | OMPClause *ActOnOpenMPPrivateClause(ArrayRef<Expr *> VarList, |
| 12073 | SourceLocation StartLoc, |
| 12074 | SourceLocation LParenLoc, |
| 12075 | SourceLocation EndLoc); |
| 12076 | /// Called on well-formed 'firstprivate' clause. |
| 12077 | OMPClause *ActOnOpenMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 12078 | SourceLocation StartLoc, |
| 12079 | SourceLocation LParenLoc, |
| 12080 | SourceLocation EndLoc); |
| 12081 | /// Called on well-formed 'lastprivate' clause. |
| 12082 | OMPClause *ActOnOpenMPLastprivateClause( |
| 12083 | ArrayRef<Expr *> VarList, OpenMPLastprivateModifier LPKind, |
| 12084 | SourceLocation LPKindLoc, SourceLocation ColonLoc, |
| 12085 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc); |
| 12086 | /// Called on well-formed 'shared' clause. |
| 12087 | OMPClause *ActOnOpenMPSharedClause(ArrayRef<Expr *> VarList, |
| 12088 | SourceLocation StartLoc, |
| 12089 | SourceLocation LParenLoc, |
| 12090 | SourceLocation EndLoc); |
| 12091 | /// Called on well-formed 'reduction' clause. |
| 12092 | OMPClause *ActOnOpenMPReductionClause( |
| 12093 | ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, |
| 12094 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 12095 | SourceLocation ModifierLoc, SourceLocation ColonLoc, |
| 12096 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
| 12097 | const DeclarationNameInfo &ReductionId, |
| 12098 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
| 12099 | /// Called on well-formed 'task_reduction' clause. |
| 12100 | OMPClause *ActOnOpenMPTaskReductionClause( |
| 12101 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 12102 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
| 12103 | CXXScopeSpec &ReductionIdScopeSpec, |
| 12104 | const DeclarationNameInfo &ReductionId, |
| 12105 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
| 12106 | /// Called on well-formed 'in_reduction' clause. |
| 12107 | OMPClause *ActOnOpenMPInReductionClause( |
| 12108 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 12109 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
| 12110 | CXXScopeSpec &ReductionIdScopeSpec, |
| 12111 | const DeclarationNameInfo &ReductionId, |
| 12112 | ArrayRef<Expr *> UnresolvedReductions = std::nullopt); |
| 12113 | /// Called on well-formed 'linear' clause. |
| 12114 | OMPClause * |
| 12115 | ActOnOpenMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 12116 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 12117 | OpenMPLinearClauseKind LinKind, SourceLocation LinLoc, |
| 12118 | SourceLocation ColonLoc, SourceLocation EndLoc); |
| 12119 | /// Called on well-formed 'aligned' clause. |
| 12120 | OMPClause *ActOnOpenMPAlignedClause(ArrayRef<Expr *> VarList, |
| 12121 | Expr *Alignment, |
| 12122 | SourceLocation StartLoc, |
| 12123 | SourceLocation LParenLoc, |
| 12124 | SourceLocation ColonLoc, |
| 12125 | SourceLocation EndLoc); |
| 12126 | /// Called on well-formed 'copyin' clause. |
| 12127 | OMPClause *ActOnOpenMPCopyinClause(ArrayRef<Expr *> VarList, |
| 12128 | SourceLocation StartLoc, |
| 12129 | SourceLocation LParenLoc, |
| 12130 | SourceLocation EndLoc); |
| 12131 | /// Called on well-formed 'copyprivate' clause. |
| 12132 | OMPClause *ActOnOpenMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 12133 | SourceLocation StartLoc, |
| 12134 | SourceLocation LParenLoc, |
| 12135 | SourceLocation EndLoc); |
| 12136 | /// Called on well-formed 'flush' pseudo clause. |
| 12137 | OMPClause *ActOnOpenMPFlushClause(ArrayRef<Expr *> VarList, |
| 12138 | SourceLocation StartLoc, |
| 12139 | SourceLocation LParenLoc, |
| 12140 | SourceLocation EndLoc); |
| 12141 | /// Called on well-formed 'depobj' pseudo clause. |
| 12142 | OMPClause *ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, |
| 12143 | SourceLocation LParenLoc, |
| 12144 | SourceLocation EndLoc); |
| 12145 | /// Called on well-formed 'depend' clause. |
| 12146 | OMPClause *ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, |
| 12147 | Expr *DepModifier, |
| 12148 | ArrayRef<Expr *> VarList, |
| 12149 | SourceLocation StartLoc, |
| 12150 | SourceLocation LParenLoc, |
| 12151 | SourceLocation EndLoc); |
| 12152 | /// Called on well-formed 'device' clause. |
| 12153 | OMPClause *ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, |
| 12154 | Expr *Device, SourceLocation StartLoc, |
| 12155 | SourceLocation LParenLoc, |
| 12156 | SourceLocation ModifierLoc, |
| 12157 | SourceLocation EndLoc); |
| 12158 | /// Called on well-formed 'map' clause. |
| 12159 | OMPClause *ActOnOpenMPMapClause( |
| 12160 | Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
| 12161 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
| 12162 | CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, |
| 12163 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 12164 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 12165 | const OMPVarListLocTy &Locs, bool NoDiagnose = false, |
| 12166 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
| 12167 | /// Called on well-formed 'num_teams' clause. |
| 12168 | OMPClause *ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
| 12169 | SourceLocation LParenLoc, |
| 12170 | SourceLocation EndLoc); |
| 12171 | /// Called on well-formed 'thread_limit' clause. |
| 12172 | OMPClause *ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, |
| 12173 | SourceLocation StartLoc, |
| 12174 | SourceLocation LParenLoc, |
| 12175 | SourceLocation EndLoc); |
| 12176 | /// Called on well-formed 'priority' clause. |
| 12177 | OMPClause *ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
| 12178 | SourceLocation LParenLoc, |
| 12179 | SourceLocation EndLoc); |
| 12180 | /// Called on well-formed 'dist_schedule' clause. |
| 12181 | OMPClause *ActOnOpenMPDistScheduleClause( |
| 12182 | OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, |
| 12183 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, |
| 12184 | SourceLocation CommaLoc, SourceLocation EndLoc); |
| 12185 | /// Called on well-formed 'defaultmap' clause. |
| 12186 | OMPClause *ActOnOpenMPDefaultmapClause( |
| 12187 | OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, |
| 12188 | SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, |
| 12189 | SourceLocation KindLoc, SourceLocation EndLoc); |
| 12190 | /// Called on well-formed 'to' clause. |
| 12191 | OMPClause * |
| 12192 | ActOnOpenMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
| 12193 | ArrayRef<SourceLocation> MotionModifiersLoc, |
| 12194 | CXXScopeSpec &MapperIdScopeSpec, |
| 12195 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
| 12196 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
| 12197 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
| 12198 | /// Called on well-formed 'from' clause. |
| 12199 | OMPClause * |
| 12200 | ActOnOpenMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
| 12201 | ArrayRef<SourceLocation> MotionModifiersLoc, |
| 12202 | CXXScopeSpec &MapperIdScopeSpec, |
| 12203 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
| 12204 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
| 12205 | ArrayRef<Expr *> UnresolvedMappers = std::nullopt); |
| 12206 | /// Called on well-formed 'use_device_ptr' clause. |
| 12207 | OMPClause *ActOnOpenMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 12208 | const OMPVarListLocTy &Locs); |
| 12209 | /// Called on well-formed 'use_device_addr' clause. |
| 12210 | OMPClause *ActOnOpenMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, |
| 12211 | const OMPVarListLocTy &Locs); |
| 12212 | /// Called on well-formed 'is_device_ptr' clause. |
| 12213 | OMPClause *ActOnOpenMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 12214 | const OMPVarListLocTy &Locs); |
| 12215 | /// Called on well-formed 'has_device_addr' clause. |
| 12216 | OMPClause *ActOnOpenMPHasDeviceAddrClause(ArrayRef<Expr *> VarList, |
| 12217 | const OMPVarListLocTy &Locs); |
| 12218 | /// Called on well-formed 'nontemporal' clause. |
| 12219 | OMPClause *ActOnOpenMPNontemporalClause(ArrayRef<Expr *> VarList, |
| 12220 | SourceLocation StartLoc, |
| 12221 | SourceLocation LParenLoc, |
| 12222 | SourceLocation EndLoc); |
| 12223 | |
| 12224 | /// Data for list of allocators. |
| 12225 | struct UsesAllocatorsData { |
| 12226 | /// Allocator. |
| 12227 | Expr *Allocator = nullptr; |
| 12228 | /// Allocator traits. |
| 12229 | Expr *AllocatorTraits = nullptr; |
| 12230 | /// Locations of '(' and ')' symbols. |
| 12231 | SourceLocation LParenLoc, RParenLoc; |
| 12232 | }; |
| 12233 | /// Called on well-formed 'uses_allocators' clause. |
| 12234 | OMPClause *ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, |
| 12235 | SourceLocation LParenLoc, |
| 12236 | SourceLocation EndLoc, |
| 12237 | ArrayRef<UsesAllocatorsData> Data); |
| 12238 | /// Called on well-formed 'affinity' clause. |
| 12239 | OMPClause *ActOnOpenMPAffinityClause(SourceLocation StartLoc, |
| 12240 | SourceLocation LParenLoc, |
| 12241 | SourceLocation ColonLoc, |
| 12242 | SourceLocation EndLoc, Expr *Modifier, |
| 12243 | ArrayRef<Expr *> Locators); |
| 12244 | /// Called on a well-formed 'bind' clause. |
| 12245 | OMPClause *ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, |
| 12246 | SourceLocation KindLoc, |
| 12247 | SourceLocation StartLoc, |
| 12248 | SourceLocation LParenLoc, |
| 12249 | SourceLocation EndLoc); |
| 12250 | |
| 12251 | /// Called on a well-formed 'ompx_dyn_cgroup_mem' clause. |
| 12252 | OMPClause *ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, |
| 12253 | SourceLocation LParenLoc, |
| 12254 | SourceLocation EndLoc); |
| 12255 | |
| 12256 | /// The kind of conversion being performed. |
| 12257 | enum CheckedConversionKind { |
| 12258 | /// An implicit conversion. |
| 12259 | CCK_ImplicitConversion, |
| 12260 | /// A C-style cast. |
| 12261 | CCK_CStyleCast, |
| 12262 | /// A functional-style cast. |
| 12263 | CCK_FunctionalCast, |
| 12264 | /// A cast other than a C-style cast. |
| 12265 | CCK_OtherCast, |
| 12266 | /// A conversion for an operand of a builtin overloaded operator. |
| 12267 | CCK_ForBuiltinOverloadedOp |
| 12268 | }; |
| 12269 | |
| 12270 | static bool isCast(CheckedConversionKind CCK) { |
| 12271 | return CCK == CCK_CStyleCast || CCK == CCK_FunctionalCast || |
| 12272 | CCK == CCK_OtherCast; |
| 12273 | } |
| 12274 | |
| 12275 | /// ImpCastExprToType - If Expr is not of type 'Type', insert an implicit |
| 12276 | /// cast. If there is already an implicit cast, merge into the existing one. |
| 12277 | /// If isLvalue, the result of the cast is an lvalue. |
| 12278 | ExprResult |
| 12279 | ImpCastExprToType(Expr *E, QualType Type, CastKind CK, |
| 12280 | ExprValueKind VK = VK_PRValue, |
| 12281 | const CXXCastPath *BasePath = nullptr, |
| 12282 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
| 12283 | |
| 12284 | /// ScalarTypeToBooleanCastKind - Returns the cast kind corresponding |
| 12285 | /// to the conversion from scalar type ScalarTy to the Boolean type. |
| 12286 | static CastKind ScalarTypeToBooleanCastKind(QualType ScalarTy); |
| 12287 | |
| 12288 | /// IgnoredValueConversions - Given that an expression's result is |
| 12289 | /// syntactically ignored, perform any conversions that are |
| 12290 | /// required. |
| 12291 | ExprResult IgnoredValueConversions(Expr *E); |
| 12292 | |
| 12293 | // UsualUnaryConversions - promotes integers (C99 6.3.1.1p2) and converts |
| 12294 | // functions and arrays to their respective pointers (C99 6.3.2.1). |
| 12295 | ExprResult UsualUnaryConversions(Expr *E); |
| 12296 | |
| 12297 | /// CallExprUnaryConversions - a special case of an unary conversion |
| 12298 | /// performed on a function designator of a call expression. |
| 12299 | ExprResult CallExprUnaryConversions(Expr *E); |
| 12300 | |
| 12301 | // DefaultFunctionArrayConversion - converts functions and arrays |
| 12302 | // to their respective pointers (C99 6.3.2.1). |
| 12303 | ExprResult DefaultFunctionArrayConversion(Expr *E, bool Diagnose = true); |
| 12304 | |
| 12305 | // DefaultFunctionArrayLvalueConversion - converts functions and |
| 12306 | // arrays to their respective pointers and performs the |
| 12307 | // lvalue-to-rvalue conversion. |
| 12308 | ExprResult DefaultFunctionArrayLvalueConversion(Expr *E, |
| 12309 | bool Diagnose = true); |
| 12310 | |
| 12311 | // DefaultLvalueConversion - performs lvalue-to-rvalue conversion on |
| 12312 | // the operand. This function is a no-op if the operand has a function type |
| 12313 | // or an array type. |
| 12314 | ExprResult DefaultLvalueConversion(Expr *E); |
| 12315 | |
| 12316 | // DefaultArgumentPromotion (C99 6.5.2.2p6). Used for function calls that |
| 12317 | // do not have a prototype. Integer promotions are performed on each |
| 12318 | // argument, and arguments that have type float are promoted to double. |
| 12319 | ExprResult DefaultArgumentPromotion(Expr *E); |
| 12320 | |
| 12321 | /// If \p E is a prvalue denoting an unmaterialized temporary, materialize |
| 12322 | /// it as an xvalue. In C++98, the result will still be a prvalue, because |
| 12323 | /// we don't have xvalues there. |
| 12324 | ExprResult TemporaryMaterializationConversion(Expr *E); |
| 12325 | |
| 12326 | // Used for emitting the right warning by DefaultVariadicArgumentPromotion |
| 12327 | enum VariadicCallType { |
| 12328 | VariadicFunction, |
| 12329 | VariadicBlock, |
| 12330 | VariadicMethod, |
| 12331 | VariadicConstructor, |
| 12332 | VariadicDoesNotApply |
| 12333 | }; |
| 12334 | |
| 12335 | VariadicCallType getVariadicCallType(FunctionDecl *FDecl, |
| 12336 | const FunctionProtoType *Proto, |
| 12337 | Expr *Fn); |
| 12338 | |
| 12339 | // Used for determining in which context a type is allowed to be passed to a |
| 12340 | // vararg function. |
| 12341 | enum VarArgKind { |
| 12342 | VAK_Valid, |
| 12343 | VAK_ValidInCXX11, |
| 12344 | VAK_Undefined, |
| 12345 | VAK_MSVCUndefined, |
| 12346 | VAK_Invalid |
| 12347 | }; |
| 12348 | |
| 12349 | // Determines which VarArgKind fits an expression. |
| 12350 | VarArgKind isValidVarArgType(const QualType &Ty); |
| 12351 | |
| 12352 | /// Check to see if the given expression is a valid argument to a variadic |
| 12353 | /// function, issuing a diagnostic if not. |
| 12354 | void checkVariadicArgument(const Expr *E, VariadicCallType CT); |
| 12355 | |
| 12356 | /// Check whether the given statement can have musttail applied to it, |
| 12357 | /// issuing a diagnostic and returning false if not. In the success case, |
| 12358 | /// the statement is rewritten to remove implicit nodes from the return |
| 12359 | /// value. |
| 12360 | bool checkAndRewriteMustTailAttr(Stmt *St, const Attr &MTA); |
| 12361 | |
| 12362 | private: |
| 12363 | /// Check whether the given statement can have musttail applied to it, |
| 12364 | /// issuing a diagnostic and returning false if not. |
| 12365 | bool checkMustTailAttr(const Stmt *St, const Attr &MTA); |
| 12366 | |
| 12367 | public: |
| 12368 | /// Check to see if a given expression could have '.c_str()' called on it. |
| 12369 | bool hasCStrMethod(const Expr *E); |
| 12370 | |
| 12371 | /// GatherArgumentsForCall - Collector argument expressions for various |
| 12372 | /// form of call prototypes. |
| 12373 | bool GatherArgumentsForCall(SourceLocation CallLoc, FunctionDecl *FDecl, |
| 12374 | const FunctionProtoType *Proto, |
| 12375 | unsigned FirstParam, ArrayRef<Expr *> Args, |
| 12376 | SmallVectorImpl<Expr *> &AllArgs, |
| 12377 | VariadicCallType CallType = VariadicDoesNotApply, |
| 12378 | bool AllowExplicit = false, |
| 12379 | bool IsListInitialization = false); |
| 12380 | |
| 12381 | // DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but |
| 12382 | // will create a runtime trap if the resulting type is not a POD type. |
| 12383 | ExprResult DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, |
| 12384 | FunctionDecl *FDecl); |
| 12385 | |
| 12386 | /// Context in which we're performing a usual arithmetic conversion. |
| 12387 | enum ArithConvKind { |
| 12388 | /// An arithmetic operation. |
| 12389 | ACK_Arithmetic, |
| 12390 | /// A bitwise operation. |
| 12391 | ACK_BitwiseOp, |
| 12392 | /// A comparison. |
| 12393 | ACK_Comparison, |
| 12394 | /// A conditional (?:) operator. |
| 12395 | ACK_Conditional, |
| 12396 | /// A compound assignment expression. |
| 12397 | ACK_CompAssign, |
| 12398 | }; |
| 12399 | |
| 12400 | // UsualArithmeticConversions - performs the UsualUnaryConversions on it's |
| 12401 | // operands and then handles various conversions that are common to binary |
| 12402 | // operators (C99 6.3.1.8). If both operands aren't arithmetic, this |
| 12403 | // routine returns the first non-arithmetic type found. The client is |
| 12404 | // responsible for emitting appropriate error diagnostics. |
| 12405 | QualType UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, |
| 12406 | SourceLocation Loc, ArithConvKind ACK); |
| 12407 | |
| 12408 | /// AssignConvertType - All of the 'assignment' semantic checks return this |
| 12409 | /// enum to indicate whether the assignment was allowed. These checks are |
| 12410 | /// done for simple assignments, as well as initialization, return from |
| 12411 | /// function, argument passing, etc. The query is phrased in terms of a |
| 12412 | /// source and destination type. |
| 12413 | enum AssignConvertType { |
| 12414 | /// Compatible - the types are compatible according to the standard. |
| 12415 | Compatible, |
| 12416 | |
| 12417 | /// PointerToInt - The assignment converts a pointer to an int, which we |
| 12418 | /// accept as an extension. |
| 12419 | PointerToInt, |
| 12420 | |
| 12421 | /// IntToPointer - The assignment converts an int to a pointer, which we |
| 12422 | /// accept as an extension. |
| 12423 | IntToPointer, |
| 12424 | |
| 12425 | /// FunctionVoidPointer - The assignment is between a function pointer and |
| 12426 | /// void*, which the standard doesn't allow, but we accept as an extension. |
| 12427 | FunctionVoidPointer, |
| 12428 | |
| 12429 | /// IncompatiblePointer - The assignment is between two pointers types that |
| 12430 | /// are not compatible, but we accept them as an extension. |
| 12431 | IncompatiblePointer, |
| 12432 | |
| 12433 | /// IncompatibleFunctionPointer - The assignment is between two function |
| 12434 | /// pointers types that are not compatible, but we accept them as an |
| 12435 | /// extension. |
| 12436 | IncompatibleFunctionPointer, |
| 12437 | |
| 12438 | /// IncompatibleFunctionPointerStrict - The assignment is between two |
| 12439 | /// function pointer types that are not identical, but are compatible, |
| 12440 | /// unless compiled with -fsanitize=cfi, in which case the type mismatch |
| 12441 | /// may trip an indirect call runtime check. |
| 12442 | IncompatibleFunctionPointerStrict, |
| 12443 | |
| 12444 | /// IncompatiblePointerSign - The assignment is between two pointers types |
| 12445 | /// which point to integers which have a different sign, but are otherwise |
| 12446 | /// identical. This is a subset of the above, but broken out because it's by |
| 12447 | /// far the most common case of incompatible pointers. |
| 12448 | IncompatiblePointerSign, |
| 12449 | |
| 12450 | /// CompatiblePointerDiscardsQualifiers - The assignment discards |
| 12451 | /// c/v/r qualifiers, which we accept as an extension. |
| 12452 | CompatiblePointerDiscardsQualifiers, |
| 12453 | |
| 12454 | /// IncompatiblePointerDiscardsQualifiers - The assignment |
| 12455 | /// discards qualifiers that we don't permit to be discarded, |
| 12456 | /// like address spaces. |
| 12457 | IncompatiblePointerDiscardsQualifiers, |
| 12458 | |
| 12459 | /// IncompatibleNestedPointerAddressSpaceMismatch - The assignment |
| 12460 | /// changes address spaces in nested pointer types which is not allowed. |
| 12461 | /// For instance, converting __private int ** to __generic int ** is |
| 12462 | /// illegal even though __private could be converted to __generic. |
| 12463 | IncompatibleNestedPointerAddressSpaceMismatch, |
| 12464 | |
| 12465 | /// IncompatibleNestedPointerQualifiers - The assignment is between two |
| 12466 | /// nested pointer types, and the qualifiers other than the first two |
| 12467 | /// levels differ e.g. char ** -> const char **, but we accept them as an |
| 12468 | /// extension. |
| 12469 | IncompatibleNestedPointerQualifiers, |
| 12470 | |
| 12471 | /// IncompatibleVectors - The assignment is between two vector types that |
| 12472 | /// have the same size, which we accept as an extension. |
| 12473 | IncompatibleVectors, |
| 12474 | |
| 12475 | /// IntToBlockPointer - The assignment converts an int to a block |
| 12476 | /// pointer. We disallow this. |
| 12477 | IntToBlockPointer, |
| 12478 | |
| 12479 | /// IncompatibleBlockPointer - The assignment is between two block |
| 12480 | /// pointers types that are not compatible. |
| 12481 | IncompatibleBlockPointer, |
| 12482 | |
| 12483 | /// IncompatibleObjCQualifiedId - The assignment is between a qualified |
| 12484 | /// id type and something else (that is incompatible with it). For example, |
| 12485 | /// "id <XXX>" = "Foo *", where "Foo *" doesn't implement the XXX protocol. |
| 12486 | IncompatibleObjCQualifiedId, |
| 12487 | |
| 12488 | /// IncompatibleObjCWeakRef - Assigning a weak-unavailable object to an |
| 12489 | /// object with __weak qualifier. |
| 12490 | IncompatibleObjCWeakRef, |
| 12491 | |
| 12492 | /// Incompatible - We reject this conversion outright, it is invalid to |
| 12493 | /// represent it in the AST. |
| 12494 | Incompatible |
| 12495 | }; |
| 12496 | |
| 12497 | /// DiagnoseAssignmentResult - Emit a diagnostic, if required, for the |
| 12498 | /// assignment conversion type specified by ConvTy. This returns true if the |
| 12499 | /// conversion was invalid or false if the conversion was accepted. |
| 12500 | bool DiagnoseAssignmentResult(AssignConvertType ConvTy, |
| 12501 | SourceLocation Loc, |
| 12502 | QualType DstType, QualType SrcType, |
| 12503 | Expr *SrcExpr, AssignmentAction Action, |
| 12504 | bool *Complained = nullptr); |
| 12505 | |
| 12506 | /// IsValueInFlagEnum - Determine if a value is allowed as part of a flag |
| 12507 | /// enum. If AllowMask is true, then we also allow the complement of a valid |
| 12508 | /// value, to be used as a mask. |
| 12509 | bool IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val, |
| 12510 | bool AllowMask) const; |
| 12511 | |
| 12512 | /// DiagnoseAssignmentEnum - Warn if assignment to enum is a constant |
| 12513 | /// integer not in the range of enum values. |
| 12514 | void DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, |
| 12515 | Expr *SrcExpr); |
| 12516 | |
| 12517 | /// CheckAssignmentConstraints - Perform type checking for assignment, |
| 12518 | /// argument passing, variable initialization, and function return values. |
| 12519 | /// C99 6.5.16. |
| 12520 | AssignConvertType CheckAssignmentConstraints(SourceLocation Loc, |
| 12521 | QualType LHSType, |
| 12522 | QualType RHSType); |
| 12523 | |
| 12524 | /// Check assignment constraints and optionally prepare for a conversion of |
| 12525 | /// the RHS to the LHS type. The conversion is prepared for if ConvertRHS |
| 12526 | /// is true. |
| 12527 | AssignConvertType CheckAssignmentConstraints(QualType LHSType, |
| 12528 | ExprResult &RHS, |
| 12529 | CastKind &Kind, |
| 12530 | bool ConvertRHS = true); |
| 12531 | |
| 12532 | /// Check assignment constraints for an assignment of RHS to LHSType. |
| 12533 | /// |
| 12534 | /// \param LHSType The destination type for the assignment. |
| 12535 | /// \param RHS The source expression for the assignment. |
| 12536 | /// \param Diagnose If \c true, diagnostics may be produced when checking |
| 12537 | /// for assignability. If a diagnostic is produced, \p RHS will be |
| 12538 | /// set to ExprError(). Note that this function may still return |
| 12539 | /// without producing a diagnostic, even for an invalid assignment. |
| 12540 | /// \param DiagnoseCFAudited If \c true, the target is a function parameter |
| 12541 | /// in an audited Core Foundation API and does not need to be checked |
| 12542 | /// for ARC retain issues. |
| 12543 | /// \param ConvertRHS If \c true, \p RHS will be updated to model the |
| 12544 | /// conversions necessary to perform the assignment. If \c false, |
| 12545 | /// \p Diagnose must also be \c false. |
| 12546 | AssignConvertType CheckSingleAssignmentConstraints( |
| 12547 | QualType LHSType, ExprResult &RHS, bool Diagnose = true, |
| 12548 | bool DiagnoseCFAudited = false, bool ConvertRHS = true); |
| 12549 | |
| 12550 | // If the lhs type is a transparent union, check whether we |
| 12551 | // can initialize the transparent union with the given expression. |
| 12552 | AssignConvertType CheckTransparentUnionArgumentConstraints(QualType ArgType, |
| 12553 | ExprResult &RHS); |
| 12554 | |
| 12555 | bool IsStringLiteralToNonConstPointerConversion(Expr *From, QualType ToType); |
| 12556 | |
| 12557 | bool CheckExceptionSpecCompatibility(Expr *From, QualType ToType); |
| 12558 | |
| 12559 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
| 12560 | AssignmentAction Action, |
| 12561 | bool AllowExplicit = false); |
| 12562 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
| 12563 | const ImplicitConversionSequence& ICS, |
| 12564 | AssignmentAction Action, |
| 12565 | CheckedConversionKind CCK |
| 12566 | = CCK_ImplicitConversion); |
| 12567 | ExprResult PerformImplicitConversion(Expr *From, QualType ToType, |
| 12568 | const StandardConversionSequence& SCS, |
| 12569 | AssignmentAction Action, |
| 12570 | CheckedConversionKind CCK); |
| 12571 | |
| 12572 | ExprResult PerformQualificationConversion( |
| 12573 | Expr *E, QualType Ty, ExprValueKind VK = VK_PRValue, |
| 12574 | CheckedConversionKind CCK = CCK_ImplicitConversion); |
| 12575 | |
| 12576 | /// the following "Check" methods will return a valid/converted QualType |
| 12577 | /// or a null QualType (indicating an error diagnostic was issued). |
| 12578 | |
| 12579 | /// type checking binary operators (subroutines of CreateBuiltinBinOp). |
| 12580 | QualType InvalidOperands(SourceLocation Loc, ExprResult &LHS, |
| 12581 | ExprResult &RHS); |
| 12582 | QualType InvalidLogicalVectorOperands(SourceLocation Loc, ExprResult &LHS, |
| 12583 | ExprResult &RHS); |
| 12584 | QualType CheckPointerToMemberOperands( // C++ 5.5 |
| 12585 | ExprResult &LHS, ExprResult &RHS, ExprValueKind &VK, |
| 12586 | SourceLocation OpLoc, bool isIndirect); |
| 12587 | QualType CheckMultiplyDivideOperands( // C99 6.5.5 |
| 12588 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, |
| 12589 | bool IsDivide); |
| 12590 | QualType CheckRemainderOperands( // C99 6.5.5 |
| 12591 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 12592 | bool IsCompAssign = false); |
| 12593 | QualType CheckAdditionOperands( // C99 6.5.6 |
| 12594 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 12595 | BinaryOperatorKind Opc, QualType* CompLHSTy = nullptr); |
| 12596 | QualType CheckSubtractionOperands( // C99 6.5.6 |
| 12597 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 12598 | QualType* CompLHSTy = nullptr); |
| 12599 | QualType CheckShiftOperands( // C99 6.5.7 |
| 12600 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 12601 | BinaryOperatorKind Opc, bool IsCompAssign = false); |
| 12602 | void CheckPtrComparisonWithNullChar(ExprResult &E, ExprResult &NullE); |
| 12603 | QualType CheckCompareOperands( // C99 6.5.8/9 |
| 12604 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 12605 | BinaryOperatorKind Opc); |
| 12606 | QualType CheckBitwiseOperands( // C99 6.5.[10...12] |
| 12607 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 12608 | BinaryOperatorKind Opc); |
| 12609 | QualType CheckLogicalOperands( // C99 6.5.[13,14] |
| 12610 | ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, |
| 12611 | BinaryOperatorKind Opc); |
| 12612 | // CheckAssignmentOperands is used for both simple and compound assignment. |
| 12613 | // For simple assignment, pass both expressions and a null converted type. |
| 12614 | // For compound assignment, pass both expressions and the converted type. |
| 12615 | QualType CheckAssignmentOperands( // C99 6.5.16.[1,2] |
| 12616 | Expr *LHSExpr, ExprResult &RHS, SourceLocation Loc, QualType CompoundType, |
| 12617 | BinaryOperatorKind Opc); |
| 12618 | |
| 12619 | ExprResult checkPseudoObjectIncDec(Scope *S, SourceLocation OpLoc, |
| 12620 | UnaryOperatorKind Opcode, Expr *Op); |
| 12621 | ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, |
| 12622 | BinaryOperatorKind Opcode, |
| 12623 | Expr *LHS, Expr *RHS); |
| 12624 | ExprResult checkPseudoObjectRValue(Expr *E); |
| 12625 | Expr *recreateSyntacticForm(PseudoObjectExpr *E); |
| 12626 | |
| 12627 | QualType CheckConditionalOperands( // C99 6.5.15 |
| 12628 | ExprResult &Cond, ExprResult &LHS, ExprResult &RHS, |
| 12629 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation QuestionLoc); |
| 12630 | QualType CXXCheckConditionalOperands( // C++ 5.16 |
| 12631 | ExprResult &cond, ExprResult &lhs, ExprResult &rhs, |
| 12632 | ExprValueKind &VK, ExprObjectKind &OK, SourceLocation questionLoc); |
| 12633 | QualType CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS, |
| 12634 | ExprResult &RHS, |
| 12635 | SourceLocation QuestionLoc); |
| 12636 | |
| 12637 | QualType CheckSizelessVectorConditionalTypes(ExprResult &Cond, |
| 12638 | ExprResult &LHS, ExprResult &RHS, |
| 12639 | SourceLocation QuestionLoc); |
| 12640 | QualType FindCompositePointerType(SourceLocation Loc, Expr *&E1, Expr *&E2, |
| 12641 | bool ConvertArgs = true); |
| 12642 | QualType FindCompositePointerType(SourceLocation Loc, |
| 12643 | ExprResult &E1, ExprResult &E2, |
| 12644 | bool ConvertArgs = true) { |
| 12645 | Expr *E1Tmp = E1.get(), *E2Tmp = E2.get(); |
| 12646 | QualType Composite = |
| 12647 | FindCompositePointerType(Loc, E1Tmp, E2Tmp, ConvertArgs); |
| 12648 | E1 = E1Tmp; |
| 12649 | E2 = E2Tmp; |
| 12650 | return Composite; |
| 12651 | } |
| 12652 | |
| 12653 | QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, |
| 12654 | SourceLocation QuestionLoc); |
| 12655 | |
| 12656 | bool DiagnoseConditionalForNull(Expr *LHSExpr, Expr *RHSExpr, |
| 12657 | SourceLocation QuestionLoc); |
| 12658 | |
| 12659 | void DiagnoseAlwaysNonNullPointer(Expr *E, |
| 12660 | Expr::NullPointerConstantKind NullType, |
| 12661 | bool IsEqual, SourceRange Range); |
| 12662 | |
| 12663 | /// type checking for vector binary operators. |
| 12664 | QualType CheckVectorOperands(ExprResult &LHS, ExprResult &RHS, |
| 12665 | SourceLocation Loc, bool IsCompAssign, |
| 12666 | bool AllowBothBool, bool AllowBoolConversion, |
| 12667 | bool AllowBoolOperation, bool ReportInvalid); |
| 12668 | QualType GetSignedVectorType(QualType V); |
| 12669 | QualType GetSignedSizelessVectorType(QualType V); |
| 12670 | QualType CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
| 12671 | SourceLocation Loc, |
| 12672 | BinaryOperatorKind Opc); |
| 12673 | QualType CheckSizelessVectorCompareOperands(ExprResult &LHS, ExprResult &RHS, |
| 12674 | SourceLocation Loc, |
| 12675 | BinaryOperatorKind Opc); |
| 12676 | QualType CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, |
| 12677 | SourceLocation Loc); |
| 12678 | |
| 12679 | // type checking for sizeless vector binary operators. |
| 12680 | QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS, |
| 12681 | SourceLocation Loc, bool IsCompAssign, |
| 12682 | ArithConvKind OperationKind); |
| 12683 | |
| 12684 | /// Type checking for matrix binary operators. |
| 12685 | QualType CheckMatrixElementwiseOperands(ExprResult &LHS, ExprResult &RHS, |
| 12686 | SourceLocation Loc, |
| 12687 | bool IsCompAssign); |
| 12688 | QualType CheckMatrixMultiplyOperands(ExprResult &LHS, ExprResult &RHS, |
| 12689 | SourceLocation Loc, bool IsCompAssign); |
| 12690 | |
| 12691 | bool isValidSveBitcast(QualType srcType, QualType destType); |
| 12692 | bool isValidRVVBitcast(QualType srcType, QualType destType); |
| 12693 | |
| 12694 | bool areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy); |
| 12695 | |
| 12696 | bool areVectorTypesSameSize(QualType srcType, QualType destType); |
| 12697 | bool areLaxCompatibleVectorTypes(QualType srcType, QualType destType); |
| 12698 | bool isLaxVectorConversion(QualType srcType, QualType destType); |
| 12699 | bool anyAltivecTypes(QualType srcType, QualType destType); |
| 12700 | |
| 12701 | /// type checking declaration initializers (C99 6.7.8) |
| 12702 | bool CheckForConstantInitializer(Expr *e, QualType t); |
| 12703 | |
| 12704 | // type checking C++ declaration initializers (C++ [dcl.init]). |
| 12705 | |
| 12706 | /// ReferenceCompareResult - Expresses the result of comparing two |
| 12707 | /// types (cv1 T1 and cv2 T2) to determine their compatibility for the |
| 12708 | /// purposes of initialization by reference (C++ [dcl.init.ref]p4). |
| 12709 | enum ReferenceCompareResult { |
| 12710 | /// Ref_Incompatible - The two types are incompatible, so direct |
| 12711 | /// reference binding is not possible. |
| 12712 | Ref_Incompatible = 0, |
| 12713 | /// Ref_Related - The two types are reference-related, which means |
| 12714 | /// that their unqualified forms (T1 and T2) are either the same |
| 12715 | /// or T1 is a base class of T2. |
| 12716 | Ref_Related, |
| 12717 | /// Ref_Compatible - The two types are reference-compatible. |
| 12718 | Ref_Compatible |
| 12719 | }; |
| 12720 | |
| 12721 | // Fake up a scoped enumeration that still contextually converts to bool. |
| 12722 | struct ReferenceConversionsScope { |
| 12723 | /// The conversions that would be performed on an lvalue of type T2 when |
| 12724 | /// binding a reference of type T1 to it, as determined when evaluating |
| 12725 | /// whether T1 is reference-compatible with T2. |
| 12726 | enum ReferenceConversions { |
| 12727 | Qualification = 0x1, |
| 12728 | NestedQualification = 0x2, |
| 12729 | Function = 0x4, |
| 12730 | DerivedToBase = 0x8, |
| 12731 | ObjC = 0x10, |
| 12732 | ObjCLifetime = 0x20, |
| 12733 | |
| 12734 | LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue=*/ObjCLifetime)LLVM_BITMASK_LARGEST_ENUMERATOR = ObjCLifetime |
| 12735 | }; |
| 12736 | }; |
| 12737 | using ReferenceConversions = ReferenceConversionsScope::ReferenceConversions; |
| 12738 | |
| 12739 | ReferenceCompareResult |
| 12740 | CompareReferenceRelationship(SourceLocation Loc, QualType T1, QualType T2, |
| 12741 | ReferenceConversions *Conv = nullptr); |
| 12742 | |
| 12743 | ExprResult checkUnknownAnyCast(SourceRange TypeRange, QualType CastType, |
| 12744 | Expr *CastExpr, CastKind &CastKind, |
| 12745 | ExprValueKind &VK, CXXCastPath &Path); |
| 12746 | |
| 12747 | /// Force an expression with unknown-type to an expression of the |
| 12748 | /// given type. |
| 12749 | ExprResult forceUnknownAnyToType(Expr *E, QualType ToType); |
| 12750 | |
| 12751 | /// Type-check an expression that's being passed to an |
| 12752 | /// __unknown_anytype parameter. |
| 12753 | ExprResult checkUnknownAnyArg(SourceLocation callLoc, |
| 12754 | Expr *result, QualType ¶mType); |
| 12755 | |
| 12756 | // CheckMatrixCast - Check type constraints for matrix casts. |
| 12757 | // We allow casting between matrixes of the same dimensions i.e. when they |
| 12758 | // have the same number of rows and column. Returns true if the cast is |
| 12759 | // invalid. |
| 12760 | bool CheckMatrixCast(SourceRange R, QualType DestTy, QualType SrcTy, |
| 12761 | CastKind &Kind); |
| 12762 | |
| 12763 | // CheckVectorCast - check type constraints for vectors. |
| 12764 | // Since vectors are an extension, there are no C standard reference for this. |
| 12765 | // We allow casting between vectors and integer datatypes of the same size. |
| 12766 | // returns true if the cast is invalid |
| 12767 | bool CheckVectorCast(SourceRange R, QualType VectorTy, QualType Ty, |
| 12768 | CastKind &Kind); |
| 12769 | |
| 12770 | /// Prepare `SplattedExpr` for a vector splat operation, adding |
| 12771 | /// implicit casts if necessary. |
| 12772 | ExprResult prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr); |
| 12773 | |
| 12774 | // CheckExtVectorCast - check type constraints for extended vectors. |
| 12775 | // Since vectors are an extension, there are no C standard reference for this. |
| 12776 | // We allow casting between vectors and integer datatypes of the same size, |
| 12777 | // or vectors and the element type of that vector. |
| 12778 | // returns the cast expr |
| 12779 | ExprResult CheckExtVectorCast(SourceRange R, QualType DestTy, Expr *CastExpr, |
| 12780 | CastKind &Kind); |
| 12781 | |
| 12782 | ExprResult BuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, QualType Type, |
| 12783 | SourceLocation LParenLoc, |
| 12784 | Expr *CastExpr, |
| 12785 | SourceLocation RParenLoc); |
| 12786 | |
| 12787 | enum ARCConversionResult { ACR_okay, ACR_unbridged, ACR_error }; |
| 12788 | |
| 12789 | /// Checks for invalid conversions and casts between |
| 12790 | /// retainable pointers and other pointer kinds for ARC and Weak. |
| 12791 | ARCConversionResult CheckObjCConversion(SourceRange castRange, |
| 12792 | QualType castType, Expr *&op, |
| 12793 | CheckedConversionKind CCK, |
| 12794 | bool Diagnose = true, |
| 12795 | bool DiagnoseCFAudited = false, |
| 12796 | BinaryOperatorKind Opc = BO_PtrMemD |
| 12797 | ); |
| 12798 | |
| 12799 | Expr *stripARCUnbridgedCast(Expr *e); |
| 12800 | void diagnoseARCUnbridgedCast(Expr *e); |
| 12801 | |
| 12802 | bool CheckObjCARCUnavailableWeakConversion(QualType castType, |
| 12803 | QualType ExprType); |
| 12804 | |
| 12805 | /// checkRetainCycles - Check whether an Objective-C message send |
| 12806 | /// might create an obvious retain cycle. |
| 12807 | void checkRetainCycles(ObjCMessageExpr *msg); |
| 12808 | void checkRetainCycles(Expr *receiver, Expr *argument); |
| 12809 | void checkRetainCycles(VarDecl *Var, Expr *Init); |
| 12810 | |
| 12811 | /// checkUnsafeAssigns - Check whether +1 expr is being assigned |
| 12812 | /// to weak/__unsafe_unretained type. |
| 12813 | bool checkUnsafeAssigns(SourceLocation Loc, QualType LHS, Expr *RHS); |
| 12814 | |
| 12815 | /// checkUnsafeExprAssigns - Check whether +1 expr is being assigned |
| 12816 | /// to weak/__unsafe_unretained expression. |
| 12817 | void checkUnsafeExprAssigns(SourceLocation Loc, Expr *LHS, Expr *RHS); |
| 12818 | |
| 12819 | /// CheckMessageArgumentTypes - Check types in an Obj-C message send. |
| 12820 | /// \param Method - May be null. |
| 12821 | /// \param [out] ReturnType - The return type of the send. |
| 12822 | /// \return true iff there were any incompatible types. |
| 12823 | bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType, |
| 12824 | MultiExprArg Args, Selector Sel, |
| 12825 | ArrayRef<SourceLocation> SelectorLocs, |
| 12826 | ObjCMethodDecl *Method, bool isClassMessage, |
| 12827 | bool isSuperMessage, SourceLocation lbrac, |
| 12828 | SourceLocation rbrac, SourceRange RecRange, |
| 12829 | QualType &ReturnType, ExprValueKind &VK); |
| 12830 | |
| 12831 | /// Determine the result of a message send expression based on |
| 12832 | /// the type of the receiver, the method expected to receive the message, |
| 12833 | /// and the form of the message send. |
| 12834 | QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType, |
| 12835 | ObjCMethodDecl *Method, bool isClassMessage, |
| 12836 | bool isSuperMessage); |
| 12837 | |
| 12838 | /// If the given expression involves a message send to a method |
| 12839 | /// with a related result type, emit a note describing what happened. |
| 12840 | void EmitRelatedResultTypeNote(const Expr *E); |
| 12841 | |
| 12842 | /// Given that we had incompatible pointer types in a return |
| 12843 | /// statement, check whether we're in a method with a related result |
| 12844 | /// type, and if so, emit a note describing what happened. |
| 12845 | void EmitRelatedResultTypeNoteForReturn(QualType destType); |
| 12846 | |
| 12847 | class ConditionResult { |
| 12848 | Decl *ConditionVar; |
| 12849 | FullExprArg Condition; |
| 12850 | bool Invalid; |
| 12851 | std::optional<bool> KnownValue; |
| 12852 | |
| 12853 | friend class Sema; |
| 12854 | ConditionResult(Sema &S, Decl *ConditionVar, FullExprArg Condition, |
| 12855 | bool IsConstexpr) |
| 12856 | : ConditionVar(ConditionVar), Condition(Condition), Invalid(false) { |
| 12857 | if (IsConstexpr && Condition.get()) { |
| 12858 | if (std::optional<llvm::APSInt> Val = |
| 12859 | Condition.get()->getIntegerConstantExpr(S.Context)) { |
| 12860 | KnownValue = !!(*Val); |
| 12861 | } |
| 12862 | } |
| 12863 | } |
| 12864 | explicit ConditionResult(bool Invalid) |
| 12865 | : ConditionVar(nullptr), Condition(nullptr), Invalid(Invalid), |
| 12866 | KnownValue(std::nullopt) {} |
| 12867 | |
| 12868 | public: |
| 12869 | ConditionResult() : ConditionResult(false) {} |
| 12870 | bool isInvalid() const { return Invalid; } |
| 12871 | std::pair<VarDecl *, Expr *> get() const { |
| 12872 | return std::make_pair(cast_or_null<VarDecl>(ConditionVar), |
| 12873 | Condition.get()); |
| 12874 | } |
| 12875 | std::optional<bool> getKnownValue() const { return KnownValue; } |
| 12876 | }; |
| 12877 | static ConditionResult ConditionError() { return ConditionResult(true); } |
| 12878 | |
| 12879 | enum class ConditionKind { |
| 12880 | Boolean, ///< A boolean condition, from 'if', 'while', 'for', or 'do'. |
| 12881 | ConstexprIf, ///< A constant boolean condition from 'if constexpr'. |
| 12882 | Switch ///< An integral condition for a 'switch' statement. |
| 12883 | }; |
| 12884 | QualType PreferredConditionType(ConditionKind K) const { |
| 12885 | return K == ConditionKind::Switch ? Context.IntTy : Context.BoolTy; |
| 12886 | } |
| 12887 | |
| 12888 | ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, |
| 12889 | ConditionKind CK, bool MissingOK = false); |
| 12890 | |
| 12891 | ConditionResult ActOnConditionVariable(Decl *ConditionVar, |
| 12892 | SourceLocation StmtLoc, |
| 12893 | ConditionKind CK); |
| 12894 | |
| 12895 | DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D); |
| 12896 | |
| 12897 | ExprResult CheckConditionVariable(VarDecl *ConditionVar, |
| 12898 | SourceLocation StmtLoc, |
| 12899 | ConditionKind CK); |
| 12900 | ExprResult CheckSwitchCondition(SourceLocation SwitchLoc, Expr *Cond); |
| 12901 | |
| 12902 | /// CheckBooleanCondition - Diagnose problems involving the use of |
| 12903 | /// the given expression as a boolean condition (e.g. in an if |
| 12904 | /// statement). Also performs the standard function and array |
| 12905 | /// decays, possibly changing the input variable. |
| 12906 | /// |
| 12907 | /// \param Loc - A location associated with the condition, e.g. the |
| 12908 | /// 'if' keyword. |
| 12909 | /// \return true iff there were any errors |
| 12910 | ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, |
| 12911 | bool IsConstexpr = false); |
| 12912 | |
| 12913 | /// ActOnExplicitBoolSpecifier - Build an ExplicitSpecifier from an expression |
| 12914 | /// found in an explicit(bool) specifier. |
| 12915 | ExplicitSpecifier ActOnExplicitBoolSpecifier(Expr *E); |
| 12916 | |
| 12917 | /// tryResolveExplicitSpecifier - Attempt to resolve the explict specifier. |
| 12918 | /// Returns true if the explicit specifier is now resolved. |
| 12919 | bool tryResolveExplicitSpecifier(ExplicitSpecifier &ExplicitSpec); |
| 12920 | |
| 12921 | /// DiagnoseAssignmentAsCondition - Given that an expression is |
| 12922 | /// being used as a boolean condition, warn if it's an assignment. |
| 12923 | void DiagnoseAssignmentAsCondition(Expr *E); |
| 12924 | |
| 12925 | /// Redundant parentheses over an equality comparison can indicate |
| 12926 | /// that the user intended an assignment used as condition. |
| 12927 | void DiagnoseEqualityWithExtraParens(ParenExpr *ParenE); |
| 12928 | |
| 12929 | /// CheckCXXBooleanCondition - Returns true if conversion to bool is invalid. |
| 12930 | ExprResult CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr = false); |
| 12931 | |
| 12932 | /// ConvertIntegerToTypeWarnOnOverflow - Convert the specified APInt to have |
| 12933 | /// the specified width and sign. If an overflow occurs, detect it and emit |
| 12934 | /// the specified diagnostic. |
| 12935 | void ConvertIntegerToTypeWarnOnOverflow(llvm::APSInt &OldVal, |
| 12936 | unsigned NewWidth, bool NewSign, |
| 12937 | SourceLocation Loc, unsigned DiagID); |
| 12938 | |
| 12939 | /// Checks that the Objective-C declaration is declared in the global scope. |
| 12940 | /// Emits an error and marks the declaration as invalid if it's not declared |
| 12941 | /// in the global scope. |
| 12942 | bool CheckObjCDeclScope(Decl *D); |
| 12943 | |
| 12944 | /// Abstract base class used for diagnosing integer constant |
| 12945 | /// expression violations. |
| 12946 | class VerifyICEDiagnoser { |
| 12947 | public: |
| 12948 | bool Suppress; |
| 12949 | |
| 12950 | VerifyICEDiagnoser(bool Suppress = false) : Suppress(Suppress) { } |
| 12951 | |
| 12952 | virtual SemaDiagnosticBuilder |
| 12953 | diagnoseNotICEType(Sema &S, SourceLocation Loc, QualType T); |
| 12954 | virtual SemaDiagnosticBuilder diagnoseNotICE(Sema &S, |
| 12955 | SourceLocation Loc) = 0; |
| 12956 | virtual SemaDiagnosticBuilder diagnoseFold(Sema &S, SourceLocation Loc); |
| 12957 | virtual ~VerifyICEDiagnoser() {} |
| 12958 | }; |
| 12959 | |
| 12960 | enum AllowFoldKind { |
| 12961 | NoFold, |
| 12962 | AllowFold, |
| 12963 | }; |
| 12964 | |
| 12965 | /// VerifyIntegerConstantExpression - Verifies that an expression is an ICE, |
| 12966 | /// and reports the appropriate diagnostics. Returns false on success. |
| 12967 | /// Can optionally return the value of the expression. |
| 12968 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
| 12969 | VerifyICEDiagnoser &Diagnoser, |
| 12970 | AllowFoldKind CanFold = NoFold); |
| 12971 | ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, |
| 12972 | unsigned DiagID, |
| 12973 | AllowFoldKind CanFold = NoFold); |
| 12974 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
| 12975 | llvm::APSInt *Result = nullptr, |
| 12976 | AllowFoldKind CanFold = NoFold); |
| 12977 | ExprResult VerifyIntegerConstantExpression(Expr *E, |
| 12978 | AllowFoldKind CanFold = NoFold) { |
| 12979 | return VerifyIntegerConstantExpression(E, nullptr, CanFold); |
| 12980 | } |
| 12981 | |
| 12982 | /// VerifyBitField - verifies that a bit field expression is an ICE and has |
| 12983 | /// the correct width, and that the field type is valid. |
| 12984 | /// Returns false on success. |
| 12985 | ExprResult VerifyBitField(SourceLocation FieldLoc, IdentifierInfo *FieldName, |
| 12986 | QualType FieldTy, bool IsMsStruct, Expr *BitWidth); |
| 12987 | |
| 12988 | private: |
| 12989 | unsigned ForceCUDAHostDeviceDepth = 0; |
| 12990 | |
| 12991 | public: |
| 12992 | /// Increments our count of the number of times we've seen a pragma forcing |
| 12993 | /// functions to be __host__ __device__. So long as this count is greater |
| 12994 | /// than zero, all functions encountered will be __host__ __device__. |
| 12995 | void PushForceCUDAHostDevice(); |
| 12996 | |
| 12997 | /// Decrements our count of the number of times we've seen a pragma forcing |
| 12998 | /// functions to be __host__ __device__. Returns false if the count is 0 |
| 12999 | /// before incrementing, so you can emit an error. |
| 13000 | bool PopForceCUDAHostDevice(); |
| 13001 | |
| 13002 | /// Diagnostics that are emitted only if we discover that the given function |
| 13003 | /// must be codegen'ed. Because handling these correctly adds overhead to |
| 13004 | /// compilation, this is currently only enabled for CUDA compilations. |
| 13005 | llvm::DenseMap<CanonicalDeclPtr<const FunctionDecl>, |
| 13006 | std::vector<PartialDiagnosticAt>> |
| 13007 | DeviceDeferredDiags; |
| 13008 | |
| 13009 | /// A pair of a canonical FunctionDecl and a SourceLocation. When used as the |
| 13010 | /// key in a hashtable, both the FD and location are hashed. |
| 13011 | struct FunctionDeclAndLoc { |
| 13012 | CanonicalDeclPtr<const FunctionDecl> FD; |
| 13013 | SourceLocation Loc; |
| 13014 | }; |
| 13015 | |
| 13016 | /// FunctionDecls and SourceLocations for which CheckCUDACall has emitted a |
| 13017 | /// (maybe deferred) "bad call" diagnostic. We use this to avoid emitting the |
| 13018 | /// same deferred diag twice. |
| 13019 | llvm::DenseSet<FunctionDeclAndLoc> LocsWithCUDACallDiags; |
| 13020 | |
| 13021 | /// An inverse call graph, mapping known-emitted functions to one of their |
| 13022 | /// known-emitted callers (plus the location of the call). |
| 13023 | /// |
| 13024 | /// Functions that we can tell a priori must be emitted aren't added to this |
| 13025 | /// map. |
| 13026 | llvm::DenseMap</* Callee = */ CanonicalDeclPtr<const FunctionDecl>, |
| 13027 | /* Caller = */ FunctionDeclAndLoc> |
| 13028 | DeviceKnownEmittedFns; |
| 13029 | |
| 13030 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
| 13031 | /// context is "used as device code". |
| 13032 | /// |
| 13033 | /// - If CurContext is a __host__ function, does not emit any diagnostics |
| 13034 | /// unless \p EmitOnBothSides is true. |
| 13035 | /// - If CurContext is a __device__ or __global__ function, emits the |
| 13036 | /// diagnostics immediately. |
| 13037 | /// - If CurContext is a __host__ __device__ function and we are compiling for |
| 13038 | /// the device, creates a diagnostic which is emitted if and when we realize |
| 13039 | /// that the function will be codegen'ed. |
| 13040 | /// |
| 13041 | /// Example usage: |
| 13042 | /// |
| 13043 | /// // Variable-length arrays are not allowed in CUDA device code. |
| 13044 | /// if (CUDADiagIfDeviceCode(Loc, diag::err_cuda_vla) << CurrentCUDATarget()) |
| 13045 | /// return ExprError(); |
| 13046 | /// // Otherwise, continue parsing as normal. |
| 13047 | SemaDiagnosticBuilder CUDADiagIfDeviceCode(SourceLocation Loc, |
| 13048 | unsigned DiagID); |
| 13049 | |
| 13050 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
| 13051 | /// context is "used as host code". |
| 13052 | /// |
| 13053 | /// Same as CUDADiagIfDeviceCode, with "host" and "device" switched. |
| 13054 | SemaDiagnosticBuilder CUDADiagIfHostCode(SourceLocation Loc, unsigned DiagID); |
| 13055 | |
| 13056 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
| 13057 | /// context is "used as device code". |
| 13058 | /// |
| 13059 | /// - If CurContext is a `declare target` function or it is known that the |
| 13060 | /// function is emitted for the device, emits the diagnostics immediately. |
| 13061 | /// - If CurContext is a non-`declare target` function and we are compiling |
| 13062 | /// for the device, creates a diagnostic which is emitted if and when we |
| 13063 | /// realize that the function will be codegen'ed. |
| 13064 | /// |
| 13065 | /// Example usage: |
| 13066 | /// |
| 13067 | /// // Variable-length arrays are not allowed in NVPTX device code. |
| 13068 | /// if (diagIfOpenMPDeviceCode(Loc, diag::err_vla_unsupported)) |
| 13069 | /// return ExprError(); |
| 13070 | /// // Otherwise, continue parsing as normal. |
| 13071 | SemaDiagnosticBuilder diagIfOpenMPDeviceCode(SourceLocation Loc, |
| 13072 | unsigned DiagID, |
| 13073 | const FunctionDecl *FD); |
| 13074 | |
| 13075 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
| 13076 | /// context is "used as host code". |
| 13077 | /// |
| 13078 | /// - If CurContext is a `declare target` function or it is known that the |
| 13079 | /// function is emitted for the host, emits the diagnostics immediately. |
| 13080 | /// - If CurContext is a non-host function, just ignore it. |
| 13081 | /// |
| 13082 | /// Example usage: |
| 13083 | /// |
| 13084 | /// // Variable-length arrays are not allowed in NVPTX device code. |
| 13085 | /// if (diagIfOpenMPHostode(Loc, diag::err_vla_unsupported)) |
| 13086 | /// return ExprError(); |
| 13087 | /// // Otherwise, continue parsing as normal. |
| 13088 | SemaDiagnosticBuilder diagIfOpenMPHostCode(SourceLocation Loc, |
| 13089 | unsigned DiagID, |
| 13090 | const FunctionDecl *FD); |
| 13091 | |
| 13092 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, unsigned DiagID, |
| 13093 | const FunctionDecl *FD = nullptr); |
| 13094 | SemaDiagnosticBuilder targetDiag(SourceLocation Loc, |
| 13095 | const PartialDiagnostic &PD, |
| 13096 | const FunctionDecl *FD = nullptr) { |
| 13097 | return targetDiag(Loc, PD.getDiagID(), FD) << PD; |
| 13098 | } |
| 13099 | |
| 13100 | /// Check if the type is allowed to be used for the current target. |
| 13101 | void checkTypeSupport(QualType Ty, SourceLocation Loc, |
| 13102 | ValueDecl *D = nullptr); |
| 13103 | |
| 13104 | enum CUDAFunctionTarget { |
| 13105 | CFT_Device, |
| 13106 | CFT_Global, |
| 13107 | CFT_Host, |
| 13108 | CFT_HostDevice, |
| 13109 | CFT_InvalidTarget |
| 13110 | }; |
| 13111 | |
| 13112 | /// Determines whether the given function is a CUDA device/host/kernel/etc. |
| 13113 | /// function. |
| 13114 | /// |
| 13115 | /// Use this rather than examining the function's attributes yourself -- you |
| 13116 | /// will get it wrong. Returns CFT_Host if D is null. |
| 13117 | CUDAFunctionTarget IdentifyCUDATarget(const FunctionDecl *D, |
| 13118 | bool IgnoreImplicitHDAttr = false); |
| 13119 | CUDAFunctionTarget IdentifyCUDATarget(const ParsedAttributesView &Attrs); |
| 13120 | |
| 13121 | enum CUDAVariableTarget { |
| 13122 | CVT_Device, /// Emitted on device side with a shadow variable on host side |
| 13123 | CVT_Host, /// Emitted on host side only |
| 13124 | CVT_Both, /// Emitted on both sides with different addresses |
| 13125 | CVT_Unified, /// Emitted as a unified address, e.g. managed variables |
| 13126 | }; |
| 13127 | /// Determines whether the given variable is emitted on host or device side. |
| 13128 | CUDAVariableTarget IdentifyCUDATarget(const VarDecl *D); |
| 13129 | |
| 13130 | /// Gets the CUDA target for the current context. |
| 13131 | CUDAFunctionTarget CurrentCUDATarget() { |
| 13132 | return IdentifyCUDATarget(dyn_cast<FunctionDecl>(CurContext)); |
| 13133 | } |
| 13134 | |
| 13135 | static bool isCUDAImplicitHostDeviceFunction(const FunctionDecl *D); |
| 13136 | |
| 13137 | // CUDA function call preference. Must be ordered numerically from |
| 13138 | // worst to best. |
| 13139 | enum CUDAFunctionPreference { |
| 13140 | CFP_Never, // Invalid caller/callee combination. |
| 13141 | CFP_WrongSide, // Calls from host-device to host or device |
| 13142 | // function that do not match current compilation |
| 13143 | // mode. |
| 13144 | CFP_HostDevice, // Any calls to host/device functions. |
| 13145 | CFP_SameSide, // Calls from host-device to host or device |
| 13146 | // function matching current compilation mode. |
| 13147 | CFP_Native, // host-to-host or device-to-device calls. |
| 13148 | }; |
| 13149 | |
| 13150 | /// Identifies relative preference of a given Caller/Callee |
| 13151 | /// combination, based on their host/device attributes. |
| 13152 | /// \param Caller function which needs address of \p Callee. |
| 13153 | /// nullptr in case of global context. |
| 13154 | /// \param Callee target function |
| 13155 | /// |
| 13156 | /// \returns preference value for particular Caller/Callee combination. |
| 13157 | CUDAFunctionPreference IdentifyCUDAPreference(const FunctionDecl *Caller, |
| 13158 | const FunctionDecl *Callee); |
| 13159 | |
| 13160 | /// Determines whether Caller may invoke Callee, based on their CUDA |
| 13161 | /// host/device attributes. Returns false if the call is not allowed. |
| 13162 | /// |
| 13163 | /// Note: Will return true for CFP_WrongSide calls. These may appear in |
| 13164 | /// semantically correct CUDA programs, but only if they're never codegen'ed. |
| 13165 | bool IsAllowedCUDACall(const FunctionDecl *Caller, |
| 13166 | const FunctionDecl *Callee) { |
| 13167 | return IdentifyCUDAPreference(Caller, Callee) != CFP_Never; |
| 13168 | } |
| 13169 | |
| 13170 | /// May add implicit CUDAHostAttr and CUDADeviceAttr attributes to FD, |
| 13171 | /// depending on FD and the current compilation settings. |
| 13172 | void maybeAddCUDAHostDeviceAttrs(FunctionDecl *FD, |
| 13173 | const LookupResult &Previous); |
| 13174 | |
| 13175 | /// May add implicit CUDAConstantAttr attribute to VD, depending on VD |
| 13176 | /// and current compilation settings. |
| 13177 | void MaybeAddCUDAConstantAttr(VarDecl *VD); |
| 13178 | |
| 13179 | public: |
| 13180 | /// Check whether we're allowed to call Callee from the current context. |
| 13181 | /// |
| 13182 | /// - If the call is never allowed in a semantically-correct program |
| 13183 | /// (CFP_Never), emits an error and returns false. |
| 13184 | /// |
| 13185 | /// - If the call is allowed in semantically-correct programs, but only if |
| 13186 | /// it's never codegen'ed (CFP_WrongSide), creates a deferred diagnostic to |
| 13187 | /// be emitted if and when the caller is codegen'ed, and returns true. |
| 13188 | /// |
| 13189 | /// Will only create deferred diagnostics for a given SourceLocation once, |
| 13190 | /// so you can safely call this multiple times without generating duplicate |
| 13191 | /// deferred errors. |
| 13192 | /// |
| 13193 | /// - Otherwise, returns true without emitting any diagnostics. |
| 13194 | bool CheckCUDACall(SourceLocation Loc, FunctionDecl *Callee); |
| 13195 | |
| 13196 | void CUDACheckLambdaCapture(CXXMethodDecl *D, const sema::Capture &Capture); |
| 13197 | |
| 13198 | /// Set __device__ or __host__ __device__ attributes on the given lambda |
| 13199 | /// operator() method. |
| 13200 | /// |
| 13201 | /// CUDA lambdas by default is host device function unless it has explicit |
| 13202 | /// host or device attribute. |
| 13203 | void CUDASetLambdaAttrs(CXXMethodDecl *Method); |
| 13204 | |
| 13205 | /// Finds a function in \p Matches with highest calling priority |
| 13206 | /// from \p Caller context and erases all functions with lower |
| 13207 | /// calling priority. |
| 13208 | void EraseUnwantedCUDAMatches( |
| 13209 | const FunctionDecl *Caller, |
| 13210 | SmallVectorImpl<std::pair<DeclAccessPair, FunctionDecl *>> &Matches); |
| 13211 | |
| 13212 | /// Given a implicit special member, infer its CUDA target from the |
| 13213 | /// calls it needs to make to underlying base/field special members. |
| 13214 | /// \param ClassDecl the class for which the member is being created. |
| 13215 | /// \param CSM the kind of special member. |
| 13216 | /// \param MemberDecl the special member itself. |
| 13217 | /// \param ConstRHS true if this is a copy operation with a const object on |
| 13218 | /// its RHS. |
| 13219 | /// \param Diagnose true if this call should emit diagnostics. |
| 13220 | /// \return true if there was an error inferring. |
| 13221 | /// The result of this call is implicit CUDA target attribute(s) attached to |
| 13222 | /// the member declaration. |
| 13223 | bool inferCUDATargetForImplicitSpecialMember(CXXRecordDecl *ClassDecl, |
| 13224 | CXXSpecialMember CSM, |
| 13225 | CXXMethodDecl *MemberDecl, |
| 13226 | bool ConstRHS, |
| 13227 | bool Diagnose); |
| 13228 | |
| 13229 | /// \return true if \p CD can be considered empty according to CUDA |
| 13230 | /// (E.2.3.1 in CUDA 7.5 Programming guide). |
| 13231 | bool isEmptyCudaConstructor(SourceLocation Loc, CXXConstructorDecl *CD); |
| 13232 | bool isEmptyCudaDestructor(SourceLocation Loc, CXXDestructorDecl *CD); |
| 13233 | |
| 13234 | // \brief Checks that initializers of \p Var satisfy CUDA restrictions. In |
| 13235 | // case of error emits appropriate diagnostic and invalidates \p Var. |
| 13236 | // |
| 13237 | // \details CUDA allows only empty constructors as initializers for global |
| 13238 | // variables (see E.2.3.1, CUDA 7.5). The same restriction also applies to all |
| 13239 | // __shared__ variables whether they are local or not (they all are implicitly |
| 13240 | // static in CUDA). One exception is that CUDA allows constant initializers |
| 13241 | // for __constant__ and __device__ variables. |
| 13242 | void checkAllowedCUDAInitializer(VarDecl *VD); |
| 13243 | |
| 13244 | /// Check whether NewFD is a valid overload for CUDA. Emits |
| 13245 | /// diagnostics and invalidates NewFD if not. |
| 13246 | void checkCUDATargetOverload(FunctionDecl *NewFD, |
| 13247 | const LookupResult &Previous); |
| 13248 | /// Copies target attributes from the template TD to the function FD. |
| 13249 | void inheritCUDATargetAttrs(FunctionDecl *FD, const FunctionTemplateDecl &TD); |
| 13250 | |
| 13251 | /// Returns the name of the launch configuration function. This is the name |
| 13252 | /// of the function that will be called to configure kernel call, with the |
| 13253 | /// parameters specified via <<<>>>. |
| 13254 | std::string getCudaConfigureFuncName() const; |
| 13255 | |
| 13256 | /// \name Code completion |
| 13257 | //@{ |
| 13258 | /// Describes the context in which code completion occurs. |
| 13259 | enum ParserCompletionContext { |
| 13260 | /// Code completion occurs at top-level or namespace context. |
| 13261 | PCC_Namespace, |
| 13262 | /// Code completion occurs within a class, struct, or union. |
| 13263 | PCC_Class, |
| 13264 | /// Code completion occurs within an Objective-C interface, protocol, |
| 13265 | /// or category. |
| 13266 | PCC_ObjCInterface, |
| 13267 | /// Code completion occurs within an Objective-C implementation or |
| 13268 | /// category implementation |
| 13269 | PCC_ObjCImplementation, |
| 13270 | /// Code completion occurs within the list of instance variables |
| 13271 | /// in an Objective-C interface, protocol, category, or implementation. |
| 13272 | PCC_ObjCInstanceVariableList, |
| 13273 | /// Code completion occurs following one or more template |
| 13274 | /// headers. |
| 13275 | PCC_Template, |
| 13276 | /// Code completion occurs following one or more template |
| 13277 | /// headers within a class. |
| 13278 | PCC_MemberTemplate, |
| 13279 | /// Code completion occurs within an expression. |
| 13280 | PCC_Expression, |
| 13281 | /// Code completion occurs within a statement, which may |
| 13282 | /// also be an expression or a declaration. |
| 13283 | PCC_Statement, |
| 13284 | /// Code completion occurs at the beginning of the |
| 13285 | /// initialization statement (or expression) in a for loop. |
| 13286 | PCC_ForInit, |
| 13287 | /// Code completion occurs within the condition of an if, |
| 13288 | /// while, switch, or for statement. |
| 13289 | PCC_Condition, |
| 13290 | /// Code completion occurs within the body of a function on a |
| 13291 | /// recovery path, where we do not have a specific handle on our position |
| 13292 | /// in the grammar. |
| 13293 | PCC_RecoveryInFunction, |
| 13294 | /// Code completion occurs where only a type is permitted. |
| 13295 | PCC_Type, |
| 13296 | /// Code completion occurs in a parenthesized expression, which |
| 13297 | /// might also be a type cast. |
| 13298 | PCC_ParenthesizedExpression, |
| 13299 | /// Code completion occurs within a sequence of declaration |
| 13300 | /// specifiers within a function, method, or block. |
| 13301 | PCC_LocalDeclarationSpecifiers |
| 13302 | }; |
| 13303 | |
| 13304 | void CodeCompleteModuleImport(SourceLocation ImportLoc, ModuleIdPath Path); |
| 13305 | void CodeCompleteOrdinaryName(Scope *S, |
| 13306 | ParserCompletionContext CompletionContext); |
| 13307 | void CodeCompleteDeclSpec(Scope *S, DeclSpec &DS, |
| 13308 | bool AllowNonIdentifiers, |
| 13309 | bool AllowNestedNameSpecifiers); |
| 13310 | |
| 13311 | struct CodeCompleteExpressionData; |
| 13312 | void CodeCompleteExpression(Scope *S, |
| 13313 | const CodeCompleteExpressionData &Data); |
| 13314 | void CodeCompleteExpression(Scope *S, QualType PreferredType, |
| 13315 | bool IsParenthesized = false); |
| 13316 | void CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base, Expr *OtherOpBase, |
| 13317 | SourceLocation OpLoc, bool IsArrow, |
| 13318 | bool IsBaseExprStatement, |
| 13319 | QualType PreferredType); |
| 13320 | void CodeCompletePostfixExpression(Scope *S, ExprResult LHS, |
| 13321 | QualType PreferredType); |
| 13322 | void CodeCompleteTag(Scope *S, unsigned TagSpec); |
| 13323 | void CodeCompleteTypeQualifiers(DeclSpec &DS); |
| 13324 | void CodeCompleteFunctionQualifiers(DeclSpec &DS, Declarator &D, |
| 13325 | const VirtSpecifiers *VS = nullptr); |
| 13326 | void CodeCompleteBracketDeclarator(Scope *S); |
| 13327 | void CodeCompleteCase(Scope *S); |
| 13328 | enum class AttributeCompletion { |
| 13329 | Attribute, |
| 13330 | Scope, |
| 13331 | None, |
| 13332 | }; |
| 13333 | void CodeCompleteAttribute( |
| 13334 | AttributeCommonInfo::Syntax Syntax, |
| 13335 | AttributeCompletion Completion = AttributeCompletion::Attribute, |
| 13336 | const IdentifierInfo *Scope = nullptr); |
| 13337 | /// Determines the preferred type of the current function argument, by |
| 13338 | /// examining the signatures of all possible overloads. |
| 13339 | /// Returns null if unknown or ambiguous, or if code completion is off. |
| 13340 | /// |
| 13341 | /// If the code completion point has been reached, also reports the function |
| 13342 | /// signatures that were considered. |
| 13343 | /// |
| 13344 | /// FIXME: rename to GuessCallArgumentType to reduce confusion. |
| 13345 | QualType ProduceCallSignatureHelp(Expr *Fn, ArrayRef<Expr *> Args, |
| 13346 | SourceLocation OpenParLoc); |
| 13347 | QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, |
| 13348 | ArrayRef<Expr *> Args, |
| 13349 | SourceLocation OpenParLoc, |
| 13350 | bool Braced); |
| 13351 | QualType ProduceCtorInitMemberSignatureHelp( |
| 13352 | Decl *ConstructorDecl, CXXScopeSpec SS, ParsedType TemplateTypeTy, |
| 13353 | ArrayRef<Expr *> ArgExprs, IdentifierInfo *II, SourceLocation OpenParLoc, |
| 13354 | bool Braced); |
| 13355 | QualType ProduceTemplateArgumentSignatureHelp( |
| 13356 | TemplateTy, ArrayRef<ParsedTemplateArgument>, SourceLocation LAngleLoc); |
| 13357 | void CodeCompleteInitializer(Scope *S, Decl *D); |
| 13358 | /// Trigger code completion for a record of \p BaseType. \p InitExprs are |
| 13359 | /// expressions in the initializer list seen so far and \p D is the current |
| 13360 | /// Designation being parsed. |
| 13361 | void CodeCompleteDesignator(const QualType BaseType, |
| 13362 | llvm::ArrayRef<Expr *> InitExprs, |
| 13363 | const Designation &D); |
| 13364 | void CodeCompleteAfterIf(Scope *S, bool IsBracedThen); |
| 13365 | |
| 13366 | void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, |
| 13367 | bool IsUsingDeclaration, QualType BaseType, |
| 13368 | QualType PreferredType); |
| 13369 | void CodeCompleteUsing(Scope *S); |
| 13370 | void CodeCompleteUsingDirective(Scope *S); |
| 13371 | void CodeCompleteNamespaceDecl(Scope *S); |
| 13372 | void CodeCompleteNamespaceAliasDecl(Scope *S); |
| 13373 | void CodeCompleteOperatorName(Scope *S); |
| 13374 | void CodeCompleteConstructorInitializer( |
| 13375 | Decl *Constructor, |
| 13376 | ArrayRef<CXXCtorInitializer *> Initializers); |
| 13377 | |
| 13378 | void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, |
| 13379 | bool AfterAmpersand); |
| 13380 | void CodeCompleteAfterFunctionEquals(Declarator &D); |
| 13381 | |
| 13382 | void CodeCompleteObjCAtDirective(Scope *S); |
| 13383 | void CodeCompleteObjCAtVisibility(Scope *S); |
| 13384 | void CodeCompleteObjCAtStatement(Scope *S); |
| 13385 | void CodeCompleteObjCAtExpression(Scope *S); |
| 13386 | void CodeCompleteObjCPropertyFlags(Scope *S, ObjCDeclSpec &ODS); |
| 13387 | void CodeCompleteObjCPropertyGetter(Scope *S); |
| 13388 | void CodeCompleteObjCPropertySetter(Scope *S); |
| 13389 | void CodeCompleteObjCPassingType(Scope *S, ObjCDeclSpec &DS, |
| 13390 | bool IsParameter); |
| 13391 | void CodeCompleteObjCMessageReceiver(Scope *S); |
| 13392 | void CodeCompleteObjCSuperMessage(Scope *S, SourceLocation SuperLoc, |
| 13393 | ArrayRef<IdentifierInfo *> SelIdents, |
| 13394 | bool AtArgumentExpression); |
| 13395 | void CodeCompleteObjCClassMessage(Scope *S, ParsedType Receiver, |
| 13396 | ArrayRef<IdentifierInfo *> SelIdents, |
| 13397 | bool AtArgumentExpression, |
| 13398 | bool IsSuper = false); |
| 13399 | void CodeCompleteObjCInstanceMessage(Scope *S, Expr *Receiver, |
| 13400 | ArrayRef<IdentifierInfo *> SelIdents, |
| 13401 | bool AtArgumentExpression, |
| 13402 | ObjCInterfaceDecl *Super = nullptr); |
| 13403 | void CodeCompleteObjCForCollection(Scope *S, |
| 13404 | DeclGroupPtrTy IterationVar); |
| 13405 | void CodeCompleteObjCSelector(Scope *S, |
| 13406 | ArrayRef<IdentifierInfo *> SelIdents); |
| 13407 | void CodeCompleteObjCProtocolReferences( |
| 13408 | ArrayRef<IdentifierLocPair> Protocols); |
| 13409 | void CodeCompleteObjCProtocolDecl(Scope *S); |
| 13410 | void CodeCompleteObjCInterfaceDecl(Scope *S); |
| 13411 | void CodeCompleteObjCSuperclass(Scope *S, |
| 13412 | IdentifierInfo *ClassName, |
| 13413 | SourceLocation ClassNameLoc); |
| 13414 | void CodeCompleteObjCImplementationDecl(Scope *S); |
| 13415 | void CodeCompleteObjCInterfaceCategory(Scope *S, |
| 13416 | IdentifierInfo *ClassName, |
| 13417 | SourceLocation ClassNameLoc); |
| 13418 | void CodeCompleteObjCImplementationCategory(Scope *S, |
| 13419 | IdentifierInfo *ClassName, |
| 13420 | SourceLocation ClassNameLoc); |
| 13421 | void CodeCompleteObjCPropertyDefinition(Scope *S); |
| 13422 | void CodeCompleteObjCPropertySynthesizeIvar(Scope *S, |
| 13423 | IdentifierInfo *PropertyName); |
| 13424 | void CodeCompleteObjCMethodDecl(Scope *S, |
| 13425 | std::optional<bool> IsInstanceMethod, |
| 13426 | ParsedType ReturnType); |
| 13427 | void CodeCompleteObjCMethodDeclSelector(Scope *S, |
| 13428 | bool IsInstanceMethod, |
| 13429 | bool AtParameterName, |
| 13430 | ParsedType ReturnType, |
| 13431 | ArrayRef<IdentifierInfo *> SelIdents); |
| 13432 | void CodeCompleteObjCClassPropertyRefExpr(Scope *S, IdentifierInfo &ClassName, |
| 13433 | SourceLocation ClassNameLoc, |
| 13434 | bool IsBaseExprStatement); |
| 13435 | void CodeCompletePreprocessorDirective(bool InConditional); |
| 13436 | void CodeCompleteInPreprocessorConditionalExclusion(Scope *S); |
| 13437 | void CodeCompletePreprocessorMacroName(bool IsDefinition); |
| 13438 | void CodeCompletePreprocessorExpression(); |
| 13439 | void CodeCompletePreprocessorMacroArgument(Scope *S, |
| 13440 | IdentifierInfo *Macro, |
| 13441 | MacroInfo *MacroInfo, |
| 13442 | unsigned Argument); |
| 13443 | void CodeCompleteIncludedFile(llvm::StringRef Dir, bool IsAngled); |
| 13444 | void CodeCompleteNaturalLanguage(); |
| 13445 | void CodeCompleteAvailabilityPlatformName(); |
| 13446 | void GatherGlobalCodeCompletions(CodeCompletionAllocator &Allocator, |
| 13447 | CodeCompletionTUInfo &CCTUInfo, |
| 13448 | SmallVectorImpl<CodeCompletionResult> &Results); |
| 13449 | //@} |
| 13450 | |
| 13451 | //===--------------------------------------------------------------------===// |
| 13452 | // Extra semantic analysis beyond the C type system |
| 13453 | |
| 13454 | public: |
| 13455 | SourceLocation getLocationOfStringLiteralByte(const StringLiteral *SL, |
| 13456 | unsigned ByteNo) const; |
| 13457 | |
| 13458 | enum FormatArgumentPassingKind { |
| 13459 | FAPK_Fixed, // values to format are fixed (no C-style variadic arguments) |
| 13460 | FAPK_Variadic, // values to format are passed as variadic arguments |
| 13461 | FAPK_VAList, // values to format are passed in a va_list |
| 13462 | }; |
| 13463 | |
| 13464 | // Used to grab the relevant information from a FormatAttr and a |
| 13465 | // FunctionDeclaration. |
| 13466 | struct FormatStringInfo { |
| 13467 | unsigned FormatIdx; |
| 13468 | unsigned FirstDataArg; |
| 13469 | FormatArgumentPassingKind ArgPassingKind; |
| 13470 | }; |
| 13471 | |
| 13472 | static bool getFormatStringInfo(const FormatAttr *Format, bool IsCXXMember, |
| 13473 | bool IsVariadic, FormatStringInfo *FSI); |
| 13474 | |
| 13475 | private: |
| 13476 | void CheckArrayAccess(const Expr *BaseExpr, const Expr *IndexExpr, |
| 13477 | const ArraySubscriptExpr *ASE = nullptr, |
| 13478 | bool AllowOnePastEnd = true, bool IndexNegated = false); |
| 13479 | void CheckArrayAccess(const Expr *E); |
| 13480 | |
| 13481 | bool CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, |
| 13482 | const FunctionProtoType *Proto); |
| 13483 | bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, |
| 13484 | ArrayRef<const Expr *> Args); |
| 13485 | bool CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall, |
| 13486 | const FunctionProtoType *Proto); |
| 13487 | bool CheckOtherCall(CallExpr *TheCall, const FunctionProtoType *Proto); |
| 13488 | void CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType, |
| 13489 | ArrayRef<const Expr *> Args, |
| 13490 | const FunctionProtoType *Proto, SourceLocation Loc); |
| 13491 | |
| 13492 | void checkAIXMemberAlignment(SourceLocation Loc, const Expr *Arg); |
| 13493 | |
| 13494 | void CheckArgAlignment(SourceLocation Loc, NamedDecl *FDecl, |
| 13495 | StringRef ParamName, QualType ArgTy, QualType ParamTy); |
| 13496 | |
| 13497 | void checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto, |
| 13498 | const Expr *ThisArg, ArrayRef<const Expr *> Args, |
| 13499 | bool IsMemberFunction, SourceLocation Loc, SourceRange Range, |
| 13500 | VariadicCallType CallType); |
| 13501 | |
| 13502 | bool CheckObjCString(Expr *Arg); |
| 13503 | ExprResult CheckOSLogFormatStringArg(Expr *Arg); |
| 13504 | |
| 13505 | ExprResult CheckBuiltinFunctionCall(FunctionDecl *FDecl, |
| 13506 | unsigned BuiltinID, CallExpr *TheCall); |
| 13507 | |
| 13508 | bool CheckTSBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 13509 | CallExpr *TheCall); |
| 13510 | |
| 13511 | void checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD, CallExpr *TheCall); |
| 13512 | |
| 13513 | bool CheckARMBuiltinExclusiveCall(unsigned BuiltinID, CallExpr *TheCall, |
| 13514 | unsigned MaxWidth); |
| 13515 | bool CheckNeonBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 13516 | CallExpr *TheCall); |
| 13517 | bool CheckMVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
| 13518 | bool CheckSVEBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
| 13519 | bool CheckCDEBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 13520 | CallExpr *TheCall); |
| 13521 | bool CheckARMCoprocessorImmediate(const TargetInfo &TI, const Expr *CoprocArg, |
| 13522 | bool WantCDE); |
| 13523 | bool CheckARMBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 13524 | CallExpr *TheCall); |
| 13525 | |
| 13526 | bool CheckAArch64BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 13527 | CallExpr *TheCall); |
| 13528 | bool CheckBPFBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
| 13529 | bool CheckHexagonBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
| 13530 | bool CheckHexagonBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
| 13531 | bool CheckMipsBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 13532 | CallExpr *TheCall); |
| 13533 | bool CheckMipsBuiltinCpu(const TargetInfo &TI, unsigned BuiltinID, |
| 13534 | CallExpr *TheCall); |
| 13535 | bool CheckMipsBuiltinArgument(unsigned BuiltinID, CallExpr *TheCall); |
| 13536 | bool CheckSystemZBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
| 13537 | bool CheckX86BuiltinRoundingOrSAE(unsigned BuiltinID, CallExpr *TheCall); |
| 13538 | bool CheckX86BuiltinGatherScatterScale(unsigned BuiltinID, CallExpr *TheCall); |
| 13539 | bool CheckX86BuiltinTileArguments(unsigned BuiltinID, CallExpr *TheCall); |
| 13540 | bool CheckX86BuiltinTileArgumentsRange(CallExpr *TheCall, |
| 13541 | ArrayRef<int> ArgNums); |
| 13542 | bool CheckX86BuiltinTileDuplicate(CallExpr *TheCall, ArrayRef<int> ArgNums); |
| 13543 | bool CheckX86BuiltinTileRangeAndDuplicate(CallExpr *TheCall, |
| 13544 | ArrayRef<int> ArgNums); |
| 13545 | bool CheckX86BuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 13546 | CallExpr *TheCall); |
| 13547 | bool CheckPPCBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 13548 | CallExpr *TheCall); |
| 13549 | bool CheckAMDGCNBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall); |
| 13550 | bool CheckRISCVLMUL(CallExpr *TheCall, unsigned ArgNum); |
| 13551 | bool CheckRISCVBuiltinFunctionCall(const TargetInfo &TI, unsigned BuiltinID, |
| 13552 | CallExpr *TheCall); |
| 13553 | bool CheckLoongArchBuiltinFunctionCall(const TargetInfo &TI, |
| 13554 | unsigned BuiltinID, CallExpr *TheCall); |
| 13555 | bool CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI, |
| 13556 | unsigned BuiltinID, |
| 13557 | CallExpr *TheCall); |
| 13558 | |
| 13559 | bool SemaBuiltinVAStart(unsigned BuiltinID, CallExpr *TheCall); |
| 13560 | bool SemaBuiltinVAStartARMMicrosoft(CallExpr *Call); |
| 13561 | bool SemaBuiltinUnorderedCompare(CallExpr *TheCall); |
| 13562 | bool SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs); |
| 13563 | bool SemaBuiltinComplex(CallExpr *TheCall); |
| 13564 | bool SemaBuiltinVSX(CallExpr *TheCall); |
| 13565 | bool SemaBuiltinOSLogFormat(CallExpr *TheCall); |
| 13566 | bool SemaValueIsRunOfOnes(CallExpr *TheCall, unsigned ArgNum); |
| 13567 | |
| 13568 | public: |
| 13569 | // Used by C++ template instantiation. |
| 13570 | ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall); |
| 13571 | ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, |
| 13572 | SourceLocation BuiltinLoc, |
| 13573 | SourceLocation RParenLoc); |
| 13574 | |
| 13575 | private: |
| 13576 | bool SemaBuiltinPrefetch(CallExpr *TheCall); |
| 13577 | bool SemaBuiltinAllocaWithAlign(CallExpr *TheCall); |
| 13578 | bool SemaBuiltinArithmeticFence(CallExpr *TheCall); |
| 13579 | bool SemaBuiltinAssume(CallExpr *TheCall); |
| 13580 | bool SemaBuiltinAssumeAligned(CallExpr *TheCall); |
| 13581 | bool SemaBuiltinLongjmp(CallExpr *TheCall); |
| 13582 | bool SemaBuiltinSetjmp(CallExpr *TheCall); |
| 13583 | ExprResult SemaBuiltinAtomicOverloaded(ExprResult TheCallResult); |
| 13584 | ExprResult SemaBuiltinNontemporalOverloaded(ExprResult TheCallResult); |
| 13585 | ExprResult SemaAtomicOpsOverloaded(ExprResult TheCallResult, |
| 13586 | AtomicExpr::AtomicOp Op); |
| 13587 | ExprResult SemaBuiltinOperatorNewDeleteOverloaded(ExprResult TheCallResult, |
| 13588 | bool IsDelete); |
| 13589 | bool SemaBuiltinConstantArg(CallExpr *TheCall, int ArgNum, |
| 13590 | llvm::APSInt &Result); |
| 13591 | bool SemaBuiltinConstantArgRange(CallExpr *TheCall, int ArgNum, int Low, |
| 13592 | int High, bool RangeIsError = true); |
| 13593 | bool SemaBuiltinConstantArgMultiple(CallExpr *TheCall, int ArgNum, |
| 13594 | unsigned Multiple); |
| 13595 | bool SemaBuiltinConstantArgPower2(CallExpr *TheCall, int ArgNum); |
| 13596 | bool SemaBuiltinConstantArgShiftedByte(CallExpr *TheCall, int ArgNum, |
| 13597 | unsigned ArgBits); |
| 13598 | bool SemaBuiltinConstantArgShiftedByteOrXXFF(CallExpr *TheCall, int ArgNum, |
| 13599 | unsigned ArgBits); |
| 13600 | bool SemaBuiltinARMSpecialReg(unsigned BuiltinID, CallExpr *TheCall, |
| 13601 | int ArgNum, unsigned ExpectedFieldNum, |
| 13602 | bool AllowName); |
| 13603 | bool SemaBuiltinARMMemoryTaggingCall(unsigned BuiltinID, CallExpr *TheCall); |
| 13604 | bool SemaBuiltinPPCMMACall(CallExpr *TheCall, unsigned BuiltinID, |
| 13605 | const char *TypeDesc); |
| 13606 | |
| 13607 | bool CheckPPCMMAType(QualType Type, SourceLocation TypeLoc); |
| 13608 | |
| 13609 | bool SemaBuiltinElementwiseMath(CallExpr *TheCall); |
| 13610 | bool SemaBuiltinElementwiseTernaryMath(CallExpr *TheCall); |
| 13611 | bool PrepareBuiltinElementwiseMathOneArgCall(CallExpr *TheCall); |
| 13612 | bool PrepareBuiltinReduceMathOneArgCall(CallExpr *TheCall); |
| 13613 | |
| 13614 | bool SemaBuiltinNonDeterministicValue(CallExpr *TheCall); |
| 13615 | |
| 13616 | // Matrix builtin handling. |
| 13617 | ExprResult SemaBuiltinMatrixTranspose(CallExpr *TheCall, |
| 13618 | ExprResult CallResult); |
| 13619 | ExprResult SemaBuiltinMatrixColumnMajorLoad(CallExpr *TheCall, |
| 13620 | ExprResult CallResult); |
| 13621 | ExprResult SemaBuiltinMatrixColumnMajorStore(CallExpr *TheCall, |
| 13622 | ExprResult CallResult); |
| 13623 | |
| 13624 | // WebAssembly builtin handling. |
| 13625 | bool BuiltinWasmRefNullExtern(CallExpr *TheCall); |
| 13626 | bool BuiltinWasmRefNullFunc(CallExpr *TheCall); |
| 13627 | |
| 13628 | public: |
| 13629 | enum FormatStringType { |
| 13630 | FST_Scanf, |
| 13631 | FST_Printf, |
| 13632 | FST_NSString, |
| 13633 | FST_Strftime, |
| 13634 | FST_Strfmon, |
| 13635 | FST_Kprintf, |
| 13636 | FST_FreeBSDKPrintf, |
| 13637 | FST_OSTrace, |
| 13638 | FST_OSLog, |
| 13639 | FST_Unknown |
| 13640 | }; |
| 13641 | static FormatStringType GetFormatStringType(const FormatAttr *Format); |
| 13642 | |
| 13643 | bool FormatStringHasSArg(const StringLiteral *FExpr); |
| 13644 | |
| 13645 | static bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx); |
| 13646 | |
| 13647 | private: |
| 13648 | bool CheckFormatArguments(const FormatAttr *Format, |
| 13649 | ArrayRef<const Expr *> Args, bool IsCXXMember, |
| 13650 | VariadicCallType CallType, SourceLocation Loc, |
| 13651 | SourceRange Range, |
| 13652 | llvm::SmallBitVector &CheckedVarArgs); |
| 13653 | bool CheckFormatArguments(ArrayRef<const Expr *> Args, |
| 13654 | FormatArgumentPassingKind FAPK, unsigned format_idx, |
| 13655 | unsigned firstDataArg, FormatStringType Type, |
| 13656 | VariadicCallType CallType, SourceLocation Loc, |
| 13657 | SourceRange range, |
| 13658 | llvm::SmallBitVector &CheckedVarArgs); |
| 13659 | |
| 13660 | void CheckAbsoluteValueFunction(const CallExpr *Call, |
| 13661 | const FunctionDecl *FDecl); |
| 13662 | |
| 13663 | void CheckMaxUnsignedZero(const CallExpr *Call, const FunctionDecl *FDecl); |
| 13664 | |
| 13665 | void CheckMemaccessArguments(const CallExpr *Call, |
| 13666 | unsigned BId, |
| 13667 | IdentifierInfo *FnName); |
| 13668 | |
| 13669 | void CheckStrlcpycatArguments(const CallExpr *Call, |
| 13670 | IdentifierInfo *FnName); |
| 13671 | |
| 13672 | void CheckStrncatArguments(const CallExpr *Call, |
| 13673 | IdentifierInfo *FnName); |
| 13674 | |
| 13675 | void CheckFreeArguments(const CallExpr *E); |
| 13676 | |
| 13677 | void CheckReturnValExpr(Expr *RetValExp, QualType lhsType, |
| 13678 | SourceLocation ReturnLoc, |
| 13679 | bool isObjCMethod = false, |
| 13680 | const AttrVec *Attrs = nullptr, |
| 13681 | const FunctionDecl *FD = nullptr); |
| 13682 | |
| 13683 | public: |
| 13684 | void CheckFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS, |
| 13685 | BinaryOperatorKind Opcode); |
| 13686 | |
| 13687 | private: |
| 13688 | void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation()); |
| 13689 | void CheckBoolLikeConversion(Expr *E, SourceLocation CC); |
| 13690 | void CheckForIntOverflow(Expr *E); |
| 13691 | void CheckUnsequencedOperations(const Expr *E); |
| 13692 | |
| 13693 | /// Perform semantic checks on a completed expression. This will either |
| 13694 | /// be a full-expression or a default argument expression. |
| 13695 | void CheckCompletedExpr(Expr *E, SourceLocation CheckLoc = SourceLocation(), |
| 13696 | bool IsConstexpr = false); |
| 13697 | |
| 13698 | void CheckBitFieldInitialization(SourceLocation InitLoc, FieldDecl *Field, |
| 13699 | Expr *Init); |
| 13700 | |
| 13701 | /// Check if there is a field shadowing. |
| 13702 | void CheckShadowInheritedFields(const SourceLocation &Loc, |
| 13703 | DeclarationName FieldName, |
| 13704 | const CXXRecordDecl *RD, |
| 13705 | bool DeclIsField = true); |
| 13706 | |
| 13707 | /// Check if the given expression contains 'break' or 'continue' |
| 13708 | /// statement that produces control flow different from GCC. |
| 13709 | void CheckBreakContinueBinding(Expr *E); |
| 13710 | |
| 13711 | /// Check whether receiver is mutable ObjC container which |
| 13712 | /// attempts to add itself into the container |
| 13713 | void CheckObjCCircularContainer(ObjCMessageExpr *Message); |
| 13714 | |
| 13715 | void CheckTCBEnforcement(const SourceLocation CallExprLoc, |
| 13716 | const NamedDecl *Callee); |
| 13717 | |
| 13718 | void AnalyzeDeleteExprMismatch(const CXXDeleteExpr *DE); |
| 13719 | void AnalyzeDeleteExprMismatch(FieldDecl *Field, SourceLocation DeleteLoc, |
| 13720 | bool DeleteWasArrayForm); |
| 13721 | public: |
| 13722 | /// Register a magic integral constant to be used as a type tag. |
| 13723 | void RegisterTypeTagForDatatype(const IdentifierInfo *ArgumentKind, |
| 13724 | uint64_t MagicValue, QualType Type, |
| 13725 | bool LayoutCompatible, bool MustBeNull); |
| 13726 | |
| 13727 | struct TypeTagData { |
| 13728 | TypeTagData() {} |
| 13729 | |
| 13730 | TypeTagData(QualType Type, bool LayoutCompatible, bool MustBeNull) : |
| 13731 | Type(Type), LayoutCompatible(LayoutCompatible), |
| 13732 | MustBeNull(MustBeNull) |
| 13733 | {} |
| 13734 | |
| 13735 | QualType Type; |
| 13736 | |
| 13737 | /// If true, \c Type should be compared with other expression's types for |
| 13738 | /// layout-compatibility. |
| 13739 | unsigned LayoutCompatible : 1; |
| 13740 | unsigned MustBeNull : 1; |
| 13741 | }; |
| 13742 | |
| 13743 | /// A pair of ArgumentKind identifier and magic value. This uniquely |
| 13744 | /// identifies the magic value. |
| 13745 | typedef std::pair<const IdentifierInfo *, uint64_t> TypeTagMagicValue; |
| 13746 | |
| 13747 | private: |
| 13748 | /// A map from magic value to type information. |
| 13749 | std::unique_ptr<llvm::DenseMap<TypeTagMagicValue, TypeTagData>> |
| 13750 | TypeTagForDatatypeMagicValues; |
| 13751 | |
| 13752 | /// Peform checks on a call of a function with argument_with_type_tag |
| 13753 | /// or pointer_with_type_tag attributes. |
| 13754 | void CheckArgumentWithTypeTag(const ArgumentWithTypeTagAttr *Attr, |
| 13755 | const ArrayRef<const Expr *> ExprArgs, |
| 13756 | SourceLocation CallSiteLoc); |
| 13757 | |
| 13758 | /// Check if we are taking the address of a packed field |
| 13759 | /// as this may be a problem if the pointer value is dereferenced. |
| 13760 | void CheckAddressOfPackedMember(Expr *rhs); |
| 13761 | |
| 13762 | /// The parser's current scope. |
| 13763 | /// |
| 13764 | /// The parser maintains this state here. |
| 13765 | Scope *CurScope; |
| 13766 | |
| 13767 | mutable IdentifierInfo *Ident_super; |
| 13768 | mutable IdentifierInfo *Ident___float128; |
| 13769 | |
| 13770 | /// Nullability type specifiers. |
| 13771 | IdentifierInfo *Ident__Nonnull = nullptr; |
| 13772 | IdentifierInfo *Ident__Nullable = nullptr; |
| 13773 | IdentifierInfo *Ident__Nullable_result = nullptr; |
| 13774 | IdentifierInfo *Ident__Null_unspecified = nullptr; |
| 13775 | |
| 13776 | IdentifierInfo *Ident_NSError = nullptr; |
| 13777 | |
| 13778 | /// The handler for the FileChanged preprocessor events. |
| 13779 | /// |
| 13780 | /// Used for diagnostics that implement custom semantic analysis for #include |
| 13781 | /// directives, like -Wpragma-pack. |
| 13782 | sema::SemaPPCallbacks *SemaPPCallbackHandler; |
| 13783 | |
| 13784 | protected: |
| 13785 | friend class Parser; |
| 13786 | friend class InitializationSequence; |
| 13787 | friend class ASTReader; |
| 13788 | friend class ASTDeclReader; |
| 13789 | friend class ASTWriter; |
| 13790 | |
| 13791 | public: |
| 13792 | /// Retrieve the keyword associated |
| 13793 | IdentifierInfo *getNullabilityKeyword(NullabilityKind nullability); |
| 13794 | |
| 13795 | /// The struct behind the CFErrorRef pointer. |
| 13796 | RecordDecl *CFError = nullptr; |
| 13797 | bool isCFError(RecordDecl *D); |
| 13798 | |
| 13799 | /// Retrieve the identifier "NSError". |
| 13800 | IdentifierInfo *getNSErrorIdent(); |
| 13801 | |
| 13802 | /// Retrieve the parser's current scope. |
| 13803 | /// |
| 13804 | /// This routine must only be used when it is certain that semantic analysis |
| 13805 | /// and the parser are in precisely the same context, which is not the case |
| 13806 | /// when, e.g., we are performing any kind of template instantiation. |
| 13807 | /// Therefore, the only safe places to use this scope are in the parser |
| 13808 | /// itself and in routines directly invoked from the parser and *never* from |
| 13809 | /// template substitution or instantiation. |
| 13810 | Scope *getCurScope() const { return CurScope; } |
| 13811 | |
| 13812 | void incrementMSManglingNumber() const { |
| 13813 | return CurScope->incrementMSManglingNumber(); |
| 13814 | } |
| 13815 | |
| 13816 | IdentifierInfo *getSuperIdentifier() const; |
| 13817 | IdentifierInfo *getFloat128Identifier() const; |
| 13818 | |
| 13819 | ObjCContainerDecl *getObjCDeclContext() const; |
| 13820 | |
| 13821 | DeclContext *getCurLexicalContext() const { |
| 13822 | return OriginalLexicalContext ? OriginalLexicalContext : CurContext; |
| 13823 | } |
| 13824 | |
| 13825 | const DeclContext *getCurObjCLexicalContext() const { |
| 13826 | const DeclContext *DC = getCurLexicalContext(); |
| 13827 | // A category implicitly has the attribute of the interface. |
| 13828 | if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC)) |
| 13829 | DC = CatD->getClassInterface(); |
| 13830 | return DC; |
| 13831 | } |
| 13832 | |
| 13833 | /// Determine the number of levels of enclosing template parameters. This is |
| 13834 | /// only usable while parsing. Note that this does not include dependent |
| 13835 | /// contexts in which no template parameters have yet been declared, such as |
| 13836 | /// in a terse function template or generic lambda before the first 'auto' is |
| 13837 | /// encountered. |
| 13838 | unsigned getTemplateDepth(Scope *S) const; |
| 13839 | |
| 13840 | /// To be used for checking whether the arguments being passed to |
| 13841 | /// function exceeds the number of parameters expected for it. |
| 13842 | static bool TooManyArguments(size_t NumParams, size_t NumArgs, |
| 13843 | bool PartialOverloading = false) { |
| 13844 | // We check whether we're just after a comma in code-completion. |
| 13845 | if (NumArgs > 0 && PartialOverloading) |
| 13846 | return NumArgs + 1 > NumParams; // If so, we view as an extra argument. |
| 13847 | return NumArgs > NumParams; |
| 13848 | } |
| 13849 | |
| 13850 | // Emitting members of dllexported classes is delayed until the class |
| 13851 | // (including field initializers) is fully parsed. |
| 13852 | SmallVector<CXXRecordDecl*, 4> DelayedDllExportClasses; |
| 13853 | SmallVector<CXXMethodDecl*, 4> DelayedDllExportMemberFunctions; |
| 13854 | |
| 13855 | private: |
| 13856 | int ParsingClassDepth = 0; |
| 13857 | |
| 13858 | class SavePendingParsedClassStateRAII { |
| 13859 | public: |
| 13860 | SavePendingParsedClassStateRAII(Sema &S) : S(S) { swapSavedState(); } |
| 13861 | |
| 13862 | ~SavePendingParsedClassStateRAII() { |
| 13863 | assert(S.DelayedOverridingExceptionSpecChecks.empty() &&(static_cast <bool> (S.DelayedOverridingExceptionSpecChecks .empty() && "there shouldn't be any pending delayed exception spec checks" ) ? void (0) : __assert_fail ("S.DelayedOverridingExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "clang/include/clang/Sema/Sema.h", 13864, __extension__ __PRETTY_FUNCTION__ )) |
| 13864 | "there shouldn't be any pending delayed exception spec checks")(static_cast <bool> (S.DelayedOverridingExceptionSpecChecks .empty() && "there shouldn't be any pending delayed exception spec checks" ) ? void (0) : __assert_fail ("S.DelayedOverridingExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "clang/include/clang/Sema/Sema.h", 13864, __extension__ __PRETTY_FUNCTION__ )); |
| 13865 | assert(S.DelayedEquivalentExceptionSpecChecks.empty() &&(static_cast <bool> (S.DelayedEquivalentExceptionSpecChecks .empty() && "there shouldn't be any pending delayed exception spec checks" ) ? void (0) : __assert_fail ("S.DelayedEquivalentExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "clang/include/clang/Sema/Sema.h", 13866, __extension__ __PRETTY_FUNCTION__ )) |
| 13866 | "there shouldn't be any pending delayed exception spec checks")(static_cast <bool> (S.DelayedEquivalentExceptionSpecChecks .empty() && "there shouldn't be any pending delayed exception spec checks" ) ? void (0) : __assert_fail ("S.DelayedEquivalentExceptionSpecChecks.empty() && \"there shouldn't be any pending delayed exception spec checks\"" , "clang/include/clang/Sema/Sema.h", 13866, __extension__ __PRETTY_FUNCTION__ )); |
| 13867 | swapSavedState(); |
| 13868 | } |
| 13869 | |
| 13870 | private: |
| 13871 | Sema &S; |
| 13872 | decltype(DelayedOverridingExceptionSpecChecks) |
| 13873 | SavedOverridingExceptionSpecChecks; |
| 13874 | decltype(DelayedEquivalentExceptionSpecChecks) |
| 13875 | SavedEquivalentExceptionSpecChecks; |
| 13876 | |
| 13877 | void swapSavedState() { |
| 13878 | SavedOverridingExceptionSpecChecks.swap( |
| 13879 | S.DelayedOverridingExceptionSpecChecks); |
| 13880 | SavedEquivalentExceptionSpecChecks.swap( |
| 13881 | S.DelayedEquivalentExceptionSpecChecks); |
| 13882 | } |
| 13883 | }; |
| 13884 | |
| 13885 | /// Helper class that collects misaligned member designations and |
| 13886 | /// their location info for delayed diagnostics. |
| 13887 | struct MisalignedMember { |
| 13888 | Expr *E; |
| 13889 | RecordDecl *RD; |
| 13890 | ValueDecl *MD; |
| 13891 | CharUnits Alignment; |
| 13892 | |
| 13893 | MisalignedMember() : E(), RD(), MD() {} |
| 13894 | MisalignedMember(Expr *E, RecordDecl *RD, ValueDecl *MD, |
| 13895 | CharUnits Alignment) |
| 13896 | : E(E), RD(RD), MD(MD), Alignment(Alignment) {} |
| 13897 | explicit MisalignedMember(Expr *E) |
| 13898 | : MisalignedMember(E, nullptr, nullptr, CharUnits()) {} |
| 13899 | |
| 13900 | bool operator==(const MisalignedMember &m) { return this->E == m.E; } |
| 13901 | }; |
| 13902 | /// Small set of gathered accesses to potentially misaligned members |
| 13903 | /// due to the packed attribute. |
| 13904 | SmallVector<MisalignedMember, 4> MisalignedMembers; |
| 13905 | |
| 13906 | /// Adds an expression to the set of gathered misaligned members. |
| 13907 | void AddPotentialMisalignedMembers(Expr *E, RecordDecl *RD, ValueDecl *MD, |
| 13908 | CharUnits Alignment); |
| 13909 | |
| 13910 | public: |
| 13911 | /// Diagnoses the current set of gathered accesses. This typically |
| 13912 | /// happens at full expression level. The set is cleared after emitting the |
| 13913 | /// diagnostics. |
| 13914 | void DiagnoseMisalignedMembers(); |
| 13915 | |
| 13916 | /// This function checks if the expression is in the sef of potentially |
| 13917 | /// misaligned members and it is converted to some pointer type T with lower |
| 13918 | /// or equal alignment requirements. If so it removes it. This is used when |
| 13919 | /// we do not want to diagnose such misaligned access (e.g. in conversions to |
| 13920 | /// void*). |
| 13921 | void DiscardMisalignedMemberAddress(const Type *T, Expr *E); |
| 13922 | |
| 13923 | /// This function calls Action when it determines that E designates a |
| 13924 | /// misaligned member due to the packed attribute. This is used to emit |
| 13925 | /// local diagnostics like in reference binding. |
| 13926 | void RefersToMemberWithReducedAlignment( |
| 13927 | Expr *E, |
| 13928 | llvm::function_ref<void(Expr *, RecordDecl *, FieldDecl *, CharUnits)> |
| 13929 | Action); |
| 13930 | |
| 13931 | /// Describes the reason a calling convention specification was ignored, used |
| 13932 | /// for diagnostics. |
| 13933 | enum class CallingConventionIgnoredReason { |
| 13934 | ForThisTarget = 0, |
| 13935 | VariadicFunction, |
| 13936 | ConstructorDestructor, |
| 13937 | BuiltinFunction |
| 13938 | }; |
| 13939 | /// Creates a SemaDiagnosticBuilder that emits the diagnostic if the current |
| 13940 | /// context is "used as device code". |
| 13941 | /// |
| 13942 | /// - If CurLexicalContext is a kernel function or it is known that the |
| 13943 | /// function will be emitted for the device, emits the diagnostics |
| 13944 | /// immediately. |
| 13945 | /// - If CurLexicalContext is a function and we are compiling |
| 13946 | /// for the device, but we don't know that this function will be codegen'ed |
| 13947 | /// for devive yet, creates a diagnostic which is emitted if and when we |
| 13948 | /// realize that the function will be codegen'ed. |
| 13949 | /// |
| 13950 | /// Example usage: |
| 13951 | /// |
| 13952 | /// Diagnose __float128 type usage only from SYCL device code if the current |
| 13953 | /// target doesn't support it |
| 13954 | /// if (!S.Context.getTargetInfo().hasFloat128Type() && |
| 13955 | /// S.getLangOpts().SYCLIsDevice) |
| 13956 | /// SYCLDiagIfDeviceCode(Loc, diag::err_type_unsupported) << "__float128"; |
| 13957 | SemaDiagnosticBuilder SYCLDiagIfDeviceCode(SourceLocation Loc, |
| 13958 | unsigned DiagID); |
| 13959 | |
| 13960 | void deepTypeCheckForSYCLDevice(SourceLocation UsedAt, |
| 13961 | llvm::DenseSet<QualType> Visited, |
| 13962 | ValueDecl *DeclToCheck); |
| 13963 | }; |
| 13964 | |
| 13965 | DeductionFailureInfo |
| 13966 | MakeDeductionFailureInfo(ASTContext &Context, Sema::TemplateDeductionResult TDK, |
| 13967 | sema::TemplateDeductionInfo &Info); |
| 13968 | |
| 13969 | /// Contains a late templated function. |
| 13970 | /// Will be parsed at the end of the translation unit, used by Sema & Parser. |
| 13971 | struct LateParsedTemplate { |
| 13972 | CachedTokens Toks; |
| 13973 | /// The template function declaration to be late parsed. |
| 13974 | Decl *D; |
| 13975 | }; |
| 13976 | |
| 13977 | template <> |
| 13978 | void Sema::PragmaStack<Sema::AlignPackInfo>::Act(SourceLocation PragmaLocation, |
| 13979 | PragmaMsStackAction Action, |
| 13980 | llvm::StringRef StackSlotLabel, |
| 13981 | AlignPackInfo Value); |
| 13982 | |
| 13983 | std::unique_ptr<sema::RISCVIntrinsicManager> |
| 13984 | CreateRISCVIntrinsicManager(Sema &S); |
| 13985 | } // end namespace clang |
| 13986 | |
| 13987 | namespace llvm { |
| 13988 | // Hash a FunctionDeclAndLoc by looking at both its FunctionDecl and its |
| 13989 | // SourceLocation. |
| 13990 | template <> struct DenseMapInfo<clang::Sema::FunctionDeclAndLoc> { |
| 13991 | using FunctionDeclAndLoc = clang::Sema::FunctionDeclAndLoc; |
| 13992 | using FDBaseInfo = |
| 13993 | DenseMapInfo<clang::CanonicalDeclPtr<const clang::FunctionDecl>>; |
| 13994 | |
| 13995 | static FunctionDeclAndLoc getEmptyKey() { |
| 13996 | return {FDBaseInfo::getEmptyKey(), clang::SourceLocation()}; |
| 13997 | } |
| 13998 | |
| 13999 | static FunctionDeclAndLoc getTombstoneKey() { |
| 14000 | return {FDBaseInfo::getTombstoneKey(), clang::SourceLocation()}; |
| 14001 | } |
| 14002 | |
| 14003 | static unsigned getHashValue(const FunctionDeclAndLoc &FDL) { |
| 14004 | return hash_combine(FDBaseInfo::getHashValue(FDL.FD), |
| 14005 | FDL.Loc.getHashValue()); |
| 14006 | } |
| 14007 | |
| 14008 | static bool isEqual(const FunctionDeclAndLoc &LHS, |
| 14009 | const FunctionDeclAndLoc &RHS) { |
| 14010 | return LHS.FD == RHS.FD && LHS.Loc == RHS.Loc; |
| 14011 | } |
| 14012 | }; |
| 14013 | } // namespace llvm |
| 14014 | |
| 14015 | #endif |
| 1 | //===- ExprCXX.h - Classes for representing expressions ---------*- 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 | /// \file | |||
| 10 | /// Defines the clang::Expr interface and subclasses for C++ expressions. | |||
| 11 | // | |||
| 12 | //===----------------------------------------------------------------------===// | |||
| 13 | ||||
| 14 | #ifndef LLVM_CLANG_AST_EXPRCXX_H | |||
| 15 | #define LLVM_CLANG_AST_EXPRCXX_H | |||
| 16 | ||||
| 17 | #include "clang/AST/ASTConcept.h" | |||
| 18 | #include "clang/AST/ComputeDependence.h" | |||
| 19 | #include "clang/AST/Decl.h" | |||
| 20 | #include "clang/AST/DeclBase.h" | |||
| 21 | #include "clang/AST/DeclCXX.h" | |||
| 22 | #include "clang/AST/DeclTemplate.h" | |||
| 23 | #include "clang/AST/DeclarationName.h" | |||
| 24 | #include "clang/AST/DependenceFlags.h" | |||
| 25 | #include "clang/AST/Expr.h" | |||
| 26 | #include "clang/AST/NestedNameSpecifier.h" | |||
| 27 | #include "clang/AST/OperationKinds.h" | |||
| 28 | #include "clang/AST/Stmt.h" | |||
| 29 | #include "clang/AST/StmtCXX.h" | |||
| 30 | #include "clang/AST/TemplateBase.h" | |||
| 31 | #include "clang/AST/Type.h" | |||
| 32 | #include "clang/AST/UnresolvedSet.h" | |||
| 33 | #include "clang/Basic/ExceptionSpecificationType.h" | |||
| 34 | #include "clang/Basic/ExpressionTraits.h" | |||
| 35 | #include "clang/Basic/LLVM.h" | |||
| 36 | #include "clang/Basic/Lambda.h" | |||
| 37 | #include "clang/Basic/LangOptions.h" | |||
| 38 | #include "clang/Basic/OperatorKinds.h" | |||
| 39 | #include "clang/Basic/SourceLocation.h" | |||
| 40 | #include "clang/Basic/Specifiers.h" | |||
| 41 | #include "clang/Basic/TypeTraits.h" | |||
| 42 | #include "llvm/ADT/ArrayRef.h" | |||
| 43 | #include "llvm/ADT/PointerUnion.h" | |||
| 44 | #include "llvm/ADT/StringRef.h" | |||
| 45 | #include "llvm/ADT/iterator_range.h" | |||
| 46 | #include "llvm/Support/Casting.h" | |||
| 47 | #include "llvm/Support/Compiler.h" | |||
| 48 | #include "llvm/Support/TrailingObjects.h" | |||
| 49 | #include <cassert> | |||
| 50 | #include <cstddef> | |||
| 51 | #include <cstdint> | |||
| 52 | #include <memory> | |||
| 53 | #include <optional> | |||
| 54 | ||||
| 55 | namespace clang { | |||
| 56 | ||||
| 57 | class ASTContext; | |||
| 58 | class DeclAccessPair; | |||
| 59 | class IdentifierInfo; | |||
| 60 | class LambdaCapture; | |||
| 61 | class NonTypeTemplateParmDecl; | |||
| 62 | class TemplateParameterList; | |||
| 63 | ||||
| 64 | //===--------------------------------------------------------------------===// | |||
| 65 | // C++ Expressions. | |||
| 66 | //===--------------------------------------------------------------------===// | |||
| 67 | ||||
| 68 | /// A call to an overloaded operator written using operator | |||
| 69 | /// syntax. | |||
| 70 | /// | |||
| 71 | /// Represents a call to an overloaded operator written using operator | |||
| 72 | /// syntax, e.g., "x + y" or "*p". While semantically equivalent to a | |||
| 73 | /// normal call, this AST node provides better information about the | |||
| 74 | /// syntactic representation of the call. | |||
| 75 | /// | |||
| 76 | /// In a C++ template, this expression node kind will be used whenever | |||
| 77 | /// any of the arguments are type-dependent. In this case, the | |||
| 78 | /// function itself will be a (possibly empty) set of functions and | |||
| 79 | /// function templates that were found by name lookup at template | |||
| 80 | /// definition time. | |||
| 81 | class CXXOperatorCallExpr final : public CallExpr { | |||
| 82 | friend class ASTStmtReader; | |||
| 83 | friend class ASTStmtWriter; | |||
| 84 | ||||
| 85 | SourceRange Range; | |||
| 86 | ||||
| 87 | // CXXOperatorCallExpr has some trailing objects belonging | |||
| 88 | // to CallExpr. See CallExpr for the details. | |||
| 89 | ||||
| 90 | SourceRange getSourceRangeImpl() const LLVM_READONLY__attribute__((__pure__)); | |||
| 91 | ||||
| 92 | CXXOperatorCallExpr(OverloadedOperatorKind OpKind, Expr *Fn, | |||
| 93 | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, | |||
| 94 | SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, | |||
| 95 | ADLCallKind UsesADL); | |||
| 96 | ||||
| 97 | CXXOperatorCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); | |||
| 98 | ||||
| 99 | public: | |||
| 100 | static CXXOperatorCallExpr * | |||
| 101 | Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, | |||
| 102 | ArrayRef<Expr *> Args, QualType Ty, ExprValueKind VK, | |||
| 103 | SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, | |||
| 104 | ADLCallKind UsesADL = NotADL); | |||
| 105 | ||||
| 106 | static CXXOperatorCallExpr *CreateEmpty(const ASTContext &Ctx, | |||
| 107 | unsigned NumArgs, bool HasFPFeatures, | |||
| 108 | EmptyShell Empty); | |||
| 109 | ||||
| 110 | /// Returns the kind of overloaded operator that this expression refers to. | |||
| 111 | OverloadedOperatorKind getOperator() const { | |||
| 112 | return static_cast<OverloadedOperatorKind>( | |||
| 113 | CXXOperatorCallExprBits.OperatorKind); | |||
| 114 | } | |||
| 115 | ||||
| 116 | static bool isAssignmentOp(OverloadedOperatorKind Opc) { | |||
| 117 | return Opc == OO_Equal || Opc == OO_StarEqual || Opc == OO_SlashEqual || | |||
| 118 | Opc == OO_PercentEqual || Opc == OO_PlusEqual || | |||
| 119 | Opc == OO_MinusEqual || Opc == OO_LessLessEqual || | |||
| 120 | Opc == OO_GreaterGreaterEqual || Opc == OO_AmpEqual || | |||
| 121 | Opc == OO_CaretEqual || Opc == OO_PipeEqual; | |||
| 122 | } | |||
| 123 | bool isAssignmentOp() const { return isAssignmentOp(getOperator()); } | |||
| 124 | ||||
| 125 | static bool isComparisonOp(OverloadedOperatorKind Opc) { | |||
| 126 | switch (Opc) { | |||
| 127 | case OO_EqualEqual: | |||
| 128 | case OO_ExclaimEqual: | |||
| 129 | case OO_Greater: | |||
| 130 | case OO_GreaterEqual: | |||
| 131 | case OO_Less: | |||
| 132 | case OO_LessEqual: | |||
| 133 | case OO_Spaceship: | |||
| 134 | return true; | |||
| 135 | default: | |||
| 136 | return false; | |||
| 137 | } | |||
| 138 | } | |||
| 139 | bool isComparisonOp() const { return isComparisonOp(getOperator()); } | |||
| 140 | ||||
| 141 | /// Is this written as an infix binary operator? | |||
| 142 | bool isInfixBinaryOp() const; | |||
| 143 | ||||
| 144 | /// Returns the location of the operator symbol in the expression. | |||
| 145 | /// | |||
| 146 | /// When \c getOperator()==OO_Call, this is the location of the right | |||
| 147 | /// parentheses; when \c getOperator()==OO_Subscript, this is the location | |||
| 148 | /// of the right bracket. | |||
| 149 | SourceLocation getOperatorLoc() const { return getRParenLoc(); } | |||
| 150 | ||||
| 151 | SourceLocation getExprLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 152 | OverloadedOperatorKind Operator = getOperator(); | |||
| 153 | return (Operator < OO_Plus || Operator >= OO_Arrow || | |||
| 154 | Operator == OO_PlusPlus || Operator == OO_MinusMinus) | |||
| 155 | ? getBeginLoc() | |||
| 156 | : getOperatorLoc(); | |||
| 157 | } | |||
| 158 | ||||
| 159 | SourceLocation getBeginLoc() const { return Range.getBegin(); } | |||
| 160 | SourceLocation getEndLoc() const { return Range.getEnd(); } | |||
| 161 | SourceRange getSourceRange() const { return Range; } | |||
| 162 | ||||
| 163 | static bool classof(const Stmt *T) { | |||
| 164 | return T->getStmtClass() == CXXOperatorCallExprClass; | |||
| 165 | } | |||
| 166 | }; | |||
| 167 | ||||
| 168 | /// Represents a call to a member function that | |||
| 169 | /// may be written either with member call syntax (e.g., "obj.func()" | |||
| 170 | /// or "objptr->func()") or with normal function-call syntax | |||
| 171 | /// ("func()") within a member function that ends up calling a member | |||
| 172 | /// function. The callee in either case is a MemberExpr that contains | |||
| 173 | /// both the object argument and the member function, while the | |||
| 174 | /// arguments are the arguments within the parentheses (not including | |||
| 175 | /// the object argument). | |||
| 176 | class CXXMemberCallExpr final : public CallExpr { | |||
| 177 | // CXXMemberCallExpr has some trailing objects belonging | |||
| 178 | // to CallExpr. See CallExpr for the details. | |||
| 179 | ||||
| 180 | CXXMemberCallExpr(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty, | |||
| 181 | ExprValueKind VK, SourceLocation RP, | |||
| 182 | FPOptionsOverride FPOptions, unsigned MinNumArgs); | |||
| 183 | ||||
| 184 | CXXMemberCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); | |||
| 185 | ||||
| 186 | public: | |||
| 187 | static CXXMemberCallExpr *Create(const ASTContext &Ctx, Expr *Fn, | |||
| 188 | ArrayRef<Expr *> Args, QualType Ty, | |||
| 189 | ExprValueKind VK, SourceLocation RP, | |||
| 190 | FPOptionsOverride FPFeatures, | |||
| 191 | unsigned MinNumArgs = 0); | |||
| 192 | ||||
| 193 | static CXXMemberCallExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs, | |||
| 194 | bool HasFPFeatures, EmptyShell Empty); | |||
| 195 | ||||
| 196 | /// Retrieve the implicit object argument for the member call. | |||
| 197 | /// | |||
| 198 | /// For example, in "x.f(5)", this returns the sub-expression "x". | |||
| 199 | Expr *getImplicitObjectArgument() const; | |||
| 200 | ||||
| 201 | /// Retrieve the type of the object argument. | |||
| 202 | /// | |||
| 203 | /// Note that this always returns a non-pointer type. | |||
| 204 | QualType getObjectType() const; | |||
| 205 | ||||
| 206 | /// Retrieve the declaration of the called method. | |||
| 207 | CXXMethodDecl *getMethodDecl() const; | |||
| 208 | ||||
| 209 | /// Retrieve the CXXRecordDecl for the underlying type of | |||
| 210 | /// the implicit object argument. | |||
| 211 | /// | |||
| 212 | /// Note that this is may not be the same declaration as that of the class | |||
| 213 | /// context of the CXXMethodDecl which this function is calling. | |||
| 214 | /// FIXME: Returns 0 for member pointer call exprs. | |||
| 215 | CXXRecordDecl *getRecordDecl() const; | |||
| 216 | ||||
| 217 | SourceLocation getExprLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 218 | SourceLocation CLoc = getCallee()->getExprLoc(); | |||
| 219 | if (CLoc.isValid()) | |||
| 220 | return CLoc; | |||
| 221 | ||||
| 222 | return getBeginLoc(); | |||
| 223 | } | |||
| 224 | ||||
| 225 | static bool classof(const Stmt *T) { | |||
| 226 | return T->getStmtClass() == CXXMemberCallExprClass; | |||
| 227 | } | |||
| 228 | }; | |||
| 229 | ||||
| 230 | /// Represents a call to a CUDA kernel function. | |||
| 231 | class CUDAKernelCallExpr final : public CallExpr { | |||
| 232 | friend class ASTStmtReader; | |||
| 233 | ||||
| 234 | enum { CONFIG, END_PREARG }; | |||
| 235 | ||||
| 236 | // CUDAKernelCallExpr has some trailing objects belonging | |||
| 237 | // to CallExpr. See CallExpr for the details. | |||
| 238 | ||||
| 239 | CUDAKernelCallExpr(Expr *Fn, CallExpr *Config, ArrayRef<Expr *> Args, | |||
| 240 | QualType Ty, ExprValueKind VK, SourceLocation RP, | |||
| 241 | FPOptionsOverride FPFeatures, unsigned MinNumArgs); | |||
| 242 | ||||
| 243 | CUDAKernelCallExpr(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); | |||
| 244 | ||||
| 245 | public: | |||
| 246 | static CUDAKernelCallExpr *Create(const ASTContext &Ctx, Expr *Fn, | |||
| 247 | CallExpr *Config, ArrayRef<Expr *> Args, | |||
| 248 | QualType Ty, ExprValueKind VK, | |||
| 249 | SourceLocation RP, | |||
| 250 | FPOptionsOverride FPFeatures, | |||
| 251 | unsigned MinNumArgs = 0); | |||
| 252 | ||||
| 253 | static CUDAKernelCallExpr *CreateEmpty(const ASTContext &Ctx, | |||
| 254 | unsigned NumArgs, bool HasFPFeatures, | |||
| 255 | EmptyShell Empty); | |||
| 256 | ||||
| 257 | const CallExpr *getConfig() const { | |||
| 258 | return cast_or_null<CallExpr>(getPreArg(CONFIG)); | |||
| 259 | } | |||
| 260 | CallExpr *getConfig() { return cast_or_null<CallExpr>(getPreArg(CONFIG)); } | |||
| 261 | ||||
| 262 | static bool classof(const Stmt *T) { | |||
| 263 | return T->getStmtClass() == CUDAKernelCallExprClass; | |||
| 264 | } | |||
| 265 | }; | |||
| 266 | ||||
| 267 | /// A rewritten comparison expression that was originally written using | |||
| 268 | /// operator syntax. | |||
| 269 | /// | |||
| 270 | /// In C++20, the following rewrites are performed: | |||
| 271 | /// - <tt>a == b</tt> -> <tt>b == a</tt> | |||
| 272 | /// - <tt>a != b</tt> -> <tt>!(a == b)</tt> | |||
| 273 | /// - <tt>a != b</tt> -> <tt>!(b == a)</tt> | |||
| 274 | /// - For \c \@ in \c <, \c <=, \c >, \c >=, \c <=>: | |||
| 275 | /// - <tt>a @ b</tt> -> <tt>(a <=> b) @ 0</tt> | |||
| 276 | /// - <tt>a @ b</tt> -> <tt>0 @ (b <=> a)</tt> | |||
| 277 | /// | |||
| 278 | /// This expression provides access to both the original syntax and the | |||
| 279 | /// rewritten expression. | |||
| 280 | /// | |||
| 281 | /// Note that the rewritten calls to \c ==, \c <=>, and \c \@ are typically | |||
| 282 | /// \c CXXOperatorCallExprs, but could theoretically be \c BinaryOperators. | |||
| 283 | class CXXRewrittenBinaryOperator : public Expr { | |||
| 284 | friend class ASTStmtReader; | |||
| 285 | ||||
| 286 | /// The rewritten semantic form. | |||
| 287 | Stmt *SemanticForm; | |||
| 288 | ||||
| 289 | public: | |||
| 290 | CXXRewrittenBinaryOperator(Expr *SemanticForm, bool IsReversed) | |||
| 291 | : Expr(CXXRewrittenBinaryOperatorClass, SemanticForm->getType(), | |||
| 292 | SemanticForm->getValueKind(), SemanticForm->getObjectKind()), | |||
| 293 | SemanticForm(SemanticForm) { | |||
| 294 | CXXRewrittenBinaryOperatorBits.IsReversed = IsReversed; | |||
| 295 | setDependence(computeDependence(this)); | |||
| 296 | } | |||
| 297 | CXXRewrittenBinaryOperator(EmptyShell Empty) | |||
| 298 | : Expr(CXXRewrittenBinaryOperatorClass, Empty), SemanticForm() {} | |||
| 299 | ||||
| 300 | /// Get an equivalent semantic form for this expression. | |||
| 301 | Expr *getSemanticForm() { return cast<Expr>(SemanticForm); } | |||
| 302 | const Expr *getSemanticForm() const { return cast<Expr>(SemanticForm); } | |||
| 303 | ||||
| 304 | struct DecomposedForm { | |||
| 305 | /// The original opcode, prior to rewriting. | |||
| 306 | BinaryOperatorKind Opcode; | |||
| 307 | /// The original left-hand side. | |||
| 308 | const Expr *LHS; | |||
| 309 | /// The original right-hand side. | |||
| 310 | const Expr *RHS; | |||
| 311 | /// The inner \c == or \c <=> operator expression. | |||
| 312 | const Expr *InnerBinOp; | |||
| 313 | }; | |||
| 314 | ||||
| 315 | /// Decompose this operator into its syntactic form. | |||
| 316 | DecomposedForm getDecomposedForm() const LLVM_READONLY__attribute__((__pure__)); | |||
| 317 | ||||
| 318 | /// Determine whether this expression was rewritten in reverse form. | |||
| 319 | bool isReversed() const { return CXXRewrittenBinaryOperatorBits.IsReversed; } | |||
| 320 | ||||
| 321 | BinaryOperatorKind getOperator() const { return getDecomposedForm().Opcode; } | |||
| 322 | BinaryOperatorKind getOpcode() const { return getOperator(); } | |||
| 323 | static StringRef getOpcodeStr(BinaryOperatorKind Op) { | |||
| 324 | return BinaryOperator::getOpcodeStr(Op); | |||
| 325 | } | |||
| 326 | StringRef getOpcodeStr() const { | |||
| 327 | return BinaryOperator::getOpcodeStr(getOpcode()); | |||
| 328 | } | |||
| 329 | bool isComparisonOp() const { return true; } | |||
| 330 | bool isAssignmentOp() const { return false; } | |||
| 331 | ||||
| 332 | const Expr *getLHS() const { return getDecomposedForm().LHS; } | |||
| 333 | const Expr *getRHS() const { return getDecomposedForm().RHS; } | |||
| 334 | ||||
| 335 | SourceLocation getOperatorLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 336 | return getDecomposedForm().InnerBinOp->getExprLoc(); | |||
| 337 | } | |||
| 338 | SourceLocation getExprLoc() const LLVM_READONLY__attribute__((__pure__)) { return getOperatorLoc(); } | |||
| 339 | ||||
| 340 | /// Compute the begin and end locations from the decomposed form. | |||
| 341 | /// The locations of the semantic form are not reliable if this is | |||
| 342 | /// a reversed expression. | |||
| 343 | //@{ | |||
| 344 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 345 | return getDecomposedForm().LHS->getBeginLoc(); | |||
| 346 | } | |||
| 347 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 348 | return getDecomposedForm().RHS->getEndLoc(); | |||
| 349 | } | |||
| 350 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 351 | DecomposedForm DF = getDecomposedForm(); | |||
| 352 | return SourceRange(DF.LHS->getBeginLoc(), DF.RHS->getEndLoc()); | |||
| 353 | } | |||
| 354 | //@} | |||
| 355 | ||||
| 356 | child_range children() { | |||
| 357 | return child_range(&SemanticForm, &SemanticForm + 1); | |||
| 358 | } | |||
| 359 | ||||
| 360 | static bool classof(const Stmt *T) { | |||
| 361 | return T->getStmtClass() == CXXRewrittenBinaryOperatorClass; | |||
| 362 | } | |||
| 363 | }; | |||
| 364 | ||||
| 365 | /// Abstract class common to all of the C++ "named"/"keyword" casts. | |||
| 366 | /// | |||
| 367 | /// This abstract class is inherited by all of the classes | |||
| 368 | /// representing "named" casts: CXXStaticCastExpr for \c static_cast, | |||
| 369 | /// CXXDynamicCastExpr for \c dynamic_cast, CXXReinterpretCastExpr for | |||
| 370 | /// reinterpret_cast, CXXConstCastExpr for \c const_cast and | |||
| 371 | /// CXXAddrspaceCastExpr for addrspace_cast (in OpenCL). | |||
| 372 | class CXXNamedCastExpr : public ExplicitCastExpr { | |||
| 373 | private: | |||
| 374 | // the location of the casting op | |||
| 375 | SourceLocation Loc; | |||
| 376 | ||||
| 377 | // the location of the right parenthesis | |||
| 378 | SourceLocation RParenLoc; | |||
| 379 | ||||
| 380 | // range for '<' '>' | |||
| 381 | SourceRange AngleBrackets; | |||
| 382 | ||||
| 383 | protected: | |||
| 384 | friend class ASTStmtReader; | |||
| 385 | ||||
| 386 | CXXNamedCastExpr(StmtClass SC, QualType ty, ExprValueKind VK, CastKind kind, | |||
| 387 | Expr *op, unsigned PathSize, bool HasFPFeatures, | |||
| 388 | TypeSourceInfo *writtenTy, SourceLocation l, | |||
| 389 | SourceLocation RParenLoc, SourceRange AngleBrackets) | |||
| 390 | : ExplicitCastExpr(SC, ty, VK, kind, op, PathSize, HasFPFeatures, | |||
| 391 | writtenTy), | |||
| 392 | Loc(l), RParenLoc(RParenLoc), AngleBrackets(AngleBrackets) {} | |||
| 393 | ||||
| 394 | explicit CXXNamedCastExpr(StmtClass SC, EmptyShell Shell, unsigned PathSize, | |||
| 395 | bool HasFPFeatures) | |||
| 396 | : ExplicitCastExpr(SC, Shell, PathSize, HasFPFeatures) {} | |||
| 397 | ||||
| 398 | public: | |||
| 399 | const char *getCastName() const; | |||
| 400 | ||||
| 401 | /// Retrieve the location of the cast operator keyword, e.g., | |||
| 402 | /// \c static_cast. | |||
| 403 | SourceLocation getOperatorLoc() const { return Loc; } | |||
| 404 | ||||
| 405 | /// Retrieve the location of the closing parenthesis. | |||
| 406 | SourceLocation getRParenLoc() const { return RParenLoc; } | |||
| 407 | ||||
| 408 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Loc; } | |||
| 409 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return RParenLoc; } | |||
| 410 | SourceRange getAngleBrackets() const LLVM_READONLY__attribute__((__pure__)) { return AngleBrackets; } | |||
| 411 | ||||
| 412 | static bool classof(const Stmt *T) { | |||
| 413 | switch (T->getStmtClass()) { | |||
| 414 | case CXXStaticCastExprClass: | |||
| 415 | case CXXDynamicCastExprClass: | |||
| 416 | case CXXReinterpretCastExprClass: | |||
| 417 | case CXXConstCastExprClass: | |||
| 418 | case CXXAddrspaceCastExprClass: | |||
| 419 | return true; | |||
| 420 | default: | |||
| 421 | return false; | |||
| 422 | } | |||
| 423 | } | |||
| 424 | }; | |||
| 425 | ||||
| 426 | /// A C++ \c static_cast expression (C++ [expr.static.cast]). | |||
| 427 | /// | |||
| 428 | /// This expression node represents a C++ static cast, e.g., | |||
| 429 | /// \c static_cast<int>(1.0). | |||
| 430 | class CXXStaticCastExpr final | |||
| 431 | : public CXXNamedCastExpr, | |||
| 432 | private llvm::TrailingObjects<CXXStaticCastExpr, CXXBaseSpecifier *, | |||
| 433 | FPOptionsOverride> { | |||
| 434 | CXXStaticCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, | |||
| 435 | unsigned pathSize, TypeSourceInfo *writtenTy, | |||
| 436 | FPOptionsOverride FPO, SourceLocation l, | |||
| 437 | SourceLocation RParenLoc, SourceRange AngleBrackets) | |||
| 438 | : CXXNamedCastExpr(CXXStaticCastExprClass, ty, vk, kind, op, pathSize, | |||
| 439 | FPO.requiresTrailingStorage(), writtenTy, l, RParenLoc, | |||
| 440 | AngleBrackets) { | |||
| 441 | if (hasStoredFPFeatures()) | |||
| 442 | *getTrailingFPFeatures() = FPO; | |||
| 443 | } | |||
| 444 | ||||
| 445 | explicit CXXStaticCastExpr(EmptyShell Empty, unsigned PathSize, | |||
| 446 | bool HasFPFeatures) | |||
| 447 | : CXXNamedCastExpr(CXXStaticCastExprClass, Empty, PathSize, | |||
| 448 | HasFPFeatures) {} | |||
| 449 | ||||
| 450 | unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const { | |||
| 451 | return path_size(); | |||
| 452 | } | |||
| 453 | ||||
| 454 | public: | |||
| 455 | friend class CastExpr; | |||
| 456 | friend TrailingObjects; | |||
| 457 | ||||
| 458 | static CXXStaticCastExpr * | |||
| 459 | Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, | |||
| 460 | Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, | |||
| 461 | FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, | |||
| 462 | SourceRange AngleBrackets); | |||
| 463 | static CXXStaticCastExpr *CreateEmpty(const ASTContext &Context, | |||
| 464 | unsigned PathSize, bool hasFPFeatures); | |||
| 465 | ||||
| 466 | static bool classof(const Stmt *T) { | |||
| 467 | return T->getStmtClass() == CXXStaticCastExprClass; | |||
| 468 | } | |||
| 469 | }; | |||
| 470 | ||||
| 471 | /// A C++ @c dynamic_cast expression (C++ [expr.dynamic.cast]). | |||
| 472 | /// | |||
| 473 | /// This expression node represents a dynamic cast, e.g., | |||
| 474 | /// \c dynamic_cast<Derived*>(BasePtr). Such a cast may perform a run-time | |||
| 475 | /// check to determine how to perform the type conversion. | |||
| 476 | class CXXDynamicCastExpr final | |||
| 477 | : public CXXNamedCastExpr, | |||
| 478 | private llvm::TrailingObjects<CXXDynamicCastExpr, CXXBaseSpecifier *> { | |||
| 479 | CXXDynamicCastExpr(QualType ty, ExprValueKind VK, CastKind kind, Expr *op, | |||
| 480 | unsigned pathSize, TypeSourceInfo *writtenTy, | |||
| 481 | SourceLocation l, SourceLocation RParenLoc, | |||
| 482 | SourceRange AngleBrackets) | |||
| 483 | : CXXNamedCastExpr(CXXDynamicCastExprClass, ty, VK, kind, op, pathSize, | |||
| 484 | /*HasFPFeatures*/ false, writtenTy, l, RParenLoc, | |||
| 485 | AngleBrackets) {} | |||
| 486 | ||||
| 487 | explicit CXXDynamicCastExpr(EmptyShell Empty, unsigned pathSize) | |||
| 488 | : CXXNamedCastExpr(CXXDynamicCastExprClass, Empty, pathSize, | |||
| 489 | /*HasFPFeatures*/ false) {} | |||
| 490 | ||||
| 491 | public: | |||
| 492 | friend class CastExpr; | |||
| 493 | friend TrailingObjects; | |||
| 494 | ||||
| 495 | static CXXDynamicCastExpr *Create(const ASTContext &Context, QualType T, | |||
| 496 | ExprValueKind VK, CastKind Kind, Expr *Op, | |||
| 497 | const CXXCastPath *Path, | |||
| 498 | TypeSourceInfo *Written, SourceLocation L, | |||
| 499 | SourceLocation RParenLoc, | |||
| 500 | SourceRange AngleBrackets); | |||
| 501 | ||||
| 502 | static CXXDynamicCastExpr *CreateEmpty(const ASTContext &Context, | |||
| 503 | unsigned pathSize); | |||
| 504 | ||||
| 505 | bool isAlwaysNull() const; | |||
| 506 | ||||
| 507 | static bool classof(const Stmt *T) { | |||
| 508 | return T->getStmtClass() == CXXDynamicCastExprClass; | |||
| 509 | } | |||
| 510 | }; | |||
| 511 | ||||
| 512 | /// A C++ @c reinterpret_cast expression (C++ [expr.reinterpret.cast]). | |||
| 513 | /// | |||
| 514 | /// This expression node represents a reinterpret cast, e.g., | |||
| 515 | /// @c reinterpret_cast<int>(VoidPtr). | |||
| 516 | /// | |||
| 517 | /// A reinterpret_cast provides a differently-typed view of a value but | |||
| 518 | /// (in Clang, as in most C++ implementations) performs no actual work at | |||
| 519 | /// run time. | |||
| 520 | class CXXReinterpretCastExpr final | |||
| 521 | : public CXXNamedCastExpr, | |||
| 522 | private llvm::TrailingObjects<CXXReinterpretCastExpr, | |||
| 523 | CXXBaseSpecifier *> { | |||
| 524 | CXXReinterpretCastExpr(QualType ty, ExprValueKind vk, CastKind kind, Expr *op, | |||
| 525 | unsigned pathSize, TypeSourceInfo *writtenTy, | |||
| 526 | SourceLocation l, SourceLocation RParenLoc, | |||
| 527 | SourceRange AngleBrackets) | |||
| 528 | : CXXNamedCastExpr(CXXReinterpretCastExprClass, ty, vk, kind, op, | |||
| 529 | pathSize, /*HasFPFeatures*/ false, writtenTy, l, | |||
| 530 | RParenLoc, AngleBrackets) {} | |||
| 531 | ||||
| 532 | CXXReinterpretCastExpr(EmptyShell Empty, unsigned pathSize) | |||
| 533 | : CXXNamedCastExpr(CXXReinterpretCastExprClass, Empty, pathSize, | |||
| 534 | /*HasFPFeatures*/ false) {} | |||
| 535 | ||||
| 536 | public: | |||
| 537 | friend class CastExpr; | |||
| 538 | friend TrailingObjects; | |||
| 539 | ||||
| 540 | static CXXReinterpretCastExpr *Create(const ASTContext &Context, QualType T, | |||
| 541 | ExprValueKind VK, CastKind Kind, | |||
| 542 | Expr *Op, const CXXCastPath *Path, | |||
| 543 | TypeSourceInfo *WrittenTy, SourceLocation L, | |||
| 544 | SourceLocation RParenLoc, | |||
| 545 | SourceRange AngleBrackets); | |||
| 546 | static CXXReinterpretCastExpr *CreateEmpty(const ASTContext &Context, | |||
| 547 | unsigned pathSize); | |||
| 548 | ||||
| 549 | static bool classof(const Stmt *T) { | |||
| 550 | return T->getStmtClass() == CXXReinterpretCastExprClass; | |||
| 551 | } | |||
| 552 | }; | |||
| 553 | ||||
| 554 | /// A C++ \c const_cast expression (C++ [expr.const.cast]). | |||
| 555 | /// | |||
| 556 | /// This expression node represents a const cast, e.g., | |||
| 557 | /// \c const_cast<char*>(PtrToConstChar). | |||
| 558 | /// | |||
| 559 | /// A const_cast can remove type qualifiers but does not change the underlying | |||
| 560 | /// value. | |||
| 561 | class CXXConstCastExpr final | |||
| 562 | : public CXXNamedCastExpr, | |||
| 563 | private llvm::TrailingObjects<CXXConstCastExpr, CXXBaseSpecifier *> { | |||
| 564 | CXXConstCastExpr(QualType ty, ExprValueKind VK, Expr *op, | |||
| 565 | TypeSourceInfo *writtenTy, SourceLocation l, | |||
| 566 | SourceLocation RParenLoc, SourceRange AngleBrackets) | |||
| 567 | : CXXNamedCastExpr(CXXConstCastExprClass, ty, VK, CK_NoOp, op, 0, | |||
| 568 | /*HasFPFeatures*/ false, writtenTy, l, RParenLoc, | |||
| 569 | AngleBrackets) {} | |||
| 570 | ||||
| 571 | explicit CXXConstCastExpr(EmptyShell Empty) | |||
| 572 | : CXXNamedCastExpr(CXXConstCastExprClass, Empty, 0, | |||
| 573 | /*HasFPFeatures*/ false) {} | |||
| 574 | ||||
| 575 | public: | |||
| 576 | friend class CastExpr; | |||
| 577 | friend TrailingObjects; | |||
| 578 | ||||
| 579 | static CXXConstCastExpr *Create(const ASTContext &Context, QualType T, | |||
| 580 | ExprValueKind VK, Expr *Op, | |||
| 581 | TypeSourceInfo *WrittenTy, SourceLocation L, | |||
| 582 | SourceLocation RParenLoc, | |||
| 583 | SourceRange AngleBrackets); | |||
| 584 | static CXXConstCastExpr *CreateEmpty(const ASTContext &Context); | |||
| 585 | ||||
| 586 | static bool classof(const Stmt *T) { | |||
| 587 | return T->getStmtClass() == CXXConstCastExprClass; | |||
| 588 | } | |||
| 589 | }; | |||
| 590 | ||||
| 591 | /// A C++ addrspace_cast expression (currently only enabled for OpenCL). | |||
| 592 | /// | |||
| 593 | /// This expression node represents a cast between pointers to objects in | |||
| 594 | /// different address spaces e.g., | |||
| 595 | /// \c addrspace_cast<global int*>(PtrToGenericInt). | |||
| 596 | /// | |||
| 597 | /// A addrspace_cast can cast address space type qualifiers but does not change | |||
| 598 | /// the underlying value. | |||
| 599 | class CXXAddrspaceCastExpr final | |||
| 600 | : public CXXNamedCastExpr, | |||
| 601 | private llvm::TrailingObjects<CXXAddrspaceCastExpr, CXXBaseSpecifier *> { | |||
| 602 | CXXAddrspaceCastExpr(QualType ty, ExprValueKind VK, CastKind Kind, Expr *op, | |||
| 603 | TypeSourceInfo *writtenTy, SourceLocation l, | |||
| 604 | SourceLocation RParenLoc, SourceRange AngleBrackets) | |||
| 605 | : CXXNamedCastExpr(CXXAddrspaceCastExprClass, ty, VK, Kind, op, 0, | |||
| 606 | /*HasFPFeatures*/ false, writtenTy, l, RParenLoc, | |||
| 607 | AngleBrackets) {} | |||
| 608 | ||||
| 609 | explicit CXXAddrspaceCastExpr(EmptyShell Empty) | |||
| 610 | : CXXNamedCastExpr(CXXAddrspaceCastExprClass, Empty, 0, | |||
| 611 | /*HasFPFeatures*/ false) {} | |||
| 612 | ||||
| 613 | public: | |||
| 614 | friend class CastExpr; | |||
| 615 | friend TrailingObjects; | |||
| 616 | ||||
| 617 | static CXXAddrspaceCastExpr * | |||
| 618 | Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, | |||
| 619 | Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, | |||
| 620 | SourceLocation RParenLoc, SourceRange AngleBrackets); | |||
| 621 | static CXXAddrspaceCastExpr *CreateEmpty(const ASTContext &Context); | |||
| 622 | ||||
| 623 | static bool classof(const Stmt *T) { | |||
| 624 | return T->getStmtClass() == CXXAddrspaceCastExprClass; | |||
| 625 | } | |||
| 626 | }; | |||
| 627 | ||||
| 628 | /// A call to a literal operator (C++11 [over.literal]) | |||
| 629 | /// written as a user-defined literal (C++11 [lit.ext]). | |||
| 630 | /// | |||
| 631 | /// Represents a user-defined literal, e.g. "foo"_bar or 1.23_xyz. While this | |||
| 632 | /// is semantically equivalent to a normal call, this AST node provides better | |||
| 633 | /// information about the syntactic representation of the literal. | |||
| 634 | /// | |||
| 635 | /// Since literal operators are never found by ADL and can only be declared at | |||
| 636 | /// namespace scope, a user-defined literal is never dependent. | |||
| 637 | class UserDefinedLiteral final : public CallExpr { | |||
| 638 | friend class ASTStmtReader; | |||
| 639 | friend class ASTStmtWriter; | |||
| 640 | ||||
| 641 | /// The location of a ud-suffix within the literal. | |||
| 642 | SourceLocation UDSuffixLoc; | |||
| 643 | ||||
| 644 | // UserDefinedLiteral has some trailing objects belonging | |||
| 645 | // to CallExpr. See CallExpr for the details. | |||
| 646 | ||||
| 647 | UserDefinedLiteral(Expr *Fn, ArrayRef<Expr *> Args, QualType Ty, | |||
| 648 | ExprValueKind VK, SourceLocation LitEndLoc, | |||
| 649 | SourceLocation SuffixLoc, FPOptionsOverride FPFeatures); | |||
| 650 | ||||
| 651 | UserDefinedLiteral(unsigned NumArgs, bool HasFPFeatures, EmptyShell Empty); | |||
| 652 | ||||
| 653 | public: | |||
| 654 | static UserDefinedLiteral *Create(const ASTContext &Ctx, Expr *Fn, | |||
| 655 | ArrayRef<Expr *> Args, QualType Ty, | |||
| 656 | ExprValueKind VK, SourceLocation LitEndLoc, | |||
| 657 | SourceLocation SuffixLoc, | |||
| 658 | FPOptionsOverride FPFeatures); | |||
| 659 | ||||
| 660 | static UserDefinedLiteral *CreateEmpty(const ASTContext &Ctx, | |||
| 661 | unsigned NumArgs, bool HasFPOptions, | |||
| 662 | EmptyShell Empty); | |||
| 663 | ||||
| 664 | /// The kind of literal operator which is invoked. | |||
| 665 | enum LiteralOperatorKind { | |||
| 666 | /// Raw form: operator "" X (const char *) | |||
| 667 | LOK_Raw, | |||
| 668 | ||||
| 669 | /// Raw form: operator "" X<cs...> () | |||
| 670 | LOK_Template, | |||
| 671 | ||||
| 672 | /// operator "" X (unsigned long long) | |||
| 673 | LOK_Integer, | |||
| 674 | ||||
| 675 | /// operator "" X (long double) | |||
| 676 | LOK_Floating, | |||
| 677 | ||||
| 678 | /// operator "" X (const CharT *, size_t) | |||
| 679 | LOK_String, | |||
| 680 | ||||
| 681 | /// operator "" X (CharT) | |||
| 682 | LOK_Character | |||
| 683 | }; | |||
| 684 | ||||
| 685 | /// Returns the kind of literal operator invocation | |||
| 686 | /// which this expression represents. | |||
| 687 | LiteralOperatorKind getLiteralOperatorKind() const; | |||
| 688 | ||||
| 689 | /// If this is not a raw user-defined literal, get the | |||
| 690 | /// underlying cooked literal (representing the literal with the suffix | |||
| 691 | /// removed). | |||
| 692 | Expr *getCookedLiteral(); | |||
| 693 | const Expr *getCookedLiteral() const { | |||
| 694 | return const_cast<UserDefinedLiteral*>(this)->getCookedLiteral(); | |||
| 695 | } | |||
| 696 | ||||
| 697 | SourceLocation getBeginLoc() const { | |||
| 698 | if (getLiteralOperatorKind() == LOK_Template) | |||
| 699 | return getRParenLoc(); | |||
| 700 | return getArg(0)->getBeginLoc(); | |||
| 701 | } | |||
| 702 | ||||
| 703 | SourceLocation getEndLoc() const { return getRParenLoc(); } | |||
| 704 | ||||
| 705 | /// Returns the location of a ud-suffix in the expression. | |||
| 706 | /// | |||
| 707 | /// For a string literal, there may be multiple identical suffixes. This | |||
| 708 | /// returns the first. | |||
| 709 | SourceLocation getUDSuffixLoc() const { return UDSuffixLoc; } | |||
| 710 | ||||
| 711 | /// Returns the ud-suffix specified for this literal. | |||
| 712 | const IdentifierInfo *getUDSuffix() const; | |||
| 713 | ||||
| 714 | static bool classof(const Stmt *S) { | |||
| 715 | return S->getStmtClass() == UserDefinedLiteralClass; | |||
| 716 | } | |||
| 717 | }; | |||
| 718 | ||||
| 719 | /// A boolean literal, per ([C++ lex.bool] Boolean literals). | |||
| 720 | class CXXBoolLiteralExpr : public Expr { | |||
| 721 | public: | |||
| 722 | CXXBoolLiteralExpr(bool Val, QualType Ty, SourceLocation Loc) | |||
| 723 | : Expr(CXXBoolLiteralExprClass, Ty, VK_PRValue, OK_Ordinary) { | |||
| 724 | CXXBoolLiteralExprBits.Value = Val; | |||
| 725 | CXXBoolLiteralExprBits.Loc = Loc; | |||
| 726 | setDependence(ExprDependence::None); | |||
| 727 | } | |||
| 728 | ||||
| 729 | explicit CXXBoolLiteralExpr(EmptyShell Empty) | |||
| 730 | : Expr(CXXBoolLiteralExprClass, Empty) {} | |||
| 731 | ||||
| 732 | static CXXBoolLiteralExpr *Create(const ASTContext &C, bool Val, QualType Ty, | |||
| 733 | SourceLocation Loc) { | |||
| 734 | return new (C) CXXBoolLiteralExpr(Val, Ty, Loc); | |||
| 735 | } | |||
| 736 | ||||
| 737 | bool getValue() const { return CXXBoolLiteralExprBits.Value; } | |||
| 738 | void setValue(bool V) { CXXBoolLiteralExprBits.Value = V; } | |||
| 739 | ||||
| 740 | SourceLocation getBeginLoc() const { return getLocation(); } | |||
| 741 | SourceLocation getEndLoc() const { return getLocation(); } | |||
| 742 | ||||
| 743 | SourceLocation getLocation() const { return CXXBoolLiteralExprBits.Loc; } | |||
| 744 | void setLocation(SourceLocation L) { CXXBoolLiteralExprBits.Loc = L; } | |||
| 745 | ||||
| 746 | static bool classof(const Stmt *T) { | |||
| 747 | return T->getStmtClass() == CXXBoolLiteralExprClass; | |||
| 748 | } | |||
| 749 | ||||
| 750 | // Iterators | |||
| 751 | child_range children() { | |||
| 752 | return child_range(child_iterator(), child_iterator()); | |||
| 753 | } | |||
| 754 | ||||
| 755 | const_child_range children() const { | |||
| 756 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 757 | } | |||
| 758 | }; | |||
| 759 | ||||
| 760 | /// The null pointer literal (C++11 [lex.nullptr]) | |||
| 761 | /// | |||
| 762 | /// Introduced in C++11, the only literal of type \c nullptr_t is \c nullptr. | |||
| 763 | /// This also implements the null pointer literal in C2x (C2x 6.4.1) which is | |||
| 764 | /// intended to have the same semantics as the feature in C++. | |||
| 765 | class CXXNullPtrLiteralExpr : public Expr { | |||
| 766 | public: | |||
| 767 | CXXNullPtrLiteralExpr(QualType Ty, SourceLocation Loc) | |||
| 768 | : Expr(CXXNullPtrLiteralExprClass, Ty, VK_PRValue, OK_Ordinary) { | |||
| 769 | CXXNullPtrLiteralExprBits.Loc = Loc; | |||
| 770 | setDependence(ExprDependence::None); | |||
| 771 | } | |||
| 772 | ||||
| 773 | explicit CXXNullPtrLiteralExpr(EmptyShell Empty) | |||
| 774 | : Expr(CXXNullPtrLiteralExprClass, Empty) {} | |||
| 775 | ||||
| 776 | SourceLocation getBeginLoc() const { return getLocation(); } | |||
| 777 | SourceLocation getEndLoc() const { return getLocation(); } | |||
| 778 | ||||
| 779 | SourceLocation getLocation() const { return CXXNullPtrLiteralExprBits.Loc; } | |||
| 780 | void setLocation(SourceLocation L) { CXXNullPtrLiteralExprBits.Loc = L; } | |||
| 781 | ||||
| 782 | static bool classof(const Stmt *T) { | |||
| 783 | return T->getStmtClass() == CXXNullPtrLiteralExprClass; | |||
| 784 | } | |||
| 785 | ||||
| 786 | child_range children() { | |||
| 787 | return child_range(child_iterator(), child_iterator()); | |||
| 788 | } | |||
| 789 | ||||
| 790 | const_child_range children() const { | |||
| 791 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 792 | } | |||
| 793 | }; | |||
| 794 | ||||
| 795 | /// Implicit construction of a std::initializer_list<T> object from an | |||
| 796 | /// array temporary within list-initialization (C++11 [dcl.init.list]p5). | |||
| 797 | class CXXStdInitializerListExpr : public Expr { | |||
| 798 | Stmt *SubExpr = nullptr; | |||
| 799 | ||||
| 800 | CXXStdInitializerListExpr(EmptyShell Empty) | |||
| 801 | : Expr(CXXStdInitializerListExprClass, Empty) {} | |||
| 802 | ||||
| 803 | public: | |||
| 804 | friend class ASTReader; | |||
| 805 | friend class ASTStmtReader; | |||
| 806 | ||||
| 807 | CXXStdInitializerListExpr(QualType Ty, Expr *SubExpr) | |||
| 808 | : Expr(CXXStdInitializerListExprClass, Ty, VK_PRValue, OK_Ordinary), | |||
| 809 | SubExpr(SubExpr) { | |||
| 810 | setDependence(computeDependence(this)); | |||
| 811 | } | |||
| 812 | ||||
| 813 | Expr *getSubExpr() { return static_cast<Expr*>(SubExpr); } | |||
| 814 | const Expr *getSubExpr() const { return static_cast<const Expr*>(SubExpr); } | |||
| 815 | ||||
| 816 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 817 | return SubExpr->getBeginLoc(); | |||
| 818 | } | |||
| 819 | ||||
| 820 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 821 | return SubExpr->getEndLoc(); | |||
| 822 | } | |||
| 823 | ||||
| 824 | /// Retrieve the source range of the expression. | |||
| 825 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 826 | return SubExpr->getSourceRange(); | |||
| 827 | } | |||
| 828 | ||||
| 829 | static bool classof(const Stmt *S) { | |||
| 830 | return S->getStmtClass() == CXXStdInitializerListExprClass; | |||
| 831 | } | |||
| 832 | ||||
| 833 | child_range children() { return child_range(&SubExpr, &SubExpr + 1); } | |||
| 834 | ||||
| 835 | const_child_range children() const { | |||
| 836 | return const_child_range(&SubExpr, &SubExpr + 1); | |||
| 837 | } | |||
| 838 | }; | |||
| 839 | ||||
| 840 | /// A C++ \c typeid expression (C++ [expr.typeid]), which gets | |||
| 841 | /// the \c type_info that corresponds to the supplied type, or the (possibly | |||
| 842 | /// dynamic) type of the supplied expression. | |||
| 843 | /// | |||
| 844 | /// This represents code like \c typeid(int) or \c typeid(*objPtr) | |||
| 845 | class CXXTypeidExpr : public Expr { | |||
| 846 | friend class ASTStmtReader; | |||
| 847 | ||||
| 848 | private: | |||
| 849 | llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; | |||
| 850 | SourceRange Range; | |||
| 851 | ||||
| 852 | public: | |||
| 853 | CXXTypeidExpr(QualType Ty, TypeSourceInfo *Operand, SourceRange R) | |||
| 854 | : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), | |||
| 855 | Range(R) { | |||
| 856 | setDependence(computeDependence(this)); | |||
| 857 | } | |||
| 858 | ||||
| 859 | CXXTypeidExpr(QualType Ty, Expr *Operand, SourceRange R) | |||
| 860 | : Expr(CXXTypeidExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), | |||
| 861 | Range(R) { | |||
| 862 | setDependence(computeDependence(this)); | |||
| 863 | } | |||
| 864 | ||||
| 865 | CXXTypeidExpr(EmptyShell Empty, bool isExpr) | |||
| 866 | : Expr(CXXTypeidExprClass, Empty) { | |||
| 867 | if (isExpr) | |||
| 868 | Operand = (Expr*)nullptr; | |||
| 869 | else | |||
| 870 | Operand = (TypeSourceInfo*)nullptr; | |||
| 871 | } | |||
| 872 | ||||
| 873 | /// Determine whether this typeid has a type operand which is potentially | |||
| 874 | /// evaluated, per C++11 [expr.typeid]p3. | |||
| 875 | bool isPotentiallyEvaluated() const; | |||
| 876 | ||||
| 877 | /// Best-effort check if the expression operand refers to a most derived | |||
| 878 | /// object. This is not a strong guarantee. | |||
| 879 | bool isMostDerived(ASTContext &Context) const; | |||
| 880 | ||||
| 881 | bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } | |||
| 882 | ||||
| 883 | /// Retrieves the type operand of this typeid() expression after | |||
| 884 | /// various required adjustments (removing reference types, cv-qualifiers). | |||
| 885 | QualType getTypeOperand(ASTContext &Context) const; | |||
| 886 | ||||
| 887 | /// Retrieve source information for the type operand. | |||
| 888 | TypeSourceInfo *getTypeOperandSourceInfo() const { | |||
| 889 | assert(isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)")(static_cast <bool> (isTypeOperand() && "Cannot call getTypeOperand for typeid(expr)" ) ? void (0) : __assert_fail ("isTypeOperand() && \"Cannot call getTypeOperand for typeid(expr)\"" , "clang/include/clang/AST/ExprCXX.h", 889, __extension__ __PRETTY_FUNCTION__ )); | |||
| 890 | return Operand.get<TypeSourceInfo *>(); | |||
| 891 | } | |||
| 892 | Expr *getExprOperand() const { | |||
| 893 | assert(!isTypeOperand() && "Cannot call getExprOperand for typeid(type)")(static_cast <bool> (!isTypeOperand() && "Cannot call getExprOperand for typeid(type)" ) ? void (0) : __assert_fail ("!isTypeOperand() && \"Cannot call getExprOperand for typeid(type)\"" , "clang/include/clang/AST/ExprCXX.h", 893, __extension__ __PRETTY_FUNCTION__ )); | |||
| 894 | return static_cast<Expr*>(Operand.get<Stmt *>()); | |||
| 895 | } | |||
| 896 | ||||
| 897 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getBegin(); } | |||
| 898 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getEnd(); } | |||
| 899 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { return Range; } | |||
| 900 | void setSourceRange(SourceRange R) { Range = R; } | |||
| 901 | ||||
| 902 | static bool classof(const Stmt *T) { | |||
| 903 | return T->getStmtClass() == CXXTypeidExprClass; | |||
| 904 | } | |||
| 905 | ||||
| 906 | // Iterators | |||
| 907 | child_range children() { | |||
| 908 | if (isTypeOperand()) | |||
| 909 | return child_range(child_iterator(), child_iterator()); | |||
| 910 | auto **begin = reinterpret_cast<Stmt **>(&Operand); | |||
| 911 | return child_range(begin, begin + 1); | |||
| 912 | } | |||
| 913 | ||||
| 914 | const_child_range children() const { | |||
| 915 | if (isTypeOperand()) | |||
| 916 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 917 | ||||
| 918 | auto **begin = | |||
| 919 | reinterpret_cast<Stmt **>(&const_cast<CXXTypeidExpr *>(this)->Operand); | |||
| 920 | return const_child_range(begin, begin + 1); | |||
| 921 | } | |||
| 922 | }; | |||
| 923 | ||||
| 924 | /// A member reference to an MSPropertyDecl. | |||
| 925 | /// | |||
| 926 | /// This expression always has pseudo-object type, and therefore it is | |||
| 927 | /// typically not encountered in a fully-typechecked expression except | |||
| 928 | /// within the syntactic form of a PseudoObjectExpr. | |||
| 929 | class MSPropertyRefExpr : public Expr { | |||
| 930 | Expr *BaseExpr; | |||
| 931 | MSPropertyDecl *TheDecl; | |||
| 932 | SourceLocation MemberLoc; | |||
| 933 | bool IsArrow; | |||
| 934 | NestedNameSpecifierLoc QualifierLoc; | |||
| 935 | ||||
| 936 | public: | |||
| 937 | friend class ASTStmtReader; | |||
| 938 | ||||
| 939 | MSPropertyRefExpr(Expr *baseExpr, MSPropertyDecl *decl, bool isArrow, | |||
| 940 | QualType ty, ExprValueKind VK, | |||
| 941 | NestedNameSpecifierLoc qualifierLoc, SourceLocation nameLoc) | |||
| 942 | : Expr(MSPropertyRefExprClass, ty, VK, OK_Ordinary), BaseExpr(baseExpr), | |||
| 943 | TheDecl(decl), MemberLoc(nameLoc), IsArrow(isArrow), | |||
| 944 | QualifierLoc(qualifierLoc) { | |||
| 945 | setDependence(computeDependence(this)); | |||
| 946 | } | |||
| 947 | ||||
| 948 | MSPropertyRefExpr(EmptyShell Empty) : Expr(MSPropertyRefExprClass, Empty) {} | |||
| 949 | ||||
| 950 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 951 | return SourceRange(getBeginLoc(), getEndLoc()); | |||
| 952 | } | |||
| 953 | ||||
| 954 | bool isImplicitAccess() const { | |||
| 955 | return getBaseExpr() && getBaseExpr()->isImplicitCXXThis(); | |||
| 956 | } | |||
| 957 | ||||
| 958 | SourceLocation getBeginLoc() const { | |||
| 959 | if (!isImplicitAccess()) | |||
| 960 | return BaseExpr->getBeginLoc(); | |||
| 961 | else if (QualifierLoc) | |||
| 962 | return QualifierLoc.getBeginLoc(); | |||
| 963 | else | |||
| 964 | return MemberLoc; | |||
| 965 | } | |||
| 966 | ||||
| 967 | SourceLocation getEndLoc() const { return getMemberLoc(); } | |||
| 968 | ||||
| 969 | child_range children() { | |||
| 970 | return child_range((Stmt**)&BaseExpr, (Stmt**)&BaseExpr + 1); | |||
| 971 | } | |||
| 972 | ||||
| 973 | const_child_range children() const { | |||
| 974 | auto Children = const_cast<MSPropertyRefExpr *>(this)->children(); | |||
| 975 | return const_child_range(Children.begin(), Children.end()); | |||
| 976 | } | |||
| 977 | ||||
| 978 | static bool classof(const Stmt *T) { | |||
| 979 | return T->getStmtClass() == MSPropertyRefExprClass; | |||
| 980 | } | |||
| 981 | ||||
| 982 | Expr *getBaseExpr() const { return BaseExpr; } | |||
| 983 | MSPropertyDecl *getPropertyDecl() const { return TheDecl; } | |||
| 984 | bool isArrow() const { return IsArrow; } | |||
| 985 | SourceLocation getMemberLoc() const { return MemberLoc; } | |||
| 986 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } | |||
| 987 | }; | |||
| 988 | ||||
| 989 | /// MS property subscript expression. | |||
| 990 | /// MSVC supports 'property' attribute and allows to apply it to the | |||
| 991 | /// declaration of an empty array in a class or structure definition. | |||
| 992 | /// For example: | |||
| 993 | /// \code | |||
| 994 | /// __declspec(property(get=GetX, put=PutX)) int x[]; | |||
| 995 | /// \endcode | |||
| 996 | /// The above statement indicates that x[] can be used with one or more array | |||
| 997 | /// indices. In this case, i=p->x[a][b] will be turned into i=p->GetX(a, b), and | |||
| 998 | /// p->x[a][b] = i will be turned into p->PutX(a, b, i). | |||
| 999 | /// This is a syntactic pseudo-object expression. | |||
| 1000 | class MSPropertySubscriptExpr : public Expr { | |||
| 1001 | friend class ASTStmtReader; | |||
| 1002 | ||||
| 1003 | enum { BASE_EXPR, IDX_EXPR, NUM_SUBEXPRS = 2 }; | |||
| 1004 | ||||
| 1005 | Stmt *SubExprs[NUM_SUBEXPRS]; | |||
| 1006 | SourceLocation RBracketLoc; | |||
| 1007 | ||||
| 1008 | void setBase(Expr *Base) { SubExprs[BASE_EXPR] = Base; } | |||
| 1009 | void setIdx(Expr *Idx) { SubExprs[IDX_EXPR] = Idx; } | |||
| 1010 | ||||
| 1011 | public: | |||
| 1012 | MSPropertySubscriptExpr(Expr *Base, Expr *Idx, QualType Ty, ExprValueKind VK, | |||
| 1013 | ExprObjectKind OK, SourceLocation RBracketLoc) | |||
| 1014 | : Expr(MSPropertySubscriptExprClass, Ty, VK, OK), | |||
| 1015 | RBracketLoc(RBracketLoc) { | |||
| 1016 | SubExprs[BASE_EXPR] = Base; | |||
| 1017 | SubExprs[IDX_EXPR] = Idx; | |||
| 1018 | setDependence(computeDependence(this)); | |||
| 1019 | } | |||
| 1020 | ||||
| 1021 | /// Create an empty array subscript expression. | |||
| 1022 | explicit MSPropertySubscriptExpr(EmptyShell Shell) | |||
| 1023 | : Expr(MSPropertySubscriptExprClass, Shell) {} | |||
| 1024 | ||||
| 1025 | Expr *getBase() { return cast<Expr>(SubExprs[BASE_EXPR]); } | |||
| 1026 | const Expr *getBase() const { return cast<Expr>(SubExprs[BASE_EXPR]); } | |||
| 1027 | ||||
| 1028 | Expr *getIdx() { return cast<Expr>(SubExprs[IDX_EXPR]); } | |||
| 1029 | const Expr *getIdx() const { return cast<Expr>(SubExprs[IDX_EXPR]); } | |||
| 1030 | ||||
| 1031 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 1032 | return getBase()->getBeginLoc(); | |||
| 1033 | } | |||
| 1034 | ||||
| 1035 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return RBracketLoc; } | |||
| 1036 | ||||
| 1037 | SourceLocation getRBracketLoc() const { return RBracketLoc; } | |||
| 1038 | void setRBracketLoc(SourceLocation L) { RBracketLoc = L; } | |||
| 1039 | ||||
| 1040 | SourceLocation getExprLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 1041 | return getBase()->getExprLoc(); | |||
| 1042 | } | |||
| 1043 | ||||
| 1044 | static bool classof(const Stmt *T) { | |||
| 1045 | return T->getStmtClass() == MSPropertySubscriptExprClass; | |||
| 1046 | } | |||
| 1047 | ||||
| 1048 | // Iterators | |||
| 1049 | child_range children() { | |||
| 1050 | return child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); | |||
| 1051 | } | |||
| 1052 | ||||
| 1053 | const_child_range children() const { | |||
| 1054 | return const_child_range(&SubExprs[0], &SubExprs[0] + NUM_SUBEXPRS); | |||
| 1055 | } | |||
| 1056 | }; | |||
| 1057 | ||||
| 1058 | /// A Microsoft C++ @c __uuidof expression, which gets | |||
| 1059 | /// the _GUID that corresponds to the supplied type or expression. | |||
| 1060 | /// | |||
| 1061 | /// This represents code like @c __uuidof(COMTYPE) or @c __uuidof(*comPtr) | |||
| 1062 | class CXXUuidofExpr : public Expr { | |||
| 1063 | friend class ASTStmtReader; | |||
| 1064 | ||||
| 1065 | private: | |||
| 1066 | llvm::PointerUnion<Stmt *, TypeSourceInfo *> Operand; | |||
| 1067 | MSGuidDecl *Guid; | |||
| 1068 | SourceRange Range; | |||
| 1069 | ||||
| 1070 | public: | |||
| 1071 | CXXUuidofExpr(QualType Ty, TypeSourceInfo *Operand, MSGuidDecl *Guid, | |||
| 1072 | SourceRange R) | |||
| 1073 | : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), | |||
| 1074 | Guid(Guid), Range(R) { | |||
| 1075 | setDependence(computeDependence(this)); | |||
| 1076 | } | |||
| 1077 | ||||
| 1078 | CXXUuidofExpr(QualType Ty, Expr *Operand, MSGuidDecl *Guid, SourceRange R) | |||
| 1079 | : Expr(CXXUuidofExprClass, Ty, VK_LValue, OK_Ordinary), Operand(Operand), | |||
| 1080 | Guid(Guid), Range(R) { | |||
| 1081 | setDependence(computeDependence(this)); | |||
| 1082 | } | |||
| 1083 | ||||
| 1084 | CXXUuidofExpr(EmptyShell Empty, bool isExpr) | |||
| 1085 | : Expr(CXXUuidofExprClass, Empty) { | |||
| 1086 | if (isExpr) | |||
| 1087 | Operand = (Expr*)nullptr; | |||
| 1088 | else | |||
| 1089 | Operand = (TypeSourceInfo*)nullptr; | |||
| 1090 | } | |||
| 1091 | ||||
| 1092 | bool isTypeOperand() const { return Operand.is<TypeSourceInfo *>(); } | |||
| 1093 | ||||
| 1094 | /// Retrieves the type operand of this __uuidof() expression after | |||
| 1095 | /// various required adjustments (removing reference types, cv-qualifiers). | |||
| 1096 | QualType getTypeOperand(ASTContext &Context) const; | |||
| 1097 | ||||
| 1098 | /// Retrieve source information for the type operand. | |||
| 1099 | TypeSourceInfo *getTypeOperandSourceInfo() const { | |||
| 1100 | assert(isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)")(static_cast <bool> (isTypeOperand() && "Cannot call getTypeOperand for __uuidof(expr)" ) ? void (0) : __assert_fail ("isTypeOperand() && \"Cannot call getTypeOperand for __uuidof(expr)\"" , "clang/include/clang/AST/ExprCXX.h", 1100, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1101 | return Operand.get<TypeSourceInfo *>(); | |||
| 1102 | } | |||
| 1103 | Expr *getExprOperand() const { | |||
| 1104 | assert(!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)")(static_cast <bool> (!isTypeOperand() && "Cannot call getExprOperand for __uuidof(type)" ) ? void (0) : __assert_fail ("!isTypeOperand() && \"Cannot call getExprOperand for __uuidof(type)\"" , "clang/include/clang/AST/ExprCXX.h", 1104, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1105 | return static_cast<Expr*>(Operand.get<Stmt *>()); | |||
| 1106 | } | |||
| 1107 | ||||
| 1108 | MSGuidDecl *getGuidDecl() const { return Guid; } | |||
| 1109 | ||||
| 1110 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getBegin(); } | |||
| 1111 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return Range.getEnd(); } | |||
| 1112 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { return Range; } | |||
| 1113 | void setSourceRange(SourceRange R) { Range = R; } | |||
| 1114 | ||||
| 1115 | static bool classof(const Stmt *T) { | |||
| 1116 | return T->getStmtClass() == CXXUuidofExprClass; | |||
| 1117 | } | |||
| 1118 | ||||
| 1119 | // Iterators | |||
| 1120 | child_range children() { | |||
| 1121 | if (isTypeOperand()) | |||
| 1122 | return child_range(child_iterator(), child_iterator()); | |||
| 1123 | auto **begin = reinterpret_cast<Stmt **>(&Operand); | |||
| 1124 | return child_range(begin, begin + 1); | |||
| 1125 | } | |||
| 1126 | ||||
| 1127 | const_child_range children() const { | |||
| 1128 | if (isTypeOperand()) | |||
| 1129 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 1130 | auto **begin = | |||
| 1131 | reinterpret_cast<Stmt **>(&const_cast<CXXUuidofExpr *>(this)->Operand); | |||
| 1132 | return const_child_range(begin, begin + 1); | |||
| 1133 | } | |||
| 1134 | }; | |||
| 1135 | ||||
| 1136 | /// Represents the \c this expression in C++. | |||
| 1137 | /// | |||
| 1138 | /// This is a pointer to the object on which the current member function is | |||
| 1139 | /// executing (C++ [expr.prim]p3). Example: | |||
| 1140 | /// | |||
| 1141 | /// \code | |||
| 1142 | /// class Foo { | |||
| 1143 | /// public: | |||
| 1144 | /// void bar(); | |||
| 1145 | /// void test() { this->bar(); } | |||
| 1146 | /// }; | |||
| 1147 | /// \endcode | |||
| 1148 | class CXXThisExpr : public Expr { | |||
| 1149 | public: | |||
| 1150 | CXXThisExpr(SourceLocation L, QualType Ty, bool IsImplicit) | |||
| 1151 | : Expr(CXXThisExprClass, Ty, VK_PRValue, OK_Ordinary) { | |||
| 1152 | CXXThisExprBits.IsImplicit = IsImplicit; | |||
| 1153 | CXXThisExprBits.Loc = L; | |||
| 1154 | setDependence(computeDependence(this)); | |||
| 1155 | } | |||
| 1156 | ||||
| 1157 | CXXThisExpr(EmptyShell Empty) : Expr(CXXThisExprClass, Empty) {} | |||
| 1158 | ||||
| 1159 | SourceLocation getLocation() const { return CXXThisExprBits.Loc; } | |||
| 1160 | void setLocation(SourceLocation L) { CXXThisExprBits.Loc = L; } | |||
| 1161 | ||||
| 1162 | SourceLocation getBeginLoc() const { return getLocation(); } | |||
| 1163 | SourceLocation getEndLoc() const { return getLocation(); } | |||
| 1164 | ||||
| 1165 | bool isImplicit() const { return CXXThisExprBits.IsImplicit; } | |||
| 1166 | void setImplicit(bool I) { CXXThisExprBits.IsImplicit = I; } | |||
| 1167 | ||||
| 1168 | static bool classof(const Stmt *T) { | |||
| 1169 | return T->getStmtClass() == CXXThisExprClass; | |||
| 1170 | } | |||
| 1171 | ||||
| 1172 | // Iterators | |||
| 1173 | child_range children() { | |||
| 1174 | return child_range(child_iterator(), child_iterator()); | |||
| 1175 | } | |||
| 1176 | ||||
| 1177 | const_child_range children() const { | |||
| 1178 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 1179 | } | |||
| 1180 | }; | |||
| 1181 | ||||
| 1182 | /// A C++ throw-expression (C++ [except.throw]). | |||
| 1183 | /// | |||
| 1184 | /// This handles 'throw' (for re-throwing the current exception) and | |||
| 1185 | /// 'throw' assignment-expression. When assignment-expression isn't | |||
| 1186 | /// present, Op will be null. | |||
| 1187 | class CXXThrowExpr : public Expr { | |||
| 1188 | friend class ASTStmtReader; | |||
| 1189 | ||||
| 1190 | /// The optional expression in the throw statement. | |||
| 1191 | Stmt *Operand; | |||
| 1192 | ||||
| 1193 | public: | |||
| 1194 | // \p Ty is the void type which is used as the result type of the | |||
| 1195 | // expression. The \p Loc is the location of the throw keyword. | |||
| 1196 | // \p Operand is the expression in the throw statement, and can be | |||
| 1197 | // null if not present. | |||
| 1198 | CXXThrowExpr(Expr *Operand, QualType Ty, SourceLocation Loc, | |||
| 1199 | bool IsThrownVariableInScope) | |||
| 1200 | : Expr(CXXThrowExprClass, Ty, VK_PRValue, OK_Ordinary), Operand(Operand) { | |||
| 1201 | CXXThrowExprBits.ThrowLoc = Loc; | |||
| 1202 | CXXThrowExprBits.IsThrownVariableInScope = IsThrownVariableInScope; | |||
| 1203 | setDependence(computeDependence(this)); | |||
| 1204 | } | |||
| 1205 | CXXThrowExpr(EmptyShell Empty) : Expr(CXXThrowExprClass, Empty) {} | |||
| 1206 | ||||
| 1207 | const Expr *getSubExpr() const { return cast_or_null<Expr>(Operand); } | |||
| 1208 | Expr *getSubExpr() { return cast_or_null<Expr>(Operand); } | |||
| 1209 | ||||
| 1210 | SourceLocation getThrowLoc() const { return CXXThrowExprBits.ThrowLoc; } | |||
| 1211 | ||||
| 1212 | /// Determines whether the variable thrown by this expression (if any!) | |||
| 1213 | /// is within the innermost try block. | |||
| 1214 | /// | |||
| 1215 | /// This information is required to determine whether the NRVO can apply to | |||
| 1216 | /// this variable. | |||
| 1217 | bool isThrownVariableInScope() const { | |||
| 1218 | return CXXThrowExprBits.IsThrownVariableInScope; | |||
| 1219 | } | |||
| 1220 | ||||
| 1221 | SourceLocation getBeginLoc() const { return getThrowLoc(); } | |||
| 1222 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 1223 | if (!getSubExpr()) | |||
| 1224 | return getThrowLoc(); | |||
| 1225 | return getSubExpr()->getEndLoc(); | |||
| 1226 | } | |||
| 1227 | ||||
| 1228 | static bool classof(const Stmt *T) { | |||
| 1229 | return T->getStmtClass() == CXXThrowExprClass; | |||
| 1230 | } | |||
| 1231 | ||||
| 1232 | // Iterators | |||
| 1233 | child_range children() { | |||
| 1234 | return child_range(&Operand, Operand ? &Operand + 1 : &Operand); | |||
| 1235 | } | |||
| 1236 | ||||
| 1237 | const_child_range children() const { | |||
| 1238 | return const_child_range(&Operand, Operand ? &Operand + 1 : &Operand); | |||
| 1239 | } | |||
| 1240 | }; | |||
| 1241 | ||||
| 1242 | /// A default argument (C++ [dcl.fct.default]). | |||
| 1243 | /// | |||
| 1244 | /// This wraps up a function call argument that was created from the | |||
| 1245 | /// corresponding parameter's default argument, when the call did not | |||
| 1246 | /// explicitly supply arguments for all of the parameters. | |||
| 1247 | class CXXDefaultArgExpr final | |||
| 1248 | : public Expr, | |||
| 1249 | private llvm::TrailingObjects<CXXDefaultArgExpr, Expr *> { | |||
| 1250 | friend class ASTStmtReader; | |||
| 1251 | friend class ASTReader; | |||
| 1252 | friend TrailingObjects; | |||
| 1253 | ||||
| 1254 | /// The parameter whose default is being used. | |||
| 1255 | ParmVarDecl *Param; | |||
| 1256 | ||||
| 1257 | /// The context where the default argument expression was used. | |||
| 1258 | DeclContext *UsedContext; | |||
| 1259 | ||||
| 1260 | CXXDefaultArgExpr(StmtClass SC, SourceLocation Loc, ParmVarDecl *Param, | |||
| 1261 | Expr *RewrittenExpr, DeclContext *UsedContext) | |||
| 1262 | : Expr(SC, | |||
| 1263 | Param->hasUnparsedDefaultArg() | |||
| 1264 | ? Param->getType().getNonReferenceType() | |||
| 1265 | : Param->getDefaultArg()->getType(), | |||
| 1266 | Param->getDefaultArg()->getValueKind(), | |||
| 1267 | Param->getDefaultArg()->getObjectKind()), | |||
| 1268 | Param(Param), UsedContext(UsedContext) { | |||
| 1269 | CXXDefaultArgExprBits.Loc = Loc; | |||
| 1270 | CXXDefaultArgExprBits.HasRewrittenInit = RewrittenExpr != nullptr; | |||
| 1271 | if (RewrittenExpr) | |||
| 1272 | *getTrailingObjects<Expr *>() = RewrittenExpr; | |||
| 1273 | setDependence(computeDependence(this)); | |||
| 1274 | } | |||
| 1275 | ||||
| 1276 | CXXDefaultArgExpr(EmptyShell Empty, bool HasRewrittenInit) | |||
| 1277 | : Expr(CXXDefaultArgExprClass, Empty) { | |||
| 1278 | CXXDefaultArgExprBits.HasRewrittenInit = HasRewrittenInit; | |||
| 1279 | } | |||
| 1280 | ||||
| 1281 | public: | |||
| 1282 | static CXXDefaultArgExpr *CreateEmpty(const ASTContext &C, | |||
| 1283 | bool HasRewrittenInit); | |||
| 1284 | ||||
| 1285 | // \p Param is the parameter whose default argument is used by this | |||
| 1286 | // expression. | |||
| 1287 | static CXXDefaultArgExpr *Create(const ASTContext &C, SourceLocation Loc, | |||
| 1288 | ParmVarDecl *Param, Expr *RewrittenExpr, | |||
| 1289 | DeclContext *UsedContext); | |||
| 1290 | // Retrieve the parameter that the argument was created from. | |||
| 1291 | const ParmVarDecl *getParam() const { return Param; } | |||
| 1292 | ParmVarDecl *getParam() { return Param; } | |||
| 1293 | ||||
| 1294 | bool hasRewrittenInit() const { | |||
| 1295 | return CXXDefaultArgExprBits.HasRewrittenInit; | |||
| 1296 | } | |||
| 1297 | ||||
| 1298 | // Retrieve the argument to the function call. | |||
| 1299 | Expr *getExpr(); | |||
| 1300 | const Expr *getExpr() const { | |||
| 1301 | return const_cast<CXXDefaultArgExpr *>(this)->getExpr(); | |||
| 1302 | } | |||
| 1303 | ||||
| 1304 | Expr *getRewrittenExpr() { | |||
| 1305 | return hasRewrittenInit() ? *getTrailingObjects<Expr *>() : nullptr; | |||
| 1306 | } | |||
| 1307 | ||||
| 1308 | const Expr *getRewrittenExpr() const { | |||
| 1309 | return const_cast<CXXDefaultArgExpr *>(this)->getRewrittenExpr(); | |||
| 1310 | } | |||
| 1311 | ||||
| 1312 | // Retrieve the rewritten init expression (for an init expression containing | |||
| 1313 | // immediate calls) with the top level FullExpr and ConstantExpr stripped off. | |||
| 1314 | Expr *getAdjustedRewrittenExpr(); | |||
| 1315 | const Expr *getAdjustedRewrittenExpr() const { | |||
| 1316 | return const_cast<CXXDefaultArgExpr *>(this)->getAdjustedRewrittenExpr(); | |||
| 1317 | } | |||
| 1318 | ||||
| 1319 | const DeclContext *getUsedContext() const { return UsedContext; } | |||
| 1320 | DeclContext *getUsedContext() { return UsedContext; } | |||
| 1321 | ||||
| 1322 | /// Retrieve the location where this default argument was actually used. | |||
| 1323 | SourceLocation getUsedLocation() const { return CXXDefaultArgExprBits.Loc; } | |||
| 1324 | ||||
| 1325 | /// Default argument expressions have no representation in the | |||
| 1326 | /// source, so they have an empty source range. | |||
| 1327 | SourceLocation getBeginLoc() const { return SourceLocation(); } | |||
| 1328 | SourceLocation getEndLoc() const { return SourceLocation(); } | |||
| 1329 | ||||
| 1330 | SourceLocation getExprLoc() const { return getUsedLocation(); } | |||
| 1331 | ||||
| 1332 | static bool classof(const Stmt *T) { | |||
| 1333 | return T->getStmtClass() == CXXDefaultArgExprClass; | |||
| 1334 | } | |||
| 1335 | ||||
| 1336 | // Iterators | |||
| 1337 | child_range children() { | |||
| 1338 | return child_range(child_iterator(), child_iterator()); | |||
| 1339 | } | |||
| 1340 | ||||
| 1341 | const_child_range children() const { | |||
| 1342 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 1343 | } | |||
| 1344 | }; | |||
| 1345 | ||||
| 1346 | /// A use of a default initializer in a constructor or in aggregate | |||
| 1347 | /// initialization. | |||
| 1348 | /// | |||
| 1349 | /// This wraps a use of a C++ default initializer (technically, | |||
| 1350 | /// a brace-or-equal-initializer for a non-static data member) when it | |||
| 1351 | /// is implicitly used in a mem-initializer-list in a constructor | |||
| 1352 | /// (C++11 [class.base.init]p8) or in aggregate initialization | |||
| 1353 | /// (C++1y [dcl.init.aggr]p7). | |||
| 1354 | class CXXDefaultInitExpr final | |||
| 1355 | : public Expr, | |||
| 1356 | private llvm::TrailingObjects<CXXDefaultInitExpr, Expr *> { | |||
| 1357 | ||||
| 1358 | friend class ASTStmtReader; | |||
| 1359 | friend class ASTReader; | |||
| 1360 | friend TrailingObjects; | |||
| 1361 | /// The field whose default is being used. | |||
| 1362 | FieldDecl *Field; | |||
| 1363 | ||||
| 1364 | /// The context where the default initializer expression was used. | |||
| 1365 | DeclContext *UsedContext; | |||
| 1366 | ||||
| 1367 | CXXDefaultInitExpr(const ASTContext &Ctx, SourceLocation Loc, | |||
| 1368 | FieldDecl *Field, QualType Ty, DeclContext *UsedContext, | |||
| 1369 | Expr *RewrittenInitExpr); | |||
| 1370 | ||||
| 1371 | CXXDefaultInitExpr(EmptyShell Empty, bool HasRewrittenInit) | |||
| 1372 | : Expr(CXXDefaultInitExprClass, Empty) { | |||
| 1373 | CXXDefaultInitExprBits.HasRewrittenInit = HasRewrittenInit; | |||
| 1374 | } | |||
| 1375 | ||||
| 1376 | public: | |||
| 1377 | static CXXDefaultInitExpr *CreateEmpty(const ASTContext &C, | |||
| 1378 | bool HasRewrittenInit); | |||
| 1379 | /// \p Field is the non-static data member whose default initializer is used | |||
| 1380 | /// by this expression. | |||
| 1381 | static CXXDefaultInitExpr *Create(const ASTContext &Ctx, SourceLocation Loc, | |||
| 1382 | FieldDecl *Field, DeclContext *UsedContext, | |||
| 1383 | Expr *RewrittenInitExpr); | |||
| 1384 | ||||
| 1385 | bool hasRewrittenInit() const { | |||
| 1386 | return CXXDefaultInitExprBits.HasRewrittenInit; | |||
| 1387 | } | |||
| 1388 | ||||
| 1389 | /// Get the field whose initializer will be used. | |||
| 1390 | FieldDecl *getField() { return Field; } | |||
| 1391 | const FieldDecl *getField() const { return Field; } | |||
| 1392 | ||||
| 1393 | /// Get the initialization expression that will be used. | |||
| 1394 | Expr *getExpr(); | |||
| 1395 | const Expr *getExpr() const { | |||
| 1396 | return const_cast<CXXDefaultInitExpr *>(this)->getExpr(); | |||
| 1397 | } | |||
| 1398 | ||||
| 1399 | /// Retrieve the initializing expression with evaluated immediate calls, if | |||
| 1400 | /// any. | |||
| 1401 | const Expr *getRewrittenExpr() const { | |||
| 1402 | assert(hasRewrittenInit() && "expected a rewritten init expression")(static_cast <bool> (hasRewrittenInit() && "expected a rewritten init expression" ) ? void (0) : __assert_fail ("hasRewrittenInit() && \"expected a rewritten init expression\"" , "clang/include/clang/AST/ExprCXX.h", 1402, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1403 | return *getTrailingObjects<Expr *>(); | |||
| 1404 | } | |||
| 1405 | ||||
| 1406 | /// Retrieve the initializing expression with evaluated immediate calls, if | |||
| 1407 | /// any. | |||
| 1408 | Expr *getRewrittenExpr() { | |||
| 1409 | assert(hasRewrittenInit() && "expected a rewritten init expression")(static_cast <bool> (hasRewrittenInit() && "expected a rewritten init expression" ) ? void (0) : __assert_fail ("hasRewrittenInit() && \"expected a rewritten init expression\"" , "clang/include/clang/AST/ExprCXX.h", 1409, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1410 | return *getTrailingObjects<Expr *>(); | |||
| 1411 | } | |||
| 1412 | ||||
| 1413 | const DeclContext *getUsedContext() const { return UsedContext; } | |||
| 1414 | DeclContext *getUsedContext() { return UsedContext; } | |||
| 1415 | ||||
| 1416 | /// Retrieve the location where this default initializer expression was | |||
| 1417 | /// actually used. | |||
| 1418 | SourceLocation getUsedLocation() const { return getBeginLoc(); } | |||
| 1419 | ||||
| 1420 | SourceLocation getBeginLoc() const { return CXXDefaultInitExprBits.Loc; } | |||
| 1421 | SourceLocation getEndLoc() const { return CXXDefaultInitExprBits.Loc; } | |||
| 1422 | ||||
| 1423 | static bool classof(const Stmt *T) { | |||
| 1424 | return T->getStmtClass() == CXXDefaultInitExprClass; | |||
| 1425 | } | |||
| 1426 | ||||
| 1427 | // Iterators | |||
| 1428 | child_range children() { | |||
| 1429 | return child_range(child_iterator(), child_iterator()); | |||
| 1430 | } | |||
| 1431 | ||||
| 1432 | const_child_range children() const { | |||
| 1433 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 1434 | } | |||
| 1435 | }; | |||
| 1436 | ||||
| 1437 | /// Represents a C++ temporary. | |||
| 1438 | class CXXTemporary { | |||
| 1439 | /// The destructor that needs to be called. | |||
| 1440 | const CXXDestructorDecl *Destructor; | |||
| 1441 | ||||
| 1442 | explicit CXXTemporary(const CXXDestructorDecl *destructor) | |||
| 1443 | : Destructor(destructor) {} | |||
| 1444 | ||||
| 1445 | public: | |||
| 1446 | static CXXTemporary *Create(const ASTContext &C, | |||
| 1447 | const CXXDestructorDecl *Destructor); | |||
| 1448 | ||||
| 1449 | const CXXDestructorDecl *getDestructor() const { return Destructor; } | |||
| 1450 | ||||
| 1451 | void setDestructor(const CXXDestructorDecl *Dtor) { | |||
| 1452 | Destructor = Dtor; | |||
| 1453 | } | |||
| 1454 | }; | |||
| 1455 | ||||
| 1456 | /// Represents binding an expression to a temporary. | |||
| 1457 | /// | |||
| 1458 | /// This ensures the destructor is called for the temporary. It should only be | |||
| 1459 | /// needed for non-POD, non-trivially destructable class types. For example: | |||
| 1460 | /// | |||
| 1461 | /// \code | |||
| 1462 | /// struct S { | |||
| 1463 | /// S() { } // User defined constructor makes S non-POD. | |||
| 1464 | /// ~S() { } // User defined destructor makes it non-trivial. | |||
| 1465 | /// }; | |||
| 1466 | /// void test() { | |||
| 1467 | /// const S &s_ref = S(); // Requires a CXXBindTemporaryExpr. | |||
| 1468 | /// } | |||
| 1469 | /// \endcode | |||
| 1470 | class CXXBindTemporaryExpr : public Expr { | |||
| 1471 | CXXTemporary *Temp = nullptr; | |||
| 1472 | Stmt *SubExpr = nullptr; | |||
| 1473 | ||||
| 1474 | CXXBindTemporaryExpr(CXXTemporary *temp, Expr *SubExpr) | |||
| 1475 | : Expr(CXXBindTemporaryExprClass, SubExpr->getType(), VK_PRValue, | |||
| 1476 | OK_Ordinary), | |||
| 1477 | Temp(temp), SubExpr(SubExpr) { | |||
| 1478 | setDependence(computeDependence(this)); | |||
| 1479 | } | |||
| 1480 | ||||
| 1481 | public: | |||
| 1482 | CXXBindTemporaryExpr(EmptyShell Empty) | |||
| 1483 | : Expr(CXXBindTemporaryExprClass, Empty) {} | |||
| 1484 | ||||
| 1485 | static CXXBindTemporaryExpr *Create(const ASTContext &C, CXXTemporary *Temp, | |||
| 1486 | Expr* SubExpr); | |||
| 1487 | ||||
| 1488 | CXXTemporary *getTemporary() { return Temp; } | |||
| 1489 | const CXXTemporary *getTemporary() const { return Temp; } | |||
| 1490 | void setTemporary(CXXTemporary *T) { Temp = T; } | |||
| 1491 | ||||
| 1492 | const Expr *getSubExpr() const { return cast<Expr>(SubExpr); } | |||
| 1493 | Expr *getSubExpr() { return cast<Expr>(SubExpr); } | |||
| 1494 | void setSubExpr(Expr *E) { SubExpr = E; } | |||
| 1495 | ||||
| 1496 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 1497 | return SubExpr->getBeginLoc(); | |||
| 1498 | } | |||
| 1499 | ||||
| 1500 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 1501 | return SubExpr->getEndLoc(); | |||
| 1502 | } | |||
| 1503 | ||||
| 1504 | // Implement isa/cast/dyncast/etc. | |||
| 1505 | static bool classof(const Stmt *T) { | |||
| 1506 | return T->getStmtClass() == CXXBindTemporaryExprClass; | |||
| 1507 | } | |||
| 1508 | ||||
| 1509 | // Iterators | |||
| 1510 | child_range children() { return child_range(&SubExpr, &SubExpr + 1); } | |||
| 1511 | ||||
| 1512 | const_child_range children() const { | |||
| 1513 | return const_child_range(&SubExpr, &SubExpr + 1); | |||
| 1514 | } | |||
| 1515 | }; | |||
| 1516 | ||||
| 1517 | /// Represents a call to a C++ constructor. | |||
| 1518 | class CXXConstructExpr : public Expr { | |||
| 1519 | friend class ASTStmtReader; | |||
| 1520 | ||||
| 1521 | public: | |||
| 1522 | enum ConstructionKind { | |||
| 1523 | CK_Complete, | |||
| 1524 | CK_NonVirtualBase, | |||
| 1525 | CK_VirtualBase, | |||
| 1526 | CK_Delegating | |||
| 1527 | }; | |||
| 1528 | ||||
| 1529 | private: | |||
| 1530 | /// A pointer to the constructor which will be ultimately called. | |||
| 1531 | CXXConstructorDecl *Constructor; | |||
| 1532 | ||||
| 1533 | SourceRange ParenOrBraceRange; | |||
| 1534 | ||||
| 1535 | /// The number of arguments. | |||
| 1536 | unsigned NumArgs; | |||
| 1537 | ||||
| 1538 | // We would like to stash the arguments of the constructor call after | |||
| 1539 | // CXXConstructExpr. However CXXConstructExpr is used as a base class of | |||
| 1540 | // CXXTemporaryObjectExpr which makes the use of llvm::TrailingObjects | |||
| 1541 | // impossible. | |||
| 1542 | // | |||
| 1543 | // Instead we manually stash the trailing object after the full object | |||
| 1544 | // containing CXXConstructExpr (that is either CXXConstructExpr or | |||
| 1545 | // CXXTemporaryObjectExpr). | |||
| 1546 | // | |||
| 1547 | // The trailing objects are: | |||
| 1548 | // | |||
| 1549 | // * An array of getNumArgs() "Stmt *" for the arguments of the | |||
| 1550 | // constructor call. | |||
| 1551 | ||||
| 1552 | /// Return a pointer to the start of the trailing arguments. | |||
| 1553 | /// Defined just after CXXTemporaryObjectExpr. | |||
| 1554 | inline Stmt **getTrailingArgs(); | |||
| 1555 | const Stmt *const *getTrailingArgs() const { | |||
| 1556 | return const_cast<CXXConstructExpr *>(this)->getTrailingArgs(); | |||
| 1557 | } | |||
| 1558 | ||||
| 1559 | protected: | |||
| 1560 | /// Build a C++ construction expression. | |||
| 1561 | CXXConstructExpr(StmtClass SC, QualType Ty, SourceLocation Loc, | |||
| 1562 | CXXConstructorDecl *Ctor, bool Elidable, | |||
| 1563 | ArrayRef<Expr *> Args, bool HadMultipleCandidates, | |||
| 1564 | bool ListInitialization, bool StdInitListInitialization, | |||
| 1565 | bool ZeroInitialization, ConstructionKind ConstructKind, | |||
| 1566 | SourceRange ParenOrBraceRange); | |||
| 1567 | ||||
| 1568 | /// Build an empty C++ construction expression. | |||
| 1569 | CXXConstructExpr(StmtClass SC, EmptyShell Empty, unsigned NumArgs); | |||
| 1570 | ||||
| 1571 | /// Return the size in bytes of the trailing objects. Used by | |||
| 1572 | /// CXXTemporaryObjectExpr to allocate the right amount of storage. | |||
| 1573 | static unsigned sizeOfTrailingObjects(unsigned NumArgs) { | |||
| 1574 | return NumArgs * sizeof(Stmt *); | |||
| 1575 | } | |||
| 1576 | ||||
| 1577 | public: | |||
| 1578 | /// Create a C++ construction expression. | |||
| 1579 | static CXXConstructExpr * | |||
| 1580 | Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, | |||
| 1581 | CXXConstructorDecl *Ctor, bool Elidable, ArrayRef<Expr *> Args, | |||
| 1582 | bool HadMultipleCandidates, bool ListInitialization, | |||
| 1583 | bool StdInitListInitialization, bool ZeroInitialization, | |||
| 1584 | ConstructionKind ConstructKind, SourceRange ParenOrBraceRange); | |||
| 1585 | ||||
| 1586 | /// Create an empty C++ construction expression. | |||
| 1587 | static CXXConstructExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumArgs); | |||
| 1588 | ||||
| 1589 | /// Get the constructor that this expression will (ultimately) call. | |||
| 1590 | CXXConstructorDecl *getConstructor() const { return Constructor; } | |||
| 1591 | ||||
| 1592 | SourceLocation getLocation() const { return CXXConstructExprBits.Loc; } | |||
| 1593 | void setLocation(SourceLocation Loc) { CXXConstructExprBits.Loc = Loc; } | |||
| 1594 | ||||
| 1595 | /// Whether this construction is elidable. | |||
| 1596 | bool isElidable() const { return CXXConstructExprBits.Elidable; } | |||
| 1597 | void setElidable(bool E) { CXXConstructExprBits.Elidable = E; } | |||
| 1598 | ||||
| 1599 | /// Whether the referred constructor was resolved from | |||
| 1600 | /// an overloaded set having size greater than 1. | |||
| 1601 | bool hadMultipleCandidates() const { | |||
| 1602 | return CXXConstructExprBits.HadMultipleCandidates; | |||
| 1603 | } | |||
| 1604 | void setHadMultipleCandidates(bool V) { | |||
| 1605 | CXXConstructExprBits.HadMultipleCandidates = V; | |||
| 1606 | } | |||
| 1607 | ||||
| 1608 | /// Whether this constructor call was written as list-initialization. | |||
| 1609 | bool isListInitialization() const { | |||
| 1610 | return CXXConstructExprBits.ListInitialization; | |||
| 1611 | } | |||
| 1612 | void setListInitialization(bool V) { | |||
| 1613 | CXXConstructExprBits.ListInitialization = V; | |||
| 1614 | } | |||
| 1615 | ||||
| 1616 | /// Whether this constructor call was written as list-initialization, | |||
| 1617 | /// but was interpreted as forming a std::initializer_list<T> from the list | |||
| 1618 | /// and passing that as a single constructor argument. | |||
| 1619 | /// See C++11 [over.match.list]p1 bullet 1. | |||
| 1620 | bool isStdInitListInitialization() const { | |||
| 1621 | return CXXConstructExprBits.StdInitListInitialization; | |||
| 1622 | } | |||
| 1623 | void setStdInitListInitialization(bool V) { | |||
| 1624 | CXXConstructExprBits.StdInitListInitialization = V; | |||
| 1625 | } | |||
| 1626 | ||||
| 1627 | /// Whether this construction first requires | |||
| 1628 | /// zero-initialization before the initializer is called. | |||
| 1629 | bool requiresZeroInitialization() const { | |||
| 1630 | return CXXConstructExprBits.ZeroInitialization; | |||
| 1631 | } | |||
| 1632 | void setRequiresZeroInitialization(bool ZeroInit) { | |||
| 1633 | CXXConstructExprBits.ZeroInitialization = ZeroInit; | |||
| 1634 | } | |||
| 1635 | ||||
| 1636 | /// Determine whether this constructor is actually constructing | |||
| 1637 | /// a base class (rather than a complete object). | |||
| 1638 | ConstructionKind getConstructionKind() const { | |||
| 1639 | return static_cast<ConstructionKind>(CXXConstructExprBits.ConstructionKind); | |||
| 1640 | } | |||
| 1641 | void setConstructionKind(ConstructionKind CK) { | |||
| 1642 | CXXConstructExprBits.ConstructionKind = CK; | |||
| 1643 | } | |||
| 1644 | ||||
| 1645 | using arg_iterator = ExprIterator; | |||
| 1646 | using const_arg_iterator = ConstExprIterator; | |||
| 1647 | using arg_range = llvm::iterator_range<arg_iterator>; | |||
| 1648 | using const_arg_range = llvm::iterator_range<const_arg_iterator>; | |||
| 1649 | ||||
| 1650 | arg_range arguments() { return arg_range(arg_begin(), arg_end()); } | |||
| 1651 | const_arg_range arguments() const { | |||
| 1652 | return const_arg_range(arg_begin(), arg_end()); | |||
| 1653 | } | |||
| 1654 | ||||
| 1655 | arg_iterator arg_begin() { return getTrailingArgs(); } | |||
| 1656 | arg_iterator arg_end() { return arg_begin() + getNumArgs(); } | |||
| 1657 | const_arg_iterator arg_begin() const { return getTrailingArgs(); } | |||
| 1658 | const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } | |||
| 1659 | ||||
| 1660 | Expr **getArgs() { return reinterpret_cast<Expr **>(getTrailingArgs()); } | |||
| 1661 | const Expr *const *getArgs() const { | |||
| 1662 | return reinterpret_cast<const Expr *const *>(getTrailingArgs()); | |||
| 1663 | } | |||
| 1664 | ||||
| 1665 | /// Return the number of arguments to the constructor call. | |||
| 1666 | unsigned getNumArgs() const { return NumArgs; } | |||
| 1667 | ||||
| 1668 | /// Return the specified argument. | |||
| 1669 | Expr *getArg(unsigned Arg) { | |||
| 1670 | assert(Arg < getNumArgs() && "Arg access out of range!")(static_cast <bool> (Arg < getNumArgs() && "Arg access out of range!" ) ? void (0) : __assert_fail ("Arg < getNumArgs() && \"Arg access out of range!\"" , "clang/include/clang/AST/ExprCXX.h", 1670, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1671 | return getArgs()[Arg]; | |||
| 1672 | } | |||
| 1673 | const Expr *getArg(unsigned Arg) const { | |||
| 1674 | assert(Arg < getNumArgs() && "Arg access out of range!")(static_cast <bool> (Arg < getNumArgs() && "Arg access out of range!" ) ? void (0) : __assert_fail ("Arg < getNumArgs() && \"Arg access out of range!\"" , "clang/include/clang/AST/ExprCXX.h", 1674, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1675 | return getArgs()[Arg]; | |||
| 1676 | } | |||
| 1677 | ||||
| 1678 | /// Set the specified argument. | |||
| 1679 | void setArg(unsigned Arg, Expr *ArgExpr) { | |||
| 1680 | assert(Arg < getNumArgs() && "Arg access out of range!")(static_cast <bool> (Arg < getNumArgs() && "Arg access out of range!" ) ? void (0) : __assert_fail ("Arg < getNumArgs() && \"Arg access out of range!\"" , "clang/include/clang/AST/ExprCXX.h", 1680, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1681 | getArgs()[Arg] = ArgExpr; | |||
| 1682 | } | |||
| 1683 | ||||
| 1684 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)); | |||
| 1685 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)); | |||
| 1686 | SourceRange getParenOrBraceRange() const { return ParenOrBraceRange; } | |||
| 1687 | void setParenOrBraceRange(SourceRange Range) { ParenOrBraceRange = Range; } | |||
| 1688 | ||||
| 1689 | static bool classof(const Stmt *T) { | |||
| 1690 | return T->getStmtClass() == CXXConstructExprClass || | |||
| 1691 | T->getStmtClass() == CXXTemporaryObjectExprClass; | |||
| 1692 | } | |||
| 1693 | ||||
| 1694 | // Iterators | |||
| 1695 | child_range children() { | |||
| 1696 | return child_range(getTrailingArgs(), getTrailingArgs() + getNumArgs()); | |||
| 1697 | } | |||
| 1698 | ||||
| 1699 | const_child_range children() const { | |||
| 1700 | auto Children = const_cast<CXXConstructExpr *>(this)->children(); | |||
| 1701 | return const_child_range(Children.begin(), Children.end()); | |||
| 1702 | } | |||
| 1703 | }; | |||
| 1704 | ||||
| 1705 | /// Represents a call to an inherited base class constructor from an | |||
| 1706 | /// inheriting constructor. This call implicitly forwards the arguments from | |||
| 1707 | /// the enclosing context (an inheriting constructor) to the specified inherited | |||
| 1708 | /// base class constructor. | |||
| 1709 | class CXXInheritedCtorInitExpr : public Expr { | |||
| 1710 | private: | |||
| 1711 | CXXConstructorDecl *Constructor = nullptr; | |||
| 1712 | ||||
| 1713 | /// The location of the using declaration. | |||
| 1714 | SourceLocation Loc; | |||
| 1715 | ||||
| 1716 | /// Whether this is the construction of a virtual base. | |||
| 1717 | unsigned ConstructsVirtualBase : 1; | |||
| 1718 | ||||
| 1719 | /// Whether the constructor is inherited from a virtual base class of the | |||
| 1720 | /// class that we construct. | |||
| 1721 | unsigned InheritedFromVirtualBase : 1; | |||
| 1722 | ||||
| 1723 | public: | |||
| 1724 | friend class ASTStmtReader; | |||
| 1725 | ||||
| 1726 | /// Construct a C++ inheriting construction expression. | |||
| 1727 | CXXInheritedCtorInitExpr(SourceLocation Loc, QualType T, | |||
| 1728 | CXXConstructorDecl *Ctor, bool ConstructsVirtualBase, | |||
| 1729 | bool InheritedFromVirtualBase) | |||
| 1730 | : Expr(CXXInheritedCtorInitExprClass, T, VK_PRValue, OK_Ordinary), | |||
| 1731 | Constructor(Ctor), Loc(Loc), | |||
| 1732 | ConstructsVirtualBase(ConstructsVirtualBase), | |||
| 1733 | InheritedFromVirtualBase(InheritedFromVirtualBase) { | |||
| 1734 | assert(!T->isDependentType())(static_cast <bool> (!T->isDependentType()) ? void ( 0) : __assert_fail ("!T->isDependentType()", "clang/include/clang/AST/ExprCXX.h" , 1734, __extension__ __PRETTY_FUNCTION__)); | |||
| 1735 | setDependence(ExprDependence::None); | |||
| 1736 | } | |||
| 1737 | ||||
| 1738 | /// Construct an empty C++ inheriting construction expression. | |||
| 1739 | explicit CXXInheritedCtorInitExpr(EmptyShell Empty) | |||
| 1740 | : Expr(CXXInheritedCtorInitExprClass, Empty), | |||
| 1741 | ConstructsVirtualBase(false), InheritedFromVirtualBase(false) {} | |||
| 1742 | ||||
| 1743 | /// Get the constructor that this expression will call. | |||
| 1744 | CXXConstructorDecl *getConstructor() const { return Constructor; } | |||
| 1745 | ||||
| 1746 | /// Determine whether this constructor is actually constructing | |||
| 1747 | /// a base class (rather than a complete object). | |||
| 1748 | bool constructsVBase() const { return ConstructsVirtualBase; } | |||
| 1749 | CXXConstructExpr::ConstructionKind getConstructionKind() const { | |||
| 1750 | return ConstructsVirtualBase ? CXXConstructExpr::CK_VirtualBase | |||
| 1751 | : CXXConstructExpr::CK_NonVirtualBase; | |||
| 1752 | } | |||
| 1753 | ||||
| 1754 | /// Determine whether the inherited constructor is inherited from a | |||
| 1755 | /// virtual base of the object we construct. If so, we are not responsible | |||
| 1756 | /// for calling the inherited constructor (the complete object constructor | |||
| 1757 | /// does that), and so we don't need to pass any arguments. | |||
| 1758 | bool inheritedFromVBase() const { return InheritedFromVirtualBase; } | |||
| 1759 | ||||
| 1760 | SourceLocation getLocation() const LLVM_READONLY__attribute__((__pure__)) { return Loc; } | |||
| 1761 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Loc; } | |||
| 1762 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return Loc; } | |||
| 1763 | ||||
| 1764 | static bool classof(const Stmt *T) { | |||
| 1765 | return T->getStmtClass() == CXXInheritedCtorInitExprClass; | |||
| 1766 | } | |||
| 1767 | ||||
| 1768 | child_range children() { | |||
| 1769 | return child_range(child_iterator(), child_iterator()); | |||
| 1770 | } | |||
| 1771 | ||||
| 1772 | const_child_range children() const { | |||
| 1773 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 1774 | } | |||
| 1775 | }; | |||
| 1776 | ||||
| 1777 | /// Represents an explicit C++ type conversion that uses "functional" | |||
| 1778 | /// notation (C++ [expr.type.conv]). | |||
| 1779 | /// | |||
| 1780 | /// Example: | |||
| 1781 | /// \code | |||
| 1782 | /// x = int(0.5); | |||
| 1783 | /// \endcode | |||
| 1784 | class CXXFunctionalCastExpr final | |||
| 1785 | : public ExplicitCastExpr, | |||
| 1786 | private llvm::TrailingObjects<CXXFunctionalCastExpr, CXXBaseSpecifier *, | |||
| 1787 | FPOptionsOverride> { | |||
| 1788 | SourceLocation LParenLoc; | |||
| 1789 | SourceLocation RParenLoc; | |||
| 1790 | ||||
| 1791 | CXXFunctionalCastExpr(QualType ty, ExprValueKind VK, | |||
| 1792 | TypeSourceInfo *writtenTy, CastKind kind, | |||
| 1793 | Expr *castExpr, unsigned pathSize, | |||
| 1794 | FPOptionsOverride FPO, SourceLocation lParenLoc, | |||
| 1795 | SourceLocation rParenLoc) | |||
| 1796 | : ExplicitCastExpr(CXXFunctionalCastExprClass, ty, VK, kind, castExpr, | |||
| 1797 | pathSize, FPO.requiresTrailingStorage(), writtenTy), | |||
| 1798 | LParenLoc(lParenLoc), RParenLoc(rParenLoc) { | |||
| 1799 | if (hasStoredFPFeatures()) | |||
| 1800 | *getTrailingFPFeatures() = FPO; | |||
| 1801 | } | |||
| 1802 | ||||
| 1803 | explicit CXXFunctionalCastExpr(EmptyShell Shell, unsigned PathSize, | |||
| 1804 | bool HasFPFeatures) | |||
| 1805 | : ExplicitCastExpr(CXXFunctionalCastExprClass, Shell, PathSize, | |||
| 1806 | HasFPFeatures) {} | |||
| 1807 | ||||
| 1808 | unsigned numTrailingObjects(OverloadToken<CXXBaseSpecifier *>) const { | |||
| 1809 | return path_size(); | |||
| 1810 | } | |||
| 1811 | ||||
| 1812 | public: | |||
| 1813 | friend class CastExpr; | |||
| 1814 | friend TrailingObjects; | |||
| 1815 | ||||
| 1816 | static CXXFunctionalCastExpr * | |||
| 1817 | Create(const ASTContext &Context, QualType T, ExprValueKind VK, | |||
| 1818 | TypeSourceInfo *Written, CastKind Kind, Expr *Op, | |||
| 1819 | const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, | |||
| 1820 | SourceLocation RPLoc); | |||
| 1821 | static CXXFunctionalCastExpr * | |||
| 1822 | CreateEmpty(const ASTContext &Context, unsigned PathSize, bool HasFPFeatures); | |||
| 1823 | ||||
| 1824 | SourceLocation getLParenLoc() const { return LParenLoc; } | |||
| 1825 | void setLParenLoc(SourceLocation L) { LParenLoc = L; } | |||
| 1826 | SourceLocation getRParenLoc() const { return RParenLoc; } | |||
| 1827 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } | |||
| 1828 | ||||
| 1829 | /// Determine whether this expression models list-initialization. | |||
| 1830 | bool isListInitialization() const { return LParenLoc.isInvalid(); } | |||
| 1831 | ||||
| 1832 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)); | |||
| 1833 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)); | |||
| 1834 | ||||
| 1835 | static bool classof(const Stmt *T) { | |||
| 1836 | return T->getStmtClass() == CXXFunctionalCastExprClass; | |||
| 1837 | } | |||
| 1838 | }; | |||
| 1839 | ||||
| 1840 | /// Represents a C++ functional cast expression that builds a | |||
| 1841 | /// temporary object. | |||
| 1842 | /// | |||
| 1843 | /// This expression type represents a C++ "functional" cast | |||
| 1844 | /// (C++[expr.type.conv]) with N != 1 arguments that invokes a | |||
| 1845 | /// constructor to build a temporary object. With N == 1 arguments the | |||
| 1846 | /// functional cast expression will be represented by CXXFunctionalCastExpr. | |||
| 1847 | /// Example: | |||
| 1848 | /// \code | |||
| 1849 | /// struct X { X(int, float); } | |||
| 1850 | /// | |||
| 1851 | /// X create_X() { | |||
| 1852 | /// return X(1, 3.14f); // creates a CXXTemporaryObjectExpr | |||
| 1853 | /// }; | |||
| 1854 | /// \endcode | |||
| 1855 | class CXXTemporaryObjectExpr final : public CXXConstructExpr { | |||
| 1856 | friend class ASTStmtReader; | |||
| 1857 | ||||
| 1858 | // CXXTemporaryObjectExpr has some trailing objects belonging | |||
| 1859 | // to CXXConstructExpr. See the comment inside CXXConstructExpr | |||
| 1860 | // for more details. | |||
| 1861 | ||||
| 1862 | TypeSourceInfo *TSI; | |||
| 1863 | ||||
| 1864 | CXXTemporaryObjectExpr(CXXConstructorDecl *Cons, QualType Ty, | |||
| 1865 | TypeSourceInfo *TSI, ArrayRef<Expr *> Args, | |||
| 1866 | SourceRange ParenOrBraceRange, | |||
| 1867 | bool HadMultipleCandidates, bool ListInitialization, | |||
| 1868 | bool StdInitListInitialization, | |||
| 1869 | bool ZeroInitialization); | |||
| 1870 | ||||
| 1871 | CXXTemporaryObjectExpr(EmptyShell Empty, unsigned NumArgs); | |||
| 1872 | ||||
| 1873 | public: | |||
| 1874 | static CXXTemporaryObjectExpr * | |||
| 1875 | Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, | |||
| 1876 | TypeSourceInfo *TSI, ArrayRef<Expr *> Args, | |||
| 1877 | SourceRange ParenOrBraceRange, bool HadMultipleCandidates, | |||
| 1878 | bool ListInitialization, bool StdInitListInitialization, | |||
| 1879 | bool ZeroInitialization); | |||
| 1880 | ||||
| 1881 | static CXXTemporaryObjectExpr *CreateEmpty(const ASTContext &Ctx, | |||
| 1882 | unsigned NumArgs); | |||
| 1883 | ||||
| 1884 | TypeSourceInfo *getTypeSourceInfo() const { return TSI; } | |||
| 1885 | ||||
| 1886 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)); | |||
| 1887 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)); | |||
| 1888 | ||||
| 1889 | static bool classof(const Stmt *T) { | |||
| 1890 | return T->getStmtClass() == CXXTemporaryObjectExprClass; | |||
| 1891 | } | |||
| 1892 | }; | |||
| 1893 | ||||
| 1894 | Stmt **CXXConstructExpr::getTrailingArgs() { | |||
| 1895 | if (auto *E = dyn_cast<CXXTemporaryObjectExpr>(this)) | |||
| 1896 | return reinterpret_cast<Stmt **>(E + 1); | |||
| 1897 | assert((getStmtClass() == CXXConstructExprClass) &&(static_cast <bool> ((getStmtClass() == CXXConstructExprClass ) && "Unexpected class deriving from CXXConstructExpr!" ) ? void (0) : __assert_fail ("(getStmtClass() == CXXConstructExprClass) && \"Unexpected class deriving from CXXConstructExpr!\"" , "clang/include/clang/AST/ExprCXX.h", 1898, __extension__ __PRETTY_FUNCTION__ )) | |||
| 1898 | "Unexpected class deriving from CXXConstructExpr!")(static_cast <bool> ((getStmtClass() == CXXConstructExprClass ) && "Unexpected class deriving from CXXConstructExpr!" ) ? void (0) : __assert_fail ("(getStmtClass() == CXXConstructExprClass) && \"Unexpected class deriving from CXXConstructExpr!\"" , "clang/include/clang/AST/ExprCXX.h", 1898, __extension__ __PRETTY_FUNCTION__ )); | |||
| 1899 | return reinterpret_cast<Stmt **>(this + 1); | |||
| 1900 | } | |||
| 1901 | ||||
| 1902 | /// A C++ lambda expression, which produces a function object | |||
| 1903 | /// (of unspecified type) that can be invoked later. | |||
| 1904 | /// | |||
| 1905 | /// Example: | |||
| 1906 | /// \code | |||
| 1907 | /// void low_pass_filter(std::vector<double> &values, double cutoff) { | |||
| 1908 | /// values.erase(std::remove_if(values.begin(), values.end(), | |||
| 1909 | /// [=](double value) { return value > cutoff; }); | |||
| 1910 | /// } | |||
| 1911 | /// \endcode | |||
| 1912 | /// | |||
| 1913 | /// C++11 lambda expressions can capture local variables, either by copying | |||
| 1914 | /// the values of those local variables at the time the function | |||
| 1915 | /// object is constructed (not when it is called!) or by holding a | |||
| 1916 | /// reference to the local variable. These captures can occur either | |||
| 1917 | /// implicitly or can be written explicitly between the square | |||
| 1918 | /// brackets ([...]) that start the lambda expression. | |||
| 1919 | /// | |||
| 1920 | /// C++1y introduces a new form of "capture" called an init-capture that | |||
| 1921 | /// includes an initializing expression (rather than capturing a variable), | |||
| 1922 | /// and which can never occur implicitly. | |||
| 1923 | class LambdaExpr final : public Expr, | |||
| 1924 | private llvm::TrailingObjects<LambdaExpr, Stmt *> { | |||
| 1925 | // LambdaExpr has some data stored in LambdaExprBits. | |||
| 1926 | ||||
| 1927 | /// The source range that covers the lambda introducer ([...]). | |||
| 1928 | SourceRange IntroducerRange; | |||
| 1929 | ||||
| 1930 | /// The source location of this lambda's capture-default ('=' or '&'). | |||
| 1931 | SourceLocation CaptureDefaultLoc; | |||
| 1932 | ||||
| 1933 | /// The location of the closing brace ('}') that completes | |||
| 1934 | /// the lambda. | |||
| 1935 | /// | |||
| 1936 | /// The location of the brace is also available by looking up the | |||
| 1937 | /// function call operator in the lambda class. However, it is | |||
| 1938 | /// stored here to improve the performance of getSourceRange(), and | |||
| 1939 | /// to avoid having to deserialize the function call operator from a | |||
| 1940 | /// module file just to determine the source range. | |||
| 1941 | SourceLocation ClosingBrace; | |||
| 1942 | ||||
| 1943 | /// Construct a lambda expression. | |||
| 1944 | LambdaExpr(QualType T, SourceRange IntroducerRange, | |||
| 1945 | LambdaCaptureDefault CaptureDefault, | |||
| 1946 | SourceLocation CaptureDefaultLoc, bool ExplicitParams, | |||
| 1947 | bool ExplicitResultType, ArrayRef<Expr *> CaptureInits, | |||
| 1948 | SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack); | |||
| 1949 | ||||
| 1950 | /// Construct an empty lambda expression. | |||
| 1951 | LambdaExpr(EmptyShell Empty, unsigned NumCaptures); | |||
| 1952 | ||||
| 1953 | Stmt **getStoredStmts() { return getTrailingObjects<Stmt *>(); } | |||
| 1954 | Stmt *const *getStoredStmts() const { return getTrailingObjects<Stmt *>(); } | |||
| 1955 | ||||
| 1956 | void initBodyIfNeeded() const; | |||
| 1957 | ||||
| 1958 | public: | |||
| 1959 | friend class ASTStmtReader; | |||
| 1960 | friend class ASTStmtWriter; | |||
| 1961 | friend TrailingObjects; | |||
| 1962 | ||||
| 1963 | /// Construct a new lambda expression. | |||
| 1964 | static LambdaExpr * | |||
| 1965 | Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, | |||
| 1966 | LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, | |||
| 1967 | bool ExplicitParams, bool ExplicitResultType, | |||
| 1968 | ArrayRef<Expr *> CaptureInits, SourceLocation ClosingBrace, | |||
| 1969 | bool ContainsUnexpandedParameterPack); | |||
| 1970 | ||||
| 1971 | /// Construct a new lambda expression that will be deserialized from | |||
| 1972 | /// an external source. | |||
| 1973 | static LambdaExpr *CreateDeserialized(const ASTContext &C, | |||
| 1974 | unsigned NumCaptures); | |||
| 1975 | ||||
| 1976 | /// Determine the default capture kind for this lambda. | |||
| 1977 | LambdaCaptureDefault getCaptureDefault() const { | |||
| 1978 | return static_cast<LambdaCaptureDefault>(LambdaExprBits.CaptureDefault); | |||
| 1979 | } | |||
| 1980 | ||||
| 1981 | /// Retrieve the location of this lambda's capture-default, if any. | |||
| 1982 | SourceLocation getCaptureDefaultLoc() const { return CaptureDefaultLoc; } | |||
| 1983 | ||||
| 1984 | /// Determine whether one of this lambda's captures is an init-capture. | |||
| 1985 | bool isInitCapture(const LambdaCapture *Capture) const; | |||
| 1986 | ||||
| 1987 | /// An iterator that walks over the captures of the lambda, | |||
| 1988 | /// both implicit and explicit. | |||
| 1989 | using capture_iterator = const LambdaCapture *; | |||
| 1990 | ||||
| 1991 | /// An iterator over a range of lambda captures. | |||
| 1992 | using capture_range = llvm::iterator_range<capture_iterator>; | |||
| 1993 | ||||
| 1994 | /// Retrieve this lambda's captures. | |||
| 1995 | capture_range captures() const; | |||
| 1996 | ||||
| 1997 | /// Retrieve an iterator pointing to the first lambda capture. | |||
| 1998 | capture_iterator capture_begin() const; | |||
| 1999 | ||||
| 2000 | /// Retrieve an iterator pointing past the end of the | |||
| 2001 | /// sequence of lambda captures. | |||
| 2002 | capture_iterator capture_end() const; | |||
| 2003 | ||||
| 2004 | /// Determine the number of captures in this lambda. | |||
| 2005 | unsigned capture_size() const { return LambdaExprBits.NumCaptures; } | |||
| 2006 | ||||
| 2007 | /// Retrieve this lambda's explicit captures. | |||
| 2008 | capture_range explicit_captures() const; | |||
| 2009 | ||||
| 2010 | /// Retrieve an iterator pointing to the first explicit | |||
| 2011 | /// lambda capture. | |||
| 2012 | capture_iterator explicit_capture_begin() const; | |||
| 2013 | ||||
| 2014 | /// Retrieve an iterator pointing past the end of the sequence of | |||
| 2015 | /// explicit lambda captures. | |||
| 2016 | capture_iterator explicit_capture_end() const; | |||
| 2017 | ||||
| 2018 | /// Retrieve this lambda's implicit captures. | |||
| 2019 | capture_range implicit_captures() const; | |||
| 2020 | ||||
| 2021 | /// Retrieve an iterator pointing to the first implicit | |||
| 2022 | /// lambda capture. | |||
| 2023 | capture_iterator implicit_capture_begin() const; | |||
| 2024 | ||||
| 2025 | /// Retrieve an iterator pointing past the end of the sequence of | |||
| 2026 | /// implicit lambda captures. | |||
| 2027 | capture_iterator implicit_capture_end() const; | |||
| 2028 | ||||
| 2029 | /// Iterator that walks over the capture initialization | |||
| 2030 | /// arguments. | |||
| 2031 | using capture_init_iterator = Expr **; | |||
| 2032 | ||||
| 2033 | /// Const iterator that walks over the capture initialization | |||
| 2034 | /// arguments. | |||
| 2035 | /// FIXME: This interface is prone to being used incorrectly. | |||
| 2036 | using const_capture_init_iterator = Expr *const *; | |||
| 2037 | ||||
| 2038 | /// Retrieve the initialization expressions for this lambda's captures. | |||
| 2039 | llvm::iterator_range<capture_init_iterator> capture_inits() { | |||
| 2040 | return llvm::make_range(capture_init_begin(), capture_init_end()); | |||
| 2041 | } | |||
| 2042 | ||||
| 2043 | /// Retrieve the initialization expressions for this lambda's captures. | |||
| 2044 | llvm::iterator_range<const_capture_init_iterator> capture_inits() const { | |||
| 2045 | return llvm::make_range(capture_init_begin(), capture_init_end()); | |||
| 2046 | } | |||
| 2047 | ||||
| 2048 | /// Retrieve the first initialization argument for this | |||
| 2049 | /// lambda expression (which initializes the first capture field). | |||
| 2050 | capture_init_iterator capture_init_begin() { | |||
| 2051 | return reinterpret_cast<Expr **>(getStoredStmts()); | |||
| 2052 | } | |||
| 2053 | ||||
| 2054 | /// Retrieve the first initialization argument for this | |||
| 2055 | /// lambda expression (which initializes the first capture field). | |||
| 2056 | const_capture_init_iterator capture_init_begin() const { | |||
| 2057 | return reinterpret_cast<Expr *const *>(getStoredStmts()); | |||
| 2058 | } | |||
| 2059 | ||||
| 2060 | /// Retrieve the iterator pointing one past the last | |||
| 2061 | /// initialization argument for this lambda expression. | |||
| 2062 | capture_init_iterator capture_init_end() { | |||
| 2063 | return capture_init_begin() + capture_size(); | |||
| 2064 | } | |||
| 2065 | ||||
| 2066 | /// Retrieve the iterator pointing one past the last | |||
| 2067 | /// initialization argument for this lambda expression. | |||
| 2068 | const_capture_init_iterator capture_init_end() const { | |||
| 2069 | return capture_init_begin() + capture_size(); | |||
| 2070 | } | |||
| 2071 | ||||
| 2072 | /// Retrieve the source range covering the lambda introducer, | |||
| 2073 | /// which contains the explicit capture list surrounded by square | |||
| 2074 | /// brackets ([...]). | |||
| 2075 | SourceRange getIntroducerRange() const { return IntroducerRange; } | |||
| 2076 | ||||
| 2077 | /// Retrieve the class that corresponds to the lambda. | |||
| 2078 | /// | |||
| 2079 | /// This is the "closure type" (C++1y [expr.prim.lambda]), and stores the | |||
| 2080 | /// captures in its fields and provides the various operations permitted | |||
| 2081 | /// on a lambda (copying, calling). | |||
| 2082 | CXXRecordDecl *getLambdaClass() const; | |||
| 2083 | ||||
| 2084 | /// Retrieve the function call operator associated with this | |||
| 2085 | /// lambda expression. | |||
| 2086 | CXXMethodDecl *getCallOperator() const; | |||
| 2087 | ||||
| 2088 | /// Retrieve the function template call operator associated with this | |||
| 2089 | /// lambda expression. | |||
| 2090 | FunctionTemplateDecl *getDependentCallOperator() const; | |||
| 2091 | ||||
| 2092 | /// If this is a generic lambda expression, retrieve the template | |||
| 2093 | /// parameter list associated with it, or else return null. | |||
| 2094 | TemplateParameterList *getTemplateParameterList() const; | |||
| 2095 | ||||
| 2096 | /// Get the template parameters were explicitly specified (as opposed to being | |||
| 2097 | /// invented by use of an auto parameter). | |||
| 2098 | ArrayRef<NamedDecl *> getExplicitTemplateParameters() const; | |||
| 2099 | ||||
| 2100 | /// Get the trailing requires clause, if any. | |||
| 2101 | Expr *getTrailingRequiresClause() const; | |||
| 2102 | ||||
| 2103 | /// Whether this is a generic lambda. | |||
| 2104 | bool isGenericLambda() const { return getTemplateParameterList(); } | |||
| 2105 | ||||
| 2106 | /// Retrieve the body of the lambda. This will be most of the time | |||
| 2107 | /// a \p CompoundStmt, but can also be \p CoroutineBodyStmt wrapping | |||
| 2108 | /// a \p CompoundStmt. Note that unlike functions, lambda-expressions | |||
| 2109 | /// cannot have a function-try-block. | |||
| 2110 | Stmt *getBody() const; | |||
| 2111 | ||||
| 2112 | /// Retrieve the \p CompoundStmt representing the body of the lambda. | |||
| 2113 | /// This is a convenience function for callers who do not need | |||
| 2114 | /// to handle node(s) which may wrap a \p CompoundStmt. | |||
| 2115 | const CompoundStmt *getCompoundStmtBody() const; | |||
| 2116 | CompoundStmt *getCompoundStmtBody() { | |||
| 2117 | const auto *ConstThis = this; | |||
| 2118 | return const_cast<CompoundStmt *>(ConstThis->getCompoundStmtBody()); | |||
| 2119 | } | |||
| 2120 | ||||
| 2121 | /// Determine whether the lambda is mutable, meaning that any | |||
| 2122 | /// captures values can be modified. | |||
| 2123 | bool isMutable() const; | |||
| 2124 | ||||
| 2125 | /// Determine whether this lambda has an explicit parameter | |||
| 2126 | /// list vs. an implicit (empty) parameter list. | |||
| 2127 | bool hasExplicitParameters() const { return LambdaExprBits.ExplicitParams; } | |||
| 2128 | ||||
| 2129 | /// Whether this lambda had its result type explicitly specified. | |||
| 2130 | bool hasExplicitResultType() const { | |||
| 2131 | return LambdaExprBits.ExplicitResultType; | |||
| 2132 | } | |||
| 2133 | ||||
| 2134 | static bool classof(const Stmt *T) { | |||
| 2135 | return T->getStmtClass() == LambdaExprClass; | |||
| 2136 | } | |||
| 2137 | ||||
| 2138 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 2139 | return IntroducerRange.getBegin(); | |||
| 2140 | } | |||
| 2141 | ||||
| 2142 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return ClosingBrace; } | |||
| 2143 | ||||
| 2144 | /// Includes the captures and the body of the lambda. | |||
| 2145 | child_range children(); | |||
| 2146 | const_child_range children() const; | |||
| 2147 | }; | |||
| 2148 | ||||
| 2149 | /// An expression "T()" which creates a value-initialized rvalue of type | |||
| 2150 | /// T, which is a non-class type. See (C++98 [5.2.3p2]). | |||
| 2151 | class CXXScalarValueInitExpr : public Expr { | |||
| 2152 | friend class ASTStmtReader; | |||
| 2153 | ||||
| 2154 | TypeSourceInfo *TypeInfo; | |||
| 2155 | ||||
| 2156 | public: | |||
| 2157 | /// Create an explicitly-written scalar-value initialization | |||
| 2158 | /// expression. | |||
| 2159 | CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo, | |||
| 2160 | SourceLocation RParenLoc) | |||
| 2161 | : Expr(CXXScalarValueInitExprClass, Type, VK_PRValue, OK_Ordinary), | |||
| 2162 | TypeInfo(TypeInfo) { | |||
| 2163 | CXXScalarValueInitExprBits.RParenLoc = RParenLoc; | |||
| 2164 | setDependence(computeDependence(this)); | |||
| 2165 | } | |||
| 2166 | ||||
| 2167 | explicit CXXScalarValueInitExpr(EmptyShell Shell) | |||
| 2168 | : Expr(CXXScalarValueInitExprClass, Shell) {} | |||
| 2169 | ||||
| 2170 | TypeSourceInfo *getTypeSourceInfo() const { | |||
| 2171 | return TypeInfo; | |||
| 2172 | } | |||
| 2173 | ||||
| 2174 | SourceLocation getRParenLoc() const { | |||
| 2175 | return CXXScalarValueInitExprBits.RParenLoc; | |||
| 2176 | } | |||
| 2177 | ||||
| 2178 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)); | |||
| 2179 | SourceLocation getEndLoc() const { return getRParenLoc(); } | |||
| 2180 | ||||
| 2181 | static bool classof(const Stmt *T) { | |||
| 2182 | return T->getStmtClass() == CXXScalarValueInitExprClass; | |||
| 2183 | } | |||
| 2184 | ||||
| 2185 | // Iterators | |||
| 2186 | child_range children() { | |||
| 2187 | return child_range(child_iterator(), child_iterator()); | |||
| 2188 | } | |||
| 2189 | ||||
| 2190 | const_child_range children() const { | |||
| 2191 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 2192 | } | |||
| 2193 | }; | |||
| 2194 | ||||
| 2195 | /// Represents a new-expression for memory allocation and constructor | |||
| 2196 | /// calls, e.g: "new CXXNewExpr(foo)". | |||
| 2197 | class CXXNewExpr final | |||
| 2198 | : public Expr, | |||
| 2199 | private llvm::TrailingObjects<CXXNewExpr, Stmt *, SourceRange> { | |||
| 2200 | friend class ASTStmtReader; | |||
| 2201 | friend class ASTStmtWriter; | |||
| 2202 | friend TrailingObjects; | |||
| 2203 | ||||
| 2204 | /// Points to the allocation function used. | |||
| 2205 | FunctionDecl *OperatorNew; | |||
| 2206 | ||||
| 2207 | /// Points to the deallocation function used in case of error. May be null. | |||
| 2208 | FunctionDecl *OperatorDelete; | |||
| 2209 | ||||
| 2210 | /// The allocated type-source information, as written in the source. | |||
| 2211 | TypeSourceInfo *AllocatedTypeInfo; | |||
| 2212 | ||||
| 2213 | /// Range of the entire new expression. | |||
| 2214 | SourceRange Range; | |||
| 2215 | ||||
| 2216 | /// Source-range of a paren-delimited initializer. | |||
| 2217 | SourceRange DirectInitRange; | |||
| 2218 | ||||
| 2219 | // CXXNewExpr is followed by several optional trailing objects. | |||
| 2220 | // They are in order: | |||
| 2221 | // | |||
| 2222 | // * An optional "Stmt *" for the array size expression. | |||
| 2223 | // Present if and ony if isArray(). | |||
| 2224 | // | |||
| 2225 | // * An optional "Stmt *" for the init expression. | |||
| 2226 | // Present if and only if hasInitializer(). | |||
| 2227 | // | |||
| 2228 | // * An array of getNumPlacementArgs() "Stmt *" for the placement new | |||
| 2229 | // arguments, if any. | |||
| 2230 | // | |||
| 2231 | // * An optional SourceRange for the range covering the parenthesized type-id | |||
| 2232 | // if the allocated type was expressed as a parenthesized type-id. | |||
| 2233 | // Present if and only if isParenTypeId(). | |||
| 2234 | unsigned arraySizeOffset() const { return 0; } | |||
| 2235 | unsigned initExprOffset() const { return arraySizeOffset() + isArray(); } | |||
| 2236 | unsigned placementNewArgsOffset() const { | |||
| 2237 | return initExprOffset() + hasInitializer(); | |||
| 2238 | } | |||
| 2239 | ||||
| 2240 | unsigned numTrailingObjects(OverloadToken<Stmt *>) const { | |||
| 2241 | return isArray() + hasInitializer() + getNumPlacementArgs(); | |||
| 2242 | } | |||
| 2243 | ||||
| 2244 | unsigned numTrailingObjects(OverloadToken<SourceRange>) const { | |||
| 2245 | return isParenTypeId(); | |||
| 2246 | } | |||
| 2247 | ||||
| 2248 | public: | |||
| 2249 | enum InitializationStyle { | |||
| 2250 | /// New-expression has no initializer as written. | |||
| 2251 | NoInit, | |||
| 2252 | ||||
| 2253 | /// New-expression has a C++98 paren-delimited initializer. | |||
| 2254 | CallInit, | |||
| 2255 | ||||
| 2256 | /// New-expression has a C++11 list-initializer. | |||
| 2257 | ListInit | |||
| 2258 | }; | |||
| 2259 | ||||
| 2260 | private: | |||
| 2261 | /// Build a c++ new expression. | |||
| 2262 | CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew, | |||
| 2263 | FunctionDecl *OperatorDelete, bool ShouldPassAlignment, | |||
| 2264 | bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, | |||
| 2265 | SourceRange TypeIdParens, std::optional<Expr *> ArraySize, | |||
| 2266 | InitializationStyle InitializationStyle, Expr *Initializer, | |||
| 2267 | QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, | |||
| 2268 | SourceRange DirectInitRange); | |||
| 2269 | ||||
| 2270 | /// Build an empty c++ new expression. | |||
| 2271 | CXXNewExpr(EmptyShell Empty, bool IsArray, unsigned NumPlacementArgs, | |||
| 2272 | bool IsParenTypeId); | |||
| 2273 | ||||
| 2274 | public: | |||
| 2275 | /// Create a c++ new expression. | |||
| 2276 | static CXXNewExpr * | |||
| 2277 | Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, | |||
| 2278 | FunctionDecl *OperatorDelete, bool ShouldPassAlignment, | |||
| 2279 | bool UsualArrayDeleteWantsSize, ArrayRef<Expr *> PlacementArgs, | |||
| 2280 | SourceRange TypeIdParens, std::optional<Expr *> ArraySize, | |||
| 2281 | InitializationStyle InitializationStyle, Expr *Initializer, | |||
| 2282 | QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, | |||
| 2283 | SourceRange DirectInitRange); | |||
| 2284 | ||||
| 2285 | /// Create an empty c++ new expression. | |||
| 2286 | static CXXNewExpr *CreateEmpty(const ASTContext &Ctx, bool IsArray, | |||
| 2287 | bool HasInit, unsigned NumPlacementArgs, | |||
| 2288 | bool IsParenTypeId); | |||
| 2289 | ||||
| 2290 | QualType getAllocatedType() const { | |||
| 2291 | return getType()->castAs<PointerType>()->getPointeeType(); | |||
| 2292 | } | |||
| 2293 | ||||
| 2294 | TypeSourceInfo *getAllocatedTypeSourceInfo() const { | |||
| 2295 | return AllocatedTypeInfo; | |||
| 2296 | } | |||
| 2297 | ||||
| 2298 | /// True if the allocation result needs to be null-checked. | |||
| 2299 | /// | |||
| 2300 | /// C++11 [expr.new]p13: | |||
| 2301 | /// If the allocation function returns null, initialization shall | |||
| 2302 | /// not be done, the deallocation function shall not be called, | |||
| 2303 | /// and the value of the new-expression shall be null. | |||
| 2304 | /// | |||
| 2305 | /// C++ DR1748: | |||
| 2306 | /// If the allocation function is a reserved placement allocation | |||
| 2307 | /// function that returns null, the behavior is undefined. | |||
| 2308 | /// | |||
| 2309 | /// An allocation function is not allowed to return null unless it | |||
| 2310 | /// has a non-throwing exception-specification. The '03 rule is | |||
| 2311 | /// identical except that the definition of a non-throwing | |||
| 2312 | /// exception specification is just "is it throw()?". | |||
| 2313 | bool shouldNullCheckAllocation() const; | |||
| 2314 | ||||
| 2315 | FunctionDecl *getOperatorNew() const { return OperatorNew; } | |||
| 2316 | void setOperatorNew(FunctionDecl *D) { OperatorNew = D; } | |||
| 2317 | FunctionDecl *getOperatorDelete() const { return OperatorDelete; } | |||
| 2318 | void setOperatorDelete(FunctionDecl *D) { OperatorDelete = D; } | |||
| 2319 | ||||
| 2320 | bool isArray() const { return CXXNewExprBits.IsArray; } | |||
| 2321 | ||||
| 2322 | /// This might return std::nullopt even if isArray() returns true, | |||
| 2323 | /// since there might not be an array size expression. | |||
| 2324 | /// If the result is not std::nullopt, it will never wrap a nullptr. | |||
| 2325 | std::optional<Expr *> getArraySize() { | |||
| 2326 | if (!isArray()) | |||
| 2327 | return std::nullopt; | |||
| 2328 | ||||
| 2329 | if (auto *Result = | |||
| 2330 | cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()])) | |||
| 2331 | return Result; | |||
| 2332 | ||||
| 2333 | return std::nullopt; | |||
| 2334 | } | |||
| 2335 | ||||
| 2336 | /// This might return std::nullopt even if isArray() returns true, | |||
| 2337 | /// since there might not be an array size expression. | |||
| 2338 | /// If the result is not std::nullopt, it will never wrap a nullptr. | |||
| 2339 | std::optional<const Expr *> getArraySize() const { | |||
| 2340 | if (!isArray()) | |||
| 2341 | return std::nullopt; | |||
| 2342 | ||||
| 2343 | if (auto *Result = | |||
| 2344 | cast_or_null<Expr>(getTrailingObjects<Stmt *>()[arraySizeOffset()])) | |||
| 2345 | return Result; | |||
| 2346 | ||||
| 2347 | return std::nullopt; | |||
| 2348 | } | |||
| 2349 | ||||
| 2350 | unsigned getNumPlacementArgs() const { | |||
| 2351 | return CXXNewExprBits.NumPlacementArgs; | |||
| 2352 | } | |||
| 2353 | ||||
| 2354 | Expr **getPlacementArgs() { | |||
| 2355 | return reinterpret_cast<Expr **>(getTrailingObjects<Stmt *>() + | |||
| 2356 | placementNewArgsOffset()); | |||
| 2357 | } | |||
| 2358 | ||||
| 2359 | Expr *getPlacementArg(unsigned I) { | |||
| 2360 | assert((I < getNumPlacementArgs()) && "Index out of range!")(static_cast <bool> ((I < getNumPlacementArgs()) && "Index out of range!") ? void (0) : __assert_fail ("(I < getNumPlacementArgs()) && \"Index out of range!\"" , "clang/include/clang/AST/ExprCXX.h", 2360, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2361 | return getPlacementArgs()[I]; | |||
| 2362 | } | |||
| 2363 | const Expr *getPlacementArg(unsigned I) const { | |||
| 2364 | return const_cast<CXXNewExpr *>(this)->getPlacementArg(I); | |||
| 2365 | } | |||
| 2366 | ||||
| 2367 | bool isParenTypeId() const { return CXXNewExprBits.IsParenTypeId; } | |||
| 2368 | SourceRange getTypeIdParens() const { | |||
| 2369 | return isParenTypeId() ? getTrailingObjects<SourceRange>()[0] | |||
| 2370 | : SourceRange(); | |||
| 2371 | } | |||
| 2372 | ||||
| 2373 | bool isGlobalNew() const { return CXXNewExprBits.IsGlobalNew; } | |||
| 2374 | ||||
| 2375 | /// Whether this new-expression has any initializer at all. | |||
| 2376 | bool hasInitializer() const { | |||
| 2377 | return CXXNewExprBits.StoredInitializationStyle > 0; | |||
| 2378 | } | |||
| 2379 | ||||
| 2380 | /// The kind of initializer this new-expression has. | |||
| 2381 | InitializationStyle getInitializationStyle() const { | |||
| 2382 | if (CXXNewExprBits.StoredInitializationStyle == 0) | |||
| 2383 | return NoInit; | |||
| 2384 | return static_cast<InitializationStyle>( | |||
| 2385 | CXXNewExprBits.StoredInitializationStyle - 1); | |||
| 2386 | } | |||
| 2387 | ||||
| 2388 | /// The initializer of this new-expression. | |||
| 2389 | Expr *getInitializer() { | |||
| 2390 | return hasInitializer() | |||
| 2391 | ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()]) | |||
| 2392 | : nullptr; | |||
| 2393 | } | |||
| 2394 | const Expr *getInitializer() const { | |||
| 2395 | return hasInitializer() | |||
| 2396 | ? cast<Expr>(getTrailingObjects<Stmt *>()[initExprOffset()]) | |||
| 2397 | : nullptr; | |||
| 2398 | } | |||
| 2399 | ||||
| 2400 | /// Returns the CXXConstructExpr from this new-expression, or null. | |||
| 2401 | const CXXConstructExpr *getConstructExpr() const { | |||
| 2402 | return dyn_cast_or_null<CXXConstructExpr>(getInitializer()); | |||
| 2403 | } | |||
| 2404 | ||||
| 2405 | /// Indicates whether the required alignment should be implicitly passed to | |||
| 2406 | /// the allocation function. | |||
| 2407 | bool passAlignment() const { return CXXNewExprBits.ShouldPassAlignment; } | |||
| 2408 | ||||
| 2409 | /// Answers whether the usual array deallocation function for the | |||
| 2410 | /// allocated type expects the size of the allocation as a | |||
| 2411 | /// parameter. | |||
| 2412 | bool doesUsualArrayDeleteWantSize() const { | |||
| 2413 | return CXXNewExprBits.UsualArrayDeleteWantsSize; | |||
| 2414 | } | |||
| 2415 | ||||
| 2416 | using arg_iterator = ExprIterator; | |||
| 2417 | using const_arg_iterator = ConstExprIterator; | |||
| 2418 | ||||
| 2419 | llvm::iterator_range<arg_iterator> placement_arguments() { | |||
| 2420 | return llvm::make_range(placement_arg_begin(), placement_arg_end()); | |||
| 2421 | } | |||
| 2422 | ||||
| 2423 | llvm::iterator_range<const_arg_iterator> placement_arguments() const { | |||
| 2424 | return llvm::make_range(placement_arg_begin(), placement_arg_end()); | |||
| 2425 | } | |||
| 2426 | ||||
| 2427 | arg_iterator placement_arg_begin() { | |||
| 2428 | return getTrailingObjects<Stmt *>() + placementNewArgsOffset(); | |||
| 2429 | } | |||
| 2430 | arg_iterator placement_arg_end() { | |||
| 2431 | return placement_arg_begin() + getNumPlacementArgs(); | |||
| 2432 | } | |||
| 2433 | const_arg_iterator placement_arg_begin() const { | |||
| 2434 | return getTrailingObjects<Stmt *>() + placementNewArgsOffset(); | |||
| 2435 | } | |||
| 2436 | const_arg_iterator placement_arg_end() const { | |||
| 2437 | return placement_arg_begin() + getNumPlacementArgs(); | |||
| 2438 | } | |||
| 2439 | ||||
| 2440 | using raw_arg_iterator = Stmt **; | |||
| 2441 | ||||
| 2442 | raw_arg_iterator raw_arg_begin() { return getTrailingObjects<Stmt *>(); } | |||
| 2443 | raw_arg_iterator raw_arg_end() { | |||
| 2444 | return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>()); | |||
| 2445 | } | |||
| 2446 | const_arg_iterator raw_arg_begin() const { | |||
| 2447 | return getTrailingObjects<Stmt *>(); | |||
| 2448 | } | |||
| 2449 | const_arg_iterator raw_arg_end() const { | |||
| 2450 | return raw_arg_begin() + numTrailingObjects(OverloadToken<Stmt *>()); | |||
| 2451 | } | |||
| 2452 | ||||
| 2453 | SourceLocation getBeginLoc() const { return Range.getBegin(); } | |||
| 2454 | SourceLocation getEndLoc() const { return Range.getEnd(); } | |||
| 2455 | ||||
| 2456 | SourceRange getDirectInitRange() const { return DirectInitRange; } | |||
| 2457 | SourceRange getSourceRange() const { return Range; } | |||
| 2458 | ||||
| 2459 | static bool classof(const Stmt *T) { | |||
| 2460 | return T->getStmtClass() == CXXNewExprClass; | |||
| 2461 | } | |||
| 2462 | ||||
| 2463 | // Iterators | |||
| 2464 | child_range children() { return child_range(raw_arg_begin(), raw_arg_end()); } | |||
| 2465 | ||||
| 2466 | const_child_range children() const { | |||
| 2467 | return const_child_range(const_cast<CXXNewExpr *>(this)->children()); | |||
| 2468 | } | |||
| 2469 | }; | |||
| 2470 | ||||
| 2471 | /// Represents a \c delete expression for memory deallocation and | |||
| 2472 | /// destructor calls, e.g. "delete[] pArray". | |||
| 2473 | class CXXDeleteExpr : public Expr { | |||
| 2474 | friend class ASTStmtReader; | |||
| 2475 | ||||
| 2476 | /// Points to the operator delete overload that is used. Could be a member. | |||
| 2477 | FunctionDecl *OperatorDelete = nullptr; | |||
| 2478 | ||||
| 2479 | /// The pointer expression to be deleted. | |||
| 2480 | Stmt *Argument = nullptr; | |||
| 2481 | ||||
| 2482 | public: | |||
| 2483 | CXXDeleteExpr(QualType Ty, bool GlobalDelete, bool ArrayForm, | |||
| 2484 | bool ArrayFormAsWritten, bool UsualArrayDeleteWantsSize, | |||
| 2485 | FunctionDecl *OperatorDelete, Expr *Arg, SourceLocation Loc) | |||
| 2486 | : Expr(CXXDeleteExprClass, Ty, VK_PRValue, OK_Ordinary), | |||
| 2487 | OperatorDelete(OperatorDelete), Argument(Arg) { | |||
| 2488 | CXXDeleteExprBits.GlobalDelete = GlobalDelete; | |||
| 2489 | CXXDeleteExprBits.ArrayForm = ArrayForm; | |||
| 2490 | CXXDeleteExprBits.ArrayFormAsWritten = ArrayFormAsWritten; | |||
| 2491 | CXXDeleteExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize; | |||
| 2492 | CXXDeleteExprBits.Loc = Loc; | |||
| 2493 | setDependence(computeDependence(this)); | |||
| 2494 | } | |||
| 2495 | ||||
| 2496 | explicit CXXDeleteExpr(EmptyShell Shell) : Expr(CXXDeleteExprClass, Shell) {} | |||
| 2497 | ||||
| 2498 | bool isGlobalDelete() const { return CXXDeleteExprBits.GlobalDelete; } | |||
| 2499 | bool isArrayForm() const { return CXXDeleteExprBits.ArrayForm; } | |||
| 2500 | bool isArrayFormAsWritten() const { | |||
| 2501 | return CXXDeleteExprBits.ArrayFormAsWritten; | |||
| 2502 | } | |||
| 2503 | ||||
| 2504 | /// Answers whether the usual array deallocation function for the | |||
| 2505 | /// allocated type expects the size of the allocation as a | |||
| 2506 | /// parameter. This can be true even if the actual deallocation | |||
| 2507 | /// function that we're using doesn't want a size. | |||
| 2508 | bool doesUsualArrayDeleteWantSize() const { | |||
| 2509 | return CXXDeleteExprBits.UsualArrayDeleteWantsSize; | |||
| 2510 | } | |||
| 2511 | ||||
| 2512 | FunctionDecl *getOperatorDelete() const { return OperatorDelete; } | |||
| 2513 | ||||
| 2514 | Expr *getArgument() { return cast<Expr>(Argument); } | |||
| 2515 | const Expr *getArgument() const { return cast<Expr>(Argument); } | |||
| 2516 | ||||
| 2517 | /// Retrieve the type being destroyed. | |||
| 2518 | /// | |||
| 2519 | /// If the type being destroyed is a dependent type which may or may not | |||
| 2520 | /// be a pointer, return an invalid type. | |||
| 2521 | QualType getDestroyedType() const; | |||
| 2522 | ||||
| 2523 | SourceLocation getBeginLoc() const { return CXXDeleteExprBits.Loc; } | |||
| 2524 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 2525 | return Argument->getEndLoc(); | |||
| 2526 | } | |||
| 2527 | ||||
| 2528 | static bool classof(const Stmt *T) { | |||
| 2529 | return T->getStmtClass() == CXXDeleteExprClass; | |||
| 2530 | } | |||
| 2531 | ||||
| 2532 | // Iterators | |||
| 2533 | child_range children() { return child_range(&Argument, &Argument + 1); } | |||
| 2534 | ||||
| 2535 | const_child_range children() const { | |||
| 2536 | return const_child_range(&Argument, &Argument + 1); | |||
| 2537 | } | |||
| 2538 | }; | |||
| 2539 | ||||
| 2540 | /// Stores the type being destroyed by a pseudo-destructor expression. | |||
| 2541 | class PseudoDestructorTypeStorage { | |||
| 2542 | /// Either the type source information or the name of the type, if | |||
| 2543 | /// it couldn't be resolved due to type-dependence. | |||
| 2544 | llvm::PointerUnion<TypeSourceInfo *, IdentifierInfo *> Type; | |||
| 2545 | ||||
| 2546 | /// The starting source location of the pseudo-destructor type. | |||
| 2547 | SourceLocation Location; | |||
| 2548 | ||||
| 2549 | public: | |||
| 2550 | PseudoDestructorTypeStorage() = default; | |||
| 2551 | ||||
| 2552 | PseudoDestructorTypeStorage(IdentifierInfo *II, SourceLocation Loc) | |||
| 2553 | : Type(II), Location(Loc) {} | |||
| 2554 | ||||
| 2555 | PseudoDestructorTypeStorage(TypeSourceInfo *Info); | |||
| 2556 | ||||
| 2557 | TypeSourceInfo *getTypeSourceInfo() const { | |||
| 2558 | return Type.dyn_cast<TypeSourceInfo *>(); | |||
| 2559 | } | |||
| 2560 | ||||
| 2561 | IdentifierInfo *getIdentifier() const { | |||
| 2562 | return Type.dyn_cast<IdentifierInfo *>(); | |||
| 2563 | } | |||
| 2564 | ||||
| 2565 | SourceLocation getLocation() const { return Location; } | |||
| 2566 | }; | |||
| 2567 | ||||
| 2568 | /// Represents a C++ pseudo-destructor (C++ [expr.pseudo]). | |||
| 2569 | /// | |||
| 2570 | /// A pseudo-destructor is an expression that looks like a member access to a | |||
| 2571 | /// destructor of a scalar type, except that scalar types don't have | |||
| 2572 | /// destructors. For example: | |||
| 2573 | /// | |||
| 2574 | /// \code | |||
| 2575 | /// typedef int T; | |||
| 2576 | /// void f(int *p) { | |||
| 2577 | /// p->T::~T(); | |||
| 2578 | /// } | |||
| 2579 | /// \endcode | |||
| 2580 | /// | |||
| 2581 | /// Pseudo-destructors typically occur when instantiating templates such as: | |||
| 2582 | /// | |||
| 2583 | /// \code | |||
| 2584 | /// template<typename T> | |||
| 2585 | /// void destroy(T* ptr) { | |||
| 2586 | /// ptr->T::~T(); | |||
| 2587 | /// } | |||
| 2588 | /// \endcode | |||
| 2589 | /// | |||
| 2590 | /// for scalar types. A pseudo-destructor expression has no run-time semantics | |||
| 2591 | /// beyond evaluating the base expression. | |||
| 2592 | class CXXPseudoDestructorExpr : public Expr { | |||
| 2593 | friend class ASTStmtReader; | |||
| 2594 | ||||
| 2595 | /// The base expression (that is being destroyed). | |||
| 2596 | Stmt *Base = nullptr; | |||
| 2597 | ||||
| 2598 | /// Whether the operator was an arrow ('->'); otherwise, it was a | |||
| 2599 | /// period ('.'). | |||
| 2600 | bool IsArrow : 1; | |||
| 2601 | ||||
| 2602 | /// The location of the '.' or '->' operator. | |||
| 2603 | SourceLocation OperatorLoc; | |||
| 2604 | ||||
| 2605 | /// The nested-name-specifier that follows the operator, if present. | |||
| 2606 | NestedNameSpecifierLoc QualifierLoc; | |||
| 2607 | ||||
| 2608 | /// The type that precedes the '::' in a qualified pseudo-destructor | |||
| 2609 | /// expression. | |||
| 2610 | TypeSourceInfo *ScopeType = nullptr; | |||
| 2611 | ||||
| 2612 | /// The location of the '::' in a qualified pseudo-destructor | |||
| 2613 | /// expression. | |||
| 2614 | SourceLocation ColonColonLoc; | |||
| 2615 | ||||
| 2616 | /// The location of the '~'. | |||
| 2617 | SourceLocation TildeLoc; | |||
| 2618 | ||||
| 2619 | /// The type being destroyed, or its name if we were unable to | |||
| 2620 | /// resolve the name. | |||
| 2621 | PseudoDestructorTypeStorage DestroyedType; | |||
| 2622 | ||||
| 2623 | public: | |||
| 2624 | CXXPseudoDestructorExpr(const ASTContext &Context, | |||
| 2625 | Expr *Base, bool isArrow, SourceLocation OperatorLoc, | |||
| 2626 | NestedNameSpecifierLoc QualifierLoc, | |||
| 2627 | TypeSourceInfo *ScopeType, | |||
| 2628 | SourceLocation ColonColonLoc, | |||
| 2629 | SourceLocation TildeLoc, | |||
| 2630 | PseudoDestructorTypeStorage DestroyedType); | |||
| 2631 | ||||
| 2632 | explicit CXXPseudoDestructorExpr(EmptyShell Shell) | |||
| 2633 | : Expr(CXXPseudoDestructorExprClass, Shell), IsArrow(false) {} | |||
| 2634 | ||||
| 2635 | Expr *getBase() const { return cast<Expr>(Base); } | |||
| 2636 | ||||
| 2637 | /// Determines whether this member expression actually had | |||
| 2638 | /// a C++ nested-name-specifier prior to the name of the member, e.g., | |||
| 2639 | /// x->Base::foo. | |||
| 2640 | bool hasQualifier() const { return QualifierLoc.hasQualifier(); } | |||
| 2641 | ||||
| 2642 | /// Retrieves the nested-name-specifier that qualifies the type name, | |||
| 2643 | /// with source-location information. | |||
| 2644 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } | |||
| 2645 | ||||
| 2646 | /// If the member name was qualified, retrieves the | |||
| 2647 | /// nested-name-specifier that precedes the member name. Otherwise, returns | |||
| 2648 | /// null. | |||
| 2649 | NestedNameSpecifier *getQualifier() const { | |||
| 2650 | return QualifierLoc.getNestedNameSpecifier(); | |||
| 2651 | } | |||
| 2652 | ||||
| 2653 | /// Determine whether this pseudo-destructor expression was written | |||
| 2654 | /// using an '->' (otherwise, it used a '.'). | |||
| 2655 | bool isArrow() const { return IsArrow; } | |||
| 2656 | ||||
| 2657 | /// Retrieve the location of the '.' or '->' operator. | |||
| 2658 | SourceLocation getOperatorLoc() const { return OperatorLoc; } | |||
| 2659 | ||||
| 2660 | /// Retrieve the scope type in a qualified pseudo-destructor | |||
| 2661 | /// expression. | |||
| 2662 | /// | |||
| 2663 | /// Pseudo-destructor expressions can have extra qualification within them | |||
| 2664 | /// that is not part of the nested-name-specifier, e.g., \c p->T::~T(). | |||
| 2665 | /// Here, if the object type of the expression is (or may be) a scalar type, | |||
| 2666 | /// \p T may also be a scalar type and, therefore, cannot be part of a | |||
| 2667 | /// nested-name-specifier. It is stored as the "scope type" of the pseudo- | |||
| 2668 | /// destructor expression. | |||
| 2669 | TypeSourceInfo *getScopeTypeInfo() const { return ScopeType; } | |||
| 2670 | ||||
| 2671 | /// Retrieve the location of the '::' in a qualified pseudo-destructor | |||
| 2672 | /// expression. | |||
| 2673 | SourceLocation getColonColonLoc() const { return ColonColonLoc; } | |||
| 2674 | ||||
| 2675 | /// Retrieve the location of the '~'. | |||
| 2676 | SourceLocation getTildeLoc() const { return TildeLoc; } | |||
| 2677 | ||||
| 2678 | /// Retrieve the source location information for the type | |||
| 2679 | /// being destroyed. | |||
| 2680 | /// | |||
| 2681 | /// This type-source information is available for non-dependent | |||
| 2682 | /// pseudo-destructor expressions and some dependent pseudo-destructor | |||
| 2683 | /// expressions. Returns null if we only have the identifier for a | |||
| 2684 | /// dependent pseudo-destructor expression. | |||
| 2685 | TypeSourceInfo *getDestroyedTypeInfo() const { | |||
| 2686 | return DestroyedType.getTypeSourceInfo(); | |||
| 2687 | } | |||
| 2688 | ||||
| 2689 | /// In a dependent pseudo-destructor expression for which we do not | |||
| 2690 | /// have full type information on the destroyed type, provides the name | |||
| 2691 | /// of the destroyed type. | |||
| 2692 | IdentifierInfo *getDestroyedTypeIdentifier() const { | |||
| 2693 | return DestroyedType.getIdentifier(); | |||
| 2694 | } | |||
| 2695 | ||||
| 2696 | /// Retrieve the type being destroyed. | |||
| 2697 | QualType getDestroyedType() const; | |||
| 2698 | ||||
| 2699 | /// Retrieve the starting location of the type being destroyed. | |||
| 2700 | SourceLocation getDestroyedTypeLoc() const { | |||
| 2701 | return DestroyedType.getLocation(); | |||
| 2702 | } | |||
| 2703 | ||||
| 2704 | /// Set the name of destroyed type for a dependent pseudo-destructor | |||
| 2705 | /// expression. | |||
| 2706 | void setDestroyedType(IdentifierInfo *II, SourceLocation Loc) { | |||
| 2707 | DestroyedType = PseudoDestructorTypeStorage(II, Loc); | |||
| 2708 | } | |||
| 2709 | ||||
| 2710 | /// Set the destroyed type. | |||
| 2711 | void setDestroyedType(TypeSourceInfo *Info) { | |||
| 2712 | DestroyedType = PseudoDestructorTypeStorage(Info); | |||
| 2713 | } | |||
| 2714 | ||||
| 2715 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 2716 | return Base->getBeginLoc(); | |||
| 2717 | } | |||
| 2718 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)); | |||
| 2719 | ||||
| 2720 | static bool classof(const Stmt *T) { | |||
| 2721 | return T->getStmtClass() == CXXPseudoDestructorExprClass; | |||
| 2722 | } | |||
| 2723 | ||||
| 2724 | // Iterators | |||
| 2725 | child_range children() { return child_range(&Base, &Base + 1); } | |||
| 2726 | ||||
| 2727 | const_child_range children() const { | |||
| 2728 | return const_child_range(&Base, &Base + 1); | |||
| 2729 | } | |||
| 2730 | }; | |||
| 2731 | ||||
| 2732 | /// A type trait used in the implementation of various C++11 and | |||
| 2733 | /// Library TR1 trait templates. | |||
| 2734 | /// | |||
| 2735 | /// \code | |||
| 2736 | /// __is_pod(int) == true | |||
| 2737 | /// __is_enum(std::string) == false | |||
| 2738 | /// __is_trivially_constructible(vector<int>, int*, int*) | |||
| 2739 | /// \endcode | |||
| 2740 | class TypeTraitExpr final | |||
| 2741 | : public Expr, | |||
| 2742 | private llvm::TrailingObjects<TypeTraitExpr, TypeSourceInfo *> { | |||
| 2743 | /// The location of the type trait keyword. | |||
| 2744 | SourceLocation Loc; | |||
| 2745 | ||||
| 2746 | /// The location of the closing parenthesis. | |||
| 2747 | SourceLocation RParenLoc; | |||
| 2748 | ||||
| 2749 | // Note: The TypeSourceInfos for the arguments are allocated after the | |||
| 2750 | // TypeTraitExpr. | |||
| 2751 | ||||
| 2752 | TypeTraitExpr(QualType T, SourceLocation Loc, TypeTrait Kind, | |||
| 2753 | ArrayRef<TypeSourceInfo *> Args, | |||
| 2754 | SourceLocation RParenLoc, | |||
| 2755 | bool Value); | |||
| 2756 | ||||
| 2757 | TypeTraitExpr(EmptyShell Empty) : Expr(TypeTraitExprClass, Empty) {} | |||
| 2758 | ||||
| 2759 | size_t numTrailingObjects(OverloadToken<TypeSourceInfo *>) const { | |||
| 2760 | return getNumArgs(); | |||
| 2761 | } | |||
| 2762 | ||||
| 2763 | public: | |||
| 2764 | friend class ASTStmtReader; | |||
| 2765 | friend class ASTStmtWriter; | |||
| 2766 | friend TrailingObjects; | |||
| 2767 | ||||
| 2768 | /// Create a new type trait expression. | |||
| 2769 | static TypeTraitExpr *Create(const ASTContext &C, QualType T, | |||
| 2770 | SourceLocation Loc, TypeTrait Kind, | |||
| 2771 | ArrayRef<TypeSourceInfo *> Args, | |||
| 2772 | SourceLocation RParenLoc, | |||
| 2773 | bool Value); | |||
| 2774 | ||||
| 2775 | static TypeTraitExpr *CreateDeserialized(const ASTContext &C, | |||
| 2776 | unsigned NumArgs); | |||
| 2777 | ||||
| 2778 | /// Determine which type trait this expression uses. | |||
| 2779 | TypeTrait getTrait() const { | |||
| 2780 | return static_cast<TypeTrait>(TypeTraitExprBits.Kind); | |||
| 2781 | } | |||
| 2782 | ||||
| 2783 | bool getValue() const { | |||
| 2784 | assert(!isValueDependent())(static_cast <bool> (!isValueDependent()) ? void (0) : __assert_fail ("!isValueDependent()", "clang/include/clang/AST/ExprCXX.h", 2784, __extension__ __PRETTY_FUNCTION__)); | |||
| 2785 | return TypeTraitExprBits.Value; | |||
| 2786 | } | |||
| 2787 | ||||
| 2788 | /// Determine the number of arguments to this type trait. | |||
| 2789 | unsigned getNumArgs() const { return TypeTraitExprBits.NumArgs; } | |||
| 2790 | ||||
| 2791 | /// Retrieve the Ith argument. | |||
| 2792 | TypeSourceInfo *getArg(unsigned I) const { | |||
| 2793 | assert(I < getNumArgs() && "Argument out-of-range")(static_cast <bool> (I < getNumArgs() && "Argument out-of-range" ) ? void (0) : __assert_fail ("I < getNumArgs() && \"Argument out-of-range\"" , "clang/include/clang/AST/ExprCXX.h", 2793, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2794 | return getArgs()[I]; | |||
| 2795 | } | |||
| 2796 | ||||
| 2797 | /// Retrieve the argument types. | |||
| 2798 | ArrayRef<TypeSourceInfo *> getArgs() const { | |||
| 2799 | return llvm::ArrayRef(getTrailingObjects<TypeSourceInfo *>(), getNumArgs()); | |||
| 2800 | } | |||
| 2801 | ||||
| 2802 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Loc; } | |||
| 2803 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return RParenLoc; } | |||
| 2804 | ||||
| 2805 | static bool classof(const Stmt *T) { | |||
| 2806 | return T->getStmtClass() == TypeTraitExprClass; | |||
| 2807 | } | |||
| 2808 | ||||
| 2809 | // Iterators | |||
| 2810 | child_range children() { | |||
| 2811 | return child_range(child_iterator(), child_iterator()); | |||
| 2812 | } | |||
| 2813 | ||||
| 2814 | const_child_range children() const { | |||
| 2815 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 2816 | } | |||
| 2817 | }; | |||
| 2818 | ||||
| 2819 | /// An Embarcadero array type trait, as used in the implementation of | |||
| 2820 | /// __array_rank and __array_extent. | |||
| 2821 | /// | |||
| 2822 | /// Example: | |||
| 2823 | /// \code | |||
| 2824 | /// __array_rank(int[10][20]) == 2 | |||
| 2825 | /// __array_extent(int, 1) == 20 | |||
| 2826 | /// \endcode | |||
| 2827 | class ArrayTypeTraitExpr : public Expr { | |||
| 2828 | /// The trait. An ArrayTypeTrait enum in MSVC compat unsigned. | |||
| 2829 | unsigned ATT : 2; | |||
| 2830 | ||||
| 2831 | /// The value of the type trait. Unspecified if dependent. | |||
| 2832 | uint64_t Value = 0; | |||
| 2833 | ||||
| 2834 | /// The array dimension being queried, or -1 if not used. | |||
| 2835 | Expr *Dimension; | |||
| 2836 | ||||
| 2837 | /// The location of the type trait keyword. | |||
| 2838 | SourceLocation Loc; | |||
| 2839 | ||||
| 2840 | /// The location of the closing paren. | |||
| 2841 | SourceLocation RParen; | |||
| 2842 | ||||
| 2843 | /// The type being queried. | |||
| 2844 | TypeSourceInfo *QueriedType = nullptr; | |||
| 2845 | ||||
| 2846 | public: | |||
| 2847 | friend class ASTStmtReader; | |||
| 2848 | ||||
| 2849 | ArrayTypeTraitExpr(SourceLocation loc, ArrayTypeTrait att, | |||
| 2850 | TypeSourceInfo *queried, uint64_t value, Expr *dimension, | |||
| 2851 | SourceLocation rparen, QualType ty) | |||
| 2852 | : Expr(ArrayTypeTraitExprClass, ty, VK_PRValue, OK_Ordinary), ATT(att), | |||
| 2853 | Value(value), Dimension(dimension), Loc(loc), RParen(rparen), | |||
| 2854 | QueriedType(queried) { | |||
| 2855 | assert(att <= ATT_Last && "invalid enum value!")(static_cast <bool> (att <= ATT_Last && "invalid enum value!" ) ? void (0) : __assert_fail ("att <= ATT_Last && \"invalid enum value!\"" , "clang/include/clang/AST/ExprCXX.h", 2855, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2856 | assert(static_cast<unsigned>(att) == ATT && "ATT overflow!")(static_cast <bool> (static_cast<unsigned>(att) == ATT && "ATT overflow!") ? void (0) : __assert_fail ( "static_cast<unsigned>(att) == ATT && \"ATT overflow!\"" , "clang/include/clang/AST/ExprCXX.h", 2856, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2857 | setDependence(computeDependence(this)); | |||
| 2858 | } | |||
| 2859 | ||||
| 2860 | explicit ArrayTypeTraitExpr(EmptyShell Empty) | |||
| 2861 | : Expr(ArrayTypeTraitExprClass, Empty), ATT(0) {} | |||
| 2862 | ||||
| 2863 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Loc; } | |||
| 2864 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return RParen; } | |||
| 2865 | ||||
| 2866 | ArrayTypeTrait getTrait() const { return static_cast<ArrayTypeTrait>(ATT); } | |||
| 2867 | ||||
| 2868 | QualType getQueriedType() const { return QueriedType->getType(); } | |||
| 2869 | ||||
| 2870 | TypeSourceInfo *getQueriedTypeSourceInfo() const { return QueriedType; } | |||
| 2871 | ||||
| 2872 | uint64_t getValue() const { assert(!isTypeDependent())(static_cast <bool> (!isTypeDependent()) ? void (0) : __assert_fail ("!isTypeDependent()", "clang/include/clang/AST/ExprCXX.h", 2872 , __extension__ __PRETTY_FUNCTION__)); return Value; } | |||
| 2873 | ||||
| 2874 | Expr *getDimensionExpression() const { return Dimension; } | |||
| 2875 | ||||
| 2876 | static bool classof(const Stmt *T) { | |||
| 2877 | return T->getStmtClass() == ArrayTypeTraitExprClass; | |||
| 2878 | } | |||
| 2879 | ||||
| 2880 | // Iterators | |||
| 2881 | child_range children() { | |||
| 2882 | return child_range(child_iterator(), child_iterator()); | |||
| 2883 | } | |||
| 2884 | ||||
| 2885 | const_child_range children() const { | |||
| 2886 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 2887 | } | |||
| 2888 | }; | |||
| 2889 | ||||
| 2890 | /// An expression trait intrinsic. | |||
| 2891 | /// | |||
| 2892 | /// Example: | |||
| 2893 | /// \code | |||
| 2894 | /// __is_lvalue_expr(std::cout) == true | |||
| 2895 | /// __is_lvalue_expr(1) == false | |||
| 2896 | /// \endcode | |||
| 2897 | class ExpressionTraitExpr : public Expr { | |||
| 2898 | /// The trait. A ExpressionTrait enum in MSVC compatible unsigned. | |||
| 2899 | unsigned ET : 31; | |||
| 2900 | ||||
| 2901 | /// The value of the type trait. Unspecified if dependent. | |||
| 2902 | unsigned Value : 1; | |||
| 2903 | ||||
| 2904 | /// The location of the type trait keyword. | |||
| 2905 | SourceLocation Loc; | |||
| 2906 | ||||
| 2907 | /// The location of the closing paren. | |||
| 2908 | SourceLocation RParen; | |||
| 2909 | ||||
| 2910 | /// The expression being queried. | |||
| 2911 | Expr* QueriedExpression = nullptr; | |||
| 2912 | ||||
| 2913 | public: | |||
| 2914 | friend class ASTStmtReader; | |||
| 2915 | ||||
| 2916 | ExpressionTraitExpr(SourceLocation loc, ExpressionTrait et, Expr *queried, | |||
| 2917 | bool value, SourceLocation rparen, QualType resultType) | |||
| 2918 | : Expr(ExpressionTraitExprClass, resultType, VK_PRValue, OK_Ordinary), | |||
| 2919 | ET(et), Value(value), Loc(loc), RParen(rparen), | |||
| 2920 | QueriedExpression(queried) { | |||
| 2921 | assert(et <= ET_Last && "invalid enum value!")(static_cast <bool> (et <= ET_Last && "invalid enum value!" ) ? void (0) : __assert_fail ("et <= ET_Last && \"invalid enum value!\"" , "clang/include/clang/AST/ExprCXX.h", 2921, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2922 | assert(static_cast<unsigned>(et) == ET && "ET overflow!")(static_cast <bool> (static_cast<unsigned>(et) == ET && "ET overflow!") ? void (0) : __assert_fail ("static_cast<unsigned>(et) == ET && \"ET overflow!\"" , "clang/include/clang/AST/ExprCXX.h", 2922, __extension__ __PRETTY_FUNCTION__ )); | |||
| 2923 | setDependence(computeDependence(this)); | |||
| 2924 | } | |||
| 2925 | ||||
| 2926 | explicit ExpressionTraitExpr(EmptyShell Empty) | |||
| 2927 | : Expr(ExpressionTraitExprClass, Empty), ET(0), Value(false) {} | |||
| 2928 | ||||
| 2929 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return Loc; } | |||
| 2930 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return RParen; } | |||
| 2931 | ||||
| 2932 | ExpressionTrait getTrait() const { return static_cast<ExpressionTrait>(ET); } | |||
| 2933 | ||||
| 2934 | Expr *getQueriedExpression() const { return QueriedExpression; } | |||
| 2935 | ||||
| 2936 | bool getValue() const { return Value; } | |||
| 2937 | ||||
| 2938 | static bool classof(const Stmt *T) { | |||
| 2939 | return T->getStmtClass() == ExpressionTraitExprClass; | |||
| 2940 | } | |||
| 2941 | ||||
| 2942 | // Iterators | |||
| 2943 | child_range children() { | |||
| 2944 | return child_range(child_iterator(), child_iterator()); | |||
| 2945 | } | |||
| 2946 | ||||
| 2947 | const_child_range children() const { | |||
| 2948 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 2949 | } | |||
| 2950 | }; | |||
| 2951 | ||||
| 2952 | /// A reference to an overloaded function set, either an | |||
| 2953 | /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr. | |||
| 2954 | class OverloadExpr : public Expr { | |||
| 2955 | friend class ASTStmtReader; | |||
| 2956 | friend class ASTStmtWriter; | |||
| 2957 | ||||
| 2958 | /// The common name of these declarations. | |||
| 2959 | DeclarationNameInfo NameInfo; | |||
| 2960 | ||||
| 2961 | /// The nested-name-specifier that qualifies the name, if any. | |||
| 2962 | NestedNameSpecifierLoc QualifierLoc; | |||
| 2963 | ||||
| 2964 | protected: | |||
| 2965 | OverloadExpr(StmtClass SC, const ASTContext &Context, | |||
| 2966 | NestedNameSpecifierLoc QualifierLoc, | |||
| 2967 | SourceLocation TemplateKWLoc, | |||
| 2968 | const DeclarationNameInfo &NameInfo, | |||
| 2969 | const TemplateArgumentListInfo *TemplateArgs, | |||
| 2970 | UnresolvedSetIterator Begin, UnresolvedSetIterator End, | |||
| 2971 | bool KnownDependent, bool KnownInstantiationDependent, | |||
| 2972 | bool KnownContainsUnexpandedParameterPack); | |||
| 2973 | ||||
| 2974 | OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults, | |||
| 2975 | bool HasTemplateKWAndArgsInfo); | |||
| 2976 | ||||
| 2977 | /// Return the results. Defined after UnresolvedMemberExpr. | |||
| 2978 | inline DeclAccessPair *getTrailingResults(); | |||
| 2979 | const DeclAccessPair *getTrailingResults() const { | |||
| 2980 | return const_cast<OverloadExpr *>(this)->getTrailingResults(); | |||
| 2981 | } | |||
| 2982 | ||||
| 2983 | /// Return the optional template keyword and arguments info. | |||
| 2984 | /// Defined after UnresolvedMemberExpr. | |||
| 2985 | inline ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo(); | |||
| 2986 | const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const { | |||
| 2987 | return const_cast<OverloadExpr *>(this) | |||
| 2988 | ->getTrailingASTTemplateKWAndArgsInfo(); | |||
| 2989 | } | |||
| 2990 | ||||
| 2991 | /// Return the optional template arguments. Defined after | |||
| 2992 | /// UnresolvedMemberExpr. | |||
| 2993 | inline TemplateArgumentLoc *getTrailingTemplateArgumentLoc(); | |||
| 2994 | const TemplateArgumentLoc *getTrailingTemplateArgumentLoc() const { | |||
| 2995 | return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc(); | |||
| 2996 | } | |||
| 2997 | ||||
| 2998 | bool hasTemplateKWAndArgsInfo() const { | |||
| 2999 | return OverloadExprBits.HasTemplateKWAndArgsInfo; | |||
| 3000 | } | |||
| 3001 | ||||
| 3002 | public: | |||
| 3003 | struct FindResult { | |||
| 3004 | OverloadExpr *Expression; | |||
| 3005 | bool IsAddressOfOperand; | |||
| 3006 | bool HasFormOfMemberPointer; | |||
| 3007 | }; | |||
| 3008 | ||||
| 3009 | /// Finds the overloaded expression in the given expression \p E of | |||
| 3010 | /// OverloadTy. | |||
| 3011 | /// | |||
| 3012 | /// \return the expression (which must be there) and true if it has | |||
| 3013 | /// the particular form of a member pointer expression | |||
| 3014 | static FindResult find(Expr *E) { | |||
| 3015 | assert(E->getType()->isSpecificBuiltinType(BuiltinType::Overload))(static_cast <bool> (E->getType()->isSpecificBuiltinType (BuiltinType::Overload)) ? void (0) : __assert_fail ("E->getType()->isSpecificBuiltinType(BuiltinType::Overload)" , "clang/include/clang/AST/ExprCXX.h", 3015, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3016 | ||||
| 3017 | FindResult Result; | |||
| 3018 | ||||
| 3019 | E = E->IgnoreParens(); | |||
| 3020 | if (isa<UnaryOperator>(E)) { | |||
| 3021 | assert(cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf)(static_cast <bool> (cast<UnaryOperator>(E)->getOpcode () == UO_AddrOf) ? void (0) : __assert_fail ("cast<UnaryOperator>(E)->getOpcode() == UO_AddrOf" , "clang/include/clang/AST/ExprCXX.h", 3021, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3022 | E = cast<UnaryOperator>(E)->getSubExpr(); | |||
| 3023 | auto *Ovl = cast<OverloadExpr>(E->IgnoreParens()); | |||
| 3024 | ||||
| 3025 | Result.HasFormOfMemberPointer = (E == Ovl && Ovl->getQualifier()); | |||
| 3026 | Result.IsAddressOfOperand = true; | |||
| 3027 | Result.Expression = Ovl; | |||
| 3028 | } else { | |||
| 3029 | Result.HasFormOfMemberPointer = false; | |||
| 3030 | Result.IsAddressOfOperand = false; | |||
| 3031 | Result.Expression = cast<OverloadExpr>(E); | |||
| 3032 | } | |||
| 3033 | ||||
| 3034 | return Result; | |||
| 3035 | } | |||
| 3036 | ||||
| 3037 | /// Gets the naming class of this lookup, if any. | |||
| 3038 | /// Defined after UnresolvedMemberExpr. | |||
| 3039 | inline CXXRecordDecl *getNamingClass(); | |||
| 3040 | const CXXRecordDecl *getNamingClass() const { | |||
| 3041 | return const_cast<OverloadExpr *>(this)->getNamingClass(); | |||
| 3042 | } | |||
| 3043 | ||||
| 3044 | using decls_iterator = UnresolvedSetImpl::iterator; | |||
| 3045 | ||||
| 3046 | decls_iterator decls_begin() const { | |||
| 3047 | return UnresolvedSetIterator(getTrailingResults()); | |||
| 3048 | } | |||
| 3049 | decls_iterator decls_end() const { | |||
| 3050 | return UnresolvedSetIterator(getTrailingResults() + getNumDecls()); | |||
| 3051 | } | |||
| 3052 | llvm::iterator_range<decls_iterator> decls() const { | |||
| 3053 | return llvm::make_range(decls_begin(), decls_end()); | |||
| 3054 | } | |||
| 3055 | ||||
| 3056 | /// Gets the number of declarations in the unresolved set. | |||
| 3057 | unsigned getNumDecls() const { return OverloadExprBits.NumResults; } | |||
| 3058 | ||||
| 3059 | /// Gets the full name info. | |||
| 3060 | const DeclarationNameInfo &getNameInfo() const { return NameInfo; } | |||
| 3061 | ||||
| 3062 | /// Gets the name looked up. | |||
| 3063 | DeclarationName getName() const { return NameInfo.getName(); } | |||
| 3064 | ||||
| 3065 | /// Gets the location of the name. | |||
| 3066 | SourceLocation getNameLoc() const { return NameInfo.getLoc(); } | |||
| 3067 | ||||
| 3068 | /// Fetches the nested-name qualifier, if one was given. | |||
| 3069 | NestedNameSpecifier *getQualifier() const { | |||
| 3070 | return QualifierLoc.getNestedNameSpecifier(); | |||
| 3071 | } | |||
| 3072 | ||||
| 3073 | /// Fetches the nested-name qualifier with source-location | |||
| 3074 | /// information, if one was given. | |||
| 3075 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } | |||
| 3076 | ||||
| 3077 | /// Retrieve the location of the template keyword preceding | |||
| 3078 | /// this name, if any. | |||
| 3079 | SourceLocation getTemplateKeywordLoc() const { | |||
| 3080 | if (!hasTemplateKWAndArgsInfo()) | |||
| 3081 | return SourceLocation(); | |||
| 3082 | return getTrailingASTTemplateKWAndArgsInfo()->TemplateKWLoc; | |||
| 3083 | } | |||
| 3084 | ||||
| 3085 | /// Retrieve the location of the left angle bracket starting the | |||
| 3086 | /// explicit template argument list following the name, if any. | |||
| 3087 | SourceLocation getLAngleLoc() const { | |||
| 3088 | if (!hasTemplateKWAndArgsInfo()) | |||
| 3089 | return SourceLocation(); | |||
| 3090 | return getTrailingASTTemplateKWAndArgsInfo()->LAngleLoc; | |||
| 3091 | } | |||
| 3092 | ||||
| 3093 | /// Retrieve the location of the right angle bracket ending the | |||
| 3094 | /// explicit template argument list following the name, if any. | |||
| 3095 | SourceLocation getRAngleLoc() const { | |||
| 3096 | if (!hasTemplateKWAndArgsInfo()) | |||
| 3097 | return SourceLocation(); | |||
| 3098 | return getTrailingASTTemplateKWAndArgsInfo()->RAngleLoc; | |||
| 3099 | } | |||
| 3100 | ||||
| 3101 | /// Determines whether the name was preceded by the template keyword. | |||
| 3102 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } | |||
| 3103 | ||||
| 3104 | /// Determines whether this expression had explicit template arguments. | |||
| 3105 | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } | |||
| 3106 | ||||
| 3107 | TemplateArgumentLoc const *getTemplateArgs() const { | |||
| 3108 | if (!hasExplicitTemplateArgs()) | |||
| 3109 | return nullptr; | |||
| 3110 | return const_cast<OverloadExpr *>(this)->getTrailingTemplateArgumentLoc(); | |||
| 3111 | } | |||
| 3112 | ||||
| 3113 | unsigned getNumTemplateArgs() const { | |||
| 3114 | if (!hasExplicitTemplateArgs()) | |||
| 3115 | return 0; | |||
| 3116 | ||||
| 3117 | return getTrailingASTTemplateKWAndArgsInfo()->NumTemplateArgs; | |||
| 3118 | } | |||
| 3119 | ||||
| 3120 | ArrayRef<TemplateArgumentLoc> template_arguments() const { | |||
| 3121 | return {getTemplateArgs(), getNumTemplateArgs()}; | |||
| 3122 | } | |||
| 3123 | ||||
| 3124 | /// Copies the template arguments into the given structure. | |||
| 3125 | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { | |||
| 3126 | if (hasExplicitTemplateArgs()) | |||
| 3127 | getTrailingASTTemplateKWAndArgsInfo()->copyInto(getTemplateArgs(), List); | |||
| 3128 | } | |||
| 3129 | ||||
| 3130 | static bool classof(const Stmt *T) { | |||
| 3131 | return T->getStmtClass() == UnresolvedLookupExprClass || | |||
| 3132 | T->getStmtClass() == UnresolvedMemberExprClass; | |||
| 3133 | } | |||
| 3134 | }; | |||
| 3135 | ||||
| 3136 | /// A reference to a name which we were able to look up during | |||
| 3137 | /// parsing but could not resolve to a specific declaration. | |||
| 3138 | /// | |||
| 3139 | /// This arises in several ways: | |||
| 3140 | /// * we might be waiting for argument-dependent lookup; | |||
| 3141 | /// * the name might resolve to an overloaded function; | |||
| 3142 | /// and eventually: | |||
| 3143 | /// * the lookup might have included a function template. | |||
| 3144 | /// | |||
| 3145 | /// These never include UnresolvedUsingValueDecls, which are always class | |||
| 3146 | /// members and therefore appear only in UnresolvedMemberLookupExprs. | |||
| 3147 | class UnresolvedLookupExpr final | |||
| 3148 | : public OverloadExpr, | |||
| 3149 | private llvm::TrailingObjects<UnresolvedLookupExpr, DeclAccessPair, | |||
| 3150 | ASTTemplateKWAndArgsInfo, | |||
| 3151 | TemplateArgumentLoc> { | |||
| 3152 | friend class ASTStmtReader; | |||
| 3153 | friend class OverloadExpr; | |||
| 3154 | friend TrailingObjects; | |||
| 3155 | ||||
| 3156 | /// The naming class (C++ [class.access.base]p5) of the lookup, if | |||
| 3157 | /// any. This can generally be recalculated from the context chain, | |||
| 3158 | /// but that can be fairly expensive for unqualified lookups. | |||
| 3159 | CXXRecordDecl *NamingClass; | |||
| 3160 | ||||
| 3161 | // UnresolvedLookupExpr is followed by several trailing objects. | |||
| 3162 | // They are in order: | |||
| 3163 | // | |||
| 3164 | // * An array of getNumResults() DeclAccessPair for the results. These are | |||
| 3165 | // undesugared, which is to say, they may include UsingShadowDecls. | |||
| 3166 | // Access is relative to the naming class. | |||
| 3167 | // | |||
| 3168 | // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified | |||
| 3169 | // template keyword and arguments. Present if and only if | |||
| 3170 | // hasTemplateKWAndArgsInfo(). | |||
| 3171 | // | |||
| 3172 | // * An array of getNumTemplateArgs() TemplateArgumentLoc containing | |||
| 3173 | // location information for the explicitly specified template arguments. | |||
| 3174 | ||||
| 3175 | UnresolvedLookupExpr(const ASTContext &Context, CXXRecordDecl *NamingClass, | |||
| 3176 | NestedNameSpecifierLoc QualifierLoc, | |||
| 3177 | SourceLocation TemplateKWLoc, | |||
| 3178 | const DeclarationNameInfo &NameInfo, bool RequiresADL, | |||
| 3179 | bool Overloaded, | |||
| 3180 | const TemplateArgumentListInfo *TemplateArgs, | |||
| 3181 | UnresolvedSetIterator Begin, UnresolvedSetIterator End); | |||
| 3182 | ||||
| 3183 | UnresolvedLookupExpr(EmptyShell Empty, unsigned NumResults, | |||
| 3184 | bool HasTemplateKWAndArgsInfo); | |||
| 3185 | ||||
| 3186 | unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const { | |||
| 3187 | return getNumDecls(); | |||
| 3188 | } | |||
| 3189 | ||||
| 3190 | unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { | |||
| 3191 | return hasTemplateKWAndArgsInfo(); | |||
| 3192 | } | |||
| 3193 | ||||
| 3194 | public: | |||
| 3195 | static UnresolvedLookupExpr * | |||
| 3196 | Create(const ASTContext &Context, CXXRecordDecl *NamingClass, | |||
| 3197 | NestedNameSpecifierLoc QualifierLoc, | |||
| 3198 | const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, | |||
| 3199 | UnresolvedSetIterator Begin, UnresolvedSetIterator End); | |||
| 3200 | ||||
| 3201 | static UnresolvedLookupExpr * | |||
| 3202 | Create(const ASTContext &Context, CXXRecordDecl *NamingClass, | |||
| 3203 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, | |||
| 3204 | const DeclarationNameInfo &NameInfo, bool RequiresADL, | |||
| 3205 | const TemplateArgumentListInfo *Args, UnresolvedSetIterator Begin, | |||
| 3206 | UnresolvedSetIterator End); | |||
| 3207 | ||||
| 3208 | static UnresolvedLookupExpr *CreateEmpty(const ASTContext &Context, | |||
| 3209 | unsigned NumResults, | |||
| 3210 | bool HasTemplateKWAndArgsInfo, | |||
| 3211 | unsigned NumTemplateArgs); | |||
| 3212 | ||||
| 3213 | /// True if this declaration should be extended by | |||
| 3214 | /// argument-dependent lookup. | |||
| 3215 | bool requiresADL() const { return UnresolvedLookupExprBits.RequiresADL; } | |||
| 3216 | ||||
| 3217 | /// True if this lookup is overloaded. | |||
| 3218 | bool isOverloaded() const { return UnresolvedLookupExprBits.Overloaded; } | |||
| 3219 | ||||
| 3220 | /// Gets the 'naming class' (in the sense of C++0x | |||
| 3221 | /// [class.access.base]p5) of the lookup. This is the scope | |||
| 3222 | /// that was looked in to find these results. | |||
| 3223 | CXXRecordDecl *getNamingClass() { return NamingClass; } | |||
| 3224 | const CXXRecordDecl *getNamingClass() const { return NamingClass; } | |||
| 3225 | ||||
| 3226 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 3227 | if (NestedNameSpecifierLoc l = getQualifierLoc()) | |||
| 3228 | return l.getBeginLoc(); | |||
| 3229 | return getNameInfo().getBeginLoc(); | |||
| 3230 | } | |||
| 3231 | ||||
| 3232 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 3233 | if (hasExplicitTemplateArgs()) | |||
| 3234 | return getRAngleLoc(); | |||
| 3235 | return getNameInfo().getEndLoc(); | |||
| 3236 | } | |||
| 3237 | ||||
| 3238 | child_range children() { | |||
| 3239 | return child_range(child_iterator(), child_iterator()); | |||
| 3240 | } | |||
| 3241 | ||||
| 3242 | const_child_range children() const { | |||
| 3243 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 3244 | } | |||
| 3245 | ||||
| 3246 | static bool classof(const Stmt *T) { | |||
| 3247 | return T->getStmtClass() == UnresolvedLookupExprClass; | |||
| 3248 | } | |||
| 3249 | }; | |||
| 3250 | ||||
| 3251 | /// A qualified reference to a name whose declaration cannot | |||
| 3252 | /// yet be resolved. | |||
| 3253 | /// | |||
| 3254 | /// DependentScopeDeclRefExpr is similar to DeclRefExpr in that | |||
| 3255 | /// it expresses a reference to a declaration such as | |||
| 3256 | /// X<T>::value. The difference, however, is that an | |||
| 3257 | /// DependentScopeDeclRefExpr node is used only within C++ templates when | |||
| 3258 | /// the qualification (e.g., X<T>::) refers to a dependent type. In | |||
| 3259 | /// this case, X<T>::value cannot resolve to a declaration because the | |||
| 3260 | /// declaration will differ from one instantiation of X<T> to the | |||
| 3261 | /// next. Therefore, DependentScopeDeclRefExpr keeps track of the | |||
| 3262 | /// qualifier (X<T>::) and the name of the entity being referenced | |||
| 3263 | /// ("value"). Such expressions will instantiate to a DeclRefExpr once the | |||
| 3264 | /// declaration can be found. | |||
| 3265 | class DependentScopeDeclRefExpr final | |||
| 3266 | : public Expr, | |||
| 3267 | private llvm::TrailingObjects<DependentScopeDeclRefExpr, | |||
| 3268 | ASTTemplateKWAndArgsInfo, | |||
| 3269 | TemplateArgumentLoc> { | |||
| 3270 | friend class ASTStmtReader; | |||
| 3271 | friend class ASTStmtWriter; | |||
| 3272 | friend TrailingObjects; | |||
| 3273 | ||||
| 3274 | /// The nested-name-specifier that qualifies this unresolved | |||
| 3275 | /// declaration name. | |||
| 3276 | NestedNameSpecifierLoc QualifierLoc; | |||
| 3277 | ||||
| 3278 | /// The name of the entity we will be referencing. | |||
| 3279 | DeclarationNameInfo NameInfo; | |||
| 3280 | ||||
| 3281 | DependentScopeDeclRefExpr(QualType Ty, NestedNameSpecifierLoc QualifierLoc, | |||
| 3282 | SourceLocation TemplateKWLoc, | |||
| 3283 | const DeclarationNameInfo &NameInfo, | |||
| 3284 | const TemplateArgumentListInfo *Args); | |||
| 3285 | ||||
| 3286 | size_t numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { | |||
| 3287 | return hasTemplateKWAndArgsInfo(); | |||
| 3288 | } | |||
| 3289 | ||||
| 3290 | bool hasTemplateKWAndArgsInfo() const { | |||
| 3291 | return DependentScopeDeclRefExprBits.HasTemplateKWAndArgsInfo; | |||
| 3292 | } | |||
| 3293 | ||||
| 3294 | public: | |||
| 3295 | static DependentScopeDeclRefExpr * | |||
| 3296 | Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, | |||
| 3297 | SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, | |||
| 3298 | const TemplateArgumentListInfo *TemplateArgs); | |||
| 3299 | ||||
| 3300 | static DependentScopeDeclRefExpr *CreateEmpty(const ASTContext &Context, | |||
| 3301 | bool HasTemplateKWAndArgsInfo, | |||
| 3302 | unsigned NumTemplateArgs); | |||
| 3303 | ||||
| 3304 | /// Retrieve the name that this expression refers to. | |||
| 3305 | const DeclarationNameInfo &getNameInfo() const { return NameInfo; } | |||
| 3306 | ||||
| 3307 | /// Retrieve the name that this expression refers to. | |||
| 3308 | DeclarationName getDeclName() const { return NameInfo.getName(); } | |||
| 3309 | ||||
| 3310 | /// Retrieve the location of the name within the expression. | |||
| 3311 | /// | |||
| 3312 | /// For example, in "X<T>::value" this is the location of "value". | |||
| 3313 | SourceLocation getLocation() const { return NameInfo.getLoc(); } | |||
| 3314 | ||||
| 3315 | /// Retrieve the nested-name-specifier that qualifies the | |||
| 3316 | /// name, with source location information. | |||
| 3317 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } | |||
| 3318 | ||||
| 3319 | /// Retrieve the nested-name-specifier that qualifies this | |||
| 3320 | /// declaration. | |||
| 3321 | NestedNameSpecifier *getQualifier() const { | |||
| 3322 | return QualifierLoc.getNestedNameSpecifier(); | |||
| 3323 | } | |||
| 3324 | ||||
| 3325 | /// Retrieve the location of the template keyword preceding | |||
| 3326 | /// this name, if any. | |||
| 3327 | SourceLocation getTemplateKeywordLoc() const { | |||
| 3328 | if (!hasTemplateKWAndArgsInfo()) | |||
| 3329 | return SourceLocation(); | |||
| 3330 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc; | |||
| 3331 | } | |||
| 3332 | ||||
| 3333 | /// Retrieve the location of the left angle bracket starting the | |||
| 3334 | /// explicit template argument list following the name, if any. | |||
| 3335 | SourceLocation getLAngleLoc() const { | |||
| 3336 | if (!hasTemplateKWAndArgsInfo()) | |||
| 3337 | return SourceLocation(); | |||
| 3338 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc; | |||
| 3339 | } | |||
| 3340 | ||||
| 3341 | /// Retrieve the location of the right angle bracket ending the | |||
| 3342 | /// explicit template argument list following the name, if any. | |||
| 3343 | SourceLocation getRAngleLoc() const { | |||
| 3344 | if (!hasTemplateKWAndArgsInfo()) | |||
| 3345 | return SourceLocation(); | |||
| 3346 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc; | |||
| 3347 | } | |||
| 3348 | ||||
| 3349 | /// Determines whether the name was preceded by the template keyword. | |||
| 3350 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } | |||
| 3351 | ||||
| 3352 | /// Determines whether this lookup had explicit template arguments. | |||
| 3353 | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } | |||
| 3354 | ||||
| 3355 | /// Copies the template arguments (if present) into the given | |||
| 3356 | /// structure. | |||
| 3357 | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { | |||
| 3358 | if (hasExplicitTemplateArgs()) | |||
| 3359 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto( | |||
| 3360 | getTrailingObjects<TemplateArgumentLoc>(), List); | |||
| 3361 | } | |||
| 3362 | ||||
| 3363 | TemplateArgumentLoc const *getTemplateArgs() const { | |||
| 3364 | if (!hasExplicitTemplateArgs()) | |||
| 3365 | return nullptr; | |||
| 3366 | ||||
| 3367 | return getTrailingObjects<TemplateArgumentLoc>(); | |||
| 3368 | } | |||
| 3369 | ||||
| 3370 | unsigned getNumTemplateArgs() const { | |||
| 3371 | if (!hasExplicitTemplateArgs()) | |||
| 3372 | return 0; | |||
| 3373 | ||||
| 3374 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; | |||
| 3375 | } | |||
| 3376 | ||||
| 3377 | ArrayRef<TemplateArgumentLoc> template_arguments() const { | |||
| 3378 | return {getTemplateArgs(), getNumTemplateArgs()}; | |||
| 3379 | } | |||
| 3380 | ||||
| 3381 | /// Note: getBeginLoc() is the start of the whole DependentScopeDeclRefExpr, | |||
| 3382 | /// and differs from getLocation().getStart(). | |||
| 3383 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 3384 | return QualifierLoc.getBeginLoc(); | |||
| 3385 | } | |||
| 3386 | ||||
| 3387 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 3388 | if (hasExplicitTemplateArgs()) | |||
| 3389 | return getRAngleLoc(); | |||
| 3390 | return getLocation(); | |||
| 3391 | } | |||
| 3392 | ||||
| 3393 | static bool classof(const Stmt *T) { | |||
| 3394 | return T->getStmtClass() == DependentScopeDeclRefExprClass; | |||
| 3395 | } | |||
| 3396 | ||||
| 3397 | child_range children() { | |||
| 3398 | return child_range(child_iterator(), child_iterator()); | |||
| 3399 | } | |||
| 3400 | ||||
| 3401 | const_child_range children() const { | |||
| 3402 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 3403 | } | |||
| 3404 | }; | |||
| 3405 | ||||
| 3406 | /// Represents an expression -- generally a full-expression -- that | |||
| 3407 | /// introduces cleanups to be run at the end of the sub-expression's | |||
| 3408 | /// evaluation. The most common source of expression-introduced | |||
| 3409 | /// cleanups is temporary objects in C++, but several other kinds of | |||
| 3410 | /// expressions can create cleanups, including basically every | |||
| 3411 | /// call in ARC that returns an Objective-C pointer. | |||
| 3412 | /// | |||
| 3413 | /// This expression also tracks whether the sub-expression contains a | |||
| 3414 | /// potentially-evaluated block literal. The lifetime of a block | |||
| 3415 | /// literal is the extent of the enclosing scope. | |||
| 3416 | class ExprWithCleanups final | |||
| 3417 | : public FullExpr, | |||
| 3418 | private llvm::TrailingObjects< | |||
| 3419 | ExprWithCleanups, | |||
| 3420 | llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>> { | |||
| 3421 | public: | |||
| 3422 | /// The type of objects that are kept in the cleanup. | |||
| 3423 | /// It's useful to remember the set of blocks and block-scoped compound | |||
| 3424 | /// literals; we could also remember the set of temporaries, but there's | |||
| 3425 | /// currently no need. | |||
| 3426 | using CleanupObject = llvm::PointerUnion<BlockDecl *, CompoundLiteralExpr *>; | |||
| 3427 | ||||
| 3428 | private: | |||
| 3429 | friend class ASTStmtReader; | |||
| 3430 | friend TrailingObjects; | |||
| 3431 | ||||
| 3432 | ExprWithCleanups(EmptyShell, unsigned NumObjects); | |||
| 3433 | ExprWithCleanups(Expr *SubExpr, bool CleanupsHaveSideEffects, | |||
| 3434 | ArrayRef<CleanupObject> Objects); | |||
| 3435 | ||||
| 3436 | public: | |||
| 3437 | static ExprWithCleanups *Create(const ASTContext &C, EmptyShell empty, | |||
| 3438 | unsigned numObjects); | |||
| 3439 | ||||
| 3440 | static ExprWithCleanups *Create(const ASTContext &C, Expr *subexpr, | |||
| 3441 | bool CleanupsHaveSideEffects, | |||
| 3442 | ArrayRef<CleanupObject> objects); | |||
| 3443 | ||||
| 3444 | ArrayRef<CleanupObject> getObjects() const { | |||
| 3445 | return llvm::ArrayRef(getTrailingObjects<CleanupObject>(), getNumObjects()); | |||
| 3446 | } | |||
| 3447 | ||||
| 3448 | unsigned getNumObjects() const { return ExprWithCleanupsBits.NumObjects; } | |||
| 3449 | ||||
| 3450 | CleanupObject getObject(unsigned i) const { | |||
| 3451 | assert(i < getNumObjects() && "Index out of range")(static_cast <bool> (i < getNumObjects() && "Index out of range" ) ? void (0) : __assert_fail ("i < getNumObjects() && \"Index out of range\"" , "clang/include/clang/AST/ExprCXX.h", 3451, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3452 | return getObjects()[i]; | |||
| 3453 | } | |||
| 3454 | ||||
| 3455 | bool cleanupsHaveSideEffects() const { | |||
| 3456 | return ExprWithCleanupsBits.CleanupsHaveSideEffects; | |||
| 3457 | } | |||
| 3458 | ||||
| 3459 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 3460 | return SubExpr->getBeginLoc(); | |||
| 3461 | } | |||
| 3462 | ||||
| 3463 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 3464 | return SubExpr->getEndLoc(); | |||
| 3465 | } | |||
| 3466 | ||||
| 3467 | // Implement isa/cast/dyncast/etc. | |||
| 3468 | static bool classof(const Stmt *T) { | |||
| 3469 | return T->getStmtClass() == ExprWithCleanupsClass; | |||
| 3470 | } | |||
| 3471 | ||||
| 3472 | // Iterators | |||
| 3473 | child_range children() { return child_range(&SubExpr, &SubExpr + 1); } | |||
| 3474 | ||||
| 3475 | const_child_range children() const { | |||
| 3476 | return const_child_range(&SubExpr, &SubExpr + 1); | |||
| 3477 | } | |||
| 3478 | }; | |||
| 3479 | ||||
| 3480 | /// Describes an explicit type conversion that uses functional | |||
| 3481 | /// notion but could not be resolved because one or more arguments are | |||
| 3482 | /// type-dependent. | |||
| 3483 | /// | |||
| 3484 | /// The explicit type conversions expressed by | |||
| 3485 | /// CXXUnresolvedConstructExpr have the form <tt>T(a1, a2, ..., aN)</tt>, | |||
| 3486 | /// where \c T is some type and \c a1, \c a2, ..., \c aN are values, and | |||
| 3487 | /// either \c T is a dependent type or one or more of the <tt>a</tt>'s is | |||
| 3488 | /// type-dependent. For example, this would occur in a template such | |||
| 3489 | /// as: | |||
| 3490 | /// | |||
| 3491 | /// \code | |||
| 3492 | /// template<typename T, typename A1> | |||
| 3493 | /// inline T make_a(const A1& a1) { | |||
| 3494 | /// return T(a1); | |||
| 3495 | /// } | |||
| 3496 | /// \endcode | |||
| 3497 | /// | |||
| 3498 | /// When the returned expression is instantiated, it may resolve to a | |||
| 3499 | /// constructor call, conversion function call, or some kind of type | |||
| 3500 | /// conversion. | |||
| 3501 | class CXXUnresolvedConstructExpr final | |||
| 3502 | : public Expr, | |||
| 3503 | private llvm::TrailingObjects<CXXUnresolvedConstructExpr, Expr *> { | |||
| 3504 | friend class ASTStmtReader; | |||
| 3505 | friend TrailingObjects; | |||
| 3506 | ||||
| 3507 | /// The type being constructed, and whether the construct expression models | |||
| 3508 | /// list initialization or not. | |||
| 3509 | llvm::PointerIntPair<TypeSourceInfo *, 1> TypeAndInitForm; | |||
| 3510 | ||||
| 3511 | /// The location of the left parentheses ('('). | |||
| 3512 | SourceLocation LParenLoc; | |||
| 3513 | ||||
| 3514 | /// The location of the right parentheses (')'). | |||
| 3515 | SourceLocation RParenLoc; | |||
| 3516 | ||||
| 3517 | CXXUnresolvedConstructExpr(QualType T, TypeSourceInfo *TSI, | |||
| 3518 | SourceLocation LParenLoc, ArrayRef<Expr *> Args, | |||
| 3519 | SourceLocation RParenLoc, bool IsListInit); | |||
| 3520 | ||||
| 3521 | CXXUnresolvedConstructExpr(EmptyShell Empty, unsigned NumArgs) | |||
| 3522 | : Expr(CXXUnresolvedConstructExprClass, Empty) { | |||
| 3523 | CXXUnresolvedConstructExprBits.NumArgs = NumArgs; | |||
| 3524 | } | |||
| 3525 | ||||
| 3526 | public: | |||
| 3527 | static CXXUnresolvedConstructExpr * | |||
| 3528 | Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, | |||
| 3529 | SourceLocation LParenLoc, ArrayRef<Expr *> Args, | |||
| 3530 | SourceLocation RParenLoc, bool IsListInit); | |||
| 3531 | ||||
| 3532 | static CXXUnresolvedConstructExpr *CreateEmpty(const ASTContext &Context, | |||
| 3533 | unsigned NumArgs); | |||
| 3534 | ||||
| 3535 | /// Retrieve the type that is being constructed, as specified | |||
| 3536 | /// in the source code. | |||
| 3537 | QualType getTypeAsWritten() const { return getTypeSourceInfo()->getType(); } | |||
| 3538 | ||||
| 3539 | /// Retrieve the type source information for the type being | |||
| 3540 | /// constructed. | |||
| 3541 | TypeSourceInfo *getTypeSourceInfo() const { | |||
| 3542 | return TypeAndInitForm.getPointer(); | |||
| 3543 | } | |||
| 3544 | ||||
| 3545 | /// Retrieve the location of the left parentheses ('(') that | |||
| 3546 | /// precedes the argument list. | |||
| 3547 | SourceLocation getLParenLoc() const { return LParenLoc; } | |||
| 3548 | void setLParenLoc(SourceLocation L) { LParenLoc = L; } | |||
| 3549 | ||||
| 3550 | /// Retrieve the location of the right parentheses (')') that | |||
| 3551 | /// follows the argument list. | |||
| 3552 | SourceLocation getRParenLoc() const { return RParenLoc; } | |||
| 3553 | void setRParenLoc(SourceLocation L) { RParenLoc = L; } | |||
| 3554 | ||||
| 3555 | /// Determine whether this expression models list-initialization. | |||
| 3556 | /// If so, there will be exactly one subexpression, which will be | |||
| 3557 | /// an InitListExpr. | |||
| 3558 | bool isListInitialization() const { return TypeAndInitForm.getInt(); } | |||
| 3559 | ||||
| 3560 | /// Retrieve the number of arguments. | |||
| 3561 | unsigned getNumArgs() const { return CXXUnresolvedConstructExprBits.NumArgs; } | |||
| 3562 | ||||
| 3563 | using arg_iterator = Expr **; | |||
| 3564 | using arg_range = llvm::iterator_range<arg_iterator>; | |||
| 3565 | ||||
| 3566 | arg_iterator arg_begin() { return getTrailingObjects<Expr *>(); } | |||
| 3567 | arg_iterator arg_end() { return arg_begin() + getNumArgs(); } | |||
| 3568 | arg_range arguments() { return arg_range(arg_begin(), arg_end()); } | |||
| 3569 | ||||
| 3570 | using const_arg_iterator = const Expr* const *; | |||
| 3571 | using const_arg_range = llvm::iterator_range<const_arg_iterator>; | |||
| 3572 | ||||
| 3573 | const_arg_iterator arg_begin() const { return getTrailingObjects<Expr *>(); } | |||
| 3574 | const_arg_iterator arg_end() const { return arg_begin() + getNumArgs(); } | |||
| 3575 | const_arg_range arguments() const { | |||
| 3576 | return const_arg_range(arg_begin(), arg_end()); | |||
| 3577 | } | |||
| 3578 | ||||
| 3579 | Expr *getArg(unsigned I) { | |||
| 3580 | assert(I < getNumArgs() && "Argument index out-of-range")(static_cast <bool> (I < getNumArgs() && "Argument index out-of-range" ) ? void (0) : __assert_fail ("I < getNumArgs() && \"Argument index out-of-range\"" , "clang/include/clang/AST/ExprCXX.h", 3580, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3581 | return arg_begin()[I]; | |||
| 3582 | } | |||
| 3583 | ||||
| 3584 | const Expr *getArg(unsigned I) const { | |||
| 3585 | assert(I < getNumArgs() && "Argument index out-of-range")(static_cast <bool> (I < getNumArgs() && "Argument index out-of-range" ) ? void (0) : __assert_fail ("I < getNumArgs() && \"Argument index out-of-range\"" , "clang/include/clang/AST/ExprCXX.h", 3585, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3586 | return arg_begin()[I]; | |||
| 3587 | } | |||
| 3588 | ||||
| 3589 | void setArg(unsigned I, Expr *E) { | |||
| 3590 | assert(I < getNumArgs() && "Argument index out-of-range")(static_cast <bool> (I < getNumArgs() && "Argument index out-of-range" ) ? void (0) : __assert_fail ("I < getNumArgs() && \"Argument index out-of-range\"" , "clang/include/clang/AST/ExprCXX.h", 3590, __extension__ __PRETTY_FUNCTION__ )); | |||
| 3591 | arg_begin()[I] = E; | |||
| 3592 | } | |||
| 3593 | ||||
| 3594 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)); | |||
| 3595 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 3596 | if (!RParenLoc.isValid() && getNumArgs() > 0) | |||
| 3597 | return getArg(getNumArgs() - 1)->getEndLoc(); | |||
| 3598 | return RParenLoc; | |||
| 3599 | } | |||
| 3600 | ||||
| 3601 | static bool classof(const Stmt *T) { | |||
| 3602 | return T->getStmtClass() == CXXUnresolvedConstructExprClass; | |||
| 3603 | } | |||
| 3604 | ||||
| 3605 | // Iterators | |||
| 3606 | child_range children() { | |||
| 3607 | auto **begin = reinterpret_cast<Stmt **>(arg_begin()); | |||
| 3608 | return child_range(begin, begin + getNumArgs()); | |||
| 3609 | } | |||
| 3610 | ||||
| 3611 | const_child_range children() const { | |||
| 3612 | auto **begin = reinterpret_cast<Stmt **>( | |||
| 3613 | const_cast<CXXUnresolvedConstructExpr *>(this)->arg_begin()); | |||
| 3614 | return const_child_range(begin, begin + getNumArgs()); | |||
| 3615 | } | |||
| 3616 | }; | |||
| 3617 | ||||
| 3618 | /// Represents a C++ member access expression where the actual | |||
| 3619 | /// member referenced could not be resolved because the base | |||
| 3620 | /// expression or the member name was dependent. | |||
| 3621 | /// | |||
| 3622 | /// Like UnresolvedMemberExprs, these can be either implicit or | |||
| 3623 | /// explicit accesses. It is only possible to get one of these with | |||
| 3624 | /// an implicit access if a qualifier is provided. | |||
| 3625 | class CXXDependentScopeMemberExpr final | |||
| 3626 | : public Expr, | |||
| 3627 | private llvm::TrailingObjects<CXXDependentScopeMemberExpr, | |||
| 3628 | ASTTemplateKWAndArgsInfo, | |||
| 3629 | TemplateArgumentLoc, NamedDecl *> { | |||
| 3630 | friend class ASTStmtReader; | |||
| 3631 | friend class ASTStmtWriter; | |||
| 3632 | friend TrailingObjects; | |||
| 3633 | ||||
| 3634 | /// The expression for the base pointer or class reference, | |||
| 3635 | /// e.g., the \c x in x.f. Can be null in implicit accesses. | |||
| 3636 | Stmt *Base; | |||
| 3637 | ||||
| 3638 | /// The type of the base expression. Never null, even for | |||
| 3639 | /// implicit accesses. | |||
| 3640 | QualType BaseType; | |||
| 3641 | ||||
| 3642 | /// The nested-name-specifier that precedes the member name, if any. | |||
| 3643 | /// FIXME: This could be in principle store as a trailing object. | |||
| 3644 | /// However the performance impact of doing so should be investigated first. | |||
| 3645 | NestedNameSpecifierLoc QualifierLoc; | |||
| 3646 | ||||
| 3647 | /// The member to which this member expression refers, which | |||
| 3648 | /// can be name, overloaded operator, or destructor. | |||
| 3649 | /// | |||
| 3650 | /// FIXME: could also be a template-id | |||
| 3651 | DeclarationNameInfo MemberNameInfo; | |||
| 3652 | ||||
| 3653 | // CXXDependentScopeMemberExpr is followed by several trailing objects, | |||
| 3654 | // some of which optional. They are in order: | |||
| 3655 | // | |||
| 3656 | // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified | |||
| 3657 | // template keyword and arguments. Present if and only if | |||
| 3658 | // hasTemplateKWAndArgsInfo(). | |||
| 3659 | // | |||
| 3660 | // * An array of getNumTemplateArgs() TemplateArgumentLoc containing location | |||
| 3661 | // information for the explicitly specified template arguments. | |||
| 3662 | // | |||
| 3663 | // * An optional NamedDecl *. In a qualified member access expression such | |||
| 3664 | // as t->Base::f, this member stores the resolves of name lookup in the | |||
| 3665 | // context of the member access expression, to be used at instantiation | |||
| 3666 | // time. Present if and only if hasFirstQualifierFoundInScope(). | |||
| 3667 | ||||
| 3668 | bool hasTemplateKWAndArgsInfo() const { | |||
| 3669 | return CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo; | |||
| 3670 | } | |||
| 3671 | ||||
| 3672 | bool hasFirstQualifierFoundInScope() const { | |||
| 3673 | return CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope; | |||
| 3674 | } | |||
| 3675 | ||||
| 3676 | unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { | |||
| 3677 | return hasTemplateKWAndArgsInfo(); | |||
| 3678 | } | |||
| 3679 | ||||
| 3680 | unsigned numTrailingObjects(OverloadToken<TemplateArgumentLoc>) const { | |||
| 3681 | return getNumTemplateArgs(); | |||
| 3682 | } | |||
| 3683 | ||||
| 3684 | unsigned numTrailingObjects(OverloadToken<NamedDecl *>) const { | |||
| 3685 | return hasFirstQualifierFoundInScope(); | |||
| 3686 | } | |||
| 3687 | ||||
| 3688 | CXXDependentScopeMemberExpr(const ASTContext &Ctx, Expr *Base, | |||
| 3689 | QualType BaseType, bool IsArrow, | |||
| 3690 | SourceLocation OperatorLoc, | |||
| 3691 | NestedNameSpecifierLoc QualifierLoc, | |||
| 3692 | SourceLocation TemplateKWLoc, | |||
| 3693 | NamedDecl *FirstQualifierFoundInScope, | |||
| 3694 | DeclarationNameInfo MemberNameInfo, | |||
| 3695 | const TemplateArgumentListInfo *TemplateArgs); | |||
| 3696 | ||||
| 3697 | CXXDependentScopeMemberExpr(EmptyShell Empty, bool HasTemplateKWAndArgsInfo, | |||
| 3698 | bool HasFirstQualifierFoundInScope); | |||
| 3699 | ||||
| 3700 | public: | |||
| 3701 | static CXXDependentScopeMemberExpr * | |||
| 3702 | Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, | |||
| 3703 | SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, | |||
| 3704 | SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, | |||
| 3705 | DeclarationNameInfo MemberNameInfo, | |||
| 3706 | const TemplateArgumentListInfo *TemplateArgs); | |||
| 3707 | ||||
| 3708 | static CXXDependentScopeMemberExpr * | |||
| 3709 | CreateEmpty(const ASTContext &Ctx, bool HasTemplateKWAndArgsInfo, | |||
| 3710 | unsigned NumTemplateArgs, bool HasFirstQualifierFoundInScope); | |||
| 3711 | ||||
| 3712 | /// True if this is an implicit access, i.e. one in which the | |||
| 3713 | /// member being accessed was not written in the source. The source | |||
| 3714 | /// location of the operator is invalid in this case. | |||
| 3715 | bool isImplicitAccess() const { | |||
| 3716 | if (!Base) | |||
| 3717 | return true; | |||
| 3718 | return cast<Expr>(Base)->isImplicitCXXThis(); | |||
| 3719 | } | |||
| 3720 | ||||
| 3721 | /// Retrieve the base object of this member expressions, | |||
| 3722 | /// e.g., the \c x in \c x.m. | |||
| 3723 | Expr *getBase() const { | |||
| 3724 | assert(!isImplicitAccess())(static_cast <bool> (!isImplicitAccess()) ? void (0) : __assert_fail ("!isImplicitAccess()", "clang/include/clang/AST/ExprCXX.h", 3724, __extension__ __PRETTY_FUNCTION__)); | |||
| 3725 | return cast<Expr>(Base); | |||
| 3726 | } | |||
| 3727 | ||||
| 3728 | QualType getBaseType() const { return BaseType; } | |||
| 3729 | ||||
| 3730 | /// Determine whether this member expression used the '->' | |||
| 3731 | /// operator; otherwise, it used the '.' operator. | |||
| 3732 | bool isArrow() const { return CXXDependentScopeMemberExprBits.IsArrow; } | |||
| 3733 | ||||
| 3734 | /// Retrieve the location of the '->' or '.' operator. | |||
| 3735 | SourceLocation getOperatorLoc() const { | |||
| 3736 | return CXXDependentScopeMemberExprBits.OperatorLoc; | |||
| 3737 | } | |||
| 3738 | ||||
| 3739 | /// Retrieve the nested-name-specifier that qualifies the member name. | |||
| 3740 | NestedNameSpecifier *getQualifier() const { | |||
| 3741 | return QualifierLoc.getNestedNameSpecifier(); | |||
| 3742 | } | |||
| 3743 | ||||
| 3744 | /// Retrieve the nested-name-specifier that qualifies the member | |||
| 3745 | /// name, with source location information. | |||
| 3746 | NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; } | |||
| 3747 | ||||
| 3748 | /// Retrieve the first part of the nested-name-specifier that was | |||
| 3749 | /// found in the scope of the member access expression when the member access | |||
| 3750 | /// was initially parsed. | |||
| 3751 | /// | |||
| 3752 | /// This function only returns a useful result when member access expression | |||
| 3753 | /// uses a qualified member name, e.g., "x.Base::f". Here, the declaration | |||
| 3754 | /// returned by this function describes what was found by unqualified name | |||
| 3755 | /// lookup for the identifier "Base" within the scope of the member access | |||
| 3756 | /// expression itself. At template instantiation time, this information is | |||
| 3757 | /// combined with the results of name lookup into the type of the object | |||
| 3758 | /// expression itself (the class type of x). | |||
| 3759 | NamedDecl *getFirstQualifierFoundInScope() const { | |||
| 3760 | if (!hasFirstQualifierFoundInScope()) | |||
| 3761 | return nullptr; | |||
| 3762 | return *getTrailingObjects<NamedDecl *>(); | |||
| 3763 | } | |||
| 3764 | ||||
| 3765 | /// Retrieve the name of the member that this expression refers to. | |||
| 3766 | const DeclarationNameInfo &getMemberNameInfo() const { | |||
| 3767 | return MemberNameInfo; | |||
| 3768 | } | |||
| 3769 | ||||
| 3770 | /// Retrieve the name of the member that this expression refers to. | |||
| 3771 | DeclarationName getMember() const { return MemberNameInfo.getName(); } | |||
| 3772 | ||||
| 3773 | // Retrieve the location of the name of the member that this | |||
| 3774 | // expression refers to. | |||
| 3775 | SourceLocation getMemberLoc() const { return MemberNameInfo.getLoc(); } | |||
| 3776 | ||||
| 3777 | /// Retrieve the location of the template keyword preceding the | |||
| 3778 | /// member name, if any. | |||
| 3779 | SourceLocation getTemplateKeywordLoc() const { | |||
| 3780 | if (!hasTemplateKWAndArgsInfo()) | |||
| 3781 | return SourceLocation(); | |||
| 3782 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->TemplateKWLoc; | |||
| 3783 | } | |||
| 3784 | ||||
| 3785 | /// Retrieve the location of the left angle bracket starting the | |||
| 3786 | /// explicit template argument list following the member name, if any. | |||
| 3787 | SourceLocation getLAngleLoc() const { | |||
| 3788 | if (!hasTemplateKWAndArgsInfo()) | |||
| 3789 | return SourceLocation(); | |||
| 3790 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->LAngleLoc; | |||
| 3791 | } | |||
| 3792 | ||||
| 3793 | /// Retrieve the location of the right angle bracket ending the | |||
| 3794 | /// explicit template argument list following the member name, if any. | |||
| 3795 | SourceLocation getRAngleLoc() const { | |||
| 3796 | if (!hasTemplateKWAndArgsInfo()) | |||
| 3797 | return SourceLocation(); | |||
| 3798 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->RAngleLoc; | |||
| 3799 | } | |||
| 3800 | ||||
| 3801 | /// Determines whether the member name was preceded by the template keyword. | |||
| 3802 | bool hasTemplateKeyword() const { return getTemplateKeywordLoc().isValid(); } | |||
| 3803 | ||||
| 3804 | /// Determines whether this member expression actually had a C++ | |||
| 3805 | /// template argument list explicitly specified, e.g., x.f<int>. | |||
| 3806 | bool hasExplicitTemplateArgs() const { return getLAngleLoc().isValid(); } | |||
| 3807 | ||||
| 3808 | /// Copies the template arguments (if present) into the given | |||
| 3809 | /// structure. | |||
| 3810 | void copyTemplateArgumentsInto(TemplateArgumentListInfo &List) const { | |||
| 3811 | if (hasExplicitTemplateArgs()) | |||
| 3812 | getTrailingObjects<ASTTemplateKWAndArgsInfo>()->copyInto( | |||
| 3813 | getTrailingObjects<TemplateArgumentLoc>(), List); | |||
| 3814 | } | |||
| 3815 | ||||
| 3816 | /// Retrieve the template arguments provided as part of this | |||
| 3817 | /// template-id. | |||
| 3818 | const TemplateArgumentLoc *getTemplateArgs() const { | |||
| 3819 | if (!hasExplicitTemplateArgs()) | |||
| 3820 | return nullptr; | |||
| 3821 | ||||
| 3822 | return getTrailingObjects<TemplateArgumentLoc>(); | |||
| 3823 | } | |||
| 3824 | ||||
| 3825 | /// Retrieve the number of template arguments provided as part of this | |||
| 3826 | /// template-id. | |||
| 3827 | unsigned getNumTemplateArgs() const { | |||
| 3828 | if (!hasExplicitTemplateArgs()) | |||
| 3829 | return 0; | |||
| 3830 | ||||
| 3831 | return getTrailingObjects<ASTTemplateKWAndArgsInfo>()->NumTemplateArgs; | |||
| 3832 | } | |||
| 3833 | ||||
| 3834 | ArrayRef<TemplateArgumentLoc> template_arguments() const { | |||
| 3835 | return {getTemplateArgs(), getNumTemplateArgs()}; | |||
| 3836 | } | |||
| 3837 | ||||
| 3838 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 3839 | if (!isImplicitAccess()) | |||
| 3840 | return Base->getBeginLoc(); | |||
| 3841 | if (getQualifier()) | |||
| 3842 | return getQualifierLoc().getBeginLoc(); | |||
| 3843 | return MemberNameInfo.getBeginLoc(); | |||
| 3844 | } | |||
| 3845 | ||||
| 3846 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 3847 | if (hasExplicitTemplateArgs()) | |||
| 3848 | return getRAngleLoc(); | |||
| 3849 | return MemberNameInfo.getEndLoc(); | |||
| 3850 | } | |||
| 3851 | ||||
| 3852 | static bool classof(const Stmt *T) { | |||
| 3853 | return T->getStmtClass() == CXXDependentScopeMemberExprClass; | |||
| 3854 | } | |||
| 3855 | ||||
| 3856 | // Iterators | |||
| 3857 | child_range children() { | |||
| 3858 | if (isImplicitAccess()) | |||
| 3859 | return child_range(child_iterator(), child_iterator()); | |||
| 3860 | return child_range(&Base, &Base + 1); | |||
| 3861 | } | |||
| 3862 | ||||
| 3863 | const_child_range children() const { | |||
| 3864 | if (isImplicitAccess()) | |||
| 3865 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 3866 | return const_child_range(&Base, &Base + 1); | |||
| 3867 | } | |||
| 3868 | }; | |||
| 3869 | ||||
| 3870 | /// Represents a C++ member access expression for which lookup | |||
| 3871 | /// produced a set of overloaded functions. | |||
| 3872 | /// | |||
| 3873 | /// The member access may be explicit or implicit: | |||
| 3874 | /// \code | |||
| 3875 | /// struct A { | |||
| 3876 | /// int a, b; | |||
| 3877 | /// int explicitAccess() { return this->a + this->A::b; } | |||
| 3878 | /// int implicitAccess() { return a + A::b; } | |||
| 3879 | /// }; | |||
| 3880 | /// \endcode | |||
| 3881 | /// | |||
| 3882 | /// In the final AST, an explicit access always becomes a MemberExpr. | |||
| 3883 | /// An implicit access may become either a MemberExpr or a | |||
| 3884 | /// DeclRefExpr, depending on whether the member is static. | |||
| 3885 | class UnresolvedMemberExpr final | |||
| 3886 | : public OverloadExpr, | |||
| 3887 | private llvm::TrailingObjects<UnresolvedMemberExpr, DeclAccessPair, | |||
| 3888 | ASTTemplateKWAndArgsInfo, | |||
| 3889 | TemplateArgumentLoc> { | |||
| 3890 | friend class ASTStmtReader; | |||
| 3891 | friend class OverloadExpr; | |||
| 3892 | friend TrailingObjects; | |||
| 3893 | ||||
| 3894 | /// The expression for the base pointer or class reference, | |||
| 3895 | /// e.g., the \c x in x.f. | |||
| 3896 | /// | |||
| 3897 | /// This can be null if this is an 'unbased' member expression. | |||
| 3898 | Stmt *Base; | |||
| 3899 | ||||
| 3900 | /// The type of the base expression; never null. | |||
| 3901 | QualType BaseType; | |||
| 3902 | ||||
| 3903 | /// The location of the '->' or '.' operator. | |||
| 3904 | SourceLocation OperatorLoc; | |||
| 3905 | ||||
| 3906 | // UnresolvedMemberExpr is followed by several trailing objects. | |||
| 3907 | // They are in order: | |||
| 3908 | // | |||
| 3909 | // * An array of getNumResults() DeclAccessPair for the results. These are | |||
| 3910 | // undesugared, which is to say, they may include UsingShadowDecls. | |||
| 3911 | // Access is relative to the naming class. | |||
| 3912 | // | |||
| 3913 | // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified | |||
| 3914 | // template keyword and arguments. Present if and only if | |||
| 3915 | // hasTemplateKWAndArgsInfo(). | |||
| 3916 | // | |||
| 3917 | // * An array of getNumTemplateArgs() TemplateArgumentLoc containing | |||
| 3918 | // location information for the explicitly specified template arguments. | |||
| 3919 | ||||
| 3920 | UnresolvedMemberExpr(const ASTContext &Context, bool HasUnresolvedUsing, | |||
| 3921 | Expr *Base, QualType BaseType, bool IsArrow, | |||
| 3922 | SourceLocation OperatorLoc, | |||
| 3923 | NestedNameSpecifierLoc QualifierLoc, | |||
| 3924 | SourceLocation TemplateKWLoc, | |||
| 3925 | const DeclarationNameInfo &MemberNameInfo, | |||
| 3926 | const TemplateArgumentListInfo *TemplateArgs, | |||
| 3927 | UnresolvedSetIterator Begin, UnresolvedSetIterator End); | |||
| 3928 | ||||
| 3929 | UnresolvedMemberExpr(EmptyShell Empty, unsigned NumResults, | |||
| 3930 | bool HasTemplateKWAndArgsInfo); | |||
| 3931 | ||||
| 3932 | unsigned numTrailingObjects(OverloadToken<DeclAccessPair>) const { | |||
| 3933 | return getNumDecls(); | |||
| 3934 | } | |||
| 3935 | ||||
| 3936 | unsigned numTrailingObjects(OverloadToken<ASTTemplateKWAndArgsInfo>) const { | |||
| 3937 | return hasTemplateKWAndArgsInfo(); | |||
| 3938 | } | |||
| 3939 | ||||
| 3940 | public: | |||
| 3941 | static UnresolvedMemberExpr * | |||
| 3942 | Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, | |||
| 3943 | QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, | |||
| 3944 | NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, | |||
| 3945 | const DeclarationNameInfo &MemberNameInfo, | |||
| 3946 | const TemplateArgumentListInfo *TemplateArgs, | |||
| 3947 | UnresolvedSetIterator Begin, UnresolvedSetIterator End); | |||
| 3948 | ||||
| 3949 | static UnresolvedMemberExpr *CreateEmpty(const ASTContext &Context, | |||
| 3950 | unsigned NumResults, | |||
| 3951 | bool HasTemplateKWAndArgsInfo, | |||
| 3952 | unsigned NumTemplateArgs); | |||
| 3953 | ||||
| 3954 | /// True if this is an implicit access, i.e., one in which the | |||
| 3955 | /// member being accessed was not written in the source. | |||
| 3956 | /// | |||
| 3957 | /// The source location of the operator is invalid in this case. | |||
| 3958 | bool isImplicitAccess() const; | |||
| 3959 | ||||
| 3960 | /// Retrieve the base object of this member expressions, | |||
| 3961 | /// e.g., the \c x in \c x.m. | |||
| 3962 | Expr *getBase() { | |||
| 3963 | assert(!isImplicitAccess())(static_cast <bool> (!isImplicitAccess()) ? void (0) : __assert_fail ("!isImplicitAccess()", "clang/include/clang/AST/ExprCXX.h", 3963, __extension__ __PRETTY_FUNCTION__)); | |||
| 3964 | return cast<Expr>(Base); | |||
| 3965 | } | |||
| 3966 | const Expr *getBase() const { | |||
| 3967 | assert(!isImplicitAccess())(static_cast <bool> (!isImplicitAccess()) ? void (0) : __assert_fail ("!isImplicitAccess()", "clang/include/clang/AST/ExprCXX.h", 3967, __extension__ __PRETTY_FUNCTION__)); | |||
| 3968 | return cast<Expr>(Base); | |||
| 3969 | } | |||
| 3970 | ||||
| 3971 | QualType getBaseType() const { return BaseType; } | |||
| 3972 | ||||
| 3973 | /// Determine whether the lookup results contain an unresolved using | |||
| 3974 | /// declaration. | |||
| 3975 | bool hasUnresolvedUsing() const { | |||
| 3976 | return UnresolvedMemberExprBits.HasUnresolvedUsing; | |||
| 3977 | } | |||
| 3978 | ||||
| 3979 | /// Determine whether this member expression used the '->' | |||
| 3980 | /// operator; otherwise, it used the '.' operator. | |||
| 3981 | bool isArrow() const { return UnresolvedMemberExprBits.IsArrow; } | |||
| 3982 | ||||
| 3983 | /// Retrieve the location of the '->' or '.' operator. | |||
| 3984 | SourceLocation getOperatorLoc() const { return OperatorLoc; } | |||
| 3985 | ||||
| 3986 | /// Retrieve the naming class of this lookup. | |||
| 3987 | CXXRecordDecl *getNamingClass(); | |||
| 3988 | const CXXRecordDecl *getNamingClass() const { | |||
| 3989 | return const_cast<UnresolvedMemberExpr *>(this)->getNamingClass(); | |||
| 3990 | } | |||
| 3991 | ||||
| 3992 | /// Retrieve the full name info for the member that this expression | |||
| 3993 | /// refers to. | |||
| 3994 | const DeclarationNameInfo &getMemberNameInfo() const { return getNameInfo(); } | |||
| 3995 | ||||
| 3996 | /// Retrieve the name of the member that this expression refers to. | |||
| 3997 | DeclarationName getMemberName() const { return getName(); } | |||
| 3998 | ||||
| 3999 | /// Retrieve the location of the name of the member that this | |||
| 4000 | /// expression refers to. | |||
| 4001 | SourceLocation getMemberLoc() const { return getNameLoc(); } | |||
| 4002 | ||||
| 4003 | /// Return the preferred location (the member name) for the arrow when | |||
| 4004 | /// diagnosing a problem with this expression. | |||
| 4005 | SourceLocation getExprLoc() const LLVM_READONLY__attribute__((__pure__)) { return getMemberLoc(); } | |||
| 4006 | ||||
| 4007 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 4008 | if (!isImplicitAccess()) | |||
| 4009 | return Base->getBeginLoc(); | |||
| 4010 | if (NestedNameSpecifierLoc l = getQualifierLoc()) | |||
| 4011 | return l.getBeginLoc(); | |||
| 4012 | return getMemberNameInfo().getBeginLoc(); | |||
| 4013 | } | |||
| 4014 | ||||
| 4015 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 4016 | if (hasExplicitTemplateArgs()) | |||
| 4017 | return getRAngleLoc(); | |||
| 4018 | return getMemberNameInfo().getEndLoc(); | |||
| 4019 | } | |||
| 4020 | ||||
| 4021 | static bool classof(const Stmt *T) { | |||
| 4022 | return T->getStmtClass() == UnresolvedMemberExprClass; | |||
| 4023 | } | |||
| 4024 | ||||
| 4025 | // Iterators | |||
| 4026 | child_range children() { | |||
| 4027 | if (isImplicitAccess()) | |||
| 4028 | return child_range(child_iterator(), child_iterator()); | |||
| 4029 | return child_range(&Base, &Base + 1); | |||
| 4030 | } | |||
| 4031 | ||||
| 4032 | const_child_range children() const { | |||
| 4033 | if (isImplicitAccess()) | |||
| 4034 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 4035 | return const_child_range(&Base, &Base + 1); | |||
| 4036 | } | |||
| 4037 | }; | |||
| 4038 | ||||
| 4039 | DeclAccessPair *OverloadExpr::getTrailingResults() { | |||
| 4040 | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) | |||
| 4041 | return ULE->getTrailingObjects<DeclAccessPair>(); | |||
| 4042 | return cast<UnresolvedMemberExpr>(this)->getTrailingObjects<DeclAccessPair>(); | |||
| 4043 | } | |||
| 4044 | ||||
| 4045 | ASTTemplateKWAndArgsInfo *OverloadExpr::getTrailingASTTemplateKWAndArgsInfo() { | |||
| 4046 | if (!hasTemplateKWAndArgsInfo()) | |||
| 4047 | return nullptr; | |||
| 4048 | ||||
| 4049 | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) | |||
| 4050 | return ULE->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); | |||
| 4051 | return cast<UnresolvedMemberExpr>(this) | |||
| 4052 | ->getTrailingObjects<ASTTemplateKWAndArgsInfo>(); | |||
| 4053 | } | |||
| 4054 | ||||
| 4055 | TemplateArgumentLoc *OverloadExpr::getTrailingTemplateArgumentLoc() { | |||
| 4056 | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) | |||
| 4057 | return ULE->getTrailingObjects<TemplateArgumentLoc>(); | |||
| 4058 | return cast<UnresolvedMemberExpr>(this) | |||
| 4059 | ->getTrailingObjects<TemplateArgumentLoc>(); | |||
| 4060 | } | |||
| 4061 | ||||
| 4062 | CXXRecordDecl *OverloadExpr::getNamingClass() { | |||
| 4063 | if (auto *ULE = dyn_cast<UnresolvedLookupExpr>(this)) | |||
| 4064 | return ULE->getNamingClass(); | |||
| 4065 | return cast<UnresolvedMemberExpr>(this)->getNamingClass(); | |||
| 4066 | } | |||
| 4067 | ||||
| 4068 | /// Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]). | |||
| 4069 | /// | |||
| 4070 | /// The noexcept expression tests whether a given expression might throw. Its | |||
| 4071 | /// result is a boolean constant. | |||
| 4072 | class CXXNoexceptExpr : public Expr { | |||
| 4073 | friend class ASTStmtReader; | |||
| 4074 | ||||
| 4075 | Stmt *Operand; | |||
| 4076 | SourceRange Range; | |||
| 4077 | ||||
| 4078 | public: | |||
| 4079 | CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val, | |||
| 4080 | SourceLocation Keyword, SourceLocation RParen) | |||
| 4081 | : Expr(CXXNoexceptExprClass, Ty, VK_PRValue, OK_Ordinary), | |||
| 4082 | Operand(Operand), Range(Keyword, RParen) { | |||
| 4083 | CXXNoexceptExprBits.Value = Val == CT_Cannot; | |||
| 4084 | setDependence(computeDependence(this, Val)); | |||
| 4085 | } | |||
| 4086 | ||||
| 4087 | CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {} | |||
| 4088 | ||||
| 4089 | Expr *getOperand() const { return static_cast<Expr *>(Operand); } | |||
| 4090 | ||||
| 4091 | SourceLocation getBeginLoc() const { return Range.getBegin(); } | |||
| 4092 | SourceLocation getEndLoc() const { return Range.getEnd(); } | |||
| 4093 | SourceRange getSourceRange() const { return Range; } | |||
| 4094 | ||||
| 4095 | bool getValue() const { return CXXNoexceptExprBits.Value; } | |||
| 4096 | ||||
| 4097 | static bool classof(const Stmt *T) { | |||
| 4098 | return T->getStmtClass() == CXXNoexceptExprClass; | |||
| 4099 | } | |||
| 4100 | ||||
| 4101 | // Iterators | |||
| 4102 | child_range children() { return child_range(&Operand, &Operand + 1); } | |||
| 4103 | ||||
| 4104 | const_child_range children() const { | |||
| 4105 | return const_child_range(&Operand, &Operand + 1); | |||
| 4106 | } | |||
| 4107 | }; | |||
| 4108 | ||||
| 4109 | /// Represents a C++11 pack expansion that produces a sequence of | |||
| 4110 | /// expressions. | |||
| 4111 | /// | |||
| 4112 | /// A pack expansion expression contains a pattern (which itself is an | |||
| 4113 | /// expression) followed by an ellipsis. For example: | |||
| 4114 | /// | |||
| 4115 | /// \code | |||
| 4116 | /// template<typename F, typename ...Types> | |||
| 4117 | /// void forward(F f, Types &&...args) { | |||
| 4118 | /// f(static_cast<Types&&>(args)...); | |||
| 4119 | /// } | |||
| 4120 | /// \endcode | |||
| 4121 | /// | |||
| 4122 | /// Here, the argument to the function object \c f is a pack expansion whose | |||
| 4123 | /// pattern is \c static_cast<Types&&>(args). When the \c forward function | |||
| 4124 | /// template is instantiated, the pack expansion will instantiate to zero or | |||
| 4125 | /// or more function arguments to the function object \c f. | |||
| 4126 | class PackExpansionExpr : public Expr { | |||
| 4127 | friend class ASTStmtReader; | |||
| 4128 | friend class ASTStmtWriter; | |||
| 4129 | ||||
| 4130 | SourceLocation EllipsisLoc; | |||
| 4131 | ||||
| 4132 | /// The number of expansions that will be produced by this pack | |||
| 4133 | /// expansion expression, if known. | |||
| 4134 | /// | |||
| 4135 | /// When zero, the number of expansions is not known. Otherwise, this value | |||
| 4136 | /// is the number of expansions + 1. | |||
| 4137 | unsigned NumExpansions; | |||
| 4138 | ||||
| 4139 | Stmt *Pattern; | |||
| 4140 | ||||
| 4141 | public: | |||
| 4142 | PackExpansionExpr(QualType T, Expr *Pattern, SourceLocation EllipsisLoc, | |||
| 4143 | std::optional<unsigned> NumExpansions) | |||
| 4144 | : Expr(PackExpansionExprClass, T, Pattern->getValueKind(), | |||
| 4145 | Pattern->getObjectKind()), | |||
| 4146 | EllipsisLoc(EllipsisLoc), | |||
| 4147 | NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), | |||
| 4148 | Pattern(Pattern) { | |||
| 4149 | setDependence(computeDependence(this)); | |||
| 4150 | } | |||
| 4151 | ||||
| 4152 | PackExpansionExpr(EmptyShell Empty) : Expr(PackExpansionExprClass, Empty) {} | |||
| 4153 | ||||
| 4154 | /// Retrieve the pattern of the pack expansion. | |||
| 4155 | Expr *getPattern() { return reinterpret_cast<Expr *>(Pattern); } | |||
| 4156 | ||||
| 4157 | /// Retrieve the pattern of the pack expansion. | |||
| 4158 | const Expr *getPattern() const { return reinterpret_cast<Expr *>(Pattern); } | |||
| 4159 | ||||
| 4160 | /// Retrieve the location of the ellipsis that describes this pack | |||
| 4161 | /// expansion. | |||
| 4162 | SourceLocation getEllipsisLoc() const { return EllipsisLoc; } | |||
| 4163 | ||||
| 4164 | /// Determine the number of expansions that will be produced when | |||
| 4165 | /// this pack expansion is instantiated, if already known. | |||
| 4166 | std::optional<unsigned> getNumExpansions() const { | |||
| 4167 | if (NumExpansions) | |||
| 4168 | return NumExpansions - 1; | |||
| 4169 | ||||
| 4170 | return std::nullopt; | |||
| 4171 | } | |||
| 4172 | ||||
| 4173 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 4174 | return Pattern->getBeginLoc(); | |||
| 4175 | } | |||
| 4176 | ||||
| 4177 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return EllipsisLoc; } | |||
| 4178 | ||||
| 4179 | static bool classof(const Stmt *T) { | |||
| 4180 | return T->getStmtClass() == PackExpansionExprClass; | |||
| 4181 | } | |||
| 4182 | ||||
| 4183 | // Iterators | |||
| 4184 | child_range children() { | |||
| 4185 | return child_range(&Pattern, &Pattern + 1); | |||
| 4186 | } | |||
| 4187 | ||||
| 4188 | const_child_range children() const { | |||
| 4189 | return const_child_range(&Pattern, &Pattern + 1); | |||
| 4190 | } | |||
| 4191 | }; | |||
| 4192 | ||||
| 4193 | /// Represents an expression that computes the length of a parameter | |||
| 4194 | /// pack. | |||
| 4195 | /// | |||
| 4196 | /// \code | |||
| 4197 | /// template<typename ...Types> | |||
| 4198 | /// struct count { | |||
| 4199 | /// static const unsigned value = sizeof...(Types); | |||
| 4200 | /// }; | |||
| 4201 | /// \endcode | |||
| 4202 | class SizeOfPackExpr final | |||
| 4203 | : public Expr, | |||
| 4204 | private llvm::TrailingObjects<SizeOfPackExpr, TemplateArgument> { | |||
| 4205 | friend class ASTStmtReader; | |||
| 4206 | friend class ASTStmtWriter; | |||
| 4207 | friend TrailingObjects; | |||
| 4208 | ||||
| 4209 | /// The location of the \c sizeof keyword. | |||
| 4210 | SourceLocation OperatorLoc; | |||
| 4211 | ||||
| 4212 | /// The location of the name of the parameter pack. | |||
| 4213 | SourceLocation PackLoc; | |||
| 4214 | ||||
| 4215 | /// The location of the closing parenthesis. | |||
| 4216 | SourceLocation RParenLoc; | |||
| 4217 | ||||
| 4218 | /// The length of the parameter pack, if known. | |||
| 4219 | /// | |||
| 4220 | /// When this expression is not value-dependent, this is the length of | |||
| 4221 | /// the pack. When the expression was parsed rather than instantiated | |||
| 4222 | /// (and thus is value-dependent), this is zero. | |||
| 4223 | /// | |||
| 4224 | /// After partial substitution into a sizeof...(X) expression (for instance, | |||
| 4225 | /// within an alias template or during function template argument deduction), | |||
| 4226 | /// we store a trailing array of partially-substituted TemplateArguments, | |||
| 4227 | /// and this is the length of that array. | |||
| 4228 | unsigned Length; | |||
| 4229 | ||||
| 4230 | /// The parameter pack. | |||
| 4231 | NamedDecl *Pack = nullptr; | |||
| 4232 | ||||
| 4233 | /// Create an expression that computes the length of | |||
| 4234 | /// the given parameter pack. | |||
| 4235 | SizeOfPackExpr(QualType SizeType, SourceLocation OperatorLoc, NamedDecl *Pack, | |||
| 4236 | SourceLocation PackLoc, SourceLocation RParenLoc, | |||
| 4237 | std::optional<unsigned> Length, | |||
| 4238 | ArrayRef<TemplateArgument> PartialArgs) | |||
| 4239 | : Expr(SizeOfPackExprClass, SizeType, VK_PRValue, OK_Ordinary), | |||
| 4240 | OperatorLoc(OperatorLoc), PackLoc(PackLoc), RParenLoc(RParenLoc), | |||
| 4241 | Length(Length ? *Length : PartialArgs.size()), Pack(Pack) { | |||
| 4242 | assert((!Length || PartialArgs.empty()) &&(static_cast <bool> ((!Length || PartialArgs.empty()) && "have partial args for non-dependent sizeof... expression") ? void (0) : __assert_fail ("(!Length || PartialArgs.empty()) && \"have partial args for non-dependent sizeof... expression\"" , "clang/include/clang/AST/ExprCXX.h", 4243, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4243 | "have partial args for non-dependent sizeof... expression")(static_cast <bool> ((!Length || PartialArgs.empty()) && "have partial args for non-dependent sizeof... expression") ? void (0) : __assert_fail ("(!Length || PartialArgs.empty()) && \"have partial args for non-dependent sizeof... expression\"" , "clang/include/clang/AST/ExprCXX.h", 4243, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4244 | auto *Args = getTrailingObjects<TemplateArgument>(); | |||
| 4245 | std::uninitialized_copy(PartialArgs.begin(), PartialArgs.end(), Args); | |||
| 4246 | setDependence(Length ? ExprDependence::None | |||
| 4247 | : ExprDependence::ValueInstantiation); | |||
| 4248 | } | |||
| 4249 | ||||
| 4250 | /// Create an empty expression. | |||
| 4251 | SizeOfPackExpr(EmptyShell Empty, unsigned NumPartialArgs) | |||
| 4252 | : Expr(SizeOfPackExprClass, Empty), Length(NumPartialArgs) {} | |||
| 4253 | ||||
| 4254 | public: | |||
| 4255 | static SizeOfPackExpr * | |||
| 4256 | Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, | |||
| 4257 | SourceLocation PackLoc, SourceLocation RParenLoc, | |||
| 4258 | std::optional<unsigned> Length = std::nullopt, | |||
| 4259 | ArrayRef<TemplateArgument> PartialArgs = std::nullopt); | |||
| 4260 | static SizeOfPackExpr *CreateDeserialized(ASTContext &Context, | |||
| 4261 | unsigned NumPartialArgs); | |||
| 4262 | ||||
| 4263 | /// Determine the location of the 'sizeof' keyword. | |||
| 4264 | SourceLocation getOperatorLoc() const { return OperatorLoc; } | |||
| 4265 | ||||
| 4266 | /// Determine the location of the parameter pack. | |||
| 4267 | SourceLocation getPackLoc() const { return PackLoc; } | |||
| 4268 | ||||
| 4269 | /// Determine the location of the right parenthesis. | |||
| 4270 | SourceLocation getRParenLoc() const { return RParenLoc; } | |||
| 4271 | ||||
| 4272 | /// Retrieve the parameter pack. | |||
| 4273 | NamedDecl *getPack() const { return Pack; } | |||
| 4274 | ||||
| 4275 | /// Retrieve the length of the parameter pack. | |||
| 4276 | /// | |||
| 4277 | /// This routine may only be invoked when the expression is not | |||
| 4278 | /// value-dependent. | |||
| 4279 | unsigned getPackLength() const { | |||
| 4280 | assert(!isValueDependent() &&(static_cast <bool> (!isValueDependent() && "Cannot get the length of a value-dependent pack size expression" ) ? void (0) : __assert_fail ("!isValueDependent() && \"Cannot get the length of a value-dependent pack size expression\"" , "clang/include/clang/AST/ExprCXX.h", 4281, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4281 | "Cannot get the length of a value-dependent pack size expression")(static_cast <bool> (!isValueDependent() && "Cannot get the length of a value-dependent pack size expression" ) ? void (0) : __assert_fail ("!isValueDependent() && \"Cannot get the length of a value-dependent pack size expression\"" , "clang/include/clang/AST/ExprCXX.h", 4281, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4282 | return Length; | |||
| 4283 | } | |||
| 4284 | ||||
| 4285 | /// Determine whether this represents a partially-substituted sizeof... | |||
| 4286 | /// expression, such as is produced for: | |||
| 4287 | /// | |||
| 4288 | /// template<typename ...Ts> using X = int[sizeof...(Ts)]; | |||
| 4289 | /// template<typename ...Us> void f(X<Us..., 1, 2, 3, Us...>); | |||
| 4290 | bool isPartiallySubstituted() const { | |||
| 4291 | return isValueDependent() && Length; | |||
| 4292 | } | |||
| 4293 | ||||
| 4294 | /// Get | |||
| 4295 | ArrayRef<TemplateArgument> getPartialArguments() const { | |||
| 4296 | assert(isPartiallySubstituted())(static_cast <bool> (isPartiallySubstituted()) ? void ( 0) : __assert_fail ("isPartiallySubstituted()", "clang/include/clang/AST/ExprCXX.h" , 4296, __extension__ __PRETTY_FUNCTION__)); | |||
| 4297 | const auto *Args = getTrailingObjects<TemplateArgument>(); | |||
| 4298 | return llvm::ArrayRef(Args, Args + Length); | |||
| 4299 | } | |||
| 4300 | ||||
| 4301 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return OperatorLoc; } | |||
| 4302 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return RParenLoc; } | |||
| 4303 | ||||
| 4304 | static bool classof(const Stmt *T) { | |||
| 4305 | return T->getStmtClass() == SizeOfPackExprClass; | |||
| 4306 | } | |||
| 4307 | ||||
| 4308 | // Iterators | |||
| 4309 | child_range children() { | |||
| 4310 | return child_range(child_iterator(), child_iterator()); | |||
| 4311 | } | |||
| 4312 | ||||
| 4313 | const_child_range children() const { | |||
| 4314 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 4315 | } | |||
| 4316 | }; | |||
| 4317 | ||||
| 4318 | /// Represents a reference to a non-type template parameter | |||
| 4319 | /// that has been substituted with a template argument. | |||
| 4320 | class SubstNonTypeTemplateParmExpr : public Expr { | |||
| 4321 | friend class ASTReader; | |||
| 4322 | friend class ASTStmtReader; | |||
| 4323 | ||||
| 4324 | /// The replacement expression. | |||
| 4325 | Stmt *Replacement; | |||
| 4326 | ||||
| 4327 | /// The associated declaration and a flag indicating if it was a reference | |||
| 4328 | /// parameter. For class NTTPs, we can't determine that based on the value | |||
| 4329 | /// category alone. | |||
| 4330 | llvm::PointerIntPair<Decl *, 1, bool> AssociatedDeclAndRef; | |||
| 4331 | ||||
| 4332 | unsigned Index : 15; | |||
| 4333 | unsigned PackIndex : 16; | |||
| 4334 | ||||
| 4335 | explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty) | |||
| 4336 | : Expr(SubstNonTypeTemplateParmExprClass, Empty) {} | |||
| 4337 | ||||
| 4338 | public: | |||
| 4339 | SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind, | |||
| 4340 | SourceLocation Loc, Expr *Replacement, | |||
| 4341 | Decl *AssociatedDecl, unsigned Index, | |||
| 4342 | std::optional<unsigned> PackIndex, bool RefParam) | |||
| 4343 | : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary), | |||
| 4344 | Replacement(Replacement), | |||
| 4345 | AssociatedDeclAndRef(AssociatedDecl, RefParam), Index(Index), | |||
| 4346 | PackIndex(PackIndex ? *PackIndex + 1 : 0) { | |||
| 4347 | assert(AssociatedDecl != nullptr)(static_cast <bool> (AssociatedDecl != nullptr) ? void ( 0) : __assert_fail ("AssociatedDecl != nullptr", "clang/include/clang/AST/ExprCXX.h" , 4347, __extension__ __PRETTY_FUNCTION__)); | |||
| 4348 | SubstNonTypeTemplateParmExprBits.NameLoc = Loc; | |||
| 4349 | setDependence(computeDependence(this)); | |||
| 4350 | } | |||
| 4351 | ||||
| 4352 | SourceLocation getNameLoc() const { | |||
| 4353 | return SubstNonTypeTemplateParmExprBits.NameLoc; | |||
| 4354 | } | |||
| 4355 | SourceLocation getBeginLoc() const { return getNameLoc(); } | |||
| 4356 | SourceLocation getEndLoc() const { return getNameLoc(); } | |||
| 4357 | ||||
| 4358 | Expr *getReplacement() const { return cast<Expr>(Replacement); } | |||
| 4359 | ||||
| 4360 | /// A template-like entity which owns the whole pattern being substituted. | |||
| 4361 | /// This will own a set of template parameters. | |||
| 4362 | Decl *getAssociatedDecl() const { return AssociatedDeclAndRef.getPointer(); } | |||
| 4363 | ||||
| 4364 | /// Returns the index of the replaced parameter in the associated declaration. | |||
| 4365 | /// This should match the result of `getParameter()->getIndex()`. | |||
| 4366 | unsigned getIndex() const { return Index; } | |||
| 4367 | ||||
| 4368 | std::optional<unsigned> getPackIndex() const { | |||
| 4369 | if (PackIndex == 0) | |||
| 4370 | return std::nullopt; | |||
| 4371 | return PackIndex - 1; | |||
| 4372 | } | |||
| 4373 | ||||
| 4374 | NonTypeTemplateParmDecl *getParameter() const; | |||
| 4375 | ||||
| 4376 | bool isReferenceParameter() const { return AssociatedDeclAndRef.getInt(); } | |||
| 4377 | ||||
| 4378 | /// Determine the substituted type of the template parameter. | |||
| 4379 | QualType getParameterType(const ASTContext &Ctx) const; | |||
| 4380 | ||||
| 4381 | static bool classof(const Stmt *s) { | |||
| 4382 | return s->getStmtClass() == SubstNonTypeTemplateParmExprClass; | |||
| 4383 | } | |||
| 4384 | ||||
| 4385 | // Iterators | |||
| 4386 | child_range children() { return child_range(&Replacement, &Replacement + 1); } | |||
| 4387 | ||||
| 4388 | const_child_range children() const { | |||
| 4389 | return const_child_range(&Replacement, &Replacement + 1); | |||
| 4390 | } | |||
| 4391 | }; | |||
| 4392 | ||||
| 4393 | /// Represents a reference to a non-type template parameter pack that | |||
| 4394 | /// has been substituted with a non-template argument pack. | |||
| 4395 | /// | |||
| 4396 | /// When a pack expansion in the source code contains multiple parameter packs | |||
| 4397 | /// and those parameter packs correspond to different levels of template | |||
| 4398 | /// parameter lists, this node is used to represent a non-type template | |||
| 4399 | /// parameter pack from an outer level, which has already had its argument pack | |||
| 4400 | /// substituted but that still lives within a pack expansion that itself | |||
| 4401 | /// could not be instantiated. When actually performing a substitution into | |||
| 4402 | /// that pack expansion (e.g., when all template parameters have corresponding | |||
| 4403 | /// arguments), this type will be replaced with the appropriate underlying | |||
| 4404 | /// expression at the current pack substitution index. | |||
| 4405 | class SubstNonTypeTemplateParmPackExpr : public Expr { | |||
| 4406 | friend class ASTReader; | |||
| 4407 | friend class ASTStmtReader; | |||
| 4408 | ||||
| 4409 | /// The non-type template parameter pack itself. | |||
| 4410 | Decl *AssociatedDecl; | |||
| 4411 | ||||
| 4412 | /// A pointer to the set of template arguments that this | |||
| 4413 | /// parameter pack is instantiated with. | |||
| 4414 | const TemplateArgument *Arguments; | |||
| 4415 | ||||
| 4416 | /// The number of template arguments in \c Arguments. | |||
| 4417 | unsigned NumArguments : 16; | |||
| 4418 | ||||
| 4419 | unsigned Index : 16; | |||
| 4420 | ||||
| 4421 | /// The location of the non-type template parameter pack reference. | |||
| 4422 | SourceLocation NameLoc; | |||
| 4423 | ||||
| 4424 | explicit SubstNonTypeTemplateParmPackExpr(EmptyShell Empty) | |||
| 4425 | : Expr(SubstNonTypeTemplateParmPackExprClass, Empty) {} | |||
| 4426 | ||||
| 4427 | public: | |||
| 4428 | SubstNonTypeTemplateParmPackExpr(QualType T, ExprValueKind ValueKind, | |||
| 4429 | SourceLocation NameLoc, | |||
| 4430 | const TemplateArgument &ArgPack, | |||
| 4431 | Decl *AssociatedDecl, unsigned Index); | |||
| 4432 | ||||
| 4433 | /// A template-like entity which owns the whole pattern being substituted. | |||
| 4434 | /// This will own a set of template parameters. | |||
| 4435 | Decl *getAssociatedDecl() const { return AssociatedDecl; } | |||
| 4436 | ||||
| 4437 | /// Returns the index of the replaced parameter in the associated declaration. | |||
| 4438 | /// This should match the result of `getParameterPack()->getIndex()`. | |||
| 4439 | unsigned getIndex() const { return Index; } | |||
| 4440 | ||||
| 4441 | /// Retrieve the non-type template parameter pack being substituted. | |||
| 4442 | NonTypeTemplateParmDecl *getParameterPack() const; | |||
| 4443 | ||||
| 4444 | /// Retrieve the location of the parameter pack name. | |||
| 4445 | SourceLocation getParameterPackLocation() const { return NameLoc; } | |||
| 4446 | ||||
| 4447 | /// Retrieve the template argument pack containing the substituted | |||
| 4448 | /// template arguments. | |||
| 4449 | TemplateArgument getArgumentPack() const; | |||
| 4450 | ||||
| 4451 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return NameLoc; } | |||
| 4452 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return NameLoc; } | |||
| 4453 | ||||
| 4454 | static bool classof(const Stmt *T) { | |||
| 4455 | return T->getStmtClass() == SubstNonTypeTemplateParmPackExprClass; | |||
| 4456 | } | |||
| 4457 | ||||
| 4458 | // Iterators | |||
| 4459 | child_range children() { | |||
| 4460 | return child_range(child_iterator(), child_iterator()); | |||
| 4461 | } | |||
| 4462 | ||||
| 4463 | const_child_range children() const { | |||
| 4464 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 4465 | } | |||
| 4466 | }; | |||
| 4467 | ||||
| 4468 | /// Represents a reference to a function parameter pack or init-capture pack | |||
| 4469 | /// that has been substituted but not yet expanded. | |||
| 4470 | /// | |||
| 4471 | /// When a pack expansion contains multiple parameter packs at different levels, | |||
| 4472 | /// this node is used to represent a function parameter pack at an outer level | |||
| 4473 | /// which we have already substituted to refer to expanded parameters, but where | |||
| 4474 | /// the containing pack expansion cannot yet be expanded. | |||
| 4475 | /// | |||
| 4476 | /// \code | |||
| 4477 | /// template<typename...Ts> struct S { | |||
| 4478 | /// template<typename...Us> auto f(Ts ...ts) -> decltype(g(Us(ts)...)); | |||
| 4479 | /// }; | |||
| 4480 | /// template struct S<int, int>; | |||
| 4481 | /// \endcode | |||
| 4482 | class FunctionParmPackExpr final | |||
| 4483 | : public Expr, | |||
| 4484 | private llvm::TrailingObjects<FunctionParmPackExpr, VarDecl *> { | |||
| 4485 | friend class ASTReader; | |||
| 4486 | friend class ASTStmtReader; | |||
| 4487 | friend TrailingObjects; | |||
| 4488 | ||||
| 4489 | /// The function parameter pack which was referenced. | |||
| 4490 | VarDecl *ParamPack; | |||
| 4491 | ||||
| 4492 | /// The location of the function parameter pack reference. | |||
| 4493 | SourceLocation NameLoc; | |||
| 4494 | ||||
| 4495 | /// The number of expansions of this pack. | |||
| 4496 | unsigned NumParameters; | |||
| 4497 | ||||
| 4498 | FunctionParmPackExpr(QualType T, VarDecl *ParamPack, | |||
| 4499 | SourceLocation NameLoc, unsigned NumParams, | |||
| 4500 | VarDecl *const *Params); | |||
| 4501 | ||||
| 4502 | public: | |||
| 4503 | static FunctionParmPackExpr *Create(const ASTContext &Context, QualType T, | |||
| 4504 | VarDecl *ParamPack, | |||
| 4505 | SourceLocation NameLoc, | |||
| 4506 | ArrayRef<VarDecl *> Params); | |||
| 4507 | static FunctionParmPackExpr *CreateEmpty(const ASTContext &Context, | |||
| 4508 | unsigned NumParams); | |||
| 4509 | ||||
| 4510 | /// Get the parameter pack which this expression refers to. | |||
| 4511 | VarDecl *getParameterPack() const { return ParamPack; } | |||
| 4512 | ||||
| 4513 | /// Get the location of the parameter pack. | |||
| 4514 | SourceLocation getParameterPackLocation() const { return NameLoc; } | |||
| 4515 | ||||
| 4516 | /// Iterators over the parameters which the parameter pack expanded | |||
| 4517 | /// into. | |||
| 4518 | using iterator = VarDecl * const *; | |||
| 4519 | iterator begin() const { return getTrailingObjects<VarDecl *>(); } | |||
| 4520 | iterator end() const { return begin() + NumParameters; } | |||
| 4521 | ||||
| 4522 | /// Get the number of parameters in this parameter pack. | |||
| 4523 | unsigned getNumExpansions() const { return NumParameters; } | |||
| 4524 | ||||
| 4525 | /// Get an expansion of the parameter pack by index. | |||
| 4526 | VarDecl *getExpansion(unsigned I) const { return begin()[I]; } | |||
| 4527 | ||||
| 4528 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return NameLoc; } | |||
| 4529 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return NameLoc; } | |||
| 4530 | ||||
| 4531 | static bool classof(const Stmt *T) { | |||
| 4532 | return T->getStmtClass() == FunctionParmPackExprClass; | |||
| 4533 | } | |||
| 4534 | ||||
| 4535 | child_range children() { | |||
| 4536 | return child_range(child_iterator(), child_iterator()); | |||
| 4537 | } | |||
| 4538 | ||||
| 4539 | const_child_range children() const { | |||
| 4540 | return const_child_range(const_child_iterator(), const_child_iterator()); | |||
| 4541 | } | |||
| 4542 | }; | |||
| 4543 | ||||
| 4544 | /// Represents a prvalue temporary that is written into memory so that | |||
| 4545 | /// a reference can bind to it. | |||
| 4546 | /// | |||
| 4547 | /// Prvalue expressions are materialized when they need to have an address | |||
| 4548 | /// in memory for a reference to bind to. This happens when binding a | |||
| 4549 | /// reference to the result of a conversion, e.g., | |||
| 4550 | /// | |||
| 4551 | /// \code | |||
| 4552 | /// const int &r = 1.0; | |||
| 4553 | /// \endcode | |||
| 4554 | /// | |||
| 4555 | /// Here, 1.0 is implicitly converted to an \c int. That resulting \c int is | |||
| 4556 | /// then materialized via a \c MaterializeTemporaryExpr, and the reference | |||
| 4557 | /// binds to the temporary. \c MaterializeTemporaryExprs are always glvalues | |||
| 4558 | /// (either an lvalue or an xvalue, depending on the kind of reference binding | |||
| 4559 | /// to it), maintaining the invariant that references always bind to glvalues. | |||
| 4560 | /// | |||
| 4561 | /// Reference binding and copy-elision can both extend the lifetime of a | |||
| 4562 | /// temporary. When either happens, the expression will also track the | |||
| 4563 | /// declaration which is responsible for the lifetime extension. | |||
| 4564 | class MaterializeTemporaryExpr : public Expr { | |||
| 4565 | private: | |||
| 4566 | friend class ASTStmtReader; | |||
| 4567 | friend class ASTStmtWriter; | |||
| 4568 | ||||
| 4569 | llvm::PointerUnion<Stmt *, LifetimeExtendedTemporaryDecl *> State; | |||
| 4570 | ||||
| 4571 | public: | |||
| 4572 | MaterializeTemporaryExpr(QualType T, Expr *Temporary, | |||
| 4573 | bool BoundToLvalueReference, | |||
| 4574 | LifetimeExtendedTemporaryDecl *MTD = nullptr); | |||
| 4575 | ||||
| 4576 | MaterializeTemporaryExpr(EmptyShell Empty) | |||
| 4577 | : Expr(MaterializeTemporaryExprClass, Empty) {} | |||
| 4578 | ||||
| 4579 | /// Retrieve the temporary-generating subexpression whose value will | |||
| 4580 | /// be materialized into a glvalue. | |||
| 4581 | Expr *getSubExpr() const { | |||
| 4582 | return cast<Expr>( | |||
| 4583 | State.is<Stmt *>() | |||
| 4584 | ? State.get<Stmt *>() | |||
| 4585 | : State.get<LifetimeExtendedTemporaryDecl *>()->getTemporaryExpr()); | |||
| 4586 | } | |||
| 4587 | ||||
| 4588 | /// Retrieve the storage duration for the materialized temporary. | |||
| 4589 | StorageDuration getStorageDuration() const { | |||
| 4590 | return State.is<Stmt *>() ? SD_FullExpression | |||
| 4591 | : State.get<LifetimeExtendedTemporaryDecl *>() | |||
| 4592 | ->getStorageDuration(); | |||
| 4593 | } | |||
| 4594 | ||||
| 4595 | /// Get the storage for the constant value of a materialized temporary | |||
| 4596 | /// of static storage duration. | |||
| 4597 | APValue *getOrCreateValue(bool MayCreate) const { | |||
| 4598 | assert(State.is<LifetimeExtendedTemporaryDecl *>() &&(static_cast <bool> (State.is<LifetimeExtendedTemporaryDecl *>() && "the temporary has not been lifetime extended" ) ? void (0) : __assert_fail ("State.is<LifetimeExtendedTemporaryDecl *>() && \"the temporary has not been lifetime extended\"" , "clang/include/clang/AST/ExprCXX.h", 4599, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4599 | "the temporary has not been lifetime extended")(static_cast <bool> (State.is<LifetimeExtendedTemporaryDecl *>() && "the temporary has not been lifetime extended" ) ? void (0) : __assert_fail ("State.is<LifetimeExtendedTemporaryDecl *>() && \"the temporary has not been lifetime extended\"" , "clang/include/clang/AST/ExprCXX.h", 4599, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4600 | return State.get<LifetimeExtendedTemporaryDecl *>()->getOrCreateValue( | |||
| 4601 | MayCreate); | |||
| 4602 | } | |||
| 4603 | ||||
| 4604 | LifetimeExtendedTemporaryDecl *getLifetimeExtendedTemporaryDecl() { | |||
| 4605 | return State.dyn_cast<LifetimeExtendedTemporaryDecl *>(); | |||
| 4606 | } | |||
| 4607 | const LifetimeExtendedTemporaryDecl * | |||
| 4608 | getLifetimeExtendedTemporaryDecl() const { | |||
| 4609 | return State.dyn_cast<LifetimeExtendedTemporaryDecl *>(); | |||
| 4610 | } | |||
| 4611 | ||||
| 4612 | /// Get the declaration which triggered the lifetime-extension of this | |||
| 4613 | /// temporary, if any. | |||
| 4614 | ValueDecl *getExtendingDecl() { | |||
| 4615 | return State.is<Stmt *>() ? nullptr | |||
| 4616 | : State.get<LifetimeExtendedTemporaryDecl *>() | |||
| 4617 | ->getExtendingDecl(); | |||
| 4618 | } | |||
| 4619 | const ValueDecl *getExtendingDecl() const { | |||
| 4620 | return const_cast<MaterializeTemporaryExpr *>(this)->getExtendingDecl(); | |||
| 4621 | } | |||
| 4622 | ||||
| 4623 | void setExtendingDecl(ValueDecl *ExtendedBy, unsigned ManglingNumber); | |||
| 4624 | ||||
| 4625 | unsigned getManglingNumber() const { | |||
| 4626 | return State.is<Stmt *>() ? 0 | |||
| 4627 | : State.get<LifetimeExtendedTemporaryDecl *>() | |||
| 4628 | ->getManglingNumber(); | |||
| 4629 | } | |||
| 4630 | ||||
| 4631 | /// Determine whether this materialized temporary is bound to an | |||
| 4632 | /// lvalue reference; otherwise, it's bound to an rvalue reference. | |||
| 4633 | bool isBoundToLvalueReference() const { return isLValue(); } | |||
| 4634 | ||||
| 4635 | /// Determine whether this temporary object is usable in constant | |||
| 4636 | /// expressions, as specified in C++20 [expr.const]p4. | |||
| 4637 | bool isUsableInConstantExpressions(const ASTContext &Context) const; | |||
| 4638 | ||||
| 4639 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 4640 | return getSubExpr()->getBeginLoc(); | |||
| 4641 | } | |||
| 4642 | ||||
| 4643 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 4644 | return getSubExpr()->getEndLoc(); | |||
| 4645 | } | |||
| 4646 | ||||
| 4647 | static bool classof(const Stmt *T) { | |||
| 4648 | return T->getStmtClass() == MaterializeTemporaryExprClass; | |||
| 4649 | } | |||
| 4650 | ||||
| 4651 | // Iterators | |||
| 4652 | child_range children() { | |||
| 4653 | return State.is<Stmt *>() | |||
| 4654 | ? child_range(State.getAddrOfPtr1(), State.getAddrOfPtr1() + 1) | |||
| 4655 | : State.get<LifetimeExtendedTemporaryDecl *>()->childrenExpr(); | |||
| 4656 | } | |||
| 4657 | ||||
| 4658 | const_child_range children() const { | |||
| 4659 | return State.is<Stmt *>() | |||
| 4660 | ? const_child_range(State.getAddrOfPtr1(), | |||
| 4661 | State.getAddrOfPtr1() + 1) | |||
| 4662 | : const_cast<const LifetimeExtendedTemporaryDecl *>( | |||
| 4663 | State.get<LifetimeExtendedTemporaryDecl *>()) | |||
| 4664 | ->childrenExpr(); | |||
| 4665 | } | |||
| 4666 | }; | |||
| 4667 | ||||
| 4668 | /// Represents a folding of a pack over an operator. | |||
| 4669 | /// | |||
| 4670 | /// This expression is always dependent and represents a pack expansion of the | |||
| 4671 | /// forms: | |||
| 4672 | /// | |||
| 4673 | /// ( expr op ... ) | |||
| 4674 | /// ( ... op expr ) | |||
| 4675 | /// ( expr op ... op expr ) | |||
| 4676 | class CXXFoldExpr : public Expr { | |||
| 4677 | friend class ASTStmtReader; | |||
| 4678 | friend class ASTStmtWriter; | |||
| 4679 | ||||
| 4680 | enum SubExpr { Callee, LHS, RHS, Count }; | |||
| 4681 | ||||
| 4682 | SourceLocation LParenLoc; | |||
| 4683 | SourceLocation EllipsisLoc; | |||
| 4684 | SourceLocation RParenLoc; | |||
| 4685 | // When 0, the number of expansions is not known. Otherwise, this is one more | |||
| 4686 | // than the number of expansions. | |||
| 4687 | unsigned NumExpansions; | |||
| 4688 | Stmt *SubExprs[SubExpr::Count]; | |||
| 4689 | BinaryOperatorKind Opcode; | |||
| 4690 | ||||
| 4691 | public: | |||
| 4692 | CXXFoldExpr(QualType T, UnresolvedLookupExpr *Callee, | |||
| 4693 | SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Opcode, | |||
| 4694 | SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, | |||
| 4695 | std::optional<unsigned> NumExpansions) | |||
| 4696 | : Expr(CXXFoldExprClass, T, VK_PRValue, OK_Ordinary), | |||
| 4697 | LParenLoc(LParenLoc), EllipsisLoc(EllipsisLoc), RParenLoc(RParenLoc), | |||
| 4698 | NumExpansions(NumExpansions ? *NumExpansions + 1 : 0), Opcode(Opcode) { | |||
| 4699 | SubExprs[SubExpr::Callee] = Callee; | |||
| 4700 | SubExprs[SubExpr::LHS] = LHS; | |||
| 4701 | SubExprs[SubExpr::RHS] = RHS; | |||
| 4702 | setDependence(computeDependence(this)); | |||
| 4703 | } | |||
| 4704 | ||||
| 4705 | CXXFoldExpr(EmptyShell Empty) : Expr(CXXFoldExprClass, Empty) {} | |||
| 4706 | ||||
| 4707 | UnresolvedLookupExpr *getCallee() const { | |||
| 4708 | return static_cast<UnresolvedLookupExpr *>(SubExprs[SubExpr::Callee]); | |||
| 4709 | } | |||
| 4710 | Expr *getLHS() const { return static_cast<Expr*>(SubExprs[SubExpr::LHS]); } | |||
| 4711 | Expr *getRHS() const { return static_cast<Expr*>(SubExprs[SubExpr::RHS]); } | |||
| 4712 | ||||
| 4713 | /// Does this produce a right-associated sequence of operators? | |||
| 4714 | bool isRightFold() const { | |||
| 4715 | return getLHS() && getLHS()->containsUnexpandedParameterPack(); | |||
| 4716 | } | |||
| 4717 | ||||
| 4718 | /// Does this produce a left-associated sequence of operators? | |||
| 4719 | bool isLeftFold() const { return !isRightFold(); } | |||
| 4720 | ||||
| 4721 | /// Get the pattern, that is, the operand that contains an unexpanded pack. | |||
| 4722 | Expr *getPattern() const { return isLeftFold() ? getRHS() : getLHS(); } | |||
| 4723 | ||||
| 4724 | /// Get the operand that doesn't contain a pack, for a binary fold. | |||
| 4725 | Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); } | |||
| 4726 | ||||
| 4727 | SourceLocation getLParenLoc() const { return LParenLoc; } | |||
| 4728 | SourceLocation getRParenLoc() const { return RParenLoc; } | |||
| 4729 | SourceLocation getEllipsisLoc() const { return EllipsisLoc; } | |||
| 4730 | BinaryOperatorKind getOperator() const { return Opcode; } | |||
| 4731 | ||||
| 4732 | std::optional<unsigned> getNumExpansions() const { | |||
| 4733 | if (NumExpansions) | |||
| 4734 | return NumExpansions - 1; | |||
| 4735 | return std::nullopt; | |||
| 4736 | } | |||
| 4737 | ||||
| 4738 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 4739 | if (LParenLoc.isValid()) | |||
| 4740 | return LParenLoc; | |||
| 4741 | if (isLeftFold()) | |||
| 4742 | return getEllipsisLoc(); | |||
| 4743 | return getLHS()->getBeginLoc(); | |||
| 4744 | } | |||
| 4745 | ||||
| 4746 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 4747 | if (RParenLoc.isValid()) | |||
| 4748 | return RParenLoc; | |||
| 4749 | if (isRightFold()) | |||
| 4750 | return getEllipsisLoc(); | |||
| 4751 | return getRHS()->getEndLoc(); | |||
| 4752 | } | |||
| 4753 | ||||
| 4754 | static bool classof(const Stmt *T) { | |||
| 4755 | return T->getStmtClass() == CXXFoldExprClass; | |||
| 4756 | } | |||
| 4757 | ||||
| 4758 | // Iterators | |||
| 4759 | child_range children() { | |||
| 4760 | return child_range(SubExprs, SubExprs + SubExpr::Count); | |||
| 4761 | } | |||
| 4762 | ||||
| 4763 | const_child_range children() const { | |||
| 4764 | return const_child_range(SubExprs, SubExprs + SubExpr::Count); | |||
| 4765 | } | |||
| 4766 | }; | |||
| 4767 | ||||
| 4768 | /// Represents a list-initialization with parenthesis. | |||
| 4769 | /// | |||
| 4770 | /// As per P0960R3, this is a C++20 feature that allows aggregate to | |||
| 4771 | /// be initialized with a parenthesized list of values: | |||
| 4772 | /// ``` | |||
| 4773 | /// struct A { | |||
| 4774 | /// int a; | |||
| 4775 | /// double b; | |||
| 4776 | /// }; | |||
| 4777 | /// | |||
| 4778 | /// void foo() { | |||
| 4779 | /// A a1(0); // Well-formed in C++20 | |||
| 4780 | /// A a2(1.5, 1.0); // Well-formed in C++20 | |||
| 4781 | /// } | |||
| 4782 | /// ``` | |||
| 4783 | /// It has some sort of similiarity to braced | |||
| 4784 | /// list-initialization, with some differences such as | |||
| 4785 | /// it allows narrowing conversion whilst braced | |||
| 4786 | /// list-initialization doesn't. | |||
| 4787 | /// ``` | |||
| 4788 | /// struct A { | |||
| 4789 | /// char a; | |||
| 4790 | /// }; | |||
| 4791 | /// void foo() { | |||
| 4792 | /// A a(1.5); // Well-formed in C++20 | |||
| 4793 | /// A b{1.5}; // Ill-formed ! | |||
| 4794 | /// } | |||
| 4795 | /// ``` | |||
| 4796 | class CXXParenListInitExpr final | |||
| 4797 | : public Expr, | |||
| 4798 | private llvm::TrailingObjects<CXXParenListInitExpr, Expr *> { | |||
| 4799 | friend class TrailingObjects; | |||
| 4800 | friend class ASTStmtReader; | |||
| 4801 | friend class ASTStmtWriter; | |||
| 4802 | ||||
| 4803 | unsigned NumExprs; | |||
| 4804 | unsigned NumUserSpecifiedExprs; | |||
| 4805 | SourceLocation InitLoc, LParenLoc, RParenLoc; | |||
| 4806 | llvm::PointerUnion<Expr *, FieldDecl *> ArrayFillerOrUnionFieldInit; | |||
| 4807 | ||||
| 4808 | CXXParenListInitExpr(ArrayRef<Expr *> Args, QualType T, | |||
| 4809 | unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, | |||
| 4810 | SourceLocation LParenLoc, SourceLocation RParenLoc) | |||
| 4811 | : Expr(CXXParenListInitExprClass, T, getValueKindForType(T), OK_Ordinary), | |||
| 4812 | NumExprs(Args.size()), NumUserSpecifiedExprs(NumUserSpecifiedExprs), | |||
| 4813 | InitLoc(InitLoc), LParenLoc(LParenLoc), RParenLoc(RParenLoc) { | |||
| 4814 | std::copy(Args.begin(), Args.end(), getTrailingObjects<Expr *>()); | |||
| 4815 | assert(NumExprs >= NumUserSpecifiedExprs &&(static_cast <bool> (NumExprs >= NumUserSpecifiedExprs && "number of user specified inits is greater than the number of " "passed inits") ? void (0) : __assert_fail ("NumExprs >= NumUserSpecifiedExprs && \"number of user specified inits is greater than the number of \" \"passed inits\"" , "clang/include/clang/AST/ExprCXX.h", 4817, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4816 | "number of user specified inits is greater than the number of "(static_cast <bool> (NumExprs >= NumUserSpecifiedExprs && "number of user specified inits is greater than the number of " "passed inits") ? void (0) : __assert_fail ("NumExprs >= NumUserSpecifiedExprs && \"number of user specified inits is greater than the number of \" \"passed inits\"" , "clang/include/clang/AST/ExprCXX.h", 4817, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4817 | "passed inits")(static_cast <bool> (NumExprs >= NumUserSpecifiedExprs && "number of user specified inits is greater than the number of " "passed inits") ? void (0) : __assert_fail ("NumExprs >= NumUserSpecifiedExprs && \"number of user specified inits is greater than the number of \" \"passed inits\"" , "clang/include/clang/AST/ExprCXX.h", 4817, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4818 | setDependence(computeDependence(this)); | |||
| 4819 | } | |||
| 4820 | ||||
| 4821 | size_t numTrailingObjects(OverloadToken<Expr *>) const { return NumExprs; } | |||
| 4822 | ||||
| 4823 | public: | |||
| 4824 | static CXXParenListInitExpr * | |||
| 4825 | Create(ASTContext &C, ArrayRef<Expr *> Args, QualType T, | |||
| 4826 | unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, | |||
| 4827 | SourceLocation LParenLoc, SourceLocation RParenLoc); | |||
| 4828 | ||||
| 4829 | static CXXParenListInitExpr *CreateEmpty(ASTContext &C, unsigned numExprs, | |||
| 4830 | EmptyShell Empty); | |||
| 4831 | ||||
| 4832 | explicit CXXParenListInitExpr(EmptyShell Empty, unsigned NumExprs) | |||
| 4833 | : Expr(CXXParenListInitExprClass, Empty), NumExprs(NumExprs), | |||
| 4834 | NumUserSpecifiedExprs(0) {} | |||
| 4835 | ||||
| 4836 | void updateDependence() { setDependence(computeDependence(this)); } | |||
| 4837 | ||||
| 4838 | ArrayRef<Expr *> getInitExprs() { | |||
| 4839 | return ArrayRef(getTrailingObjects<Expr *>(), NumExprs); | |||
| 4840 | } | |||
| 4841 | ||||
| 4842 | const ArrayRef<Expr *> getInitExprs() const { | |||
| 4843 | return ArrayRef(getTrailingObjects<Expr *>(), NumExprs); | |||
| 4844 | } | |||
| 4845 | ||||
| 4846 | ArrayRef<Expr *> getUserSpecifiedInitExprs() { | |||
| 4847 | return ArrayRef(getTrailingObjects<Expr *>(), NumUserSpecifiedExprs); | |||
| 4848 | } | |||
| 4849 | ||||
| 4850 | const ArrayRef<Expr *> getUserSpecifiedInitExprs() const { | |||
| 4851 | return ArrayRef(getTrailingObjects<Expr *>(), NumUserSpecifiedExprs); | |||
| 4852 | } | |||
| 4853 | ||||
| 4854 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return LParenLoc; } | |||
| 4855 | ||||
| 4856 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return RParenLoc; } | |||
| 4857 | ||||
| 4858 | SourceLocation getInitLoc() const LLVM_READONLY__attribute__((__pure__)) { return InitLoc; } | |||
| 4859 | ||||
| 4860 | SourceRange getSourceRange() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 4861 | return SourceRange(getBeginLoc(), getEndLoc()); | |||
| 4862 | } | |||
| 4863 | ||||
| 4864 | void setArrayFiller(Expr *E) { ArrayFillerOrUnionFieldInit = E; } | |||
| 4865 | ||||
| 4866 | Expr *getArrayFiller() { | |||
| 4867 | return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); | |||
| 4868 | } | |||
| 4869 | ||||
| 4870 | const Expr *getArrayFiller() const { | |||
| 4871 | return ArrayFillerOrUnionFieldInit.dyn_cast<Expr *>(); | |||
| 4872 | } | |||
| 4873 | ||||
| 4874 | void setInitializedFieldInUnion(FieldDecl *FD) { | |||
| 4875 | ArrayFillerOrUnionFieldInit = FD; | |||
| 4876 | } | |||
| 4877 | ||||
| 4878 | FieldDecl *getInitializedFieldInUnion() { | |||
| 4879 | return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); | |||
| 4880 | } | |||
| 4881 | ||||
| 4882 | const FieldDecl *getInitializedFieldInUnion() const { | |||
| 4883 | return ArrayFillerOrUnionFieldInit.dyn_cast<FieldDecl *>(); | |||
| 4884 | } | |||
| 4885 | ||||
| 4886 | child_range children() { | |||
| 4887 | Stmt **Begin = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>()); | |||
| 4888 | return child_range(Begin, Begin + NumExprs); | |||
| 4889 | } | |||
| 4890 | ||||
| 4891 | const_child_range children() const { | |||
| 4892 | Stmt *const *Begin = | |||
| 4893 | reinterpret_cast<Stmt *const *>(getTrailingObjects<Expr *>()); | |||
| 4894 | return const_child_range(Begin, Begin + NumExprs); | |||
| 4895 | } | |||
| 4896 | ||||
| 4897 | static bool classof(const Stmt *T) { | |||
| 4898 | return T->getStmtClass() == CXXParenListInitExprClass; | |||
| 4899 | } | |||
| 4900 | }; | |||
| 4901 | ||||
| 4902 | /// Represents an expression that might suspend coroutine execution; | |||
| 4903 | /// either a co_await or co_yield expression. | |||
| 4904 | /// | |||
| 4905 | /// Evaluation of this expression first evaluates its 'ready' expression. If | |||
| 4906 | /// that returns 'false': | |||
| 4907 | /// -- execution of the coroutine is suspended | |||
| 4908 | /// -- the 'suspend' expression is evaluated | |||
| 4909 | /// -- if the 'suspend' expression returns 'false', the coroutine is | |||
| 4910 | /// resumed | |||
| 4911 | /// -- otherwise, control passes back to the resumer. | |||
| 4912 | /// If the coroutine is not suspended, or when it is resumed, the 'resume' | |||
| 4913 | /// expression is evaluated, and its result is the result of the overall | |||
| 4914 | /// expression. | |||
| 4915 | class CoroutineSuspendExpr : public Expr { | |||
| 4916 | friend class ASTStmtReader; | |||
| 4917 | ||||
| 4918 | SourceLocation KeywordLoc; | |||
| 4919 | ||||
| 4920 | enum SubExpr { Operand, Common, Ready, Suspend, Resume, Count }; | |||
| 4921 | ||||
| 4922 | Stmt *SubExprs[SubExpr::Count]; | |||
| 4923 | OpaqueValueExpr *OpaqueValue = nullptr; | |||
| 4924 | ||||
| 4925 | public: | |||
| 4926 | CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, Expr *Operand, | |||
| 4927 | Expr *Common, Expr *Ready, Expr *Suspend, Expr *Resume, | |||
| 4928 | OpaqueValueExpr *OpaqueValue) | |||
| 4929 | : Expr(SC, Resume->getType(), Resume->getValueKind(), | |||
| ||||
| 4930 | Resume->getObjectKind()), | |||
| 4931 | KeywordLoc(KeywordLoc), OpaqueValue(OpaqueValue) { | |||
| 4932 | SubExprs[SubExpr::Operand] = Operand; | |||
| 4933 | SubExprs[SubExpr::Common] = Common; | |||
| 4934 | SubExprs[SubExpr::Ready] = Ready; | |||
| 4935 | SubExprs[SubExpr::Suspend] = Suspend; | |||
| 4936 | SubExprs[SubExpr::Resume] = Resume; | |||
| 4937 | setDependence(computeDependence(this)); | |||
| 4938 | } | |||
| 4939 | ||||
| 4940 | CoroutineSuspendExpr(StmtClass SC, SourceLocation KeywordLoc, QualType Ty, | |||
| 4941 | Expr *Operand, Expr *Common) | |||
| 4942 | : Expr(SC, Ty, VK_PRValue, OK_Ordinary), KeywordLoc(KeywordLoc) { | |||
| 4943 | assert(Common->isTypeDependent() && Ty->isDependentType() &&(static_cast <bool> (Common->isTypeDependent() && Ty->isDependentType() && "wrong constructor for non-dependent co_await/co_yield expression" ) ? void (0) : __assert_fail ("Common->isTypeDependent() && Ty->isDependentType() && \"wrong constructor for non-dependent co_await/co_yield expression\"" , "clang/include/clang/AST/ExprCXX.h", 4944, __extension__ __PRETTY_FUNCTION__ )) | |||
| 4944 | "wrong constructor for non-dependent co_await/co_yield expression")(static_cast <bool> (Common->isTypeDependent() && Ty->isDependentType() && "wrong constructor for non-dependent co_await/co_yield expression" ) ? void (0) : __assert_fail ("Common->isTypeDependent() && Ty->isDependentType() && \"wrong constructor for non-dependent co_await/co_yield expression\"" , "clang/include/clang/AST/ExprCXX.h", 4944, __extension__ __PRETTY_FUNCTION__ )); | |||
| 4945 | SubExprs[SubExpr::Operand] = Operand; | |||
| 4946 | SubExprs[SubExpr::Common] = Common; | |||
| 4947 | SubExprs[SubExpr::Ready] = nullptr; | |||
| 4948 | SubExprs[SubExpr::Suspend] = nullptr; | |||
| 4949 | SubExprs[SubExpr::Resume] = nullptr; | |||
| 4950 | setDependence(computeDependence(this)); | |||
| 4951 | } | |||
| 4952 | ||||
| 4953 | CoroutineSuspendExpr(StmtClass SC, EmptyShell Empty) : Expr(SC, Empty) { | |||
| 4954 | SubExprs[SubExpr::Operand] = nullptr; | |||
| 4955 | SubExprs[SubExpr::Common] = nullptr; | |||
| 4956 | SubExprs[SubExpr::Ready] = nullptr; | |||
| 4957 | SubExprs[SubExpr::Suspend] = nullptr; | |||
| 4958 | SubExprs[SubExpr::Resume] = nullptr; | |||
| 4959 | } | |||
| 4960 | ||||
| 4961 | Expr *getCommonExpr() const { | |||
| 4962 | return static_cast<Expr*>(SubExprs[SubExpr::Common]); | |||
| 4963 | } | |||
| 4964 | ||||
| 4965 | /// getOpaqueValue - Return the opaque value placeholder. | |||
| 4966 | OpaqueValueExpr *getOpaqueValue() const { return OpaqueValue; } | |||
| 4967 | ||||
| 4968 | Expr *getReadyExpr() const { | |||
| 4969 | return static_cast<Expr*>(SubExprs[SubExpr::Ready]); | |||
| 4970 | } | |||
| 4971 | ||||
| 4972 | Expr *getSuspendExpr() const { | |||
| 4973 | return static_cast<Expr*>(SubExprs[SubExpr::Suspend]); | |||
| 4974 | } | |||
| 4975 | ||||
| 4976 | Expr *getResumeExpr() const { | |||
| 4977 | return static_cast<Expr*>(SubExprs[SubExpr::Resume]); | |||
| 4978 | } | |||
| 4979 | ||||
| 4980 | // The syntactic operand written in the code | |||
| 4981 | Expr *getOperand() const { | |||
| 4982 | return static_cast<Expr *>(SubExprs[SubExpr::Operand]); | |||
| 4983 | } | |||
| 4984 | ||||
| 4985 | SourceLocation getKeywordLoc() const { return KeywordLoc; } | |||
| 4986 | ||||
| 4987 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return KeywordLoc; } | |||
| 4988 | ||||
| 4989 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 4990 | return getOperand()->getEndLoc(); | |||
| 4991 | } | |||
| 4992 | ||||
| 4993 | child_range children() { | |||
| 4994 | return child_range(SubExprs, SubExprs + SubExpr::Count); | |||
| 4995 | } | |||
| 4996 | ||||
| 4997 | const_child_range children() const { | |||
| 4998 | return const_child_range(SubExprs, SubExprs + SubExpr::Count); | |||
| 4999 | } | |||
| 5000 | ||||
| 5001 | static bool classof(const Stmt *T) { | |||
| 5002 | return T->getStmtClass() == CoawaitExprClass || | |||
| 5003 | T->getStmtClass() == CoyieldExprClass; | |||
| 5004 | } | |||
| 5005 | }; | |||
| 5006 | ||||
| 5007 | /// Represents a 'co_await' expression. | |||
| 5008 | class CoawaitExpr : public CoroutineSuspendExpr { | |||
| 5009 | friend class ASTStmtReader; | |||
| 5010 | ||||
| 5011 | public: | |||
| 5012 | CoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, Expr *Common, | |||
| 5013 | Expr *Ready, Expr *Suspend, Expr *Resume, | |||
| 5014 | OpaqueValueExpr *OpaqueValue, bool IsImplicit = false) | |||
| 5015 | : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Operand, Common, | |||
| 5016 | Ready, Suspend, Resume, OpaqueValue) { | |||
| 5017 | CoawaitBits.IsImplicit = IsImplicit; | |||
| 5018 | } | |||
| 5019 | ||||
| 5020 | CoawaitExpr(SourceLocation CoawaitLoc, QualType Ty, Expr *Operand, | |||
| 5021 | Expr *Common, bool IsImplicit = false) | |||
| 5022 | : CoroutineSuspendExpr(CoawaitExprClass, CoawaitLoc, Ty, Operand, | |||
| 5023 | Common) { | |||
| 5024 | CoawaitBits.IsImplicit = IsImplicit; | |||
| 5025 | } | |||
| 5026 | ||||
| 5027 | CoawaitExpr(EmptyShell Empty) | |||
| 5028 | : CoroutineSuspendExpr(CoawaitExprClass, Empty) {} | |||
| 5029 | ||||
| 5030 | bool isImplicit() const { return CoawaitBits.IsImplicit; } | |||
| 5031 | void setIsImplicit(bool value = true) { CoawaitBits.IsImplicit = value; } | |||
| 5032 | ||||
| 5033 | static bool classof(const Stmt *T) { | |||
| 5034 | return T->getStmtClass() == CoawaitExprClass; | |||
| 5035 | } | |||
| 5036 | }; | |||
| 5037 | ||||
| 5038 | /// Represents a 'co_await' expression while the type of the promise | |||
| 5039 | /// is dependent. | |||
| 5040 | class DependentCoawaitExpr : public Expr { | |||
| 5041 | friend class ASTStmtReader; | |||
| 5042 | ||||
| 5043 | SourceLocation KeywordLoc; | |||
| 5044 | Stmt *SubExprs[2]; | |||
| 5045 | ||||
| 5046 | public: | |||
| 5047 | DependentCoawaitExpr(SourceLocation KeywordLoc, QualType Ty, Expr *Op, | |||
| 5048 | UnresolvedLookupExpr *OpCoawait) | |||
| 5049 | : Expr(DependentCoawaitExprClass, Ty, VK_PRValue, OK_Ordinary), | |||
| 5050 | KeywordLoc(KeywordLoc) { | |||
| 5051 | // NOTE: A co_await expression is dependent on the coroutines promise | |||
| 5052 | // type and may be dependent even when the `Op` expression is not. | |||
| 5053 | assert(Ty->isDependentType() &&(static_cast <bool> (Ty->isDependentType() && "wrong constructor for non-dependent co_await/co_yield expression" ) ? void (0) : __assert_fail ("Ty->isDependentType() && \"wrong constructor for non-dependent co_await/co_yield expression\"" , "clang/include/clang/AST/ExprCXX.h", 5054, __extension__ __PRETTY_FUNCTION__ )) | |||
| 5054 | "wrong constructor for non-dependent co_await/co_yield expression")(static_cast <bool> (Ty->isDependentType() && "wrong constructor for non-dependent co_await/co_yield expression" ) ? void (0) : __assert_fail ("Ty->isDependentType() && \"wrong constructor for non-dependent co_await/co_yield expression\"" , "clang/include/clang/AST/ExprCXX.h", 5054, __extension__ __PRETTY_FUNCTION__ )); | |||
| 5055 | SubExprs[0] = Op; | |||
| 5056 | SubExprs[1] = OpCoawait; | |||
| 5057 | setDependence(computeDependence(this)); | |||
| 5058 | } | |||
| 5059 | ||||
| 5060 | DependentCoawaitExpr(EmptyShell Empty) | |||
| 5061 | : Expr(DependentCoawaitExprClass, Empty) {} | |||
| 5062 | ||||
| 5063 | Expr *getOperand() const { return cast<Expr>(SubExprs[0]); } | |||
| 5064 | ||||
| 5065 | UnresolvedLookupExpr *getOperatorCoawaitLookup() const { | |||
| 5066 | return cast<UnresolvedLookupExpr>(SubExprs[1]); | |||
| 5067 | } | |||
| 5068 | ||||
| 5069 | SourceLocation getKeywordLoc() const { return KeywordLoc; } | |||
| 5070 | ||||
| 5071 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return KeywordLoc; } | |||
| 5072 | ||||
| 5073 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { | |||
| 5074 | return getOperand()->getEndLoc(); | |||
| 5075 | } | |||
| 5076 | ||||
| 5077 | child_range children() { return child_range(SubExprs, SubExprs + 2); } | |||
| 5078 | ||||
| 5079 | const_child_range children() const { | |||
| 5080 | return const_child_range(SubExprs, SubExprs + 2); | |||
| 5081 | } | |||
| 5082 | ||||
| 5083 | static bool classof(const Stmt *T) { | |||
| 5084 | return T->getStmtClass() == DependentCoawaitExprClass; | |||
| 5085 | } | |||
| 5086 | }; | |||
| 5087 | ||||
| 5088 | /// Represents a 'co_yield' expression. | |||
| 5089 | class CoyieldExpr : public CoroutineSuspendExpr { | |||
| 5090 | friend class ASTStmtReader; | |||
| 5091 | ||||
| 5092 | public: | |||
| 5093 | CoyieldExpr(SourceLocation CoyieldLoc, Expr *Operand, Expr *Common, | |||
| 5094 | Expr *Ready, Expr *Suspend, Expr *Resume, | |||
| 5095 | OpaqueValueExpr *OpaqueValue) | |||
| 5096 | : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Operand, Common, | |||
| 5097 | Ready, Suspend, Resume, OpaqueValue) {} | |||
| 5098 | CoyieldExpr(SourceLocation CoyieldLoc, QualType Ty, Expr *Operand, | |||
| 5099 | Expr *Common) | |||
| 5100 | : CoroutineSuspendExpr(CoyieldExprClass, CoyieldLoc, Ty, Operand, | |||
| 5101 | Common) {} | |||
| 5102 | CoyieldExpr(EmptyShell Empty) | |||
| 5103 | : CoroutineSuspendExpr(CoyieldExprClass, Empty) {} | |||
| 5104 | ||||
| 5105 | static bool classof(const Stmt *T) { | |||
| 5106 | return T->getStmtClass() == CoyieldExprClass; | |||
| 5107 | } | |||
| 5108 | }; | |||
| 5109 | ||||
| 5110 | /// Represents a C++2a __builtin_bit_cast(T, v) expression. Used to implement | |||
| 5111 | /// std::bit_cast. These can sometimes be evaluated as part of a constant | |||
| 5112 | /// expression, but otherwise CodeGen to a simple memcpy in general. | |||
| 5113 | class BuiltinBitCastExpr final | |||
| 5114 | : public ExplicitCastExpr, | |||
| 5115 | private llvm::TrailingObjects<BuiltinBitCastExpr, CXXBaseSpecifier *> { | |||
| 5116 | friend class ASTStmtReader; | |||
| 5117 | friend class CastExpr; | |||
| 5118 | friend TrailingObjects; | |||
| 5119 | ||||
| 5120 | SourceLocation KWLoc; | |||
| 5121 | SourceLocation RParenLoc; | |||
| 5122 | ||||
| 5123 | public: | |||
| 5124 | BuiltinBitCastExpr(QualType T, ExprValueKind VK, CastKind CK, Expr *SrcExpr, | |||
| 5125 | TypeSourceInfo *DstType, SourceLocation KWLoc, | |||
| 5126 | SourceLocation RParenLoc) | |||
| 5127 | : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0, false, | |||
| 5128 | DstType), | |||
| 5129 | KWLoc(KWLoc), RParenLoc(RParenLoc) {} | |||
| 5130 | BuiltinBitCastExpr(EmptyShell Empty) | |||
| 5131 | : ExplicitCastExpr(BuiltinBitCastExprClass, Empty, 0, false) {} | |||
| 5132 | ||||
| 5133 | SourceLocation getBeginLoc() const LLVM_READONLY__attribute__((__pure__)) { return KWLoc; } | |||
| 5134 | SourceLocation getEndLoc() const LLVM_READONLY__attribute__((__pure__)) { return RParenLoc; } | |||
| 5135 | ||||
| 5136 | static bool classof(const Stmt *T) { | |||
| 5137 | return T->getStmtClass() == BuiltinBitCastExprClass; | |||
| 5138 | } | |||
| 5139 | }; | |||
| 5140 | ||||
| 5141 | } // namespace clang | |||
| 5142 | ||||
| 5143 | #endif // LLVM_CLANG_AST_EXPRCXX_H |