1 //===------- TreeTransform.h - Semantic Tree Transformation -----*- 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 // This file implements a semantic tree transformation that takes a given 9 // AST and rebuilds it, possibly transforming some nodes in the process. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H 14 #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H 15 16 #include "CoroutineStmtBuilder.h" 17 #include "TypeLocBuilder.h" 18 #include "clang/AST/Decl.h" 19 #include "clang/AST/DeclObjC.h" 20 #include "clang/AST/DeclTemplate.h" 21 #include "clang/AST/Expr.h" 22 #include "clang/AST/ExprCXX.h" 23 #include "clang/AST/ExprConcepts.h" 24 #include "clang/AST/ExprObjC.h" 25 #include "clang/AST/ExprOpenMP.h" 26 #include "clang/AST/OpenMPClause.h" 27 #include "clang/AST/Stmt.h" 28 #include "clang/AST/StmtCXX.h" 29 #include "clang/AST/StmtObjC.h" 30 #include "clang/AST/StmtOpenMP.h" 31 #include "clang/Basic/DiagnosticParse.h" 32 #include "clang/Basic/OpenMPKinds.h" 33 #include "clang/Sema/Designator.h" 34 #include "clang/Sema/EnterExpressionEvaluationContext.h" 35 #include "clang/Sema/Lookup.h" 36 #include "clang/Sema/Ownership.h" 37 #include "clang/Sema/ParsedTemplate.h" 38 #include "clang/Sema/ScopeInfo.h" 39 #include "clang/Sema/SemaDiagnostic.h" 40 #include "clang/Sema/SemaInternal.h" 41 #include "llvm/ADT/ArrayRef.h" 42 #include "llvm/Support/ErrorHandling.h" 43 #include <algorithm> 44 #include <optional> 45 46 using namespace llvm::omp; 47 48 namespace clang { 49 using namespace sema; 50 51 /// A semantic tree transformation that allows one to transform one 52 /// abstract syntax tree into another. 53 /// 54 /// A new tree transformation is defined by creating a new subclass \c X of 55 /// \c TreeTransform<X> and then overriding certain operations to provide 56 /// behavior specific to that transformation. For example, template 57 /// instantiation is implemented as a tree transformation where the 58 /// transformation of TemplateTypeParmType nodes involves substituting the 59 /// template arguments for their corresponding template parameters; a similar 60 /// transformation is performed for non-type template parameters and 61 /// template template parameters. 62 /// 63 /// This tree-transformation template uses static polymorphism to allow 64 /// subclasses to customize any of its operations. Thus, a subclass can 65 /// override any of the transformation or rebuild operators by providing an 66 /// operation with the same signature as the default implementation. The 67 /// overriding function should not be virtual. 68 /// 69 /// Semantic tree transformations are split into two stages, either of which 70 /// can be replaced by a subclass. The "transform" step transforms an AST node 71 /// or the parts of an AST node using the various transformation functions, 72 /// then passes the pieces on to the "rebuild" step, which constructs a new AST 73 /// node of the appropriate kind from the pieces. The default transformation 74 /// routines recursively transform the operands to composite AST nodes (e.g., 75 /// the pointee type of a PointerType node) and, if any of those operand nodes 76 /// were changed by the transformation, invokes the rebuild operation to create 77 /// a new AST node. 78 /// 79 /// Subclasses can customize the transformation at various levels. The 80 /// most coarse-grained transformations involve replacing TransformType(), 81 /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), 82 /// TransformTemplateName(), or TransformTemplateArgument() with entirely 83 /// new implementations. 84 /// 85 /// For more fine-grained transformations, subclasses can replace any of the 86 /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., 87 /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, 88 /// replacing TransformTemplateTypeParmType() allows template instantiation 89 /// to substitute template arguments for their corresponding template 90 /// parameters. Additionally, subclasses can override the \c RebuildXXX 91 /// functions to control how AST nodes are rebuilt when their operands change. 92 /// By default, \c TreeTransform will invoke semantic analysis to rebuild 93 /// AST nodes. However, certain other tree transformations (e.g, cloning) may 94 /// be able to use more efficient rebuild steps. 95 /// 96 /// There are a handful of other functions that can be overridden, allowing one 97 /// to avoid traversing nodes that don't need any transformation 98 /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their 99 /// operands have not changed (\c AlwaysRebuild()), and customize the 100 /// default locations and entity names used for type-checking 101 /// (\c getBaseLocation(), \c getBaseEntity()). 102 template<typename Derived> 103 class TreeTransform { 104 /// Private RAII object that helps us forget and then re-remember 105 /// the template argument corresponding to a partially-substituted parameter 106 /// pack. 107 class ForgetPartiallySubstitutedPackRAII { 108 Derived &Self; 109 TemplateArgument Old; 110 111 public: 112 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { 113 Old = Self.ForgetPartiallySubstitutedPack(); 114 } 115 116 ~ForgetPartiallySubstitutedPackRAII() { 117 Self.RememberPartiallySubstitutedPack(Old); 118 } 119 }; 120 121 protected: 122 Sema &SemaRef; 123 124 /// The set of local declarations that have been transformed, for 125 /// cases where we are forced to build new declarations within the transformer 126 /// rather than in the subclass (e.g., lambda closure types). 127 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; 128 129 public: 130 /// Initializes a new tree transformer. 131 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } 132 133 /// Retrieves a reference to the derived class. 134 Derived &getDerived() { return static_cast<Derived&>(*this); } 135 136 /// Retrieves a reference to the derived class. 137 const Derived &getDerived() const { 138 return static_cast<const Derived&>(*this); 139 } 140 141 static inline ExprResult Owned(Expr *E) { return E; } 142 static inline StmtResult Owned(Stmt *S) { return S; } 143 144 /// Retrieves a reference to the semantic analysis object used for 145 /// this tree transform. 146 Sema &getSema() const { return SemaRef; } 147 148 /// Whether the transformation should always rebuild AST nodes, even 149 /// if none of the children have changed. 150 /// 151 /// Subclasses may override this function to specify when the transformation 152 /// should rebuild all AST nodes. 153 /// 154 /// We must always rebuild all AST nodes when performing variadic template 155 /// pack expansion, in order to avoid violating the AST invariant that each 156 /// statement node appears at most once in its containing declaration. 157 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } 158 159 /// Whether the transformation is forming an expression or statement that 160 /// replaces the original. In this case, we'll reuse mangling numbers from 161 /// existing lambdas. 162 bool ReplacingOriginal() { return false; } 163 164 /// Wether CXXConstructExpr can be skipped when they are implicit. 165 /// They will be reconstructed when used if needed. 166 /// This is useful when the user that cause rebuilding of the 167 /// CXXConstructExpr is outside of the expression at which the TreeTransform 168 /// started. 169 bool AllowSkippingCXXConstructExpr() { return true; } 170 171 /// Returns the location of the entity being transformed, if that 172 /// information was not available elsewhere in the AST. 173 /// 174 /// By default, returns no source-location information. Subclasses can 175 /// provide an alternative implementation that provides better location 176 /// information. 177 SourceLocation getBaseLocation() { return SourceLocation(); } 178 179 /// Returns the name of the entity being transformed, if that 180 /// information was not available elsewhere in the AST. 181 /// 182 /// By default, returns an empty name. Subclasses can provide an alternative 183 /// implementation with a more precise name. 184 DeclarationName getBaseEntity() { return DeclarationName(); } 185 186 /// Sets the "base" location and entity when that 187 /// information is known based on another transformation. 188 /// 189 /// By default, the source location and entity are ignored. Subclasses can 190 /// override this function to provide a customized implementation. 191 void setBase(SourceLocation Loc, DeclarationName Entity) { } 192 193 /// RAII object that temporarily sets the base location and entity 194 /// used for reporting diagnostics in types. 195 class TemporaryBase { 196 TreeTransform &Self; 197 SourceLocation OldLocation; 198 DeclarationName OldEntity; 199 200 public: 201 TemporaryBase(TreeTransform &Self, SourceLocation Location, 202 DeclarationName Entity) : Self(Self) { 203 OldLocation = Self.getDerived().getBaseLocation(); 204 OldEntity = Self.getDerived().getBaseEntity(); 205 206 if (Location.isValid()) 207 Self.getDerived().setBase(Location, Entity); 208 } 209 210 ~TemporaryBase() { 211 Self.getDerived().setBase(OldLocation, OldEntity); 212 } 213 }; 214 215 /// Determine whether the given type \p T has already been 216 /// transformed. 217 /// 218 /// Subclasses can provide an alternative implementation of this routine 219 /// to short-circuit evaluation when it is known that a given type will 220 /// not change. For example, template instantiation need not traverse 221 /// non-dependent types. 222 bool AlreadyTransformed(QualType T) { 223 return T.isNull(); 224 } 225 226 /// Transform a template parameter depth level. 227 /// 228 /// During a transformation that transforms template parameters, this maps 229 /// an old template parameter depth to a new depth. 230 unsigned TransformTemplateDepth(unsigned Depth) { 231 return Depth; 232 } 233 234 /// Determine whether the given call argument should be dropped, e.g., 235 /// because it is a default argument. 236 /// 237 /// Subclasses can provide an alternative implementation of this routine to 238 /// determine which kinds of call arguments get dropped. By default, 239 /// CXXDefaultArgument nodes are dropped (prior to transformation). 240 bool DropCallArgument(Expr *E) { 241 return E->isDefaultArgument(); 242 } 243 244 /// Determine whether we should expand a pack expansion with the 245 /// given set of parameter packs into separate arguments by repeatedly 246 /// transforming the pattern. 247 /// 248 /// By default, the transformer never tries to expand pack expansions. 249 /// Subclasses can override this routine to provide different behavior. 250 /// 251 /// \param EllipsisLoc The location of the ellipsis that identifies the 252 /// pack expansion. 253 /// 254 /// \param PatternRange The source range that covers the entire pattern of 255 /// the pack expansion. 256 /// 257 /// \param Unexpanded The set of unexpanded parameter packs within the 258 /// pattern. 259 /// 260 /// \param ShouldExpand Will be set to \c true if the transformer should 261 /// expand the corresponding pack expansions into separate arguments. When 262 /// set, \c NumExpansions must also be set. 263 /// 264 /// \param RetainExpansion Whether the caller should add an unexpanded 265 /// pack expansion after all of the expanded arguments. This is used 266 /// when extending explicitly-specified template argument packs per 267 /// C++0x [temp.arg.explicit]p9. 268 /// 269 /// \param NumExpansions The number of separate arguments that will be in 270 /// the expanded form of the corresponding pack expansion. This is both an 271 /// input and an output parameter, which can be set by the caller if the 272 /// number of expansions is known a priori (e.g., due to a prior substitution) 273 /// and will be set by the callee when the number of expansions is known. 274 /// The callee must set this value when \c ShouldExpand is \c true; it may 275 /// set this value in other cases. 276 /// 277 /// \returns true if an error occurred (e.g., because the parameter packs 278 /// are to be instantiated with arguments of different lengths), false 279 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 280 /// must be set. 281 bool TryExpandParameterPacks(SourceLocation EllipsisLoc, 282 SourceRange PatternRange, 283 ArrayRef<UnexpandedParameterPack> Unexpanded, 284 bool &ShouldExpand, bool &RetainExpansion, 285 std::optional<unsigned> &NumExpansions) { 286 ShouldExpand = false; 287 return false; 288 } 289 290 /// "Forget" about the partially-substituted pack template argument, 291 /// when performing an instantiation that must preserve the parameter pack 292 /// use. 293 /// 294 /// This routine is meant to be overridden by the template instantiator. 295 TemplateArgument ForgetPartiallySubstitutedPack() { 296 return TemplateArgument(); 297 } 298 299 /// "Remember" the partially-substituted pack template argument 300 /// after performing an instantiation that must preserve the parameter pack 301 /// use. 302 /// 303 /// This routine is meant to be overridden by the template instantiator. 304 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } 305 306 /// Note to the derived class when a function parameter pack is 307 /// being expanded. 308 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } 309 310 /// Transforms the given type into another type. 311 /// 312 /// By default, this routine transforms a type by creating a 313 /// TypeSourceInfo for it and delegating to the appropriate 314 /// function. This is expensive, but we don't mind, because 315 /// this method is deprecated anyway; all users should be 316 /// switched to storing TypeSourceInfos. 317 /// 318 /// \returns the transformed type. 319 QualType TransformType(QualType T); 320 321 /// Transforms the given type-with-location into a new 322 /// type-with-location. 323 /// 324 /// By default, this routine transforms a type by delegating to the 325 /// appropriate TransformXXXType to build a new type. Subclasses 326 /// may override this function (to take over all type 327 /// transformations) or some set of the TransformXXXType functions 328 /// to alter the transformation. 329 TypeSourceInfo *TransformType(TypeSourceInfo *DI); 330 331 /// Transform the given type-with-location into a new 332 /// type, collecting location information in the given builder 333 /// as necessary. 334 /// 335 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); 336 337 /// Transform a type that is permitted to produce a 338 /// DeducedTemplateSpecializationType. 339 /// 340 /// This is used in the (relatively rare) contexts where it is acceptable 341 /// for transformation to produce a class template type with deduced 342 /// template arguments. 343 /// @{ 344 QualType TransformTypeWithDeducedTST(QualType T); 345 TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI); 346 /// @} 347 348 /// The reason why the value of a statement is not discarded, if any. 349 enum StmtDiscardKind { 350 SDK_Discarded, 351 SDK_NotDiscarded, 352 SDK_StmtExprResult, 353 }; 354 355 /// Transform the given statement. 356 /// 357 /// By default, this routine transforms a statement by delegating to the 358 /// appropriate TransformXXXStmt function to transform a specific kind of 359 /// statement or the TransformExpr() function to transform an expression. 360 /// Subclasses may override this function to transform statements using some 361 /// other mechanism. 362 /// 363 /// \returns the transformed statement. 364 StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded); 365 366 /// Transform the given statement. 367 /// 368 /// By default, this routine transforms a statement by delegating to the 369 /// appropriate TransformOMPXXXClause function to transform a specific kind 370 /// of clause. Subclasses may override this function to transform statements 371 /// using some other mechanism. 372 /// 373 /// \returns the transformed OpenMP clause. 374 OMPClause *TransformOMPClause(OMPClause *S); 375 376 /// Transform the given attribute. 377 /// 378 /// By default, this routine transforms a statement by delegating to the 379 /// appropriate TransformXXXAttr function to transform a specific kind 380 /// of attribute. Subclasses may override this function to transform 381 /// attributed statements/types using some other mechanism. 382 /// 383 /// \returns the transformed attribute 384 const Attr *TransformAttr(const Attr *S); 385 386 // Transform the given statement attribute. 387 // 388 // Delegates to the appropriate TransformXXXAttr function to transform a 389 // specific kind of statement attribute. Unlike the non-statement taking 390 // version of this, this implements all attributes, not just pragmas. 391 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS, 392 const Attr *A); 393 394 // Transform the specified attribute. 395 // 396 // Subclasses should override the transformation of attributes with a pragma 397 // spelling to transform expressions stored within the attribute. 398 // 399 // \returns the transformed attribute. 400 #define ATTR(X) \ 401 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } 402 #include "clang/Basic/AttrList.inc" 403 404 // Transform the specified attribute. 405 // 406 // Subclasses should override the transformation of attributes to do 407 // transformation and checking of statement attributes. By default, this 408 // delegates to the non-statement taking version. 409 // 410 // \returns the transformed attribute. 411 #define ATTR(X) \ 412 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \ 413 const X##Attr *A) { \ 414 return getDerived().Transform##X##Attr(A); \ 415 } 416 #include "clang/Basic/AttrList.inc" 417 418 /// Transform the given expression. 419 /// 420 /// By default, this routine transforms an expression by delegating to the 421 /// appropriate TransformXXXExpr function to build a new expression. 422 /// Subclasses may override this function to transform expressions using some 423 /// other mechanism. 424 /// 425 /// \returns the transformed expression. 426 ExprResult TransformExpr(Expr *E); 427 428 /// Transform the given initializer. 429 /// 430 /// By default, this routine transforms an initializer by stripping off the 431 /// semantic nodes added by initialization, then passing the result to 432 /// TransformExpr or TransformExprs. 433 /// 434 /// \returns the transformed initializer. 435 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); 436 437 /// Transform the given list of expressions. 438 /// 439 /// This routine transforms a list of expressions by invoking 440 /// \c TransformExpr() for each subexpression. However, it also provides 441 /// support for variadic templates by expanding any pack expansions (if the 442 /// derived class permits such expansion) along the way. When pack expansions 443 /// are present, the number of outputs may not equal the number of inputs. 444 /// 445 /// \param Inputs The set of expressions to be transformed. 446 /// 447 /// \param NumInputs The number of expressions in \c Inputs. 448 /// 449 /// \param IsCall If \c true, then this transform is being performed on 450 /// function-call arguments, and any arguments that should be dropped, will 451 /// be. 452 /// 453 /// \param Outputs The transformed input expressions will be added to this 454 /// vector. 455 /// 456 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed 457 /// due to transformation. 458 /// 459 /// \returns true if an error occurred, false otherwise. 460 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, 461 SmallVectorImpl<Expr *> &Outputs, 462 bool *ArgChanged = nullptr); 463 464 /// Transform the given declaration, which is referenced from a type 465 /// or expression. 466 /// 467 /// By default, acts as the identity function on declarations, unless the 468 /// transformer has had to transform the declaration itself. Subclasses 469 /// may override this function to provide alternate behavior. 470 Decl *TransformDecl(SourceLocation Loc, Decl *D) { 471 llvm::DenseMap<Decl *, Decl *>::iterator Known 472 = TransformedLocalDecls.find(D); 473 if (Known != TransformedLocalDecls.end()) 474 return Known->second; 475 476 return D; 477 } 478 479 /// Transform the specified condition. 480 /// 481 /// By default, this transforms the variable and expression and rebuilds 482 /// the condition. 483 Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, 484 Expr *Expr, 485 Sema::ConditionKind Kind); 486 487 /// Transform the attributes associated with the given declaration and 488 /// place them on the new declaration. 489 /// 490 /// By default, this operation does nothing. Subclasses may override this 491 /// behavior to transform attributes. 492 void transformAttrs(Decl *Old, Decl *New) { } 493 494 /// Note that a local declaration has been transformed by this 495 /// transformer. 496 /// 497 /// Local declarations are typically transformed via a call to 498 /// TransformDefinition. However, in some cases (e.g., lambda expressions), 499 /// the transformer itself has to transform the declarations. This routine 500 /// can be overridden by a subclass that keeps track of such mappings. 501 void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) { 502 assert(New.size() == 1 && 503 "must override transformedLocalDecl if performing pack expansion"); 504 TransformedLocalDecls[Old] = New.front(); 505 } 506 507 /// Transform the definition of the given declaration. 508 /// 509 /// By default, invokes TransformDecl() to transform the declaration. 510 /// Subclasses may override this function to provide alternate behavior. 511 Decl *TransformDefinition(SourceLocation Loc, Decl *D) { 512 return getDerived().TransformDecl(Loc, D); 513 } 514 515 /// Transform the given declaration, which was the first part of a 516 /// nested-name-specifier in a member access expression. 517 /// 518 /// This specific declaration transformation only applies to the first 519 /// identifier in a nested-name-specifier of a member access expression, e.g., 520 /// the \c T in \c x->T::member 521 /// 522 /// By default, invokes TransformDecl() to transform the declaration. 523 /// Subclasses may override this function to provide alternate behavior. 524 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { 525 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); 526 } 527 528 /// Transform the set of declarations in an OverloadExpr. 529 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, 530 LookupResult &R); 531 532 /// Transform the given nested-name-specifier with source-location 533 /// information. 534 /// 535 /// By default, transforms all of the types and declarations within the 536 /// nested-name-specifier. Subclasses may override this function to provide 537 /// alternate behavior. 538 NestedNameSpecifierLoc 539 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, 540 QualType ObjectType = QualType(), 541 NamedDecl *FirstQualifierInScope = nullptr); 542 543 /// Transform the given declaration name. 544 /// 545 /// By default, transforms the types of conversion function, constructor, 546 /// and destructor names and then (if needed) rebuilds the declaration name. 547 /// Identifiers and selectors are returned unmodified. Subclasses may 548 /// override this function to provide alternate behavior. 549 DeclarationNameInfo 550 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); 551 552 bool TransformRequiresExprRequirements(ArrayRef<concepts::Requirement *> Reqs, 553 llvm::SmallVectorImpl<concepts::Requirement *> &Transformed); 554 concepts::TypeRequirement * 555 TransformTypeRequirement(concepts::TypeRequirement *Req); 556 concepts::ExprRequirement * 557 TransformExprRequirement(concepts::ExprRequirement *Req); 558 concepts::NestedRequirement * 559 TransformNestedRequirement(concepts::NestedRequirement *Req); 560 561 /// Transform the given template name. 562 /// 563 /// \param SS The nested-name-specifier that qualifies the template 564 /// name. This nested-name-specifier must already have been transformed. 565 /// 566 /// \param Name The template name to transform. 567 /// 568 /// \param NameLoc The source location of the template name. 569 /// 570 /// \param ObjectType If we're translating a template name within a member 571 /// access expression, this is the type of the object whose member template 572 /// is being referenced. 573 /// 574 /// \param FirstQualifierInScope If the first part of a nested-name-specifier 575 /// also refers to a name within the current (lexical) scope, this is the 576 /// declaration it refers to. 577 /// 578 /// By default, transforms the template name by transforming the declarations 579 /// and nested-name-specifiers that occur within the template name. 580 /// Subclasses may override this function to provide alternate behavior. 581 TemplateName 582 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, 583 SourceLocation NameLoc, 584 QualType ObjectType = QualType(), 585 NamedDecl *FirstQualifierInScope = nullptr, 586 bool AllowInjectedClassName = false); 587 588 /// Transform the given template argument. 589 /// 590 /// By default, this operation transforms the type, expression, or 591 /// declaration stored within the template argument and constructs a 592 /// new template argument from the transformed result. Subclasses may 593 /// override this function to provide alternate behavior. 594 /// 595 /// Returns true if there was an error. 596 bool TransformTemplateArgument(const TemplateArgumentLoc &Input, 597 TemplateArgumentLoc &Output, 598 bool Uneval = false); 599 600 /// Transform the given set of template arguments. 601 /// 602 /// By default, this operation transforms all of the template arguments 603 /// in the input set using \c TransformTemplateArgument(), and appends 604 /// the transformed arguments to the output list. 605 /// 606 /// Note that this overload of \c TransformTemplateArguments() is merely 607 /// a convenience function. Subclasses that wish to override this behavior 608 /// should override the iterator-based member template version. 609 /// 610 /// \param Inputs The set of template arguments to be transformed. 611 /// 612 /// \param NumInputs The number of template arguments in \p Inputs. 613 /// 614 /// \param Outputs The set of transformed template arguments output by this 615 /// routine. 616 /// 617 /// Returns true if an error occurred. 618 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, 619 unsigned NumInputs, 620 TemplateArgumentListInfo &Outputs, 621 bool Uneval = false) { 622 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs, 623 Uneval); 624 } 625 626 /// Transform the given set of template arguments. 627 /// 628 /// By default, this operation transforms all of the template arguments 629 /// in the input set using \c TransformTemplateArgument(), and appends 630 /// the transformed arguments to the output list. 631 /// 632 /// \param First An iterator to the first template argument. 633 /// 634 /// \param Last An iterator one step past the last template argument. 635 /// 636 /// \param Outputs The set of transformed template arguments output by this 637 /// routine. 638 /// 639 /// Returns true if an error occurred. 640 template<typename InputIterator> 641 bool TransformTemplateArguments(InputIterator First, 642 InputIterator Last, 643 TemplateArgumentListInfo &Outputs, 644 bool Uneval = false); 645 646 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument. 647 void InventTemplateArgumentLoc(const TemplateArgument &Arg, 648 TemplateArgumentLoc &ArgLoc); 649 650 /// Fakes up a TypeSourceInfo for a type. 651 TypeSourceInfo *InventTypeSourceInfo(QualType T) { 652 return SemaRef.Context.getTrivialTypeSourceInfo(T, 653 getDerived().getBaseLocation()); 654 } 655 656 #define ABSTRACT_TYPELOC(CLASS, PARENT) 657 #define TYPELOC(CLASS, PARENT) \ 658 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); 659 #include "clang/AST/TypeLocNodes.def" 660 661 QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, 662 TemplateTypeParmTypeLoc TL, 663 bool SuppressObjCLifetime); 664 QualType 665 TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, 666 SubstTemplateTypeParmPackTypeLoc TL, 667 bool SuppressObjCLifetime); 668 669 template<typename Fn> 670 QualType TransformFunctionProtoType(TypeLocBuilder &TLB, 671 FunctionProtoTypeLoc TL, 672 CXXRecordDecl *ThisContext, 673 Qualifiers ThisTypeQuals, 674 Fn TransformExceptionSpec); 675 676 bool TransformExceptionSpec(SourceLocation Loc, 677 FunctionProtoType::ExceptionSpecInfo &ESI, 678 SmallVectorImpl<QualType> &Exceptions, 679 bool &Changed); 680 681 StmtResult TransformSEHHandler(Stmt *Handler); 682 683 QualType 684 TransformTemplateSpecializationType(TypeLocBuilder &TLB, 685 TemplateSpecializationTypeLoc TL, 686 TemplateName Template); 687 688 QualType 689 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 690 DependentTemplateSpecializationTypeLoc TL, 691 TemplateName Template, 692 CXXScopeSpec &SS); 693 694 QualType TransformDependentTemplateSpecializationType( 695 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, 696 NestedNameSpecifierLoc QualifierLoc); 697 698 /// Transforms the parameters of a function type into the 699 /// given vectors. 700 /// 701 /// The result vectors should be kept in sync; null entries in the 702 /// variables vector are acceptable. 703 /// 704 /// LastParamTransformed, if non-null, will be set to the index of the last 705 /// parameter on which transfromation was started. In the event of an error, 706 /// this will contain the parameter which failed to instantiate. 707 /// 708 /// Return true on error. 709 bool TransformFunctionTypeParams( 710 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, 711 const QualType *ParamTypes, 712 const FunctionProtoType::ExtParameterInfo *ParamInfos, 713 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, 714 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed); 715 716 bool TransformFunctionTypeParams( 717 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, 718 const QualType *ParamTypes, 719 const FunctionProtoType::ExtParameterInfo *ParamInfos, 720 SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, 721 Sema::ExtParameterInfoBuilder &PInfos) { 722 return getDerived().TransformFunctionTypeParams( 723 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr); 724 } 725 726 /// Transforms the parameters of a requires expresison into the given vectors. 727 /// 728 /// The result vectors should be kept in sync; null entries in the 729 /// variables vector are acceptable. 730 /// 731 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not 732 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of 733 /// which are cases where transformation shouldn't continue. 734 ExprResult TransformRequiresTypeParams( 735 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE, 736 RequiresExprBodyDecl *Body, ArrayRef<ParmVarDecl *> Params, 737 SmallVectorImpl<QualType> &PTypes, 738 SmallVectorImpl<ParmVarDecl *> &TransParams, 739 Sema::ExtParameterInfoBuilder &PInfos) { 740 if (getDerived().TransformFunctionTypeParams( 741 KWLoc, Params, /*ParamTypes=*/nullptr, 742 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos)) 743 return ExprError(); 744 745 return ExprResult{}; 746 } 747 748 /// Transforms a single function-type parameter. Return null 749 /// on error. 750 /// 751 /// \param indexAdjustment - A number to add to the parameter's 752 /// scope index; can be negative 753 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, 754 int indexAdjustment, 755 std::optional<unsigned> NumExpansions, 756 bool ExpectParameterPack); 757 758 /// Transform the body of a lambda-expression. 759 StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body); 760 /// Alternative implementation of TransformLambdaBody that skips transforming 761 /// the body. 762 StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body); 763 764 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); 765 766 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); 767 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); 768 769 TemplateParameterList *TransformTemplateParameterList( 770 TemplateParameterList *TPL) { 771 return TPL; 772 } 773 774 ExprResult TransformAddressOfOperand(Expr *E); 775 776 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, 777 bool IsAddressOfOperand, 778 TypeSourceInfo **RecoveryTSI); 779 780 ExprResult TransformParenDependentScopeDeclRefExpr( 781 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, 782 TypeSourceInfo **RecoveryTSI); 783 784 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); 785 786 // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous 787 // amount of stack usage with clang. 788 #define STMT(Node, Parent) \ 789 LLVM_ATTRIBUTE_NOINLINE \ 790 StmtResult Transform##Node(Node *S); 791 #define VALUESTMT(Node, Parent) \ 792 LLVM_ATTRIBUTE_NOINLINE \ 793 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK); 794 #define EXPR(Node, Parent) \ 795 LLVM_ATTRIBUTE_NOINLINE \ 796 ExprResult Transform##Node(Node *E); 797 #define ABSTRACT_STMT(Stmt) 798 #include "clang/AST/StmtNodes.inc" 799 800 #define GEN_CLANG_CLAUSE_CLASS 801 #define CLAUSE_CLASS(Enum, Str, Class) \ 802 LLVM_ATTRIBUTE_NOINLINE \ 803 OMPClause *Transform##Class(Class *S); 804 #include "llvm/Frontend/OpenMP/OMP.inc" 805 806 /// Build a new qualified type given its unqualified type and type location. 807 /// 808 /// By default, this routine adds type qualifiers only to types that can 809 /// have qualifiers, and silently suppresses those qualifiers that are not 810 /// permitted. Subclasses may override this routine to provide different 811 /// behavior. 812 QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL); 813 814 /// Build a new pointer type given its pointee type. 815 /// 816 /// By default, performs semantic analysis when building the pointer type. 817 /// Subclasses may override this routine to provide different behavior. 818 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); 819 820 /// Build a new block pointer type given its pointee type. 821 /// 822 /// By default, performs semantic analysis when building the block pointer 823 /// type. Subclasses may override this routine to provide different behavior. 824 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); 825 826 /// Build a new reference type given the type it references. 827 /// 828 /// By default, performs semantic analysis when building the 829 /// reference type. Subclasses may override this routine to provide 830 /// different behavior. 831 /// 832 /// \param LValue whether the type was written with an lvalue sigil 833 /// or an rvalue sigil. 834 QualType RebuildReferenceType(QualType ReferentType, 835 bool LValue, 836 SourceLocation Sigil); 837 838 /// Build a new member pointer type given the pointee type and the 839 /// class type it refers into. 840 /// 841 /// By default, performs semantic analysis when building the member pointer 842 /// type. Subclasses may override this routine to provide different behavior. 843 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, 844 SourceLocation Sigil); 845 846 QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, 847 SourceLocation ProtocolLAngleLoc, 848 ArrayRef<ObjCProtocolDecl *> Protocols, 849 ArrayRef<SourceLocation> ProtocolLocs, 850 SourceLocation ProtocolRAngleLoc); 851 852 /// Build an Objective-C object type. 853 /// 854 /// By default, performs semantic analysis when building the object type. 855 /// Subclasses may override this routine to provide different behavior. 856 QualType RebuildObjCObjectType(QualType BaseType, 857 SourceLocation Loc, 858 SourceLocation TypeArgsLAngleLoc, 859 ArrayRef<TypeSourceInfo *> TypeArgs, 860 SourceLocation TypeArgsRAngleLoc, 861 SourceLocation ProtocolLAngleLoc, 862 ArrayRef<ObjCProtocolDecl *> Protocols, 863 ArrayRef<SourceLocation> ProtocolLocs, 864 SourceLocation ProtocolRAngleLoc); 865 866 /// Build a new Objective-C object pointer type given the pointee type. 867 /// 868 /// By default, directly builds the pointer type, with no additional semantic 869 /// analysis. 870 QualType RebuildObjCObjectPointerType(QualType PointeeType, 871 SourceLocation Star); 872 873 /// Build a new array type given the element type, size 874 /// modifier, size of the array (if known), size expression, and index type 875 /// qualifiers. 876 /// 877 /// By default, performs semantic analysis when building the array type. 878 /// Subclasses may override this routine to provide different behavior. 879 /// Also by default, all of the other Rebuild*Array 880 QualType RebuildArrayType(QualType ElementType, 881 ArrayType::ArraySizeModifier SizeMod, 882 const llvm::APInt *Size, 883 Expr *SizeExpr, 884 unsigned IndexTypeQuals, 885 SourceRange BracketsRange); 886 887 /// Build a new constant array type given the element type, size 888 /// modifier, (known) size of the array, and index type qualifiers. 889 /// 890 /// By default, performs semantic analysis when building the array type. 891 /// Subclasses may override this routine to provide different behavior. 892 QualType RebuildConstantArrayType(QualType ElementType, 893 ArrayType::ArraySizeModifier SizeMod, 894 const llvm::APInt &Size, 895 Expr *SizeExpr, 896 unsigned IndexTypeQuals, 897 SourceRange BracketsRange); 898 899 /// Build a new incomplete array type given the element type, size 900 /// modifier, and index type qualifiers. 901 /// 902 /// By default, performs semantic analysis when building the array type. 903 /// Subclasses may override this routine to provide different behavior. 904 QualType RebuildIncompleteArrayType(QualType ElementType, 905 ArrayType::ArraySizeModifier SizeMod, 906 unsigned IndexTypeQuals, 907 SourceRange BracketsRange); 908 909 /// Build a new variable-length array type given the element type, 910 /// size modifier, size expression, and index type qualifiers. 911 /// 912 /// By default, performs semantic analysis when building the array type. 913 /// Subclasses may override this routine to provide different behavior. 914 QualType RebuildVariableArrayType(QualType ElementType, 915 ArrayType::ArraySizeModifier SizeMod, 916 Expr *SizeExpr, 917 unsigned IndexTypeQuals, 918 SourceRange BracketsRange); 919 920 /// Build a new dependent-sized array type given the element type, 921 /// size modifier, size expression, and index type qualifiers. 922 /// 923 /// By default, performs semantic analysis when building the array type. 924 /// Subclasses may override this routine to provide different behavior. 925 QualType RebuildDependentSizedArrayType(QualType ElementType, 926 ArrayType::ArraySizeModifier SizeMod, 927 Expr *SizeExpr, 928 unsigned IndexTypeQuals, 929 SourceRange BracketsRange); 930 931 /// Build a new vector type given the element type and 932 /// number of elements. 933 /// 934 /// By default, performs semantic analysis when building the vector type. 935 /// Subclasses may override this routine to provide different behavior. 936 QualType RebuildVectorType(QualType ElementType, unsigned NumElements, 937 VectorType::VectorKind VecKind); 938 939 /// Build a new potentially dependently-sized extended vector type 940 /// given the element type and number of elements. 941 /// 942 /// By default, performs semantic analysis when building the vector type. 943 /// Subclasses may override this routine to provide different behavior. 944 QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, 945 SourceLocation AttributeLoc, 946 VectorType::VectorKind); 947 948 /// Build a new extended vector type given the element type and 949 /// number of elements. 950 /// 951 /// By default, performs semantic analysis when building the vector type. 952 /// Subclasses may override this routine to provide different behavior. 953 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, 954 SourceLocation AttributeLoc); 955 956 /// Build a new potentially dependently-sized extended vector type 957 /// given the element type and number of elements. 958 /// 959 /// By default, performs semantic analysis when building the vector type. 960 /// Subclasses may override this routine to provide different behavior. 961 QualType RebuildDependentSizedExtVectorType(QualType ElementType, 962 Expr *SizeExpr, 963 SourceLocation AttributeLoc); 964 965 /// Build a new matrix type given the element type and dimensions. 966 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, 967 unsigned NumColumns); 968 969 /// Build a new matrix type given the type and dependently-defined 970 /// dimensions. 971 QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, 972 Expr *ColumnExpr, 973 SourceLocation AttributeLoc); 974 975 /// Build a new DependentAddressSpaceType or return the pointee 976 /// type variable with the correct address space (retrieved from 977 /// AddrSpaceExpr) applied to it. The former will be returned in cases 978 /// where the address space remains dependent. 979 /// 980 /// By default, performs semantic analysis when building the type with address 981 /// space applied. Subclasses may override this routine to provide different 982 /// behavior. 983 QualType RebuildDependentAddressSpaceType(QualType PointeeType, 984 Expr *AddrSpaceExpr, 985 SourceLocation AttributeLoc); 986 987 /// Build a new function type. 988 /// 989 /// By default, performs semantic analysis when building the function type. 990 /// Subclasses may override this routine to provide different behavior. 991 QualType RebuildFunctionProtoType(QualType T, 992 MutableArrayRef<QualType> ParamTypes, 993 const FunctionProtoType::ExtProtoInfo &EPI); 994 995 /// Build a new unprototyped function type. 996 QualType RebuildFunctionNoProtoType(QualType ResultType); 997 998 /// Rebuild an unresolved typename type, given the decl that 999 /// the UnresolvedUsingTypenameDecl was transformed to. 1000 QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D); 1001 1002 /// Build a new type found via an alias. 1003 QualType RebuildUsingType(UsingShadowDecl *Found, QualType Underlying) { 1004 return SemaRef.Context.getUsingType(Found, Underlying); 1005 } 1006 1007 /// Build a new typedef type. 1008 QualType RebuildTypedefType(TypedefNameDecl *Typedef) { 1009 return SemaRef.Context.getTypeDeclType(Typedef); 1010 } 1011 1012 /// Build a new MacroDefined type. 1013 QualType RebuildMacroQualifiedType(QualType T, 1014 const IdentifierInfo *MacroII) { 1015 return SemaRef.Context.getMacroQualifiedType(T, MacroII); 1016 } 1017 1018 /// Build a new class/struct/union type. 1019 QualType RebuildRecordType(RecordDecl *Record) { 1020 return SemaRef.Context.getTypeDeclType(Record); 1021 } 1022 1023 /// Build a new Enum type. 1024 QualType RebuildEnumType(EnumDecl *Enum) { 1025 return SemaRef.Context.getTypeDeclType(Enum); 1026 } 1027 1028 /// Build a new typeof(expr) type. 1029 /// 1030 /// By default, performs semantic analysis when building the typeof type. 1031 /// Subclasses may override this routine to provide different behavior. 1032 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc, 1033 TypeOfKind Kind); 1034 1035 /// Build a new typeof(type) type. 1036 /// 1037 /// By default, builds a new TypeOfType with the given underlying type. 1038 QualType RebuildTypeOfType(QualType Underlying, TypeOfKind Kind); 1039 1040 /// Build a new unary transform type. 1041 QualType RebuildUnaryTransformType(QualType BaseType, 1042 UnaryTransformType::UTTKind UKind, 1043 SourceLocation Loc); 1044 1045 /// Build a new C++11 decltype type. 1046 /// 1047 /// By default, performs semantic analysis when building the decltype type. 1048 /// Subclasses may override this routine to provide different behavior. 1049 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); 1050 1051 /// Build a new C++11 auto type. 1052 /// 1053 /// By default, builds a new AutoType with the given deduced type. 1054 QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, 1055 ConceptDecl *TypeConstraintConcept, 1056 ArrayRef<TemplateArgument> TypeConstraintArgs) { 1057 // Note, IsDependent is always false here: we implicitly convert an 'auto' 1058 // which has been deduced to a dependent type into an undeduced 'auto', so 1059 // that we'll retry deduction after the transformation. 1060 return SemaRef.Context.getAutoType(Deduced, Keyword, 1061 /*IsDependent*/ false, /*IsPack=*/false, 1062 TypeConstraintConcept, 1063 TypeConstraintArgs); 1064 } 1065 1066 /// By default, builds a new DeducedTemplateSpecializationType with the given 1067 /// deduced type. 1068 QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, 1069 QualType Deduced) { 1070 return SemaRef.Context.getDeducedTemplateSpecializationType( 1071 Template, Deduced, /*IsDependent*/ false); 1072 } 1073 1074 /// Build a new template specialization type. 1075 /// 1076 /// By default, performs semantic analysis when building the template 1077 /// specialization type. Subclasses may override this routine to provide 1078 /// different behavior. 1079 QualType RebuildTemplateSpecializationType(TemplateName Template, 1080 SourceLocation TemplateLoc, 1081 TemplateArgumentListInfo &Args); 1082 1083 /// Build a new parenthesized type. 1084 /// 1085 /// By default, builds a new ParenType type from the inner type. 1086 /// Subclasses may override this routine to provide different behavior. 1087 QualType RebuildParenType(QualType InnerType) { 1088 return SemaRef.BuildParenType(InnerType); 1089 } 1090 1091 /// Build a new qualified name type. 1092 /// 1093 /// By default, builds a new ElaboratedType type from the keyword, 1094 /// the nested-name-specifier and the named type. 1095 /// Subclasses may override this routine to provide different behavior. 1096 QualType RebuildElaboratedType(SourceLocation KeywordLoc, 1097 ElaboratedTypeKeyword Keyword, 1098 NestedNameSpecifierLoc QualifierLoc, 1099 QualType Named) { 1100 return SemaRef.Context.getElaboratedType(Keyword, 1101 QualifierLoc.getNestedNameSpecifier(), 1102 Named); 1103 } 1104 1105 /// Build a new typename type that refers to a template-id. 1106 /// 1107 /// By default, builds a new DependentNameType type from the 1108 /// nested-name-specifier and the given type. Subclasses may override 1109 /// this routine to provide different behavior. 1110 QualType RebuildDependentTemplateSpecializationType( 1111 ElaboratedTypeKeyword Keyword, 1112 NestedNameSpecifierLoc QualifierLoc, 1113 SourceLocation TemplateKWLoc, 1114 const IdentifierInfo *Name, 1115 SourceLocation NameLoc, 1116 TemplateArgumentListInfo &Args, 1117 bool AllowInjectedClassName) { 1118 // Rebuild the template name. 1119 // TODO: avoid TemplateName abstraction 1120 CXXScopeSpec SS; 1121 SS.Adopt(QualifierLoc); 1122 TemplateName InstName = getDerived().RebuildTemplateName( 1123 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr, 1124 AllowInjectedClassName); 1125 1126 if (InstName.isNull()) 1127 return QualType(); 1128 1129 // If it's still dependent, make a dependent specialization. 1130 if (InstName.getAsDependentTemplateName()) 1131 return SemaRef.Context.getDependentTemplateSpecializationType( 1132 Keyword, QualifierLoc.getNestedNameSpecifier(), Name, 1133 Args.arguments()); 1134 1135 // Otherwise, make an elaborated type wrapping a non-dependent 1136 // specialization. 1137 QualType T = 1138 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); 1139 if (T.isNull()) 1140 return QualType(); 1141 return SemaRef.Context.getElaboratedType( 1142 Keyword, QualifierLoc.getNestedNameSpecifier(), T); 1143 } 1144 1145 /// Build a new typename type that refers to an identifier. 1146 /// 1147 /// By default, performs semantic analysis when building the typename type 1148 /// (or elaborated type). Subclasses may override this routine to provide 1149 /// different behavior. 1150 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, 1151 SourceLocation KeywordLoc, 1152 NestedNameSpecifierLoc QualifierLoc, 1153 const IdentifierInfo *Id, 1154 SourceLocation IdLoc, 1155 bool DeducedTSTContext) { 1156 CXXScopeSpec SS; 1157 SS.Adopt(QualifierLoc); 1158 1159 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { 1160 // If the name is still dependent, just build a new dependent name type. 1161 if (!SemaRef.computeDeclContext(SS)) 1162 return SemaRef.Context.getDependentNameType(Keyword, 1163 QualifierLoc.getNestedNameSpecifier(), 1164 Id); 1165 } 1166 1167 if (Keyword == ETK_None || Keyword == ETK_Typename) { 1168 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, 1169 *Id, IdLoc, DeducedTSTContext); 1170 } 1171 1172 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); 1173 1174 // We had a dependent elaborated-type-specifier that has been transformed 1175 // into a non-dependent elaborated-type-specifier. Find the tag we're 1176 // referring to. 1177 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 1178 DeclContext *DC = SemaRef.computeDeclContext(SS, false); 1179 if (!DC) 1180 return QualType(); 1181 1182 if (SemaRef.RequireCompleteDeclContext(SS, DC)) 1183 return QualType(); 1184 1185 TagDecl *Tag = nullptr; 1186 SemaRef.LookupQualifiedName(Result, DC); 1187 switch (Result.getResultKind()) { 1188 case LookupResult::NotFound: 1189 case LookupResult::NotFoundInCurrentInstantiation: 1190 break; 1191 1192 case LookupResult::Found: 1193 Tag = Result.getAsSingle<TagDecl>(); 1194 break; 1195 1196 case LookupResult::FoundOverloaded: 1197 case LookupResult::FoundUnresolvedValue: 1198 llvm_unreachable("Tag lookup cannot find non-tags"); 1199 1200 case LookupResult::Ambiguous: 1201 // Let the LookupResult structure handle ambiguities. 1202 return QualType(); 1203 } 1204 1205 if (!Tag) { 1206 // Check where the name exists but isn't a tag type and use that to emit 1207 // better diagnostics. 1208 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 1209 SemaRef.LookupQualifiedName(Result, DC); 1210 switch (Result.getResultKind()) { 1211 case LookupResult::Found: 1212 case LookupResult::FoundOverloaded: 1213 case LookupResult::FoundUnresolvedValue: { 1214 NamedDecl *SomeDecl = Result.getRepresentativeDecl(); 1215 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind); 1216 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl 1217 << NTK << Kind; 1218 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); 1219 break; 1220 } 1221 default: 1222 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) 1223 << Kind << Id << DC << QualifierLoc.getSourceRange(); 1224 break; 1225 } 1226 return QualType(); 1227 } 1228 1229 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, 1230 IdLoc, Id)) { 1231 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; 1232 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); 1233 return QualType(); 1234 } 1235 1236 // Build the elaborated-type-specifier type. 1237 QualType T = SemaRef.Context.getTypeDeclType(Tag); 1238 return SemaRef.Context.getElaboratedType(Keyword, 1239 QualifierLoc.getNestedNameSpecifier(), 1240 T); 1241 } 1242 1243 /// Build a new pack expansion type. 1244 /// 1245 /// By default, builds a new PackExpansionType type from the given pattern. 1246 /// Subclasses may override this routine to provide different behavior. 1247 QualType RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, 1248 SourceLocation EllipsisLoc, 1249 std::optional<unsigned> NumExpansions) { 1250 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, 1251 NumExpansions); 1252 } 1253 1254 /// Build a new atomic type given its value type. 1255 /// 1256 /// By default, performs semantic analysis when building the atomic type. 1257 /// Subclasses may override this routine to provide different behavior. 1258 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); 1259 1260 /// Build a new pipe type given its value type. 1261 QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, 1262 bool isReadPipe); 1263 1264 /// Build a bit-precise int given its value type. 1265 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits, 1266 SourceLocation Loc); 1267 1268 /// Build a dependent bit-precise int given its value type. 1269 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr, 1270 SourceLocation Loc); 1271 1272 /// Build a new template name given a nested name specifier, a flag 1273 /// indicating whether the "template" keyword was provided, and the template 1274 /// that the template name refers to. 1275 /// 1276 /// By default, builds the new template name directly. Subclasses may override 1277 /// this routine to provide different behavior. 1278 TemplateName RebuildTemplateName(CXXScopeSpec &SS, 1279 bool TemplateKW, 1280 TemplateDecl *Template); 1281 1282 /// Build a new template name given a nested name specifier and the 1283 /// name that is referred to as a template. 1284 /// 1285 /// By default, performs semantic analysis to determine whether the name can 1286 /// be resolved to a specific template, then builds the appropriate kind of 1287 /// template name. Subclasses may override this routine to provide different 1288 /// behavior. 1289 TemplateName RebuildTemplateName(CXXScopeSpec &SS, 1290 SourceLocation TemplateKWLoc, 1291 const IdentifierInfo &Name, 1292 SourceLocation NameLoc, QualType ObjectType, 1293 NamedDecl *FirstQualifierInScope, 1294 bool AllowInjectedClassName); 1295 1296 /// Build a new template name given a nested name specifier and the 1297 /// overloaded operator name that is referred to as a template. 1298 /// 1299 /// By default, performs semantic analysis to determine whether the name can 1300 /// be resolved to a specific template, then builds the appropriate kind of 1301 /// template name. Subclasses may override this routine to provide different 1302 /// behavior. 1303 TemplateName RebuildTemplateName(CXXScopeSpec &SS, 1304 SourceLocation TemplateKWLoc, 1305 OverloadedOperatorKind Operator, 1306 SourceLocation NameLoc, QualType ObjectType, 1307 bool AllowInjectedClassName); 1308 1309 /// Build a new template name given a template template parameter pack 1310 /// and the 1311 /// 1312 /// By default, performs semantic analysis to determine whether the name can 1313 /// be resolved to a specific template, then builds the appropriate kind of 1314 /// template name. Subclasses may override this routine to provide different 1315 /// behavior. 1316 TemplateName RebuildTemplateName(const TemplateArgument &ArgPack, 1317 Decl *AssociatedDecl, unsigned Index, 1318 bool Final) { 1319 return getSema().Context.getSubstTemplateTemplateParmPack( 1320 ArgPack, AssociatedDecl, Index, Final); 1321 } 1322 1323 /// Build a new compound statement. 1324 /// 1325 /// By default, performs semantic analysis to build the new statement. 1326 /// Subclasses may override this routine to provide different behavior. 1327 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, 1328 MultiStmtArg Statements, 1329 SourceLocation RBraceLoc, 1330 bool IsStmtExpr) { 1331 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, 1332 IsStmtExpr); 1333 } 1334 1335 /// Build a new case statement. 1336 /// 1337 /// By default, performs semantic analysis to build the new statement. 1338 /// Subclasses may override this routine to provide different behavior. 1339 StmtResult RebuildCaseStmt(SourceLocation CaseLoc, 1340 Expr *LHS, 1341 SourceLocation EllipsisLoc, 1342 Expr *RHS, 1343 SourceLocation ColonLoc) { 1344 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, 1345 ColonLoc); 1346 } 1347 1348 /// Attach the body to a new case statement. 1349 /// 1350 /// By default, performs semantic analysis to build the new statement. 1351 /// Subclasses may override this routine to provide different behavior. 1352 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { 1353 getSema().ActOnCaseStmtBody(S, Body); 1354 return S; 1355 } 1356 1357 /// Build a new default statement. 1358 /// 1359 /// By default, performs semantic analysis to build the new statement. 1360 /// Subclasses may override this routine to provide different behavior. 1361 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, 1362 SourceLocation ColonLoc, 1363 Stmt *SubStmt) { 1364 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, 1365 /*CurScope=*/nullptr); 1366 } 1367 1368 /// Build a new label statement. 1369 /// 1370 /// By default, performs semantic analysis to build the new statement. 1371 /// Subclasses may override this routine to provide different behavior. 1372 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, 1373 SourceLocation ColonLoc, Stmt *SubStmt) { 1374 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); 1375 } 1376 1377 /// Build a new attributed statement. 1378 /// 1379 /// By default, performs semantic analysis to build the new statement. 1380 /// Subclasses may override this routine to provide different behavior. 1381 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, 1382 ArrayRef<const Attr *> Attrs, 1383 Stmt *SubStmt) { 1384 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt); 1385 } 1386 1387 /// Build a new "if" statement. 1388 /// 1389 /// By default, performs semantic analysis to build the new statement. 1390 /// Subclasses may override this routine to provide different behavior. 1391 StmtResult RebuildIfStmt(SourceLocation IfLoc, IfStatementKind Kind, 1392 SourceLocation LParenLoc, Sema::ConditionResult Cond, 1393 SourceLocation RParenLoc, Stmt *Init, Stmt *Then, 1394 SourceLocation ElseLoc, Stmt *Else) { 1395 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc, 1396 Then, ElseLoc, Else); 1397 } 1398 1399 /// Start building a new switch statement. 1400 /// 1401 /// By default, performs semantic analysis to build the new statement. 1402 /// Subclasses may override this routine to provide different behavior. 1403 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, 1404 SourceLocation LParenLoc, Stmt *Init, 1405 Sema::ConditionResult Cond, 1406 SourceLocation RParenLoc) { 1407 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond, 1408 RParenLoc); 1409 } 1410 1411 /// Attach the body to the switch statement. 1412 /// 1413 /// By default, performs semantic analysis to build the new statement. 1414 /// Subclasses may override this routine to provide different behavior. 1415 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, 1416 Stmt *Switch, Stmt *Body) { 1417 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); 1418 } 1419 1420 /// Build a new while statement. 1421 /// 1422 /// By default, performs semantic analysis to build the new statement. 1423 /// Subclasses may override this routine to provide different behavior. 1424 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, 1425 Sema::ConditionResult Cond, 1426 SourceLocation RParenLoc, Stmt *Body) { 1427 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body); 1428 } 1429 1430 /// Build a new do-while statement. 1431 /// 1432 /// By default, performs semantic analysis to build the new statement. 1433 /// Subclasses may override this routine to provide different behavior. 1434 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, 1435 SourceLocation WhileLoc, SourceLocation LParenLoc, 1436 Expr *Cond, SourceLocation RParenLoc) { 1437 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, 1438 Cond, RParenLoc); 1439 } 1440 1441 /// Build a new for statement. 1442 /// 1443 /// By default, performs semantic analysis to build the new statement. 1444 /// Subclasses may override this routine to provide different behavior. 1445 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 1446 Stmt *Init, Sema::ConditionResult Cond, 1447 Sema::FullExprArg Inc, SourceLocation RParenLoc, 1448 Stmt *Body) { 1449 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, 1450 Inc, RParenLoc, Body); 1451 } 1452 1453 /// Build a new goto statement. 1454 /// 1455 /// By default, performs semantic analysis to build the new statement. 1456 /// Subclasses may override this routine to provide different behavior. 1457 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, 1458 LabelDecl *Label) { 1459 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); 1460 } 1461 1462 /// Build a new indirect goto statement. 1463 /// 1464 /// By default, performs semantic analysis to build the new statement. 1465 /// Subclasses may override this routine to provide different behavior. 1466 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, 1467 SourceLocation StarLoc, 1468 Expr *Target) { 1469 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); 1470 } 1471 1472 /// Build a new return statement. 1473 /// 1474 /// By default, performs semantic analysis to build the new statement. 1475 /// Subclasses may override this routine to provide different behavior. 1476 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { 1477 return getSema().BuildReturnStmt(ReturnLoc, Result); 1478 } 1479 1480 /// Build a new declaration statement. 1481 /// 1482 /// By default, performs semantic analysis to build the new statement. 1483 /// Subclasses may override this routine to provide different behavior. 1484 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, 1485 SourceLocation StartLoc, SourceLocation EndLoc) { 1486 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); 1487 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); 1488 } 1489 1490 /// Build a new inline asm statement. 1491 /// 1492 /// By default, performs semantic analysis to build the new statement. 1493 /// Subclasses may override this routine to provide different behavior. 1494 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, 1495 bool IsVolatile, unsigned NumOutputs, 1496 unsigned NumInputs, IdentifierInfo **Names, 1497 MultiExprArg Constraints, MultiExprArg Exprs, 1498 Expr *AsmString, MultiExprArg Clobbers, 1499 unsigned NumLabels, 1500 SourceLocation RParenLoc) { 1501 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, 1502 NumInputs, Names, Constraints, Exprs, 1503 AsmString, Clobbers, NumLabels, RParenLoc); 1504 } 1505 1506 /// Build a new MS style inline asm statement. 1507 /// 1508 /// By default, performs semantic analysis to build the new statement. 1509 /// Subclasses may override this routine to provide different behavior. 1510 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, 1511 ArrayRef<Token> AsmToks, 1512 StringRef AsmString, 1513 unsigned NumOutputs, unsigned NumInputs, 1514 ArrayRef<StringRef> Constraints, 1515 ArrayRef<StringRef> Clobbers, 1516 ArrayRef<Expr*> Exprs, 1517 SourceLocation EndLoc) { 1518 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, 1519 NumOutputs, NumInputs, 1520 Constraints, Clobbers, Exprs, EndLoc); 1521 } 1522 1523 /// Build a new co_return statement. 1524 /// 1525 /// By default, performs semantic analysis to build the new statement. 1526 /// Subclasses may override this routine to provide different behavior. 1527 StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, 1528 bool IsImplicit) { 1529 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit); 1530 } 1531 1532 /// Build a new co_await expression. 1533 /// 1534 /// By default, performs semantic analysis to build the new expression. 1535 /// Subclasses may override this routine to provide different behavior. 1536 ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, 1537 UnresolvedLookupExpr *OpCoawaitLookup, 1538 bool IsImplicit) { 1539 // This function rebuilds a coawait-expr given its operator. 1540 // For an explicit coawait-expr, the rebuild involves the full set 1541 // of transformations performed by BuildUnresolvedCoawaitExpr(), 1542 // including calling await_transform(). 1543 // For an implicit coawait-expr, we need to rebuild the "operator 1544 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr(). 1545 // This mirrors how the implicit CoawaitExpr is originally created 1546 // in Sema::ActOnCoroutineBodyStart(). 1547 if (IsImplicit) { 1548 ExprResult Suspend = getSema().BuildOperatorCoawaitCall( 1549 CoawaitLoc, Operand, OpCoawaitLookup); 1550 if (Suspend.isInvalid()) 1551 return ExprError(); 1552 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand, 1553 Suspend.get(), true); 1554 } 1555 1556 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand, 1557 OpCoawaitLookup); 1558 } 1559 1560 /// Build a new co_await expression. 1561 /// 1562 /// By default, performs semantic analysis to build the new expression. 1563 /// Subclasses may override this routine to provide different behavior. 1564 ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, 1565 Expr *Result, 1566 UnresolvedLookupExpr *Lookup) { 1567 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup); 1568 } 1569 1570 /// Build a new co_yield expression. 1571 /// 1572 /// By default, performs semantic analysis to build the new expression. 1573 /// Subclasses may override this routine to provide different behavior. 1574 ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) { 1575 return getSema().BuildCoyieldExpr(CoyieldLoc, Result); 1576 } 1577 1578 StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) { 1579 return getSema().BuildCoroutineBodyStmt(Args); 1580 } 1581 1582 /// Build a new Objective-C \@try statement. 1583 /// 1584 /// By default, performs semantic analysis to build the new statement. 1585 /// Subclasses may override this routine to provide different behavior. 1586 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, 1587 Stmt *TryBody, 1588 MultiStmtArg CatchStmts, 1589 Stmt *Finally) { 1590 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, 1591 Finally); 1592 } 1593 1594 /// Rebuild an Objective-C exception declaration. 1595 /// 1596 /// By default, performs semantic analysis to build the new declaration. 1597 /// Subclasses may override this routine to provide different behavior. 1598 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, 1599 TypeSourceInfo *TInfo, QualType T) { 1600 return getSema().BuildObjCExceptionDecl(TInfo, T, 1601 ExceptionDecl->getInnerLocStart(), 1602 ExceptionDecl->getLocation(), 1603 ExceptionDecl->getIdentifier()); 1604 } 1605 1606 /// Build a new Objective-C \@catch statement. 1607 /// 1608 /// By default, performs semantic analysis to build the new statement. 1609 /// Subclasses may override this routine to provide different behavior. 1610 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, 1611 SourceLocation RParenLoc, 1612 VarDecl *Var, 1613 Stmt *Body) { 1614 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, 1615 Var, Body); 1616 } 1617 1618 /// Build a new Objective-C \@finally statement. 1619 /// 1620 /// By default, performs semantic analysis to build the new statement. 1621 /// Subclasses may override this routine to provide different behavior. 1622 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, 1623 Stmt *Body) { 1624 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); 1625 } 1626 1627 /// Build a new Objective-C \@throw statement. 1628 /// 1629 /// By default, performs semantic analysis to build the new statement. 1630 /// Subclasses may override this routine to provide different behavior. 1631 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, 1632 Expr *Operand) { 1633 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); 1634 } 1635 1636 /// Build a new OpenMP Canonical loop. 1637 /// 1638 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a 1639 /// OMPCanonicalLoop. 1640 StmtResult RebuildOMPCanonicalLoop(Stmt *LoopStmt) { 1641 return getSema().ActOnOpenMPCanonicalLoop(LoopStmt); 1642 } 1643 1644 /// Build a new OpenMP executable directive. 1645 /// 1646 /// By default, performs semantic analysis to build the new statement. 1647 /// Subclasses may override this routine to provide different behavior. 1648 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, 1649 DeclarationNameInfo DirName, 1650 OpenMPDirectiveKind CancelRegion, 1651 ArrayRef<OMPClause *> Clauses, 1652 Stmt *AStmt, SourceLocation StartLoc, 1653 SourceLocation EndLoc) { 1654 return getSema().ActOnOpenMPExecutableDirective( 1655 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); 1656 } 1657 1658 /// Build a new OpenMP 'if' clause. 1659 /// 1660 /// By default, performs semantic analysis to build the new OpenMP clause. 1661 /// Subclasses may override this routine to provide different behavior. 1662 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, 1663 Expr *Condition, SourceLocation StartLoc, 1664 SourceLocation LParenLoc, 1665 SourceLocation NameModifierLoc, 1666 SourceLocation ColonLoc, 1667 SourceLocation EndLoc) { 1668 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc, 1669 LParenLoc, NameModifierLoc, ColonLoc, 1670 EndLoc); 1671 } 1672 1673 /// Build a new OpenMP 'final' clause. 1674 /// 1675 /// By default, performs semantic analysis to build the new OpenMP clause. 1676 /// Subclasses may override this routine to provide different behavior. 1677 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, 1678 SourceLocation LParenLoc, 1679 SourceLocation EndLoc) { 1680 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, 1681 EndLoc); 1682 } 1683 1684 /// Build a new OpenMP 'num_threads' clause. 1685 /// 1686 /// By default, performs semantic analysis to build the new OpenMP clause. 1687 /// Subclasses may override this routine to provide different behavior. 1688 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, 1689 SourceLocation StartLoc, 1690 SourceLocation LParenLoc, 1691 SourceLocation EndLoc) { 1692 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, 1693 LParenLoc, EndLoc); 1694 } 1695 1696 /// Build a new OpenMP 'safelen' clause. 1697 /// 1698 /// By default, performs semantic analysis to build the new OpenMP clause. 1699 /// Subclasses may override this routine to provide different behavior. 1700 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, 1701 SourceLocation LParenLoc, 1702 SourceLocation EndLoc) { 1703 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); 1704 } 1705 1706 /// Build a new OpenMP 'simdlen' clause. 1707 /// 1708 /// By default, performs semantic analysis to build the new OpenMP clause. 1709 /// Subclasses may override this routine to provide different behavior. 1710 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, 1711 SourceLocation LParenLoc, 1712 SourceLocation EndLoc) { 1713 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc); 1714 } 1715 1716 OMPClause *RebuildOMPSizesClause(ArrayRef<Expr *> Sizes, 1717 SourceLocation StartLoc, 1718 SourceLocation LParenLoc, 1719 SourceLocation EndLoc) { 1720 return getSema().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc, EndLoc); 1721 } 1722 1723 /// Build a new OpenMP 'full' clause. 1724 OMPClause *RebuildOMPFullClause(SourceLocation StartLoc, 1725 SourceLocation EndLoc) { 1726 return getSema().ActOnOpenMPFullClause(StartLoc, EndLoc); 1727 } 1728 1729 /// Build a new OpenMP 'partial' clause. 1730 OMPClause *RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc, 1731 SourceLocation LParenLoc, 1732 SourceLocation EndLoc) { 1733 return getSema().ActOnOpenMPPartialClause(Factor, StartLoc, LParenLoc, 1734 EndLoc); 1735 } 1736 1737 /// Build a new OpenMP 'allocator' clause. 1738 /// 1739 /// By default, performs semantic analysis to build the new OpenMP clause. 1740 /// Subclasses may override this routine to provide different behavior. 1741 OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, 1742 SourceLocation LParenLoc, 1743 SourceLocation EndLoc) { 1744 return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc); 1745 } 1746 1747 /// Build a new OpenMP 'collapse' clause. 1748 /// 1749 /// By default, performs semantic analysis to build the new OpenMP clause. 1750 /// Subclasses may override this routine to provide different behavior. 1751 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, 1752 SourceLocation LParenLoc, 1753 SourceLocation EndLoc) { 1754 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, 1755 EndLoc); 1756 } 1757 1758 /// Build a new OpenMP 'default' clause. 1759 /// 1760 /// By default, performs semantic analysis to build the new OpenMP clause. 1761 /// Subclasses may override this routine to provide different behavior. 1762 OMPClause *RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, 1763 SourceLocation StartLoc, 1764 SourceLocation LParenLoc, 1765 SourceLocation EndLoc) { 1766 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, 1767 StartLoc, LParenLoc, EndLoc); 1768 } 1769 1770 /// Build a new OpenMP 'proc_bind' clause. 1771 /// 1772 /// By default, performs semantic analysis to build the new OpenMP clause. 1773 /// Subclasses may override this routine to provide different behavior. 1774 OMPClause *RebuildOMPProcBindClause(ProcBindKind Kind, 1775 SourceLocation KindKwLoc, 1776 SourceLocation StartLoc, 1777 SourceLocation LParenLoc, 1778 SourceLocation EndLoc) { 1779 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, 1780 StartLoc, LParenLoc, EndLoc); 1781 } 1782 1783 /// Build a new OpenMP 'schedule' clause. 1784 /// 1785 /// By default, performs semantic analysis to build the new OpenMP clause. 1786 /// Subclasses may override this routine to provide different behavior. 1787 OMPClause *RebuildOMPScheduleClause( 1788 OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, 1789 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, 1790 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, 1791 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { 1792 return getSema().ActOnOpenMPScheduleClause( 1793 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc, 1794 CommaLoc, EndLoc); 1795 } 1796 1797 /// Build a new OpenMP 'ordered' clause. 1798 /// 1799 /// By default, performs semantic analysis to build the new OpenMP clause. 1800 /// Subclasses may override this routine to provide different behavior. 1801 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, 1802 SourceLocation EndLoc, 1803 SourceLocation LParenLoc, Expr *Num) { 1804 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num); 1805 } 1806 1807 /// Build a new OpenMP 'private' clause. 1808 /// 1809 /// By default, performs semantic analysis to build the new OpenMP clause. 1810 /// Subclasses may override this routine to provide different behavior. 1811 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, 1812 SourceLocation StartLoc, 1813 SourceLocation LParenLoc, 1814 SourceLocation EndLoc) { 1815 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, 1816 EndLoc); 1817 } 1818 1819 /// Build a new OpenMP 'firstprivate' clause. 1820 /// 1821 /// By default, performs semantic analysis to build the new OpenMP clause. 1822 /// Subclasses may override this routine to provide different behavior. 1823 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, 1824 SourceLocation StartLoc, 1825 SourceLocation LParenLoc, 1826 SourceLocation EndLoc) { 1827 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, 1828 EndLoc); 1829 } 1830 1831 /// Build a new OpenMP 'lastprivate' clause. 1832 /// 1833 /// By default, performs semantic analysis to build the new OpenMP clause. 1834 /// Subclasses may override this routine to provide different behavior. 1835 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, 1836 OpenMPLastprivateModifier LPKind, 1837 SourceLocation LPKindLoc, 1838 SourceLocation ColonLoc, 1839 SourceLocation StartLoc, 1840 SourceLocation LParenLoc, 1841 SourceLocation EndLoc) { 1842 return getSema().ActOnOpenMPLastprivateClause( 1843 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc); 1844 } 1845 1846 /// Build a new OpenMP 'shared' clause. 1847 /// 1848 /// By default, performs semantic analysis to build the new OpenMP clause. 1849 /// Subclasses may override this routine to provide different behavior. 1850 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, 1851 SourceLocation StartLoc, 1852 SourceLocation LParenLoc, 1853 SourceLocation EndLoc) { 1854 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, 1855 EndLoc); 1856 } 1857 1858 /// Build a new OpenMP 'reduction' clause. 1859 /// 1860 /// By default, performs semantic analysis to build the new statement. 1861 /// Subclasses may override this routine to provide different behavior. 1862 OMPClause *RebuildOMPReductionClause( 1863 ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, 1864 SourceLocation StartLoc, SourceLocation LParenLoc, 1865 SourceLocation ModifierLoc, SourceLocation ColonLoc, 1866 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, 1867 const DeclarationNameInfo &ReductionId, 1868 ArrayRef<Expr *> UnresolvedReductions) { 1869 return getSema().ActOnOpenMPReductionClause( 1870 VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc, 1871 ReductionIdScopeSpec, ReductionId, UnresolvedReductions); 1872 } 1873 1874 /// Build a new OpenMP 'task_reduction' clause. 1875 /// 1876 /// By default, performs semantic analysis to build the new statement. 1877 /// Subclasses may override this routine to provide different behavior. 1878 OMPClause *RebuildOMPTaskReductionClause( 1879 ArrayRef<Expr *> VarList, SourceLocation StartLoc, 1880 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, 1881 CXXScopeSpec &ReductionIdScopeSpec, 1882 const DeclarationNameInfo &ReductionId, 1883 ArrayRef<Expr *> UnresolvedReductions) { 1884 return getSema().ActOnOpenMPTaskReductionClause( 1885 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, 1886 ReductionId, UnresolvedReductions); 1887 } 1888 1889 /// Build a new OpenMP 'in_reduction' clause. 1890 /// 1891 /// By default, performs semantic analysis to build the new statement. 1892 /// Subclasses may override this routine to provide different behavior. 1893 OMPClause * 1894 RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc, 1895 SourceLocation LParenLoc, SourceLocation ColonLoc, 1896 SourceLocation EndLoc, 1897 CXXScopeSpec &ReductionIdScopeSpec, 1898 const DeclarationNameInfo &ReductionId, 1899 ArrayRef<Expr *> UnresolvedReductions) { 1900 return getSema().ActOnOpenMPInReductionClause( 1901 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, 1902 ReductionId, UnresolvedReductions); 1903 } 1904 1905 /// Build a new OpenMP 'linear' clause. 1906 /// 1907 /// By default, performs semantic analysis to build the new OpenMP clause. 1908 /// Subclasses may override this routine to provide different behavior. 1909 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, 1910 SourceLocation StartLoc, 1911 SourceLocation LParenLoc, 1912 OpenMPLinearClauseKind Modifier, 1913 SourceLocation ModifierLoc, 1914 SourceLocation ColonLoc, 1915 SourceLocation EndLoc) { 1916 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, 1917 Modifier, ModifierLoc, ColonLoc, 1918 EndLoc); 1919 } 1920 1921 /// Build a new OpenMP 'aligned' clause. 1922 /// 1923 /// By default, performs semantic analysis to build the new OpenMP clause. 1924 /// Subclasses may override this routine to provide different behavior. 1925 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, 1926 SourceLocation StartLoc, 1927 SourceLocation LParenLoc, 1928 SourceLocation ColonLoc, 1929 SourceLocation EndLoc) { 1930 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, 1931 LParenLoc, ColonLoc, EndLoc); 1932 } 1933 1934 /// Build a new OpenMP 'copyin' clause. 1935 /// 1936 /// By default, performs semantic analysis to build the new OpenMP clause. 1937 /// Subclasses may override this routine to provide different behavior. 1938 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, 1939 SourceLocation StartLoc, 1940 SourceLocation LParenLoc, 1941 SourceLocation EndLoc) { 1942 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, 1943 EndLoc); 1944 } 1945 1946 /// Build a new OpenMP 'copyprivate' clause. 1947 /// 1948 /// By default, performs semantic analysis to build the new OpenMP clause. 1949 /// Subclasses may override this routine to provide different behavior. 1950 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, 1951 SourceLocation StartLoc, 1952 SourceLocation LParenLoc, 1953 SourceLocation EndLoc) { 1954 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, 1955 EndLoc); 1956 } 1957 1958 /// Build a new OpenMP 'flush' pseudo clause. 1959 /// 1960 /// By default, performs semantic analysis to build the new OpenMP clause. 1961 /// Subclasses may override this routine to provide different behavior. 1962 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, 1963 SourceLocation StartLoc, 1964 SourceLocation LParenLoc, 1965 SourceLocation EndLoc) { 1966 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, 1967 EndLoc); 1968 } 1969 1970 /// Build a new OpenMP 'depobj' pseudo clause. 1971 /// 1972 /// By default, performs semantic analysis to build the new OpenMP clause. 1973 /// Subclasses may override this routine to provide different behavior. 1974 OMPClause *RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, 1975 SourceLocation LParenLoc, 1976 SourceLocation EndLoc) { 1977 return getSema().ActOnOpenMPDepobjClause(Depobj, StartLoc, LParenLoc, 1978 EndLoc); 1979 } 1980 1981 /// Build a new OpenMP 'depend' pseudo clause. 1982 /// 1983 /// By default, performs semantic analysis to build the new OpenMP clause. 1984 /// Subclasses may override this routine to provide different behavior. 1985 OMPClause *RebuildOMPDependClause(OMPDependClause::DependDataTy Data, 1986 Expr *DepModifier, ArrayRef<Expr *> VarList, 1987 SourceLocation StartLoc, 1988 SourceLocation LParenLoc, 1989 SourceLocation EndLoc) { 1990 return getSema().ActOnOpenMPDependClause(Data, DepModifier, VarList, 1991 StartLoc, LParenLoc, EndLoc); 1992 } 1993 1994 /// Build a new OpenMP 'device' clause. 1995 /// 1996 /// By default, performs semantic analysis to build the new statement. 1997 /// Subclasses may override this routine to provide different behavior. 1998 OMPClause *RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, 1999 Expr *Device, SourceLocation StartLoc, 2000 SourceLocation LParenLoc, 2001 SourceLocation ModifierLoc, 2002 SourceLocation EndLoc) { 2003 return getSema().ActOnOpenMPDeviceClause(Modifier, Device, StartLoc, 2004 LParenLoc, ModifierLoc, EndLoc); 2005 } 2006 2007 /// Build a new OpenMP 'map' clause. 2008 /// 2009 /// By default, performs semantic analysis to build the new OpenMP clause. 2010 /// Subclasses may override this routine to provide different behavior. 2011 OMPClause *RebuildOMPMapClause( 2012 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, 2013 ArrayRef<SourceLocation> MapTypeModifiersLoc, 2014 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, 2015 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, 2016 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, 2017 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) { 2018 return getSema().ActOnOpenMPMapClause( 2019 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc, 2020 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc, 2021 ColonLoc, VarList, Locs, 2022 /*NoDiagnose=*/false, UnresolvedMappers); 2023 } 2024 2025 /// Build a new OpenMP 'allocate' clause. 2026 /// 2027 /// By default, performs semantic analysis to build the new OpenMP clause. 2028 /// Subclasses may override this routine to provide different behavior. 2029 OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList, 2030 SourceLocation StartLoc, 2031 SourceLocation LParenLoc, 2032 SourceLocation ColonLoc, 2033 SourceLocation EndLoc) { 2034 return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc, 2035 LParenLoc, ColonLoc, EndLoc); 2036 } 2037 2038 /// Build a new OpenMP 'num_teams' clause. 2039 /// 2040 /// By default, performs semantic analysis to build the new statement. 2041 /// Subclasses may override this routine to provide different behavior. 2042 OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, 2043 SourceLocation LParenLoc, 2044 SourceLocation EndLoc) { 2045 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc, 2046 EndLoc); 2047 } 2048 2049 /// Build a new OpenMP 'thread_limit' clause. 2050 /// 2051 /// By default, performs semantic analysis to build the new statement. 2052 /// Subclasses may override this routine to provide different behavior. 2053 OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit, 2054 SourceLocation StartLoc, 2055 SourceLocation LParenLoc, 2056 SourceLocation EndLoc) { 2057 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc, 2058 LParenLoc, EndLoc); 2059 } 2060 2061 /// Build a new OpenMP 'priority' clause. 2062 /// 2063 /// By default, performs semantic analysis to build the new statement. 2064 /// Subclasses may override this routine to provide different behavior. 2065 OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, 2066 SourceLocation LParenLoc, 2067 SourceLocation EndLoc) { 2068 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc, 2069 EndLoc); 2070 } 2071 2072 /// Build a new OpenMP 'grainsize' clause. 2073 /// 2074 /// By default, performs semantic analysis to build the new statement. 2075 /// Subclasses may override this routine to provide different behavior. 2076 OMPClause *RebuildOMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, 2077 Expr *Device, SourceLocation StartLoc, 2078 SourceLocation LParenLoc, 2079 SourceLocation ModifierLoc, 2080 SourceLocation EndLoc) { 2081 return getSema().ActOnOpenMPGrainsizeClause(Modifier, Device, StartLoc, 2082 LParenLoc, ModifierLoc, EndLoc); 2083 } 2084 2085 /// Build a new OpenMP 'num_tasks' clause. 2086 /// 2087 /// By default, performs semantic analysis to build the new statement. 2088 /// Subclasses may override this routine to provide different behavior. 2089 OMPClause *RebuildOMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, 2090 Expr *NumTasks, SourceLocation StartLoc, 2091 SourceLocation LParenLoc, 2092 SourceLocation ModifierLoc, 2093 SourceLocation EndLoc) { 2094 return getSema().ActOnOpenMPNumTasksClause(Modifier, NumTasks, StartLoc, 2095 LParenLoc, ModifierLoc, EndLoc); 2096 } 2097 2098 /// Build a new OpenMP 'hint' clause. 2099 /// 2100 /// By default, performs semantic analysis to build the new statement. 2101 /// Subclasses may override this routine to provide different behavior. 2102 OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, 2103 SourceLocation LParenLoc, 2104 SourceLocation EndLoc) { 2105 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc); 2106 } 2107 2108 /// Build a new OpenMP 'detach' clause. 2109 /// 2110 /// By default, performs semantic analysis to build the new statement. 2111 /// Subclasses may override this routine to provide different behavior. 2112 OMPClause *RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc, 2113 SourceLocation LParenLoc, 2114 SourceLocation EndLoc) { 2115 return getSema().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc); 2116 } 2117 2118 /// Build a new OpenMP 'dist_schedule' clause. 2119 /// 2120 /// By default, performs semantic analysis to build the new OpenMP clause. 2121 /// Subclasses may override this routine to provide different behavior. 2122 OMPClause * 2123 RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, 2124 Expr *ChunkSize, SourceLocation StartLoc, 2125 SourceLocation LParenLoc, SourceLocation KindLoc, 2126 SourceLocation CommaLoc, SourceLocation EndLoc) { 2127 return getSema().ActOnOpenMPDistScheduleClause( 2128 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); 2129 } 2130 2131 /// Build a new OpenMP 'to' clause. 2132 /// 2133 /// By default, performs semantic analysis to build the new statement. 2134 /// Subclasses may override this routine to provide different behavior. 2135 OMPClause * 2136 RebuildOMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, 2137 ArrayRef<SourceLocation> MotionModifiersLoc, 2138 CXXScopeSpec &MapperIdScopeSpec, 2139 DeclarationNameInfo &MapperId, SourceLocation ColonLoc, 2140 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, 2141 ArrayRef<Expr *> UnresolvedMappers) { 2142 return getSema().ActOnOpenMPToClause(MotionModifiers, MotionModifiersLoc, 2143 MapperIdScopeSpec, MapperId, ColonLoc, 2144 VarList, Locs, UnresolvedMappers); 2145 } 2146 2147 /// Build a new OpenMP 'from' clause. 2148 /// 2149 /// By default, performs semantic analysis to build the new statement. 2150 /// Subclasses may override this routine to provide different behavior. 2151 OMPClause * 2152 RebuildOMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, 2153 ArrayRef<SourceLocation> MotionModifiersLoc, 2154 CXXScopeSpec &MapperIdScopeSpec, 2155 DeclarationNameInfo &MapperId, SourceLocation ColonLoc, 2156 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, 2157 ArrayRef<Expr *> UnresolvedMappers) { 2158 return getSema().ActOnOpenMPFromClause( 2159 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId, 2160 ColonLoc, VarList, Locs, UnresolvedMappers); 2161 } 2162 2163 /// Build a new OpenMP 'use_device_ptr' clause. 2164 /// 2165 /// By default, performs semantic analysis to build the new OpenMP clause. 2166 /// Subclasses may override this routine to provide different behavior. 2167 OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList, 2168 const OMPVarListLocTy &Locs) { 2169 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs); 2170 } 2171 2172 /// Build a new OpenMP 'use_device_addr' clause. 2173 /// 2174 /// By default, performs semantic analysis to build the new OpenMP clause. 2175 /// Subclasses may override this routine to provide different behavior. 2176 OMPClause *RebuildOMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, 2177 const OMPVarListLocTy &Locs) { 2178 return getSema().ActOnOpenMPUseDeviceAddrClause(VarList, Locs); 2179 } 2180 2181 /// Build a new OpenMP 'is_device_ptr' clause. 2182 /// 2183 /// By default, performs semantic analysis to build the new OpenMP clause. 2184 /// Subclasses may override this routine to provide different behavior. 2185 OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList, 2186 const OMPVarListLocTy &Locs) { 2187 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs); 2188 } 2189 2190 /// Build a new OpenMP 'has_device_addr' clause. 2191 /// 2192 /// By default, performs semantic analysis to build the new OpenMP clause. 2193 /// Subclasses may override this routine to provide different behavior. 2194 OMPClause *RebuildOMPHasDeviceAddrClause(ArrayRef<Expr *> VarList, 2195 const OMPVarListLocTy &Locs) { 2196 return getSema().ActOnOpenMPHasDeviceAddrClause(VarList, Locs); 2197 } 2198 2199 /// Build a new OpenMP 'defaultmap' clause. 2200 /// 2201 /// By default, performs semantic analysis to build the new OpenMP clause. 2202 /// Subclasses may override this routine to provide different behavior. 2203 OMPClause *RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, 2204 OpenMPDefaultmapClauseKind Kind, 2205 SourceLocation StartLoc, 2206 SourceLocation LParenLoc, 2207 SourceLocation MLoc, 2208 SourceLocation KindLoc, 2209 SourceLocation EndLoc) { 2210 return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc, 2211 MLoc, KindLoc, EndLoc); 2212 } 2213 2214 /// Build a new OpenMP 'nontemporal' clause. 2215 /// 2216 /// By default, performs semantic analysis to build the new OpenMP clause. 2217 /// Subclasses may override this routine to provide different behavior. 2218 OMPClause *RebuildOMPNontemporalClause(ArrayRef<Expr *> VarList, 2219 SourceLocation StartLoc, 2220 SourceLocation LParenLoc, 2221 SourceLocation EndLoc) { 2222 return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc, 2223 EndLoc); 2224 } 2225 2226 /// Build a new OpenMP 'inclusive' clause. 2227 /// 2228 /// By default, performs semantic analysis to build the new OpenMP clause. 2229 /// Subclasses may override this routine to provide different behavior. 2230 OMPClause *RebuildOMPInclusiveClause(ArrayRef<Expr *> VarList, 2231 SourceLocation StartLoc, 2232 SourceLocation LParenLoc, 2233 SourceLocation EndLoc) { 2234 return getSema().ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc, 2235 EndLoc); 2236 } 2237 2238 /// Build a new OpenMP 'exclusive' clause. 2239 /// 2240 /// By default, performs semantic analysis to build the new OpenMP clause. 2241 /// Subclasses may override this routine to provide different behavior. 2242 OMPClause *RebuildOMPExclusiveClause(ArrayRef<Expr *> VarList, 2243 SourceLocation StartLoc, 2244 SourceLocation LParenLoc, 2245 SourceLocation EndLoc) { 2246 return getSema().ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc, 2247 EndLoc); 2248 } 2249 2250 /// Build a new OpenMP 'uses_allocators' clause. 2251 /// 2252 /// By default, performs semantic analysis to build the new OpenMP clause. 2253 /// Subclasses may override this routine to provide different behavior. 2254 OMPClause *RebuildOMPUsesAllocatorsClause( 2255 ArrayRef<Sema::UsesAllocatorsData> Data, SourceLocation StartLoc, 2256 SourceLocation LParenLoc, SourceLocation EndLoc) { 2257 return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc, LParenLoc, EndLoc, 2258 Data); 2259 } 2260 2261 /// Build a new OpenMP 'affinity' clause. 2262 /// 2263 /// By default, performs semantic analysis to build the new OpenMP clause. 2264 /// Subclasses may override this routine to provide different behavior. 2265 OMPClause *RebuildOMPAffinityClause(SourceLocation StartLoc, 2266 SourceLocation LParenLoc, 2267 SourceLocation ColonLoc, 2268 SourceLocation EndLoc, Expr *Modifier, 2269 ArrayRef<Expr *> Locators) { 2270 return getSema().ActOnOpenMPAffinityClause(StartLoc, LParenLoc, ColonLoc, 2271 EndLoc, Modifier, Locators); 2272 } 2273 2274 /// Build a new OpenMP 'order' clause. 2275 /// 2276 /// By default, performs semantic analysis to build the new OpenMP clause. 2277 /// Subclasses may override this routine to provide different behavior. 2278 OMPClause *RebuildOMPOrderClause( 2279 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc, 2280 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, 2281 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) { 2282 return getSema().ActOnOpenMPOrderClause(Modifier, Kind, StartLoc, LParenLoc, 2283 ModifierKwLoc, KindKwLoc, EndLoc); 2284 } 2285 2286 /// Build a new OpenMP 'init' clause. 2287 /// 2288 /// By default, performs semantic analysis to build the new OpenMP clause. 2289 /// Subclasses may override this routine to provide different behavior. 2290 OMPClause *RebuildOMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, 2291 SourceLocation StartLoc, 2292 SourceLocation LParenLoc, 2293 SourceLocation VarLoc, 2294 SourceLocation EndLoc) { 2295 return getSema().ActOnOpenMPInitClause(InteropVar, InteropInfo, StartLoc, 2296 LParenLoc, VarLoc, EndLoc); 2297 } 2298 2299 /// Build a new OpenMP 'use' clause. 2300 /// 2301 /// By default, performs semantic analysis to build the new OpenMP clause. 2302 /// Subclasses may override this routine to provide different behavior. 2303 OMPClause *RebuildOMPUseClause(Expr *InteropVar, SourceLocation StartLoc, 2304 SourceLocation LParenLoc, 2305 SourceLocation VarLoc, SourceLocation EndLoc) { 2306 return getSema().ActOnOpenMPUseClause(InteropVar, StartLoc, LParenLoc, 2307 VarLoc, EndLoc); 2308 } 2309 2310 /// Build a new OpenMP 'destroy' clause. 2311 /// 2312 /// By default, performs semantic analysis to build the new OpenMP clause. 2313 /// Subclasses may override this routine to provide different behavior. 2314 OMPClause *RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, 2315 SourceLocation LParenLoc, 2316 SourceLocation VarLoc, 2317 SourceLocation EndLoc) { 2318 return getSema().ActOnOpenMPDestroyClause(InteropVar, StartLoc, LParenLoc, 2319 VarLoc, EndLoc); 2320 } 2321 2322 /// Build a new OpenMP 'novariants' clause. 2323 /// 2324 /// By default, performs semantic analysis to build the new OpenMP clause. 2325 /// Subclasses may override this routine to provide different behavior. 2326 OMPClause *RebuildOMPNovariantsClause(Expr *Condition, 2327 SourceLocation StartLoc, 2328 SourceLocation LParenLoc, 2329 SourceLocation EndLoc) { 2330 return getSema().ActOnOpenMPNovariantsClause(Condition, StartLoc, LParenLoc, 2331 EndLoc); 2332 } 2333 2334 /// Build a new OpenMP 'nocontext' clause. 2335 /// 2336 /// By default, performs semantic analysis to build the new OpenMP clause. 2337 /// Subclasses may override this routine to provide different behavior. 2338 OMPClause *RebuildOMPNocontextClause(Expr *Condition, SourceLocation StartLoc, 2339 SourceLocation LParenLoc, 2340 SourceLocation EndLoc) { 2341 return getSema().ActOnOpenMPNocontextClause(Condition, StartLoc, LParenLoc, 2342 EndLoc); 2343 } 2344 2345 /// Build a new OpenMP 'filter' clause. 2346 /// 2347 /// By default, performs semantic analysis to build the new OpenMP clause. 2348 /// Subclasses may override this routine to provide different behavior. 2349 OMPClause *RebuildOMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, 2350 SourceLocation LParenLoc, 2351 SourceLocation EndLoc) { 2352 return getSema().ActOnOpenMPFilterClause(ThreadID, StartLoc, LParenLoc, 2353 EndLoc); 2354 } 2355 2356 /// Build a new OpenMP 'bind' clause. 2357 /// 2358 /// By default, performs semantic analysis to build the new OpenMP clause. 2359 /// Subclasses may override this routine to provide different behavior. 2360 OMPClause *RebuildOMPBindClause(OpenMPBindClauseKind Kind, 2361 SourceLocation KindLoc, 2362 SourceLocation StartLoc, 2363 SourceLocation LParenLoc, 2364 SourceLocation EndLoc) { 2365 return getSema().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc, LParenLoc, 2366 EndLoc); 2367 } 2368 2369 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause. 2370 /// 2371 /// By default, performs semantic analysis to build the new OpenMP clause. 2372 /// Subclasses may override this routine to provide different behavior. 2373 OMPClause *RebuildOMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, 2374 SourceLocation LParenLoc, 2375 SourceLocation EndLoc) { 2376 return getSema().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc, LParenLoc, 2377 EndLoc); 2378 } 2379 2380 /// Build a new OpenMP 'align' clause. 2381 /// 2382 /// By default, performs semantic analysis to build the new OpenMP clause. 2383 /// Subclasses may override this routine to provide different behavior. 2384 OMPClause *RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc, 2385 SourceLocation LParenLoc, 2386 SourceLocation EndLoc) { 2387 return getSema().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc, EndLoc); 2388 } 2389 2390 /// Build a new OpenMP 'at' clause. 2391 /// 2392 /// By default, performs semantic analysis to build the new OpenMP clause. 2393 /// Subclasses may override this routine to provide different behavior. 2394 OMPClause *RebuildOMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KwLoc, 2395 SourceLocation StartLoc, 2396 SourceLocation LParenLoc, 2397 SourceLocation EndLoc) { 2398 return getSema().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc, LParenLoc, 2399 EndLoc); 2400 } 2401 2402 /// Build a new OpenMP 'severity' clause. 2403 /// 2404 /// By default, performs semantic analysis to build the new OpenMP clause. 2405 /// Subclasses may override this routine to provide different behavior. 2406 OMPClause *RebuildOMPSeverityClause(OpenMPSeverityClauseKind Kind, 2407 SourceLocation KwLoc, 2408 SourceLocation StartLoc, 2409 SourceLocation LParenLoc, 2410 SourceLocation EndLoc) { 2411 return getSema().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc, LParenLoc, 2412 EndLoc); 2413 } 2414 2415 /// Build a new OpenMP 'message' clause. 2416 /// 2417 /// By default, performs semantic analysis to build the new OpenMP clause. 2418 /// Subclasses may override this routine to provide different behavior. 2419 OMPClause *RebuildOMPMessageClause(Expr *MS, SourceLocation StartLoc, 2420 SourceLocation LParenLoc, 2421 SourceLocation EndLoc) { 2422 return getSema().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc, EndLoc); 2423 } 2424 2425 /// Build a new OpenMP 'doacross' clause. 2426 /// 2427 /// By default, performs semantic analysis to build the new OpenMP clause. 2428 /// Subclasses may override this routine to provide different behavior. 2429 OMPClause * 2430 RebuildOMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, 2431 SourceLocation DepLoc, SourceLocation ColonLoc, 2432 ArrayRef<Expr *> VarList, SourceLocation StartLoc, 2433 SourceLocation LParenLoc, SourceLocation EndLoc) { 2434 return getSema().ActOnOpenMPDoacrossClause( 2435 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc); 2436 } 2437 2438 /// Rebuild the operand to an Objective-C \@synchronized statement. 2439 /// 2440 /// By default, performs semantic analysis to build the new statement. 2441 /// Subclasses may override this routine to provide different behavior. 2442 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, 2443 Expr *object) { 2444 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); 2445 } 2446 2447 /// Build a new Objective-C \@synchronized statement. 2448 /// 2449 /// By default, performs semantic analysis to build the new statement. 2450 /// Subclasses may override this routine to provide different behavior. 2451 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, 2452 Expr *Object, Stmt *Body) { 2453 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); 2454 } 2455 2456 /// Build a new Objective-C \@autoreleasepool statement. 2457 /// 2458 /// By default, performs semantic analysis to build the new statement. 2459 /// Subclasses may override this routine to provide different behavior. 2460 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, 2461 Stmt *Body) { 2462 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); 2463 } 2464 2465 /// Build a new Objective-C fast enumeration statement. 2466 /// 2467 /// By default, performs semantic analysis to build the new statement. 2468 /// Subclasses may override this routine to provide different behavior. 2469 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, 2470 Stmt *Element, 2471 Expr *Collection, 2472 SourceLocation RParenLoc, 2473 Stmt *Body) { 2474 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, 2475 Element, 2476 Collection, 2477 RParenLoc); 2478 if (ForEachStmt.isInvalid()) 2479 return StmtError(); 2480 2481 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); 2482 } 2483 2484 /// Build a new C++ exception declaration. 2485 /// 2486 /// By default, performs semantic analysis to build the new decaration. 2487 /// Subclasses may override this routine to provide different behavior. 2488 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, 2489 TypeSourceInfo *Declarator, 2490 SourceLocation StartLoc, 2491 SourceLocation IdLoc, 2492 IdentifierInfo *Id) { 2493 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, 2494 StartLoc, IdLoc, Id); 2495 if (Var) 2496 getSema().CurContext->addDecl(Var); 2497 return Var; 2498 } 2499 2500 /// Build a new C++ catch statement. 2501 /// 2502 /// By default, performs semantic analysis to build the new statement. 2503 /// Subclasses may override this routine to provide different behavior. 2504 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, 2505 VarDecl *ExceptionDecl, 2506 Stmt *Handler) { 2507 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, 2508 Handler)); 2509 } 2510 2511 /// Build a new C++ try statement. 2512 /// 2513 /// By default, performs semantic analysis to build the new statement. 2514 /// Subclasses may override this routine to provide different behavior. 2515 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, 2516 ArrayRef<Stmt *> Handlers) { 2517 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); 2518 } 2519 2520 /// Build a new C++0x range-based for statement. 2521 /// 2522 /// By default, performs semantic analysis to build the new statement. 2523 /// Subclasses may override this routine to provide different behavior. 2524 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, 2525 SourceLocation CoawaitLoc, Stmt *Init, 2526 SourceLocation ColonLoc, Stmt *Range, 2527 Stmt *Begin, Stmt *End, Expr *Cond, 2528 Expr *Inc, Stmt *LoopVar, 2529 SourceLocation RParenLoc) { 2530 // If we've just learned that the range is actually an Objective-C 2531 // collection, treat this as an Objective-C fast enumeration loop. 2532 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { 2533 if (RangeStmt->isSingleDecl()) { 2534 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { 2535 if (RangeVar->isInvalidDecl()) 2536 return StmtError(); 2537 2538 Expr *RangeExpr = RangeVar->getInit(); 2539 if (!RangeExpr->isTypeDependent() && 2540 RangeExpr->getType()->isObjCObjectPointerType()) { 2541 // FIXME: Support init-statements in Objective-C++20 ranged for 2542 // statement. 2543 if (Init) { 2544 return SemaRef.Diag(Init->getBeginLoc(), 2545 diag::err_objc_for_range_init_stmt) 2546 << Init->getSourceRange(); 2547 } 2548 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, 2549 RangeExpr, RParenLoc); 2550 } 2551 } 2552 } 2553 } 2554 2555 return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc, 2556 Range, Begin, End, Cond, Inc, LoopVar, 2557 RParenLoc, Sema::BFRK_Rebuild); 2558 } 2559 2560 /// Build a new C++0x range-based for statement. 2561 /// 2562 /// By default, performs semantic analysis to build the new statement. 2563 /// Subclasses may override this routine to provide different behavior. 2564 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, 2565 bool IsIfExists, 2566 NestedNameSpecifierLoc QualifierLoc, 2567 DeclarationNameInfo NameInfo, 2568 Stmt *Nested) { 2569 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, 2570 QualifierLoc, NameInfo, Nested); 2571 } 2572 2573 /// Attach body to a C++0x range-based for statement. 2574 /// 2575 /// By default, performs semantic analysis to finish the new statement. 2576 /// Subclasses may override this routine to provide different behavior. 2577 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { 2578 return getSema().FinishCXXForRangeStmt(ForRange, Body); 2579 } 2580 2581 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, 2582 Stmt *TryBlock, Stmt *Handler) { 2583 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); 2584 } 2585 2586 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, 2587 Stmt *Block) { 2588 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); 2589 } 2590 2591 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { 2592 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); 2593 } 2594 2595 ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, 2596 SourceLocation LParen, 2597 SourceLocation RParen, 2598 TypeSourceInfo *TSI) { 2599 return getSema().BuildSYCLUniqueStableNameExpr(OpLoc, LParen, RParen, TSI); 2600 } 2601 2602 /// Build a new predefined expression. 2603 /// 2604 /// By default, performs semantic analysis to build the new expression. 2605 /// Subclasses may override this routine to provide different behavior. 2606 ExprResult RebuildPredefinedExpr(SourceLocation Loc, 2607 PredefinedExpr::IdentKind IK) { 2608 return getSema().BuildPredefinedExpr(Loc, IK); 2609 } 2610 2611 /// Build a new expression that references a declaration. 2612 /// 2613 /// By default, performs semantic analysis to build the new expression. 2614 /// Subclasses may override this routine to provide different behavior. 2615 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, 2616 LookupResult &R, 2617 bool RequiresADL) { 2618 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); 2619 } 2620 2621 2622 /// Build a new expression that references a declaration. 2623 /// 2624 /// By default, performs semantic analysis to build the new expression. 2625 /// Subclasses may override this routine to provide different behavior. 2626 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 2627 ValueDecl *VD, 2628 const DeclarationNameInfo &NameInfo, 2629 NamedDecl *Found, 2630 TemplateArgumentListInfo *TemplateArgs) { 2631 CXXScopeSpec SS; 2632 SS.Adopt(QualifierLoc); 2633 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found, 2634 TemplateArgs); 2635 } 2636 2637 /// Build a new expression in parentheses. 2638 /// 2639 /// By default, performs semantic analysis to build the new expression. 2640 /// Subclasses may override this routine to provide different behavior. 2641 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, 2642 SourceLocation RParen) { 2643 return getSema().ActOnParenExpr(LParen, RParen, SubExpr); 2644 } 2645 2646 /// Build a new pseudo-destructor expression. 2647 /// 2648 /// By default, performs semantic analysis to build the new expression. 2649 /// Subclasses may override this routine to provide different behavior. 2650 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, 2651 SourceLocation OperatorLoc, 2652 bool isArrow, 2653 CXXScopeSpec &SS, 2654 TypeSourceInfo *ScopeType, 2655 SourceLocation CCLoc, 2656 SourceLocation TildeLoc, 2657 PseudoDestructorTypeStorage Destroyed); 2658 2659 /// Build a new unary operator expression. 2660 /// 2661 /// By default, performs semantic analysis to build the new expression. 2662 /// Subclasses may override this routine to provide different behavior. 2663 ExprResult RebuildUnaryOperator(SourceLocation OpLoc, 2664 UnaryOperatorKind Opc, 2665 Expr *SubExpr) { 2666 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); 2667 } 2668 2669 /// Build a new builtin offsetof expression. 2670 /// 2671 /// By default, performs semantic analysis to build the new expression. 2672 /// Subclasses may override this routine to provide different behavior. 2673 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, 2674 TypeSourceInfo *Type, 2675 ArrayRef<Sema::OffsetOfComponent> Components, 2676 SourceLocation RParenLoc) { 2677 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, 2678 RParenLoc); 2679 } 2680 2681 /// Build a new sizeof, alignof or vec_step expression with a 2682 /// type argument. 2683 /// 2684 /// By default, performs semantic analysis to build the new expression. 2685 /// Subclasses may override this routine to provide different behavior. 2686 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, 2687 SourceLocation OpLoc, 2688 UnaryExprOrTypeTrait ExprKind, 2689 SourceRange R) { 2690 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); 2691 } 2692 2693 /// Build a new sizeof, alignof or vec step expression with an 2694 /// expression argument. 2695 /// 2696 /// By default, performs semantic analysis to build the new expression. 2697 /// Subclasses may override this routine to provide different behavior. 2698 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, 2699 UnaryExprOrTypeTrait ExprKind, 2700 SourceRange R) { 2701 ExprResult Result 2702 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); 2703 if (Result.isInvalid()) 2704 return ExprError(); 2705 2706 return Result; 2707 } 2708 2709 /// Build a new array subscript expression. 2710 /// 2711 /// By default, performs semantic analysis to build the new expression. 2712 /// Subclasses may override this routine to provide different behavior. 2713 ExprResult RebuildArraySubscriptExpr(Expr *LHS, 2714 SourceLocation LBracketLoc, 2715 Expr *RHS, 2716 SourceLocation RBracketLoc) { 2717 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, 2718 LBracketLoc, RHS, 2719 RBracketLoc); 2720 } 2721 2722 /// Build a new matrix subscript expression. 2723 /// 2724 /// By default, performs semantic analysis to build the new expression. 2725 /// Subclasses may override this routine to provide different behavior. 2726 ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, 2727 Expr *ColumnIdx, 2728 SourceLocation RBracketLoc) { 2729 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx, 2730 RBracketLoc); 2731 } 2732 2733 /// Build a new array section expression. 2734 /// 2735 /// By default, performs semantic analysis to build the new expression. 2736 /// Subclasses may override this routine to provide different behavior. 2737 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, 2738 Expr *LowerBound, 2739 SourceLocation ColonLocFirst, 2740 SourceLocation ColonLocSecond, 2741 Expr *Length, Expr *Stride, 2742 SourceLocation RBracketLoc) { 2743 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound, 2744 ColonLocFirst, ColonLocSecond, 2745 Length, Stride, RBracketLoc); 2746 } 2747 2748 /// Build a new array shaping expression. 2749 /// 2750 /// By default, performs semantic analysis to build the new expression. 2751 /// Subclasses may override this routine to provide different behavior. 2752 ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, 2753 SourceLocation RParenLoc, 2754 ArrayRef<Expr *> Dims, 2755 ArrayRef<SourceRange> BracketsRanges) { 2756 return getSema().ActOnOMPArrayShapingExpr(Base, LParenLoc, RParenLoc, Dims, 2757 BracketsRanges); 2758 } 2759 2760 /// Build a new iterator expression. 2761 /// 2762 /// By default, performs semantic analysis to build the new expression. 2763 /// Subclasses may override this routine to provide different behavior. 2764 ExprResult RebuildOMPIteratorExpr( 2765 SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, 2766 ArrayRef<Sema::OMPIteratorData> Data) { 2767 return getSema().ActOnOMPIteratorExpr(/*Scope=*/nullptr, IteratorKwLoc, 2768 LLoc, RLoc, Data); 2769 } 2770 2771 /// Build a new call expression. 2772 /// 2773 /// By default, performs semantic analysis to build the new expression. 2774 /// Subclasses may override this routine to provide different behavior. 2775 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, 2776 MultiExprArg Args, 2777 SourceLocation RParenLoc, 2778 Expr *ExecConfig = nullptr) { 2779 return getSema().ActOnCallExpr( 2780 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig); 2781 } 2782 2783 ExprResult RebuildCxxSubscriptExpr(Expr *Callee, SourceLocation LParenLoc, 2784 MultiExprArg Args, 2785 SourceLocation RParenLoc) { 2786 return getSema().ActOnArraySubscriptExpr( 2787 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc); 2788 } 2789 2790 /// Build a new member access expression. 2791 /// 2792 /// By default, performs semantic analysis to build the new expression. 2793 /// Subclasses may override this routine to provide different behavior. 2794 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, 2795 bool isArrow, 2796 NestedNameSpecifierLoc QualifierLoc, 2797 SourceLocation TemplateKWLoc, 2798 const DeclarationNameInfo &MemberNameInfo, 2799 ValueDecl *Member, 2800 NamedDecl *FoundDecl, 2801 const TemplateArgumentListInfo *ExplicitTemplateArgs, 2802 NamedDecl *FirstQualifierInScope) { 2803 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, 2804 isArrow); 2805 if (!Member->getDeclName()) { 2806 // We have a reference to an unnamed field. This is always the 2807 // base of an anonymous struct/union member access, i.e. the 2808 // field is always of record type. 2809 assert(Member->getType()->isRecordType() && 2810 "unnamed member not of record type?"); 2811 2812 BaseResult = 2813 getSema().PerformObjectMemberConversion(BaseResult.get(), 2814 QualifierLoc.getNestedNameSpecifier(), 2815 FoundDecl, Member); 2816 if (BaseResult.isInvalid()) 2817 return ExprError(); 2818 Base = BaseResult.get(); 2819 2820 CXXScopeSpec EmptySS; 2821 return getSema().BuildFieldReferenceExpr( 2822 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member), 2823 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo); 2824 } 2825 2826 CXXScopeSpec SS; 2827 SS.Adopt(QualifierLoc); 2828 2829 Base = BaseResult.get(); 2830 QualType BaseType = Base->getType(); 2831 2832 if (isArrow && !BaseType->isPointerType()) 2833 return ExprError(); 2834 2835 // FIXME: this involves duplicating earlier analysis in a lot of 2836 // cases; we should avoid this when possible. 2837 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 2838 R.addDecl(FoundDecl); 2839 R.resolveKind(); 2840 2841 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() && 2842 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) { 2843 if (auto *ThisClass = cast<CXXThisExpr>(Base) 2844 ->getType() 2845 ->getPointeeType() 2846 ->getAsCXXRecordDecl()) { 2847 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext()); 2848 // In unevaluated contexts, an expression supposed to be a member access 2849 // might reference a member in an unrelated class. 2850 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class)) 2851 return getSema().BuildDeclRefExpr(Member, Member->getType(), 2852 VK_LValue, Member->getLocation()); 2853 } 2854 } 2855 2856 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 2857 SS, TemplateKWLoc, 2858 FirstQualifierInScope, 2859 R, ExplicitTemplateArgs, 2860 /*S*/nullptr); 2861 } 2862 2863 /// Build a new binary operator expression. 2864 /// 2865 /// By default, performs semantic analysis to build the new expression. 2866 /// Subclasses may override this routine to provide different behavior. 2867 ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 2868 BinaryOperatorKind Opc, 2869 Expr *LHS, Expr *RHS) { 2870 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); 2871 } 2872 2873 /// Build a new rewritten operator expression. 2874 /// 2875 /// By default, performs semantic analysis to build the new expression. 2876 /// Subclasses may override this routine to provide different behavior. 2877 ExprResult RebuildCXXRewrittenBinaryOperator( 2878 SourceLocation OpLoc, BinaryOperatorKind Opcode, 2879 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) { 2880 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS, 2881 RHS, /*RequiresADL*/false); 2882 } 2883 2884 /// Build a new conditional operator expression. 2885 /// 2886 /// By default, performs semantic analysis to build the new expression. 2887 /// Subclasses may override this routine to provide different behavior. 2888 ExprResult RebuildConditionalOperator(Expr *Cond, 2889 SourceLocation QuestionLoc, 2890 Expr *LHS, 2891 SourceLocation ColonLoc, 2892 Expr *RHS) { 2893 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 2894 LHS, RHS); 2895 } 2896 2897 /// Build a new C-style cast expression. 2898 /// 2899 /// By default, performs semantic analysis to build the new expression. 2900 /// Subclasses may override this routine to provide different behavior. 2901 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 2902 TypeSourceInfo *TInfo, 2903 SourceLocation RParenLoc, 2904 Expr *SubExpr) { 2905 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 2906 SubExpr); 2907 } 2908 2909 /// Build a new compound literal expression. 2910 /// 2911 /// By default, performs semantic analysis to build the new expression. 2912 /// Subclasses may override this routine to provide different behavior. 2913 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 2914 TypeSourceInfo *TInfo, 2915 SourceLocation RParenLoc, 2916 Expr *Init) { 2917 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 2918 Init); 2919 } 2920 2921 /// Build a new extended vector element access expression. 2922 /// 2923 /// By default, performs semantic analysis to build the new expression. 2924 /// Subclasses may override this routine to provide different behavior. 2925 ExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, 2926 bool IsArrow, 2927 SourceLocation AccessorLoc, 2928 IdentifierInfo &Accessor) { 2929 2930 CXXScopeSpec SS; 2931 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 2932 return getSema().BuildMemberReferenceExpr( 2933 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(), 2934 /*FirstQualifierInScope*/ nullptr, NameInfo, 2935 /* TemplateArgs */ nullptr, 2936 /*S*/ nullptr); 2937 } 2938 2939 /// Build a new initializer list expression. 2940 /// 2941 /// By default, performs semantic analysis to build the new expression. 2942 /// Subclasses may override this routine to provide different behavior. 2943 ExprResult RebuildInitList(SourceLocation LBraceLoc, 2944 MultiExprArg Inits, 2945 SourceLocation RBraceLoc) { 2946 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc); 2947 } 2948 2949 /// Build a new designated initializer expression. 2950 /// 2951 /// By default, performs semantic analysis to build the new expression. 2952 /// Subclasses may override this routine to provide different behavior. 2953 ExprResult RebuildDesignatedInitExpr(Designation &Desig, 2954 MultiExprArg ArrayExprs, 2955 SourceLocation EqualOrColonLoc, 2956 bool GNUSyntax, 2957 Expr *Init) { 2958 ExprResult Result 2959 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 2960 Init); 2961 if (Result.isInvalid()) 2962 return ExprError(); 2963 2964 return Result; 2965 } 2966 2967 /// Build a new value-initialized expression. 2968 /// 2969 /// By default, builds the implicit value initialization without performing 2970 /// any semantic analysis. Subclasses may override this routine to provide 2971 /// different behavior. 2972 ExprResult RebuildImplicitValueInitExpr(QualType T) { 2973 return new (SemaRef.Context) ImplicitValueInitExpr(T); 2974 } 2975 2976 /// Build a new \c va_arg expression. 2977 /// 2978 /// By default, performs semantic analysis to build the new expression. 2979 /// Subclasses may override this routine to provide different behavior. 2980 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 2981 Expr *SubExpr, TypeSourceInfo *TInfo, 2982 SourceLocation RParenLoc) { 2983 return getSema().BuildVAArgExpr(BuiltinLoc, 2984 SubExpr, TInfo, 2985 RParenLoc); 2986 } 2987 2988 /// Build a new expression list in parentheses. 2989 /// 2990 /// By default, performs semantic analysis to build the new expression. 2991 /// Subclasses may override this routine to provide different behavior. 2992 ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 2993 MultiExprArg SubExprs, 2994 SourceLocation RParenLoc) { 2995 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); 2996 } 2997 2998 /// Build a new address-of-label expression. 2999 /// 3000 /// By default, performs semantic analysis, using the name of the label 3001 /// rather than attempting to map the label statement itself. 3002 /// Subclasses may override this routine to provide different behavior. 3003 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 3004 SourceLocation LabelLoc, LabelDecl *Label) { 3005 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); 3006 } 3007 3008 /// Build a new GNU statement expression. 3009 /// 3010 /// By default, performs semantic analysis to build the new expression. 3011 /// Subclasses may override this routine to provide different behavior. 3012 ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, 3013 SourceLocation RParenLoc, unsigned TemplateDepth) { 3014 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc, 3015 TemplateDepth); 3016 } 3017 3018 /// Build a new __builtin_choose_expr expression. 3019 /// 3020 /// By default, performs semantic analysis to build the new expression. 3021 /// Subclasses may override this routine to provide different behavior. 3022 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 3023 Expr *Cond, Expr *LHS, Expr *RHS, 3024 SourceLocation RParenLoc) { 3025 return SemaRef.ActOnChooseExpr(BuiltinLoc, 3026 Cond, LHS, RHS, 3027 RParenLoc); 3028 } 3029 3030 /// Build a new generic selection expression with an expression predicate. 3031 /// 3032 /// By default, performs semantic analysis to build the new expression. 3033 /// Subclasses may override this routine to provide different behavior. 3034 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, 3035 SourceLocation DefaultLoc, 3036 SourceLocation RParenLoc, 3037 Expr *ControllingExpr, 3038 ArrayRef<TypeSourceInfo *> Types, 3039 ArrayRef<Expr *> Exprs) { 3040 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, 3041 /*PredicateIsExpr=*/true, 3042 ControllingExpr, Types, Exprs); 3043 } 3044 3045 /// Build a new generic selection expression with a type predicate. 3046 /// 3047 /// By default, performs semantic analysis to build the new expression. 3048 /// Subclasses may override this routine to provide different behavior. 3049 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, 3050 SourceLocation DefaultLoc, 3051 SourceLocation RParenLoc, 3052 TypeSourceInfo *ControllingType, 3053 ArrayRef<TypeSourceInfo *> Types, 3054 ArrayRef<Expr *> Exprs) { 3055 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, 3056 /*PredicateIsExpr=*/false, 3057 ControllingType, Types, Exprs); 3058 } 3059 3060 /// Build a new overloaded operator call expression. 3061 /// 3062 /// By default, performs semantic analysis to build the new expression. 3063 /// The semantic analysis provides the behavior of template instantiation, 3064 /// copying with transformations that turn what looks like an overloaded 3065 /// operator call into a use of a builtin operator, performing 3066 /// argument-dependent lookup, etc. Subclasses may override this routine to 3067 /// provide different behavior. 3068 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 3069 SourceLocation OpLoc, 3070 SourceLocation CalleeLoc, 3071 bool RequiresADL, 3072 const UnresolvedSetImpl &Functions, 3073 Expr *First, Expr *Second); 3074 3075 /// Build a new C++ "named" cast expression, such as static_cast or 3076 /// reinterpret_cast. 3077 /// 3078 /// By default, this routine dispatches to one of the more-specific routines 3079 /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 3080 /// Subclasses may override this routine to provide different behavior. 3081 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 3082 Stmt::StmtClass Class, 3083 SourceLocation LAngleLoc, 3084 TypeSourceInfo *TInfo, 3085 SourceLocation RAngleLoc, 3086 SourceLocation LParenLoc, 3087 Expr *SubExpr, 3088 SourceLocation RParenLoc) { 3089 switch (Class) { 3090 case Stmt::CXXStaticCastExprClass: 3091 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 3092 RAngleLoc, LParenLoc, 3093 SubExpr, RParenLoc); 3094 3095 case Stmt::CXXDynamicCastExprClass: 3096 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 3097 RAngleLoc, LParenLoc, 3098 SubExpr, RParenLoc); 3099 3100 case Stmt::CXXReinterpretCastExprClass: 3101 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 3102 RAngleLoc, LParenLoc, 3103 SubExpr, 3104 RParenLoc); 3105 3106 case Stmt::CXXConstCastExprClass: 3107 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 3108 RAngleLoc, LParenLoc, 3109 SubExpr, RParenLoc); 3110 3111 case Stmt::CXXAddrspaceCastExprClass: 3112 return getDerived().RebuildCXXAddrspaceCastExpr( 3113 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc); 3114 3115 default: 3116 llvm_unreachable("Invalid C++ named cast"); 3117 } 3118 } 3119 3120 /// Build a new C++ static_cast expression. 3121 /// 3122 /// By default, performs semantic analysis to build the new expression. 3123 /// Subclasses may override this routine to provide different behavior. 3124 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 3125 SourceLocation LAngleLoc, 3126 TypeSourceInfo *TInfo, 3127 SourceLocation RAngleLoc, 3128 SourceLocation LParenLoc, 3129 Expr *SubExpr, 3130 SourceLocation RParenLoc) { 3131 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 3132 TInfo, SubExpr, 3133 SourceRange(LAngleLoc, RAngleLoc), 3134 SourceRange(LParenLoc, RParenLoc)); 3135 } 3136 3137 /// Build a new C++ dynamic_cast expression. 3138 /// 3139 /// By default, performs semantic analysis to build the new expression. 3140 /// Subclasses may override this routine to provide different behavior. 3141 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 3142 SourceLocation LAngleLoc, 3143 TypeSourceInfo *TInfo, 3144 SourceLocation RAngleLoc, 3145 SourceLocation LParenLoc, 3146 Expr *SubExpr, 3147 SourceLocation RParenLoc) { 3148 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 3149 TInfo, SubExpr, 3150 SourceRange(LAngleLoc, RAngleLoc), 3151 SourceRange(LParenLoc, RParenLoc)); 3152 } 3153 3154 /// Build a new C++ reinterpret_cast expression. 3155 /// 3156 /// By default, performs semantic analysis to build the new expression. 3157 /// Subclasses may override this routine to provide different behavior. 3158 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 3159 SourceLocation LAngleLoc, 3160 TypeSourceInfo *TInfo, 3161 SourceLocation RAngleLoc, 3162 SourceLocation LParenLoc, 3163 Expr *SubExpr, 3164 SourceLocation RParenLoc) { 3165 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 3166 TInfo, SubExpr, 3167 SourceRange(LAngleLoc, RAngleLoc), 3168 SourceRange(LParenLoc, RParenLoc)); 3169 } 3170 3171 /// Build a new C++ const_cast expression. 3172 /// 3173 /// By default, performs semantic analysis to build the new expression. 3174 /// Subclasses may override this routine to provide different behavior. 3175 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, 3176 SourceLocation LAngleLoc, 3177 TypeSourceInfo *TInfo, 3178 SourceLocation RAngleLoc, 3179 SourceLocation LParenLoc, 3180 Expr *SubExpr, 3181 SourceLocation RParenLoc) { 3182 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 3183 TInfo, SubExpr, 3184 SourceRange(LAngleLoc, RAngleLoc), 3185 SourceRange(LParenLoc, RParenLoc)); 3186 } 3187 3188 ExprResult 3189 RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, 3190 TypeSourceInfo *TInfo, SourceLocation RAngleLoc, 3191 SourceLocation LParenLoc, Expr *SubExpr, 3192 SourceLocation RParenLoc) { 3193 return getSema().BuildCXXNamedCast( 3194 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr, 3195 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc)); 3196 } 3197 3198 /// Build a new C++ functional-style cast expression. 3199 /// 3200 /// By default, performs semantic analysis to build the new expression. 3201 /// Subclasses may override this routine to provide different behavior. 3202 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 3203 SourceLocation LParenLoc, 3204 Expr *Sub, 3205 SourceLocation RParenLoc, 3206 bool ListInitialization) { 3207 // If Sub is a ParenListExpr, then Sub is the syntatic form of a 3208 // CXXParenListInitExpr. Pass its expanded arguments so that the 3209 // CXXParenListInitExpr can be rebuilt. 3210 if (auto *PLE = dyn_cast<ParenListExpr>(Sub)) 3211 return getSema().BuildCXXTypeConstructExpr( 3212 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()), 3213 RParenLoc, ListInitialization); 3214 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 3215 MultiExprArg(&Sub, 1), RParenLoc, 3216 ListInitialization); 3217 } 3218 3219 /// Build a new C++ __builtin_bit_cast expression. 3220 /// 3221 /// By default, performs semantic analysis to build the new expression. 3222 /// Subclasses may override this routine to provide different behavior. 3223 ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, 3224 TypeSourceInfo *TSI, Expr *Sub, 3225 SourceLocation RParenLoc) { 3226 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc); 3227 } 3228 3229 /// Build a new C++ typeid(type) expression. 3230 /// 3231 /// By default, performs semantic analysis to build the new expression. 3232 /// Subclasses may override this routine to provide different behavior. 3233 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 3234 SourceLocation TypeidLoc, 3235 TypeSourceInfo *Operand, 3236 SourceLocation RParenLoc) { 3237 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 3238 RParenLoc); 3239 } 3240 3241 3242 /// Build a new C++ typeid(expr) expression. 3243 /// 3244 /// By default, performs semantic analysis to build the new expression. 3245 /// Subclasses may override this routine to provide different behavior. 3246 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 3247 SourceLocation TypeidLoc, 3248 Expr *Operand, 3249 SourceLocation RParenLoc) { 3250 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 3251 RParenLoc); 3252 } 3253 3254 /// Build a new C++ __uuidof(type) expression. 3255 /// 3256 /// By default, performs semantic analysis to build the new expression. 3257 /// Subclasses may override this routine to provide different behavior. 3258 ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, 3259 TypeSourceInfo *Operand, 3260 SourceLocation RParenLoc) { 3261 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc); 3262 } 3263 3264 /// Build a new C++ __uuidof(expr) expression. 3265 /// 3266 /// By default, performs semantic analysis to build the new expression. 3267 /// Subclasses may override this routine to provide different behavior. 3268 ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, 3269 Expr *Operand, SourceLocation RParenLoc) { 3270 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc); 3271 } 3272 3273 /// Build a new C++ "this" expression. 3274 /// 3275 /// By default, builds a new "this" expression without performing any 3276 /// semantic analysis. Subclasses may override this routine to provide 3277 /// different behavior. 3278 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 3279 QualType ThisType, 3280 bool isImplicit) { 3281 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit); 3282 } 3283 3284 /// Build a new C++ throw expression. 3285 /// 3286 /// By default, performs semantic analysis to build the new expression. 3287 /// Subclasses may override this routine to provide different behavior. 3288 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, 3289 bool IsThrownVariableInScope) { 3290 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); 3291 } 3292 3293 /// Build a new C++ default-argument expression. 3294 /// 3295 /// By default, builds a new default-argument expression, which does not 3296 /// require any semantic analysis. Subclasses may override this routine to 3297 /// provide different behavior. 3298 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, 3299 Expr *RewrittenExpr) { 3300 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param, 3301 RewrittenExpr, getSema().CurContext); 3302 } 3303 3304 /// Build a new C++11 default-initialization expression. 3305 /// 3306 /// By default, builds a new default field initialization expression, which 3307 /// does not require any semantic analysis. Subclasses may override this 3308 /// routine to provide different behavior. 3309 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, 3310 FieldDecl *Field) { 3311 return getSema().BuildCXXDefaultInitExpr(Loc, Field); 3312 } 3313 3314 /// Build a new C++ zero-initialization expression. 3315 /// 3316 /// By default, performs semantic analysis to build the new expression. 3317 /// Subclasses may override this routine to provide different behavior. 3318 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 3319 SourceLocation LParenLoc, 3320 SourceLocation RParenLoc) { 3321 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, std::nullopt, 3322 RParenLoc, 3323 /*ListInitialization=*/false); 3324 } 3325 3326 /// Build a new C++ "new" expression. 3327 /// 3328 /// By default, performs semantic analysis to build the new expression. 3329 /// Subclasses may override this routine to provide different behavior. 3330 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, 3331 SourceLocation PlacementLParen, 3332 MultiExprArg PlacementArgs, 3333 SourceLocation PlacementRParen, 3334 SourceRange TypeIdParens, QualType AllocatedType, 3335 TypeSourceInfo *AllocatedTypeInfo, 3336 std::optional<Expr *> ArraySize, 3337 SourceRange DirectInitRange, Expr *Initializer) { 3338 return getSema().BuildCXXNew(StartLoc, UseGlobal, 3339 PlacementLParen, 3340 PlacementArgs, 3341 PlacementRParen, 3342 TypeIdParens, 3343 AllocatedType, 3344 AllocatedTypeInfo, 3345 ArraySize, 3346 DirectInitRange, 3347 Initializer); 3348 } 3349 3350 /// Build a new C++ "delete" expression. 3351 /// 3352 /// By default, performs semantic analysis to build the new expression. 3353 /// Subclasses may override this routine to provide different behavior. 3354 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 3355 bool IsGlobalDelete, 3356 bool IsArrayForm, 3357 Expr *Operand) { 3358 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 3359 Operand); 3360 } 3361 3362 /// Build a new type trait expression. 3363 /// 3364 /// By default, performs semantic analysis to build the new expression. 3365 /// Subclasses may override this routine to provide different behavior. 3366 ExprResult RebuildTypeTrait(TypeTrait Trait, 3367 SourceLocation StartLoc, 3368 ArrayRef<TypeSourceInfo *> Args, 3369 SourceLocation RParenLoc) { 3370 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); 3371 } 3372 3373 /// Build a new array type trait expression. 3374 /// 3375 /// By default, performs semantic analysis to build the new expression. 3376 /// Subclasses may override this routine to provide different behavior. 3377 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, 3378 SourceLocation StartLoc, 3379 TypeSourceInfo *TSInfo, 3380 Expr *DimExpr, 3381 SourceLocation RParenLoc) { 3382 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); 3383 } 3384 3385 /// Build a new expression trait expression. 3386 /// 3387 /// By default, performs semantic analysis to build the new expression. 3388 /// Subclasses may override this routine to provide different behavior. 3389 ExprResult RebuildExpressionTrait(ExpressionTrait Trait, 3390 SourceLocation StartLoc, 3391 Expr *Queried, 3392 SourceLocation RParenLoc) { 3393 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); 3394 } 3395 3396 /// Build a new (previously unresolved) declaration reference 3397 /// expression. 3398 /// 3399 /// By default, performs semantic analysis to build the new expression. 3400 /// Subclasses may override this routine to provide different behavior. 3401 ExprResult RebuildDependentScopeDeclRefExpr( 3402 NestedNameSpecifierLoc QualifierLoc, 3403 SourceLocation TemplateKWLoc, 3404 const DeclarationNameInfo &NameInfo, 3405 const TemplateArgumentListInfo *TemplateArgs, 3406 bool IsAddressOfOperand, 3407 TypeSourceInfo **RecoveryTSI) { 3408 CXXScopeSpec SS; 3409 SS.Adopt(QualifierLoc); 3410 3411 if (TemplateArgs || TemplateKWLoc.isValid()) 3412 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, 3413 TemplateArgs); 3414 3415 return getSema().BuildQualifiedDeclarationNameExpr( 3416 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI); 3417 } 3418 3419 /// Build a new template-id expression. 3420 /// 3421 /// By default, performs semantic analysis to build the new expression. 3422 /// Subclasses may override this routine to provide different behavior. 3423 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 3424 SourceLocation TemplateKWLoc, 3425 LookupResult &R, 3426 bool RequiresADL, 3427 const TemplateArgumentListInfo *TemplateArgs) { 3428 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, 3429 TemplateArgs); 3430 } 3431 3432 /// Build a new object-construction expression. 3433 /// 3434 /// By default, performs semantic analysis to build the new expression. 3435 /// Subclasses may override this routine to provide different behavior. 3436 ExprResult RebuildCXXConstructExpr(QualType T, 3437 SourceLocation Loc, 3438 CXXConstructorDecl *Constructor, 3439 bool IsElidable, 3440 MultiExprArg Args, 3441 bool HadMultipleCandidates, 3442 bool ListInitialization, 3443 bool StdInitListInitialization, 3444 bool RequiresZeroInit, 3445 CXXConstructExpr::ConstructionKind ConstructKind, 3446 SourceRange ParenRange) { 3447 // Reconstruct the constructor we originally found, which might be 3448 // different if this is a call to an inherited constructor. 3449 CXXConstructorDecl *FoundCtor = Constructor; 3450 if (Constructor->isInheritingConstructor()) 3451 FoundCtor = Constructor->getInheritedConstructor().getConstructor(); 3452 3453 SmallVector<Expr *, 8> ConvertedArgs; 3454 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc, 3455 ConvertedArgs)) 3456 return ExprError(); 3457 3458 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, 3459 IsElidable, 3460 ConvertedArgs, 3461 HadMultipleCandidates, 3462 ListInitialization, 3463 StdInitListInitialization, 3464 RequiresZeroInit, ConstructKind, 3465 ParenRange); 3466 } 3467 3468 /// Build a new implicit construction via inherited constructor 3469 /// expression. 3470 ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, 3471 CXXConstructorDecl *Constructor, 3472 bool ConstructsVBase, 3473 bool InheritedFromVBase) { 3474 return new (getSema().Context) CXXInheritedCtorInitExpr( 3475 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase); 3476 } 3477 3478 /// Build a new object-construction expression. 3479 /// 3480 /// By default, performs semantic analysis to build the new expression. 3481 /// Subclasses may override this routine to provide different behavior. 3482 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 3483 SourceLocation LParenOrBraceLoc, 3484 MultiExprArg Args, 3485 SourceLocation RParenOrBraceLoc, 3486 bool ListInitialization) { 3487 return getSema().BuildCXXTypeConstructExpr( 3488 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization); 3489 } 3490 3491 /// Build a new object-construction expression. 3492 /// 3493 /// By default, performs semantic analysis to build the new expression. 3494 /// Subclasses may override this routine to provide different behavior. 3495 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 3496 SourceLocation LParenLoc, 3497 MultiExprArg Args, 3498 SourceLocation RParenLoc, 3499 bool ListInitialization) { 3500 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args, 3501 RParenLoc, ListInitialization); 3502 } 3503 3504 /// Build a new member reference expression. 3505 /// 3506 /// By default, performs semantic analysis to build the new expression. 3507 /// Subclasses may override this routine to provide different behavior. 3508 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 3509 QualType BaseType, 3510 bool IsArrow, 3511 SourceLocation OperatorLoc, 3512 NestedNameSpecifierLoc QualifierLoc, 3513 SourceLocation TemplateKWLoc, 3514 NamedDecl *FirstQualifierInScope, 3515 const DeclarationNameInfo &MemberNameInfo, 3516 const TemplateArgumentListInfo *TemplateArgs) { 3517 CXXScopeSpec SS; 3518 SS.Adopt(QualifierLoc); 3519 3520 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 3521 OperatorLoc, IsArrow, 3522 SS, TemplateKWLoc, 3523 FirstQualifierInScope, 3524 MemberNameInfo, 3525 TemplateArgs, /*S*/nullptr); 3526 } 3527 3528 /// Build a new member reference expression. 3529 /// 3530 /// By default, performs semantic analysis to build the new expression. 3531 /// Subclasses may override this routine to provide different behavior. 3532 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, 3533 SourceLocation OperatorLoc, 3534 bool IsArrow, 3535 NestedNameSpecifierLoc QualifierLoc, 3536 SourceLocation TemplateKWLoc, 3537 NamedDecl *FirstQualifierInScope, 3538 LookupResult &R, 3539 const TemplateArgumentListInfo *TemplateArgs) { 3540 CXXScopeSpec SS; 3541 SS.Adopt(QualifierLoc); 3542 3543 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 3544 OperatorLoc, IsArrow, 3545 SS, TemplateKWLoc, 3546 FirstQualifierInScope, 3547 R, TemplateArgs, /*S*/nullptr); 3548 } 3549 3550 /// Build a new noexcept expression. 3551 /// 3552 /// By default, performs semantic analysis to build the new expression. 3553 /// Subclasses may override this routine to provide different behavior. 3554 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 3555 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 3556 } 3557 3558 /// Build a new expression to compute the length of a parameter pack. 3559 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, 3560 SourceLocation PackLoc, 3561 SourceLocation RParenLoc, 3562 std::optional<unsigned> Length, 3563 ArrayRef<TemplateArgument> PartialArgs) { 3564 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc, 3565 RParenLoc, Length, PartialArgs); 3566 } 3567 3568 /// Build a new expression representing a call to a source location 3569 /// builtin. 3570 /// 3571 /// By default, performs semantic analysis to build the new expression. 3572 /// Subclasses may override this routine to provide different behavior. 3573 ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind, 3574 QualType ResultTy, SourceLocation BuiltinLoc, 3575 SourceLocation RPLoc, 3576 DeclContext *ParentContext) { 3577 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc, 3578 ParentContext); 3579 } 3580 3581 /// Build a new Objective-C boxed expression. 3582 /// 3583 /// By default, performs semantic analysis to build the new expression. 3584 /// Subclasses may override this routine to provide different behavior. 3585 ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, 3586 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, 3587 NamedDecl *FoundDecl, ConceptDecl *NamedConcept, 3588 TemplateArgumentListInfo *TALI) { 3589 CXXScopeSpec SS; 3590 SS.Adopt(NNS); 3591 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc, 3592 ConceptNameInfo, 3593 FoundDecl, 3594 NamedConcept, TALI); 3595 if (Result.isInvalid()) 3596 return ExprError(); 3597 return Result; 3598 } 3599 3600 /// \brief Build a new requires expression. 3601 /// 3602 /// By default, performs semantic analysis to build the new expression. 3603 /// Subclasses may override this routine to provide different behavior. 3604 ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc, 3605 RequiresExprBodyDecl *Body, 3606 ArrayRef<ParmVarDecl *> LocalParameters, 3607 ArrayRef<concepts::Requirement *> Requirements, 3608 SourceLocation ClosingBraceLoc) { 3609 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, 3610 LocalParameters, Requirements, ClosingBraceLoc); 3611 } 3612 3613 concepts::TypeRequirement * 3614 RebuildTypeRequirement( 3615 concepts::Requirement::SubstitutionDiagnostic *SubstDiag) { 3616 return SemaRef.BuildTypeRequirement(SubstDiag); 3617 } 3618 3619 concepts::TypeRequirement *RebuildTypeRequirement(TypeSourceInfo *T) { 3620 return SemaRef.BuildTypeRequirement(T); 3621 } 3622 3623 concepts::ExprRequirement * 3624 RebuildExprRequirement( 3625 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, 3626 SourceLocation NoexceptLoc, 3627 concepts::ExprRequirement::ReturnTypeRequirement Ret) { 3628 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc, 3629 std::move(Ret)); 3630 } 3631 3632 concepts::ExprRequirement * 3633 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, 3634 concepts::ExprRequirement::ReturnTypeRequirement Ret) { 3635 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc, 3636 std::move(Ret)); 3637 } 3638 3639 concepts::NestedRequirement * 3640 RebuildNestedRequirement(StringRef InvalidConstraintEntity, 3641 const ASTConstraintSatisfaction &Satisfaction) { 3642 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity, 3643 Satisfaction); 3644 } 3645 3646 concepts::NestedRequirement *RebuildNestedRequirement(Expr *Constraint) { 3647 return SemaRef.BuildNestedRequirement(Constraint); 3648 } 3649 3650 /// \brief Build a new Objective-C boxed expression. 3651 /// 3652 /// By default, performs semantic analysis to build the new expression. 3653 /// Subclasses may override this routine to provide different behavior. 3654 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { 3655 return getSema().BuildObjCBoxedExpr(SR, ValueExpr); 3656 } 3657 3658 /// Build a new Objective-C array literal. 3659 /// 3660 /// By default, performs semantic analysis to build the new expression. 3661 /// Subclasses may override this routine to provide different behavior. 3662 ExprResult RebuildObjCArrayLiteral(SourceRange Range, 3663 Expr **Elements, unsigned NumElements) { 3664 return getSema().BuildObjCArrayLiteral(Range, 3665 MultiExprArg(Elements, NumElements)); 3666 } 3667 3668 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, 3669 Expr *Base, Expr *Key, 3670 ObjCMethodDecl *getterMethod, 3671 ObjCMethodDecl *setterMethod) { 3672 return getSema().BuildObjCSubscriptExpression(RB, Base, Key, 3673 getterMethod, setterMethod); 3674 } 3675 3676 /// Build a new Objective-C dictionary literal. 3677 /// 3678 /// By default, performs semantic analysis to build the new expression. 3679 /// Subclasses may override this routine to provide different behavior. 3680 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, 3681 MutableArrayRef<ObjCDictionaryElement> Elements) { 3682 return getSema().BuildObjCDictionaryLiteral(Range, Elements); 3683 } 3684 3685 /// Build a new Objective-C \@encode expression. 3686 /// 3687 /// By default, performs semantic analysis to build the new expression. 3688 /// Subclasses may override this routine to provide different behavior. 3689 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 3690 TypeSourceInfo *EncodeTypeInfo, 3691 SourceLocation RParenLoc) { 3692 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); 3693 } 3694 3695 /// Build a new Objective-C class message. 3696 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 3697 Selector Sel, 3698 ArrayRef<SourceLocation> SelectorLocs, 3699 ObjCMethodDecl *Method, 3700 SourceLocation LBracLoc, 3701 MultiExprArg Args, 3702 SourceLocation RBracLoc) { 3703 return SemaRef.BuildClassMessage(ReceiverTypeInfo, 3704 ReceiverTypeInfo->getType(), 3705 /*SuperLoc=*/SourceLocation(), 3706 Sel, Method, LBracLoc, SelectorLocs, 3707 RBracLoc, Args); 3708 } 3709 3710 /// Build a new Objective-C instance message. 3711 ExprResult RebuildObjCMessageExpr(Expr *Receiver, 3712 Selector Sel, 3713 ArrayRef<SourceLocation> SelectorLocs, 3714 ObjCMethodDecl *Method, 3715 SourceLocation LBracLoc, 3716 MultiExprArg Args, 3717 SourceLocation RBracLoc) { 3718 return SemaRef.BuildInstanceMessage(Receiver, 3719 Receiver->getType(), 3720 /*SuperLoc=*/SourceLocation(), 3721 Sel, Method, LBracLoc, SelectorLocs, 3722 RBracLoc, Args); 3723 } 3724 3725 /// Build a new Objective-C instance/class message to 'super'. 3726 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, 3727 Selector Sel, 3728 ArrayRef<SourceLocation> SelectorLocs, 3729 QualType SuperType, 3730 ObjCMethodDecl *Method, 3731 SourceLocation LBracLoc, 3732 MultiExprArg Args, 3733 SourceLocation RBracLoc) { 3734 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr, 3735 SuperType, 3736 SuperLoc, 3737 Sel, Method, LBracLoc, SelectorLocs, 3738 RBracLoc, Args) 3739 : SemaRef.BuildClassMessage(nullptr, 3740 SuperType, 3741 SuperLoc, 3742 Sel, Method, LBracLoc, SelectorLocs, 3743 RBracLoc, Args); 3744 3745 3746 } 3747 3748 /// Build a new Objective-C ivar reference expression. 3749 /// 3750 /// By default, performs semantic analysis to build the new expression. 3751 /// Subclasses may override this routine to provide different behavior. 3752 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 3753 SourceLocation IvarLoc, 3754 bool IsArrow, bool IsFreeIvar) { 3755 CXXScopeSpec SS; 3756 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); 3757 ExprResult Result = getSema().BuildMemberReferenceExpr( 3758 BaseArg, BaseArg->getType(), 3759 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(), 3760 /*FirstQualifierInScope=*/nullptr, NameInfo, 3761 /*TemplateArgs=*/nullptr, 3762 /*S=*/nullptr); 3763 if (IsFreeIvar && Result.isUsable()) 3764 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar); 3765 return Result; 3766 } 3767 3768 /// Build a new Objective-C property reference expression. 3769 /// 3770 /// By default, performs semantic analysis to build the new expression. 3771 /// Subclasses may override this routine to provide different behavior. 3772 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 3773 ObjCPropertyDecl *Property, 3774 SourceLocation PropertyLoc) { 3775 CXXScopeSpec SS; 3776 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); 3777 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), 3778 /*FIXME:*/PropertyLoc, 3779 /*IsArrow=*/false, 3780 SS, SourceLocation(), 3781 /*FirstQualifierInScope=*/nullptr, 3782 NameInfo, 3783 /*TemplateArgs=*/nullptr, 3784 /*S=*/nullptr); 3785 } 3786 3787 /// Build a new Objective-C property reference expression. 3788 /// 3789 /// By default, performs semantic analysis to build the new expression. 3790 /// Subclasses may override this routine to provide different behavior. 3791 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 3792 ObjCMethodDecl *Getter, 3793 ObjCMethodDecl *Setter, 3794 SourceLocation PropertyLoc) { 3795 // Since these expressions can only be value-dependent, we do not 3796 // need to perform semantic analysis again. 3797 return Owned( 3798 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 3799 VK_LValue, OK_ObjCProperty, 3800 PropertyLoc, Base)); 3801 } 3802 3803 /// Build a new Objective-C "isa" expression. 3804 /// 3805 /// By default, performs semantic analysis to build the new expression. 3806 /// Subclasses may override this routine to provide different behavior. 3807 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 3808 SourceLocation OpLoc, bool IsArrow) { 3809 CXXScopeSpec SS; 3810 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc); 3811 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), 3812 OpLoc, IsArrow, 3813 SS, SourceLocation(), 3814 /*FirstQualifierInScope=*/nullptr, 3815 NameInfo, 3816 /*TemplateArgs=*/nullptr, 3817 /*S=*/nullptr); 3818 } 3819 3820 /// Build a new shuffle vector expression. 3821 /// 3822 /// By default, performs semantic analysis to build the new expression. 3823 /// Subclasses may override this routine to provide different behavior. 3824 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 3825 MultiExprArg SubExprs, 3826 SourceLocation RParenLoc) { 3827 // Find the declaration for __builtin_shufflevector 3828 const IdentifierInfo &Name 3829 = SemaRef.Context.Idents.get("__builtin_shufflevector"); 3830 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 3831 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 3832 assert(!Lookup.empty() && "No __builtin_shufflevector?"); 3833 3834 // Build a reference to the __builtin_shufflevector builtin 3835 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); 3836 Expr *Callee = new (SemaRef.Context) 3837 DeclRefExpr(SemaRef.Context, Builtin, false, 3838 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc); 3839 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); 3840 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, 3841 CK_BuiltinFnToFnPtr).get(); 3842 3843 // Build the CallExpr 3844 ExprResult TheCall = CallExpr::Create( 3845 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), 3846 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc, 3847 FPOptionsOverride()); 3848 3849 // Type-check the __builtin_shufflevector expression. 3850 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); 3851 } 3852 3853 /// Build a new convert vector expression. 3854 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, 3855 Expr *SrcExpr, TypeSourceInfo *DstTInfo, 3856 SourceLocation RParenLoc) { 3857 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, 3858 BuiltinLoc, RParenLoc); 3859 } 3860 3861 /// Build a new template argument pack expansion. 3862 /// 3863 /// By default, performs semantic analysis to build a new pack expansion 3864 /// for a template argument. Subclasses may override this routine to provide 3865 /// different behavior. 3866 TemplateArgumentLoc 3867 RebuildPackExpansion(TemplateArgumentLoc Pattern, SourceLocation EllipsisLoc, 3868 std::optional<unsigned> NumExpansions) { 3869 switch (Pattern.getArgument().getKind()) { 3870 case TemplateArgument::Expression: { 3871 ExprResult Result 3872 = getSema().CheckPackExpansion(Pattern.getSourceExpression(), 3873 EllipsisLoc, NumExpansions); 3874 if (Result.isInvalid()) 3875 return TemplateArgumentLoc(); 3876 3877 return TemplateArgumentLoc(Result.get(), Result.get()); 3878 } 3879 3880 case TemplateArgument::Template: 3881 return TemplateArgumentLoc( 3882 SemaRef.Context, 3883 TemplateArgument(Pattern.getArgument().getAsTemplate(), 3884 NumExpansions), 3885 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(), 3886 EllipsisLoc); 3887 3888 case TemplateArgument::Null: 3889 case TemplateArgument::Integral: 3890 case TemplateArgument::Declaration: 3891 case TemplateArgument::Pack: 3892 case TemplateArgument::TemplateExpansion: 3893 case TemplateArgument::NullPtr: 3894 llvm_unreachable("Pack expansion pattern has no parameter packs"); 3895 3896 case TemplateArgument::Type: 3897 if (TypeSourceInfo *Expansion 3898 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 3899 EllipsisLoc, 3900 NumExpansions)) 3901 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 3902 Expansion); 3903 break; 3904 } 3905 3906 return TemplateArgumentLoc(); 3907 } 3908 3909 /// Build a new expression pack expansion. 3910 /// 3911 /// By default, performs semantic analysis to build a new pack expansion 3912 /// for an expression. Subclasses may override this routine to provide 3913 /// different behavior. 3914 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 3915 std::optional<unsigned> NumExpansions) { 3916 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); 3917 } 3918 3919 /// Build a new C++1z fold-expression. 3920 /// 3921 /// By default, performs semantic analysis in order to build a new fold 3922 /// expression. 3923 ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, 3924 SourceLocation LParenLoc, Expr *LHS, 3925 BinaryOperatorKind Operator, 3926 SourceLocation EllipsisLoc, Expr *RHS, 3927 SourceLocation RParenLoc, 3928 std::optional<unsigned> NumExpansions) { 3929 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator, 3930 EllipsisLoc, RHS, RParenLoc, 3931 NumExpansions); 3932 } 3933 3934 /// Build an empty C++1z fold-expression with the given operator. 3935 /// 3936 /// By default, produces the fallback value for the fold-expression, or 3937 /// produce an error if there is no fallback value. 3938 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, 3939 BinaryOperatorKind Operator) { 3940 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); 3941 } 3942 3943 /// Build a new atomic operation expression. 3944 /// 3945 /// By default, performs semantic analysis to build the new expression. 3946 /// Subclasses may override this routine to provide different behavior. 3947 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, 3948 AtomicExpr::AtomicOp Op, 3949 SourceLocation RParenLoc) { 3950 // Use this for all of the locations, since we don't know the difference 3951 // between the call and the expr at this point. 3952 SourceRange Range{BuiltinLoc, RParenLoc}; 3953 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op, 3954 Sema::AtomicArgumentOrder::AST); 3955 } 3956 3957 ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc, 3958 ArrayRef<Expr *> SubExprs, QualType Type) { 3959 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type); 3960 } 3961 3962 private: 3963 TypeLoc TransformTypeInObjectScope(TypeLoc TL, 3964 QualType ObjectType, 3965 NamedDecl *FirstQualifierInScope, 3966 CXXScopeSpec &SS); 3967 3968 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 3969 QualType ObjectType, 3970 NamedDecl *FirstQualifierInScope, 3971 CXXScopeSpec &SS); 3972 3973 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, 3974 NamedDecl *FirstQualifierInScope, 3975 CXXScopeSpec &SS); 3976 3977 QualType TransformDependentNameType(TypeLocBuilder &TLB, 3978 DependentNameTypeLoc TL, 3979 bool DeducibleTSTContext); 3980 }; 3981 3982 template <typename Derived> 3983 StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) { 3984 if (!S) 3985 return S; 3986 3987 switch (S->getStmtClass()) { 3988 case Stmt::NoStmtClass: break; 3989 3990 // Transform individual statement nodes 3991 // Pass SDK into statements that can produce a value 3992 #define STMT(Node, Parent) \ 3993 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 3994 #define VALUESTMT(Node, Parent) \ 3995 case Stmt::Node##Class: \ 3996 return getDerived().Transform##Node(cast<Node>(S), SDK); 3997 #define ABSTRACT_STMT(Node) 3998 #define EXPR(Node, Parent) 3999 #include "clang/AST/StmtNodes.inc" 4000 4001 // Transform expressions by calling TransformExpr. 4002 #define STMT(Node, Parent) 4003 #define ABSTRACT_STMT(Stmt) 4004 #define EXPR(Node, Parent) case Stmt::Node##Class: 4005 #include "clang/AST/StmtNodes.inc" 4006 { 4007 ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 4008 4009 if (SDK == SDK_StmtExprResult) 4010 E = getSema().ActOnStmtExprResult(E); 4011 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded); 4012 } 4013 } 4014 4015 return S; 4016 } 4017 4018 template<typename Derived> 4019 OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { 4020 if (!S) 4021 return S; 4022 4023 switch (S->getClauseKind()) { 4024 default: break; 4025 // Transform individual clause nodes 4026 #define GEN_CLANG_CLAUSE_CLASS 4027 #define CLAUSE_CLASS(Enum, Str, Class) \ 4028 case Enum: \ 4029 return getDerived().Transform##Class(cast<Class>(S)); 4030 #include "llvm/Frontend/OpenMP/OMP.inc" 4031 } 4032 4033 return S; 4034 } 4035 4036 4037 template<typename Derived> 4038 ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 4039 if (!E) 4040 return E; 4041 4042 switch (E->getStmtClass()) { 4043 case Stmt::NoStmtClass: break; 4044 #define STMT(Node, Parent) case Stmt::Node##Class: break; 4045 #define ABSTRACT_STMT(Stmt) 4046 #define EXPR(Node, Parent) \ 4047 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 4048 #include "clang/AST/StmtNodes.inc" 4049 } 4050 4051 return E; 4052 } 4053 4054 template<typename Derived> 4055 ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, 4056 bool NotCopyInit) { 4057 // Initializers are instantiated like expressions, except that various outer 4058 // layers are stripped. 4059 if (!Init) 4060 return Init; 4061 4062 if (auto *FE = dyn_cast<FullExpr>(Init)) 4063 Init = FE->getSubExpr(); 4064 4065 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) { 4066 OpaqueValueExpr *OVE = AIL->getCommonExpr(); 4067 Init = OVE->getSourceExpr(); 4068 } 4069 4070 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) 4071 Init = MTE->getSubExpr(); 4072 4073 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) 4074 Init = Binder->getSubExpr(); 4075 4076 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) 4077 Init = ICE->getSubExprAsWritten(); 4078 4079 if (CXXStdInitializerListExpr *ILE = 4080 dyn_cast<CXXStdInitializerListExpr>(Init)) 4081 return TransformInitializer(ILE->getSubExpr(), NotCopyInit); 4082 4083 // If this is copy-initialization, we only need to reconstruct 4084 // InitListExprs. Other forms of copy-initialization will be a no-op if 4085 // the initializer is already the right type. 4086 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); 4087 if (!NotCopyInit && !(Construct && Construct->isListInitialization())) 4088 return getDerived().TransformExpr(Init); 4089 4090 // Revert value-initialization back to empty parens. 4091 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { 4092 SourceRange Parens = VIE->getSourceRange(); 4093 return getDerived().RebuildParenListExpr(Parens.getBegin(), std::nullopt, 4094 Parens.getEnd()); 4095 } 4096 4097 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. 4098 if (isa<ImplicitValueInitExpr>(Init)) 4099 return getDerived().RebuildParenListExpr(SourceLocation(), std::nullopt, 4100 SourceLocation()); 4101 4102 // Revert initialization by constructor back to a parenthesized or braced list 4103 // of expressions. Any other form of initializer can just be reused directly. 4104 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) 4105 return getDerived().TransformExpr(Init); 4106 4107 // If the initialization implicitly converted an initializer list to a 4108 // std::initializer_list object, unwrap the std::initializer_list too. 4109 if (Construct && Construct->isStdInitListInitialization()) 4110 return TransformInitializer(Construct->getArg(0), NotCopyInit); 4111 4112 // Enter a list-init context if this was list initialization. 4113 EnterExpressionEvaluationContext Context( 4114 getSema(), EnterExpressionEvaluationContext::InitList, 4115 Construct->isListInitialization()); 4116 4117 SmallVector<Expr*, 8> NewArgs; 4118 bool ArgChanged = false; 4119 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), 4120 /*IsCall*/true, NewArgs, &ArgChanged)) 4121 return ExprError(); 4122 4123 // If this was list initialization, revert to syntactic list form. 4124 if (Construct->isListInitialization()) 4125 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs, 4126 Construct->getEndLoc()); 4127 4128 // Build a ParenListExpr to represent anything else. 4129 SourceRange Parens = Construct->getParenOrBraceRange(); 4130 if (Parens.isInvalid()) { 4131 // This was a variable declaration's initialization for which no initializer 4132 // was specified. 4133 assert(NewArgs.empty() && 4134 "no parens or braces but have direct init with arguments?"); 4135 return ExprEmpty(); 4136 } 4137 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, 4138 Parens.getEnd()); 4139 } 4140 4141 template<typename Derived> 4142 bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs, 4143 unsigned NumInputs, 4144 bool IsCall, 4145 SmallVectorImpl<Expr *> &Outputs, 4146 bool *ArgChanged) { 4147 for (unsigned I = 0; I != NumInputs; ++I) { 4148 // If requested, drop call arguments that need to be dropped. 4149 if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 4150 if (ArgChanged) 4151 *ArgChanged = true; 4152 4153 break; 4154 } 4155 4156 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 4157 Expr *Pattern = Expansion->getPattern(); 4158 4159 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 4160 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 4161 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 4162 4163 // Determine whether the set of unexpanded parameter packs can and should 4164 // be expanded. 4165 bool Expand = true; 4166 bool RetainExpansion = false; 4167 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); 4168 std::optional<unsigned> NumExpansions = OrigNumExpansions; 4169 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 4170 Pattern->getSourceRange(), 4171 Unexpanded, 4172 Expand, RetainExpansion, 4173 NumExpansions)) 4174 return true; 4175 4176 if (!Expand) { 4177 // The transform has determined that we should perform a simple 4178 // transformation on the pack expansion, producing another pack 4179 // expansion. 4180 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4181 ExprResult OutPattern = getDerived().TransformExpr(Pattern); 4182 if (OutPattern.isInvalid()) 4183 return true; 4184 4185 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 4186 Expansion->getEllipsisLoc(), 4187 NumExpansions); 4188 if (Out.isInvalid()) 4189 return true; 4190 4191 if (ArgChanged) 4192 *ArgChanged = true; 4193 Outputs.push_back(Out.get()); 4194 continue; 4195 } 4196 4197 // Record right away that the argument was changed. This needs 4198 // to happen even if the array expands to nothing. 4199 if (ArgChanged) *ArgChanged = true; 4200 4201 // The transform has determined that we should perform an elementwise 4202 // expansion of the pattern. Do so. 4203 for (unsigned I = 0; I != *NumExpansions; ++I) { 4204 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 4205 ExprResult Out = getDerived().TransformExpr(Pattern); 4206 if (Out.isInvalid()) 4207 return true; 4208 4209 if (Out.get()->containsUnexpandedParameterPack()) { 4210 Out = getDerived().RebuildPackExpansion( 4211 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); 4212 if (Out.isInvalid()) 4213 return true; 4214 } 4215 4216 Outputs.push_back(Out.get()); 4217 } 4218 4219 // If we're supposed to retain a pack expansion, do so by temporarily 4220 // forgetting the partially-substituted parameter pack. 4221 if (RetainExpansion) { 4222 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 4223 4224 ExprResult Out = getDerived().TransformExpr(Pattern); 4225 if (Out.isInvalid()) 4226 return true; 4227 4228 Out = getDerived().RebuildPackExpansion( 4229 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); 4230 if (Out.isInvalid()) 4231 return true; 4232 4233 Outputs.push_back(Out.get()); 4234 } 4235 4236 continue; 4237 } 4238 4239 ExprResult Result = 4240 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) 4241 : getDerived().TransformExpr(Inputs[I]); 4242 if (Result.isInvalid()) 4243 return true; 4244 4245 if (Result.get() != Inputs[I] && ArgChanged) 4246 *ArgChanged = true; 4247 4248 Outputs.push_back(Result.get()); 4249 } 4250 4251 return false; 4252 } 4253 4254 template <typename Derived> 4255 Sema::ConditionResult TreeTransform<Derived>::TransformCondition( 4256 SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) { 4257 if (Var) { 4258 VarDecl *ConditionVar = cast_or_null<VarDecl>( 4259 getDerived().TransformDefinition(Var->getLocation(), Var)); 4260 4261 if (!ConditionVar) 4262 return Sema::ConditionError(); 4263 4264 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind); 4265 } 4266 4267 if (Expr) { 4268 ExprResult CondExpr = getDerived().TransformExpr(Expr); 4269 4270 if (CondExpr.isInvalid()) 4271 return Sema::ConditionError(); 4272 4273 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind, 4274 /*MissingOK=*/true); 4275 } 4276 4277 return Sema::ConditionResult(); 4278 } 4279 4280 template <typename Derived> 4281 NestedNameSpecifierLoc TreeTransform<Derived>::TransformNestedNameSpecifierLoc( 4282 NestedNameSpecifierLoc NNS, QualType ObjectType, 4283 NamedDecl *FirstQualifierInScope) { 4284 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; 4285 4286 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) { 4287 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; 4288 Qualifier = Qualifier.getPrefix()) 4289 Qualifiers.push_back(Qualifier); 4290 }; 4291 insertNNS(NNS); 4292 4293 CXXScopeSpec SS; 4294 while (!Qualifiers.empty()) { 4295 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); 4296 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); 4297 4298 switch (QNNS->getKind()) { 4299 case NestedNameSpecifier::Identifier: { 4300 Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(), 4301 Q.getLocalBeginLoc(), Q.getLocalEndLoc(), 4302 ObjectType); 4303 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false, 4304 SS, FirstQualifierInScope, false)) 4305 return NestedNameSpecifierLoc(); 4306 break; 4307 } 4308 4309 case NestedNameSpecifier::Namespace: { 4310 NamespaceDecl *NS = 4311 cast_or_null<NamespaceDecl>(getDerived().TransformDecl( 4312 Q.getLocalBeginLoc(), QNNS->getAsNamespace())); 4313 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); 4314 break; 4315 } 4316 4317 case NestedNameSpecifier::NamespaceAlias: { 4318 NamespaceAliasDecl *Alias = 4319 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl( 4320 Q.getLocalBeginLoc(), QNNS->getAsNamespaceAlias())); 4321 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), 4322 Q.getLocalEndLoc()); 4323 break; 4324 } 4325 4326 case NestedNameSpecifier::Global: 4327 // There is no meaningful transformation that one could perform on the 4328 // global scope. 4329 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); 4330 break; 4331 4332 case NestedNameSpecifier::Super: { 4333 CXXRecordDecl *RD = 4334 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 4335 SourceLocation(), QNNS->getAsRecordDecl())); 4336 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); 4337 break; 4338 } 4339 4340 case NestedNameSpecifier::TypeSpecWithTemplate: 4341 case NestedNameSpecifier::TypeSpec: { 4342 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, 4343 FirstQualifierInScope, SS); 4344 4345 if (!TL) 4346 return NestedNameSpecifierLoc(); 4347 4348 QualType T = TL.getType(); 4349 if (T->isDependentType() || T->isRecordType() || 4350 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) { 4351 if (T->isEnumeralType()) 4352 SemaRef.Diag(TL.getBeginLoc(), 4353 diag::warn_cxx98_compat_enum_nested_name_spec); 4354 4355 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) { 4356 SS.Adopt(ETL.getQualifierLoc()); 4357 TL = ETL.getNamedTypeLoc(); 4358 } 4359 SS.Extend(SemaRef.Context, /*FIXME:*/ SourceLocation(), TL, 4360 Q.getLocalEndLoc()); 4361 break; 4362 } 4363 // If the nested-name-specifier is an invalid type def, don't emit an 4364 // error because a previous error should have already been emitted. 4365 TypedefTypeLoc TTL = TL.getAsAdjusted<TypedefTypeLoc>(); 4366 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { 4367 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) 4368 << T << SS.getRange(); 4369 } 4370 return NestedNameSpecifierLoc(); 4371 } 4372 } 4373 4374 // The qualifier-in-scope and object type only apply to the leftmost entity. 4375 FirstQualifierInScope = nullptr; 4376 ObjectType = QualType(); 4377 } 4378 4379 // Don't rebuild the nested-name-specifier if we don't have to. 4380 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && 4381 !getDerived().AlwaysRebuild()) 4382 return NNS; 4383 4384 // If we can re-use the source-location data from the original 4385 // nested-name-specifier, do so. 4386 if (SS.location_size() == NNS.getDataLength() && 4387 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) 4388 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); 4389 4390 // Allocate new nested-name-specifier location information. 4391 return SS.getWithLocInContext(SemaRef.Context); 4392 } 4393 4394 template<typename Derived> 4395 DeclarationNameInfo 4396 TreeTransform<Derived> 4397 ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 4398 DeclarationName Name = NameInfo.getName(); 4399 if (!Name) 4400 return DeclarationNameInfo(); 4401 4402 switch (Name.getNameKind()) { 4403 case DeclarationName::Identifier: 4404 case DeclarationName::ObjCZeroArgSelector: 4405 case DeclarationName::ObjCOneArgSelector: 4406 case DeclarationName::ObjCMultiArgSelector: 4407 case DeclarationName::CXXOperatorName: 4408 case DeclarationName::CXXLiteralOperatorName: 4409 case DeclarationName::CXXUsingDirective: 4410 return NameInfo; 4411 4412 case DeclarationName::CXXDeductionGuideName: { 4413 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate(); 4414 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>( 4415 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate)); 4416 if (!NewTemplate) 4417 return DeclarationNameInfo(); 4418 4419 DeclarationNameInfo NewNameInfo(NameInfo); 4420 NewNameInfo.setName( 4421 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate)); 4422 return NewNameInfo; 4423 } 4424 4425 case DeclarationName::CXXConstructorName: 4426 case DeclarationName::CXXDestructorName: 4427 case DeclarationName::CXXConversionFunctionName: { 4428 TypeSourceInfo *NewTInfo; 4429 CanQualType NewCanTy; 4430 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 4431 NewTInfo = getDerived().TransformType(OldTInfo); 4432 if (!NewTInfo) 4433 return DeclarationNameInfo(); 4434 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 4435 } 4436 else { 4437 NewTInfo = nullptr; 4438 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 4439 QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 4440 if (NewT.isNull()) 4441 return DeclarationNameInfo(); 4442 NewCanTy = SemaRef.Context.getCanonicalType(NewT); 4443 } 4444 4445 DeclarationName NewName 4446 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 4447 NewCanTy); 4448 DeclarationNameInfo NewNameInfo(NameInfo); 4449 NewNameInfo.setName(NewName); 4450 NewNameInfo.setNamedTypeInfo(NewTInfo); 4451 return NewNameInfo; 4452 } 4453 } 4454 4455 llvm_unreachable("Unknown name kind."); 4456 } 4457 4458 template<typename Derived> 4459 TemplateName 4460 TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, 4461 TemplateName Name, 4462 SourceLocation NameLoc, 4463 QualType ObjectType, 4464 NamedDecl *FirstQualifierInScope, 4465 bool AllowInjectedClassName) { 4466 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 4467 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl(); 4468 assert(Template && "qualified template name must refer to a template"); 4469 4470 TemplateDecl *TransTemplate 4471 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 4472 Template)); 4473 if (!TransTemplate) 4474 return TemplateName(); 4475 4476 if (!getDerived().AlwaysRebuild() && 4477 SS.getScopeRep() == QTN->getQualifier() && 4478 TransTemplate == Template) 4479 return Name; 4480 4481 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), 4482 TransTemplate); 4483 } 4484 4485 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 4486 if (SS.getScopeRep()) { 4487 // These apply to the scope specifier, not the template. 4488 ObjectType = QualType(); 4489 FirstQualifierInScope = nullptr; 4490 } 4491 4492 if (!getDerived().AlwaysRebuild() && 4493 SS.getScopeRep() == DTN->getQualifier() && 4494 ObjectType.isNull()) 4495 return Name; 4496 4497 // FIXME: Preserve the location of the "template" keyword. 4498 SourceLocation TemplateKWLoc = NameLoc; 4499 4500 if (DTN->isIdentifier()) { 4501 return getDerived().RebuildTemplateName(SS, 4502 TemplateKWLoc, 4503 *DTN->getIdentifier(), 4504 NameLoc, 4505 ObjectType, 4506 FirstQualifierInScope, 4507 AllowInjectedClassName); 4508 } 4509 4510 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, 4511 DTN->getOperator(), NameLoc, 4512 ObjectType, AllowInjectedClassName); 4513 } 4514 4515 if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 4516 TemplateDecl *TransTemplate 4517 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 4518 Template)); 4519 if (!TransTemplate) 4520 return TemplateName(); 4521 4522 if (!getDerived().AlwaysRebuild() && 4523 TransTemplate == Template) 4524 return Name; 4525 4526 return TemplateName(TransTemplate); 4527 } 4528 4529 if (SubstTemplateTemplateParmPackStorage *SubstPack 4530 = Name.getAsSubstTemplateTemplateParmPack()) { 4531 return getDerived().RebuildTemplateName( 4532 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(), 4533 SubstPack->getIndex(), SubstPack->getFinal()); 4534 } 4535 4536 // These should be getting filtered out before they reach the AST. 4537 llvm_unreachable("overloaded function decl survived to here"); 4538 } 4539 4540 template<typename Derived> 4541 void TreeTransform<Derived>::InventTemplateArgumentLoc( 4542 const TemplateArgument &Arg, 4543 TemplateArgumentLoc &Output) { 4544 Output = getSema().getTrivialTemplateArgumentLoc( 4545 Arg, QualType(), getDerived().getBaseLocation()); 4546 } 4547 4548 template <typename Derived> 4549 bool TreeTransform<Derived>::TransformTemplateArgument( 4550 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, 4551 bool Uneval) { 4552 const TemplateArgument &Arg = Input.getArgument(); 4553 switch (Arg.getKind()) { 4554 case TemplateArgument::Null: 4555 case TemplateArgument::Pack: 4556 llvm_unreachable("Unexpected TemplateArgument"); 4557 4558 case TemplateArgument::Integral: 4559 case TemplateArgument::NullPtr: 4560 case TemplateArgument::Declaration: { 4561 // Transform a resolved template argument straight to a resolved template 4562 // argument. We get here when substituting into an already-substituted 4563 // template type argument during concept satisfaction checking. 4564 QualType T = Arg.getNonTypeTemplateArgumentType(); 4565 QualType NewT = getDerived().TransformType(T); 4566 if (NewT.isNull()) 4567 return true; 4568 4569 ValueDecl *D = Arg.getKind() == TemplateArgument::Declaration 4570 ? Arg.getAsDecl() 4571 : nullptr; 4572 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl( 4573 getDerived().getBaseLocation(), D)) 4574 : nullptr; 4575 if (D && !NewD) 4576 return true; 4577 4578 if (NewT == T && D == NewD) 4579 Output = Input; 4580 else if (Arg.getKind() == TemplateArgument::Integral) 4581 Output = TemplateArgumentLoc( 4582 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT), 4583 TemplateArgumentLocInfo()); 4584 else if (Arg.getKind() == TemplateArgument::NullPtr) 4585 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true), 4586 TemplateArgumentLocInfo()); 4587 else 4588 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT), 4589 TemplateArgumentLocInfo()); 4590 4591 return false; 4592 } 4593 4594 case TemplateArgument::Type: { 4595 TypeSourceInfo *DI = Input.getTypeSourceInfo(); 4596 if (!DI) 4597 DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 4598 4599 DI = getDerived().TransformType(DI); 4600 if (!DI) 4601 return true; 4602 4603 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 4604 return false; 4605 } 4606 4607 case TemplateArgument::Template: { 4608 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); 4609 if (QualifierLoc) { 4610 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); 4611 if (!QualifierLoc) 4612 return true; 4613 } 4614 4615 CXXScopeSpec SS; 4616 SS.Adopt(QualifierLoc); 4617 TemplateName Template = getDerived().TransformTemplateName( 4618 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc()); 4619 if (Template.isNull()) 4620 return true; 4621 4622 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template), 4623 QualifierLoc, Input.getTemplateNameLoc()); 4624 return false; 4625 } 4626 4627 case TemplateArgument::TemplateExpansion: 4628 llvm_unreachable("Caller should expand pack expansions"); 4629 4630 case TemplateArgument::Expression: { 4631 // Template argument expressions are constant expressions. 4632 EnterExpressionEvaluationContext Unevaluated( 4633 getSema(), 4634 Uneval ? Sema::ExpressionEvaluationContext::Unevaluated 4635 : Sema::ExpressionEvaluationContext::ConstantEvaluated, 4636 Sema::ReuseLambdaContextDecl, /*ExprContext=*/ 4637 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); 4638 4639 Expr *InputExpr = Input.getSourceExpression(); 4640 if (!InputExpr) 4641 InputExpr = Input.getArgument().getAsExpr(); 4642 4643 ExprResult E = getDerived().TransformExpr(InputExpr); 4644 E = SemaRef.ActOnConstantExpression(E); 4645 if (E.isInvalid()) 4646 return true; 4647 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); 4648 return false; 4649 } 4650 } 4651 4652 // Work around bogus GCC warning 4653 return true; 4654 } 4655 4656 /// Iterator adaptor that invents template argument location information 4657 /// for each of the template arguments in its underlying iterator. 4658 template<typename Derived, typename InputIterator> 4659 class TemplateArgumentLocInventIterator { 4660 TreeTransform<Derived> &Self; 4661 InputIterator Iter; 4662 4663 public: 4664 typedef TemplateArgumentLoc value_type; 4665 typedef TemplateArgumentLoc reference; 4666 typedef typename std::iterator_traits<InputIterator>::difference_type 4667 difference_type; 4668 typedef std::input_iterator_tag iterator_category; 4669 4670 class pointer { 4671 TemplateArgumentLoc Arg; 4672 4673 public: 4674 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 4675 4676 const TemplateArgumentLoc *operator->() const { return &Arg; } 4677 }; 4678 4679 TemplateArgumentLocInventIterator() { } 4680 4681 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 4682 InputIterator Iter) 4683 : Self(Self), Iter(Iter) { } 4684 4685 TemplateArgumentLocInventIterator &operator++() { 4686 ++Iter; 4687 return *this; 4688 } 4689 4690 TemplateArgumentLocInventIterator operator++(int) { 4691 TemplateArgumentLocInventIterator Old(*this); 4692 ++(*this); 4693 return Old; 4694 } 4695 4696 reference operator*() const { 4697 TemplateArgumentLoc Result; 4698 Self.InventTemplateArgumentLoc(*Iter, Result); 4699 return Result; 4700 } 4701 4702 pointer operator->() const { return pointer(**this); } 4703 4704 friend bool operator==(const TemplateArgumentLocInventIterator &X, 4705 const TemplateArgumentLocInventIterator &Y) { 4706 return X.Iter == Y.Iter; 4707 } 4708 4709 friend bool operator!=(const TemplateArgumentLocInventIterator &X, 4710 const TemplateArgumentLocInventIterator &Y) { 4711 return X.Iter != Y.Iter; 4712 } 4713 }; 4714 4715 template<typename Derived> 4716 template<typename InputIterator> 4717 bool TreeTransform<Derived>::TransformTemplateArguments( 4718 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, 4719 bool Uneval) { 4720 for (; First != Last; ++First) { 4721 TemplateArgumentLoc Out; 4722 TemplateArgumentLoc In = *First; 4723 4724 if (In.getArgument().getKind() == TemplateArgument::Pack) { 4725 // Unpack argument packs, which we translate them into separate 4726 // arguments. 4727 // FIXME: We could do much better if we could guarantee that the 4728 // TemplateArgumentLocInfo for the pack expansion would be usable for 4729 // all of the template arguments in the argument pack. 4730 typedef TemplateArgumentLocInventIterator<Derived, 4731 TemplateArgument::pack_iterator> 4732 PackLocIterator; 4733 if (TransformTemplateArguments(PackLocIterator(*this, 4734 In.getArgument().pack_begin()), 4735 PackLocIterator(*this, 4736 In.getArgument().pack_end()), 4737 Outputs, Uneval)) 4738 return true; 4739 4740 continue; 4741 } 4742 4743 if (In.getArgument().isPackExpansion()) { 4744 // We have a pack expansion, for which we will be substituting into 4745 // the pattern. 4746 SourceLocation Ellipsis; 4747 std::optional<unsigned> OrigNumExpansions; 4748 TemplateArgumentLoc Pattern 4749 = getSema().getTemplateArgumentPackExpansionPattern( 4750 In, Ellipsis, OrigNumExpansions); 4751 4752 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 4753 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 4754 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 4755 4756 // Determine whether the set of unexpanded parameter packs can and should 4757 // be expanded. 4758 bool Expand = true; 4759 bool RetainExpansion = false; 4760 std::optional<unsigned> NumExpansions = OrigNumExpansions; 4761 if (getDerived().TryExpandParameterPacks(Ellipsis, 4762 Pattern.getSourceRange(), 4763 Unexpanded, 4764 Expand, 4765 RetainExpansion, 4766 NumExpansions)) 4767 return true; 4768 4769 if (!Expand) { 4770 // The transform has determined that we should perform a simple 4771 // transformation on the pack expansion, producing another pack 4772 // expansion. 4773 TemplateArgumentLoc OutPattern; 4774 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4775 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval)) 4776 return true; 4777 4778 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, 4779 NumExpansions); 4780 if (Out.getArgument().isNull()) 4781 return true; 4782 4783 Outputs.addArgument(Out); 4784 continue; 4785 } 4786 4787 // The transform has determined that we should perform an elementwise 4788 // expansion of the pattern. Do so. 4789 for (unsigned I = 0; I != *NumExpansions; ++I) { 4790 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 4791 4792 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) 4793 return true; 4794 4795 if (Out.getArgument().containsUnexpandedParameterPack()) { 4796 Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 4797 OrigNumExpansions); 4798 if (Out.getArgument().isNull()) 4799 return true; 4800 } 4801 4802 Outputs.addArgument(Out); 4803 } 4804 4805 // If we're supposed to retain a pack expansion, do so by temporarily 4806 // forgetting the partially-substituted parameter pack. 4807 if (RetainExpansion) { 4808 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 4809 4810 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) 4811 return true; 4812 4813 Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 4814 OrigNumExpansions); 4815 if (Out.getArgument().isNull()) 4816 return true; 4817 4818 Outputs.addArgument(Out); 4819 } 4820 4821 continue; 4822 } 4823 4824 // The simple case: 4825 if (getDerived().TransformTemplateArgument(In, Out, Uneval)) 4826 return true; 4827 4828 Outputs.addArgument(Out); 4829 } 4830 4831 return false; 4832 4833 } 4834 4835 //===----------------------------------------------------------------------===// 4836 // Type transformation 4837 //===----------------------------------------------------------------------===// 4838 4839 template<typename Derived> 4840 QualType TreeTransform<Derived>::TransformType(QualType T) { 4841 if (getDerived().AlreadyTransformed(T)) 4842 return T; 4843 4844 // Temporary workaround. All of these transformations should 4845 // eventually turn into transformations on TypeLocs. 4846 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 4847 getDerived().getBaseLocation()); 4848 4849 TypeSourceInfo *NewDI = getDerived().TransformType(DI); 4850 4851 if (!NewDI) 4852 return QualType(); 4853 4854 return NewDI->getType(); 4855 } 4856 4857 template<typename Derived> 4858 TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 4859 // Refine the base location to the type's location. 4860 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), 4861 getDerived().getBaseEntity()); 4862 if (getDerived().AlreadyTransformed(DI->getType())) 4863 return DI; 4864 4865 TypeLocBuilder TLB; 4866 4867 TypeLoc TL = DI->getTypeLoc(); 4868 TLB.reserve(TL.getFullDataSize()); 4869 4870 QualType Result = getDerived().TransformType(TLB, TL); 4871 if (Result.isNull()) 4872 return nullptr; 4873 4874 return TLB.getTypeSourceInfo(SemaRef.Context, Result); 4875 } 4876 4877 template<typename Derived> 4878 QualType 4879 TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 4880 switch (T.getTypeLocClass()) { 4881 #define ABSTRACT_TYPELOC(CLASS, PARENT) 4882 #define TYPELOC(CLASS, PARENT) \ 4883 case TypeLoc::CLASS: \ 4884 return getDerived().Transform##CLASS##Type(TLB, \ 4885 T.castAs<CLASS##TypeLoc>()); 4886 #include "clang/AST/TypeLocNodes.def" 4887 } 4888 4889 llvm_unreachable("unhandled type loc!"); 4890 } 4891 4892 template<typename Derived> 4893 QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) { 4894 if (!isa<DependentNameType>(T)) 4895 return TransformType(T); 4896 4897 if (getDerived().AlreadyTransformed(T)) 4898 return T; 4899 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 4900 getDerived().getBaseLocation()); 4901 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI); 4902 return NewDI ? NewDI->getType() : QualType(); 4903 } 4904 4905 template<typename Derived> 4906 TypeSourceInfo * 4907 TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) { 4908 if (!isa<DependentNameType>(DI->getType())) 4909 return TransformType(DI); 4910 4911 // Refine the base location to the type's location. 4912 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), 4913 getDerived().getBaseEntity()); 4914 if (getDerived().AlreadyTransformed(DI->getType())) 4915 return DI; 4916 4917 TypeLocBuilder TLB; 4918 4919 TypeLoc TL = DI->getTypeLoc(); 4920 TLB.reserve(TL.getFullDataSize()); 4921 4922 auto QTL = TL.getAs<QualifiedTypeLoc>(); 4923 if (QTL) 4924 TL = QTL.getUnqualifiedLoc(); 4925 4926 auto DNTL = TL.castAs<DependentNameTypeLoc>(); 4927 4928 QualType Result = getDerived().TransformDependentNameType( 4929 TLB, DNTL, /*DeducedTSTContext*/true); 4930 if (Result.isNull()) 4931 return nullptr; 4932 4933 if (QTL) { 4934 Result = getDerived().RebuildQualifiedType(Result, QTL); 4935 if (Result.isNull()) 4936 return nullptr; 4937 TLB.TypeWasModifiedSafely(Result); 4938 } 4939 4940 return TLB.getTypeSourceInfo(SemaRef.Context, Result); 4941 } 4942 4943 template<typename Derived> 4944 QualType 4945 TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 4946 QualifiedTypeLoc T) { 4947 QualType Result; 4948 TypeLoc UnqualTL = T.getUnqualifiedLoc(); 4949 auto SuppressObjCLifetime = 4950 T.getType().getLocalQualifiers().hasObjCLifetime(); 4951 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) { 4952 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP, 4953 SuppressObjCLifetime); 4954 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) { 4955 Result = getDerived().TransformSubstTemplateTypeParmPackType( 4956 TLB, STTP, SuppressObjCLifetime); 4957 } else { 4958 Result = getDerived().TransformType(TLB, UnqualTL); 4959 } 4960 4961 if (Result.isNull()) 4962 return QualType(); 4963 4964 Result = getDerived().RebuildQualifiedType(Result, T); 4965 4966 if (Result.isNull()) 4967 return QualType(); 4968 4969 // RebuildQualifiedType might have updated the type, but not in a way 4970 // that invalidates the TypeLoc. (There's no location information for 4971 // qualifiers.) 4972 TLB.TypeWasModifiedSafely(Result); 4973 4974 return Result; 4975 } 4976 4977 template <typename Derived> 4978 QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T, 4979 QualifiedTypeLoc TL) { 4980 4981 SourceLocation Loc = TL.getBeginLoc(); 4982 Qualifiers Quals = TL.getType().getLocalQualifiers(); 4983 4984 if ((T.getAddressSpace() != LangAS::Default && 4985 Quals.getAddressSpace() != LangAS::Default) && 4986 T.getAddressSpace() != Quals.getAddressSpace()) { 4987 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst) 4988 << TL.getType() << T; 4989 return QualType(); 4990 } 4991 4992 // C++ [dcl.fct]p7: 4993 // [When] adding cv-qualifications on top of the function type [...] the 4994 // cv-qualifiers are ignored. 4995 if (T->isFunctionType()) { 4996 T = SemaRef.getASTContext().getAddrSpaceQualType(T, 4997 Quals.getAddressSpace()); 4998 return T; 4999 } 5000 5001 // C++ [dcl.ref]p1: 5002 // when the cv-qualifiers are introduced through the use of a typedef-name 5003 // or decltype-specifier [...] the cv-qualifiers are ignored. 5004 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be 5005 // applied to a reference type. 5006 if (T->isReferenceType()) { 5007 // The only qualifier that applies to a reference type is restrict. 5008 if (!Quals.hasRestrict()) 5009 return T; 5010 Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); 5011 } 5012 5013 // Suppress Objective-C lifetime qualifiers if they don't make sense for the 5014 // resulting type. 5015 if (Quals.hasObjCLifetime()) { 5016 if (!T->isObjCLifetimeType() && !T->isDependentType()) 5017 Quals.removeObjCLifetime(); 5018 else if (T.getObjCLifetime()) { 5019 // Objective-C ARC: 5020 // A lifetime qualifier applied to a substituted template parameter 5021 // overrides the lifetime qualifier from the template argument. 5022 const AutoType *AutoTy; 5023 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) { 5024 // 'auto' types behave the same way as template parameters. 5025 QualType Deduced = AutoTy->getDeducedType(); 5026 Qualifiers Qs = Deduced.getQualifiers(); 5027 Qs.removeObjCLifetime(); 5028 Deduced = 5029 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs); 5030 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(), 5031 AutoTy->isDependentType(), 5032 /*isPack=*/false, 5033 AutoTy->getTypeConstraintConcept(), 5034 AutoTy->getTypeConstraintArguments()); 5035 } else { 5036 // Otherwise, complain about the addition of a qualifier to an 5037 // already-qualified type. 5038 // FIXME: Why is this check not in Sema::BuildQualifiedType? 5039 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T; 5040 Quals.removeObjCLifetime(); 5041 } 5042 } 5043 } 5044 5045 return SemaRef.BuildQualifiedType(T, Loc, Quals); 5046 } 5047 5048 template<typename Derived> 5049 TypeLoc 5050 TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, 5051 QualType ObjectType, 5052 NamedDecl *UnqualLookup, 5053 CXXScopeSpec &SS) { 5054 if (getDerived().AlreadyTransformed(TL.getType())) 5055 return TL; 5056 5057 TypeSourceInfo *TSI = 5058 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); 5059 if (TSI) 5060 return TSI->getTypeLoc(); 5061 return TypeLoc(); 5062 } 5063 5064 template<typename Derived> 5065 TypeSourceInfo * 5066 TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 5067 QualType ObjectType, 5068 NamedDecl *UnqualLookup, 5069 CXXScopeSpec &SS) { 5070 if (getDerived().AlreadyTransformed(TSInfo->getType())) 5071 return TSInfo; 5072 5073 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, 5074 UnqualLookup, SS); 5075 } 5076 5077 template <typename Derived> 5078 TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( 5079 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, 5080 CXXScopeSpec &SS) { 5081 QualType T = TL.getType(); 5082 assert(!getDerived().AlreadyTransformed(T)); 5083 5084 TypeLocBuilder TLB; 5085 QualType Result; 5086 5087 if (isa<TemplateSpecializationType>(T)) { 5088 TemplateSpecializationTypeLoc SpecTL = 5089 TL.castAs<TemplateSpecializationTypeLoc>(); 5090 5091 TemplateName Template = getDerived().TransformTemplateName( 5092 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(), 5093 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true); 5094 if (Template.isNull()) 5095 return nullptr; 5096 5097 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 5098 Template); 5099 } else if (isa<DependentTemplateSpecializationType>(T)) { 5100 DependentTemplateSpecializationTypeLoc SpecTL = 5101 TL.castAs<DependentTemplateSpecializationTypeLoc>(); 5102 5103 TemplateName Template 5104 = getDerived().RebuildTemplateName(SS, 5105 SpecTL.getTemplateKeywordLoc(), 5106 *SpecTL.getTypePtr()->getIdentifier(), 5107 SpecTL.getTemplateNameLoc(), 5108 ObjectType, UnqualLookup, 5109 /*AllowInjectedClassName*/true); 5110 if (Template.isNull()) 5111 return nullptr; 5112 5113 Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 5114 SpecTL, 5115 Template, 5116 SS); 5117 } else { 5118 // Nothing special needs to be done for these. 5119 Result = getDerived().TransformType(TLB, TL); 5120 } 5121 5122 if (Result.isNull()) 5123 return nullptr; 5124 5125 return TLB.getTypeSourceInfo(SemaRef.Context, Result); 5126 } 5127 5128 template <class TyLoc> static inline 5129 QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 5130 TyLoc NewT = TLB.push<TyLoc>(T.getType()); 5131 NewT.setNameLoc(T.getNameLoc()); 5132 return T.getType(); 5133 } 5134 5135 template<typename Derived> 5136 QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 5137 BuiltinTypeLoc T) { 5138 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 5139 NewT.setBuiltinLoc(T.getBuiltinLoc()); 5140 if (T.needsExtraLocalData()) 5141 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 5142 return T.getType(); 5143 } 5144 5145 template<typename Derived> 5146 QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 5147 ComplexTypeLoc T) { 5148 // FIXME: recurse? 5149 return TransformTypeSpecType(TLB, T); 5150 } 5151 5152 template <typename Derived> 5153 QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, 5154 AdjustedTypeLoc TL) { 5155 // Adjustments applied during transformation are handled elsewhere. 5156 return getDerived().TransformType(TLB, TL.getOriginalLoc()); 5157 } 5158 5159 template<typename Derived> 5160 QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, 5161 DecayedTypeLoc TL) { 5162 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); 5163 if (OriginalType.isNull()) 5164 return QualType(); 5165 5166 QualType Result = TL.getType(); 5167 if (getDerived().AlwaysRebuild() || 5168 OriginalType != TL.getOriginalLoc().getType()) 5169 Result = SemaRef.Context.getDecayedType(OriginalType); 5170 TLB.push<DecayedTypeLoc>(Result); 5171 // Nothing to set for DecayedTypeLoc. 5172 return Result; 5173 } 5174 5175 template<typename Derived> 5176 QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 5177 PointerTypeLoc TL) { 5178 QualType PointeeType 5179 = getDerived().TransformType(TLB, TL.getPointeeLoc()); 5180 if (PointeeType.isNull()) 5181 return QualType(); 5182 5183 QualType Result = TL.getType(); 5184 if (PointeeType->getAs<ObjCObjectType>()) { 5185 // A dependent pointer type 'T *' has is being transformed such 5186 // that an Objective-C class type is being replaced for 'T'. The 5187 // resulting pointer type is an ObjCObjectPointerType, not a 5188 // PointerType. 5189 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 5190 5191 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 5192 NewT.setStarLoc(TL.getStarLoc()); 5193 return Result; 5194 } 5195 5196 if (getDerived().AlwaysRebuild() || 5197 PointeeType != TL.getPointeeLoc().getType()) { 5198 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 5199 if (Result.isNull()) 5200 return QualType(); 5201 } 5202 5203 // Objective-C ARC can add lifetime qualifiers to the type that we're 5204 // pointing to. 5205 TLB.TypeWasModifiedSafely(Result->getPointeeType()); 5206 5207 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 5208 NewT.setSigilLoc(TL.getSigilLoc()); 5209 return Result; 5210 } 5211 5212 template<typename Derived> 5213 QualType 5214 TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 5215 BlockPointerTypeLoc TL) { 5216 QualType PointeeType 5217 = getDerived().TransformType(TLB, TL.getPointeeLoc()); 5218 if (PointeeType.isNull()) 5219 return QualType(); 5220 5221 QualType Result = TL.getType(); 5222 if (getDerived().AlwaysRebuild() || 5223 PointeeType != TL.getPointeeLoc().getType()) { 5224 Result = getDerived().RebuildBlockPointerType(PointeeType, 5225 TL.getSigilLoc()); 5226 if (Result.isNull()) 5227 return QualType(); 5228 } 5229 5230 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 5231 NewT.setSigilLoc(TL.getSigilLoc()); 5232 return Result; 5233 } 5234 5235 /// Transforms a reference type. Note that somewhat paradoxically we 5236 /// don't care whether the type itself is an l-value type or an r-value 5237 /// type; we only care if the type was *written* as an l-value type 5238 /// or an r-value type. 5239 template<typename Derived> 5240 QualType 5241 TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 5242 ReferenceTypeLoc TL) { 5243 const ReferenceType *T = TL.getTypePtr(); 5244 5245 // Note that this works with the pointee-as-written. 5246 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 5247 if (PointeeType.isNull()) 5248 return QualType(); 5249 5250 QualType Result = TL.getType(); 5251 if (getDerived().AlwaysRebuild() || 5252 PointeeType != T->getPointeeTypeAsWritten()) { 5253 Result = getDerived().RebuildReferenceType(PointeeType, 5254 T->isSpelledAsLValue(), 5255 TL.getSigilLoc()); 5256 if (Result.isNull()) 5257 return QualType(); 5258 } 5259 5260 // Objective-C ARC can add lifetime qualifiers to the type that we're 5261 // referring to. 5262 TLB.TypeWasModifiedSafely( 5263 Result->castAs<ReferenceType>()->getPointeeTypeAsWritten()); 5264 5265 // r-value references can be rebuilt as l-value references. 5266 ReferenceTypeLoc NewTL; 5267 if (isa<LValueReferenceType>(Result)) 5268 NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 5269 else 5270 NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 5271 NewTL.setSigilLoc(TL.getSigilLoc()); 5272 5273 return Result; 5274 } 5275 5276 template<typename Derived> 5277 QualType 5278 TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 5279 LValueReferenceTypeLoc TL) { 5280 return TransformReferenceType(TLB, TL); 5281 } 5282 5283 template<typename Derived> 5284 QualType 5285 TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 5286 RValueReferenceTypeLoc TL) { 5287 return TransformReferenceType(TLB, TL); 5288 } 5289 5290 template<typename Derived> 5291 QualType 5292 TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 5293 MemberPointerTypeLoc TL) { 5294 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 5295 if (PointeeType.isNull()) 5296 return QualType(); 5297 5298 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); 5299 TypeSourceInfo *NewClsTInfo = nullptr; 5300 if (OldClsTInfo) { 5301 NewClsTInfo = getDerived().TransformType(OldClsTInfo); 5302 if (!NewClsTInfo) 5303 return QualType(); 5304 } 5305 5306 const MemberPointerType *T = TL.getTypePtr(); 5307 QualType OldClsType = QualType(T->getClass(), 0); 5308 QualType NewClsType; 5309 if (NewClsTInfo) 5310 NewClsType = NewClsTInfo->getType(); 5311 else { 5312 NewClsType = getDerived().TransformType(OldClsType); 5313 if (NewClsType.isNull()) 5314 return QualType(); 5315 } 5316 5317 QualType Result = TL.getType(); 5318 if (getDerived().AlwaysRebuild() || 5319 PointeeType != T->getPointeeType() || 5320 NewClsType != OldClsType) { 5321 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, 5322 TL.getStarLoc()); 5323 if (Result.isNull()) 5324 return QualType(); 5325 } 5326 5327 // If we had to adjust the pointee type when building a member pointer, make 5328 // sure to push TypeLoc info for it. 5329 const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); 5330 if (MPT && PointeeType != MPT->getPointeeType()) { 5331 assert(isa<AdjustedType>(MPT->getPointeeType())); 5332 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); 5333 } 5334 5335 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 5336 NewTL.setSigilLoc(TL.getSigilLoc()); 5337 NewTL.setClassTInfo(NewClsTInfo); 5338 5339 return Result; 5340 } 5341 5342 template<typename Derived> 5343 QualType 5344 TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 5345 ConstantArrayTypeLoc TL) { 5346 const ConstantArrayType *T = TL.getTypePtr(); 5347 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 5348 if (ElementType.isNull()) 5349 return QualType(); 5350 5351 // Prefer the expression from the TypeLoc; the other may have been uniqued. 5352 Expr *OldSize = TL.getSizeExpr(); 5353 if (!OldSize) 5354 OldSize = const_cast<Expr*>(T->getSizeExpr()); 5355 Expr *NewSize = nullptr; 5356 if (OldSize) { 5357 EnterExpressionEvaluationContext Unevaluated( 5358 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 5359 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>(); 5360 NewSize = SemaRef.ActOnConstantExpression(NewSize).get(); 5361 } 5362 5363 QualType Result = TL.getType(); 5364 if (getDerived().AlwaysRebuild() || 5365 ElementType != T->getElementType() || 5366 (T->getSizeExpr() && NewSize != OldSize)) { 5367 Result = getDerived().RebuildConstantArrayType(ElementType, 5368 T->getSizeModifier(), 5369 T->getSize(), NewSize, 5370 T->getIndexTypeCVRQualifiers(), 5371 TL.getBracketsRange()); 5372 if (Result.isNull()) 5373 return QualType(); 5374 } 5375 5376 // We might have either a ConstantArrayType or a VariableArrayType now: 5377 // a ConstantArrayType is allowed to have an element type which is a 5378 // VariableArrayType if the type is dependent. Fortunately, all array 5379 // types have the same location layout. 5380 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 5381 NewTL.setLBracketLoc(TL.getLBracketLoc()); 5382 NewTL.setRBracketLoc(TL.getRBracketLoc()); 5383 NewTL.setSizeExpr(NewSize); 5384 5385 return Result; 5386 } 5387 5388 template<typename Derived> 5389 QualType TreeTransform<Derived>::TransformIncompleteArrayType( 5390 TypeLocBuilder &TLB, 5391 IncompleteArrayTypeLoc TL) { 5392 const IncompleteArrayType *T = TL.getTypePtr(); 5393 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 5394 if (ElementType.isNull()) 5395 return QualType(); 5396 5397 QualType Result = TL.getType(); 5398 if (getDerived().AlwaysRebuild() || 5399 ElementType != T->getElementType()) { 5400 Result = getDerived().RebuildIncompleteArrayType(ElementType, 5401 T->getSizeModifier(), 5402 T->getIndexTypeCVRQualifiers(), 5403 TL.getBracketsRange()); 5404 if (Result.isNull()) 5405 return QualType(); 5406 } 5407 5408 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 5409 NewTL.setLBracketLoc(TL.getLBracketLoc()); 5410 NewTL.setRBracketLoc(TL.getRBracketLoc()); 5411 NewTL.setSizeExpr(nullptr); 5412 5413 return Result; 5414 } 5415 5416 template<typename Derived> 5417 QualType 5418 TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 5419 VariableArrayTypeLoc TL) { 5420 const VariableArrayType *T = TL.getTypePtr(); 5421 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 5422 if (ElementType.isNull()) 5423 return QualType(); 5424 5425 ExprResult SizeResult; 5426 { 5427 EnterExpressionEvaluationContext Context( 5428 SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); 5429 SizeResult = getDerived().TransformExpr(T->getSizeExpr()); 5430 } 5431 if (SizeResult.isInvalid()) 5432 return QualType(); 5433 SizeResult = 5434 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false); 5435 if (SizeResult.isInvalid()) 5436 return QualType(); 5437 5438 Expr *Size = SizeResult.get(); 5439 5440 QualType Result = TL.getType(); 5441 if (getDerived().AlwaysRebuild() || 5442 ElementType != T->getElementType() || 5443 Size != T->getSizeExpr()) { 5444 Result = getDerived().RebuildVariableArrayType(ElementType, 5445 T->getSizeModifier(), 5446 Size, 5447 T->getIndexTypeCVRQualifiers(), 5448 TL.getBracketsRange()); 5449 if (Result.isNull()) 5450 return QualType(); 5451 } 5452 5453 // We might have constant size array now, but fortunately it has the same 5454 // location layout. 5455 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 5456 NewTL.setLBracketLoc(TL.getLBracketLoc()); 5457 NewTL.setRBracketLoc(TL.getRBracketLoc()); 5458 NewTL.setSizeExpr(Size); 5459 5460 return Result; 5461 } 5462 5463 template<typename Derived> 5464 QualType 5465 TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 5466 DependentSizedArrayTypeLoc TL) { 5467 const DependentSizedArrayType *T = TL.getTypePtr(); 5468 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 5469 if (ElementType.isNull()) 5470 return QualType(); 5471 5472 // Array bounds are constant expressions. 5473 EnterExpressionEvaluationContext Unevaluated( 5474 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 5475 5476 // Prefer the expression from the TypeLoc; the other may have been uniqued. 5477 Expr *origSize = TL.getSizeExpr(); 5478 if (!origSize) origSize = T->getSizeExpr(); 5479 5480 ExprResult sizeResult 5481 = getDerived().TransformExpr(origSize); 5482 sizeResult = SemaRef.ActOnConstantExpression(sizeResult); 5483 if (sizeResult.isInvalid()) 5484 return QualType(); 5485 5486 Expr *size = sizeResult.get(); 5487 5488 QualType Result = TL.getType(); 5489 if (getDerived().AlwaysRebuild() || 5490 ElementType != T->getElementType() || 5491 size != origSize) { 5492 Result = getDerived().RebuildDependentSizedArrayType(ElementType, 5493 T->getSizeModifier(), 5494 size, 5495 T->getIndexTypeCVRQualifiers(), 5496 TL.getBracketsRange()); 5497 if (Result.isNull()) 5498 return QualType(); 5499 } 5500 5501 // We might have any sort of array type now, but fortunately they 5502 // all have the same location layout. 5503 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 5504 NewTL.setLBracketLoc(TL.getLBracketLoc()); 5505 NewTL.setRBracketLoc(TL.getRBracketLoc()); 5506 NewTL.setSizeExpr(size); 5507 5508 return Result; 5509 } 5510 5511 template <typename Derived> 5512 QualType TreeTransform<Derived>::TransformDependentVectorType( 5513 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) { 5514 const DependentVectorType *T = TL.getTypePtr(); 5515 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 5516 if (ElementType.isNull()) 5517 return QualType(); 5518 5519 EnterExpressionEvaluationContext Unevaluated( 5520 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 5521 5522 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 5523 Size = SemaRef.ActOnConstantExpression(Size); 5524 if (Size.isInvalid()) 5525 return QualType(); 5526 5527 QualType Result = TL.getType(); 5528 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || 5529 Size.get() != T->getSizeExpr()) { 5530 Result = getDerived().RebuildDependentVectorType( 5531 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind()); 5532 if (Result.isNull()) 5533 return QualType(); 5534 } 5535 5536 // Result might be dependent or not. 5537 if (isa<DependentVectorType>(Result)) { 5538 DependentVectorTypeLoc NewTL = 5539 TLB.push<DependentVectorTypeLoc>(Result); 5540 NewTL.setNameLoc(TL.getNameLoc()); 5541 } else { 5542 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 5543 NewTL.setNameLoc(TL.getNameLoc()); 5544 } 5545 5546 return Result; 5547 } 5548 5549 template<typename Derived> 5550 QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 5551 TypeLocBuilder &TLB, 5552 DependentSizedExtVectorTypeLoc TL) { 5553 const DependentSizedExtVectorType *T = TL.getTypePtr(); 5554 5555 // FIXME: ext vector locs should be nested 5556 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 5557 if (ElementType.isNull()) 5558 return QualType(); 5559 5560 // Vector sizes are constant expressions. 5561 EnterExpressionEvaluationContext Unevaluated( 5562 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 5563 5564 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 5565 Size = SemaRef.ActOnConstantExpression(Size); 5566 if (Size.isInvalid()) 5567 return QualType(); 5568 5569 QualType Result = TL.getType(); 5570 if (getDerived().AlwaysRebuild() || 5571 ElementType != T->getElementType() || 5572 Size.get() != T->getSizeExpr()) { 5573 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 5574 Size.get(), 5575 T->getAttributeLoc()); 5576 if (Result.isNull()) 5577 return QualType(); 5578 } 5579 5580 // Result might be dependent or not. 5581 if (isa<DependentSizedExtVectorType>(Result)) { 5582 DependentSizedExtVectorTypeLoc NewTL 5583 = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 5584 NewTL.setNameLoc(TL.getNameLoc()); 5585 } else { 5586 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 5587 NewTL.setNameLoc(TL.getNameLoc()); 5588 } 5589 5590 return Result; 5591 } 5592 5593 template <typename Derived> 5594 QualType 5595 TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB, 5596 ConstantMatrixTypeLoc TL) { 5597 const ConstantMatrixType *T = TL.getTypePtr(); 5598 QualType ElementType = getDerived().TransformType(T->getElementType()); 5599 if (ElementType.isNull()) 5600 return QualType(); 5601 5602 QualType Result = TL.getType(); 5603 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) { 5604 Result = getDerived().RebuildConstantMatrixType( 5605 ElementType, T->getNumRows(), T->getNumColumns()); 5606 if (Result.isNull()) 5607 return QualType(); 5608 } 5609 5610 ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result); 5611 NewTL.setAttrNameLoc(TL.getAttrNameLoc()); 5612 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 5613 NewTL.setAttrRowOperand(TL.getAttrRowOperand()); 5614 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand()); 5615 5616 return Result; 5617 } 5618 5619 template <typename Derived> 5620 QualType TreeTransform<Derived>::TransformDependentSizedMatrixType( 5621 TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) { 5622 const DependentSizedMatrixType *T = TL.getTypePtr(); 5623 5624 QualType ElementType = getDerived().TransformType(T->getElementType()); 5625 if (ElementType.isNull()) { 5626 return QualType(); 5627 } 5628 5629 // Matrix dimensions are constant expressions. 5630 EnterExpressionEvaluationContext Unevaluated( 5631 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 5632 5633 Expr *origRows = TL.getAttrRowOperand(); 5634 if (!origRows) 5635 origRows = T->getRowExpr(); 5636 Expr *origColumns = TL.getAttrColumnOperand(); 5637 if (!origColumns) 5638 origColumns = T->getColumnExpr(); 5639 5640 ExprResult rowResult = getDerived().TransformExpr(origRows); 5641 rowResult = SemaRef.ActOnConstantExpression(rowResult); 5642 if (rowResult.isInvalid()) 5643 return QualType(); 5644 5645 ExprResult columnResult = getDerived().TransformExpr(origColumns); 5646 columnResult = SemaRef.ActOnConstantExpression(columnResult); 5647 if (columnResult.isInvalid()) 5648 return QualType(); 5649 5650 Expr *rows = rowResult.get(); 5651 Expr *columns = columnResult.get(); 5652 5653 QualType Result = TL.getType(); 5654 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || 5655 rows != origRows || columns != origColumns) { 5656 Result = getDerived().RebuildDependentSizedMatrixType( 5657 ElementType, rows, columns, T->getAttributeLoc()); 5658 5659 if (Result.isNull()) 5660 return QualType(); 5661 } 5662 5663 // We might have any sort of matrix type now, but fortunately they 5664 // all have the same location layout. 5665 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result); 5666 NewTL.setAttrNameLoc(TL.getAttrNameLoc()); 5667 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 5668 NewTL.setAttrRowOperand(rows); 5669 NewTL.setAttrColumnOperand(columns); 5670 return Result; 5671 } 5672 5673 template <typename Derived> 5674 QualType TreeTransform<Derived>::TransformDependentAddressSpaceType( 5675 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) { 5676 const DependentAddressSpaceType *T = TL.getTypePtr(); 5677 5678 QualType pointeeType = getDerived().TransformType(T->getPointeeType()); 5679 5680 if (pointeeType.isNull()) 5681 return QualType(); 5682 5683 // Address spaces are constant expressions. 5684 EnterExpressionEvaluationContext Unevaluated( 5685 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 5686 5687 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr()); 5688 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace); 5689 if (AddrSpace.isInvalid()) 5690 return QualType(); 5691 5692 QualType Result = TL.getType(); 5693 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() || 5694 AddrSpace.get() != T->getAddrSpaceExpr()) { 5695 Result = getDerived().RebuildDependentAddressSpaceType( 5696 pointeeType, AddrSpace.get(), T->getAttributeLoc()); 5697 if (Result.isNull()) 5698 return QualType(); 5699 } 5700 5701 // Result might be dependent or not. 5702 if (isa<DependentAddressSpaceType>(Result)) { 5703 DependentAddressSpaceTypeLoc NewTL = 5704 TLB.push<DependentAddressSpaceTypeLoc>(Result); 5705 5706 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 5707 NewTL.setAttrExprOperand(TL.getAttrExprOperand()); 5708 NewTL.setAttrNameLoc(TL.getAttrNameLoc()); 5709 5710 } else { 5711 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo( 5712 Result, getDerived().getBaseLocation()); 5713 TransformType(TLB, DI->getTypeLoc()); 5714 } 5715 5716 return Result; 5717 } 5718 5719 template <typename Derived> 5720 QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 5721 VectorTypeLoc TL) { 5722 const VectorType *T = TL.getTypePtr(); 5723 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 5724 if (ElementType.isNull()) 5725 return QualType(); 5726 5727 QualType Result = TL.getType(); 5728 if (getDerived().AlwaysRebuild() || 5729 ElementType != T->getElementType()) { 5730 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 5731 T->getVectorKind()); 5732 if (Result.isNull()) 5733 return QualType(); 5734 } 5735 5736 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 5737 NewTL.setNameLoc(TL.getNameLoc()); 5738 5739 return Result; 5740 } 5741 5742 template<typename Derived> 5743 QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 5744 ExtVectorTypeLoc TL) { 5745 const VectorType *T = TL.getTypePtr(); 5746 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 5747 if (ElementType.isNull()) 5748 return QualType(); 5749 5750 QualType Result = TL.getType(); 5751 if (getDerived().AlwaysRebuild() || 5752 ElementType != T->getElementType()) { 5753 Result = getDerived().RebuildExtVectorType(ElementType, 5754 T->getNumElements(), 5755 /*FIXME*/ SourceLocation()); 5756 if (Result.isNull()) 5757 return QualType(); 5758 } 5759 5760 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 5761 NewTL.setNameLoc(TL.getNameLoc()); 5762 5763 return Result; 5764 } 5765 5766 template <typename Derived> 5767 ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( 5768 ParmVarDecl *OldParm, int indexAdjustment, 5769 std::optional<unsigned> NumExpansions, bool ExpectParameterPack) { 5770 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 5771 TypeSourceInfo *NewDI = nullptr; 5772 5773 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { 5774 // If we're substituting into a pack expansion type and we know the 5775 // length we want to expand to, just substitute for the pattern. 5776 TypeLoc OldTL = OldDI->getTypeLoc(); 5777 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); 5778 5779 TypeLocBuilder TLB; 5780 TypeLoc NewTL = OldDI->getTypeLoc(); 5781 TLB.reserve(NewTL.getFullDataSize()); 5782 5783 QualType Result = getDerived().TransformType(TLB, 5784 OldExpansionTL.getPatternLoc()); 5785 if (Result.isNull()) 5786 return nullptr; 5787 5788 Result = RebuildPackExpansionType(Result, 5789 OldExpansionTL.getPatternLoc().getSourceRange(), 5790 OldExpansionTL.getEllipsisLoc(), 5791 NumExpansions); 5792 if (Result.isNull()) 5793 return nullptr; 5794 5795 PackExpansionTypeLoc NewExpansionTL 5796 = TLB.push<PackExpansionTypeLoc>(Result); 5797 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); 5798 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); 5799 } else 5800 NewDI = getDerived().TransformType(OldDI); 5801 if (!NewDI) 5802 return nullptr; 5803 5804 if (NewDI == OldDI && indexAdjustment == 0) 5805 return OldParm; 5806 5807 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, 5808 OldParm->getDeclContext(), 5809 OldParm->getInnerLocStart(), 5810 OldParm->getLocation(), 5811 OldParm->getIdentifier(), 5812 NewDI->getType(), 5813 NewDI, 5814 OldParm->getStorageClass(), 5815 /* DefArg */ nullptr); 5816 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), 5817 OldParm->getFunctionScopeIndex() + indexAdjustment); 5818 transformedLocalDecl(OldParm, {newParm}); 5819 return newParm; 5820 } 5821 5822 template <typename Derived> 5823 bool TreeTransform<Derived>::TransformFunctionTypeParams( 5824 SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, 5825 const QualType *ParamTypes, 5826 const FunctionProtoType::ExtParameterInfo *ParamInfos, 5827 SmallVectorImpl<QualType> &OutParamTypes, 5828 SmallVectorImpl<ParmVarDecl *> *PVars, 5829 Sema::ExtParameterInfoBuilder &PInfos, 5830 unsigned *LastParamTransformed) { 5831 int indexAdjustment = 0; 5832 5833 unsigned NumParams = Params.size(); 5834 for (unsigned i = 0; i != NumParams; ++i) { 5835 if (LastParamTransformed) 5836 *LastParamTransformed = i; 5837 if (ParmVarDecl *OldParm = Params[i]) { 5838 assert(OldParm->getFunctionScopeIndex() == i); 5839 5840 std::optional<unsigned> NumExpansions; 5841 ParmVarDecl *NewParm = nullptr; 5842 if (OldParm->isParameterPack()) { 5843 // We have a function parameter pack that may need to be expanded. 5844 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 5845 5846 // Find the parameter packs that could be expanded. 5847 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); 5848 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); 5849 TypeLoc Pattern = ExpansionTL.getPatternLoc(); 5850 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); 5851 5852 // Determine whether we should expand the parameter packs. 5853 bool ShouldExpand = false; 5854 bool RetainExpansion = false; 5855 std::optional<unsigned> OrigNumExpansions; 5856 if (Unexpanded.size() > 0) { 5857 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions(); 5858 NumExpansions = OrigNumExpansions; 5859 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 5860 Pattern.getSourceRange(), 5861 Unexpanded, 5862 ShouldExpand, 5863 RetainExpansion, 5864 NumExpansions)) { 5865 return true; 5866 } 5867 } else { 5868 #ifndef NDEBUG 5869 const AutoType *AT = 5870 Pattern.getType().getTypePtr()->getContainedAutoType(); 5871 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) && 5872 "Could not find parameter packs or undeduced auto type!"); 5873 #endif 5874 } 5875 5876 if (ShouldExpand) { 5877 // Expand the function parameter pack into multiple, separate 5878 // parameters. 5879 getDerived().ExpandingFunctionParameterPack(OldParm); 5880 for (unsigned I = 0; I != *NumExpansions; ++I) { 5881 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 5882 ParmVarDecl *NewParm 5883 = getDerived().TransformFunctionTypeParam(OldParm, 5884 indexAdjustment++, 5885 OrigNumExpansions, 5886 /*ExpectParameterPack=*/false); 5887 if (!NewParm) 5888 return true; 5889 5890 if (ParamInfos) 5891 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5892 OutParamTypes.push_back(NewParm->getType()); 5893 if (PVars) 5894 PVars->push_back(NewParm); 5895 } 5896 5897 // If we're supposed to retain a pack expansion, do so by temporarily 5898 // forgetting the partially-substituted parameter pack. 5899 if (RetainExpansion) { 5900 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 5901 ParmVarDecl *NewParm 5902 = getDerived().TransformFunctionTypeParam(OldParm, 5903 indexAdjustment++, 5904 OrigNumExpansions, 5905 /*ExpectParameterPack=*/false); 5906 if (!NewParm) 5907 return true; 5908 5909 if (ParamInfos) 5910 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5911 OutParamTypes.push_back(NewParm->getType()); 5912 if (PVars) 5913 PVars->push_back(NewParm); 5914 } 5915 5916 // The next parameter should have the same adjustment as the 5917 // last thing we pushed, but we post-incremented indexAdjustment 5918 // on every push. Also, if we push nothing, the adjustment should 5919 // go down by one. 5920 indexAdjustment--; 5921 5922 // We're done with the pack expansion. 5923 continue; 5924 } 5925 5926 // We'll substitute the parameter now without expanding the pack 5927 // expansion. 5928 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 5929 NewParm = getDerived().TransformFunctionTypeParam(OldParm, 5930 indexAdjustment, 5931 NumExpansions, 5932 /*ExpectParameterPack=*/true); 5933 assert(NewParm->isParameterPack() && 5934 "Parameter pack no longer a parameter pack after " 5935 "transformation."); 5936 } else { 5937 NewParm = getDerived().TransformFunctionTypeParam( 5938 OldParm, indexAdjustment, std::nullopt, 5939 /*ExpectParameterPack=*/false); 5940 } 5941 5942 if (!NewParm) 5943 return true; 5944 5945 if (ParamInfos) 5946 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5947 OutParamTypes.push_back(NewParm->getType()); 5948 if (PVars) 5949 PVars->push_back(NewParm); 5950 continue; 5951 } 5952 5953 // Deal with the possibility that we don't have a parameter 5954 // declaration for this parameter. 5955 assert(ParamTypes); 5956 QualType OldType = ParamTypes[i]; 5957 bool IsPackExpansion = false; 5958 std::optional<unsigned> NumExpansions; 5959 QualType NewType; 5960 if (const PackExpansionType *Expansion 5961 = dyn_cast<PackExpansionType>(OldType)) { 5962 // We have a function parameter pack that may need to be expanded. 5963 QualType Pattern = Expansion->getPattern(); 5964 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 5965 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 5966 5967 // Determine whether we should expand the parameter packs. 5968 bool ShouldExpand = false; 5969 bool RetainExpansion = false; 5970 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), 5971 Unexpanded, 5972 ShouldExpand, 5973 RetainExpansion, 5974 NumExpansions)) { 5975 return true; 5976 } 5977 5978 if (ShouldExpand) { 5979 // Expand the function parameter pack into multiple, separate 5980 // parameters. 5981 for (unsigned I = 0; I != *NumExpansions; ++I) { 5982 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 5983 QualType NewType = getDerived().TransformType(Pattern); 5984 if (NewType.isNull()) 5985 return true; 5986 5987 if (NewType->containsUnexpandedParameterPack()) { 5988 NewType = getSema().getASTContext().getPackExpansionType( 5989 NewType, std::nullopt); 5990 5991 if (NewType.isNull()) 5992 return true; 5993 } 5994 5995 if (ParamInfos) 5996 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 5997 OutParamTypes.push_back(NewType); 5998 if (PVars) 5999 PVars->push_back(nullptr); 6000 } 6001 6002 // We're done with the pack expansion. 6003 continue; 6004 } 6005 6006 // If we're supposed to retain a pack expansion, do so by temporarily 6007 // forgetting the partially-substituted parameter pack. 6008 if (RetainExpansion) { 6009 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 6010 QualType NewType = getDerived().TransformType(Pattern); 6011 if (NewType.isNull()) 6012 return true; 6013 6014 if (ParamInfos) 6015 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 6016 OutParamTypes.push_back(NewType); 6017 if (PVars) 6018 PVars->push_back(nullptr); 6019 } 6020 6021 // We'll substitute the parameter now without expanding the pack 6022 // expansion. 6023 OldType = Expansion->getPattern(); 6024 IsPackExpansion = true; 6025 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 6026 NewType = getDerived().TransformType(OldType); 6027 } else { 6028 NewType = getDerived().TransformType(OldType); 6029 } 6030 6031 if (NewType.isNull()) 6032 return true; 6033 6034 if (IsPackExpansion) 6035 NewType = getSema().Context.getPackExpansionType(NewType, 6036 NumExpansions); 6037 6038 if (ParamInfos) 6039 PInfos.set(OutParamTypes.size(), ParamInfos[i]); 6040 OutParamTypes.push_back(NewType); 6041 if (PVars) 6042 PVars->push_back(nullptr); 6043 } 6044 6045 #ifndef NDEBUG 6046 if (PVars) { 6047 for (unsigned i = 0, e = PVars->size(); i != e; ++i) 6048 if (ParmVarDecl *parm = (*PVars)[i]) 6049 assert(parm->getFunctionScopeIndex() == i); 6050 } 6051 #endif 6052 6053 return false; 6054 } 6055 6056 template<typename Derived> 6057 QualType 6058 TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 6059 FunctionProtoTypeLoc TL) { 6060 SmallVector<QualType, 4> ExceptionStorage; 6061 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. 6062 return getDerived().TransformFunctionProtoType( 6063 TLB, TL, nullptr, Qualifiers(), 6064 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { 6065 return This->getDerived().TransformExceptionSpec( 6066 TL.getBeginLoc(), ESI, ExceptionStorage, Changed); 6067 }); 6068 } 6069 6070 template<typename Derived> template<typename Fn> 6071 QualType TreeTransform<Derived>::TransformFunctionProtoType( 6072 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, 6073 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) { 6074 6075 // Transform the parameters and return type. 6076 // 6077 // We are required to instantiate the params and return type in source order. 6078 // When the function has a trailing return type, we instantiate the 6079 // parameters before the return type, since the return type can then refer 6080 // to the parameters themselves (via decltype, sizeof, etc.). 6081 // 6082 SmallVector<QualType, 4> ParamTypes; 6083 SmallVector<ParmVarDecl*, 4> ParamDecls; 6084 Sema::ExtParameterInfoBuilder ExtParamInfos; 6085 const FunctionProtoType *T = TL.getTypePtr(); 6086 6087 QualType ResultType; 6088 6089 if (T->hasTrailingReturn()) { 6090 if (getDerived().TransformFunctionTypeParams( 6091 TL.getBeginLoc(), TL.getParams(), 6092 TL.getTypePtr()->param_type_begin(), 6093 T->getExtParameterInfosOrNull(), 6094 ParamTypes, &ParamDecls, ExtParamInfos)) 6095 return QualType(); 6096 6097 { 6098 // C++11 [expr.prim.general]p3: 6099 // If a declaration declares a member function or member function 6100 // template of a class X, the expression this is a prvalue of type 6101 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq 6102 // and the end of the function-definition, member-declarator, or 6103 // declarator. 6104 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); 6105 6106 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); 6107 if (ResultType.isNull()) 6108 return QualType(); 6109 } 6110 } 6111 else { 6112 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); 6113 if (ResultType.isNull()) 6114 return QualType(); 6115 6116 if (getDerived().TransformFunctionTypeParams( 6117 TL.getBeginLoc(), TL.getParams(), 6118 TL.getTypePtr()->param_type_begin(), 6119 T->getExtParameterInfosOrNull(), 6120 ParamTypes, &ParamDecls, ExtParamInfos)) 6121 return QualType(); 6122 } 6123 6124 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); 6125 6126 bool EPIChanged = false; 6127 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) 6128 return QualType(); 6129 6130 // Handle extended parameter information. 6131 if (auto NewExtParamInfos = 6132 ExtParamInfos.getPointerOrNull(ParamTypes.size())) { 6133 if (!EPI.ExtParameterInfos || 6134 llvm::ArrayRef(EPI.ExtParameterInfos, TL.getNumParams()) != 6135 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) { 6136 EPIChanged = true; 6137 } 6138 EPI.ExtParameterInfos = NewExtParamInfos; 6139 } else if (EPI.ExtParameterInfos) { 6140 EPIChanged = true; 6141 EPI.ExtParameterInfos = nullptr; 6142 } 6143 6144 QualType Result = TL.getType(); 6145 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || 6146 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) { 6147 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); 6148 if (Result.isNull()) 6149 return QualType(); 6150 } 6151 6152 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 6153 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 6154 NewTL.setLParenLoc(TL.getLParenLoc()); 6155 NewTL.setRParenLoc(TL.getRParenLoc()); 6156 NewTL.setExceptionSpecRange(TL.getExceptionSpecRange()); 6157 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 6158 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) 6159 NewTL.setParam(i, ParamDecls[i]); 6160 6161 return Result; 6162 } 6163 6164 template<typename Derived> 6165 bool TreeTransform<Derived>::TransformExceptionSpec( 6166 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, 6167 SmallVectorImpl<QualType> &Exceptions, bool &Changed) { 6168 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); 6169 6170 // Instantiate a dynamic noexcept expression, if any. 6171 if (isComputedNoexcept(ESI.Type)) { 6172 EnterExpressionEvaluationContext Unevaluated( 6173 getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); 6174 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); 6175 if (NoexceptExpr.isInvalid()) 6176 return true; 6177 6178 ExceptionSpecificationType EST = ESI.Type; 6179 NoexceptExpr = 6180 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST); 6181 if (NoexceptExpr.isInvalid()) 6182 return true; 6183 6184 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type) 6185 Changed = true; 6186 ESI.NoexceptExpr = NoexceptExpr.get(); 6187 ESI.Type = EST; 6188 } 6189 6190 if (ESI.Type != EST_Dynamic) 6191 return false; 6192 6193 // Instantiate a dynamic exception specification's type. 6194 for (QualType T : ESI.Exceptions) { 6195 if (const PackExpansionType *PackExpansion = 6196 T->getAs<PackExpansionType>()) { 6197 Changed = true; 6198 6199 // We have a pack expansion. Instantiate it. 6200 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 6201 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), 6202 Unexpanded); 6203 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 6204 6205 // Determine whether the set of unexpanded parameter packs can and 6206 // should 6207 // be expanded. 6208 bool Expand = false; 6209 bool RetainExpansion = false; 6210 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); 6211 // FIXME: Track the location of the ellipsis (and track source location 6212 // information for the types in the exception specification in general). 6213 if (getDerived().TryExpandParameterPacks( 6214 Loc, SourceRange(), Unexpanded, Expand, 6215 RetainExpansion, NumExpansions)) 6216 return true; 6217 6218 if (!Expand) { 6219 // We can't expand this pack expansion into separate arguments yet; 6220 // just substitute into the pattern and create a new pack expansion 6221 // type. 6222 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 6223 QualType U = getDerived().TransformType(PackExpansion->getPattern()); 6224 if (U.isNull()) 6225 return true; 6226 6227 U = SemaRef.Context.getPackExpansionType(U, NumExpansions); 6228 Exceptions.push_back(U); 6229 continue; 6230 } 6231 6232 // Substitute into the pack expansion pattern for each slice of the 6233 // pack. 6234 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { 6235 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); 6236 6237 QualType U = getDerived().TransformType(PackExpansion->getPattern()); 6238 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) 6239 return true; 6240 6241 Exceptions.push_back(U); 6242 } 6243 } else { 6244 QualType U = getDerived().TransformType(T); 6245 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) 6246 return true; 6247 if (T != U) 6248 Changed = true; 6249 6250 Exceptions.push_back(U); 6251 } 6252 } 6253 6254 ESI.Exceptions = Exceptions; 6255 if (ESI.Exceptions.empty()) 6256 ESI.Type = EST_DynamicNone; 6257 return false; 6258 } 6259 6260 template<typename Derived> 6261 QualType TreeTransform<Derived>::TransformFunctionNoProtoType( 6262 TypeLocBuilder &TLB, 6263 FunctionNoProtoTypeLoc TL) { 6264 const FunctionNoProtoType *T = TL.getTypePtr(); 6265 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); 6266 if (ResultType.isNull()) 6267 return QualType(); 6268 6269 QualType Result = TL.getType(); 6270 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) 6271 Result = getDerived().RebuildFunctionNoProtoType(ResultType); 6272 6273 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 6274 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 6275 NewTL.setLParenLoc(TL.getLParenLoc()); 6276 NewTL.setRParenLoc(TL.getRParenLoc()); 6277 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 6278 6279 return Result; 6280 } 6281 6282 template <typename Derived> 6283 QualType TreeTransform<Derived>::TransformUnresolvedUsingType( 6284 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) { 6285 const UnresolvedUsingType *T = TL.getTypePtr(); 6286 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 6287 if (!D) 6288 return QualType(); 6289 6290 QualType Result = TL.getType(); 6291 if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 6292 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D); 6293 if (Result.isNull()) 6294 return QualType(); 6295 } 6296 6297 // We might get an arbitrary type spec type back. We should at 6298 // least always get a type spec type, though. 6299 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 6300 NewTL.setNameLoc(TL.getNameLoc()); 6301 6302 return Result; 6303 } 6304 6305 template <typename Derived> 6306 QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB, 6307 UsingTypeLoc TL) { 6308 const UsingType *T = TL.getTypePtr(); 6309 6310 auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl( 6311 TL.getLocalSourceRange().getBegin(), T->getFoundDecl())); 6312 if (!Found) 6313 return QualType(); 6314 6315 QualType Underlying = getDerived().TransformType(T->desugar()); 6316 if (Underlying.isNull()) 6317 return QualType(); 6318 6319 QualType Result = TL.getType(); 6320 if (getDerived().AlwaysRebuild() || Found != T->getFoundDecl() || 6321 Underlying != T->getUnderlyingType()) { 6322 Result = getDerived().RebuildUsingType(Found, Underlying); 6323 if (Result.isNull()) 6324 return QualType(); 6325 } 6326 6327 TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc()); 6328 return Result; 6329 } 6330 6331 template<typename Derived> 6332 QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 6333 TypedefTypeLoc TL) { 6334 const TypedefType *T = TL.getTypePtr(); 6335 TypedefNameDecl *Typedef 6336 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), 6337 T->getDecl())); 6338 if (!Typedef) 6339 return QualType(); 6340 6341 QualType Result = TL.getType(); 6342 if (getDerived().AlwaysRebuild() || 6343 Typedef != T->getDecl()) { 6344 Result = getDerived().RebuildTypedefType(Typedef); 6345 if (Result.isNull()) 6346 return QualType(); 6347 } 6348 6349 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 6350 NewTL.setNameLoc(TL.getNameLoc()); 6351 6352 return Result; 6353 } 6354 6355 template<typename Derived> 6356 QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 6357 TypeOfExprTypeLoc TL) { 6358 // typeof expressions are not potentially evaluated contexts 6359 EnterExpressionEvaluationContext Unevaluated( 6360 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, 6361 Sema::ReuseLambdaContextDecl); 6362 6363 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 6364 if (E.isInvalid()) 6365 return QualType(); 6366 6367 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); 6368 if (E.isInvalid()) 6369 return QualType(); 6370 6371 QualType Result = TL.getType(); 6372 TypeOfKind Kind = Result->getAs<TypeOfExprType>()->getKind(); 6373 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) { 6374 Result = 6375 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind); 6376 if (Result.isNull()) 6377 return QualType(); 6378 } 6379 6380 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 6381 NewTL.setTypeofLoc(TL.getTypeofLoc()); 6382 NewTL.setLParenLoc(TL.getLParenLoc()); 6383 NewTL.setRParenLoc(TL.getRParenLoc()); 6384 6385 return Result; 6386 } 6387 6388 template<typename Derived> 6389 QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 6390 TypeOfTypeLoc TL) { 6391 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo(); 6392 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 6393 if (!New_Under_TI) 6394 return QualType(); 6395 6396 QualType Result = TL.getType(); 6397 TypeOfKind Kind = Result->getAs<TypeOfType>()->getKind(); 6398 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 6399 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind); 6400 if (Result.isNull()) 6401 return QualType(); 6402 } 6403 6404 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 6405 NewTL.setTypeofLoc(TL.getTypeofLoc()); 6406 NewTL.setLParenLoc(TL.getLParenLoc()); 6407 NewTL.setRParenLoc(TL.getRParenLoc()); 6408 NewTL.setUnmodifiedTInfo(New_Under_TI); 6409 6410 return Result; 6411 } 6412 6413 template<typename Derived> 6414 QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 6415 DecltypeTypeLoc TL) { 6416 const DecltypeType *T = TL.getTypePtr(); 6417 6418 // decltype expressions are not potentially evaluated contexts 6419 EnterExpressionEvaluationContext Unevaluated( 6420 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, 6421 Sema::ExpressionEvaluationContextRecord::EK_Decltype); 6422 6423 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 6424 if (E.isInvalid()) 6425 return QualType(); 6426 6427 E = getSema().ActOnDecltypeExpression(E.get()); 6428 if (E.isInvalid()) 6429 return QualType(); 6430 6431 QualType Result = TL.getType(); 6432 if (getDerived().AlwaysRebuild() || 6433 E.get() != T->getUnderlyingExpr()) { 6434 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc()); 6435 if (Result.isNull()) 6436 return QualType(); 6437 } 6438 else E.get(); 6439 6440 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 6441 NewTL.setDecltypeLoc(TL.getDecltypeLoc()); 6442 NewTL.setRParenLoc(TL.getRParenLoc()); 6443 return Result; 6444 } 6445 6446 template<typename Derived> 6447 QualType TreeTransform<Derived>::TransformUnaryTransformType( 6448 TypeLocBuilder &TLB, 6449 UnaryTransformTypeLoc TL) { 6450 QualType Result = TL.getType(); 6451 if (Result->isDependentType()) { 6452 const UnaryTransformType *T = TL.getTypePtr(); 6453 QualType NewBase = 6454 getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); 6455 Result = getDerived().RebuildUnaryTransformType(NewBase, 6456 T->getUTTKind(), 6457 TL.getKWLoc()); 6458 if (Result.isNull()) 6459 return QualType(); 6460 } 6461 6462 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); 6463 NewTL.setKWLoc(TL.getKWLoc()); 6464 NewTL.setParensRange(TL.getParensRange()); 6465 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); 6466 return Result; 6467 } 6468 6469 template<typename Derived> 6470 QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType( 6471 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) { 6472 const DeducedTemplateSpecializationType *T = TL.getTypePtr(); 6473 6474 CXXScopeSpec SS; 6475 TemplateName TemplateName = getDerived().TransformTemplateName( 6476 SS, T->getTemplateName(), TL.getTemplateNameLoc()); 6477 if (TemplateName.isNull()) 6478 return QualType(); 6479 6480 QualType OldDeduced = T->getDeducedType(); 6481 QualType NewDeduced; 6482 if (!OldDeduced.isNull()) { 6483 NewDeduced = getDerived().TransformType(OldDeduced); 6484 if (NewDeduced.isNull()) 6485 return QualType(); 6486 } 6487 6488 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType( 6489 TemplateName, NewDeduced); 6490 if (Result.isNull()) 6491 return QualType(); 6492 6493 DeducedTemplateSpecializationTypeLoc NewTL = 6494 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result); 6495 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6496 6497 return Result; 6498 } 6499 6500 template<typename Derived> 6501 QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 6502 RecordTypeLoc TL) { 6503 const RecordType *T = TL.getTypePtr(); 6504 RecordDecl *Record 6505 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 6506 T->getDecl())); 6507 if (!Record) 6508 return QualType(); 6509 6510 QualType Result = TL.getType(); 6511 if (getDerived().AlwaysRebuild() || 6512 Record != T->getDecl()) { 6513 Result = getDerived().RebuildRecordType(Record); 6514 if (Result.isNull()) 6515 return QualType(); 6516 } 6517 6518 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 6519 NewTL.setNameLoc(TL.getNameLoc()); 6520 6521 return Result; 6522 } 6523 6524 template<typename Derived> 6525 QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 6526 EnumTypeLoc TL) { 6527 const EnumType *T = TL.getTypePtr(); 6528 EnumDecl *Enum 6529 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 6530 T->getDecl())); 6531 if (!Enum) 6532 return QualType(); 6533 6534 QualType Result = TL.getType(); 6535 if (getDerived().AlwaysRebuild() || 6536 Enum != T->getDecl()) { 6537 Result = getDerived().RebuildEnumType(Enum); 6538 if (Result.isNull()) 6539 return QualType(); 6540 } 6541 6542 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 6543 NewTL.setNameLoc(TL.getNameLoc()); 6544 6545 return Result; 6546 } 6547 6548 template<typename Derived> 6549 QualType TreeTransform<Derived>::TransformInjectedClassNameType( 6550 TypeLocBuilder &TLB, 6551 InjectedClassNameTypeLoc TL) { 6552 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 6553 TL.getTypePtr()->getDecl()); 6554 if (!D) return QualType(); 6555 6556 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 6557 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 6558 return T; 6559 } 6560 6561 template<typename Derived> 6562 QualType TreeTransform<Derived>::TransformTemplateTypeParmType( 6563 TypeLocBuilder &TLB, 6564 TemplateTypeParmTypeLoc TL) { 6565 return getDerived().TransformTemplateTypeParmType( 6566 TLB, TL, 6567 /*SuppressObjCLifetime=*/false); 6568 } 6569 6570 template <typename Derived> 6571 QualType TreeTransform<Derived>::TransformTemplateTypeParmType( 6572 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) { 6573 return TransformTypeSpecType(TLB, TL); 6574 } 6575 6576 template<typename Derived> 6577 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 6578 TypeLocBuilder &TLB, 6579 SubstTemplateTypeParmTypeLoc TL) { 6580 const SubstTemplateTypeParmType *T = TL.getTypePtr(); 6581 6582 Decl *NewReplaced = 6583 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl()); 6584 6585 // Substitute into the replacement type, which itself might involve something 6586 // that needs to be transformed. This only tends to occur with default 6587 // template arguments of template template parameters. 6588 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); 6589 QualType Replacement = getDerived().TransformType(T->getReplacementType()); 6590 if (Replacement.isNull()) 6591 return QualType(); 6592 6593 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType( 6594 Replacement, NewReplaced, T->getIndex(), T->getPackIndex()); 6595 6596 // Propagate type-source information. 6597 SubstTemplateTypeParmTypeLoc NewTL 6598 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); 6599 NewTL.setNameLoc(TL.getNameLoc()); 6600 return Result; 6601 6602 } 6603 6604 template<typename Derived> 6605 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 6606 TypeLocBuilder &TLB, 6607 SubstTemplateTypeParmPackTypeLoc TL) { 6608 return getDerived().TransformSubstTemplateTypeParmPackType( 6609 TLB, TL, /*SuppressObjCLifetime=*/false); 6610 } 6611 6612 template <typename Derived> 6613 QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 6614 TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL, bool) { 6615 return TransformTypeSpecType(TLB, TL); 6616 } 6617 6618 template<typename Derived> 6619 QualType TreeTransform<Derived>::TransformTemplateSpecializationType( 6620 TypeLocBuilder &TLB, 6621 TemplateSpecializationTypeLoc TL) { 6622 const TemplateSpecializationType *T = TL.getTypePtr(); 6623 6624 // The nested-name-specifier never matters in a TemplateSpecializationType, 6625 // because we can't have a dependent nested-name-specifier anyway. 6626 CXXScopeSpec SS; 6627 TemplateName Template 6628 = getDerived().TransformTemplateName(SS, T->getTemplateName(), 6629 TL.getTemplateNameLoc()); 6630 if (Template.isNull()) 6631 return QualType(); 6632 6633 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 6634 } 6635 6636 template<typename Derived> 6637 QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, 6638 AtomicTypeLoc TL) { 6639 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); 6640 if (ValueType.isNull()) 6641 return QualType(); 6642 6643 QualType Result = TL.getType(); 6644 if (getDerived().AlwaysRebuild() || 6645 ValueType != TL.getValueLoc().getType()) { 6646 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); 6647 if (Result.isNull()) 6648 return QualType(); 6649 } 6650 6651 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); 6652 NewTL.setKWLoc(TL.getKWLoc()); 6653 NewTL.setLParenLoc(TL.getLParenLoc()); 6654 NewTL.setRParenLoc(TL.getRParenLoc()); 6655 6656 return Result; 6657 } 6658 6659 template <typename Derived> 6660 QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB, 6661 PipeTypeLoc TL) { 6662 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); 6663 if (ValueType.isNull()) 6664 return QualType(); 6665 6666 QualType Result = TL.getType(); 6667 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) { 6668 const PipeType *PT = Result->castAs<PipeType>(); 6669 bool isReadPipe = PT->isReadOnly(); 6670 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe); 6671 if (Result.isNull()) 6672 return QualType(); 6673 } 6674 6675 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result); 6676 NewTL.setKWLoc(TL.getKWLoc()); 6677 6678 return Result; 6679 } 6680 6681 template <typename Derived> 6682 QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB, 6683 BitIntTypeLoc TL) { 6684 const BitIntType *EIT = TL.getTypePtr(); 6685 QualType Result = TL.getType(); 6686 6687 if (getDerived().AlwaysRebuild()) { 6688 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(), 6689 EIT->getNumBits(), TL.getNameLoc()); 6690 if (Result.isNull()) 6691 return QualType(); 6692 } 6693 6694 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result); 6695 NewTL.setNameLoc(TL.getNameLoc()); 6696 return Result; 6697 } 6698 6699 template <typename Derived> 6700 QualType TreeTransform<Derived>::TransformDependentBitIntType( 6701 TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) { 6702 const DependentBitIntType *EIT = TL.getTypePtr(); 6703 6704 EnterExpressionEvaluationContext Unevaluated( 6705 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 6706 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr()); 6707 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr); 6708 6709 if (BitsExpr.isInvalid()) 6710 return QualType(); 6711 6712 QualType Result = TL.getType(); 6713 6714 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) { 6715 Result = getDerived().RebuildDependentBitIntType( 6716 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc()); 6717 6718 if (Result.isNull()) 6719 return QualType(); 6720 } 6721 6722 if (isa<DependentBitIntType>(Result)) { 6723 DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result); 6724 NewTL.setNameLoc(TL.getNameLoc()); 6725 } else { 6726 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result); 6727 NewTL.setNameLoc(TL.getNameLoc()); 6728 } 6729 return Result; 6730 } 6731 6732 /// Simple iterator that traverses the template arguments in a 6733 /// container that provides a \c getArgLoc() member function. 6734 /// 6735 /// This iterator is intended to be used with the iterator form of 6736 /// \c TreeTransform<Derived>::TransformTemplateArguments(). 6737 template<typename ArgLocContainer> 6738 class TemplateArgumentLocContainerIterator { 6739 ArgLocContainer *Container; 6740 unsigned Index; 6741 6742 public: 6743 typedef TemplateArgumentLoc value_type; 6744 typedef TemplateArgumentLoc reference; 6745 typedef int difference_type; 6746 typedef std::input_iterator_tag iterator_category; 6747 6748 class pointer { 6749 TemplateArgumentLoc Arg; 6750 6751 public: 6752 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 6753 6754 const TemplateArgumentLoc *operator->() const { 6755 return &Arg; 6756 } 6757 }; 6758 6759 6760 TemplateArgumentLocContainerIterator() {} 6761 6762 TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 6763 unsigned Index) 6764 : Container(&Container), Index(Index) { } 6765 6766 TemplateArgumentLocContainerIterator &operator++() { 6767 ++Index; 6768 return *this; 6769 } 6770 6771 TemplateArgumentLocContainerIterator operator++(int) { 6772 TemplateArgumentLocContainerIterator Old(*this); 6773 ++(*this); 6774 return Old; 6775 } 6776 6777 TemplateArgumentLoc operator*() const { 6778 return Container->getArgLoc(Index); 6779 } 6780 6781 pointer operator->() const { 6782 return pointer(Container->getArgLoc(Index)); 6783 } 6784 6785 friend bool operator==(const TemplateArgumentLocContainerIterator &X, 6786 const TemplateArgumentLocContainerIterator &Y) { 6787 return X.Container == Y.Container && X.Index == Y.Index; 6788 } 6789 6790 friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 6791 const TemplateArgumentLocContainerIterator &Y) { 6792 return !(X == Y); 6793 } 6794 }; 6795 6796 template<typename Derived> 6797 QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, 6798 AutoTypeLoc TL) { 6799 const AutoType *T = TL.getTypePtr(); 6800 QualType OldDeduced = T->getDeducedType(); 6801 QualType NewDeduced; 6802 if (!OldDeduced.isNull()) { 6803 NewDeduced = getDerived().TransformType(OldDeduced); 6804 if (NewDeduced.isNull()) 6805 return QualType(); 6806 } 6807 6808 ConceptDecl *NewCD = nullptr; 6809 TemplateArgumentListInfo NewTemplateArgs; 6810 NestedNameSpecifierLoc NewNestedNameSpec; 6811 if (T->isConstrained()) { 6812 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl( 6813 TL.getConceptNameLoc(), T->getTypeConstraintConcept())); 6814 6815 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 6816 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 6817 typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator; 6818 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 6819 ArgIterator(TL, 6820 TL.getNumArgs()), 6821 NewTemplateArgs)) 6822 return QualType(); 6823 6824 if (TL.getNestedNameSpecifierLoc()) { 6825 NewNestedNameSpec 6826 = getDerived().TransformNestedNameSpecifierLoc( 6827 TL.getNestedNameSpecifierLoc()); 6828 if (!NewNestedNameSpec) 6829 return QualType(); 6830 } 6831 } 6832 6833 QualType Result = TL.getType(); 6834 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || 6835 T->isDependentType() || T->isConstrained()) { 6836 // FIXME: Maybe don't rebuild if all template arguments are the same. 6837 llvm::SmallVector<TemplateArgument, 4> NewArgList; 6838 NewArgList.reserve(NewTemplateArgs.size()); 6839 for (const auto &ArgLoc : NewTemplateArgs.arguments()) 6840 NewArgList.push_back(ArgLoc.getArgument()); 6841 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD, 6842 NewArgList); 6843 if (Result.isNull()) 6844 return QualType(); 6845 } 6846 6847 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); 6848 NewTL.setNameLoc(TL.getNameLoc()); 6849 NewTL.setNestedNameSpecifierLoc(NewNestedNameSpec); 6850 NewTL.setTemplateKWLoc(TL.getTemplateKWLoc()); 6851 NewTL.setConceptNameLoc(TL.getConceptNameLoc()); 6852 NewTL.setFoundDecl(TL.getFoundDecl()); 6853 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6854 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6855 NewTL.setRParenLoc(TL.getRParenLoc()); 6856 for (unsigned I = 0; I < NewTL.getNumArgs(); ++I) 6857 NewTL.setArgLocInfo(I, NewTemplateArgs.arguments()[I].getLocInfo()); 6858 6859 return Result; 6860 } 6861 6862 template <typename Derived> 6863 QualType TreeTransform<Derived>::TransformTemplateSpecializationType( 6864 TypeLocBuilder &TLB, 6865 TemplateSpecializationTypeLoc TL, 6866 TemplateName Template) { 6867 TemplateArgumentListInfo NewTemplateArgs; 6868 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 6869 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 6870 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 6871 ArgIterator; 6872 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 6873 ArgIterator(TL, TL.getNumArgs()), 6874 NewTemplateArgs)) 6875 return QualType(); 6876 6877 // FIXME: maybe don't rebuild if all the template arguments are the same. 6878 6879 QualType Result = 6880 getDerived().RebuildTemplateSpecializationType(Template, 6881 TL.getTemplateNameLoc(), 6882 NewTemplateArgs); 6883 6884 if (!Result.isNull()) { 6885 // Specializations of template template parameters are represented as 6886 // TemplateSpecializationTypes, and substitution of type alias templates 6887 // within a dependent context can transform them into 6888 // DependentTemplateSpecializationTypes. 6889 if (isa<DependentTemplateSpecializationType>(Result)) { 6890 DependentTemplateSpecializationTypeLoc NewTL 6891 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 6892 NewTL.setElaboratedKeywordLoc(SourceLocation()); 6893 NewTL.setQualifierLoc(NestedNameSpecifierLoc()); 6894 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6895 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6896 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6897 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6898 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 6899 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 6900 return Result; 6901 } 6902 6903 TemplateSpecializationTypeLoc NewTL 6904 = TLB.push<TemplateSpecializationTypeLoc>(Result); 6905 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6906 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6907 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6908 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6909 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 6910 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 6911 } 6912 6913 return Result; 6914 } 6915 6916 template <typename Derived> 6917 QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( 6918 TypeLocBuilder &TLB, 6919 DependentTemplateSpecializationTypeLoc TL, 6920 TemplateName Template, 6921 CXXScopeSpec &SS) { 6922 TemplateArgumentListInfo NewTemplateArgs; 6923 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 6924 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 6925 typedef TemplateArgumentLocContainerIterator< 6926 DependentTemplateSpecializationTypeLoc> ArgIterator; 6927 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 6928 ArgIterator(TL, TL.getNumArgs()), 6929 NewTemplateArgs)) 6930 return QualType(); 6931 6932 // FIXME: maybe don't rebuild if all the template arguments are the same. 6933 6934 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { 6935 QualType Result = getSema().Context.getDependentTemplateSpecializationType( 6936 TL.getTypePtr()->getKeyword(), DTN->getQualifier(), 6937 DTN->getIdentifier(), NewTemplateArgs.arguments()); 6938 6939 DependentTemplateSpecializationTypeLoc NewTL 6940 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 6941 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 6942 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); 6943 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6944 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6945 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6946 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6947 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 6948 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 6949 return Result; 6950 } 6951 6952 QualType Result 6953 = getDerived().RebuildTemplateSpecializationType(Template, 6954 TL.getTemplateNameLoc(), 6955 NewTemplateArgs); 6956 6957 if (!Result.isNull()) { 6958 /// FIXME: Wrap this in an elaborated-type-specifier? 6959 TemplateSpecializationTypeLoc NewTL 6960 = TLB.push<TemplateSpecializationTypeLoc>(Result); 6961 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 6962 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 6963 NewTL.setLAngleLoc(TL.getLAngleLoc()); 6964 NewTL.setRAngleLoc(TL.getRAngleLoc()); 6965 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 6966 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 6967 } 6968 6969 return Result; 6970 } 6971 6972 template<typename Derived> 6973 QualType 6974 TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 6975 ElaboratedTypeLoc TL) { 6976 const ElaboratedType *T = TL.getTypePtr(); 6977 6978 NestedNameSpecifierLoc QualifierLoc; 6979 // NOTE: the qualifier in an ElaboratedType is optional. 6980 if (TL.getQualifierLoc()) { 6981 QualifierLoc 6982 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 6983 if (!QualifierLoc) 6984 return QualType(); 6985 } 6986 6987 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 6988 if (NamedT.isNull()) 6989 return QualType(); 6990 6991 // C++0x [dcl.type.elab]p2: 6992 // If the identifier resolves to a typedef-name or the simple-template-id 6993 // resolves to an alias template specialization, the 6994 // elaborated-type-specifier is ill-formed. 6995 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { 6996 if (const TemplateSpecializationType *TST = 6997 NamedT->getAs<TemplateSpecializationType>()) { 6998 TemplateName Template = TST->getTemplateName(); 6999 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( 7000 Template.getAsTemplateDecl())) { 7001 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), 7002 diag::err_tag_reference_non_tag) 7003 << TAT << Sema::NTK_TypeAliasTemplate 7004 << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword()); 7005 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); 7006 } 7007 } 7008 } 7009 7010 QualType Result = TL.getType(); 7011 if (getDerived().AlwaysRebuild() || 7012 QualifierLoc != TL.getQualifierLoc() || 7013 NamedT != T->getNamedType()) { 7014 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), 7015 T->getKeyword(), 7016 QualifierLoc, NamedT); 7017 if (Result.isNull()) 7018 return QualType(); 7019 } 7020 7021 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 7022 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 7023 NewTL.setQualifierLoc(QualifierLoc); 7024 return Result; 7025 } 7026 7027 template<typename Derived> 7028 QualType TreeTransform<Derived>::TransformAttributedType( 7029 TypeLocBuilder &TLB, 7030 AttributedTypeLoc TL) { 7031 const AttributedType *oldType = TL.getTypePtr(); 7032 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); 7033 if (modifiedType.isNull()) 7034 return QualType(); 7035 7036 // oldAttr can be null if we started with a QualType rather than a TypeLoc. 7037 const Attr *oldAttr = TL.getAttr(); 7038 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr; 7039 if (oldAttr && !newAttr) 7040 return QualType(); 7041 7042 QualType result = TL.getType(); 7043 7044 // FIXME: dependent operand expressions? 7045 if (getDerived().AlwaysRebuild() || 7046 modifiedType != oldType->getModifiedType()) { 7047 // TODO: this is really lame; we should really be rebuilding the 7048 // equivalent type from first principles. 7049 QualType equivalentType 7050 = getDerived().TransformType(oldType->getEquivalentType()); 7051 if (equivalentType.isNull()) 7052 return QualType(); 7053 7054 // Check whether we can add nullability; it is only represented as 7055 // type sugar, and therefore cannot be diagnosed in any other way. 7056 if (auto nullability = oldType->getImmediateNullability()) { 7057 if (!modifiedType->canHaveNullability()) { 7058 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation() 7059 : TL.getModifiedLoc().getBeginLoc()), 7060 diag::err_nullability_nonpointer) 7061 << DiagNullabilityKind(*nullability, false) << modifiedType; 7062 return QualType(); 7063 } 7064 } 7065 7066 result = SemaRef.Context.getAttributedType(TL.getAttrKind(), 7067 modifiedType, 7068 equivalentType); 7069 } 7070 7071 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); 7072 newTL.setAttr(newAttr); 7073 return result; 7074 } 7075 7076 template <typename Derived> 7077 QualType TreeTransform<Derived>::TransformBTFTagAttributedType( 7078 TypeLocBuilder &TLB, BTFTagAttributedTypeLoc TL) { 7079 // The BTFTagAttributedType is available for C only. 7080 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType"); 7081 } 7082 7083 template<typename Derived> 7084 QualType 7085 TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 7086 ParenTypeLoc TL) { 7087 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 7088 if (Inner.isNull()) 7089 return QualType(); 7090 7091 QualType Result = TL.getType(); 7092 if (getDerived().AlwaysRebuild() || 7093 Inner != TL.getInnerLoc().getType()) { 7094 Result = getDerived().RebuildParenType(Inner); 7095 if (Result.isNull()) 7096 return QualType(); 7097 } 7098 7099 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 7100 NewTL.setLParenLoc(TL.getLParenLoc()); 7101 NewTL.setRParenLoc(TL.getRParenLoc()); 7102 return Result; 7103 } 7104 7105 template <typename Derived> 7106 QualType 7107 TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB, 7108 MacroQualifiedTypeLoc TL) { 7109 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 7110 if (Inner.isNull()) 7111 return QualType(); 7112 7113 QualType Result = TL.getType(); 7114 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) { 7115 Result = 7116 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier()); 7117 if (Result.isNull()) 7118 return QualType(); 7119 } 7120 7121 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result); 7122 NewTL.setExpansionLoc(TL.getExpansionLoc()); 7123 return Result; 7124 } 7125 7126 template<typename Derived> 7127 QualType TreeTransform<Derived>::TransformDependentNameType( 7128 TypeLocBuilder &TLB, DependentNameTypeLoc TL) { 7129 return TransformDependentNameType(TLB, TL, false); 7130 } 7131 7132 template<typename Derived> 7133 QualType TreeTransform<Derived>::TransformDependentNameType( 7134 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) { 7135 const DependentNameType *T = TL.getTypePtr(); 7136 7137 NestedNameSpecifierLoc QualifierLoc 7138 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 7139 if (!QualifierLoc) 7140 return QualType(); 7141 7142 QualType Result 7143 = getDerived().RebuildDependentNameType(T->getKeyword(), 7144 TL.getElaboratedKeywordLoc(), 7145 QualifierLoc, 7146 T->getIdentifier(), 7147 TL.getNameLoc(), 7148 DeducedTSTContext); 7149 if (Result.isNull()) 7150 return QualType(); 7151 7152 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 7153 QualType NamedT = ElabT->getNamedType(); 7154 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 7155 7156 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 7157 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 7158 NewTL.setQualifierLoc(QualifierLoc); 7159 } else { 7160 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 7161 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 7162 NewTL.setQualifierLoc(QualifierLoc); 7163 NewTL.setNameLoc(TL.getNameLoc()); 7164 } 7165 return Result; 7166 } 7167 7168 template<typename Derived> 7169 QualType TreeTransform<Derived>:: 7170 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 7171 DependentTemplateSpecializationTypeLoc TL) { 7172 NestedNameSpecifierLoc QualifierLoc; 7173 if (TL.getQualifierLoc()) { 7174 QualifierLoc 7175 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 7176 if (!QualifierLoc) 7177 return QualType(); 7178 } 7179 7180 return getDerived() 7181 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); 7182 } 7183 7184 template<typename Derived> 7185 QualType TreeTransform<Derived>:: 7186 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 7187 DependentTemplateSpecializationTypeLoc TL, 7188 NestedNameSpecifierLoc QualifierLoc) { 7189 const DependentTemplateSpecializationType *T = TL.getTypePtr(); 7190 7191 TemplateArgumentListInfo NewTemplateArgs; 7192 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 7193 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 7194 7195 typedef TemplateArgumentLocContainerIterator< 7196 DependentTemplateSpecializationTypeLoc> ArgIterator; 7197 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 7198 ArgIterator(TL, TL.getNumArgs()), 7199 NewTemplateArgs)) 7200 return QualType(); 7201 7202 QualType Result = getDerived().RebuildDependentTemplateSpecializationType( 7203 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(), 7204 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs, 7205 /*AllowInjectedClassName*/ false); 7206 if (Result.isNull()) 7207 return QualType(); 7208 7209 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 7210 QualType NamedT = ElabT->getNamedType(); 7211 7212 // Copy information relevant to the template specialization. 7213 TemplateSpecializationTypeLoc NamedTL 7214 = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 7215 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 7216 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 7217 NamedTL.setLAngleLoc(TL.getLAngleLoc()); 7218 NamedTL.setRAngleLoc(TL.getRAngleLoc()); 7219 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 7220 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 7221 7222 // Copy information relevant to the elaborated type. 7223 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 7224 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 7225 NewTL.setQualifierLoc(QualifierLoc); 7226 } else if (isa<DependentTemplateSpecializationType>(Result)) { 7227 DependentTemplateSpecializationTypeLoc SpecTL 7228 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 7229 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 7230 SpecTL.setQualifierLoc(QualifierLoc); 7231 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 7232 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 7233 SpecTL.setLAngleLoc(TL.getLAngleLoc()); 7234 SpecTL.setRAngleLoc(TL.getRAngleLoc()); 7235 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 7236 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 7237 } else { 7238 TemplateSpecializationTypeLoc SpecTL 7239 = TLB.push<TemplateSpecializationTypeLoc>(Result); 7240 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 7241 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 7242 SpecTL.setLAngleLoc(TL.getLAngleLoc()); 7243 SpecTL.setRAngleLoc(TL.getRAngleLoc()); 7244 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 7245 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 7246 } 7247 return Result; 7248 } 7249 7250 template<typename Derived> 7251 QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 7252 PackExpansionTypeLoc TL) { 7253 QualType Pattern 7254 = getDerived().TransformType(TLB, TL.getPatternLoc()); 7255 if (Pattern.isNull()) 7256 return QualType(); 7257 7258 QualType Result = TL.getType(); 7259 if (getDerived().AlwaysRebuild() || 7260 Pattern != TL.getPatternLoc().getType()) { 7261 Result = getDerived().RebuildPackExpansionType(Pattern, 7262 TL.getPatternLoc().getSourceRange(), 7263 TL.getEllipsisLoc(), 7264 TL.getTypePtr()->getNumExpansions()); 7265 if (Result.isNull()) 7266 return QualType(); 7267 } 7268 7269 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); 7270 NewT.setEllipsisLoc(TL.getEllipsisLoc()); 7271 return Result; 7272 } 7273 7274 template<typename Derived> 7275 QualType 7276 TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 7277 ObjCInterfaceTypeLoc TL) { 7278 // ObjCInterfaceType is never dependent. 7279 TLB.pushFullCopy(TL); 7280 return TL.getType(); 7281 } 7282 7283 template<typename Derived> 7284 QualType 7285 TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB, 7286 ObjCTypeParamTypeLoc TL) { 7287 const ObjCTypeParamType *T = TL.getTypePtr(); 7288 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>( 7289 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl())); 7290 if (!OTP) 7291 return QualType(); 7292 7293 QualType Result = TL.getType(); 7294 if (getDerived().AlwaysRebuild() || 7295 OTP != T->getDecl()) { 7296 Result = getDerived().RebuildObjCTypeParamType( 7297 OTP, TL.getProtocolLAngleLoc(), 7298 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()), 7299 TL.getProtocolLocs(), TL.getProtocolRAngleLoc()); 7300 if (Result.isNull()) 7301 return QualType(); 7302 } 7303 7304 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result); 7305 if (TL.getNumProtocols()) { 7306 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); 7307 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) 7308 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i)); 7309 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); 7310 } 7311 return Result; 7312 } 7313 7314 template<typename Derived> 7315 QualType 7316 TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 7317 ObjCObjectTypeLoc TL) { 7318 // Transform base type. 7319 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); 7320 if (BaseType.isNull()) 7321 return QualType(); 7322 7323 bool AnyChanged = BaseType != TL.getBaseLoc().getType(); 7324 7325 // Transform type arguments. 7326 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; 7327 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { 7328 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); 7329 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); 7330 QualType TypeArg = TypeArgInfo->getType(); 7331 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { 7332 AnyChanged = true; 7333 7334 // We have a pack expansion. Instantiate it. 7335 const auto *PackExpansion = PackExpansionLoc.getType() 7336 ->castAs<PackExpansionType>(); 7337 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 7338 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), 7339 Unexpanded); 7340 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 7341 7342 // Determine whether the set of unexpanded parameter packs can 7343 // and should be expanded. 7344 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); 7345 bool Expand = false; 7346 bool RetainExpansion = false; 7347 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); 7348 if (getDerived().TryExpandParameterPacks( 7349 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), 7350 Unexpanded, Expand, RetainExpansion, NumExpansions)) 7351 return QualType(); 7352 7353 if (!Expand) { 7354 // We can't expand this pack expansion into separate arguments yet; 7355 // just substitute into the pattern and create a new pack expansion 7356 // type. 7357 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 7358 7359 TypeLocBuilder TypeArgBuilder; 7360 TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); 7361 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, 7362 PatternLoc); 7363 if (NewPatternType.isNull()) 7364 return QualType(); 7365 7366 QualType NewExpansionType = SemaRef.Context.getPackExpansionType( 7367 NewPatternType, NumExpansions); 7368 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); 7369 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); 7370 NewTypeArgInfos.push_back( 7371 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); 7372 continue; 7373 } 7374 7375 // Substitute into the pack expansion pattern for each slice of the 7376 // pack. 7377 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { 7378 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); 7379 7380 TypeLocBuilder TypeArgBuilder; 7381 TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); 7382 7383 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, 7384 PatternLoc); 7385 if (NewTypeArg.isNull()) 7386 return QualType(); 7387 7388 NewTypeArgInfos.push_back( 7389 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); 7390 } 7391 7392 continue; 7393 } 7394 7395 TypeLocBuilder TypeArgBuilder; 7396 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); 7397 QualType NewTypeArg = 7398 getDerived().TransformType(TypeArgBuilder, TypeArgLoc); 7399 if (NewTypeArg.isNull()) 7400 return QualType(); 7401 7402 // If nothing changed, just keep the old TypeSourceInfo. 7403 if (NewTypeArg == TypeArg) { 7404 NewTypeArgInfos.push_back(TypeArgInfo); 7405 continue; 7406 } 7407 7408 NewTypeArgInfos.push_back( 7409 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); 7410 AnyChanged = true; 7411 } 7412 7413 QualType Result = TL.getType(); 7414 if (getDerived().AlwaysRebuild() || AnyChanged) { 7415 // Rebuild the type. 7416 Result = getDerived().RebuildObjCObjectType( 7417 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos, 7418 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(), 7419 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()), 7420 TL.getProtocolLocs(), TL.getProtocolRAngleLoc()); 7421 7422 if (Result.isNull()) 7423 return QualType(); 7424 } 7425 7426 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); 7427 NewT.setHasBaseTypeAsWritten(true); 7428 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); 7429 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) 7430 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); 7431 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); 7432 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); 7433 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) 7434 NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); 7435 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); 7436 return Result; 7437 } 7438 7439 template<typename Derived> 7440 QualType 7441 TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 7442 ObjCObjectPointerTypeLoc TL) { 7443 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 7444 if (PointeeType.isNull()) 7445 return QualType(); 7446 7447 QualType Result = TL.getType(); 7448 if (getDerived().AlwaysRebuild() || 7449 PointeeType != TL.getPointeeLoc().getType()) { 7450 Result = getDerived().RebuildObjCObjectPointerType(PointeeType, 7451 TL.getStarLoc()); 7452 if (Result.isNull()) 7453 return QualType(); 7454 } 7455 7456 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 7457 NewT.setStarLoc(TL.getStarLoc()); 7458 return Result; 7459 } 7460 7461 //===----------------------------------------------------------------------===// 7462 // Statement transformation 7463 //===----------------------------------------------------------------------===// 7464 template<typename Derived> 7465 StmtResult 7466 TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 7467 return S; 7468 } 7469 7470 template<typename Derived> 7471 StmtResult 7472 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 7473 return getDerived().TransformCompoundStmt(S, false); 7474 } 7475 7476 template<typename Derived> 7477 StmtResult 7478 TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 7479 bool IsStmtExpr) { 7480 Sema::CompoundScopeRAII CompoundScope(getSema()); 7481 7482 const Stmt *ExprResult = S->getStmtExprResult(); 7483 bool SubStmtInvalid = false; 7484 bool SubStmtChanged = false; 7485 SmallVector<Stmt*, 8> Statements; 7486 for (auto *B : S->body()) { 7487 StmtResult Result = getDerived().TransformStmt( 7488 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded); 7489 7490 if (Result.isInvalid()) { 7491 // Immediately fail if this was a DeclStmt, since it's very 7492 // likely that this will cause problems for future statements. 7493 if (isa<DeclStmt>(B)) 7494 return StmtError(); 7495 7496 // Otherwise, just keep processing substatements and fail later. 7497 SubStmtInvalid = true; 7498 continue; 7499 } 7500 7501 SubStmtChanged = SubStmtChanged || Result.get() != B; 7502 Statements.push_back(Result.getAs<Stmt>()); 7503 } 7504 7505 if (SubStmtInvalid) 7506 return StmtError(); 7507 7508 if (!getDerived().AlwaysRebuild() && 7509 !SubStmtChanged) 7510 return S; 7511 7512 return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 7513 Statements, 7514 S->getRBracLoc(), 7515 IsStmtExpr); 7516 } 7517 7518 template<typename Derived> 7519 StmtResult 7520 TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 7521 ExprResult LHS, RHS; 7522 { 7523 EnterExpressionEvaluationContext Unevaluated( 7524 SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); 7525 7526 // Transform the left-hand case value. 7527 LHS = getDerived().TransformExpr(S->getLHS()); 7528 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS); 7529 if (LHS.isInvalid()) 7530 return StmtError(); 7531 7532 // Transform the right-hand case value (for the GNU case-range extension). 7533 RHS = getDerived().TransformExpr(S->getRHS()); 7534 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS); 7535 if (RHS.isInvalid()) 7536 return StmtError(); 7537 } 7538 7539 // Build the case statement. 7540 // Case statements are always rebuilt so that they will attached to their 7541 // transformed switch statement. 7542 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 7543 LHS.get(), 7544 S->getEllipsisLoc(), 7545 RHS.get(), 7546 S->getColonLoc()); 7547 if (Case.isInvalid()) 7548 return StmtError(); 7549 7550 // Transform the statement following the case 7551 StmtResult SubStmt = 7552 getDerived().TransformStmt(S->getSubStmt()); 7553 if (SubStmt.isInvalid()) 7554 return StmtError(); 7555 7556 // Attach the body to the case statement 7557 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 7558 } 7559 7560 template <typename Derived> 7561 StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 7562 // Transform the statement following the default case 7563 StmtResult SubStmt = 7564 getDerived().TransformStmt(S->getSubStmt()); 7565 if (SubStmt.isInvalid()) 7566 return StmtError(); 7567 7568 // Default statements are always rebuilt 7569 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 7570 SubStmt.get()); 7571 } 7572 7573 template<typename Derived> 7574 StmtResult 7575 TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) { 7576 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); 7577 if (SubStmt.isInvalid()) 7578 return StmtError(); 7579 7580 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), 7581 S->getDecl()); 7582 if (!LD) 7583 return StmtError(); 7584 7585 // If we're transforming "in-place" (we're not creating new local 7586 // declarations), assume we're replacing the old label statement 7587 // and clear out the reference to it. 7588 if (LD == S->getDecl()) 7589 S->getDecl()->setStmt(nullptr); 7590 7591 // FIXME: Pass the real colon location in. 7592 return getDerived().RebuildLabelStmt(S->getIdentLoc(), 7593 cast<LabelDecl>(LD), SourceLocation(), 7594 SubStmt.get()); 7595 } 7596 7597 template <typename Derived> 7598 const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { 7599 if (!R) 7600 return R; 7601 7602 switch (R->getKind()) { 7603 // Transform attributes by calling TransformXXXAttr. 7604 #define ATTR(X) \ 7605 case attr::X: \ 7606 return getDerived().Transform##X##Attr(cast<X##Attr>(R)); 7607 #include "clang/Basic/AttrList.inc" 7608 } 7609 return R; 7610 } 7611 7612 template <typename Derived> 7613 const Attr *TreeTransform<Derived>::TransformStmtAttr(const Stmt *OrigS, 7614 const Stmt *InstS, 7615 const Attr *R) { 7616 if (!R) 7617 return R; 7618 7619 switch (R->getKind()) { 7620 // Transform attributes by calling TransformStmtXXXAttr. 7621 #define ATTR(X) \ 7622 case attr::X: \ 7623 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R)); 7624 #include "clang/Basic/AttrList.inc" 7625 } 7626 return TransformAttr(R); 7627 } 7628 7629 template <typename Derived> 7630 StmtResult 7631 TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S, 7632 StmtDiscardKind SDK) { 7633 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); 7634 if (SubStmt.isInvalid()) 7635 return StmtError(); 7636 7637 bool AttrsChanged = false; 7638 SmallVector<const Attr *, 1> Attrs; 7639 7640 // Visit attributes and keep track if any are transformed. 7641 for (const auto *I : S->getAttrs()) { 7642 const Attr *R = 7643 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I); 7644 AttrsChanged |= (I != R); 7645 if (R) 7646 Attrs.push_back(R); 7647 } 7648 7649 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) 7650 return S; 7651 7652 // If transforming the attributes failed for all of the attributes in the 7653 // statement, don't make an AttributedStmt without attributes. 7654 if (Attrs.empty()) 7655 return SubStmt; 7656 7657 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, 7658 SubStmt.get()); 7659 } 7660 7661 template<typename Derived> 7662 StmtResult 7663 TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 7664 // Transform the initialization statement 7665 StmtResult Init = getDerived().TransformStmt(S->getInit()); 7666 if (Init.isInvalid()) 7667 return StmtError(); 7668 7669 Sema::ConditionResult Cond; 7670 if (!S->isConsteval()) { 7671 // Transform the condition 7672 Cond = getDerived().TransformCondition( 7673 S->getIfLoc(), S->getConditionVariable(), S->getCond(), 7674 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf 7675 : Sema::ConditionKind::Boolean); 7676 if (Cond.isInvalid()) 7677 return StmtError(); 7678 } 7679 7680 // If this is a constexpr if, determine which arm we should instantiate. 7681 std::optional<bool> ConstexprConditionValue; 7682 if (S->isConstexpr()) 7683 ConstexprConditionValue = Cond.getKnownValue(); 7684 7685 // Transform the "then" branch. 7686 StmtResult Then; 7687 if (!ConstexprConditionValue || *ConstexprConditionValue) { 7688 Then = getDerived().TransformStmt(S->getThen()); 7689 if (Then.isInvalid()) 7690 return StmtError(); 7691 } else { 7692 Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc()); 7693 } 7694 7695 // Transform the "else" branch. 7696 StmtResult Else; 7697 if (!ConstexprConditionValue || !*ConstexprConditionValue) { 7698 Else = getDerived().TransformStmt(S->getElse()); 7699 if (Else.isInvalid()) 7700 return StmtError(); 7701 } 7702 7703 if (!getDerived().AlwaysRebuild() && 7704 Init.get() == S->getInit() && 7705 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && 7706 Then.get() == S->getThen() && 7707 Else.get() == S->getElse()) 7708 return S; 7709 7710 return getDerived().RebuildIfStmt( 7711 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond, 7712 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get()); 7713 } 7714 7715 template<typename Derived> 7716 StmtResult 7717 TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 7718 // Transform the initialization statement 7719 StmtResult Init = getDerived().TransformStmt(S->getInit()); 7720 if (Init.isInvalid()) 7721 return StmtError(); 7722 7723 // Transform the condition. 7724 Sema::ConditionResult Cond = getDerived().TransformCondition( 7725 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(), 7726 Sema::ConditionKind::Switch); 7727 if (Cond.isInvalid()) 7728 return StmtError(); 7729 7730 // Rebuild the switch statement. 7731 StmtResult Switch = 7732 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(), 7733 Init.get(), Cond, S->getRParenLoc()); 7734 if (Switch.isInvalid()) 7735 return StmtError(); 7736 7737 // Transform the body of the switch statement. 7738 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7739 if (Body.isInvalid()) 7740 return StmtError(); 7741 7742 // Complete the switch statement. 7743 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 7744 Body.get()); 7745 } 7746 7747 template<typename Derived> 7748 StmtResult 7749 TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 7750 // Transform the condition 7751 Sema::ConditionResult Cond = getDerived().TransformCondition( 7752 S->getWhileLoc(), S->getConditionVariable(), S->getCond(), 7753 Sema::ConditionKind::Boolean); 7754 if (Cond.isInvalid()) 7755 return StmtError(); 7756 7757 // Transform the body 7758 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7759 if (Body.isInvalid()) 7760 return StmtError(); 7761 7762 if (!getDerived().AlwaysRebuild() && 7763 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && 7764 Body.get() == S->getBody()) 7765 return Owned(S); 7766 7767 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(), 7768 Cond, S->getRParenLoc(), Body.get()); 7769 } 7770 7771 template<typename Derived> 7772 StmtResult 7773 TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 7774 // Transform the body 7775 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7776 if (Body.isInvalid()) 7777 return StmtError(); 7778 7779 // Transform the condition 7780 ExprResult Cond = getDerived().TransformExpr(S->getCond()); 7781 if (Cond.isInvalid()) 7782 return StmtError(); 7783 7784 if (!getDerived().AlwaysRebuild() && 7785 Cond.get() == S->getCond() && 7786 Body.get() == S->getBody()) 7787 return S; 7788 7789 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 7790 /*FIXME:*/S->getWhileLoc(), Cond.get(), 7791 S->getRParenLoc()); 7792 } 7793 7794 template<typename Derived> 7795 StmtResult 7796 TreeTransform<Derived>::TransformForStmt(ForStmt *S) { 7797 if (getSema().getLangOpts().OpenMP) 7798 getSema().startOpenMPLoop(); 7799 7800 // Transform the initialization statement 7801 StmtResult Init = getDerived().TransformStmt(S->getInit()); 7802 if (Init.isInvalid()) 7803 return StmtError(); 7804 7805 // In OpenMP loop region loop control variable must be captured and be 7806 // private. Perform analysis of first part (if any). 7807 if (getSema().getLangOpts().OpenMP && Init.isUsable()) 7808 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get()); 7809 7810 // Transform the condition 7811 Sema::ConditionResult Cond = getDerived().TransformCondition( 7812 S->getForLoc(), S->getConditionVariable(), S->getCond(), 7813 Sema::ConditionKind::Boolean); 7814 if (Cond.isInvalid()) 7815 return StmtError(); 7816 7817 // Transform the increment 7818 ExprResult Inc = getDerived().TransformExpr(S->getInc()); 7819 if (Inc.isInvalid()) 7820 return StmtError(); 7821 7822 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); 7823 if (S->getInc() && !FullInc.get()) 7824 return StmtError(); 7825 7826 // Transform the body 7827 StmtResult Body = getDerived().TransformStmt(S->getBody()); 7828 if (Body.isInvalid()) 7829 return StmtError(); 7830 7831 if (!getDerived().AlwaysRebuild() && 7832 Init.get() == S->getInit() && 7833 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && 7834 Inc.get() == S->getInc() && 7835 Body.get() == S->getBody()) 7836 return S; 7837 7838 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 7839 Init.get(), Cond, FullInc, 7840 S->getRParenLoc(), Body.get()); 7841 } 7842 7843 template<typename Derived> 7844 StmtResult 7845 TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 7846 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), 7847 S->getLabel()); 7848 if (!LD) 7849 return StmtError(); 7850 7851 // Goto statements must always be rebuilt, to resolve the label. 7852 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 7853 cast<LabelDecl>(LD)); 7854 } 7855 7856 template<typename Derived> 7857 StmtResult 7858 TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 7859 ExprResult Target = getDerived().TransformExpr(S->getTarget()); 7860 if (Target.isInvalid()) 7861 return StmtError(); 7862 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); 7863 7864 if (!getDerived().AlwaysRebuild() && 7865 Target.get() == S->getTarget()) 7866 return S; 7867 7868 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 7869 Target.get()); 7870 } 7871 7872 template<typename Derived> 7873 StmtResult 7874 TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 7875 return S; 7876 } 7877 7878 template<typename Derived> 7879 StmtResult 7880 TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 7881 return S; 7882 } 7883 7884 template<typename Derived> 7885 StmtResult 7886 TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 7887 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), 7888 /*NotCopyInit*/false); 7889 if (Result.isInvalid()) 7890 return StmtError(); 7891 7892 // FIXME: We always rebuild the return statement because there is no way 7893 // to tell whether the return type of the function has changed. 7894 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 7895 } 7896 7897 template<typename Derived> 7898 StmtResult 7899 TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 7900 bool DeclChanged = false; 7901 SmallVector<Decl *, 4> Decls; 7902 for (auto *D : S->decls()) { 7903 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); 7904 if (!Transformed) 7905 return StmtError(); 7906 7907 if (Transformed != D) 7908 DeclChanged = true; 7909 7910 Decls.push_back(Transformed); 7911 } 7912 7913 if (!getDerived().AlwaysRebuild() && !DeclChanged) 7914 return S; 7915 7916 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc()); 7917 } 7918 7919 template<typename Derived> 7920 StmtResult 7921 TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { 7922 7923 SmallVector<Expr*, 8> Constraints; 7924 SmallVector<Expr*, 8> Exprs; 7925 SmallVector<IdentifierInfo *, 4> Names; 7926 7927 ExprResult AsmString; 7928 SmallVector<Expr*, 8> Clobbers; 7929 7930 bool ExprsChanged = false; 7931 7932 // Go through the outputs. 7933 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 7934 Names.push_back(S->getOutputIdentifier(I)); 7935 7936 // No need to transform the constraint literal. 7937 Constraints.push_back(S->getOutputConstraintLiteral(I)); 7938 7939 // Transform the output expr. 7940 Expr *OutputExpr = S->getOutputExpr(I); 7941 ExprResult Result = getDerived().TransformExpr(OutputExpr); 7942 if (Result.isInvalid()) 7943 return StmtError(); 7944 7945 ExprsChanged |= Result.get() != OutputExpr; 7946 7947 Exprs.push_back(Result.get()); 7948 } 7949 7950 // Go through the inputs. 7951 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 7952 Names.push_back(S->getInputIdentifier(I)); 7953 7954 // No need to transform the constraint literal. 7955 Constraints.push_back(S->getInputConstraintLiteral(I)); 7956 7957 // Transform the input expr. 7958 Expr *InputExpr = S->getInputExpr(I); 7959 ExprResult Result = getDerived().TransformExpr(InputExpr); 7960 if (Result.isInvalid()) 7961 return StmtError(); 7962 7963 ExprsChanged |= Result.get() != InputExpr; 7964 7965 Exprs.push_back(Result.get()); 7966 } 7967 7968 // Go through the Labels. 7969 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) { 7970 Names.push_back(S->getLabelIdentifier(I)); 7971 7972 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I)); 7973 if (Result.isInvalid()) 7974 return StmtError(); 7975 ExprsChanged |= Result.get() != S->getLabelExpr(I); 7976 Exprs.push_back(Result.get()); 7977 } 7978 if (!getDerived().AlwaysRebuild() && !ExprsChanged) 7979 return S; 7980 7981 // Go through the clobbers. 7982 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 7983 Clobbers.push_back(S->getClobberStringLiteral(I)); 7984 7985 // No need to transform the asm string literal. 7986 AsmString = S->getAsmString(); 7987 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), 7988 S->isVolatile(), S->getNumOutputs(), 7989 S->getNumInputs(), Names.data(), 7990 Constraints, Exprs, AsmString.get(), 7991 Clobbers, S->getNumLabels(), 7992 S->getRParenLoc()); 7993 } 7994 7995 template<typename Derived> 7996 StmtResult 7997 TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { 7998 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks()); 7999 8000 bool HadError = false, HadChange = false; 8001 8002 ArrayRef<Expr*> SrcExprs = S->getAllExprs(); 8003 SmallVector<Expr*, 8> TransformedExprs; 8004 TransformedExprs.reserve(SrcExprs.size()); 8005 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { 8006 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); 8007 if (!Result.isUsable()) { 8008 HadError = true; 8009 } else { 8010 HadChange |= (Result.get() != SrcExprs[i]); 8011 TransformedExprs.push_back(Result.get()); 8012 } 8013 } 8014 8015 if (HadError) return StmtError(); 8016 if (!HadChange && !getDerived().AlwaysRebuild()) 8017 return Owned(S); 8018 8019 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), 8020 AsmToks, S->getAsmString(), 8021 S->getNumOutputs(), S->getNumInputs(), 8022 S->getAllConstraints(), S->getClobbers(), 8023 TransformedExprs, S->getEndLoc()); 8024 } 8025 8026 // C++ Coroutines 8027 template<typename Derived> 8028 StmtResult 8029 TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) { 8030 auto *ScopeInfo = SemaRef.getCurFunction(); 8031 auto *FD = cast<FunctionDecl>(SemaRef.CurContext); 8032 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise && 8033 ScopeInfo->NeedsCoroutineSuspends && 8034 ScopeInfo->CoroutineSuspends.first == nullptr && 8035 ScopeInfo->CoroutineSuspends.second == nullptr && 8036 "expected clean scope info"); 8037 8038 // Set that we have (possibly-invalid) suspend points before we do anything 8039 // that may fail. 8040 ScopeInfo->setNeedsCoroutineSuspends(false); 8041 8042 // We re-build the coroutine promise object (and the coroutine parameters its 8043 // type and constructor depend on) based on the types used in our current 8044 // function. We must do so, and set it on the current FunctionScopeInfo, 8045 // before attempting to transform the other parts of the coroutine body 8046 // statement, such as the implicit suspend statements (because those 8047 // statements reference the FunctionScopeInfo::CoroutinePromise). 8048 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation())) 8049 return StmtError(); 8050 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation()); 8051 if (!Promise) 8052 return StmtError(); 8053 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise}); 8054 ScopeInfo->CoroutinePromise = Promise; 8055 8056 // Transform the implicit coroutine statements constructed using dependent 8057 // types during the previous parse: initial and final suspensions, the return 8058 // object, and others. We also transform the coroutine function's body. 8059 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt()); 8060 if (InitSuspend.isInvalid()) 8061 return StmtError(); 8062 StmtResult FinalSuspend = 8063 getDerived().TransformStmt(S->getFinalSuspendStmt()); 8064 if (FinalSuspend.isInvalid() || 8065 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get())) 8066 return StmtError(); 8067 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get()); 8068 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get())); 8069 8070 StmtResult BodyRes = getDerived().TransformStmt(S->getBody()); 8071 if (BodyRes.isInvalid()) 8072 return StmtError(); 8073 8074 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get()); 8075 if (Builder.isInvalid()) 8076 return StmtError(); 8077 8078 Expr *ReturnObject = S->getReturnValueInit(); 8079 assert(ReturnObject && "the return object is expected to be valid"); 8080 ExprResult Res = getDerived().TransformInitializer(ReturnObject, 8081 /*NoCopyInit*/ false); 8082 if (Res.isInvalid()) 8083 return StmtError(); 8084 Builder.ReturnValue = Res.get(); 8085 8086 // If during the previous parse the coroutine still had a dependent promise 8087 // statement, we may need to build some implicit coroutine statements 8088 // (such as exception and fallthrough handlers) for the first time. 8089 if (S->hasDependentPromiseType()) { 8090 // We can only build these statements, however, if the current promise type 8091 // is not dependent. 8092 if (!Promise->getType()->isDependentType()) { 8093 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() && 8094 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() && 8095 "these nodes should not have been built yet"); 8096 if (!Builder.buildDependentStatements()) 8097 return StmtError(); 8098 } 8099 } else { 8100 if (auto *OnFallthrough = S->getFallthroughHandler()) { 8101 StmtResult Res = getDerived().TransformStmt(OnFallthrough); 8102 if (Res.isInvalid()) 8103 return StmtError(); 8104 Builder.OnFallthrough = Res.get(); 8105 } 8106 8107 if (auto *OnException = S->getExceptionHandler()) { 8108 StmtResult Res = getDerived().TransformStmt(OnException); 8109 if (Res.isInvalid()) 8110 return StmtError(); 8111 Builder.OnException = Res.get(); 8112 } 8113 8114 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) { 8115 StmtResult Res = getDerived().TransformStmt(OnAllocFailure); 8116 if (Res.isInvalid()) 8117 return StmtError(); 8118 Builder.ReturnStmtOnAllocFailure = Res.get(); 8119 } 8120 8121 // Transform any additional statements we may have already built 8122 assert(S->getAllocate() && S->getDeallocate() && 8123 "allocation and deallocation calls must already be built"); 8124 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate()); 8125 if (AllocRes.isInvalid()) 8126 return StmtError(); 8127 Builder.Allocate = AllocRes.get(); 8128 8129 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate()); 8130 if (DeallocRes.isInvalid()) 8131 return StmtError(); 8132 Builder.Deallocate = DeallocRes.get(); 8133 8134 if (auto *ResultDecl = S->getResultDecl()) { 8135 StmtResult Res = getDerived().TransformStmt(ResultDecl); 8136 if (Res.isInvalid()) 8137 return StmtError(); 8138 Builder.ResultDecl = Res.get(); 8139 } 8140 8141 if (auto *ReturnStmt = S->getReturnStmt()) { 8142 StmtResult Res = getDerived().TransformStmt(ReturnStmt); 8143 if (Res.isInvalid()) 8144 return StmtError(); 8145 Builder.ReturnStmt = Res.get(); 8146 } 8147 } 8148 8149 return getDerived().RebuildCoroutineBodyStmt(Builder); 8150 } 8151 8152 template<typename Derived> 8153 StmtResult 8154 TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) { 8155 ExprResult Result = getDerived().TransformInitializer(S->getOperand(), 8156 /*NotCopyInit*/false); 8157 if (Result.isInvalid()) 8158 return StmtError(); 8159 8160 // Always rebuild; we don't know if this needs to be injected into a new 8161 // context or if the promise type has changed. 8162 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(), 8163 S->isImplicit()); 8164 } 8165 8166 template <typename Derived> 8167 ExprResult TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) { 8168 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(), 8169 /*NotCopyInit*/ false); 8170 if (Operand.isInvalid()) 8171 return ExprError(); 8172 8173 // Rebuild the common-expr from the operand rather than transforming it 8174 // separately. 8175 8176 // FIXME: getCurScope() should not be used during template instantiation. 8177 // We should pick up the set of unqualified lookup results for operator 8178 // co_await during the initial parse. 8179 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr( 8180 getSema().getCurScope(), E->getKeywordLoc()); 8181 8182 // Always rebuild; we don't know if this needs to be injected into a new 8183 // context or if the promise type has changed. 8184 return getDerived().RebuildCoawaitExpr( 8185 E->getKeywordLoc(), Operand.get(), 8186 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit()); 8187 } 8188 8189 template <typename Derived> 8190 ExprResult 8191 TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) { 8192 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(), 8193 /*NotCopyInit*/ false); 8194 if (OperandResult.isInvalid()) 8195 return ExprError(); 8196 8197 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr( 8198 E->getOperatorCoawaitLookup()); 8199 8200 if (LookupResult.isInvalid()) 8201 return ExprError(); 8202 8203 // Always rebuild; we don't know if this needs to be injected into a new 8204 // context or if the promise type has changed. 8205 return getDerived().RebuildDependentCoawaitExpr( 8206 E->getKeywordLoc(), OperandResult.get(), 8207 cast<UnresolvedLookupExpr>(LookupResult.get())); 8208 } 8209 8210 template<typename Derived> 8211 ExprResult 8212 TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) { 8213 ExprResult Result = getDerived().TransformInitializer(E->getOperand(), 8214 /*NotCopyInit*/false); 8215 if (Result.isInvalid()) 8216 return ExprError(); 8217 8218 // Always rebuild; we don't know if this needs to be injected into a new 8219 // context or if the promise type has changed. 8220 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get()); 8221 } 8222 8223 // Objective-C Statements. 8224 8225 template<typename Derived> 8226 StmtResult 8227 TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 8228 // Transform the body of the @try. 8229 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 8230 if (TryBody.isInvalid()) 8231 return StmtError(); 8232 8233 // Transform the @catch statements (if present). 8234 bool AnyCatchChanged = false; 8235 SmallVector<Stmt*, 8> CatchStmts; 8236 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 8237 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 8238 if (Catch.isInvalid()) 8239 return StmtError(); 8240 if (Catch.get() != S->getCatchStmt(I)) 8241 AnyCatchChanged = true; 8242 CatchStmts.push_back(Catch.get()); 8243 } 8244 8245 // Transform the @finally statement (if present). 8246 StmtResult Finally; 8247 if (S->getFinallyStmt()) { 8248 Finally = getDerived().TransformStmt(S->getFinallyStmt()); 8249 if (Finally.isInvalid()) 8250 return StmtError(); 8251 } 8252 8253 // If nothing changed, just retain this statement. 8254 if (!getDerived().AlwaysRebuild() && 8255 TryBody.get() == S->getTryBody() && 8256 !AnyCatchChanged && 8257 Finally.get() == S->getFinallyStmt()) 8258 return S; 8259 8260 // Build a new statement. 8261 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 8262 CatchStmts, Finally.get()); 8263 } 8264 8265 template<typename Derived> 8266 StmtResult 8267 TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 8268 // Transform the @catch parameter, if there is one. 8269 VarDecl *Var = nullptr; 8270 if (VarDecl *FromVar = S->getCatchParamDecl()) { 8271 TypeSourceInfo *TSInfo = nullptr; 8272 if (FromVar->getTypeSourceInfo()) { 8273 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 8274 if (!TSInfo) 8275 return StmtError(); 8276 } 8277 8278 QualType T; 8279 if (TSInfo) 8280 T = TSInfo->getType(); 8281 else { 8282 T = getDerived().TransformType(FromVar->getType()); 8283 if (T.isNull()) 8284 return StmtError(); 8285 } 8286 8287 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 8288 if (!Var) 8289 return StmtError(); 8290 } 8291 8292 StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 8293 if (Body.isInvalid()) 8294 return StmtError(); 8295 8296 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 8297 S->getRParenLoc(), 8298 Var, Body.get()); 8299 } 8300 8301 template<typename Derived> 8302 StmtResult 8303 TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 8304 // Transform the body. 8305 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 8306 if (Body.isInvalid()) 8307 return StmtError(); 8308 8309 // If nothing changed, just retain this statement. 8310 if (!getDerived().AlwaysRebuild() && 8311 Body.get() == S->getFinallyBody()) 8312 return S; 8313 8314 // Build a new statement. 8315 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 8316 Body.get()); 8317 } 8318 8319 template<typename Derived> 8320 StmtResult 8321 TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 8322 ExprResult Operand; 8323 if (S->getThrowExpr()) { 8324 Operand = getDerived().TransformExpr(S->getThrowExpr()); 8325 if (Operand.isInvalid()) 8326 return StmtError(); 8327 } 8328 8329 if (!getDerived().AlwaysRebuild() && 8330 Operand.get() == S->getThrowExpr()) 8331 return S; 8332 8333 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 8334 } 8335 8336 template<typename Derived> 8337 StmtResult 8338 TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 8339 ObjCAtSynchronizedStmt *S) { 8340 // Transform the object we are locking. 8341 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 8342 if (Object.isInvalid()) 8343 return StmtError(); 8344 Object = 8345 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), 8346 Object.get()); 8347 if (Object.isInvalid()) 8348 return StmtError(); 8349 8350 // Transform the body. 8351 StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 8352 if (Body.isInvalid()) 8353 return StmtError(); 8354 8355 // If nothing change, just retain the current statement. 8356 if (!getDerived().AlwaysRebuild() && 8357 Object.get() == S->getSynchExpr() && 8358 Body.get() == S->getSynchBody()) 8359 return S; 8360 8361 // Build a new statement. 8362 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 8363 Object.get(), Body.get()); 8364 } 8365 8366 template<typename Derived> 8367 StmtResult 8368 TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( 8369 ObjCAutoreleasePoolStmt *S) { 8370 // Transform the body. 8371 StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); 8372 if (Body.isInvalid()) 8373 return StmtError(); 8374 8375 // If nothing changed, just retain this statement. 8376 if (!getDerived().AlwaysRebuild() && 8377 Body.get() == S->getSubStmt()) 8378 return S; 8379 8380 // Build a new statement. 8381 return getDerived().RebuildObjCAutoreleasePoolStmt( 8382 S->getAtLoc(), Body.get()); 8383 } 8384 8385 template<typename Derived> 8386 StmtResult 8387 TreeTransform<Derived>::TransformObjCForCollectionStmt( 8388 ObjCForCollectionStmt *S) { 8389 // Transform the element statement. 8390 StmtResult Element = 8391 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded); 8392 if (Element.isInvalid()) 8393 return StmtError(); 8394 8395 // Transform the collection expression. 8396 ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 8397 if (Collection.isInvalid()) 8398 return StmtError(); 8399 8400 // Transform the body. 8401 StmtResult Body = getDerived().TransformStmt(S->getBody()); 8402 if (Body.isInvalid()) 8403 return StmtError(); 8404 8405 // If nothing changed, just retain this statement. 8406 if (!getDerived().AlwaysRebuild() && 8407 Element.get() == S->getElement() && 8408 Collection.get() == S->getCollection() && 8409 Body.get() == S->getBody()) 8410 return S; 8411 8412 // Build a new statement. 8413 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 8414 Element.get(), 8415 Collection.get(), 8416 S->getRParenLoc(), 8417 Body.get()); 8418 } 8419 8420 template <typename Derived> 8421 StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 8422 // Transform the exception declaration, if any. 8423 VarDecl *Var = nullptr; 8424 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { 8425 TypeSourceInfo *T = 8426 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); 8427 if (!T) 8428 return StmtError(); 8429 8430 Var = getDerived().RebuildExceptionDecl( 8431 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), 8432 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); 8433 if (!Var || Var->isInvalidDecl()) 8434 return StmtError(); 8435 } 8436 8437 // Transform the actual exception handler. 8438 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 8439 if (Handler.isInvalid()) 8440 return StmtError(); 8441 8442 if (!getDerived().AlwaysRebuild() && !Var && 8443 Handler.get() == S->getHandlerBlock()) 8444 return S; 8445 8446 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); 8447 } 8448 8449 template <typename Derived> 8450 StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 8451 // Transform the try block itself. 8452 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); 8453 if (TryBlock.isInvalid()) 8454 return StmtError(); 8455 8456 // Transform the handlers. 8457 bool HandlerChanged = false; 8458 SmallVector<Stmt *, 8> Handlers; 8459 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 8460 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 8461 if (Handler.isInvalid()) 8462 return StmtError(); 8463 8464 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 8465 Handlers.push_back(Handler.getAs<Stmt>()); 8466 } 8467 8468 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && 8469 !HandlerChanged) 8470 return S; 8471 8472 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 8473 Handlers); 8474 } 8475 8476 template<typename Derived> 8477 StmtResult 8478 TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { 8479 StmtResult Init = 8480 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult(); 8481 if (Init.isInvalid()) 8482 return StmtError(); 8483 8484 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); 8485 if (Range.isInvalid()) 8486 return StmtError(); 8487 8488 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt()); 8489 if (Begin.isInvalid()) 8490 return StmtError(); 8491 StmtResult End = getDerived().TransformStmt(S->getEndStmt()); 8492 if (End.isInvalid()) 8493 return StmtError(); 8494 8495 ExprResult Cond = getDerived().TransformExpr(S->getCond()); 8496 if (Cond.isInvalid()) 8497 return StmtError(); 8498 if (Cond.get()) 8499 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get()); 8500 if (Cond.isInvalid()) 8501 return StmtError(); 8502 if (Cond.get()) 8503 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); 8504 8505 ExprResult Inc = getDerived().TransformExpr(S->getInc()); 8506 if (Inc.isInvalid()) 8507 return StmtError(); 8508 if (Inc.get()) 8509 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); 8510 8511 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); 8512 if (LoopVar.isInvalid()) 8513 return StmtError(); 8514 8515 StmtResult NewStmt = S; 8516 if (getDerived().AlwaysRebuild() || 8517 Init.get() != S->getInit() || 8518 Range.get() != S->getRangeStmt() || 8519 Begin.get() != S->getBeginStmt() || 8520 End.get() != S->getEndStmt() || 8521 Cond.get() != S->getCond() || 8522 Inc.get() != S->getInc() || 8523 LoopVar.get() != S->getLoopVarStmt()) { 8524 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 8525 S->getCoawaitLoc(), Init.get(), 8526 S->getColonLoc(), Range.get(), 8527 Begin.get(), End.get(), 8528 Cond.get(), 8529 Inc.get(), LoopVar.get(), 8530 S->getRParenLoc()); 8531 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) { 8532 // Might not have attached any initializer to the loop variable. 8533 getSema().ActOnInitializerError( 8534 cast<DeclStmt>(LoopVar.get())->getSingleDecl()); 8535 return StmtError(); 8536 } 8537 } 8538 8539 StmtResult Body = getDerived().TransformStmt(S->getBody()); 8540 if (Body.isInvalid()) 8541 return StmtError(); 8542 8543 // Body has changed but we didn't rebuild the for-range statement. Rebuild 8544 // it now so we have a new statement to attach the body to. 8545 if (Body.get() != S->getBody() && NewStmt.get() == S) { 8546 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 8547 S->getCoawaitLoc(), Init.get(), 8548 S->getColonLoc(), Range.get(), 8549 Begin.get(), End.get(), 8550 Cond.get(), 8551 Inc.get(), LoopVar.get(), 8552 S->getRParenLoc()); 8553 if (NewStmt.isInvalid()) 8554 return StmtError(); 8555 } 8556 8557 if (NewStmt.get() == S) 8558 return S; 8559 8560 return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); 8561 } 8562 8563 template<typename Derived> 8564 StmtResult 8565 TreeTransform<Derived>::TransformMSDependentExistsStmt( 8566 MSDependentExistsStmt *S) { 8567 // Transform the nested-name-specifier, if any. 8568 NestedNameSpecifierLoc QualifierLoc; 8569 if (S->getQualifierLoc()) { 8570 QualifierLoc 8571 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); 8572 if (!QualifierLoc) 8573 return StmtError(); 8574 } 8575 8576 // Transform the declaration name. 8577 DeclarationNameInfo NameInfo = S->getNameInfo(); 8578 if (NameInfo.getName()) { 8579 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 8580 if (!NameInfo.getName()) 8581 return StmtError(); 8582 } 8583 8584 // Check whether anything changed. 8585 if (!getDerived().AlwaysRebuild() && 8586 QualifierLoc == S->getQualifierLoc() && 8587 NameInfo.getName() == S->getNameInfo().getName()) 8588 return S; 8589 8590 // Determine whether this name exists, if we can. 8591 CXXScopeSpec SS; 8592 SS.Adopt(QualifierLoc); 8593 bool Dependent = false; 8594 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { 8595 case Sema::IER_Exists: 8596 if (S->isIfExists()) 8597 break; 8598 8599 return new (getSema().Context) NullStmt(S->getKeywordLoc()); 8600 8601 case Sema::IER_DoesNotExist: 8602 if (S->isIfNotExists()) 8603 break; 8604 8605 return new (getSema().Context) NullStmt(S->getKeywordLoc()); 8606 8607 case Sema::IER_Dependent: 8608 Dependent = true; 8609 break; 8610 8611 case Sema::IER_Error: 8612 return StmtError(); 8613 } 8614 8615 // We need to continue with the instantiation, so do so now. 8616 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); 8617 if (SubStmt.isInvalid()) 8618 return StmtError(); 8619 8620 // If we have resolved the name, just transform to the substatement. 8621 if (!Dependent) 8622 return SubStmt; 8623 8624 // The name is still dependent, so build a dependent expression again. 8625 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), 8626 S->isIfExists(), 8627 QualifierLoc, 8628 NameInfo, 8629 SubStmt.get()); 8630 } 8631 8632 template<typename Derived> 8633 ExprResult 8634 TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { 8635 NestedNameSpecifierLoc QualifierLoc; 8636 if (E->getQualifierLoc()) { 8637 QualifierLoc 8638 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 8639 if (!QualifierLoc) 8640 return ExprError(); 8641 } 8642 8643 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( 8644 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); 8645 if (!PD) 8646 return ExprError(); 8647 8648 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); 8649 if (Base.isInvalid()) 8650 return ExprError(); 8651 8652 return new (SemaRef.getASTContext()) 8653 MSPropertyRefExpr(Base.get(), PD, E->isArrow(), 8654 SemaRef.getASTContext().PseudoObjectTy, VK_LValue, 8655 QualifierLoc, E->getMemberLoc()); 8656 } 8657 8658 template <typename Derived> 8659 ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr( 8660 MSPropertySubscriptExpr *E) { 8661 auto BaseRes = getDerived().TransformExpr(E->getBase()); 8662 if (BaseRes.isInvalid()) 8663 return ExprError(); 8664 auto IdxRes = getDerived().TransformExpr(E->getIdx()); 8665 if (IdxRes.isInvalid()) 8666 return ExprError(); 8667 8668 if (!getDerived().AlwaysRebuild() && 8669 BaseRes.get() == E->getBase() && 8670 IdxRes.get() == E->getIdx()) 8671 return E; 8672 8673 return getDerived().RebuildArraySubscriptExpr( 8674 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc()); 8675 } 8676 8677 template <typename Derived> 8678 StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { 8679 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); 8680 if (TryBlock.isInvalid()) 8681 return StmtError(); 8682 8683 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); 8684 if (Handler.isInvalid()) 8685 return StmtError(); 8686 8687 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && 8688 Handler.get() == S->getHandler()) 8689 return S; 8690 8691 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), 8692 TryBlock.get(), Handler.get()); 8693 } 8694 8695 template <typename Derived> 8696 StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { 8697 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); 8698 if (Block.isInvalid()) 8699 return StmtError(); 8700 8701 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); 8702 } 8703 8704 template <typename Derived> 8705 StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { 8706 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); 8707 if (FilterExpr.isInvalid()) 8708 return StmtError(); 8709 8710 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); 8711 if (Block.isInvalid()) 8712 return StmtError(); 8713 8714 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), 8715 Block.get()); 8716 } 8717 8718 template <typename Derived> 8719 StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { 8720 if (isa<SEHFinallyStmt>(Handler)) 8721 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); 8722 else 8723 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); 8724 } 8725 8726 template<typename Derived> 8727 StmtResult 8728 TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { 8729 return S; 8730 } 8731 8732 //===----------------------------------------------------------------------===// 8733 // OpenMP directive transformation 8734 //===----------------------------------------------------------------------===// 8735 8736 template <typename Derived> 8737 StmtResult 8738 TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) { 8739 // OMPCanonicalLoops are eliminated during transformation, since they will be 8740 // recomputed by semantic analysis of the associated OMPLoopBasedDirective 8741 // after transformation. 8742 return getDerived().TransformStmt(L->getLoopStmt()); 8743 } 8744 8745 template <typename Derived> 8746 StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( 8747 OMPExecutableDirective *D) { 8748 8749 // Transform the clauses 8750 llvm::SmallVector<OMPClause *, 16> TClauses; 8751 ArrayRef<OMPClause *> Clauses = D->clauses(); 8752 TClauses.reserve(Clauses.size()); 8753 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); 8754 I != E; ++I) { 8755 if (*I) { 8756 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind()); 8757 OMPClause *Clause = getDerived().TransformOMPClause(*I); 8758 getDerived().getSema().EndOpenMPClause(); 8759 if (Clause) 8760 TClauses.push_back(Clause); 8761 } else { 8762 TClauses.push_back(nullptr); 8763 } 8764 } 8765 StmtResult AssociatedStmt; 8766 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) { 8767 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(), 8768 /*CurScope=*/nullptr); 8769 StmtResult Body; 8770 { 8771 Sema::CompoundScopeRAII CompoundScope(getSema()); 8772 Stmt *CS; 8773 if (D->getDirectiveKind() == OMPD_atomic || 8774 D->getDirectiveKind() == OMPD_critical || 8775 D->getDirectiveKind() == OMPD_section || 8776 D->getDirectiveKind() == OMPD_master) 8777 CS = D->getAssociatedStmt(); 8778 else 8779 CS = D->getRawStmt(); 8780 Body = getDerived().TransformStmt(CS); 8781 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) && 8782 getSema().getLangOpts().OpenMPIRBuilder) 8783 Body = getDerived().RebuildOMPCanonicalLoop(Body.get()); 8784 } 8785 AssociatedStmt = 8786 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses); 8787 if (AssociatedStmt.isInvalid()) { 8788 return StmtError(); 8789 } 8790 } 8791 if (TClauses.size() != Clauses.size()) { 8792 return StmtError(); 8793 } 8794 8795 // Transform directive name for 'omp critical' directive. 8796 DeclarationNameInfo DirName; 8797 if (D->getDirectiveKind() == OMPD_critical) { 8798 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); 8799 DirName = getDerived().TransformDeclarationNameInfo(DirName); 8800 } 8801 OpenMPDirectiveKind CancelRegion = OMPD_unknown; 8802 if (D->getDirectiveKind() == OMPD_cancellation_point) { 8803 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); 8804 } else if (D->getDirectiveKind() == OMPD_cancel) { 8805 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); 8806 } 8807 8808 return getDerived().RebuildOMPExecutableDirective( 8809 D->getDirectiveKind(), DirName, CancelRegion, TClauses, 8810 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc()); 8811 } 8812 8813 template <typename Derived> 8814 StmtResult 8815 TreeTransform<Derived>::TransformOMPMetaDirective(OMPMetaDirective *D) { 8816 // TODO: Fix This 8817 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported) 8818 << getOpenMPDirectiveName(D->getDirectiveKind()); 8819 return StmtError(); 8820 } 8821 8822 template <typename Derived> 8823 StmtResult 8824 TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { 8825 DeclarationNameInfo DirName; 8826 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, 8827 D->getBeginLoc()); 8828 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8829 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8830 return Res; 8831 } 8832 8833 template <typename Derived> 8834 StmtResult 8835 TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { 8836 DeclarationNameInfo DirName; 8837 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, 8838 D->getBeginLoc()); 8839 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8840 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8841 return Res; 8842 } 8843 8844 template <typename Derived> 8845 StmtResult 8846 TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) { 8847 DeclarationNameInfo DirName; 8848 getDerived().getSema().StartOpenMPDSABlock(D->getDirectiveKind(), DirName, 8849 nullptr, D->getBeginLoc()); 8850 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8851 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8852 return Res; 8853 } 8854 8855 template <typename Derived> 8856 StmtResult 8857 TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) { 8858 DeclarationNameInfo DirName; 8859 getDerived().getSema().StartOpenMPDSABlock(D->getDirectiveKind(), DirName, 8860 nullptr, D->getBeginLoc()); 8861 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8862 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8863 return Res; 8864 } 8865 8866 template <typename Derived> 8867 StmtResult 8868 TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { 8869 DeclarationNameInfo DirName; 8870 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, 8871 D->getBeginLoc()); 8872 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8873 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8874 return Res; 8875 } 8876 8877 template <typename Derived> 8878 StmtResult 8879 TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { 8880 DeclarationNameInfo DirName; 8881 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, 8882 D->getBeginLoc()); 8883 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8884 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8885 return Res; 8886 } 8887 8888 template <typename Derived> 8889 StmtResult 8890 TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { 8891 DeclarationNameInfo DirName; 8892 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, 8893 D->getBeginLoc()); 8894 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8895 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8896 return Res; 8897 } 8898 8899 template <typename Derived> 8900 StmtResult 8901 TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { 8902 DeclarationNameInfo DirName; 8903 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, 8904 D->getBeginLoc()); 8905 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8906 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8907 return Res; 8908 } 8909 8910 template <typename Derived> 8911 StmtResult 8912 TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { 8913 DeclarationNameInfo DirName; 8914 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, 8915 D->getBeginLoc()); 8916 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8917 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8918 return Res; 8919 } 8920 8921 template <typename Derived> 8922 StmtResult 8923 TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { 8924 DeclarationNameInfo DirName; 8925 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, 8926 D->getBeginLoc()); 8927 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8928 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8929 return Res; 8930 } 8931 8932 template <typename Derived> 8933 StmtResult 8934 TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { 8935 getDerived().getSema().StartOpenMPDSABlock( 8936 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc()); 8937 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8938 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8939 return Res; 8940 } 8941 8942 template <typename Derived> 8943 StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( 8944 OMPParallelForDirective *D) { 8945 DeclarationNameInfo DirName; 8946 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, 8947 nullptr, D->getBeginLoc()); 8948 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8949 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8950 return Res; 8951 } 8952 8953 template <typename Derived> 8954 StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( 8955 OMPParallelForSimdDirective *D) { 8956 DeclarationNameInfo DirName; 8957 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, 8958 nullptr, D->getBeginLoc()); 8959 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8960 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8961 return Res; 8962 } 8963 8964 template <typename Derived> 8965 StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective( 8966 OMPParallelMasterDirective *D) { 8967 DeclarationNameInfo DirName; 8968 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_master, DirName, 8969 nullptr, D->getBeginLoc()); 8970 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8971 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8972 return Res; 8973 } 8974 8975 template <typename Derived> 8976 StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective( 8977 OMPParallelMaskedDirective *D) { 8978 DeclarationNameInfo DirName; 8979 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_masked, DirName, 8980 nullptr, D->getBeginLoc()); 8981 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8982 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8983 return Res; 8984 } 8985 8986 template <typename Derived> 8987 StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( 8988 OMPParallelSectionsDirective *D) { 8989 DeclarationNameInfo DirName; 8990 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, 8991 nullptr, D->getBeginLoc()); 8992 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 8993 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 8994 return Res; 8995 } 8996 8997 template <typename Derived> 8998 StmtResult 8999 TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { 9000 DeclarationNameInfo DirName; 9001 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, 9002 D->getBeginLoc()); 9003 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9004 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9005 return Res; 9006 } 9007 9008 template <typename Derived> 9009 StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( 9010 OMPTaskyieldDirective *D) { 9011 DeclarationNameInfo DirName; 9012 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, 9013 D->getBeginLoc()); 9014 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9015 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9016 return Res; 9017 } 9018 9019 template <typename Derived> 9020 StmtResult 9021 TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { 9022 DeclarationNameInfo DirName; 9023 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, 9024 D->getBeginLoc()); 9025 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9026 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9027 return Res; 9028 } 9029 9030 template <typename Derived> 9031 StmtResult 9032 TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { 9033 DeclarationNameInfo DirName; 9034 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, 9035 D->getBeginLoc()); 9036 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9037 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9038 return Res; 9039 } 9040 9041 template <typename Derived> 9042 StmtResult 9043 TreeTransform<Derived>::TransformOMPErrorDirective(OMPErrorDirective *D) { 9044 DeclarationNameInfo DirName; 9045 getDerived().getSema().StartOpenMPDSABlock(OMPD_error, DirName, nullptr, 9046 D->getBeginLoc()); 9047 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9048 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9049 return Res; 9050 } 9051 9052 template <typename Derived> 9053 StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( 9054 OMPTaskgroupDirective *D) { 9055 DeclarationNameInfo DirName; 9056 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr, 9057 D->getBeginLoc()); 9058 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9059 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9060 return Res; 9061 } 9062 9063 template <typename Derived> 9064 StmtResult 9065 TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { 9066 DeclarationNameInfo DirName; 9067 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, 9068 D->getBeginLoc()); 9069 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9070 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9071 return Res; 9072 } 9073 9074 template <typename Derived> 9075 StmtResult 9076 TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) { 9077 DeclarationNameInfo DirName; 9078 getDerived().getSema().StartOpenMPDSABlock(OMPD_depobj, DirName, nullptr, 9079 D->getBeginLoc()); 9080 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9081 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9082 return Res; 9083 } 9084 9085 template <typename Derived> 9086 StmtResult 9087 TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) { 9088 DeclarationNameInfo DirName; 9089 getDerived().getSema().StartOpenMPDSABlock(OMPD_scan, DirName, nullptr, 9090 D->getBeginLoc()); 9091 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9092 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9093 return Res; 9094 } 9095 9096 template <typename Derived> 9097 StmtResult 9098 TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { 9099 DeclarationNameInfo DirName; 9100 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, 9101 D->getBeginLoc()); 9102 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9103 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9104 return Res; 9105 } 9106 9107 template <typename Derived> 9108 StmtResult 9109 TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { 9110 DeclarationNameInfo DirName; 9111 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, 9112 D->getBeginLoc()); 9113 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9114 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9115 return Res; 9116 } 9117 9118 template <typename Derived> 9119 StmtResult 9120 TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { 9121 DeclarationNameInfo DirName; 9122 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, 9123 D->getBeginLoc()); 9124 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9125 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9126 return Res; 9127 } 9128 9129 template <typename Derived> 9130 StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( 9131 OMPTargetDataDirective *D) { 9132 DeclarationNameInfo DirName; 9133 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr, 9134 D->getBeginLoc()); 9135 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9136 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9137 return Res; 9138 } 9139 9140 template <typename Derived> 9141 StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective( 9142 OMPTargetEnterDataDirective *D) { 9143 DeclarationNameInfo DirName; 9144 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName, 9145 nullptr, D->getBeginLoc()); 9146 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9147 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9148 return Res; 9149 } 9150 9151 template <typename Derived> 9152 StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective( 9153 OMPTargetExitDataDirective *D) { 9154 DeclarationNameInfo DirName; 9155 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName, 9156 nullptr, D->getBeginLoc()); 9157 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9158 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9159 return Res; 9160 } 9161 9162 template <typename Derived> 9163 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective( 9164 OMPTargetParallelDirective *D) { 9165 DeclarationNameInfo DirName; 9166 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName, 9167 nullptr, D->getBeginLoc()); 9168 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9169 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9170 return Res; 9171 } 9172 9173 template <typename Derived> 9174 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective( 9175 OMPTargetParallelForDirective *D) { 9176 DeclarationNameInfo DirName; 9177 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName, 9178 nullptr, D->getBeginLoc()); 9179 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9180 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9181 return Res; 9182 } 9183 9184 template <typename Derived> 9185 StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective( 9186 OMPTargetUpdateDirective *D) { 9187 DeclarationNameInfo DirName; 9188 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName, 9189 nullptr, D->getBeginLoc()); 9190 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9191 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9192 return Res; 9193 } 9194 9195 template <typename Derived> 9196 StmtResult 9197 TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { 9198 DeclarationNameInfo DirName; 9199 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, 9200 D->getBeginLoc()); 9201 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9202 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9203 return Res; 9204 } 9205 9206 template <typename Derived> 9207 StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( 9208 OMPCancellationPointDirective *D) { 9209 DeclarationNameInfo DirName; 9210 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName, 9211 nullptr, D->getBeginLoc()); 9212 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9213 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9214 return Res; 9215 } 9216 9217 template <typename Derived> 9218 StmtResult 9219 TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { 9220 DeclarationNameInfo DirName; 9221 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, 9222 D->getBeginLoc()); 9223 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9224 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9225 return Res; 9226 } 9227 9228 template <typename Derived> 9229 StmtResult 9230 TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) { 9231 DeclarationNameInfo DirName; 9232 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr, 9233 D->getBeginLoc()); 9234 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9235 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9236 return Res; 9237 } 9238 9239 template <typename Derived> 9240 StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective( 9241 OMPTaskLoopSimdDirective *D) { 9242 DeclarationNameInfo DirName; 9243 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName, 9244 nullptr, D->getBeginLoc()); 9245 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9246 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9247 return Res; 9248 } 9249 9250 template <typename Derived> 9251 StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective( 9252 OMPMasterTaskLoopDirective *D) { 9253 DeclarationNameInfo DirName; 9254 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop, DirName, 9255 nullptr, D->getBeginLoc()); 9256 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9257 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9258 return Res; 9259 } 9260 9261 template <typename Derived> 9262 StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopDirective( 9263 OMPMaskedTaskLoopDirective *D) { 9264 DeclarationNameInfo DirName; 9265 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked_taskloop, DirName, 9266 nullptr, D->getBeginLoc()); 9267 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9268 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9269 return Res; 9270 } 9271 9272 template <typename Derived> 9273 StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective( 9274 OMPMasterTaskLoopSimdDirective *D) { 9275 DeclarationNameInfo DirName; 9276 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop_simd, DirName, 9277 nullptr, D->getBeginLoc()); 9278 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9279 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9280 return Res; 9281 } 9282 9283 template <typename Derived> 9284 StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopSimdDirective( 9285 OMPMaskedTaskLoopSimdDirective *D) { 9286 DeclarationNameInfo DirName; 9287 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked_taskloop_simd, DirName, 9288 nullptr, D->getBeginLoc()); 9289 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9290 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9291 return Res; 9292 } 9293 9294 template <typename Derived> 9295 StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective( 9296 OMPParallelMasterTaskLoopDirective *D) { 9297 DeclarationNameInfo DirName; 9298 getDerived().getSema().StartOpenMPDSABlock( 9299 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc()); 9300 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9301 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9302 return Res; 9303 } 9304 9305 template <typename Derived> 9306 StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopDirective( 9307 OMPParallelMaskedTaskLoopDirective *D) { 9308 DeclarationNameInfo DirName; 9309 getDerived().getSema().StartOpenMPDSABlock( 9310 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc()); 9311 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9312 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9313 return Res; 9314 } 9315 9316 template <typename Derived> 9317 StmtResult 9318 TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective( 9319 OMPParallelMasterTaskLoopSimdDirective *D) { 9320 DeclarationNameInfo DirName; 9321 getDerived().getSema().StartOpenMPDSABlock( 9322 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc()); 9323 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9324 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9325 return Res; 9326 } 9327 9328 template <typename Derived> 9329 StmtResult 9330 TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopSimdDirective( 9331 OMPParallelMaskedTaskLoopSimdDirective *D) { 9332 DeclarationNameInfo DirName; 9333 getDerived().getSema().StartOpenMPDSABlock( 9334 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc()); 9335 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9336 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9337 return Res; 9338 } 9339 9340 template <typename Derived> 9341 StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective( 9342 OMPDistributeDirective *D) { 9343 DeclarationNameInfo DirName; 9344 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr, 9345 D->getBeginLoc()); 9346 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9347 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9348 return Res; 9349 } 9350 9351 template <typename Derived> 9352 StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective( 9353 OMPDistributeParallelForDirective *D) { 9354 DeclarationNameInfo DirName; 9355 getDerived().getSema().StartOpenMPDSABlock( 9356 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); 9357 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9358 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9359 return Res; 9360 } 9361 9362 template <typename Derived> 9363 StmtResult 9364 TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective( 9365 OMPDistributeParallelForSimdDirective *D) { 9366 DeclarationNameInfo DirName; 9367 getDerived().getSema().StartOpenMPDSABlock( 9368 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); 9369 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9370 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9371 return Res; 9372 } 9373 9374 template <typename Derived> 9375 StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective( 9376 OMPDistributeSimdDirective *D) { 9377 DeclarationNameInfo DirName; 9378 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName, 9379 nullptr, D->getBeginLoc()); 9380 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9381 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9382 return Res; 9383 } 9384 9385 template <typename Derived> 9386 StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective( 9387 OMPTargetParallelForSimdDirective *D) { 9388 DeclarationNameInfo DirName; 9389 getDerived().getSema().StartOpenMPDSABlock( 9390 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); 9391 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9392 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9393 return Res; 9394 } 9395 9396 template <typename Derived> 9397 StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective( 9398 OMPTargetSimdDirective *D) { 9399 DeclarationNameInfo DirName; 9400 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr, 9401 D->getBeginLoc()); 9402 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9403 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9404 return Res; 9405 } 9406 9407 template <typename Derived> 9408 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective( 9409 OMPTeamsDistributeDirective *D) { 9410 DeclarationNameInfo DirName; 9411 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName, 9412 nullptr, D->getBeginLoc()); 9413 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9414 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9415 return Res; 9416 } 9417 9418 template <typename Derived> 9419 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective( 9420 OMPTeamsDistributeSimdDirective *D) { 9421 DeclarationNameInfo DirName; 9422 getDerived().getSema().StartOpenMPDSABlock( 9423 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); 9424 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9425 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9426 return Res; 9427 } 9428 9429 template <typename Derived> 9430 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective( 9431 OMPTeamsDistributeParallelForSimdDirective *D) { 9432 DeclarationNameInfo DirName; 9433 getDerived().getSema().StartOpenMPDSABlock( 9434 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, 9435 D->getBeginLoc()); 9436 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9437 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9438 return Res; 9439 } 9440 9441 template <typename Derived> 9442 StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective( 9443 OMPTeamsDistributeParallelForDirective *D) { 9444 DeclarationNameInfo DirName; 9445 getDerived().getSema().StartOpenMPDSABlock( 9446 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); 9447 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9448 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9449 return Res; 9450 } 9451 9452 template <typename Derived> 9453 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective( 9454 OMPTargetTeamsDirective *D) { 9455 DeclarationNameInfo DirName; 9456 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName, 9457 nullptr, D->getBeginLoc()); 9458 auto Res = getDerived().TransformOMPExecutableDirective(D); 9459 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9460 return Res; 9461 } 9462 9463 template <typename Derived> 9464 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective( 9465 OMPTargetTeamsDistributeDirective *D) { 9466 DeclarationNameInfo DirName; 9467 getDerived().getSema().StartOpenMPDSABlock( 9468 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc()); 9469 auto Res = getDerived().TransformOMPExecutableDirective(D); 9470 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9471 return Res; 9472 } 9473 9474 template <typename Derived> 9475 StmtResult 9476 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective( 9477 OMPTargetTeamsDistributeParallelForDirective *D) { 9478 DeclarationNameInfo DirName; 9479 getDerived().getSema().StartOpenMPDSABlock( 9480 OMPD_target_teams_distribute_parallel_for, DirName, nullptr, 9481 D->getBeginLoc()); 9482 auto Res = getDerived().TransformOMPExecutableDirective(D); 9483 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9484 return Res; 9485 } 9486 9487 template <typename Derived> 9488 StmtResult TreeTransform<Derived>:: 9489 TransformOMPTargetTeamsDistributeParallelForSimdDirective( 9490 OMPTargetTeamsDistributeParallelForSimdDirective *D) { 9491 DeclarationNameInfo DirName; 9492 getDerived().getSema().StartOpenMPDSABlock( 9493 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr, 9494 D->getBeginLoc()); 9495 auto Res = getDerived().TransformOMPExecutableDirective(D); 9496 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9497 return Res; 9498 } 9499 9500 template <typename Derived> 9501 StmtResult 9502 TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective( 9503 OMPTargetTeamsDistributeSimdDirective *D) { 9504 DeclarationNameInfo DirName; 9505 getDerived().getSema().StartOpenMPDSABlock( 9506 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); 9507 auto Res = getDerived().TransformOMPExecutableDirective(D); 9508 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9509 return Res; 9510 } 9511 9512 template <typename Derived> 9513 StmtResult 9514 TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) { 9515 DeclarationNameInfo DirName; 9516 getDerived().getSema().StartOpenMPDSABlock(OMPD_interop, DirName, nullptr, 9517 D->getBeginLoc()); 9518 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9519 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9520 return Res; 9521 } 9522 9523 template <typename Derived> 9524 StmtResult 9525 TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) { 9526 DeclarationNameInfo DirName; 9527 getDerived().getSema().StartOpenMPDSABlock(OMPD_dispatch, DirName, nullptr, 9528 D->getBeginLoc()); 9529 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9530 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9531 return Res; 9532 } 9533 9534 template <typename Derived> 9535 StmtResult 9536 TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) { 9537 DeclarationNameInfo DirName; 9538 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked, DirName, nullptr, 9539 D->getBeginLoc()); 9540 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9541 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9542 return Res; 9543 } 9544 9545 template <typename Derived> 9546 StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective( 9547 OMPGenericLoopDirective *D) { 9548 DeclarationNameInfo DirName; 9549 getDerived().getSema().StartOpenMPDSABlock(OMPD_loop, DirName, nullptr, 9550 D->getBeginLoc()); 9551 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9552 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9553 return Res; 9554 } 9555 9556 template <typename Derived> 9557 StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective( 9558 OMPTeamsGenericLoopDirective *D) { 9559 DeclarationNameInfo DirName; 9560 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_loop, DirName, nullptr, 9561 D->getBeginLoc()); 9562 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9563 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9564 return Res; 9565 } 9566 9567 template <typename Derived> 9568 StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsGenericLoopDirective( 9569 OMPTargetTeamsGenericLoopDirective *D) { 9570 DeclarationNameInfo DirName; 9571 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_loop, DirName, 9572 nullptr, D->getBeginLoc()); 9573 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9574 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9575 return Res; 9576 } 9577 9578 template <typename Derived> 9579 StmtResult TreeTransform<Derived>::TransformOMPParallelGenericLoopDirective( 9580 OMPParallelGenericLoopDirective *D) { 9581 DeclarationNameInfo DirName; 9582 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_loop, DirName, 9583 nullptr, D->getBeginLoc()); 9584 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9585 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9586 return Res; 9587 } 9588 9589 template <typename Derived> 9590 StmtResult 9591 TreeTransform<Derived>::TransformOMPTargetParallelGenericLoopDirective( 9592 OMPTargetParallelGenericLoopDirective *D) { 9593 DeclarationNameInfo DirName; 9594 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_loop, DirName, 9595 nullptr, D->getBeginLoc()); 9596 StmtResult Res = getDerived().TransformOMPExecutableDirective(D); 9597 getDerived().getSema().EndOpenMPDSABlock(Res.get()); 9598 return Res; 9599 } 9600 9601 //===----------------------------------------------------------------------===// 9602 // OpenMP clause transformation 9603 //===----------------------------------------------------------------------===// 9604 template <typename Derived> 9605 OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { 9606 ExprResult Cond = getDerived().TransformExpr(C->getCondition()); 9607 if (Cond.isInvalid()) 9608 return nullptr; 9609 return getDerived().RebuildOMPIfClause( 9610 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(), 9611 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc()); 9612 } 9613 9614 template <typename Derived> 9615 OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { 9616 ExprResult Cond = getDerived().TransformExpr(C->getCondition()); 9617 if (Cond.isInvalid()) 9618 return nullptr; 9619 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(), 9620 C->getLParenLoc(), C->getEndLoc()); 9621 } 9622 9623 template <typename Derived> 9624 OMPClause * 9625 TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { 9626 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); 9627 if (NumThreads.isInvalid()) 9628 return nullptr; 9629 return getDerived().RebuildOMPNumThreadsClause( 9630 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9631 } 9632 9633 template <typename Derived> 9634 OMPClause * 9635 TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { 9636 ExprResult E = getDerived().TransformExpr(C->getSafelen()); 9637 if (E.isInvalid()) 9638 return nullptr; 9639 return getDerived().RebuildOMPSafelenClause( 9640 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9641 } 9642 9643 template <typename Derived> 9644 OMPClause * 9645 TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) { 9646 ExprResult E = getDerived().TransformExpr(C->getAllocator()); 9647 if (E.isInvalid()) 9648 return nullptr; 9649 return getDerived().RebuildOMPAllocatorClause( 9650 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9651 } 9652 9653 template <typename Derived> 9654 OMPClause * 9655 TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) { 9656 ExprResult E = getDerived().TransformExpr(C->getSimdlen()); 9657 if (E.isInvalid()) 9658 return nullptr; 9659 return getDerived().RebuildOMPSimdlenClause( 9660 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9661 } 9662 9663 template <typename Derived> 9664 OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) { 9665 SmallVector<Expr *, 4> TransformedSizes; 9666 TransformedSizes.reserve(C->getNumSizes()); 9667 bool Changed = false; 9668 for (Expr *E : C->getSizesRefs()) { 9669 if (!E) { 9670 TransformedSizes.push_back(nullptr); 9671 continue; 9672 } 9673 9674 ExprResult T = getDerived().TransformExpr(E); 9675 if (T.isInvalid()) 9676 return nullptr; 9677 if (E != T.get()) 9678 Changed = true; 9679 TransformedSizes.push_back(T.get()); 9680 } 9681 9682 if (!Changed && !getDerived().AlwaysRebuild()) 9683 return C; 9684 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(), 9685 C->getLParenLoc(), C->getEndLoc()); 9686 } 9687 9688 template <typename Derived> 9689 OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) { 9690 if (!getDerived().AlwaysRebuild()) 9691 return C; 9692 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc()); 9693 } 9694 9695 template <typename Derived> 9696 OMPClause * 9697 TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) { 9698 ExprResult T = getDerived().TransformExpr(C->getFactor()); 9699 if (T.isInvalid()) 9700 return nullptr; 9701 Expr *Factor = T.get(); 9702 bool Changed = Factor != C->getFactor(); 9703 9704 if (!Changed && !getDerived().AlwaysRebuild()) 9705 return C; 9706 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(), 9707 C->getEndLoc()); 9708 } 9709 9710 template <typename Derived> 9711 OMPClause * 9712 TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { 9713 ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); 9714 if (E.isInvalid()) 9715 return nullptr; 9716 return getDerived().RebuildOMPCollapseClause( 9717 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9718 } 9719 9720 template <typename Derived> 9721 OMPClause * 9722 TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { 9723 return getDerived().RebuildOMPDefaultClause( 9724 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(), 9725 C->getLParenLoc(), C->getEndLoc()); 9726 } 9727 9728 template <typename Derived> 9729 OMPClause * 9730 TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { 9731 return getDerived().RebuildOMPProcBindClause( 9732 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(), 9733 C->getLParenLoc(), C->getEndLoc()); 9734 } 9735 9736 template <typename Derived> 9737 OMPClause * 9738 TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { 9739 ExprResult E = getDerived().TransformExpr(C->getChunkSize()); 9740 if (E.isInvalid()) 9741 return nullptr; 9742 return getDerived().RebuildOMPScheduleClause( 9743 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(), 9744 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), 9745 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(), 9746 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); 9747 } 9748 9749 template <typename Derived> 9750 OMPClause * 9751 TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { 9752 ExprResult E; 9753 if (auto *Num = C->getNumForLoops()) { 9754 E = getDerived().TransformExpr(Num); 9755 if (E.isInvalid()) 9756 return nullptr; 9757 } 9758 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(), 9759 C->getLParenLoc(), E.get()); 9760 } 9761 9762 template <typename Derived> 9763 OMPClause * 9764 TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) { 9765 ExprResult E; 9766 if (Expr *Evt = C->getEventHandler()) { 9767 E = getDerived().TransformExpr(Evt); 9768 if (E.isInvalid()) 9769 return nullptr; 9770 } 9771 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(), 9772 C->getLParenLoc(), C->getEndLoc()); 9773 } 9774 9775 template <typename Derived> 9776 OMPClause * 9777 TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { 9778 // No need to rebuild this clause, no template-dependent parameters. 9779 return C; 9780 } 9781 9782 template <typename Derived> 9783 OMPClause * 9784 TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { 9785 // No need to rebuild this clause, no template-dependent parameters. 9786 return C; 9787 } 9788 9789 template <typename Derived> 9790 OMPClause * 9791 TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { 9792 // No need to rebuild this clause, no template-dependent parameters. 9793 return C; 9794 } 9795 9796 template <typename Derived> 9797 OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { 9798 // No need to rebuild this clause, no template-dependent parameters. 9799 return C; 9800 } 9801 9802 template <typename Derived> 9803 OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { 9804 // No need to rebuild this clause, no template-dependent parameters. 9805 return C; 9806 } 9807 9808 template <typename Derived> 9809 OMPClause * 9810 TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { 9811 // No need to rebuild this clause, no template-dependent parameters. 9812 return C; 9813 } 9814 9815 template <typename Derived> 9816 OMPClause * 9817 TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { 9818 // No need to rebuild this clause, no template-dependent parameters. 9819 return C; 9820 } 9821 9822 template <typename Derived> 9823 OMPClause * 9824 TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) { 9825 // No need to rebuild this clause, no template-dependent parameters. 9826 return C; 9827 } 9828 9829 template <typename Derived> 9830 OMPClause * 9831 TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { 9832 // No need to rebuild this clause, no template-dependent parameters. 9833 return C; 9834 } 9835 9836 template <typename Derived> 9837 OMPClause * 9838 TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) { 9839 // No need to rebuild this clause, no template-dependent parameters. 9840 return C; 9841 } 9842 9843 template <typename Derived> 9844 OMPClause * 9845 TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) { 9846 // No need to rebuild this clause, no template-dependent parameters. 9847 return C; 9848 } 9849 9850 template <typename Derived> 9851 OMPClause * 9852 TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) { 9853 // No need to rebuild this clause, no template-dependent parameters. 9854 return C; 9855 } 9856 9857 template <typename Derived> 9858 OMPClause * 9859 TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) { 9860 // No need to rebuild this clause, no template-dependent parameters. 9861 return C; 9862 } 9863 9864 template <typename Derived> 9865 OMPClause * 9866 TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) { 9867 // No need to rebuild this clause, no template-dependent parameters. 9868 return C; 9869 } 9870 9871 template <typename Derived> 9872 OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) { 9873 // No need to rebuild this clause, no template-dependent parameters. 9874 return C; 9875 } 9876 9877 template <typename Derived> 9878 OMPClause * 9879 TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) { 9880 // No need to rebuild this clause, no template-dependent parameters. 9881 return C; 9882 } 9883 9884 template <typename Derived> 9885 OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) { 9886 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar()); 9887 if (IVR.isInvalid()) 9888 return nullptr; 9889 9890 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync()); 9891 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1); 9892 for (Expr *E : llvm::drop_begin(C->varlists())) { 9893 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E)); 9894 if (ER.isInvalid()) 9895 return nullptr; 9896 InteropInfo.PreferTypes.push_back(ER.get()); 9897 } 9898 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo, 9899 C->getBeginLoc(), C->getLParenLoc(), 9900 C->getVarLoc(), C->getEndLoc()); 9901 } 9902 9903 template <typename Derived> 9904 OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) { 9905 ExprResult ER = getDerived().TransformExpr(C->getInteropVar()); 9906 if (ER.isInvalid()) 9907 return nullptr; 9908 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(), 9909 C->getLParenLoc(), C->getVarLoc(), 9910 C->getEndLoc()); 9911 } 9912 9913 template <typename Derived> 9914 OMPClause * 9915 TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) { 9916 ExprResult ER; 9917 if (Expr *IV = C->getInteropVar()) { 9918 ER = getDerived().TransformExpr(IV); 9919 if (ER.isInvalid()) 9920 return nullptr; 9921 } 9922 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(), 9923 C->getLParenLoc(), C->getVarLoc(), 9924 C->getEndLoc()); 9925 } 9926 9927 template <typename Derived> 9928 OMPClause * 9929 TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) { 9930 ExprResult Cond = getDerived().TransformExpr(C->getCondition()); 9931 if (Cond.isInvalid()) 9932 return nullptr; 9933 return getDerived().RebuildOMPNovariantsClause( 9934 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9935 } 9936 9937 template <typename Derived> 9938 OMPClause * 9939 TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) { 9940 ExprResult Cond = getDerived().TransformExpr(C->getCondition()); 9941 if (Cond.isInvalid()) 9942 return nullptr; 9943 return getDerived().RebuildOMPNocontextClause( 9944 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 9945 } 9946 9947 template <typename Derived> 9948 OMPClause * 9949 TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) { 9950 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID()); 9951 if (ThreadID.isInvalid()) 9952 return nullptr; 9953 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(), 9954 C->getLParenLoc(), C->getEndLoc()); 9955 } 9956 9957 template <typename Derived> 9958 OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) { 9959 ExprResult E = getDerived().TransformExpr(C->getAlignment()); 9960 if (E.isInvalid()) 9961 return nullptr; 9962 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(), 9963 C->getLParenLoc(), C->getEndLoc()); 9964 } 9965 9966 template <typename Derived> 9967 OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause( 9968 OMPUnifiedAddressClause *C) { 9969 llvm_unreachable("unified_address clause cannot appear in dependent context"); 9970 } 9971 9972 template <typename Derived> 9973 OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause( 9974 OMPUnifiedSharedMemoryClause *C) { 9975 llvm_unreachable( 9976 "unified_shared_memory clause cannot appear in dependent context"); 9977 } 9978 9979 template <typename Derived> 9980 OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause( 9981 OMPReverseOffloadClause *C) { 9982 llvm_unreachable("reverse_offload clause cannot appear in dependent context"); 9983 } 9984 9985 template <typename Derived> 9986 OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause( 9987 OMPDynamicAllocatorsClause *C) { 9988 llvm_unreachable( 9989 "dynamic_allocators clause cannot appear in dependent context"); 9990 } 9991 9992 template <typename Derived> 9993 OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause( 9994 OMPAtomicDefaultMemOrderClause *C) { 9995 llvm_unreachable( 9996 "atomic_default_mem_order clause cannot appear in dependent context"); 9997 } 9998 9999 template <typename Derived> 10000 OMPClause *TreeTransform<Derived>::TransformOMPAtClause(OMPAtClause *C) { 10001 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(), 10002 C->getBeginLoc(), C->getLParenLoc(), 10003 C->getEndLoc()); 10004 } 10005 10006 template <typename Derived> 10007 OMPClause * 10008 TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) { 10009 return getDerived().RebuildOMPSeverityClause( 10010 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(), 10011 C->getLParenLoc(), C->getEndLoc()); 10012 } 10013 10014 template <typename Derived> 10015 OMPClause * 10016 TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) { 10017 ExprResult E = getDerived().TransformExpr(C->getMessageString()); 10018 if (E.isInvalid()) 10019 return nullptr; 10020 return getDerived().RebuildOMPMessageClause( 10021 C->getMessageString(), C->getBeginLoc(), C->getLParenLoc(), 10022 C->getEndLoc()); 10023 } 10024 10025 template <typename Derived> 10026 OMPClause * 10027 TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { 10028 llvm::SmallVector<Expr *, 16> Vars; 10029 Vars.reserve(C->varlist_size()); 10030 for (auto *VE : C->varlists()) { 10031 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10032 if (EVar.isInvalid()) 10033 return nullptr; 10034 Vars.push_back(EVar.get()); 10035 } 10036 return getDerived().RebuildOMPPrivateClause( 10037 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10038 } 10039 10040 template <typename Derived> 10041 OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( 10042 OMPFirstprivateClause *C) { 10043 llvm::SmallVector<Expr *, 16> Vars; 10044 Vars.reserve(C->varlist_size()); 10045 for (auto *VE : C->varlists()) { 10046 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10047 if (EVar.isInvalid()) 10048 return nullptr; 10049 Vars.push_back(EVar.get()); 10050 } 10051 return getDerived().RebuildOMPFirstprivateClause( 10052 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10053 } 10054 10055 template <typename Derived> 10056 OMPClause * 10057 TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { 10058 llvm::SmallVector<Expr *, 16> Vars; 10059 Vars.reserve(C->varlist_size()); 10060 for (auto *VE : C->varlists()) { 10061 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10062 if (EVar.isInvalid()) 10063 return nullptr; 10064 Vars.push_back(EVar.get()); 10065 } 10066 return getDerived().RebuildOMPLastprivateClause( 10067 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(), 10068 C->getLParenLoc(), C->getEndLoc()); 10069 } 10070 10071 template <typename Derived> 10072 OMPClause * 10073 TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { 10074 llvm::SmallVector<Expr *, 16> Vars; 10075 Vars.reserve(C->varlist_size()); 10076 for (auto *VE : C->varlists()) { 10077 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10078 if (EVar.isInvalid()) 10079 return nullptr; 10080 Vars.push_back(EVar.get()); 10081 } 10082 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(), 10083 C->getLParenLoc(), C->getEndLoc()); 10084 } 10085 10086 template <typename Derived> 10087 OMPClause * 10088 TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { 10089 llvm::SmallVector<Expr *, 16> Vars; 10090 Vars.reserve(C->varlist_size()); 10091 for (auto *VE : C->varlists()) { 10092 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10093 if (EVar.isInvalid()) 10094 return nullptr; 10095 Vars.push_back(EVar.get()); 10096 } 10097 CXXScopeSpec ReductionIdScopeSpec; 10098 ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); 10099 10100 DeclarationNameInfo NameInfo = C->getNameInfo(); 10101 if (NameInfo.getName()) { 10102 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 10103 if (!NameInfo.getName()) 10104 return nullptr; 10105 } 10106 // Build a list of all UDR decls with the same names ranged by the Scopes. 10107 // The Scope boundary is a duplication of the previous decl. 10108 llvm::SmallVector<Expr *, 16> UnresolvedReductions; 10109 for (auto *E : C->reduction_ops()) { 10110 // Transform all the decls. 10111 if (E) { 10112 auto *ULE = cast<UnresolvedLookupExpr>(E); 10113 UnresolvedSet<8> Decls; 10114 for (auto *D : ULE->decls()) { 10115 NamedDecl *InstD = 10116 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); 10117 Decls.addDecl(InstD, InstD->getAccess()); 10118 } 10119 UnresolvedReductions.push_back( 10120 UnresolvedLookupExpr::Create( 10121 SemaRef.Context, /*NamingClass=*/nullptr, 10122 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), 10123 NameInfo, /*ADL=*/true, ULE->isOverloaded(), 10124 Decls.begin(), Decls.end())); 10125 } else 10126 UnresolvedReductions.push_back(nullptr); 10127 } 10128 return getDerived().RebuildOMPReductionClause( 10129 Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(), 10130 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(), 10131 ReductionIdScopeSpec, NameInfo, UnresolvedReductions); 10132 } 10133 10134 template <typename Derived> 10135 OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause( 10136 OMPTaskReductionClause *C) { 10137 llvm::SmallVector<Expr *, 16> Vars; 10138 Vars.reserve(C->varlist_size()); 10139 for (auto *VE : C->varlists()) { 10140 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10141 if (EVar.isInvalid()) 10142 return nullptr; 10143 Vars.push_back(EVar.get()); 10144 } 10145 CXXScopeSpec ReductionIdScopeSpec; 10146 ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); 10147 10148 DeclarationNameInfo NameInfo = C->getNameInfo(); 10149 if (NameInfo.getName()) { 10150 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 10151 if (!NameInfo.getName()) 10152 return nullptr; 10153 } 10154 // Build a list of all UDR decls with the same names ranged by the Scopes. 10155 // The Scope boundary is a duplication of the previous decl. 10156 llvm::SmallVector<Expr *, 16> UnresolvedReductions; 10157 for (auto *E : C->reduction_ops()) { 10158 // Transform all the decls. 10159 if (E) { 10160 auto *ULE = cast<UnresolvedLookupExpr>(E); 10161 UnresolvedSet<8> Decls; 10162 for (auto *D : ULE->decls()) { 10163 NamedDecl *InstD = 10164 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); 10165 Decls.addDecl(InstD, InstD->getAccess()); 10166 } 10167 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( 10168 SemaRef.Context, /*NamingClass=*/nullptr, 10169 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, 10170 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); 10171 } else 10172 UnresolvedReductions.push_back(nullptr); 10173 } 10174 return getDerived().RebuildOMPTaskReductionClause( 10175 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), 10176 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); 10177 } 10178 10179 template <typename Derived> 10180 OMPClause * 10181 TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) { 10182 llvm::SmallVector<Expr *, 16> Vars; 10183 Vars.reserve(C->varlist_size()); 10184 for (auto *VE : C->varlists()) { 10185 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10186 if (EVar.isInvalid()) 10187 return nullptr; 10188 Vars.push_back(EVar.get()); 10189 } 10190 CXXScopeSpec ReductionIdScopeSpec; 10191 ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); 10192 10193 DeclarationNameInfo NameInfo = C->getNameInfo(); 10194 if (NameInfo.getName()) { 10195 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 10196 if (!NameInfo.getName()) 10197 return nullptr; 10198 } 10199 // Build a list of all UDR decls with the same names ranged by the Scopes. 10200 // The Scope boundary is a duplication of the previous decl. 10201 llvm::SmallVector<Expr *, 16> UnresolvedReductions; 10202 for (auto *E : C->reduction_ops()) { 10203 // Transform all the decls. 10204 if (E) { 10205 auto *ULE = cast<UnresolvedLookupExpr>(E); 10206 UnresolvedSet<8> Decls; 10207 for (auto *D : ULE->decls()) { 10208 NamedDecl *InstD = 10209 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); 10210 Decls.addDecl(InstD, InstD->getAccess()); 10211 } 10212 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( 10213 SemaRef.Context, /*NamingClass=*/nullptr, 10214 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, 10215 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); 10216 } else 10217 UnresolvedReductions.push_back(nullptr); 10218 } 10219 return getDerived().RebuildOMPInReductionClause( 10220 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), 10221 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); 10222 } 10223 10224 template <typename Derived> 10225 OMPClause * 10226 TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { 10227 llvm::SmallVector<Expr *, 16> Vars; 10228 Vars.reserve(C->varlist_size()); 10229 for (auto *VE : C->varlists()) { 10230 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10231 if (EVar.isInvalid()) 10232 return nullptr; 10233 Vars.push_back(EVar.get()); 10234 } 10235 ExprResult Step = getDerived().TransformExpr(C->getStep()); 10236 if (Step.isInvalid()) 10237 return nullptr; 10238 return getDerived().RebuildOMPLinearClause( 10239 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(), 10240 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc()); 10241 } 10242 10243 template <typename Derived> 10244 OMPClause * 10245 TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { 10246 llvm::SmallVector<Expr *, 16> Vars; 10247 Vars.reserve(C->varlist_size()); 10248 for (auto *VE : C->varlists()) { 10249 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10250 if (EVar.isInvalid()) 10251 return nullptr; 10252 Vars.push_back(EVar.get()); 10253 } 10254 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); 10255 if (Alignment.isInvalid()) 10256 return nullptr; 10257 return getDerived().RebuildOMPAlignedClause( 10258 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(), 10259 C->getColonLoc(), C->getEndLoc()); 10260 } 10261 10262 template <typename Derived> 10263 OMPClause * 10264 TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { 10265 llvm::SmallVector<Expr *, 16> Vars; 10266 Vars.reserve(C->varlist_size()); 10267 for (auto *VE : C->varlists()) { 10268 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10269 if (EVar.isInvalid()) 10270 return nullptr; 10271 Vars.push_back(EVar.get()); 10272 } 10273 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(), 10274 C->getLParenLoc(), C->getEndLoc()); 10275 } 10276 10277 template <typename Derived> 10278 OMPClause * 10279 TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { 10280 llvm::SmallVector<Expr *, 16> Vars; 10281 Vars.reserve(C->varlist_size()); 10282 for (auto *VE : C->varlists()) { 10283 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10284 if (EVar.isInvalid()) 10285 return nullptr; 10286 Vars.push_back(EVar.get()); 10287 } 10288 return getDerived().RebuildOMPCopyprivateClause( 10289 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10290 } 10291 10292 template <typename Derived> 10293 OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { 10294 llvm::SmallVector<Expr *, 16> Vars; 10295 Vars.reserve(C->varlist_size()); 10296 for (auto *VE : C->varlists()) { 10297 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10298 if (EVar.isInvalid()) 10299 return nullptr; 10300 Vars.push_back(EVar.get()); 10301 } 10302 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(), 10303 C->getLParenLoc(), C->getEndLoc()); 10304 } 10305 10306 template <typename Derived> 10307 OMPClause * 10308 TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) { 10309 ExprResult E = getDerived().TransformExpr(C->getDepobj()); 10310 if (E.isInvalid()) 10311 return nullptr; 10312 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(), 10313 C->getLParenLoc(), C->getEndLoc()); 10314 } 10315 10316 template <typename Derived> 10317 OMPClause * 10318 TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { 10319 llvm::SmallVector<Expr *, 16> Vars; 10320 Expr *DepModifier = C->getModifier(); 10321 if (DepModifier) { 10322 ExprResult DepModRes = getDerived().TransformExpr(DepModifier); 10323 if (DepModRes.isInvalid()) 10324 return nullptr; 10325 DepModifier = DepModRes.get(); 10326 } 10327 Vars.reserve(C->varlist_size()); 10328 for (auto *VE : C->varlists()) { 10329 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10330 if (EVar.isInvalid()) 10331 return nullptr; 10332 Vars.push_back(EVar.get()); 10333 } 10334 return getDerived().RebuildOMPDependClause( 10335 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), 10336 C->getOmpAllMemoryLoc()}, 10337 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10338 } 10339 10340 template <typename Derived> 10341 OMPClause * 10342 TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { 10343 ExprResult E = getDerived().TransformExpr(C->getDevice()); 10344 if (E.isInvalid()) 10345 return nullptr; 10346 return getDerived().RebuildOMPDeviceClause( 10347 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(), 10348 C->getModifierLoc(), C->getEndLoc()); 10349 } 10350 10351 template <typename Derived, class T> 10352 bool transformOMPMappableExprListClause( 10353 TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C, 10354 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec, 10355 DeclarationNameInfo &MapperIdInfo, 10356 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) { 10357 // Transform expressions in the list. 10358 Vars.reserve(C->varlist_size()); 10359 for (auto *VE : C->varlists()) { 10360 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE)); 10361 if (EVar.isInvalid()) 10362 return true; 10363 Vars.push_back(EVar.get()); 10364 } 10365 // Transform mapper scope specifier and identifier. 10366 NestedNameSpecifierLoc QualifierLoc; 10367 if (C->getMapperQualifierLoc()) { 10368 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc( 10369 C->getMapperQualifierLoc()); 10370 if (!QualifierLoc) 10371 return true; 10372 } 10373 MapperIdScopeSpec.Adopt(QualifierLoc); 10374 MapperIdInfo = C->getMapperIdInfo(); 10375 if (MapperIdInfo.getName()) { 10376 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo); 10377 if (!MapperIdInfo.getName()) 10378 return true; 10379 } 10380 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by 10381 // the previous user-defined mapper lookup in dependent environment. 10382 for (auto *E : C->mapperlists()) { 10383 // Transform all the decls. 10384 if (E) { 10385 auto *ULE = cast<UnresolvedLookupExpr>(E); 10386 UnresolvedSet<8> Decls; 10387 for (auto *D : ULE->decls()) { 10388 NamedDecl *InstD = 10389 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D)); 10390 Decls.addDecl(InstD, InstD->getAccess()); 10391 } 10392 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create( 10393 TT.getSema().Context, /*NamingClass=*/nullptr, 10394 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context), 10395 MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), 10396 Decls.end())); 10397 } else { 10398 UnresolvedMappers.push_back(nullptr); 10399 } 10400 } 10401 return false; 10402 } 10403 10404 template <typename Derived> 10405 OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) { 10406 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10407 llvm::SmallVector<Expr *, 16> Vars; 10408 Expr *IteratorModifier = C->getIteratorModifier(); 10409 if (IteratorModifier) { 10410 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier); 10411 if (MapModRes.isInvalid()) 10412 return nullptr; 10413 IteratorModifier = MapModRes.get(); 10414 } 10415 CXXScopeSpec MapperIdScopeSpec; 10416 DeclarationNameInfo MapperIdInfo; 10417 llvm::SmallVector<Expr *, 16> UnresolvedMappers; 10418 if (transformOMPMappableExprListClause<Derived, OMPMapClause>( 10419 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) 10420 return nullptr; 10421 return getDerived().RebuildOMPMapClause( 10422 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), 10423 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(), 10424 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers); 10425 } 10426 10427 template <typename Derived> 10428 OMPClause * 10429 TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) { 10430 Expr *Allocator = C->getAllocator(); 10431 if (Allocator) { 10432 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator); 10433 if (AllocatorRes.isInvalid()) 10434 return nullptr; 10435 Allocator = AllocatorRes.get(); 10436 } 10437 llvm::SmallVector<Expr *, 16> Vars; 10438 Vars.reserve(C->varlist_size()); 10439 for (auto *VE : C->varlists()) { 10440 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10441 if (EVar.isInvalid()) 10442 return nullptr; 10443 Vars.push_back(EVar.get()); 10444 } 10445 return getDerived().RebuildOMPAllocateClause( 10446 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), 10447 C->getEndLoc()); 10448 } 10449 10450 template <typename Derived> 10451 OMPClause * 10452 TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) { 10453 ExprResult E = getDerived().TransformExpr(C->getNumTeams()); 10454 if (E.isInvalid()) 10455 return nullptr; 10456 return getDerived().RebuildOMPNumTeamsClause( 10457 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10458 } 10459 10460 template <typename Derived> 10461 OMPClause * 10462 TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) { 10463 ExprResult E = getDerived().TransformExpr(C->getThreadLimit()); 10464 if (E.isInvalid()) 10465 return nullptr; 10466 return getDerived().RebuildOMPThreadLimitClause( 10467 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10468 } 10469 10470 template <typename Derived> 10471 OMPClause * 10472 TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) { 10473 ExprResult E = getDerived().TransformExpr(C->getPriority()); 10474 if (E.isInvalid()) 10475 return nullptr; 10476 return getDerived().RebuildOMPPriorityClause( 10477 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10478 } 10479 10480 template <typename Derived> 10481 OMPClause * 10482 TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) { 10483 ExprResult E = getDerived().TransformExpr(C->getGrainsize()); 10484 if (E.isInvalid()) 10485 return nullptr; 10486 return getDerived().RebuildOMPGrainsizeClause( 10487 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(), 10488 C->getModifierLoc(), C->getEndLoc()); 10489 } 10490 10491 template <typename Derived> 10492 OMPClause * 10493 TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) { 10494 ExprResult E = getDerived().TransformExpr(C->getNumTasks()); 10495 if (E.isInvalid()) 10496 return nullptr; 10497 return getDerived().RebuildOMPNumTasksClause( 10498 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(), 10499 C->getModifierLoc(), C->getEndLoc()); 10500 } 10501 10502 template <typename Derived> 10503 OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) { 10504 ExprResult E = getDerived().TransformExpr(C->getHint()); 10505 if (E.isInvalid()) 10506 return nullptr; 10507 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(), 10508 C->getLParenLoc(), C->getEndLoc()); 10509 } 10510 10511 template <typename Derived> 10512 OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause( 10513 OMPDistScheduleClause *C) { 10514 ExprResult E = getDerived().TransformExpr(C->getChunkSize()); 10515 if (E.isInvalid()) 10516 return nullptr; 10517 return getDerived().RebuildOMPDistScheduleClause( 10518 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), 10519 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); 10520 } 10521 10522 template <typename Derived> 10523 OMPClause * 10524 TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) { 10525 // Rebuild Defaultmap Clause since we need to invoke the checking of 10526 // defaultmap(none:variable-category) after template initialization. 10527 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(), 10528 C->getDefaultmapKind(), 10529 C->getBeginLoc(), 10530 C->getLParenLoc(), 10531 C->getDefaultmapModifierLoc(), 10532 C->getDefaultmapKindLoc(), 10533 C->getEndLoc()); 10534 } 10535 10536 template <typename Derived> 10537 OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) { 10538 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10539 llvm::SmallVector<Expr *, 16> Vars; 10540 CXXScopeSpec MapperIdScopeSpec; 10541 DeclarationNameInfo MapperIdInfo; 10542 llvm::SmallVector<Expr *, 16> UnresolvedMappers; 10543 if (transformOMPMappableExprListClause<Derived, OMPToClause>( 10544 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) 10545 return nullptr; 10546 return getDerived().RebuildOMPToClause( 10547 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec, 10548 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers); 10549 } 10550 10551 template <typename Derived> 10552 OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) { 10553 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10554 llvm::SmallVector<Expr *, 16> Vars; 10555 CXXScopeSpec MapperIdScopeSpec; 10556 DeclarationNameInfo MapperIdInfo; 10557 llvm::SmallVector<Expr *, 16> UnresolvedMappers; 10558 if (transformOMPMappableExprListClause<Derived, OMPFromClause>( 10559 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) 10560 return nullptr; 10561 return getDerived().RebuildOMPFromClause( 10562 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec, 10563 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers); 10564 } 10565 10566 template <typename Derived> 10567 OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause( 10568 OMPUseDevicePtrClause *C) { 10569 llvm::SmallVector<Expr *, 16> Vars; 10570 Vars.reserve(C->varlist_size()); 10571 for (auto *VE : C->varlists()) { 10572 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10573 if (EVar.isInvalid()) 10574 return nullptr; 10575 Vars.push_back(EVar.get()); 10576 } 10577 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10578 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs); 10579 } 10580 10581 template <typename Derived> 10582 OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause( 10583 OMPUseDeviceAddrClause *C) { 10584 llvm::SmallVector<Expr *, 16> Vars; 10585 Vars.reserve(C->varlist_size()); 10586 for (auto *VE : C->varlists()) { 10587 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10588 if (EVar.isInvalid()) 10589 return nullptr; 10590 Vars.push_back(EVar.get()); 10591 } 10592 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10593 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs); 10594 } 10595 10596 template <typename Derived> 10597 OMPClause * 10598 TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { 10599 llvm::SmallVector<Expr *, 16> Vars; 10600 Vars.reserve(C->varlist_size()); 10601 for (auto *VE : C->varlists()) { 10602 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10603 if (EVar.isInvalid()) 10604 return nullptr; 10605 Vars.push_back(EVar.get()); 10606 } 10607 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10608 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs); 10609 } 10610 10611 template <typename Derived> 10612 OMPClause *TreeTransform<Derived>::TransformOMPHasDeviceAddrClause( 10613 OMPHasDeviceAddrClause *C) { 10614 llvm::SmallVector<Expr *, 16> Vars; 10615 Vars.reserve(C->varlist_size()); 10616 for (auto *VE : C->varlists()) { 10617 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10618 if (EVar.isInvalid()) 10619 return nullptr; 10620 Vars.push_back(EVar.get()); 10621 } 10622 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10623 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs); 10624 } 10625 10626 template <typename Derived> 10627 OMPClause * 10628 TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) { 10629 llvm::SmallVector<Expr *, 16> Vars; 10630 Vars.reserve(C->varlist_size()); 10631 for (auto *VE : C->varlists()) { 10632 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10633 if (EVar.isInvalid()) 10634 return nullptr; 10635 Vars.push_back(EVar.get()); 10636 } 10637 return getDerived().RebuildOMPNontemporalClause( 10638 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10639 } 10640 10641 template <typename Derived> 10642 OMPClause * 10643 TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) { 10644 llvm::SmallVector<Expr *, 16> Vars; 10645 Vars.reserve(C->varlist_size()); 10646 for (auto *VE : C->varlists()) { 10647 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10648 if (EVar.isInvalid()) 10649 return nullptr; 10650 Vars.push_back(EVar.get()); 10651 } 10652 return getDerived().RebuildOMPInclusiveClause( 10653 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10654 } 10655 10656 template <typename Derived> 10657 OMPClause * 10658 TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) { 10659 llvm::SmallVector<Expr *, 16> Vars; 10660 Vars.reserve(C->varlist_size()); 10661 for (auto *VE : C->varlists()) { 10662 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10663 if (EVar.isInvalid()) 10664 return nullptr; 10665 Vars.push_back(EVar.get()); 10666 } 10667 return getDerived().RebuildOMPExclusiveClause( 10668 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10669 } 10670 10671 template <typename Derived> 10672 OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause( 10673 OMPUsesAllocatorsClause *C) { 10674 SmallVector<Sema::UsesAllocatorsData, 16> Data; 10675 Data.reserve(C->getNumberOfAllocators()); 10676 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) { 10677 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I); 10678 ExprResult Allocator = getDerived().TransformExpr(D.Allocator); 10679 if (Allocator.isInvalid()) 10680 continue; 10681 ExprResult AllocatorTraits; 10682 if (Expr *AT = D.AllocatorTraits) { 10683 AllocatorTraits = getDerived().TransformExpr(AT); 10684 if (AllocatorTraits.isInvalid()) 10685 continue; 10686 } 10687 Sema::UsesAllocatorsData &NewD = Data.emplace_back(); 10688 NewD.Allocator = Allocator.get(); 10689 NewD.AllocatorTraits = AllocatorTraits.get(); 10690 NewD.LParenLoc = D.LParenLoc; 10691 NewD.RParenLoc = D.RParenLoc; 10692 } 10693 return getDerived().RebuildOMPUsesAllocatorsClause( 10694 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10695 } 10696 10697 template <typename Derived> 10698 OMPClause * 10699 TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) { 10700 SmallVector<Expr *, 4> Locators; 10701 Locators.reserve(C->varlist_size()); 10702 ExprResult ModifierRes; 10703 if (Expr *Modifier = C->getModifier()) { 10704 ModifierRes = getDerived().TransformExpr(Modifier); 10705 if (ModifierRes.isInvalid()) 10706 return nullptr; 10707 } 10708 for (Expr *E : C->varlists()) { 10709 ExprResult Locator = getDerived().TransformExpr(E); 10710 if (Locator.isInvalid()) 10711 continue; 10712 Locators.push_back(Locator.get()); 10713 } 10714 return getDerived().RebuildOMPAffinityClause( 10715 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(), 10716 ModifierRes.get(), Locators); 10717 } 10718 10719 template <typename Derived> 10720 OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) { 10721 return getDerived().RebuildOMPOrderClause( 10722 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(), 10723 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc()); 10724 } 10725 10726 template <typename Derived> 10727 OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) { 10728 return getDerived().RebuildOMPBindClause( 10729 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(), 10730 C->getLParenLoc(), C->getEndLoc()); 10731 } 10732 10733 template <typename Derived> 10734 OMPClause *TreeTransform<Derived>::TransformOMPXDynCGroupMemClause( 10735 OMPXDynCGroupMemClause *C) { 10736 ExprResult Size = getDerived().TransformExpr(C->getSize()); 10737 if (Size.isInvalid()) 10738 return nullptr; 10739 return getDerived().RebuildOMPXDynCGroupMemClause( 10740 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10741 } 10742 10743 template <typename Derived> 10744 OMPClause * 10745 TreeTransform<Derived>::TransformOMPDoacrossClause(OMPDoacrossClause *C) { 10746 llvm::SmallVector<Expr *, 16> Vars; 10747 Vars.reserve(C->varlist_size()); 10748 for (auto *VE : C->varlists()) { 10749 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); 10750 if (EVar.isInvalid()) 10751 return nullptr; 10752 Vars.push_back(EVar.get()); 10753 } 10754 return getDerived().RebuildOMPDoacrossClause( 10755 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars, 10756 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); 10757 } 10758 10759 //===----------------------------------------------------------------------===// 10760 // Expression transformation 10761 //===----------------------------------------------------------------------===// 10762 template<typename Derived> 10763 ExprResult 10764 TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) { 10765 return TransformExpr(E->getSubExpr()); 10766 } 10767 10768 template <typename Derived> 10769 ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr( 10770 SYCLUniqueStableNameExpr *E) { 10771 if (!E->isTypeDependent()) 10772 return E; 10773 10774 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo()); 10775 10776 if (!NewT) 10777 return ExprError(); 10778 10779 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT) 10780 return E; 10781 10782 return getDerived().RebuildSYCLUniqueStableNameExpr( 10783 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT); 10784 } 10785 10786 template<typename Derived> 10787 ExprResult 10788 TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 10789 if (!E->isTypeDependent()) 10790 return E; 10791 10792 return getDerived().RebuildPredefinedExpr(E->getLocation(), 10793 E->getIdentKind()); 10794 } 10795 10796 template<typename Derived> 10797 ExprResult 10798 TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 10799 NestedNameSpecifierLoc QualifierLoc; 10800 if (E->getQualifierLoc()) { 10801 QualifierLoc 10802 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 10803 if (!QualifierLoc) 10804 return ExprError(); 10805 } 10806 10807 ValueDecl *ND 10808 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 10809 E->getDecl())); 10810 if (!ND) 10811 return ExprError(); 10812 10813 NamedDecl *Found = ND; 10814 if (E->getFoundDecl() != E->getDecl()) { 10815 Found = cast_or_null<NamedDecl>( 10816 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl())); 10817 if (!Found) 10818 return ExprError(); 10819 } 10820 10821 DeclarationNameInfo NameInfo = E->getNameInfo(); 10822 if (NameInfo.getName()) { 10823 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 10824 if (!NameInfo.getName()) 10825 return ExprError(); 10826 } 10827 10828 if (!getDerived().AlwaysRebuild() && 10829 QualifierLoc == E->getQualifierLoc() && 10830 ND == E->getDecl() && 10831 Found == E->getFoundDecl() && 10832 NameInfo.getName() == E->getDecl()->getDeclName() && 10833 !E->hasExplicitTemplateArgs()) { 10834 10835 // Mark it referenced in the new context regardless. 10836 // FIXME: this is a bit instantiation-specific. 10837 SemaRef.MarkDeclRefReferenced(E); 10838 10839 return E; 10840 } 10841 10842 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; 10843 if (E->hasExplicitTemplateArgs()) { 10844 TemplateArgs = &TransArgs; 10845 TransArgs.setLAngleLoc(E->getLAngleLoc()); 10846 TransArgs.setRAngleLoc(E->getRAngleLoc()); 10847 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 10848 E->getNumTemplateArgs(), 10849 TransArgs)) 10850 return ExprError(); 10851 } 10852 10853 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, 10854 Found, TemplateArgs); 10855 } 10856 10857 template<typename Derived> 10858 ExprResult 10859 TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 10860 return E; 10861 } 10862 10863 template <typename Derived> 10864 ExprResult TreeTransform<Derived>::TransformFixedPointLiteral( 10865 FixedPointLiteral *E) { 10866 return E; 10867 } 10868 10869 template<typename Derived> 10870 ExprResult 10871 TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 10872 return E; 10873 } 10874 10875 template<typename Derived> 10876 ExprResult 10877 TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 10878 return E; 10879 } 10880 10881 template<typename Derived> 10882 ExprResult 10883 TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 10884 return E; 10885 } 10886 10887 template<typename Derived> 10888 ExprResult 10889 TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 10890 return E; 10891 } 10892 10893 template<typename Derived> 10894 ExprResult 10895 TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { 10896 return getDerived().TransformCallExpr(E); 10897 } 10898 10899 template<typename Derived> 10900 ExprResult 10901 TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { 10902 ExprResult ControllingExpr; 10903 TypeSourceInfo *ControllingType = nullptr; 10904 if (E->isExprPredicate()) 10905 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr()); 10906 else 10907 ControllingType = getDerived().TransformType(E->getControllingType()); 10908 10909 if (ControllingExpr.isInvalid() && !ControllingType) 10910 return ExprError(); 10911 10912 SmallVector<Expr *, 4> AssocExprs; 10913 SmallVector<TypeSourceInfo *, 4> AssocTypes; 10914 for (const GenericSelectionExpr::Association Assoc : E->associations()) { 10915 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo(); 10916 if (TSI) { 10917 TypeSourceInfo *AssocType = getDerived().TransformType(TSI); 10918 if (!AssocType) 10919 return ExprError(); 10920 AssocTypes.push_back(AssocType); 10921 } else { 10922 AssocTypes.push_back(nullptr); 10923 } 10924 10925 ExprResult AssocExpr = 10926 getDerived().TransformExpr(Assoc.getAssociationExpr()); 10927 if (AssocExpr.isInvalid()) 10928 return ExprError(); 10929 AssocExprs.push_back(AssocExpr.get()); 10930 } 10931 10932 if (!ControllingType) 10933 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), 10934 E->getDefaultLoc(), 10935 E->getRParenLoc(), 10936 ControllingExpr.get(), 10937 AssocTypes, 10938 AssocExprs); 10939 return getDerived().RebuildGenericSelectionExpr( 10940 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(), 10941 ControllingType, AssocTypes, AssocExprs); 10942 } 10943 10944 template<typename Derived> 10945 ExprResult 10946 TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 10947 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 10948 if (SubExpr.isInvalid()) 10949 return ExprError(); 10950 10951 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 10952 return E; 10953 10954 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 10955 E->getRParen()); 10956 } 10957 10958 /// The operand of a unary address-of operator has special rules: it's 10959 /// allowed to refer to a non-static member of a class even if there's no 'this' 10960 /// object available. 10961 template<typename Derived> 10962 ExprResult 10963 TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { 10964 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) 10965 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); 10966 else 10967 return getDerived().TransformExpr(E); 10968 } 10969 10970 template<typename Derived> 10971 ExprResult 10972 TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 10973 ExprResult SubExpr; 10974 if (E->getOpcode() == UO_AddrOf) 10975 SubExpr = TransformAddressOfOperand(E->getSubExpr()); 10976 else 10977 SubExpr = TransformExpr(E->getSubExpr()); 10978 if (SubExpr.isInvalid()) 10979 return ExprError(); 10980 10981 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 10982 return E; 10983 10984 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 10985 E->getOpcode(), 10986 SubExpr.get()); 10987 } 10988 10989 template<typename Derived> 10990 ExprResult 10991 TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 10992 // Transform the type. 10993 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 10994 if (!Type) 10995 return ExprError(); 10996 10997 // Transform all of the components into components similar to what the 10998 // parser uses. 10999 // FIXME: It would be slightly more efficient in the non-dependent case to 11000 // just map FieldDecls, rather than requiring the rebuilder to look for 11001 // the fields again. However, __builtin_offsetof is rare enough in 11002 // template code that we don't care. 11003 bool ExprChanged = false; 11004 typedef Sema::OffsetOfComponent Component; 11005 SmallVector<Component, 4> Components; 11006 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 11007 const OffsetOfNode &ON = E->getComponent(I); 11008 Component Comp; 11009 Comp.isBrackets = true; 11010 Comp.LocStart = ON.getSourceRange().getBegin(); 11011 Comp.LocEnd = ON.getSourceRange().getEnd(); 11012 switch (ON.getKind()) { 11013 case OffsetOfNode::Array: { 11014 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 11015 ExprResult Index = getDerived().TransformExpr(FromIndex); 11016 if (Index.isInvalid()) 11017 return ExprError(); 11018 11019 ExprChanged = ExprChanged || Index.get() != FromIndex; 11020 Comp.isBrackets = true; 11021 Comp.U.E = Index.get(); 11022 break; 11023 } 11024 11025 case OffsetOfNode::Field: 11026 case OffsetOfNode::Identifier: 11027 Comp.isBrackets = false; 11028 Comp.U.IdentInfo = ON.getFieldName(); 11029 if (!Comp.U.IdentInfo) 11030 continue; 11031 11032 break; 11033 11034 case OffsetOfNode::Base: 11035 // Will be recomputed during the rebuild. 11036 continue; 11037 } 11038 11039 Components.push_back(Comp); 11040 } 11041 11042 // If nothing changed, retain the existing expression. 11043 if (!getDerived().AlwaysRebuild() && 11044 Type == E->getTypeSourceInfo() && 11045 !ExprChanged) 11046 return E; 11047 11048 // Build a new offsetof expression. 11049 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 11050 Components, E->getRParenLoc()); 11051 } 11052 11053 template<typename Derived> 11054 ExprResult 11055 TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 11056 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) && 11057 "opaque value expression requires transformation"); 11058 return E; 11059 } 11060 11061 template<typename Derived> 11062 ExprResult 11063 TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { 11064 return E; 11065 } 11066 11067 template <typename Derived> 11068 ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) { 11069 llvm::SmallVector<Expr *, 8> Children; 11070 bool Changed = false; 11071 for (Expr *C : E->subExpressions()) { 11072 ExprResult NewC = getDerived().TransformExpr(C); 11073 if (NewC.isInvalid()) 11074 return ExprError(); 11075 Children.push_back(NewC.get()); 11076 11077 Changed |= NewC.get() != C; 11078 } 11079 if (!getDerived().AlwaysRebuild() && !Changed) 11080 return E; 11081 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(), 11082 Children, E->getType()); 11083 } 11084 11085 template<typename Derived> 11086 ExprResult 11087 TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { 11088 // Rebuild the syntactic form. The original syntactic form has 11089 // opaque-value expressions in it, so strip those away and rebuild 11090 // the result. This is a really awful way of doing this, but the 11091 // better solution (rebuilding the semantic expressions and 11092 // rebinding OVEs as necessary) doesn't work; we'd need 11093 // TreeTransform to not strip away implicit conversions. 11094 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); 11095 ExprResult result = getDerived().TransformExpr(newSyntacticForm); 11096 if (result.isInvalid()) return ExprError(); 11097 11098 // If that gives us a pseudo-object result back, the pseudo-object 11099 // expression must have been an lvalue-to-rvalue conversion which we 11100 // should reapply. 11101 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) 11102 result = SemaRef.checkPseudoObjectRValue(result.get()); 11103 11104 return result; 11105 } 11106 11107 template<typename Derived> 11108 ExprResult 11109 TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( 11110 UnaryExprOrTypeTraitExpr *E) { 11111 if (E->isArgumentType()) { 11112 TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 11113 11114 TypeSourceInfo *NewT = getDerived().TransformType(OldT); 11115 if (!NewT) 11116 return ExprError(); 11117 11118 if (!getDerived().AlwaysRebuild() && OldT == NewT) 11119 return E; 11120 11121 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), 11122 E->getKind(), 11123 E->getSourceRange()); 11124 } 11125 11126 // C++0x [expr.sizeof]p1: 11127 // The operand is either an expression, which is an unevaluated operand 11128 // [...] 11129 EnterExpressionEvaluationContext Unevaluated( 11130 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, 11131 Sema::ReuseLambdaContextDecl); 11132 11133 // Try to recover if we have something like sizeof(T::X) where X is a type. 11134 // Notably, there must be *exactly* one set of parens if X is a type. 11135 TypeSourceInfo *RecoveryTSI = nullptr; 11136 ExprResult SubExpr; 11137 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); 11138 if (auto *DRE = 11139 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) 11140 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( 11141 PE, DRE, false, &RecoveryTSI); 11142 else 11143 SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 11144 11145 if (RecoveryTSI) { 11146 return getDerived().RebuildUnaryExprOrTypeTrait( 11147 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); 11148 } else if (SubExpr.isInvalid()) 11149 return ExprError(); 11150 11151 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 11152 return E; 11153 11154 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), 11155 E->getOperatorLoc(), 11156 E->getKind(), 11157 E->getSourceRange()); 11158 } 11159 11160 template<typename Derived> 11161 ExprResult 11162 TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 11163 ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 11164 if (LHS.isInvalid()) 11165 return ExprError(); 11166 11167 ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 11168 if (RHS.isInvalid()) 11169 return ExprError(); 11170 11171 11172 if (!getDerived().AlwaysRebuild() && 11173 LHS.get() == E->getLHS() && 11174 RHS.get() == E->getRHS()) 11175 return E; 11176 11177 return getDerived().RebuildArraySubscriptExpr( 11178 LHS.get(), 11179 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc()); 11180 } 11181 11182 template <typename Derived> 11183 ExprResult 11184 TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) { 11185 ExprResult Base = getDerived().TransformExpr(E->getBase()); 11186 if (Base.isInvalid()) 11187 return ExprError(); 11188 11189 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx()); 11190 if (RowIdx.isInvalid()) 11191 return ExprError(); 11192 11193 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx()); 11194 if (ColumnIdx.isInvalid()) 11195 return ExprError(); 11196 11197 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && 11198 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx()) 11199 return E; 11200 11201 return getDerived().RebuildMatrixSubscriptExpr( 11202 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc()); 11203 } 11204 11205 template <typename Derived> 11206 ExprResult 11207 TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) { 11208 ExprResult Base = getDerived().TransformExpr(E->getBase()); 11209 if (Base.isInvalid()) 11210 return ExprError(); 11211 11212 ExprResult LowerBound; 11213 if (E->getLowerBound()) { 11214 LowerBound = getDerived().TransformExpr(E->getLowerBound()); 11215 if (LowerBound.isInvalid()) 11216 return ExprError(); 11217 } 11218 11219 ExprResult Length; 11220 if (E->getLength()) { 11221 Length = getDerived().TransformExpr(E->getLength()); 11222 if (Length.isInvalid()) 11223 return ExprError(); 11224 } 11225 11226 ExprResult Stride; 11227 if (Expr *Str = E->getStride()) { 11228 Stride = getDerived().TransformExpr(Str); 11229 if (Stride.isInvalid()) 11230 return ExprError(); 11231 } 11232 11233 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && 11234 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength()) 11235 return E; 11236 11237 return getDerived().RebuildOMPArraySectionExpr( 11238 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), 11239 E->getColonLocFirst(), E->getColonLocSecond(), Length.get(), Stride.get(), 11240 E->getRBracketLoc()); 11241 } 11242 11243 template <typename Derived> 11244 ExprResult 11245 TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) { 11246 ExprResult Base = getDerived().TransformExpr(E->getBase()); 11247 if (Base.isInvalid()) 11248 return ExprError(); 11249 11250 SmallVector<Expr *, 4> Dims; 11251 bool ErrorFound = false; 11252 for (Expr *Dim : E->getDimensions()) { 11253 ExprResult DimRes = getDerived().TransformExpr(Dim); 11254 if (DimRes.isInvalid()) { 11255 ErrorFound = true; 11256 continue; 11257 } 11258 Dims.push_back(DimRes.get()); 11259 } 11260 11261 if (ErrorFound) 11262 return ExprError(); 11263 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(), 11264 E->getRParenLoc(), Dims, 11265 E->getBracketsRanges()); 11266 } 11267 11268 template <typename Derived> 11269 ExprResult 11270 TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) { 11271 unsigned NumIterators = E->numOfIterators(); 11272 SmallVector<Sema::OMPIteratorData, 4> Data(NumIterators); 11273 11274 bool ErrorFound = false; 11275 bool NeedToRebuild = getDerived().AlwaysRebuild(); 11276 for (unsigned I = 0; I < NumIterators; ++I) { 11277 auto *D = cast<VarDecl>(E->getIteratorDecl(I)); 11278 Data[I].DeclIdent = D->getIdentifier(); 11279 Data[I].DeclIdentLoc = D->getLocation(); 11280 if (D->getLocation() == D->getBeginLoc()) { 11281 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) && 11282 "Implicit type must be int."); 11283 } else { 11284 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo()); 11285 QualType DeclTy = getDerived().TransformType(D->getType()); 11286 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI); 11287 } 11288 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I); 11289 ExprResult Begin = getDerived().TransformExpr(Range.Begin); 11290 ExprResult End = getDerived().TransformExpr(Range.End); 11291 ExprResult Step = getDerived().TransformExpr(Range.Step); 11292 ErrorFound = ErrorFound || 11293 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() && 11294 !Data[I].Type.get().isNull())) || 11295 Begin.isInvalid() || End.isInvalid() || Step.isInvalid(); 11296 if (ErrorFound) 11297 continue; 11298 Data[I].Range.Begin = Begin.get(); 11299 Data[I].Range.End = End.get(); 11300 Data[I].Range.Step = Step.get(); 11301 Data[I].AssignLoc = E->getAssignLoc(I); 11302 Data[I].ColonLoc = E->getColonLoc(I); 11303 Data[I].SecColonLoc = E->getSecondColonLoc(I); 11304 NeedToRebuild = 11305 NeedToRebuild || 11306 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() != 11307 D->getType().getTypePtrOrNull()) || 11308 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End || 11309 Range.Step != Data[I].Range.Step; 11310 } 11311 if (ErrorFound) 11312 return ExprError(); 11313 if (!NeedToRebuild) 11314 return E; 11315 11316 ExprResult Res = getDerived().RebuildOMPIteratorExpr( 11317 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data); 11318 if (!Res.isUsable()) 11319 return Res; 11320 auto *IE = cast<OMPIteratorExpr>(Res.get()); 11321 for (unsigned I = 0; I < NumIterators; ++I) 11322 getDerived().transformedLocalDecl(E->getIteratorDecl(I), 11323 IE->getIteratorDecl(I)); 11324 return Res; 11325 } 11326 11327 template<typename Derived> 11328 ExprResult 11329 TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 11330 // Transform the callee. 11331 ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 11332 if (Callee.isInvalid()) 11333 return ExprError(); 11334 11335 // Transform arguments. 11336 bool ArgChanged = false; 11337 SmallVector<Expr*, 8> Args; 11338 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 11339 &ArgChanged)) 11340 return ExprError(); 11341 11342 if (!getDerived().AlwaysRebuild() && 11343 Callee.get() == E->getCallee() && 11344 !ArgChanged) 11345 return SemaRef.MaybeBindToTemporary(E); 11346 11347 // FIXME: Wrong source location information for the '('. 11348 SourceLocation FakeLParenLoc 11349 = ((Expr *)Callee.get())->getSourceRange().getBegin(); 11350 11351 Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); 11352 if (E->hasStoredFPFeatures()) { 11353 FPOptionsOverride NewOverrides = E->getFPFeatures(); 11354 getSema().CurFPFeatures = 11355 NewOverrides.applyOverrides(getSema().getLangOpts()); 11356 getSema().FpPragmaStack.CurrentValue = NewOverrides; 11357 } 11358 11359 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 11360 Args, 11361 E->getRParenLoc()); 11362 } 11363 11364 template<typename Derived> 11365 ExprResult 11366 TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 11367 ExprResult Base = getDerived().TransformExpr(E->getBase()); 11368 if (Base.isInvalid()) 11369 return ExprError(); 11370 11371 NestedNameSpecifierLoc QualifierLoc; 11372 if (E->hasQualifier()) { 11373 QualifierLoc 11374 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 11375 11376 if (!QualifierLoc) 11377 return ExprError(); 11378 } 11379 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 11380 11381 ValueDecl *Member 11382 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 11383 E->getMemberDecl())); 11384 if (!Member) 11385 return ExprError(); 11386 11387 NamedDecl *FoundDecl = E->getFoundDecl(); 11388 if (FoundDecl == E->getMemberDecl()) { 11389 FoundDecl = Member; 11390 } else { 11391 FoundDecl = cast_or_null<NamedDecl>( 11392 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 11393 if (!FoundDecl) 11394 return ExprError(); 11395 } 11396 11397 if (!getDerived().AlwaysRebuild() && 11398 Base.get() == E->getBase() && 11399 QualifierLoc == E->getQualifierLoc() && 11400 Member == E->getMemberDecl() && 11401 FoundDecl == E->getFoundDecl() && 11402 !E->hasExplicitTemplateArgs()) { 11403 11404 // Skip for member expression of (this->f), rebuilt thisi->f is needed 11405 // for Openmp where the field need to be privatizized in the case. 11406 if (!(isa<CXXThisExpr>(E->getBase()) && 11407 getSema().isOpenMPRebuildMemberExpr(cast<ValueDecl>(Member)))) { 11408 // Mark it referenced in the new context regardless. 11409 // FIXME: this is a bit instantiation-specific. 11410 SemaRef.MarkMemberReferenced(E); 11411 return E; 11412 } 11413 } 11414 11415 TemplateArgumentListInfo TransArgs; 11416 if (E->hasExplicitTemplateArgs()) { 11417 TransArgs.setLAngleLoc(E->getLAngleLoc()); 11418 TransArgs.setRAngleLoc(E->getRAngleLoc()); 11419 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 11420 E->getNumTemplateArgs(), 11421 TransArgs)) 11422 return ExprError(); 11423 } 11424 11425 // FIXME: Bogus source location for the operator 11426 SourceLocation FakeOperatorLoc = 11427 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 11428 11429 // FIXME: to do this check properly, we will need to preserve the 11430 // first-qualifier-in-scope here, just in case we had a dependent 11431 // base (and therefore couldn't do the check) and a 11432 // nested-name-qualifier (and therefore could do the lookup). 11433 NamedDecl *FirstQualifierInScope = nullptr; 11434 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo(); 11435 if (MemberNameInfo.getName()) { 11436 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo); 11437 if (!MemberNameInfo.getName()) 11438 return ExprError(); 11439 } 11440 11441 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 11442 E->isArrow(), 11443 QualifierLoc, 11444 TemplateKWLoc, 11445 MemberNameInfo, 11446 Member, 11447 FoundDecl, 11448 (E->hasExplicitTemplateArgs() 11449 ? &TransArgs : nullptr), 11450 FirstQualifierInScope); 11451 } 11452 11453 template<typename Derived> 11454 ExprResult 11455 TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 11456 ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 11457 if (LHS.isInvalid()) 11458 return ExprError(); 11459 11460 ExprResult RHS = 11461 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false); 11462 if (RHS.isInvalid()) 11463 return ExprError(); 11464 11465 if (!getDerived().AlwaysRebuild() && 11466 LHS.get() == E->getLHS() && 11467 RHS.get() == E->getRHS()) 11468 return E; 11469 11470 if (E->isCompoundAssignmentOp()) 11471 // FPFeatures has already been established from trailing storage 11472 return getDerived().RebuildBinaryOperator( 11473 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get()); 11474 Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); 11475 FPOptionsOverride NewOverrides(E->getFPFeatures()); 11476 getSema().CurFPFeatures = 11477 NewOverrides.applyOverrides(getSema().getLangOpts()); 11478 getSema().FpPragmaStack.CurrentValue = NewOverrides; 11479 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 11480 LHS.get(), RHS.get()); 11481 } 11482 11483 template <typename Derived> 11484 ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator( 11485 CXXRewrittenBinaryOperator *E) { 11486 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm(); 11487 11488 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS)); 11489 if (LHS.isInvalid()) 11490 return ExprError(); 11491 11492 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS)); 11493 if (RHS.isInvalid()) 11494 return ExprError(); 11495 11496 // Extract the already-resolved callee declarations so that we can restrict 11497 // ourselves to using them as the unqualified lookup results when rebuilding. 11498 UnresolvedSet<2> UnqualLookups; 11499 bool ChangedAnyLookups = false; 11500 Expr *PossibleBinOps[] = {E->getSemanticForm(), 11501 const_cast<Expr *>(Decomp.InnerBinOp)}; 11502 for (Expr *PossibleBinOp : PossibleBinOps) { 11503 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit()); 11504 if (!Op) 11505 continue; 11506 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit()); 11507 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl())) 11508 continue; 11509 11510 // Transform the callee in case we built a call to a local extern 11511 // declaration. 11512 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl( 11513 E->getOperatorLoc(), Callee->getFoundDecl())); 11514 if (!Found) 11515 return ExprError(); 11516 if (Found != Callee->getFoundDecl()) 11517 ChangedAnyLookups = true; 11518 UnqualLookups.addDecl(Found); 11519 } 11520 11521 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups && 11522 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) { 11523 // Mark all functions used in the rewrite as referenced. Note that when 11524 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be 11525 // function calls, and/or there might be a user-defined conversion sequence 11526 // applied to the operands of the <. 11527 // FIXME: this is a bit instantiation-specific. 11528 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS}; 11529 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt); 11530 return E; 11531 } 11532 11533 return getDerived().RebuildCXXRewrittenBinaryOperator( 11534 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get()); 11535 } 11536 11537 template<typename Derived> 11538 ExprResult 11539 TreeTransform<Derived>::TransformCompoundAssignOperator( 11540 CompoundAssignOperator *E) { 11541 Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); 11542 FPOptionsOverride NewOverrides(E->getFPFeatures()); 11543 getSema().CurFPFeatures = 11544 NewOverrides.applyOverrides(getSema().getLangOpts()); 11545 getSema().FpPragmaStack.CurrentValue = NewOverrides; 11546 return getDerived().TransformBinaryOperator(E); 11547 } 11548 11549 template<typename Derived> 11550 ExprResult TreeTransform<Derived>:: 11551 TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { 11552 // Just rebuild the common and RHS expressions and see whether we 11553 // get any changes. 11554 11555 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); 11556 if (commonExpr.isInvalid()) 11557 return ExprError(); 11558 11559 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); 11560 if (rhs.isInvalid()) 11561 return ExprError(); 11562 11563 if (!getDerived().AlwaysRebuild() && 11564 commonExpr.get() == e->getCommon() && 11565 rhs.get() == e->getFalseExpr()) 11566 return e; 11567 11568 return getDerived().RebuildConditionalOperator(commonExpr.get(), 11569 e->getQuestionLoc(), 11570 nullptr, 11571 e->getColonLoc(), 11572 rhs.get()); 11573 } 11574 11575 template<typename Derived> 11576 ExprResult 11577 TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 11578 ExprResult Cond = getDerived().TransformExpr(E->getCond()); 11579 if (Cond.isInvalid()) 11580 return ExprError(); 11581 11582 ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 11583 if (LHS.isInvalid()) 11584 return ExprError(); 11585 11586 ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 11587 if (RHS.isInvalid()) 11588 return ExprError(); 11589 11590 if (!getDerived().AlwaysRebuild() && 11591 Cond.get() == E->getCond() && 11592 LHS.get() == E->getLHS() && 11593 RHS.get() == E->getRHS()) 11594 return E; 11595 11596 return getDerived().RebuildConditionalOperator(Cond.get(), 11597 E->getQuestionLoc(), 11598 LHS.get(), 11599 E->getColonLoc(), 11600 RHS.get()); 11601 } 11602 11603 template<typename Derived> 11604 ExprResult 11605 TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 11606 // Implicit casts are eliminated during transformation, since they 11607 // will be recomputed by semantic analysis after transformation. 11608 return getDerived().TransformExpr(E->getSubExprAsWritten()); 11609 } 11610 11611 template<typename Derived> 11612 ExprResult 11613 TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 11614 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 11615 if (!Type) 11616 return ExprError(); 11617 11618 ExprResult SubExpr 11619 = getDerived().TransformExpr(E->getSubExprAsWritten()); 11620 if (SubExpr.isInvalid()) 11621 return ExprError(); 11622 11623 if (!getDerived().AlwaysRebuild() && 11624 Type == E->getTypeInfoAsWritten() && 11625 SubExpr.get() == E->getSubExpr()) 11626 return E; 11627 11628 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 11629 Type, 11630 E->getRParenLoc(), 11631 SubExpr.get()); 11632 } 11633 11634 template<typename Derived> 11635 ExprResult 11636 TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 11637 TypeSourceInfo *OldT = E->getTypeSourceInfo(); 11638 TypeSourceInfo *NewT = getDerived().TransformType(OldT); 11639 if (!NewT) 11640 return ExprError(); 11641 11642 ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 11643 if (Init.isInvalid()) 11644 return ExprError(); 11645 11646 if (!getDerived().AlwaysRebuild() && 11647 OldT == NewT && 11648 Init.get() == E->getInitializer()) 11649 return SemaRef.MaybeBindToTemporary(E); 11650 11651 // Note: the expression type doesn't necessarily match the 11652 // type-as-written, but that's okay, because it should always be 11653 // derivable from the initializer. 11654 11655 return getDerived().RebuildCompoundLiteralExpr( 11656 E->getLParenLoc(), NewT, 11657 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get()); 11658 } 11659 11660 template<typename Derived> 11661 ExprResult 11662 TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 11663 ExprResult Base = getDerived().TransformExpr(E->getBase()); 11664 if (Base.isInvalid()) 11665 return ExprError(); 11666 11667 if (!getDerived().AlwaysRebuild() && 11668 Base.get() == E->getBase()) 11669 return E; 11670 11671 // FIXME: Bad source location 11672 SourceLocation FakeOperatorLoc = 11673 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc()); 11674 return getDerived().RebuildExtVectorElementExpr( 11675 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(), 11676 E->getAccessor()); 11677 } 11678 11679 template<typename Derived> 11680 ExprResult 11681 TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 11682 if (InitListExpr *Syntactic = E->getSyntacticForm()) 11683 E = Syntactic; 11684 11685 bool InitChanged = false; 11686 11687 EnterExpressionEvaluationContext Context( 11688 getSema(), EnterExpressionEvaluationContext::InitList); 11689 11690 SmallVector<Expr*, 4> Inits; 11691 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 11692 Inits, &InitChanged)) 11693 return ExprError(); 11694 11695 if (!getDerived().AlwaysRebuild() && !InitChanged) { 11696 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr 11697 // in some cases. We can't reuse it in general, because the syntactic and 11698 // semantic forms are linked, and we can't know that semantic form will 11699 // match even if the syntactic form does. 11700 } 11701 11702 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, 11703 E->getRBraceLoc()); 11704 } 11705 11706 template<typename Derived> 11707 ExprResult 11708 TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 11709 Designation Desig; 11710 11711 // transform the initializer value 11712 ExprResult Init = getDerived().TransformExpr(E->getInit()); 11713 if (Init.isInvalid()) 11714 return ExprError(); 11715 11716 // transform the designators. 11717 SmallVector<Expr*, 4> ArrayExprs; 11718 bool ExprChanged = false; 11719 for (const DesignatedInitExpr::Designator &D : E->designators()) { 11720 if (D.isFieldDesignator()) { 11721 Desig.AddDesignator(Designator::CreateFieldDesignator( 11722 D.getFieldName(), D.getDotLoc(), D.getFieldLoc())); 11723 if (D.getFieldDecl()) { 11724 FieldDecl *Field = cast_or_null<FieldDecl>( 11725 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl())); 11726 if (Field != D.getFieldDecl()) 11727 // Rebuild the expression when the transformed FieldDecl is 11728 // different to the already assigned FieldDecl. 11729 ExprChanged = true; 11730 } else { 11731 // Ensure that the designator expression is rebuilt when there isn't 11732 // a resolved FieldDecl in the designator as we don't want to assign 11733 // a FieldDecl to a pattern designator that will be instantiated again. 11734 ExprChanged = true; 11735 } 11736 continue; 11737 } 11738 11739 if (D.isArrayDesignator()) { 11740 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D)); 11741 if (Index.isInvalid()) 11742 return ExprError(); 11743 11744 Desig.AddDesignator( 11745 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc())); 11746 11747 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D); 11748 ArrayExprs.push_back(Index.get()); 11749 continue; 11750 } 11751 11752 assert(D.isArrayRangeDesignator() && "New kind of designator?"); 11753 ExprResult Start 11754 = getDerived().TransformExpr(E->getArrayRangeStart(D)); 11755 if (Start.isInvalid()) 11756 return ExprError(); 11757 11758 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D)); 11759 if (End.isInvalid()) 11760 return ExprError(); 11761 11762 Desig.AddDesignator(Designator::CreateArrayRangeDesignator( 11763 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc())); 11764 11765 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) || 11766 End.get() != E->getArrayRangeEnd(D); 11767 11768 ArrayExprs.push_back(Start.get()); 11769 ArrayExprs.push_back(End.get()); 11770 } 11771 11772 if (!getDerived().AlwaysRebuild() && 11773 Init.get() == E->getInit() && 11774 !ExprChanged) 11775 return E; 11776 11777 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, 11778 E->getEqualOrColonLoc(), 11779 E->usesGNUSyntax(), Init.get()); 11780 } 11781 11782 // Seems that if TransformInitListExpr() only works on the syntactic form of an 11783 // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. 11784 template<typename Derived> 11785 ExprResult 11786 TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( 11787 DesignatedInitUpdateExpr *E) { 11788 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " 11789 "initializer"); 11790 return ExprError(); 11791 } 11792 11793 template<typename Derived> 11794 ExprResult 11795 TreeTransform<Derived>::TransformNoInitExpr( 11796 NoInitExpr *E) { 11797 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer"); 11798 return ExprError(); 11799 } 11800 11801 template<typename Derived> 11802 ExprResult 11803 TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) { 11804 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer"); 11805 return ExprError(); 11806 } 11807 11808 template<typename Derived> 11809 ExprResult 11810 TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) { 11811 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer"); 11812 return ExprError(); 11813 } 11814 11815 template<typename Derived> 11816 ExprResult 11817 TreeTransform<Derived>::TransformImplicitValueInitExpr( 11818 ImplicitValueInitExpr *E) { 11819 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName()); 11820 11821 // FIXME: Will we ever have proper type location here? Will we actually 11822 // need to transform the type? 11823 QualType T = getDerived().TransformType(E->getType()); 11824 if (T.isNull()) 11825 return ExprError(); 11826 11827 if (!getDerived().AlwaysRebuild() && 11828 T == E->getType()) 11829 return E; 11830 11831 return getDerived().RebuildImplicitValueInitExpr(T); 11832 } 11833 11834 template<typename Derived> 11835 ExprResult 11836 TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 11837 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 11838 if (!TInfo) 11839 return ExprError(); 11840 11841 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 11842 if (SubExpr.isInvalid()) 11843 return ExprError(); 11844 11845 if (!getDerived().AlwaysRebuild() && 11846 TInfo == E->getWrittenTypeInfo() && 11847 SubExpr.get() == E->getSubExpr()) 11848 return E; 11849 11850 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 11851 TInfo, E->getRParenLoc()); 11852 } 11853 11854 template<typename Derived> 11855 ExprResult 11856 TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 11857 bool ArgumentChanged = false; 11858 SmallVector<Expr*, 4> Inits; 11859 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 11860 &ArgumentChanged)) 11861 return ExprError(); 11862 11863 return getDerived().RebuildParenListExpr(E->getLParenLoc(), 11864 Inits, 11865 E->getRParenLoc()); 11866 } 11867 11868 /// Transform an address-of-label expression. 11869 /// 11870 /// By default, the transformation of an address-of-label expression always 11871 /// rebuilds the expression, so that the label identifier can be resolved to 11872 /// the corresponding label statement by semantic analysis. 11873 template<typename Derived> 11874 ExprResult 11875 TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 11876 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), 11877 E->getLabel()); 11878 if (!LD) 11879 return ExprError(); 11880 11881 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 11882 cast<LabelDecl>(LD)); 11883 } 11884 11885 template<typename Derived> 11886 ExprResult 11887 TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 11888 SemaRef.ActOnStartStmtExpr(); 11889 StmtResult SubStmt 11890 = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 11891 if (SubStmt.isInvalid()) { 11892 SemaRef.ActOnStmtExprError(); 11893 return ExprError(); 11894 } 11895 11896 unsigned OldDepth = E->getTemplateDepth(); 11897 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth); 11898 11899 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth && 11900 SubStmt.get() == E->getSubStmt()) { 11901 // Calling this an 'error' is unintuitive, but it does the right thing. 11902 SemaRef.ActOnStmtExprError(); 11903 return SemaRef.MaybeBindToTemporary(E); 11904 } 11905 11906 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(), 11907 E->getRParenLoc(), NewDepth); 11908 } 11909 11910 template<typename Derived> 11911 ExprResult 11912 TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 11913 ExprResult Cond = getDerived().TransformExpr(E->getCond()); 11914 if (Cond.isInvalid()) 11915 return ExprError(); 11916 11917 ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 11918 if (LHS.isInvalid()) 11919 return ExprError(); 11920 11921 ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 11922 if (RHS.isInvalid()) 11923 return ExprError(); 11924 11925 if (!getDerived().AlwaysRebuild() && 11926 Cond.get() == E->getCond() && 11927 LHS.get() == E->getLHS() && 11928 RHS.get() == E->getRHS()) 11929 return E; 11930 11931 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 11932 Cond.get(), LHS.get(), RHS.get(), 11933 E->getRParenLoc()); 11934 } 11935 11936 template<typename Derived> 11937 ExprResult 11938 TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 11939 return E; 11940 } 11941 11942 template<typename Derived> 11943 ExprResult 11944 TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 11945 switch (E->getOperator()) { 11946 case OO_New: 11947 case OO_Delete: 11948 case OO_Array_New: 11949 case OO_Array_Delete: 11950 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 11951 11952 case OO_Subscript: 11953 case OO_Call: { 11954 // This is a call to an object's operator(). 11955 assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 11956 11957 // Transform the object itself. 11958 ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 11959 if (Object.isInvalid()) 11960 return ExprError(); 11961 11962 // FIXME: Poor location information 11963 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( 11964 static_cast<Expr *>(Object.get())->getEndLoc()); 11965 11966 // Transform the call arguments. 11967 SmallVector<Expr*, 8> Args; 11968 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 11969 Args)) 11970 return ExprError(); 11971 11972 if (E->getOperator() == OO_Subscript) 11973 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc, 11974 Args, E->getEndLoc()); 11975 11976 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args, 11977 E->getEndLoc()); 11978 } 11979 11980 #define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \ 11981 case OO_##Name: \ 11982 break; 11983 11984 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 11985 #include "clang/Basic/OperatorKinds.def" 11986 11987 case OO_Conditional: 11988 llvm_unreachable("conditional operator is not actually overloadable"); 11989 11990 case OO_None: 11991 case NUM_OVERLOADED_OPERATORS: 11992 llvm_unreachable("not an overloaded operator?"); 11993 } 11994 11995 ExprResult First; 11996 if (E->getOperator() == OO_Amp) 11997 First = getDerived().TransformAddressOfOperand(E->getArg(0)); 11998 else 11999 First = getDerived().TransformExpr(E->getArg(0)); 12000 if (First.isInvalid()) 12001 return ExprError(); 12002 12003 ExprResult Second; 12004 if (E->getNumArgs() == 2) { 12005 Second = 12006 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false); 12007 if (Second.isInvalid()) 12008 return ExprError(); 12009 } 12010 12011 Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); 12012 FPOptionsOverride NewOverrides(E->getFPFeatures()); 12013 getSema().CurFPFeatures = 12014 NewOverrides.applyOverrides(getSema().getLangOpts()); 12015 getSema().FpPragmaStack.CurrentValue = NewOverrides; 12016 12017 Expr *Callee = E->getCallee(); 12018 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 12019 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(), 12020 Sema::LookupOrdinaryName); 12021 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R)) 12022 return ExprError(); 12023 12024 return getDerived().RebuildCXXOperatorCallExpr( 12025 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(), 12026 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get()); 12027 } 12028 12029 UnresolvedSet<1> Functions; 12030 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee)) 12031 Callee = ICE->getSubExprAsWritten(); 12032 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl(); 12033 ValueDecl *VD = cast_or_null<ValueDecl>( 12034 getDerived().TransformDecl(DR->getLocation(), DR)); 12035 if (!VD) 12036 return ExprError(); 12037 12038 if (!isa<CXXMethodDecl>(VD)) 12039 Functions.addDecl(VD); 12040 12041 return getDerived().RebuildCXXOperatorCallExpr( 12042 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(), 12043 /*RequiresADL=*/false, Functions, First.get(), Second.get()); 12044 } 12045 12046 template<typename Derived> 12047 ExprResult 12048 TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 12049 return getDerived().TransformCallExpr(E); 12050 } 12051 12052 template <typename Derived> 12053 ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) { 12054 bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function && 12055 getSema().CurContext != E->getParentContext(); 12056 12057 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc) 12058 return E; 12059 12060 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(), 12061 E->getBeginLoc(), E->getEndLoc(), 12062 getSema().CurContext); 12063 } 12064 12065 template<typename Derived> 12066 ExprResult 12067 TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 12068 // Transform the callee. 12069 ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 12070 if (Callee.isInvalid()) 12071 return ExprError(); 12072 12073 // Transform exec config. 12074 ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); 12075 if (EC.isInvalid()) 12076 return ExprError(); 12077 12078 // Transform arguments. 12079 bool ArgChanged = false; 12080 SmallVector<Expr*, 8> Args; 12081 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 12082 &ArgChanged)) 12083 return ExprError(); 12084 12085 if (!getDerived().AlwaysRebuild() && 12086 Callee.get() == E->getCallee() && 12087 !ArgChanged) 12088 return SemaRef.MaybeBindToTemporary(E); 12089 12090 // FIXME: Wrong source location information for the '('. 12091 SourceLocation FakeLParenLoc 12092 = ((Expr *)Callee.get())->getSourceRange().getBegin(); 12093 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 12094 Args, 12095 E->getRParenLoc(), EC.get()); 12096 } 12097 12098 template<typename Derived> 12099 ExprResult 12100 TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 12101 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 12102 if (!Type) 12103 return ExprError(); 12104 12105 ExprResult SubExpr 12106 = getDerived().TransformExpr(E->getSubExprAsWritten()); 12107 if (SubExpr.isInvalid()) 12108 return ExprError(); 12109 12110 if (!getDerived().AlwaysRebuild() && 12111 Type == E->getTypeInfoAsWritten() && 12112 SubExpr.get() == E->getSubExpr()) 12113 return E; 12114 return getDerived().RebuildCXXNamedCastExpr( 12115 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), 12116 Type, E->getAngleBrackets().getEnd(), 12117 // FIXME. this should be '(' location 12118 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); 12119 } 12120 12121 template<typename Derived> 12122 ExprResult 12123 TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) { 12124 TypeSourceInfo *TSI = 12125 getDerived().TransformType(BCE->getTypeInfoAsWritten()); 12126 if (!TSI) 12127 return ExprError(); 12128 12129 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr()); 12130 if (Sub.isInvalid()) 12131 return ExprError(); 12132 12133 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI, 12134 Sub.get(), BCE->getEndLoc()); 12135 } 12136 12137 template<typename Derived> 12138 ExprResult 12139 TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 12140 return getDerived().TransformCXXNamedCastExpr(E); 12141 } 12142 12143 template<typename Derived> 12144 ExprResult 12145 TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 12146 return getDerived().TransformCXXNamedCastExpr(E); 12147 } 12148 12149 template<typename Derived> 12150 ExprResult 12151 TreeTransform<Derived>::TransformCXXReinterpretCastExpr( 12152 CXXReinterpretCastExpr *E) { 12153 return getDerived().TransformCXXNamedCastExpr(E); 12154 } 12155 12156 template<typename Derived> 12157 ExprResult 12158 TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 12159 return getDerived().TransformCXXNamedCastExpr(E); 12160 } 12161 12162 template<typename Derived> 12163 ExprResult 12164 TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) { 12165 return getDerived().TransformCXXNamedCastExpr(E); 12166 } 12167 12168 template<typename Derived> 12169 ExprResult 12170 TreeTransform<Derived>::TransformCXXFunctionalCastExpr( 12171 CXXFunctionalCastExpr *E) { 12172 TypeSourceInfo *Type = 12173 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten()); 12174 if (!Type) 12175 return ExprError(); 12176 12177 ExprResult SubExpr 12178 = getDerived().TransformExpr(E->getSubExprAsWritten()); 12179 if (SubExpr.isInvalid()) 12180 return ExprError(); 12181 12182 if (!getDerived().AlwaysRebuild() && 12183 Type == E->getTypeInfoAsWritten() && 12184 SubExpr.get() == E->getSubExpr()) 12185 return E; 12186 12187 return getDerived().RebuildCXXFunctionalCastExpr(Type, 12188 E->getLParenLoc(), 12189 SubExpr.get(), 12190 E->getRParenLoc(), 12191 E->isListInitialization()); 12192 } 12193 12194 template<typename Derived> 12195 ExprResult 12196 TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 12197 if (E->isTypeOperand()) { 12198 TypeSourceInfo *TInfo 12199 = getDerived().TransformType(E->getTypeOperandSourceInfo()); 12200 if (!TInfo) 12201 return ExprError(); 12202 12203 if (!getDerived().AlwaysRebuild() && 12204 TInfo == E->getTypeOperandSourceInfo()) 12205 return E; 12206 12207 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), 12208 TInfo, E->getEndLoc()); 12209 } 12210 12211 // Typeid's operand is an unevaluated context, unless it's a polymorphic 12212 // type. We must not unilaterally enter unevaluated context here, as then 12213 // semantic processing can re-transform an already transformed operand. 12214 Expr *Op = E->getExprOperand(); 12215 auto EvalCtx = Sema::ExpressionEvaluationContext::Unevaluated; 12216 if (E->isGLValue()) 12217 if (auto *RecordT = Op->getType()->getAs<RecordType>()) 12218 if (cast<CXXRecordDecl>(RecordT->getDecl())->isPolymorphic()) 12219 EvalCtx = SemaRef.ExprEvalContexts.back().Context; 12220 12221 EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx, 12222 Sema::ReuseLambdaContextDecl); 12223 12224 ExprResult SubExpr = getDerived().TransformExpr(Op); 12225 if (SubExpr.isInvalid()) 12226 return ExprError(); 12227 12228 if (!getDerived().AlwaysRebuild() && 12229 SubExpr.get() == E->getExprOperand()) 12230 return E; 12231 12232 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), 12233 SubExpr.get(), E->getEndLoc()); 12234 } 12235 12236 template<typename Derived> 12237 ExprResult 12238 TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 12239 if (E->isTypeOperand()) { 12240 TypeSourceInfo *TInfo 12241 = getDerived().TransformType(E->getTypeOperandSourceInfo()); 12242 if (!TInfo) 12243 return ExprError(); 12244 12245 if (!getDerived().AlwaysRebuild() && 12246 TInfo == E->getTypeOperandSourceInfo()) 12247 return E; 12248 12249 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), 12250 TInfo, E->getEndLoc()); 12251 } 12252 12253 EnterExpressionEvaluationContext Unevaluated( 12254 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); 12255 12256 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 12257 if (SubExpr.isInvalid()) 12258 return ExprError(); 12259 12260 if (!getDerived().AlwaysRebuild() && 12261 SubExpr.get() == E->getExprOperand()) 12262 return E; 12263 12264 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), 12265 SubExpr.get(), E->getEndLoc()); 12266 } 12267 12268 template<typename Derived> 12269 ExprResult 12270 TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 12271 return E; 12272 } 12273 12274 template<typename Derived> 12275 ExprResult 12276 TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 12277 CXXNullPtrLiteralExpr *E) { 12278 return E; 12279 } 12280 12281 template<typename Derived> 12282 ExprResult 12283 TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 12284 QualType T = getSema().getCurrentThisType(); 12285 12286 if (!getDerived().AlwaysRebuild() && T == E->getType()) { 12287 // Mark it referenced in the new context regardless. 12288 // FIXME: this is a bit instantiation-specific. 12289 getSema().MarkThisReferenced(E); 12290 return E; 12291 } 12292 12293 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit()); 12294 } 12295 12296 template<typename Derived> 12297 ExprResult 12298 TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 12299 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 12300 if (SubExpr.isInvalid()) 12301 return ExprError(); 12302 12303 if (!getDerived().AlwaysRebuild() && 12304 SubExpr.get() == E->getSubExpr()) 12305 return E; 12306 12307 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), 12308 E->isThrownVariableInScope()); 12309 } 12310 12311 template<typename Derived> 12312 ExprResult 12313 TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 12314 ParmVarDecl *Param = cast_or_null<ParmVarDecl>( 12315 getDerived().TransformDecl(E->getBeginLoc(), E->getParam())); 12316 if (!Param) 12317 return ExprError(); 12318 12319 ExprResult InitRes; 12320 if (E->hasRewrittenInit()) { 12321 InitRes = getDerived().TransformExpr(E->getRewrittenExpr()); 12322 if (InitRes.isInvalid()) 12323 return ExprError(); 12324 } 12325 12326 if (!getDerived().AlwaysRebuild() && Param == E->getParam() && 12327 E->getUsedContext() == SemaRef.CurContext && 12328 InitRes.get() == E->getRewrittenExpr()) 12329 return E; 12330 12331 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param, 12332 InitRes.get()); 12333 } 12334 12335 template<typename Derived> 12336 ExprResult 12337 TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { 12338 FieldDecl *Field = cast_or_null<FieldDecl>( 12339 getDerived().TransformDecl(E->getBeginLoc(), E->getField())); 12340 if (!Field) 12341 return ExprError(); 12342 12343 if (!getDerived().AlwaysRebuild() && Field == E->getField() && 12344 E->getUsedContext() == SemaRef.CurContext) 12345 return E; 12346 12347 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); 12348 } 12349 12350 template<typename Derived> 12351 ExprResult 12352 TreeTransform<Derived>::TransformCXXScalarValueInitExpr( 12353 CXXScalarValueInitExpr *E) { 12354 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 12355 if (!T) 12356 return ExprError(); 12357 12358 if (!getDerived().AlwaysRebuild() && 12359 T == E->getTypeSourceInfo()) 12360 return E; 12361 12362 return getDerived().RebuildCXXScalarValueInitExpr(T, 12363 /*FIXME:*/T->getTypeLoc().getEndLoc(), 12364 E->getRParenLoc()); 12365 } 12366 12367 template<typename Derived> 12368 ExprResult 12369 TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 12370 // Transform the type that we're allocating 12371 TypeSourceInfo *AllocTypeInfo = 12372 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo()); 12373 if (!AllocTypeInfo) 12374 return ExprError(); 12375 12376 // Transform the size of the array we're allocating (if any). 12377 std::optional<Expr *> ArraySize; 12378 if (E->isArray()) { 12379 ExprResult NewArraySize; 12380 if (std::optional<Expr *> OldArraySize = E->getArraySize()) { 12381 NewArraySize = getDerived().TransformExpr(*OldArraySize); 12382 if (NewArraySize.isInvalid()) 12383 return ExprError(); 12384 } 12385 ArraySize = NewArraySize.get(); 12386 } 12387 12388 // Transform the placement arguments (if any). 12389 bool ArgumentChanged = false; 12390 SmallVector<Expr*, 8> PlacementArgs; 12391 if (getDerived().TransformExprs(E->getPlacementArgs(), 12392 E->getNumPlacementArgs(), true, 12393 PlacementArgs, &ArgumentChanged)) 12394 return ExprError(); 12395 12396 // Transform the initializer (if any). 12397 Expr *OldInit = E->getInitializer(); 12398 ExprResult NewInit; 12399 if (OldInit) 12400 NewInit = getDerived().TransformInitializer(OldInit, true); 12401 if (NewInit.isInvalid()) 12402 return ExprError(); 12403 12404 // Transform new operator and delete operator. 12405 FunctionDecl *OperatorNew = nullptr; 12406 if (E->getOperatorNew()) { 12407 OperatorNew = cast_or_null<FunctionDecl>( 12408 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew())); 12409 if (!OperatorNew) 12410 return ExprError(); 12411 } 12412 12413 FunctionDecl *OperatorDelete = nullptr; 12414 if (E->getOperatorDelete()) { 12415 OperatorDelete = cast_or_null<FunctionDecl>( 12416 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); 12417 if (!OperatorDelete) 12418 return ExprError(); 12419 } 12420 12421 if (!getDerived().AlwaysRebuild() && 12422 AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 12423 ArraySize == E->getArraySize() && 12424 NewInit.get() == OldInit && 12425 OperatorNew == E->getOperatorNew() && 12426 OperatorDelete == E->getOperatorDelete() && 12427 !ArgumentChanged) { 12428 // Mark any declarations we need as referenced. 12429 // FIXME: instantiation-specific. 12430 if (OperatorNew) 12431 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew); 12432 if (OperatorDelete) 12433 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); 12434 12435 if (E->isArray() && !E->getAllocatedType()->isDependentType()) { 12436 QualType ElementType 12437 = SemaRef.Context.getBaseElementType(E->getAllocatedType()); 12438 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { 12439 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); 12440 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { 12441 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor); 12442 } 12443 } 12444 } 12445 12446 return E; 12447 } 12448 12449 QualType AllocType = AllocTypeInfo->getType(); 12450 if (!ArraySize) { 12451 // If no array size was specified, but the new expression was 12452 // instantiated with an array type (e.g., "new T" where T is 12453 // instantiated with "int[4]"), extract the outer bound from the 12454 // array type as our array size. We do this with constant and 12455 // dependently-sized array types. 12456 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 12457 if (!ArrayT) { 12458 // Do nothing 12459 } else if (const ConstantArrayType *ConsArrayT 12460 = dyn_cast<ConstantArrayType>(ArrayT)) { 12461 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), 12462 SemaRef.Context.getSizeType(), 12463 /*FIXME:*/ E->getBeginLoc()); 12464 AllocType = ConsArrayT->getElementType(); 12465 } else if (const DependentSizedArrayType *DepArrayT 12466 = dyn_cast<DependentSizedArrayType>(ArrayT)) { 12467 if (DepArrayT->getSizeExpr()) { 12468 ArraySize = DepArrayT->getSizeExpr(); 12469 AllocType = DepArrayT->getElementType(); 12470 } 12471 } 12472 } 12473 12474 return getDerived().RebuildCXXNewExpr( 12475 E->getBeginLoc(), E->isGlobalNew(), 12476 /*FIXME:*/ E->getBeginLoc(), PlacementArgs, 12477 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType, 12478 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get()); 12479 } 12480 12481 template<typename Derived> 12482 ExprResult 12483 TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 12484 ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 12485 if (Operand.isInvalid()) 12486 return ExprError(); 12487 12488 // Transform the delete operator, if known. 12489 FunctionDecl *OperatorDelete = nullptr; 12490 if (E->getOperatorDelete()) { 12491 OperatorDelete = cast_or_null<FunctionDecl>( 12492 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); 12493 if (!OperatorDelete) 12494 return ExprError(); 12495 } 12496 12497 if (!getDerived().AlwaysRebuild() && 12498 Operand.get() == E->getArgument() && 12499 OperatorDelete == E->getOperatorDelete()) { 12500 // Mark any declarations we need as referenced. 12501 // FIXME: instantiation-specific. 12502 if (OperatorDelete) 12503 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); 12504 12505 if (!E->getArgument()->isTypeDependent()) { 12506 QualType Destroyed = SemaRef.Context.getBaseElementType( 12507 E->getDestroyedType()); 12508 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 12509 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 12510 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), 12511 SemaRef.LookupDestructor(Record)); 12512 } 12513 } 12514 12515 return E; 12516 } 12517 12518 return getDerived().RebuildCXXDeleteExpr( 12519 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get()); 12520 } 12521 12522 template<typename Derived> 12523 ExprResult 12524 TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 12525 CXXPseudoDestructorExpr *E) { 12526 ExprResult Base = getDerived().TransformExpr(E->getBase()); 12527 if (Base.isInvalid()) 12528 return ExprError(); 12529 12530 ParsedType ObjectTypePtr; 12531 bool MayBePseudoDestructor = false; 12532 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), 12533 E->getOperatorLoc(), 12534 E->isArrow()? tok::arrow : tok::period, 12535 ObjectTypePtr, 12536 MayBePseudoDestructor); 12537 if (Base.isInvalid()) 12538 return ExprError(); 12539 12540 QualType ObjectType = ObjectTypePtr.get(); 12541 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); 12542 if (QualifierLoc) { 12543 QualifierLoc 12544 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); 12545 if (!QualifierLoc) 12546 return ExprError(); 12547 } 12548 CXXScopeSpec SS; 12549 SS.Adopt(QualifierLoc); 12550 12551 PseudoDestructorTypeStorage Destroyed; 12552 if (E->getDestroyedTypeInfo()) { 12553 TypeSourceInfo *DestroyedTypeInfo 12554 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 12555 ObjectType, nullptr, SS); 12556 if (!DestroyedTypeInfo) 12557 return ExprError(); 12558 Destroyed = DestroyedTypeInfo; 12559 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { 12560 // We aren't likely to be able to resolve the identifier down to a type 12561 // now anyway, so just retain the identifier. 12562 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 12563 E->getDestroyedTypeLoc()); 12564 } else { 12565 // Look for a destructor known with the given name. 12566 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 12567 *E->getDestroyedTypeIdentifier(), 12568 E->getDestroyedTypeLoc(), 12569 /*Scope=*/nullptr, 12570 SS, ObjectTypePtr, 12571 false); 12572 if (!T) 12573 return ExprError(); 12574 12575 Destroyed 12576 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 12577 E->getDestroyedTypeLoc()); 12578 } 12579 12580 TypeSourceInfo *ScopeTypeInfo = nullptr; 12581 if (E->getScopeTypeInfo()) { 12582 CXXScopeSpec EmptySS; 12583 ScopeTypeInfo = getDerived().TransformTypeInObjectScope( 12584 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); 12585 if (!ScopeTypeInfo) 12586 return ExprError(); 12587 } 12588 12589 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 12590 E->getOperatorLoc(), 12591 E->isArrow(), 12592 SS, 12593 ScopeTypeInfo, 12594 E->getColonColonLoc(), 12595 E->getTildeLoc(), 12596 Destroyed); 12597 } 12598 12599 template <typename Derived> 12600 bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old, 12601 bool RequiresADL, 12602 LookupResult &R) { 12603 // Transform all the decls. 12604 bool AllEmptyPacks = true; 12605 for (auto *OldD : Old->decls()) { 12606 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD); 12607 if (!InstD) { 12608 // Silently ignore these if a UsingShadowDecl instantiated to nothing. 12609 // This can happen because of dependent hiding. 12610 if (isa<UsingShadowDecl>(OldD)) 12611 continue; 12612 else { 12613 R.clear(); 12614 return true; 12615 } 12616 } 12617 12618 // Expand using pack declarations. 12619 NamedDecl *SingleDecl = cast<NamedDecl>(InstD); 12620 ArrayRef<NamedDecl*> Decls = SingleDecl; 12621 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD)) 12622 Decls = UPD->expansions(); 12623 12624 // Expand using declarations. 12625 for (auto *D : Decls) { 12626 if (auto *UD = dyn_cast<UsingDecl>(D)) { 12627 for (auto *SD : UD->shadows()) 12628 R.addDecl(SD); 12629 } else { 12630 R.addDecl(D); 12631 } 12632 } 12633 12634 AllEmptyPacks &= Decls.empty(); 12635 }; 12636 12637 // C++ [temp.res]/8.4.2: 12638 // The program is ill-formed, no diagnostic required, if [...] lookup for 12639 // a name in the template definition found a using-declaration, but the 12640 // lookup in the corresponding scope in the instantiation odoes not find 12641 // any declarations because the using-declaration was a pack expansion and 12642 // the corresponding pack is empty 12643 if (AllEmptyPacks && !RequiresADL) { 12644 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty) 12645 << isa<UnresolvedMemberExpr>(Old) << Old->getName(); 12646 return true; 12647 } 12648 12649 // Resolve a kind, but don't do any further analysis. If it's 12650 // ambiguous, the callee needs to deal with it. 12651 R.resolveKind(); 12652 return false; 12653 } 12654 12655 template<typename Derived> 12656 ExprResult 12657 TreeTransform<Derived>::TransformUnresolvedLookupExpr( 12658 UnresolvedLookupExpr *Old) { 12659 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 12660 Sema::LookupOrdinaryName); 12661 12662 // Transform the declaration set. 12663 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R)) 12664 return ExprError(); 12665 12666 // Rebuild the nested-name qualifier, if present. 12667 CXXScopeSpec SS; 12668 if (Old->getQualifierLoc()) { 12669 NestedNameSpecifierLoc QualifierLoc 12670 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 12671 if (!QualifierLoc) 12672 return ExprError(); 12673 12674 SS.Adopt(QualifierLoc); 12675 } 12676 12677 if (Old->getNamingClass()) { 12678 CXXRecordDecl *NamingClass 12679 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 12680 Old->getNameLoc(), 12681 Old->getNamingClass())); 12682 if (!NamingClass) { 12683 R.clear(); 12684 return ExprError(); 12685 } 12686 12687 R.setNamingClass(NamingClass); 12688 } 12689 12690 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 12691 12692 // If we have neither explicit template arguments, nor the template keyword, 12693 // it's a normal declaration name or member reference. 12694 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) { 12695 NamedDecl *D = R.getAsSingle<NamedDecl>(); 12696 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an 12697 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will 12698 // give a good diagnostic. 12699 if (D && D->isCXXInstanceMember()) { 12700 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, 12701 /*TemplateArgs=*/nullptr, 12702 /*Scope=*/nullptr); 12703 } 12704 12705 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 12706 } 12707 12708 // If we have template arguments, rebuild them, then rebuild the 12709 // templateid expression. 12710 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 12711 if (Old->hasExplicitTemplateArgs() && 12712 getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 12713 Old->getNumTemplateArgs(), 12714 TransArgs)) { 12715 R.clear(); 12716 return ExprError(); 12717 } 12718 12719 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, 12720 Old->requiresADL(), &TransArgs); 12721 } 12722 12723 template<typename Derived> 12724 ExprResult 12725 TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { 12726 bool ArgChanged = false; 12727 SmallVector<TypeSourceInfo *, 4> Args; 12728 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { 12729 TypeSourceInfo *From = E->getArg(I); 12730 TypeLoc FromTL = From->getTypeLoc(); 12731 if (!FromTL.getAs<PackExpansionTypeLoc>()) { 12732 TypeLocBuilder TLB; 12733 TLB.reserve(FromTL.getFullDataSize()); 12734 QualType To = getDerived().TransformType(TLB, FromTL); 12735 if (To.isNull()) 12736 return ExprError(); 12737 12738 if (To == From->getType()) 12739 Args.push_back(From); 12740 else { 12741 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 12742 ArgChanged = true; 12743 } 12744 continue; 12745 } 12746 12747 ArgChanged = true; 12748 12749 // We have a pack expansion. Instantiate it. 12750 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); 12751 TypeLoc PatternTL = ExpansionTL.getPatternLoc(); 12752 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 12753 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); 12754 12755 // Determine whether the set of unexpanded parameter packs can and should 12756 // be expanded. 12757 bool Expand = true; 12758 bool RetainExpansion = false; 12759 std::optional<unsigned> OrigNumExpansions = 12760 ExpansionTL.getTypePtr()->getNumExpansions(); 12761 std::optional<unsigned> NumExpansions = OrigNumExpansions; 12762 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 12763 PatternTL.getSourceRange(), 12764 Unexpanded, 12765 Expand, RetainExpansion, 12766 NumExpansions)) 12767 return ExprError(); 12768 12769 if (!Expand) { 12770 // The transform has determined that we should perform a simple 12771 // transformation on the pack expansion, producing another pack 12772 // expansion. 12773 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 12774 12775 TypeLocBuilder TLB; 12776 TLB.reserve(From->getTypeLoc().getFullDataSize()); 12777 12778 QualType To = getDerived().TransformType(TLB, PatternTL); 12779 if (To.isNull()) 12780 return ExprError(); 12781 12782 To = getDerived().RebuildPackExpansionType(To, 12783 PatternTL.getSourceRange(), 12784 ExpansionTL.getEllipsisLoc(), 12785 NumExpansions); 12786 if (To.isNull()) 12787 return ExprError(); 12788 12789 PackExpansionTypeLoc ToExpansionTL 12790 = TLB.push<PackExpansionTypeLoc>(To); 12791 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 12792 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 12793 continue; 12794 } 12795 12796 // Expand the pack expansion by substituting for each argument in the 12797 // pack(s). 12798 for (unsigned I = 0; I != *NumExpansions; ++I) { 12799 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); 12800 TypeLocBuilder TLB; 12801 TLB.reserve(PatternTL.getFullDataSize()); 12802 QualType To = getDerived().TransformType(TLB, PatternTL); 12803 if (To.isNull()) 12804 return ExprError(); 12805 12806 if (To->containsUnexpandedParameterPack()) { 12807 To = getDerived().RebuildPackExpansionType(To, 12808 PatternTL.getSourceRange(), 12809 ExpansionTL.getEllipsisLoc(), 12810 NumExpansions); 12811 if (To.isNull()) 12812 return ExprError(); 12813 12814 PackExpansionTypeLoc ToExpansionTL 12815 = TLB.push<PackExpansionTypeLoc>(To); 12816 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 12817 } 12818 12819 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 12820 } 12821 12822 if (!RetainExpansion) 12823 continue; 12824 12825 // If we're supposed to retain a pack expansion, do so by temporarily 12826 // forgetting the partially-substituted parameter pack. 12827 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 12828 12829 TypeLocBuilder TLB; 12830 TLB.reserve(From->getTypeLoc().getFullDataSize()); 12831 12832 QualType To = getDerived().TransformType(TLB, PatternTL); 12833 if (To.isNull()) 12834 return ExprError(); 12835 12836 To = getDerived().RebuildPackExpansionType(To, 12837 PatternTL.getSourceRange(), 12838 ExpansionTL.getEllipsisLoc(), 12839 NumExpansions); 12840 if (To.isNull()) 12841 return ExprError(); 12842 12843 PackExpansionTypeLoc ToExpansionTL 12844 = TLB.push<PackExpansionTypeLoc>(To); 12845 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 12846 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 12847 } 12848 12849 if (!getDerived().AlwaysRebuild() && !ArgChanged) 12850 return E; 12851 12852 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args, 12853 E->getEndLoc()); 12854 } 12855 12856 template<typename Derived> 12857 ExprResult 12858 TreeTransform<Derived>::TransformConceptSpecializationExpr( 12859 ConceptSpecializationExpr *E) { 12860 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten(); 12861 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc); 12862 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 12863 Old->NumTemplateArgs, TransArgs)) 12864 return ExprError(); 12865 12866 return getDerived().RebuildConceptSpecializationExpr( 12867 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(), 12868 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(), 12869 &TransArgs); 12870 } 12871 12872 template<typename Derived> 12873 ExprResult 12874 TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) { 12875 SmallVector<ParmVarDecl*, 4> TransParams; 12876 SmallVector<QualType, 4> TransParamTypes; 12877 Sema::ExtParameterInfoBuilder ExtParamInfos; 12878 12879 // C++2a [expr.prim.req]p2 12880 // Expressions appearing within a requirement-body are unevaluated operands. 12881 EnterExpressionEvaluationContext Ctx( 12882 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, 12883 Sema::ReuseLambdaContextDecl); 12884 12885 RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create( 12886 getSema().Context, getSema().CurContext, 12887 E->getBody()->getBeginLoc()); 12888 12889 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false); 12890 12891 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams( 12892 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body, 12893 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos); 12894 12895 for (ParmVarDecl *Param : TransParams) 12896 if (Param) 12897 Param->setDeclContext(Body); 12898 12899 // On failure to transform, TransformRequiresTypeParams returns an expression 12900 // in the event that the transformation of the type params failed in some way. 12901 // It is expected that this will result in a 'not satisfied' Requires clause 12902 // when instantiating. 12903 if (!TypeParamResult.isUnset()) 12904 return TypeParamResult; 12905 12906 SmallVector<concepts::Requirement *, 4> TransReqs; 12907 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(), 12908 TransReqs)) 12909 return ExprError(); 12910 12911 for (concepts::Requirement *Req : TransReqs) { 12912 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) { 12913 if (ER->getReturnTypeRequirement().isTypeConstraint()) { 12914 ER->getReturnTypeRequirement() 12915 .getTypeConstraintTemplateParameterList()->getParam(0) 12916 ->setDeclContext(Body); 12917 } 12918 } 12919 } 12920 12921 return getDerived().RebuildRequiresExpr(E->getRequiresKWLoc(), Body, 12922 TransParams, TransReqs, 12923 E->getRBraceLoc()); 12924 } 12925 12926 template<typename Derived> 12927 bool TreeTransform<Derived>::TransformRequiresExprRequirements( 12928 ArrayRef<concepts::Requirement *> Reqs, 12929 SmallVectorImpl<concepts::Requirement *> &Transformed) { 12930 for (concepts::Requirement *Req : Reqs) { 12931 concepts::Requirement *TransReq = nullptr; 12932 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) 12933 TransReq = getDerived().TransformTypeRequirement(TypeReq); 12934 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) 12935 TransReq = getDerived().TransformExprRequirement(ExprReq); 12936 else 12937 TransReq = getDerived().TransformNestedRequirement( 12938 cast<concepts::NestedRequirement>(Req)); 12939 if (!TransReq) 12940 return true; 12941 Transformed.push_back(TransReq); 12942 } 12943 return false; 12944 } 12945 12946 template<typename Derived> 12947 concepts::TypeRequirement * 12948 TreeTransform<Derived>::TransformTypeRequirement( 12949 concepts::TypeRequirement *Req) { 12950 if (Req->isSubstitutionFailure()) { 12951 if (getDerived().AlwaysRebuild()) 12952 return getDerived().RebuildTypeRequirement( 12953 Req->getSubstitutionDiagnostic()); 12954 return Req; 12955 } 12956 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType()); 12957 if (!TransType) 12958 return nullptr; 12959 return getDerived().RebuildTypeRequirement(TransType); 12960 } 12961 12962 template<typename Derived> 12963 concepts::ExprRequirement * 12964 TreeTransform<Derived>::TransformExprRequirement(concepts::ExprRequirement *Req) { 12965 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr; 12966 if (Req->isExprSubstitutionFailure()) 12967 TransExpr = Req->getExprSubstitutionDiagnostic(); 12968 else { 12969 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr()); 12970 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType()) 12971 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get()); 12972 if (TransExprRes.isInvalid()) 12973 return nullptr; 12974 TransExpr = TransExprRes.get(); 12975 } 12976 12977 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq; 12978 const auto &RetReq = Req->getReturnTypeRequirement(); 12979 if (RetReq.isEmpty()) 12980 TransRetReq.emplace(); 12981 else if (RetReq.isSubstitutionFailure()) 12982 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic()); 12983 else if (RetReq.isTypeConstraint()) { 12984 TemplateParameterList *OrigTPL = 12985 RetReq.getTypeConstraintTemplateParameterList(); 12986 TemplateParameterList *TPL = 12987 getDerived().TransformTemplateParameterList(OrigTPL); 12988 if (!TPL) 12989 return nullptr; 12990 TransRetReq.emplace(TPL); 12991 } 12992 assert(TransRetReq && "All code paths leading here must set TransRetReq"); 12993 if (Expr *E = TransExpr.dyn_cast<Expr *>()) 12994 return getDerived().RebuildExprRequirement(E, Req->isSimple(), 12995 Req->getNoexceptLoc(), 12996 std::move(*TransRetReq)); 12997 return getDerived().RebuildExprRequirement( 12998 TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(), 12999 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq)); 13000 } 13001 13002 template<typename Derived> 13003 concepts::NestedRequirement * 13004 TreeTransform<Derived>::TransformNestedRequirement( 13005 concepts::NestedRequirement *Req) { 13006 if (Req->hasInvalidConstraint()) { 13007 if (getDerived().AlwaysRebuild()) 13008 return getDerived().RebuildNestedRequirement( 13009 Req->getInvalidConstraintEntity(), Req->getConstraintSatisfaction()); 13010 return Req; 13011 } 13012 ExprResult TransConstraint = 13013 getDerived().TransformExpr(Req->getConstraintExpr()); 13014 if (TransConstraint.isInvalid()) 13015 return nullptr; 13016 return getDerived().RebuildNestedRequirement(TransConstraint.get()); 13017 } 13018 13019 template<typename Derived> 13020 ExprResult 13021 TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 13022 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 13023 if (!T) 13024 return ExprError(); 13025 13026 if (!getDerived().AlwaysRebuild() && 13027 T == E->getQueriedTypeSourceInfo()) 13028 return E; 13029 13030 ExprResult SubExpr; 13031 { 13032 EnterExpressionEvaluationContext Unevaluated( 13033 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); 13034 SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); 13035 if (SubExpr.isInvalid()) 13036 return ExprError(); 13037 13038 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) 13039 return E; 13040 } 13041 13042 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T, 13043 SubExpr.get(), E->getEndLoc()); 13044 } 13045 13046 template<typename Derived> 13047 ExprResult 13048 TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { 13049 ExprResult SubExpr; 13050 { 13051 EnterExpressionEvaluationContext Unevaluated( 13052 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); 13053 SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); 13054 if (SubExpr.isInvalid()) 13055 return ExprError(); 13056 13057 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) 13058 return E; 13059 } 13060 13061 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(), 13062 SubExpr.get(), E->getEndLoc()); 13063 } 13064 13065 template <typename Derived> 13066 ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( 13067 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, 13068 TypeSourceInfo **RecoveryTSI) { 13069 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( 13070 DRE, AddrTaken, RecoveryTSI); 13071 13072 // Propagate both errors and recovered types, which return ExprEmpty. 13073 if (!NewDRE.isUsable()) 13074 return NewDRE; 13075 13076 // We got an expr, wrap it up in parens. 13077 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) 13078 return PE; 13079 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), 13080 PE->getRParen()); 13081 } 13082 13083 template <typename Derived> 13084 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 13085 DependentScopeDeclRefExpr *E) { 13086 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, 13087 nullptr); 13088 } 13089 13090 template <typename Derived> 13091 ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 13092 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand, 13093 TypeSourceInfo **RecoveryTSI) { 13094 assert(E->getQualifierLoc()); 13095 NestedNameSpecifierLoc QualifierLoc = 13096 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 13097 if (!QualifierLoc) 13098 return ExprError(); 13099 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 13100 13101 // TODO: If this is a conversion-function-id, verify that the 13102 // destination type name (if present) resolves the same way after 13103 // instantiation as it did in the local scope. 13104 13105 DeclarationNameInfo NameInfo = 13106 getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 13107 if (!NameInfo.getName()) 13108 return ExprError(); 13109 13110 if (!E->hasExplicitTemplateArgs()) { 13111 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() && 13112 // Note: it is sufficient to compare the Name component of NameInfo: 13113 // if name has not changed, DNLoc has not changed either. 13114 NameInfo.getName() == E->getDeclName()) 13115 return E; 13116 13117 return getDerived().RebuildDependentScopeDeclRefExpr( 13118 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, 13119 IsAddressOfOperand, RecoveryTSI); 13120 } 13121 13122 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 13123 if (getDerived().TransformTemplateArguments( 13124 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs)) 13125 return ExprError(); 13126 13127 return getDerived().RebuildDependentScopeDeclRefExpr( 13128 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, 13129 RecoveryTSI); 13130 } 13131 13132 template<typename Derived> 13133 ExprResult 13134 TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 13135 // CXXConstructExprs other than for list-initialization and 13136 // CXXTemporaryObjectExpr are always implicit, so when we have 13137 // a 1-argument construction we just transform that argument. 13138 if (getDerived().AllowSkippingCXXConstructExpr() && 13139 ((E->getNumArgs() == 1 || 13140 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && 13141 (!getDerived().DropCallArgument(E->getArg(0))) && 13142 !E->isListInitialization())) 13143 return getDerived().TransformInitializer(E->getArg(0), 13144 /*DirectInit*/ false); 13145 13146 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName()); 13147 13148 QualType T = getDerived().TransformType(E->getType()); 13149 if (T.isNull()) 13150 return ExprError(); 13151 13152 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( 13153 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); 13154 if (!Constructor) 13155 return ExprError(); 13156 13157 bool ArgumentChanged = false; 13158 SmallVector<Expr*, 8> Args; 13159 { 13160 EnterExpressionEvaluationContext Context( 13161 getSema(), EnterExpressionEvaluationContext::InitList, 13162 E->isListInitialization()); 13163 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 13164 &ArgumentChanged)) 13165 return ExprError(); 13166 } 13167 13168 if (!getDerived().AlwaysRebuild() && 13169 T == E->getType() && 13170 Constructor == E->getConstructor() && 13171 !ArgumentChanged) { 13172 // Mark the constructor as referenced. 13173 // FIXME: Instantiation-specific 13174 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); 13175 return E; 13176 } 13177 13178 return getDerived().RebuildCXXConstructExpr( 13179 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args, 13180 E->hadMultipleCandidates(), E->isListInitialization(), 13181 E->isStdInitListInitialization(), E->requiresZeroInitialization(), 13182 E->getConstructionKind(), E->getParenOrBraceRange()); 13183 } 13184 13185 template<typename Derived> 13186 ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr( 13187 CXXInheritedCtorInitExpr *E) { 13188 QualType T = getDerived().TransformType(E->getType()); 13189 if (T.isNull()) 13190 return ExprError(); 13191 13192 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( 13193 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); 13194 if (!Constructor) 13195 return ExprError(); 13196 13197 if (!getDerived().AlwaysRebuild() && 13198 T == E->getType() && 13199 Constructor == E->getConstructor()) { 13200 // Mark the constructor as referenced. 13201 // FIXME: Instantiation-specific 13202 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); 13203 return E; 13204 } 13205 13206 return getDerived().RebuildCXXInheritedCtorInitExpr( 13207 T, E->getLocation(), Constructor, 13208 E->constructsVBase(), E->inheritedFromVBase()); 13209 } 13210 13211 /// Transform a C++ temporary-binding expression. 13212 /// 13213 /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 13214 /// transform the subexpression and return that. 13215 template<typename Derived> 13216 ExprResult 13217 TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 13218 if (auto *Dtor = E->getTemporary()->getDestructor()) 13219 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), 13220 const_cast<CXXDestructorDecl *>(Dtor)); 13221 return getDerived().TransformExpr(E->getSubExpr()); 13222 } 13223 13224 /// Transform a C++ expression that contains cleanups that should 13225 /// be run after the expression is evaluated. 13226 /// 13227 /// Since ExprWithCleanups nodes are implicitly generated, we 13228 /// just transform the subexpression and return that. 13229 template<typename Derived> 13230 ExprResult 13231 TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 13232 return getDerived().TransformExpr(E->getSubExpr()); 13233 } 13234 13235 template<typename Derived> 13236 ExprResult 13237 TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 13238 CXXTemporaryObjectExpr *E) { 13239 TypeSourceInfo *T = 13240 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); 13241 if (!T) 13242 return ExprError(); 13243 13244 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( 13245 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); 13246 if (!Constructor) 13247 return ExprError(); 13248 13249 bool ArgumentChanged = false; 13250 SmallVector<Expr*, 8> Args; 13251 Args.reserve(E->getNumArgs()); 13252 { 13253 EnterExpressionEvaluationContext Context( 13254 getSema(), EnterExpressionEvaluationContext::InitList, 13255 E->isListInitialization()); 13256 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 13257 &ArgumentChanged)) 13258 return ExprError(); 13259 } 13260 13261 if (!getDerived().AlwaysRebuild() && 13262 T == E->getTypeSourceInfo() && 13263 Constructor == E->getConstructor() && 13264 !ArgumentChanged) { 13265 // FIXME: Instantiation-specific 13266 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); 13267 return SemaRef.MaybeBindToTemporary(E); 13268 } 13269 13270 // FIXME: We should just pass E->isListInitialization(), but we're not 13271 // prepared to handle list-initialization without a child InitListExpr. 13272 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc(); 13273 return getDerived().RebuildCXXTemporaryObjectExpr( 13274 T, LParenLoc, Args, E->getEndLoc(), 13275 /*ListInitialization=*/LParenLoc.isInvalid()); 13276 } 13277 13278 template<typename Derived> 13279 ExprResult 13280 TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { 13281 // Transform any init-capture expressions before entering the scope of the 13282 // lambda body, because they are not semantically within that scope. 13283 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; 13284 struct TransformedInitCapture { 13285 // The location of the ... if the result is retaining a pack expansion. 13286 SourceLocation EllipsisLoc; 13287 // Zero or more expansions of the init-capture. 13288 SmallVector<InitCaptureInfoTy, 4> Expansions; 13289 }; 13290 SmallVector<TransformedInitCapture, 4> InitCaptures; 13291 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin()); 13292 for (LambdaExpr::capture_iterator C = E->capture_begin(), 13293 CEnd = E->capture_end(); 13294 C != CEnd; ++C) { 13295 if (!E->isInitCapture(C)) 13296 continue; 13297 13298 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()]; 13299 auto *OldVD = cast<VarDecl>(C->getCapturedVar()); 13300 13301 auto SubstInitCapture = [&](SourceLocation EllipsisLoc, 13302 std::optional<unsigned> NumExpansions) { 13303 ExprResult NewExprInitResult = getDerived().TransformInitializer( 13304 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit); 13305 13306 if (NewExprInitResult.isInvalid()) { 13307 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType())); 13308 return; 13309 } 13310 Expr *NewExprInit = NewExprInitResult.get(); 13311 13312 QualType NewInitCaptureType = 13313 getSema().buildLambdaInitCaptureInitialization( 13314 C->getLocation(), C->getCaptureKind() == LCK_ByRef, 13315 EllipsisLoc, NumExpansions, OldVD->getIdentifier(), 13316 cast<VarDecl>(C->getCapturedVar())->getInitStyle() != 13317 VarDecl::CInit, 13318 NewExprInit); 13319 Result.Expansions.push_back( 13320 InitCaptureInfoTy(NewExprInit, NewInitCaptureType)); 13321 }; 13322 13323 // If this is an init-capture pack, consider expanding the pack now. 13324 if (OldVD->isParameterPack()) { 13325 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo() 13326 ->getTypeLoc() 13327 .castAs<PackExpansionTypeLoc>(); 13328 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 13329 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded); 13330 13331 // Determine whether the set of unexpanded parameter packs can and should 13332 // be expanded. 13333 bool Expand = true; 13334 bool RetainExpansion = false; 13335 std::optional<unsigned> OrigNumExpansions = 13336 ExpansionTL.getTypePtr()->getNumExpansions(); 13337 std::optional<unsigned> NumExpansions = OrigNumExpansions; 13338 if (getDerived().TryExpandParameterPacks( 13339 ExpansionTL.getEllipsisLoc(), 13340 OldVD->getInit()->getSourceRange(), Unexpanded, Expand, 13341 RetainExpansion, NumExpansions)) 13342 return ExprError(); 13343 if (Expand) { 13344 for (unsigned I = 0; I != *NumExpansions; ++I) { 13345 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 13346 SubstInitCapture(SourceLocation(), std::nullopt); 13347 } 13348 } 13349 if (!Expand || RetainExpansion) { 13350 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 13351 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions); 13352 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc(); 13353 } 13354 } else { 13355 SubstInitCapture(SourceLocation(), std::nullopt); 13356 } 13357 } 13358 13359 LambdaScopeInfo *LSI = getSema().PushLambdaScope(); 13360 Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); 13361 13362 // Create the local class that will describe the lambda. 13363 13364 // FIXME: DependencyKind below is wrong when substituting inside a templated 13365 // context that isn't a DeclContext (such as a variable template), or when 13366 // substituting an unevaluated lambda inside of a function's parameter's type 13367 // - as parameter types are not instantiated from within a function's DC. We 13368 // use evaluation contexts to distinguish the function parameter case. 13369 CXXRecordDecl::LambdaDependencyKind DependencyKind = 13370 CXXRecordDecl::LDK_Unknown; 13371 if ((getSema().isUnevaluatedContext() || 13372 getSema().isConstantEvaluatedContext()) && 13373 (getSema().CurContext->isFileContext() || 13374 !getSema().CurContext->getParent()->isDependentContext())) 13375 DependencyKind = CXXRecordDecl::LDK_NeverDependent; 13376 13377 CXXRecordDecl *OldClass = E->getLambdaClass(); 13378 CXXRecordDecl *Class = getSema().createLambdaClosureType( 13379 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind, 13380 E->getCaptureDefault()); 13381 getDerived().transformedLocalDecl(OldClass, {Class}); 13382 13383 CXXMethodDecl *NewCallOperator = 13384 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class); 13385 NewCallOperator->setLexicalDeclContext(getSema().CurContext); 13386 13387 // Enter the scope of the lambda. 13388 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(), 13389 E->getCaptureDefault(), E->getCaptureDefaultLoc(), 13390 E->hasExplicitParameters(), E->isMutable()); 13391 13392 // Introduce the context of the call operator. 13393 Sema::ContextRAII SavedContext(getSema(), NewCallOperator, 13394 /*NewThisContext*/false); 13395 13396 bool Invalid = false; 13397 13398 // Transform captures. 13399 for (LambdaExpr::capture_iterator C = E->capture_begin(), 13400 CEnd = E->capture_end(); 13401 C != CEnd; ++C) { 13402 // When we hit the first implicit capture, tell Sema that we've finished 13403 // the list of explicit captures. 13404 if (C->isImplicit()) 13405 break; 13406 13407 // Capturing 'this' is trivial. 13408 if (C->capturesThis()) { 13409 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), 13410 /*BuildAndDiagnose*/ true, nullptr, 13411 C->getCaptureKind() == LCK_StarThis); 13412 continue; 13413 } 13414 // Captured expression will be recaptured during captured variables 13415 // rebuilding. 13416 if (C->capturesVLAType()) 13417 continue; 13418 13419 // Rebuild init-captures, including the implied field declaration. 13420 if (E->isInitCapture(C)) { 13421 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()]; 13422 13423 auto *OldVD = cast<VarDecl>(C->getCapturedVar()); 13424 llvm::SmallVector<Decl*, 4> NewVDs; 13425 13426 for (InitCaptureInfoTy &Info : NewC.Expansions) { 13427 ExprResult Init = Info.first; 13428 QualType InitQualType = Info.second; 13429 if (Init.isInvalid() || InitQualType.isNull()) { 13430 Invalid = true; 13431 break; 13432 } 13433 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( 13434 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc, 13435 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(), 13436 getSema().CurContext); 13437 if (!NewVD) { 13438 Invalid = true; 13439 break; 13440 } 13441 NewVDs.push_back(NewVD); 13442 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef); 13443 } 13444 13445 if (Invalid) 13446 break; 13447 13448 getDerived().transformedLocalDecl(OldVD, NewVDs); 13449 continue; 13450 } 13451 13452 assert(C->capturesVariable() && "unexpected kind of lambda capture"); 13453 13454 // Determine the capture kind for Sema. 13455 Sema::TryCaptureKind Kind 13456 = C->isImplicit()? Sema::TryCapture_Implicit 13457 : C->getCaptureKind() == LCK_ByCopy 13458 ? Sema::TryCapture_ExplicitByVal 13459 : Sema::TryCapture_ExplicitByRef; 13460 SourceLocation EllipsisLoc; 13461 if (C->isPackExpansion()) { 13462 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); 13463 bool ShouldExpand = false; 13464 bool RetainExpansion = false; 13465 std::optional<unsigned> NumExpansions; 13466 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), 13467 C->getLocation(), 13468 Unexpanded, 13469 ShouldExpand, RetainExpansion, 13470 NumExpansions)) { 13471 Invalid = true; 13472 continue; 13473 } 13474 13475 if (ShouldExpand) { 13476 // The transform has determined that we should perform an expansion; 13477 // transform and capture each of the arguments. 13478 // expansion of the pattern. Do so. 13479 auto *Pack = cast<VarDecl>(C->getCapturedVar()); 13480 for (unsigned I = 0; I != *NumExpansions; ++I) { 13481 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 13482 VarDecl *CapturedVar 13483 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), 13484 Pack)); 13485 if (!CapturedVar) { 13486 Invalid = true; 13487 continue; 13488 } 13489 13490 // Capture the transformed variable. 13491 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); 13492 } 13493 13494 // FIXME: Retain a pack expansion if RetainExpansion is true. 13495 13496 continue; 13497 } 13498 13499 EllipsisLoc = C->getEllipsisLoc(); 13500 } 13501 13502 // Transform the captured variable. 13503 auto *CapturedVar = cast_or_null<ValueDecl>( 13504 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar())); 13505 if (!CapturedVar || CapturedVar->isInvalidDecl()) { 13506 Invalid = true; 13507 continue; 13508 } 13509 13510 // Capture the transformed variable. 13511 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, 13512 EllipsisLoc); 13513 } 13514 getSema().finishLambdaExplicitCaptures(LSI); 13515 13516 // Transform the template parameters, and add them to the current 13517 // instantiation scope. The null case is handled correctly. 13518 auto TPL = getDerived().TransformTemplateParameterList( 13519 E->getTemplateParameterList()); 13520 LSI->GLTemplateParameterList = TPL; 13521 13522 // Transform the type of the original lambda's call operator. 13523 // The transformation MUST be done in the CurrentInstantiationScope since 13524 // it introduces a mapping of the original to the newly created 13525 // transformed parameters. 13526 TypeSourceInfo *NewCallOpTSI = nullptr; 13527 { 13528 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); 13529 auto OldCallOpFPTL = 13530 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); 13531 13532 TypeLocBuilder NewCallOpTLBuilder; 13533 SmallVector<QualType, 4> ExceptionStorage; 13534 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. 13535 QualType NewCallOpType = TransformFunctionProtoType( 13536 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(), 13537 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { 13538 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI, 13539 ExceptionStorage, Changed); 13540 }); 13541 if (NewCallOpType.isNull()) 13542 return ExprError(); 13543 NewCallOpTSI = 13544 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType); 13545 } 13546 13547 getSema().CompleteLambdaCallOperator( 13548 NewCallOperator, E->getCallOperator()->getLocation(), 13549 E->getCallOperator()->getInnerLocStart(), 13550 E->getCallOperator()->getTrailingRequiresClause(), NewCallOpTSI, 13551 E->getCallOperator()->getConstexprKind(), 13552 E->getCallOperator()->getStorageClass(), 13553 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(), 13554 E->hasExplicitResultType()); 13555 13556 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); 13557 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator}); 13558 13559 { 13560 // Number the lambda for linkage purposes if necessary. 13561 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext()); 13562 13563 std::optional<CXXRecordDecl::LambdaNumbering> Numbering; 13564 if (getDerived().ReplacingOriginal()) { 13565 Numbering = OldClass->getLambdaNumbering(); 13566 } 13567 13568 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering); 13569 } 13570 13571 // FIXME: Sema's lambda-building mechanism expects us to push an expression 13572 // evaluation context even if we're not transforming the function body. 13573 getSema().PushExpressionEvaluationContext( 13574 Sema::ExpressionEvaluationContext::PotentiallyEvaluated); 13575 13576 // Instantiate the body of the lambda expression. 13577 StmtResult Body = 13578 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody()); 13579 13580 // ActOnLambda* will pop the function scope for us. 13581 FuncScopeCleanup.disable(); 13582 13583 if (Body.isInvalid()) { 13584 SavedContext.pop(); 13585 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr, 13586 /*IsInstantiation=*/true); 13587 return ExprError(); 13588 } 13589 13590 // Copy the LSI before ActOnFinishFunctionBody removes it. 13591 // FIXME: This is dumb. Store the lambda information somewhere that outlives 13592 // the call operator. 13593 auto LSICopy = *LSI; 13594 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), 13595 /*IsInstantiation*/ true); 13596 SavedContext.pop(); 13597 13598 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(), 13599 &LSICopy); 13600 } 13601 13602 template<typename Derived> 13603 StmtResult 13604 TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) { 13605 return TransformStmt(S); 13606 } 13607 13608 template<typename Derived> 13609 StmtResult 13610 TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) { 13611 // Transform captures. 13612 for (LambdaExpr::capture_iterator C = E->capture_begin(), 13613 CEnd = E->capture_end(); 13614 C != CEnd; ++C) { 13615 // When we hit the first implicit capture, tell Sema that we've finished 13616 // the list of explicit captures. 13617 if (!C->isImplicit()) 13618 continue; 13619 13620 // Capturing 'this' is trivial. 13621 if (C->capturesThis()) { 13622 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), 13623 /*BuildAndDiagnose*/ true, nullptr, 13624 C->getCaptureKind() == LCK_StarThis); 13625 continue; 13626 } 13627 // Captured expression will be recaptured during captured variables 13628 // rebuilding. 13629 if (C->capturesVLAType()) 13630 continue; 13631 13632 assert(C->capturesVariable() && "unexpected kind of lambda capture"); 13633 assert(!E->isInitCapture(C) && "implicit init-capture?"); 13634 13635 // Transform the captured variable. 13636 VarDecl *CapturedVar = cast_or_null<VarDecl>( 13637 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar())); 13638 if (!CapturedVar || CapturedVar->isInvalidDecl()) 13639 return StmtError(); 13640 13641 // Capture the transformed variable. 13642 getSema().tryCaptureVariable(CapturedVar, C->getLocation()); 13643 } 13644 13645 return S; 13646 } 13647 13648 template<typename Derived> 13649 ExprResult 13650 TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 13651 CXXUnresolvedConstructExpr *E) { 13652 TypeSourceInfo *T = 13653 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); 13654 if (!T) 13655 return ExprError(); 13656 13657 bool ArgumentChanged = false; 13658 SmallVector<Expr*, 8> Args; 13659 Args.reserve(E->getNumArgs()); 13660 { 13661 EnterExpressionEvaluationContext Context( 13662 getSema(), EnterExpressionEvaluationContext::InitList, 13663 E->isListInitialization()); 13664 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args, 13665 &ArgumentChanged)) 13666 return ExprError(); 13667 } 13668 13669 if (!getDerived().AlwaysRebuild() && 13670 T == E->getTypeSourceInfo() && 13671 !ArgumentChanged) 13672 return E; 13673 13674 // FIXME: we're faking the locations of the commas 13675 return getDerived().RebuildCXXUnresolvedConstructExpr( 13676 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization()); 13677 } 13678 13679 template<typename Derived> 13680 ExprResult 13681 TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 13682 CXXDependentScopeMemberExpr *E) { 13683 // Transform the base of the expression. 13684 ExprResult Base((Expr*) nullptr); 13685 Expr *OldBase; 13686 QualType BaseType; 13687 QualType ObjectType; 13688 if (!E->isImplicitAccess()) { 13689 OldBase = E->getBase(); 13690 Base = getDerived().TransformExpr(OldBase); 13691 if (Base.isInvalid()) 13692 return ExprError(); 13693 13694 // Start the member reference and compute the object's type. 13695 ParsedType ObjectTy; 13696 bool MayBePseudoDestructor = false; 13697 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), 13698 E->getOperatorLoc(), 13699 E->isArrow()? tok::arrow : tok::period, 13700 ObjectTy, 13701 MayBePseudoDestructor); 13702 if (Base.isInvalid()) 13703 return ExprError(); 13704 13705 ObjectType = ObjectTy.get(); 13706 BaseType = ((Expr*) Base.get())->getType(); 13707 } else { 13708 OldBase = nullptr; 13709 BaseType = getDerived().TransformType(E->getBaseType()); 13710 ObjectType = BaseType->castAs<PointerType>()->getPointeeType(); 13711 } 13712 13713 // Transform the first part of the nested-name-specifier that qualifies 13714 // the member name. 13715 NamedDecl *FirstQualifierInScope 13716 = getDerived().TransformFirstQualifierInScope( 13717 E->getFirstQualifierFoundInScope(), 13718 E->getQualifierLoc().getBeginLoc()); 13719 13720 NestedNameSpecifierLoc QualifierLoc; 13721 if (E->getQualifier()) { 13722 QualifierLoc 13723 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), 13724 ObjectType, 13725 FirstQualifierInScope); 13726 if (!QualifierLoc) 13727 return ExprError(); 13728 } 13729 13730 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 13731 13732 // TODO: If this is a conversion-function-id, verify that the 13733 // destination type name (if present) resolves the same way after 13734 // instantiation as it did in the local scope. 13735 13736 DeclarationNameInfo NameInfo 13737 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 13738 if (!NameInfo.getName()) 13739 return ExprError(); 13740 13741 if (!E->hasExplicitTemplateArgs()) { 13742 // This is a reference to a member without an explicitly-specified 13743 // template argument list. Optimize for this common case. 13744 if (!getDerived().AlwaysRebuild() && 13745 Base.get() == OldBase && 13746 BaseType == E->getBaseType() && 13747 QualifierLoc == E->getQualifierLoc() && 13748 NameInfo.getName() == E->getMember() && 13749 FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 13750 return E; 13751 13752 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 13753 BaseType, 13754 E->isArrow(), 13755 E->getOperatorLoc(), 13756 QualifierLoc, 13757 TemplateKWLoc, 13758 FirstQualifierInScope, 13759 NameInfo, 13760 /*TemplateArgs*/nullptr); 13761 } 13762 13763 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 13764 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 13765 E->getNumTemplateArgs(), 13766 TransArgs)) 13767 return ExprError(); 13768 13769 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 13770 BaseType, 13771 E->isArrow(), 13772 E->getOperatorLoc(), 13773 QualifierLoc, 13774 TemplateKWLoc, 13775 FirstQualifierInScope, 13776 NameInfo, 13777 &TransArgs); 13778 } 13779 13780 template <typename Derived> 13781 ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr( 13782 UnresolvedMemberExpr *Old) { 13783 // Transform the base of the expression. 13784 ExprResult Base((Expr *)nullptr); 13785 QualType BaseType; 13786 if (!Old->isImplicitAccess()) { 13787 Base = getDerived().TransformExpr(Old->getBase()); 13788 if (Base.isInvalid()) 13789 return ExprError(); 13790 Base = 13791 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow()); 13792 if (Base.isInvalid()) 13793 return ExprError(); 13794 BaseType = Base.get()->getType(); 13795 } else { 13796 BaseType = getDerived().TransformType(Old->getBaseType()); 13797 } 13798 13799 NestedNameSpecifierLoc QualifierLoc; 13800 if (Old->getQualifierLoc()) { 13801 QualifierLoc = 13802 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 13803 if (!QualifierLoc) 13804 return ExprError(); 13805 } 13806 13807 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 13808 13809 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName); 13810 13811 // Transform the declaration set. 13812 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R)) 13813 return ExprError(); 13814 13815 // Determine the naming class. 13816 if (Old->getNamingClass()) { 13817 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>( 13818 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass())); 13819 if (!NamingClass) 13820 return ExprError(); 13821 13822 R.setNamingClass(NamingClass); 13823 } 13824 13825 TemplateArgumentListInfo TransArgs; 13826 if (Old->hasExplicitTemplateArgs()) { 13827 TransArgs.setLAngleLoc(Old->getLAngleLoc()); 13828 TransArgs.setRAngleLoc(Old->getRAngleLoc()); 13829 if (getDerived().TransformTemplateArguments( 13830 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs)) 13831 return ExprError(); 13832 } 13833 13834 // FIXME: to do this check properly, we will need to preserve the 13835 // first-qualifier-in-scope here, just in case we had a dependent 13836 // base (and therefore couldn't do the check) and a 13837 // nested-name-qualifier (and therefore could do the lookup). 13838 NamedDecl *FirstQualifierInScope = nullptr; 13839 13840 return getDerived().RebuildUnresolvedMemberExpr( 13841 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc, 13842 TemplateKWLoc, FirstQualifierInScope, R, 13843 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr)); 13844 } 13845 13846 template<typename Derived> 13847 ExprResult 13848 TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 13849 EnterExpressionEvaluationContext Unevaluated( 13850 SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); 13851 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 13852 if (SubExpr.isInvalid()) 13853 return ExprError(); 13854 13855 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 13856 return E; 13857 13858 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 13859 } 13860 13861 template<typename Derived> 13862 ExprResult 13863 TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 13864 ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); 13865 if (Pattern.isInvalid()) 13866 return ExprError(); 13867 13868 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) 13869 return E; 13870 13871 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), 13872 E->getNumExpansions()); 13873 } 13874 13875 template<typename Derived> 13876 ExprResult 13877 TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 13878 // If E is not value-dependent, then nothing will change when we transform it. 13879 // Note: This is an instantiation-centric view. 13880 if (!E->isValueDependent()) 13881 return E; 13882 13883 EnterExpressionEvaluationContext Unevaluated( 13884 getSema(), Sema::ExpressionEvaluationContext::Unevaluated); 13885 13886 ArrayRef<TemplateArgument> PackArgs; 13887 TemplateArgument ArgStorage; 13888 13889 // Find the argument list to transform. 13890 if (E->isPartiallySubstituted()) { 13891 PackArgs = E->getPartialArguments(); 13892 } else if (E->isValueDependent()) { 13893 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 13894 bool ShouldExpand = false; 13895 bool RetainExpansion = false; 13896 std::optional<unsigned> NumExpansions; 13897 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 13898 Unexpanded, 13899 ShouldExpand, RetainExpansion, 13900 NumExpansions)) 13901 return ExprError(); 13902 13903 // If we need to expand the pack, build a template argument from it and 13904 // expand that. 13905 if (ShouldExpand) { 13906 auto *Pack = E->getPack(); 13907 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) { 13908 ArgStorage = getSema().Context.getPackExpansionType( 13909 getSema().Context.getTypeDeclType(TTPD), std::nullopt); 13910 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) { 13911 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt); 13912 } else { 13913 auto *VD = cast<ValueDecl>(Pack); 13914 ExprResult DRE = getSema().BuildDeclRefExpr( 13915 VD, VD->getType().getNonLValueExprType(getSema().Context), 13916 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue, 13917 E->getPackLoc()); 13918 if (DRE.isInvalid()) 13919 return ExprError(); 13920 ArgStorage = new (getSema().Context) 13921 PackExpansionExpr(getSema().Context.DependentTy, DRE.get(), 13922 E->getPackLoc(), std::nullopt); 13923 } 13924 PackArgs = ArgStorage; 13925 } 13926 } 13927 13928 // If we're not expanding the pack, just transform the decl. 13929 if (!PackArgs.size()) { 13930 auto *Pack = cast_or_null<NamedDecl>( 13931 getDerived().TransformDecl(E->getPackLoc(), E->getPack())); 13932 if (!Pack) 13933 return ExprError(); 13934 return getDerived().RebuildSizeOfPackExpr( 13935 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(), 13936 std::nullopt, std::nullopt); 13937 } 13938 13939 // Try to compute the result without performing a partial substitution. 13940 std::optional<unsigned> Result = 0; 13941 for (const TemplateArgument &Arg : PackArgs) { 13942 if (!Arg.isPackExpansion()) { 13943 Result = *Result + 1; 13944 continue; 13945 } 13946 13947 TemplateArgumentLoc ArgLoc; 13948 InventTemplateArgumentLoc(Arg, ArgLoc); 13949 13950 // Find the pattern of the pack expansion. 13951 SourceLocation Ellipsis; 13952 std::optional<unsigned> OrigNumExpansions; 13953 TemplateArgumentLoc Pattern = 13954 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis, 13955 OrigNumExpansions); 13956 13957 // Substitute under the pack expansion. Do not expand the pack (yet). 13958 TemplateArgumentLoc OutPattern; 13959 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 13960 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, 13961 /*Uneval*/ true)) 13962 return true; 13963 13964 // See if we can determine the number of arguments from the result. 13965 std::optional<unsigned> NumExpansions = 13966 getSema().getFullyPackExpandedSize(OutPattern.getArgument()); 13967 if (!NumExpansions) { 13968 // No: we must be in an alias template expansion, and we're going to need 13969 // to actually expand the packs. 13970 Result = std::nullopt; 13971 break; 13972 } 13973 13974 Result = *Result + *NumExpansions; 13975 } 13976 13977 // Common case: we could determine the number of expansions without 13978 // substituting. 13979 if (Result) 13980 return getDerived().RebuildSizeOfPackExpr( 13981 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(), 13982 *Result, std::nullopt); 13983 13984 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(), 13985 E->getPackLoc()); 13986 { 13987 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity()); 13988 typedef TemplateArgumentLocInventIterator< 13989 Derived, const TemplateArgument*> PackLocIterator; 13990 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()), 13991 PackLocIterator(*this, PackArgs.end()), 13992 TransformedPackArgs, /*Uneval*/true)) 13993 return ExprError(); 13994 } 13995 13996 // Check whether we managed to fully-expand the pack. 13997 // FIXME: Is it possible for us to do so and not hit the early exit path? 13998 SmallVector<TemplateArgument, 8> Args; 13999 bool PartialSubstitution = false; 14000 for (auto &Loc : TransformedPackArgs.arguments()) { 14001 Args.push_back(Loc.getArgument()); 14002 if (Loc.getArgument().isPackExpansion()) 14003 PartialSubstitution = true; 14004 } 14005 14006 if (PartialSubstitution) 14007 return getDerived().RebuildSizeOfPackExpr( 14008 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(), 14009 std::nullopt, Args); 14010 14011 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), 14012 E->getPackLoc(), E->getRParenLoc(), 14013 Args.size(), std::nullopt); 14014 } 14015 14016 template<typename Derived> 14017 ExprResult 14018 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( 14019 SubstNonTypeTemplateParmPackExpr *E) { 14020 // Default behavior is to do nothing with this transformation. 14021 return E; 14022 } 14023 14024 template<typename Derived> 14025 ExprResult 14026 TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( 14027 SubstNonTypeTemplateParmExpr *E) { 14028 // Default behavior is to do nothing with this transformation. 14029 return E; 14030 } 14031 14032 template<typename Derived> 14033 ExprResult 14034 TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { 14035 // Default behavior is to do nothing with this transformation. 14036 return E; 14037 } 14038 14039 template<typename Derived> 14040 ExprResult 14041 TreeTransform<Derived>::TransformMaterializeTemporaryExpr( 14042 MaterializeTemporaryExpr *E) { 14043 return getDerived().TransformExpr(E->getSubExpr()); 14044 } 14045 14046 template<typename Derived> 14047 ExprResult 14048 TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { 14049 UnresolvedLookupExpr *Callee = nullptr; 14050 if (Expr *OldCallee = E->getCallee()) { 14051 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee); 14052 if (CalleeResult.isInvalid()) 14053 return ExprError(); 14054 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get()); 14055 } 14056 14057 Expr *Pattern = E->getPattern(); 14058 14059 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 14060 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 14061 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 14062 14063 // Determine whether the set of unexpanded parameter packs can and should 14064 // be expanded. 14065 bool Expand = true; 14066 bool RetainExpansion = false; 14067 std::optional<unsigned> OrigNumExpansions = E->getNumExpansions(), 14068 NumExpansions = OrigNumExpansions; 14069 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(), 14070 Pattern->getSourceRange(), 14071 Unexpanded, 14072 Expand, RetainExpansion, 14073 NumExpansions)) 14074 return true; 14075 14076 if (!Expand) { 14077 // Do not expand any packs here, just transform and rebuild a fold 14078 // expression. 14079 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 14080 14081 ExprResult LHS = 14082 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); 14083 if (LHS.isInvalid()) 14084 return true; 14085 14086 ExprResult RHS = 14087 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); 14088 if (RHS.isInvalid()) 14089 return true; 14090 14091 if (!getDerived().AlwaysRebuild() && 14092 LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) 14093 return E; 14094 14095 return getDerived().RebuildCXXFoldExpr( 14096 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(), 14097 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions); 14098 } 14099 14100 // Formally a fold expression expands to nested parenthesized expressions. 14101 // Enforce this limit to avoid creating trees so deep we can't safely traverse 14102 // them. 14103 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) { 14104 SemaRef.Diag(E->getEllipsisLoc(), 14105 clang::diag::err_fold_expression_limit_exceeded) 14106 << *NumExpansions << SemaRef.getLangOpts().BracketDepth 14107 << E->getSourceRange(); 14108 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth); 14109 return ExprError(); 14110 } 14111 14112 // The transform has determined that we should perform an elementwise 14113 // expansion of the pattern. Do so. 14114 ExprResult Result = getDerived().TransformExpr(E->getInit()); 14115 if (Result.isInvalid()) 14116 return true; 14117 bool LeftFold = E->isLeftFold(); 14118 14119 // If we're retaining an expansion for a right fold, it is the innermost 14120 // component and takes the init (if any). 14121 if (!LeftFold && RetainExpansion) { 14122 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 14123 14124 ExprResult Out = getDerived().TransformExpr(Pattern); 14125 if (Out.isInvalid()) 14126 return true; 14127 14128 Result = getDerived().RebuildCXXFoldExpr( 14129 Callee, E->getBeginLoc(), Out.get(), E->getOperator(), 14130 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions); 14131 if (Result.isInvalid()) 14132 return true; 14133 } 14134 14135 for (unsigned I = 0; I != *NumExpansions; ++I) { 14136 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( 14137 getSema(), LeftFold ? I : *NumExpansions - I - 1); 14138 ExprResult Out = getDerived().TransformExpr(Pattern); 14139 if (Out.isInvalid()) 14140 return true; 14141 14142 if (Out.get()->containsUnexpandedParameterPack()) { 14143 // We still have a pack; retain a pack expansion for this slice. 14144 Result = getDerived().RebuildCXXFoldExpr( 14145 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(), 14146 E->getOperator(), E->getEllipsisLoc(), 14147 LeftFold ? Out.get() : Result.get(), E->getEndLoc(), 14148 OrigNumExpansions); 14149 } else if (Result.isUsable()) { 14150 // We've got down to a single element; build a binary operator. 14151 Expr *LHS = LeftFold ? Result.get() : Out.get(); 14152 Expr *RHS = LeftFold ? Out.get() : Result.get(); 14153 if (Callee) { 14154 UnresolvedSet<16> Functions; 14155 Functions.append(Callee->decls_begin(), Callee->decls_end()); 14156 Result = getDerived().RebuildCXXOperatorCallExpr( 14157 BinaryOperator::getOverloadedOperator(E->getOperator()), 14158 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(), 14159 Functions, LHS, RHS); 14160 } else { 14161 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(), 14162 E->getOperator(), LHS, RHS); 14163 } 14164 } else 14165 Result = Out; 14166 14167 if (Result.isInvalid()) 14168 return true; 14169 } 14170 14171 // If we're retaining an expansion for a left fold, it is the outermost 14172 // component and takes the complete expansion so far as its init (if any). 14173 if (LeftFold && RetainExpansion) { 14174 ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 14175 14176 ExprResult Out = getDerived().TransformExpr(Pattern); 14177 if (Out.isInvalid()) 14178 return true; 14179 14180 Result = getDerived().RebuildCXXFoldExpr( 14181 Callee, E->getBeginLoc(), Result.get(), E->getOperator(), 14182 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions); 14183 if (Result.isInvalid()) 14184 return true; 14185 } 14186 14187 // If we had no init and an empty pack, and we're not retaining an expansion, 14188 // then produce a fallback value or error. 14189 if (Result.isUnset()) 14190 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), 14191 E->getOperator()); 14192 14193 return Result; 14194 } 14195 14196 template <typename Derived> 14197 ExprResult 14198 TreeTransform<Derived>::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) { 14199 SmallVector<Expr *, 4> TransformedInits; 14200 ArrayRef<Expr *> InitExprs = E->getInitExprs(); 14201 if (TransformExprs(InitExprs.data(), InitExprs.size(), true, 14202 TransformedInits)) 14203 return ExprError(); 14204 14205 return getDerived().RebuildParenListExpr(E->getBeginLoc(), TransformedInits, 14206 E->getEndLoc()); 14207 } 14208 14209 template<typename Derived> 14210 ExprResult 14211 TreeTransform<Derived>::TransformCXXStdInitializerListExpr( 14212 CXXStdInitializerListExpr *E) { 14213 return getDerived().TransformExpr(E->getSubExpr()); 14214 } 14215 14216 template<typename Derived> 14217 ExprResult 14218 TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 14219 return SemaRef.MaybeBindToTemporary(E); 14220 } 14221 14222 template<typename Derived> 14223 ExprResult 14224 TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { 14225 return E; 14226 } 14227 14228 template<typename Derived> 14229 ExprResult 14230 TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { 14231 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 14232 if (SubExpr.isInvalid()) 14233 return ExprError(); 14234 14235 if (!getDerived().AlwaysRebuild() && 14236 SubExpr.get() == E->getSubExpr()) 14237 return E; 14238 14239 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); 14240 } 14241 14242 template<typename Derived> 14243 ExprResult 14244 TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { 14245 // Transform each of the elements. 14246 SmallVector<Expr *, 8> Elements; 14247 bool ArgChanged = false; 14248 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), 14249 /*IsCall=*/false, Elements, &ArgChanged)) 14250 return ExprError(); 14251 14252 if (!getDerived().AlwaysRebuild() && !ArgChanged) 14253 return SemaRef.MaybeBindToTemporary(E); 14254 14255 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), 14256 Elements.data(), 14257 Elements.size()); 14258 } 14259 14260 template<typename Derived> 14261 ExprResult 14262 TreeTransform<Derived>::TransformObjCDictionaryLiteral( 14263 ObjCDictionaryLiteral *E) { 14264 // Transform each of the elements. 14265 SmallVector<ObjCDictionaryElement, 8> Elements; 14266 bool ArgChanged = false; 14267 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { 14268 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); 14269 14270 if (OrigElement.isPackExpansion()) { 14271 // This key/value element is a pack expansion. 14272 SmallVector<UnexpandedParameterPack, 2> Unexpanded; 14273 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); 14274 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); 14275 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 14276 14277 // Determine whether the set of unexpanded parameter packs can 14278 // and should be expanded. 14279 bool Expand = true; 14280 bool RetainExpansion = false; 14281 std::optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; 14282 std::optional<unsigned> NumExpansions = OrigNumExpansions; 14283 SourceRange PatternRange(OrigElement.Key->getBeginLoc(), 14284 OrigElement.Value->getEndLoc()); 14285 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, 14286 PatternRange, Unexpanded, Expand, 14287 RetainExpansion, NumExpansions)) 14288 return ExprError(); 14289 14290 if (!Expand) { 14291 // The transform has determined that we should perform a simple 14292 // transformation on the pack expansion, producing another pack 14293 // expansion. 14294 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 14295 ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 14296 if (Key.isInvalid()) 14297 return ExprError(); 14298 14299 if (Key.get() != OrigElement.Key) 14300 ArgChanged = true; 14301 14302 ExprResult Value = getDerived().TransformExpr(OrigElement.Value); 14303 if (Value.isInvalid()) 14304 return ExprError(); 14305 14306 if (Value.get() != OrigElement.Value) 14307 ArgChanged = true; 14308 14309 ObjCDictionaryElement Expansion = { 14310 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions 14311 }; 14312 Elements.push_back(Expansion); 14313 continue; 14314 } 14315 14316 // Record right away that the argument was changed. This needs 14317 // to happen even if the array expands to nothing. 14318 ArgChanged = true; 14319 14320 // The transform has determined that we should perform an elementwise 14321 // expansion of the pattern. Do so. 14322 for (unsigned I = 0; I != *NumExpansions; ++I) { 14323 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 14324 ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 14325 if (Key.isInvalid()) 14326 return ExprError(); 14327 14328 ExprResult Value = getDerived().TransformExpr(OrigElement.Value); 14329 if (Value.isInvalid()) 14330 return ExprError(); 14331 14332 ObjCDictionaryElement Element = { 14333 Key.get(), Value.get(), SourceLocation(), NumExpansions 14334 }; 14335 14336 // If any unexpanded parameter packs remain, we still have a 14337 // pack expansion. 14338 // FIXME: Can this really happen? 14339 if (Key.get()->containsUnexpandedParameterPack() || 14340 Value.get()->containsUnexpandedParameterPack()) 14341 Element.EllipsisLoc = OrigElement.EllipsisLoc; 14342 14343 Elements.push_back(Element); 14344 } 14345 14346 // FIXME: Retain a pack expansion if RetainExpansion is true. 14347 14348 // We've finished with this pack expansion. 14349 continue; 14350 } 14351 14352 // Transform and check key. 14353 ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 14354 if (Key.isInvalid()) 14355 return ExprError(); 14356 14357 if (Key.get() != OrigElement.Key) 14358 ArgChanged = true; 14359 14360 // Transform and check value. 14361 ExprResult Value 14362 = getDerived().TransformExpr(OrigElement.Value); 14363 if (Value.isInvalid()) 14364 return ExprError(); 14365 14366 if (Value.get() != OrigElement.Value) 14367 ArgChanged = true; 14368 14369 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(), 14370 std::nullopt}; 14371 Elements.push_back(Element); 14372 } 14373 14374 if (!getDerived().AlwaysRebuild() && !ArgChanged) 14375 return SemaRef.MaybeBindToTemporary(E); 14376 14377 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), 14378 Elements); 14379 } 14380 14381 template<typename Derived> 14382 ExprResult 14383 TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 14384 TypeSourceInfo *EncodedTypeInfo 14385 = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 14386 if (!EncodedTypeInfo) 14387 return ExprError(); 14388 14389 if (!getDerived().AlwaysRebuild() && 14390 EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 14391 return E; 14392 14393 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 14394 EncodedTypeInfo, 14395 E->getRParenLoc()); 14396 } 14397 14398 template<typename Derived> 14399 ExprResult TreeTransform<Derived>:: 14400 TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 14401 // This is a kind of implicit conversion, and it needs to get dropped 14402 // and recomputed for the same general reasons that ImplicitCastExprs 14403 // do, as well a more specific one: this expression is only valid when 14404 // it appears *immediately* as an argument expression. 14405 return getDerived().TransformExpr(E->getSubExpr()); 14406 } 14407 14408 template<typename Derived> 14409 ExprResult TreeTransform<Derived>:: 14410 TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 14411 TypeSourceInfo *TSInfo 14412 = getDerived().TransformType(E->getTypeInfoAsWritten()); 14413 if (!TSInfo) 14414 return ExprError(); 14415 14416 ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); 14417 if (Result.isInvalid()) 14418 return ExprError(); 14419 14420 if (!getDerived().AlwaysRebuild() && 14421 TSInfo == E->getTypeInfoAsWritten() && 14422 Result.get() == E->getSubExpr()) 14423 return E; 14424 14425 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), 14426 E->getBridgeKeywordLoc(), TSInfo, 14427 Result.get()); 14428 } 14429 14430 template <typename Derived> 14431 ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr( 14432 ObjCAvailabilityCheckExpr *E) { 14433 return E; 14434 } 14435 14436 template<typename Derived> 14437 ExprResult 14438 TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 14439 // Transform arguments. 14440 bool ArgChanged = false; 14441 SmallVector<Expr*, 8> Args; 14442 Args.reserve(E->getNumArgs()); 14443 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 14444 &ArgChanged)) 14445 return ExprError(); 14446 14447 if (E->getReceiverKind() == ObjCMessageExpr::Class) { 14448 // Class message: transform the receiver type. 14449 TypeSourceInfo *ReceiverTypeInfo 14450 = getDerived().TransformType(E->getClassReceiverTypeInfo()); 14451 if (!ReceiverTypeInfo) 14452 return ExprError(); 14453 14454 // If nothing changed, just retain the existing message send. 14455 if (!getDerived().AlwaysRebuild() && 14456 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 14457 return SemaRef.MaybeBindToTemporary(E); 14458 14459 // Build a new class message send. 14460 SmallVector<SourceLocation, 16> SelLocs; 14461 E->getSelectorLocs(SelLocs); 14462 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 14463 E->getSelector(), 14464 SelLocs, 14465 E->getMethodDecl(), 14466 E->getLeftLoc(), 14467 Args, 14468 E->getRightLoc()); 14469 } 14470 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || 14471 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { 14472 if (!E->getMethodDecl()) 14473 return ExprError(); 14474 14475 // Build a new class message send to 'super'. 14476 SmallVector<SourceLocation, 16> SelLocs; 14477 E->getSelectorLocs(SelLocs); 14478 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), 14479 E->getSelector(), 14480 SelLocs, 14481 E->getReceiverType(), 14482 E->getMethodDecl(), 14483 E->getLeftLoc(), 14484 Args, 14485 E->getRightLoc()); 14486 } 14487 14488 // Instance message: transform the receiver 14489 assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 14490 "Only class and instance messages may be instantiated"); 14491 ExprResult Receiver 14492 = getDerived().TransformExpr(E->getInstanceReceiver()); 14493 if (Receiver.isInvalid()) 14494 return ExprError(); 14495 14496 // If nothing changed, just retain the existing message send. 14497 if (!getDerived().AlwaysRebuild() && 14498 Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 14499 return SemaRef.MaybeBindToTemporary(E); 14500 14501 // Build a new instance message send. 14502 SmallVector<SourceLocation, 16> SelLocs; 14503 E->getSelectorLocs(SelLocs); 14504 return getDerived().RebuildObjCMessageExpr(Receiver.get(), 14505 E->getSelector(), 14506 SelLocs, 14507 E->getMethodDecl(), 14508 E->getLeftLoc(), 14509 Args, 14510 E->getRightLoc()); 14511 } 14512 14513 template<typename Derived> 14514 ExprResult 14515 TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 14516 return E; 14517 } 14518 14519 template<typename Derived> 14520 ExprResult 14521 TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 14522 return E; 14523 } 14524 14525 template<typename Derived> 14526 ExprResult 14527 TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 14528 // Transform the base expression. 14529 ExprResult Base = getDerived().TransformExpr(E->getBase()); 14530 if (Base.isInvalid()) 14531 return ExprError(); 14532 14533 // We don't need to transform the ivar; it will never change. 14534 14535 // If nothing changed, just retain the existing expression. 14536 if (!getDerived().AlwaysRebuild() && 14537 Base.get() == E->getBase()) 14538 return E; 14539 14540 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 14541 E->getLocation(), 14542 E->isArrow(), E->isFreeIvar()); 14543 } 14544 14545 template<typename Derived> 14546 ExprResult 14547 TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 14548 // 'super' and types never change. Property never changes. Just 14549 // retain the existing expression. 14550 if (!E->isObjectReceiver()) 14551 return E; 14552 14553 // Transform the base expression. 14554 ExprResult Base = getDerived().TransformExpr(E->getBase()); 14555 if (Base.isInvalid()) 14556 return ExprError(); 14557 14558 // We don't need to transform the property; it will never change. 14559 14560 // If nothing changed, just retain the existing expression. 14561 if (!getDerived().AlwaysRebuild() && 14562 Base.get() == E->getBase()) 14563 return E; 14564 14565 if (E->isExplicitProperty()) 14566 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 14567 E->getExplicitProperty(), 14568 E->getLocation()); 14569 14570 return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 14571 SemaRef.Context.PseudoObjectTy, 14572 E->getImplicitPropertyGetter(), 14573 E->getImplicitPropertySetter(), 14574 E->getLocation()); 14575 } 14576 14577 template<typename Derived> 14578 ExprResult 14579 TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { 14580 // Transform the base expression. 14581 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); 14582 if (Base.isInvalid()) 14583 return ExprError(); 14584 14585 // Transform the key expression. 14586 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); 14587 if (Key.isInvalid()) 14588 return ExprError(); 14589 14590 // If nothing changed, just retain the existing expression. 14591 if (!getDerived().AlwaysRebuild() && 14592 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) 14593 return E; 14594 14595 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), 14596 Base.get(), Key.get(), 14597 E->getAtIndexMethodDecl(), 14598 E->setAtIndexMethodDecl()); 14599 } 14600 14601 template<typename Derived> 14602 ExprResult 14603 TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 14604 // Transform the base expression. 14605 ExprResult Base = getDerived().TransformExpr(E->getBase()); 14606 if (Base.isInvalid()) 14607 return ExprError(); 14608 14609 // If nothing changed, just retain the existing expression. 14610 if (!getDerived().AlwaysRebuild() && 14611 Base.get() == E->getBase()) 14612 return E; 14613 14614 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 14615 E->getOpLoc(), 14616 E->isArrow()); 14617 } 14618 14619 template<typename Derived> 14620 ExprResult 14621 TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 14622 bool ArgumentChanged = false; 14623 SmallVector<Expr*, 8> SubExprs; 14624 SubExprs.reserve(E->getNumSubExprs()); 14625 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 14626 SubExprs, &ArgumentChanged)) 14627 return ExprError(); 14628 14629 if (!getDerived().AlwaysRebuild() && 14630 !ArgumentChanged) 14631 return E; 14632 14633 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 14634 SubExprs, 14635 E->getRParenLoc()); 14636 } 14637 14638 template<typename Derived> 14639 ExprResult 14640 TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { 14641 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); 14642 if (SrcExpr.isInvalid()) 14643 return ExprError(); 14644 14645 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 14646 if (!Type) 14647 return ExprError(); 14648 14649 if (!getDerived().AlwaysRebuild() && 14650 Type == E->getTypeSourceInfo() && 14651 SrcExpr.get() == E->getSrcExpr()) 14652 return E; 14653 14654 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), 14655 SrcExpr.get(), Type, 14656 E->getRParenLoc()); 14657 } 14658 14659 template<typename Derived> 14660 ExprResult 14661 TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 14662 BlockDecl *oldBlock = E->getBlockDecl(); 14663 14664 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); 14665 BlockScopeInfo *blockScope = SemaRef.getCurBlock(); 14666 14667 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); 14668 blockScope->TheDecl->setBlockMissingReturnType( 14669 oldBlock->blockMissingReturnType()); 14670 14671 SmallVector<ParmVarDecl*, 4> params; 14672 SmallVector<QualType, 4> paramTypes; 14673 14674 const FunctionProtoType *exprFunctionType = E->getFunctionType(); 14675 14676 // Parameter substitution. 14677 Sema::ExtParameterInfoBuilder extParamInfos; 14678 if (getDerived().TransformFunctionTypeParams( 14679 E->getCaretLocation(), oldBlock->parameters(), nullptr, 14680 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms, 14681 extParamInfos)) { 14682 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); 14683 return ExprError(); 14684 } 14685 14686 QualType exprResultType = 14687 getDerived().TransformType(exprFunctionType->getReturnType()); 14688 14689 auto epi = exprFunctionType->getExtProtoInfo(); 14690 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size()); 14691 14692 QualType functionType = 14693 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi); 14694 blockScope->FunctionType = functionType; 14695 14696 // Set the parameters on the block decl. 14697 if (!params.empty()) 14698 blockScope->TheDecl->setParams(params); 14699 14700 if (!oldBlock->blockMissingReturnType()) { 14701 blockScope->HasImplicitReturnType = false; 14702 blockScope->ReturnType = exprResultType; 14703 } 14704 14705 // Transform the body 14706 StmtResult body = getDerived().TransformStmt(E->getBody()); 14707 if (body.isInvalid()) { 14708 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); 14709 return ExprError(); 14710 } 14711 14712 #ifndef NDEBUG 14713 // In builds with assertions, make sure that we captured everything we 14714 // captured before. 14715 if (!SemaRef.getDiagnostics().hasErrorOccurred()) { 14716 for (const auto &I : oldBlock->captures()) { 14717 VarDecl *oldCapture = I.getVariable(); 14718 14719 // Ignore parameter packs. 14720 if (oldCapture->isParameterPack()) 14721 continue; 14722 14723 VarDecl *newCapture = 14724 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), 14725 oldCapture)); 14726 assert(blockScope->CaptureMap.count(newCapture)); 14727 } 14728 14729 // The this pointer may not be captured by the instantiated block, even when 14730 // it's captured by the original block, if the expression causing the 14731 // capture is in the discarded branch of a constexpr if statement. 14732 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) && 14733 "this pointer isn't captured in the old block"); 14734 } 14735 #endif 14736 14737 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), 14738 /*Scope=*/nullptr); 14739 } 14740 14741 template<typename Derived> 14742 ExprResult 14743 TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { 14744 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); 14745 if (SrcExpr.isInvalid()) 14746 return ExprError(); 14747 14748 QualType Type = getDerived().TransformType(E->getType()); 14749 14750 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(), 14751 E->getRParenLoc()); 14752 } 14753 14754 template<typename Derived> 14755 ExprResult 14756 TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { 14757 bool ArgumentChanged = false; 14758 SmallVector<Expr*, 8> SubExprs; 14759 SubExprs.reserve(E->getNumSubExprs()); 14760 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 14761 SubExprs, &ArgumentChanged)) 14762 return ExprError(); 14763 14764 if (!getDerived().AlwaysRebuild() && 14765 !ArgumentChanged) 14766 return E; 14767 14768 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, 14769 E->getOp(), E->getRParenLoc()); 14770 } 14771 14772 //===----------------------------------------------------------------------===// 14773 // Type reconstruction 14774 //===----------------------------------------------------------------------===// 14775 14776 template<typename Derived> 14777 QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 14778 SourceLocation Star) { 14779 return SemaRef.BuildPointerType(PointeeType, Star, 14780 getDerived().getBaseEntity()); 14781 } 14782 14783 template<typename Derived> 14784 QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 14785 SourceLocation Star) { 14786 return SemaRef.BuildBlockPointerType(PointeeType, Star, 14787 getDerived().getBaseEntity()); 14788 } 14789 14790 template<typename Derived> 14791 QualType 14792 TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 14793 bool WrittenAsLValue, 14794 SourceLocation Sigil) { 14795 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 14796 Sigil, getDerived().getBaseEntity()); 14797 } 14798 14799 template<typename Derived> 14800 QualType 14801 TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 14802 QualType ClassType, 14803 SourceLocation Sigil) { 14804 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, 14805 getDerived().getBaseEntity()); 14806 } 14807 14808 template<typename Derived> 14809 QualType TreeTransform<Derived>::RebuildObjCTypeParamType( 14810 const ObjCTypeParamDecl *Decl, 14811 SourceLocation ProtocolLAngleLoc, 14812 ArrayRef<ObjCProtocolDecl *> Protocols, 14813 ArrayRef<SourceLocation> ProtocolLocs, 14814 SourceLocation ProtocolRAngleLoc) { 14815 return SemaRef.BuildObjCTypeParamType(Decl, 14816 ProtocolLAngleLoc, Protocols, 14817 ProtocolLocs, ProtocolRAngleLoc, 14818 /*FailOnError=*/true); 14819 } 14820 14821 template<typename Derived> 14822 QualType TreeTransform<Derived>::RebuildObjCObjectType( 14823 QualType BaseType, 14824 SourceLocation Loc, 14825 SourceLocation TypeArgsLAngleLoc, 14826 ArrayRef<TypeSourceInfo *> TypeArgs, 14827 SourceLocation TypeArgsRAngleLoc, 14828 SourceLocation ProtocolLAngleLoc, 14829 ArrayRef<ObjCProtocolDecl *> Protocols, 14830 ArrayRef<SourceLocation> ProtocolLocs, 14831 SourceLocation ProtocolRAngleLoc) { 14832 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, 14833 TypeArgsRAngleLoc, ProtocolLAngleLoc, 14834 Protocols, ProtocolLocs, ProtocolRAngleLoc, 14835 /*FailOnError=*/true, 14836 /*Rebuilding=*/true); 14837 } 14838 14839 template<typename Derived> 14840 QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( 14841 QualType PointeeType, 14842 SourceLocation Star) { 14843 return SemaRef.Context.getObjCObjectPointerType(PointeeType); 14844 } 14845 14846 template<typename Derived> 14847 QualType 14848 TreeTransform<Derived>::RebuildArrayType(QualType ElementType, 14849 ArrayType::ArraySizeModifier SizeMod, 14850 const llvm::APInt *Size, 14851 Expr *SizeExpr, 14852 unsigned IndexTypeQuals, 14853 SourceRange BracketsRange) { 14854 if (SizeExpr || !Size) 14855 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 14856 IndexTypeQuals, BracketsRange, 14857 getDerived().getBaseEntity()); 14858 14859 QualType Types[] = { 14860 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 14861 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 14862 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 14863 }; 14864 QualType SizeType; 14865 for (const auto &T : Types) 14866 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) { 14867 SizeType = T; 14868 break; 14869 } 14870 14871 // Note that we can return a VariableArrayType here in the case where 14872 // the element type was a dependent VariableArrayType. 14873 IntegerLiteral *ArraySize 14874 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, 14875 /*FIXME*/BracketsRange.getBegin()); 14876 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, 14877 IndexTypeQuals, BracketsRange, 14878 getDerived().getBaseEntity()); 14879 } 14880 14881 template<typename Derived> 14882 QualType 14883 TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 14884 ArrayType::ArraySizeModifier SizeMod, 14885 const llvm::APInt &Size, 14886 Expr *SizeExpr, 14887 unsigned IndexTypeQuals, 14888 SourceRange BracketsRange) { 14889 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr, 14890 IndexTypeQuals, BracketsRange); 14891 } 14892 14893 template<typename Derived> 14894 QualType 14895 TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 14896 ArrayType::ArraySizeModifier SizeMod, 14897 unsigned IndexTypeQuals, 14898 SourceRange BracketsRange) { 14899 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, 14900 IndexTypeQuals, BracketsRange); 14901 } 14902 14903 template<typename Derived> 14904 QualType 14905 TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 14906 ArrayType::ArraySizeModifier SizeMod, 14907 Expr *SizeExpr, 14908 unsigned IndexTypeQuals, 14909 SourceRange BracketsRange) { 14910 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, 14911 SizeExpr, 14912 IndexTypeQuals, BracketsRange); 14913 } 14914 14915 template<typename Derived> 14916 QualType 14917 TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 14918 ArrayType::ArraySizeModifier SizeMod, 14919 Expr *SizeExpr, 14920 unsigned IndexTypeQuals, 14921 SourceRange BracketsRange) { 14922 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, 14923 SizeExpr, 14924 IndexTypeQuals, BracketsRange); 14925 } 14926 14927 template <typename Derived> 14928 QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType( 14929 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) { 14930 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr, 14931 AttributeLoc); 14932 } 14933 14934 template <typename Derived> 14935 QualType 14936 TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 14937 unsigned NumElements, 14938 VectorType::VectorKind VecKind) { 14939 // FIXME: semantic checking! 14940 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 14941 } 14942 14943 template <typename Derived> 14944 QualType TreeTransform<Derived>::RebuildDependentVectorType( 14945 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, 14946 VectorType::VectorKind VecKind) { 14947 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc); 14948 } 14949 14950 template<typename Derived> 14951 QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 14952 unsigned NumElements, 14953 SourceLocation AttributeLoc) { 14954 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 14955 NumElements, true); 14956 IntegerLiteral *VectorSize 14957 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 14958 AttributeLoc); 14959 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 14960 } 14961 14962 template<typename Derived> 14963 QualType 14964 TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 14965 Expr *SizeExpr, 14966 SourceLocation AttributeLoc) { 14967 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 14968 } 14969 14970 template <typename Derived> 14971 QualType TreeTransform<Derived>::RebuildConstantMatrixType( 14972 QualType ElementType, unsigned NumRows, unsigned NumColumns) { 14973 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows, 14974 NumColumns); 14975 } 14976 14977 template <typename Derived> 14978 QualType TreeTransform<Derived>::RebuildDependentSizedMatrixType( 14979 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, 14980 SourceLocation AttributeLoc) { 14981 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr, 14982 AttributeLoc); 14983 } 14984 14985 template<typename Derived> 14986 QualType TreeTransform<Derived>::RebuildFunctionProtoType( 14987 QualType T, 14988 MutableArrayRef<QualType> ParamTypes, 14989 const FunctionProtoType::ExtProtoInfo &EPI) { 14990 return SemaRef.BuildFunctionType(T, ParamTypes, 14991 getDerived().getBaseLocation(), 14992 getDerived().getBaseEntity(), 14993 EPI); 14994 } 14995 14996 template<typename Derived> 14997 QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 14998 return SemaRef.Context.getFunctionNoProtoType(T); 14999 } 15000 15001 template<typename Derived> 15002 QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc, 15003 Decl *D) { 15004 assert(D && "no decl found"); 15005 if (D->isInvalidDecl()) return QualType(); 15006 15007 // FIXME: Doesn't account for ObjCInterfaceDecl! 15008 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) { 15009 // A valid resolved using typename pack expansion decl can have multiple 15010 // UsingDecls, but they must each have exactly one type, and it must be 15011 // the same type in every case. But we must have at least one expansion! 15012 if (UPD->expansions().empty()) { 15013 getSema().Diag(Loc, diag::err_using_pack_expansion_empty) 15014 << UPD->isCXXClassMember() << UPD; 15015 return QualType(); 15016 } 15017 15018 // We might still have some unresolved types. Try to pick a resolved type 15019 // if we can. The final instantiation will check that the remaining 15020 // unresolved types instantiate to the type we pick. 15021 QualType FallbackT; 15022 QualType T; 15023 for (auto *E : UPD->expansions()) { 15024 QualType ThisT = RebuildUnresolvedUsingType(Loc, E); 15025 if (ThisT.isNull()) 15026 continue; 15027 else if (ThisT->getAs<UnresolvedUsingType>()) 15028 FallbackT = ThisT; 15029 else if (T.isNull()) 15030 T = ThisT; 15031 else 15032 assert(getSema().Context.hasSameType(ThisT, T) && 15033 "mismatched resolved types in using pack expansion"); 15034 } 15035 return T.isNull() ? FallbackT : T; 15036 } else if (auto *Using = dyn_cast<UsingDecl>(D)) { 15037 assert(Using->hasTypename() && 15038 "UnresolvedUsingTypenameDecl transformed to non-typename using"); 15039 15040 // A valid resolved using typename decl points to exactly one type decl. 15041 assert(++Using->shadow_begin() == Using->shadow_end()); 15042 15043 UsingShadowDecl *Shadow = *Using->shadow_begin(); 15044 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), Loc)) 15045 return QualType(); 15046 return SemaRef.Context.getUsingType( 15047 Shadow, SemaRef.Context.getTypeDeclType( 15048 cast<TypeDecl>(Shadow->getTargetDecl()))); 15049 } else { 15050 assert(isa<UnresolvedUsingTypenameDecl>(D) && 15051 "UnresolvedUsingTypenameDecl transformed to non-using decl"); 15052 return SemaRef.Context.getTypeDeclType( 15053 cast<UnresolvedUsingTypenameDecl>(D)); 15054 } 15055 } 15056 15057 template <typename Derived> 15058 QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, SourceLocation, 15059 TypeOfKind Kind) { 15060 return SemaRef.BuildTypeofExprType(E, Kind); 15061 } 15062 15063 template<typename Derived> 15064 QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying, 15065 TypeOfKind Kind) { 15066 return SemaRef.Context.getTypeOfType(Underlying, Kind); 15067 } 15068 15069 template <typename Derived> 15070 QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, SourceLocation) { 15071 return SemaRef.BuildDecltypeType(E); 15072 } 15073 15074 template<typename Derived> 15075 QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, 15076 UnaryTransformType::UTTKind UKind, 15077 SourceLocation Loc) { 15078 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); 15079 } 15080 15081 template<typename Derived> 15082 QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 15083 TemplateName Template, 15084 SourceLocation TemplateNameLoc, 15085 TemplateArgumentListInfo &TemplateArgs) { 15086 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 15087 } 15088 15089 template<typename Derived> 15090 QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, 15091 SourceLocation KWLoc) { 15092 return SemaRef.BuildAtomicType(ValueType, KWLoc); 15093 } 15094 15095 template<typename Derived> 15096 QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType, 15097 SourceLocation KWLoc, 15098 bool isReadPipe) { 15099 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc) 15100 : SemaRef.BuildWritePipeType(ValueType, KWLoc); 15101 } 15102 15103 template <typename Derived> 15104 QualType TreeTransform<Derived>::RebuildBitIntType(bool IsUnsigned, 15105 unsigned NumBits, 15106 SourceLocation Loc) { 15107 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 15108 NumBits, true); 15109 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP, 15110 SemaRef.Context.IntTy, Loc); 15111 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc); 15112 } 15113 15114 template <typename Derived> 15115 QualType TreeTransform<Derived>::RebuildDependentBitIntType( 15116 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) { 15117 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc); 15118 } 15119 15120 template<typename Derived> 15121 TemplateName 15122 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 15123 bool TemplateKW, 15124 TemplateDecl *Template) { 15125 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, 15126 TemplateName(Template)); 15127 } 15128 15129 template<typename Derived> 15130 TemplateName 15131 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 15132 SourceLocation TemplateKWLoc, 15133 const IdentifierInfo &Name, 15134 SourceLocation NameLoc, 15135 QualType ObjectType, 15136 NamedDecl *FirstQualifierInScope, 15137 bool AllowInjectedClassName) { 15138 UnqualifiedId TemplateName; 15139 TemplateName.setIdentifier(&Name, NameLoc); 15140 Sema::TemplateTy Template; 15141 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc, 15142 TemplateName, ParsedType::make(ObjectType), 15143 /*EnteringContext=*/false, Template, 15144 AllowInjectedClassName); 15145 return Template.get(); 15146 } 15147 15148 template<typename Derived> 15149 TemplateName 15150 TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 15151 SourceLocation TemplateKWLoc, 15152 OverloadedOperatorKind Operator, 15153 SourceLocation NameLoc, 15154 QualType ObjectType, 15155 bool AllowInjectedClassName) { 15156 UnqualifiedId Name; 15157 // FIXME: Bogus location information. 15158 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; 15159 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); 15160 Sema::TemplateTy Template; 15161 getSema().ActOnTemplateName( 15162 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType), 15163 /*EnteringContext=*/false, Template, AllowInjectedClassName); 15164 return Template.get(); 15165 } 15166 15167 template <typename Derived> 15168 ExprResult TreeTransform<Derived>::RebuildCXXOperatorCallExpr( 15169 OverloadedOperatorKind Op, SourceLocation OpLoc, SourceLocation CalleeLoc, 15170 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First, 15171 Expr *Second) { 15172 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 15173 15174 if (First->getObjectKind() == OK_ObjCProperty) { 15175 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 15176 if (BinaryOperator::isAssignmentOp(Opc)) 15177 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, 15178 First, Second); 15179 ExprResult Result = SemaRef.CheckPlaceholderExpr(First); 15180 if (Result.isInvalid()) 15181 return ExprError(); 15182 First = Result.get(); 15183 } 15184 15185 if (Second && Second->getObjectKind() == OK_ObjCProperty) { 15186 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); 15187 if (Result.isInvalid()) 15188 return ExprError(); 15189 Second = Result.get(); 15190 } 15191 15192 // Determine whether this should be a builtin operation. 15193 if (Op == OO_Subscript) { 15194 if (!First->getType()->isOverloadableType() && 15195 !Second->getType()->isOverloadableType()) 15196 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second, 15197 OpLoc); 15198 } else if (Op == OO_Arrow) { 15199 // It is possible that the type refers to a RecoveryExpr created earlier 15200 // in the tree transformation. 15201 if (First->getType()->isDependentType()) 15202 return ExprError(); 15203 // -> is never a builtin operation. 15204 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); 15205 } else if (Second == nullptr || isPostIncDec) { 15206 if (!First->getType()->isOverloadableType() || 15207 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) { 15208 // The argument is not of overloadable type, or this is an expression 15209 // of the form &Class::member, so try to create a built-in unary 15210 // operation. 15211 UnaryOperatorKind Opc 15212 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 15213 15214 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 15215 } 15216 } else { 15217 if (!First->getType()->isOverloadableType() && 15218 !Second->getType()->isOverloadableType()) { 15219 // Neither of the arguments is an overloadable type, so try to 15220 // create a built-in binary operation. 15221 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 15222 ExprResult Result 15223 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 15224 if (Result.isInvalid()) 15225 return ExprError(); 15226 15227 return Result; 15228 } 15229 } 15230 15231 // Add any functions found via argument-dependent lookup. 15232 Expr *Args[2] = { First, Second }; 15233 unsigned NumArgs = 1 + (Second != nullptr); 15234 15235 // Create the overloaded operator invocation for unary operators. 15236 if (NumArgs == 1 || isPostIncDec) { 15237 UnaryOperatorKind Opc 15238 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 15239 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First, 15240 RequiresADL); 15241 } 15242 15243 // Create the overloaded operator invocation for binary operators. 15244 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 15245 ExprResult Result = SemaRef.CreateOverloadedBinOp( 15246 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL); 15247 if (Result.isInvalid()) 15248 return ExprError(); 15249 15250 return Result; 15251 } 15252 15253 template<typename Derived> 15254 ExprResult 15255 TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 15256 SourceLocation OperatorLoc, 15257 bool isArrow, 15258 CXXScopeSpec &SS, 15259 TypeSourceInfo *ScopeType, 15260 SourceLocation CCLoc, 15261 SourceLocation TildeLoc, 15262 PseudoDestructorTypeStorage Destroyed) { 15263 QualType BaseType = Base->getType(); 15264 if (Base->isTypeDependent() || Destroyed.getIdentifier() || 15265 (!isArrow && !BaseType->getAs<RecordType>()) || 15266 (isArrow && BaseType->getAs<PointerType>() && 15267 !BaseType->castAs<PointerType>()->getPointeeType() 15268 ->template getAs<RecordType>())){ 15269 // This pseudo-destructor expression is still a pseudo-destructor. 15270 return SemaRef.BuildPseudoDestructorExpr( 15271 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, 15272 CCLoc, TildeLoc, Destroyed); 15273 } 15274 15275 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 15276 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 15277 SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 15278 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 15279 NameInfo.setNamedTypeInfo(DestroyedType); 15280 15281 // The scope type is now known to be a valid nested name specifier 15282 // component. Tack it on to the end of the nested name specifier. 15283 if (ScopeType) { 15284 if (!ScopeType->getType()->getAs<TagType>()) { 15285 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), 15286 diag::err_expected_class_or_namespace) 15287 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; 15288 return ExprError(); 15289 } 15290 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), 15291 CCLoc); 15292 } 15293 15294 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 15295 return getSema().BuildMemberReferenceExpr(Base, BaseType, 15296 OperatorLoc, isArrow, 15297 SS, TemplateKWLoc, 15298 /*FIXME: FirstQualifier*/ nullptr, 15299 NameInfo, 15300 /*TemplateArgs*/ nullptr, 15301 /*S*/nullptr); 15302 } 15303 15304 template<typename Derived> 15305 StmtResult 15306 TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { 15307 SourceLocation Loc = S->getBeginLoc(); 15308 CapturedDecl *CD = S->getCapturedDecl(); 15309 unsigned NumParams = CD->getNumParams(); 15310 unsigned ContextParamPos = CD->getContextParamPosition(); 15311 SmallVector<Sema::CapturedParamNameType, 4> Params; 15312 for (unsigned I = 0; I < NumParams; ++I) { 15313 if (I != ContextParamPos) { 15314 Params.push_back( 15315 std::make_pair( 15316 CD->getParam(I)->getName(), 15317 getDerived().TransformType(CD->getParam(I)->getType()))); 15318 } else { 15319 Params.push_back(std::make_pair(StringRef(), QualType())); 15320 } 15321 } 15322 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, 15323 S->getCapturedRegionKind(), Params); 15324 StmtResult Body; 15325 { 15326 Sema::CompoundScopeRAII CompoundScope(getSema()); 15327 Body = getDerived().TransformStmt(S->getCapturedStmt()); 15328 } 15329 15330 if (Body.isInvalid()) { 15331 getSema().ActOnCapturedRegionError(); 15332 return StmtError(); 15333 } 15334 15335 return getSema().ActOnCapturedRegionEnd(Body.get()); 15336 } 15337 15338 } // end namespace clang 15339 15340 #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H 15341