clang 20.0.0git
TreeTransform.h
Go to the documentation of this file.
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
17#include "TypeLocBuilder.h"
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
22#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
27#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
36#include "clang/Sema/Lookup.h"
42#include "clang/Sema/SemaObjC.h"
46#include "clang/Sema/SemaSYCL.h"
47#include "llvm/ADT/ArrayRef.h"
48#include "llvm/Support/ErrorHandling.h"
49#include <algorithm>
50#include <optional>
51
52using namespace llvm::omp;
53
54namespace clang {
55using namespace sema;
56
57/// A semantic tree transformation that allows one to transform one
58/// abstract syntax tree into another.
59///
60/// A new tree transformation is defined by creating a new subclass \c X of
61/// \c TreeTransform<X> and then overriding certain operations to provide
62/// behavior specific to that transformation. For example, template
63/// instantiation is implemented as a tree transformation where the
64/// transformation of TemplateTypeParmType nodes involves substituting the
65/// template arguments for their corresponding template parameters; a similar
66/// transformation is performed for non-type template parameters and
67/// template template parameters.
68///
69/// This tree-transformation template uses static polymorphism to allow
70/// subclasses to customize any of its operations. Thus, a subclass can
71/// override any of the transformation or rebuild operators by providing an
72/// operation with the same signature as the default implementation. The
73/// overriding function should not be virtual.
74///
75/// Semantic tree transformations are split into two stages, either of which
76/// can be replaced by a subclass. The "transform" step transforms an AST node
77/// or the parts of an AST node using the various transformation functions,
78/// then passes the pieces on to the "rebuild" step, which constructs a new AST
79/// node of the appropriate kind from the pieces. The default transformation
80/// routines recursively transform the operands to composite AST nodes (e.g.,
81/// the pointee type of a PointerType node) and, if any of those operand nodes
82/// were changed by the transformation, invokes the rebuild operation to create
83/// a new AST node.
84///
85/// Subclasses can customize the transformation at various levels. The
86/// most coarse-grained transformations involve replacing TransformType(),
87/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
88/// TransformTemplateName(), or TransformTemplateArgument() with entirely
89/// new implementations.
90///
91/// For more fine-grained transformations, subclasses can replace any of the
92/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
93/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
94/// replacing TransformTemplateTypeParmType() allows template instantiation
95/// to substitute template arguments for their corresponding template
96/// parameters. Additionally, subclasses can override the \c RebuildXXX
97/// functions to control how AST nodes are rebuilt when their operands change.
98/// By default, \c TreeTransform will invoke semantic analysis to rebuild
99/// AST nodes. However, certain other tree transformations (e.g, cloning) may
100/// be able to use more efficient rebuild steps.
101///
102/// There are a handful of other functions that can be overridden, allowing one
103/// to avoid traversing nodes that don't need any transformation
104/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
105/// operands have not changed (\c AlwaysRebuild()), and customize the
106/// default locations and entity names used for type-checking
107/// (\c getBaseLocation(), \c getBaseEntity()).
108template<typename Derived>
110 /// Private RAII object that helps us forget and then re-remember
111 /// the template argument corresponding to a partially-substituted parameter
112 /// pack.
113 class ForgetPartiallySubstitutedPackRAII {
114 Derived &Self;
116 // Set the pack expansion index to -1 to avoid pack substitution and
117 // indicate that parameter packs should be instantiated as themselves.
118 Sema::ArgumentPackSubstitutionIndexRAII ResetPackSubstIndex;
119
120 public:
121 ForgetPartiallySubstitutedPackRAII(Derived &Self)
122 : Self(Self), ResetPackSubstIndex(Self.getSema(), -1) {
123 Old = Self.ForgetPartiallySubstitutedPack();
124 }
125
126 ~ForgetPartiallySubstitutedPackRAII() {
127 Self.RememberPartiallySubstitutedPack(Old);
128 }
129 };
130
131protected:
133
134 /// The set of local declarations that have been transformed, for
135 /// cases where we are forced to build new declarations within the transformer
136 /// rather than in the subclass (e.g., lambda closure types).
137 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
138
139public:
140 /// Initializes a new tree transformer.
142
143 /// Retrieves a reference to the derived class.
144 Derived &getDerived() { return static_cast<Derived&>(*this); }
145
146 /// Retrieves a reference to the derived class.
147 const Derived &getDerived() const {
148 return static_cast<const Derived&>(*this);
149 }
150
151 static inline ExprResult Owned(Expr *E) { return E; }
152 static inline StmtResult Owned(Stmt *S) { return S; }
153
154 /// Retrieves a reference to the semantic analysis object used for
155 /// this tree transform.
156 Sema &getSema() const { return SemaRef; }
157
158 /// Whether the transformation should always rebuild AST nodes, even
159 /// if none of the children have changed.
160 ///
161 /// Subclasses may override this function to specify when the transformation
162 /// should rebuild all AST nodes.
163 ///
164 /// We must always rebuild all AST nodes when performing variadic template
165 /// pack expansion, in order to avoid violating the AST invariant that each
166 /// statement node appears at most once in its containing declaration.
168
169 /// Whether the transformation is forming an expression or statement that
170 /// replaces the original. In this case, we'll reuse mangling numbers from
171 /// existing lambdas.
172 bool ReplacingOriginal() { return false; }
173
174 /// Wether CXXConstructExpr can be skipped when they are implicit.
175 /// They will be reconstructed when used if needed.
176 /// This is useful when the user that cause rebuilding of the
177 /// CXXConstructExpr is outside of the expression at which the TreeTransform
178 /// started.
179 bool AllowSkippingCXXConstructExpr() { return true; }
180
181 /// Returns the location of the entity being transformed, if that
182 /// information was not available elsewhere in the AST.
183 ///
184 /// By default, returns no source-location information. Subclasses can
185 /// provide an alternative implementation that provides better location
186 /// information.
188
189 /// Returns the name of the entity being transformed, if that
190 /// information was not available elsewhere in the AST.
191 ///
192 /// By default, returns an empty name. Subclasses can provide an alternative
193 /// implementation with a more precise name.
195
196 /// Sets the "base" location and entity when that
197 /// information is known based on another transformation.
198 ///
199 /// By default, the source location and entity are ignored. Subclasses can
200 /// override this function to provide a customized implementation.
202
203 /// RAII object that temporarily sets the base location and entity
204 /// used for reporting diagnostics in types.
206 TreeTransform &Self;
207 SourceLocation OldLocation;
208 DeclarationName OldEntity;
209
210 public:
212 DeclarationName Entity) : Self(Self) {
213 OldLocation = Self.getDerived().getBaseLocation();
214 OldEntity = Self.getDerived().getBaseEntity();
215
216 if (Location.isValid())
217 Self.getDerived().setBase(Location, Entity);
218 }
219
221 Self.getDerived().setBase(OldLocation, OldEntity);
222 }
223 };
224
225 /// Determine whether the given type \p T has already been
226 /// transformed.
227 ///
228 /// Subclasses can provide an alternative implementation of this routine
229 /// to short-circuit evaluation when it is known that a given type will
230 /// not change. For example, template instantiation need not traverse
231 /// non-dependent types.
233 return T.isNull();
234 }
235
236 /// Transform a template parameter depth level.
237 ///
238 /// During a transformation that transforms template parameters, this maps
239 /// an old template parameter depth to a new depth.
240 unsigned TransformTemplateDepth(unsigned Depth) {
241 return Depth;
242 }
243
244 /// Determine whether the given call argument should be dropped, e.g.,
245 /// because it is a default argument.
246 ///
247 /// Subclasses can provide an alternative implementation of this routine to
248 /// determine which kinds of call arguments get dropped. By default,
249 /// CXXDefaultArgument nodes are dropped (prior to transformation).
251 return E->isDefaultArgument();
252 }
253
254 /// Determine whether we should expand a pack expansion with the
255 /// given set of parameter packs into separate arguments by repeatedly
256 /// transforming the pattern.
257 ///
258 /// By default, the transformer never tries to expand pack expansions.
259 /// Subclasses can override this routine to provide different behavior.
260 ///
261 /// \param EllipsisLoc The location of the ellipsis that identifies the
262 /// pack expansion.
263 ///
264 /// \param PatternRange The source range that covers the entire pattern of
265 /// the pack expansion.
266 ///
267 /// \param Unexpanded The set of unexpanded parameter packs within the
268 /// pattern.
269 ///
270 /// \param ShouldExpand Will be set to \c true if the transformer should
271 /// expand the corresponding pack expansions into separate arguments. When
272 /// set, \c NumExpansions must also be set.
273 ///
274 /// \param RetainExpansion Whether the caller should add an unexpanded
275 /// pack expansion after all of the expanded arguments. This is used
276 /// when extending explicitly-specified template argument packs per
277 /// C++0x [temp.arg.explicit]p9.
278 ///
279 /// \param NumExpansions The number of separate arguments that will be in
280 /// the expanded form of the corresponding pack expansion. This is both an
281 /// input and an output parameter, which can be set by the caller if the
282 /// number of expansions is known a priori (e.g., due to a prior substitution)
283 /// and will be set by the callee when the number of expansions is known.
284 /// The callee must set this value when \c ShouldExpand is \c true; it may
285 /// set this value in other cases.
286 ///
287 /// \returns true if an error occurred (e.g., because the parameter packs
288 /// are to be instantiated with arguments of different lengths), false
289 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
290 /// must be set.
292 SourceRange PatternRange,
294 bool &ShouldExpand, bool &RetainExpansion,
295 std::optional<unsigned> &NumExpansions) {
296 ShouldExpand = false;
297 return false;
298 }
299
300 /// "Forget" about the partially-substituted pack template argument,
301 /// when performing an instantiation that must preserve the parameter pack
302 /// use.
303 ///
304 /// This routine is meant to be overridden by the template instantiator.
306 return TemplateArgument();
307 }
308
309 /// "Remember" the partially-substituted pack template argument
310 /// after performing an instantiation that must preserve the parameter pack
311 /// use.
312 ///
313 /// This routine is meant to be overridden by the template instantiator.
315
316 /// Note to the derived class when a function parameter pack is
317 /// being expanded.
319
320 /// Transforms the given type into another type.
321 ///
322 /// By default, this routine transforms a type by creating a
323 /// TypeSourceInfo for it and delegating to the appropriate
324 /// function. This is expensive, but we don't mind, because
325 /// this method is deprecated anyway; all users should be
326 /// switched to storing TypeSourceInfos.
327 ///
328 /// \returns the transformed type.
330
331 /// Transforms the given type-with-location into a new
332 /// type-with-location.
333 ///
334 /// By default, this routine transforms a type by delegating to the
335 /// appropriate TransformXXXType to build a new type. Subclasses
336 /// may override this function (to take over all type
337 /// transformations) or some set of the TransformXXXType functions
338 /// to alter the transformation.
340
341 /// Transform the given type-with-location into a new
342 /// type, collecting location information in the given builder
343 /// as necessary.
344 ///
346
347 /// Transform a type that is permitted to produce a
348 /// DeducedTemplateSpecializationType.
349 ///
350 /// This is used in the (relatively rare) contexts where it is acceptable
351 /// for transformation to produce a class template type with deduced
352 /// template arguments.
353 /// @{
356 /// @}
357
358 /// The reason why the value of a statement is not discarded, if any.
363 };
364
365 /// Transform the given statement.
366 ///
367 /// By default, this routine transforms a statement by delegating to the
368 /// appropriate TransformXXXStmt function to transform a specific kind of
369 /// statement or the TransformExpr() function to transform an expression.
370 /// Subclasses may override this function to transform statements using some
371 /// other mechanism.
372 ///
373 /// \returns the transformed statement.
375
376 /// Transform the given statement.
377 ///
378 /// By default, this routine transforms a statement by delegating to the
379 /// appropriate TransformOMPXXXClause function to transform a specific kind
380 /// of clause. Subclasses may override this function to transform statements
381 /// using some other mechanism.
382 ///
383 /// \returns the transformed OpenMP clause.
385
386 /// Transform the given attribute.
387 ///
388 /// By default, this routine transforms a statement by delegating to the
389 /// appropriate TransformXXXAttr function to transform a specific kind
390 /// of attribute. Subclasses may override this function to transform
391 /// attributed statements/types using some other mechanism.
392 ///
393 /// \returns the transformed attribute
394 const Attr *TransformAttr(const Attr *S);
395
396 // Transform the given statement attribute.
397 //
398 // Delegates to the appropriate TransformXXXAttr function to transform a
399 // specific kind of statement attribute. Unlike the non-statement taking
400 // version of this, this implements all attributes, not just pragmas.
401 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
402 const Attr *A);
403
404 // Transform the specified attribute.
405 //
406 // Subclasses should override the transformation of attributes with a pragma
407 // spelling to transform expressions stored within the attribute.
408 //
409 // \returns the transformed attribute.
410#define ATTR(X) \
411 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
412#include "clang/Basic/AttrList.inc"
413
414 // Transform the specified attribute.
415 //
416 // Subclasses should override the transformation of attributes to do
417 // transformation and checking of statement attributes. By default, this
418 // delegates to the non-statement taking version.
419 //
420 // \returns the transformed attribute.
421#define ATTR(X) \
422 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
423 const X##Attr *A) { \
424 return getDerived().Transform##X##Attr(A); \
425 }
426#include "clang/Basic/AttrList.inc"
427
428 /// Transform the given expression.
429 ///
430 /// By default, this routine transforms an expression by delegating to the
431 /// appropriate TransformXXXExpr function to build a new expression.
432 /// Subclasses may override this function to transform expressions using some
433 /// other mechanism.
434 ///
435 /// \returns the transformed expression.
437
438 /// Transform the given initializer.
439 ///
440 /// By default, this routine transforms an initializer by stripping off the
441 /// semantic nodes added by initialization, then passing the result to
442 /// TransformExpr or TransformExprs.
443 ///
444 /// \returns the transformed initializer.
446
447 /// Transform the given list of expressions.
448 ///
449 /// This routine transforms a list of expressions by invoking
450 /// \c TransformExpr() for each subexpression. However, it also provides
451 /// support for variadic templates by expanding any pack expansions (if the
452 /// derived class permits such expansion) along the way. When pack expansions
453 /// are present, the number of outputs may not equal the number of inputs.
454 ///
455 /// \param Inputs The set of expressions to be transformed.
456 ///
457 /// \param NumInputs The number of expressions in \c Inputs.
458 ///
459 /// \param IsCall If \c true, then this transform is being performed on
460 /// function-call arguments, and any arguments that should be dropped, will
461 /// be.
462 ///
463 /// \param Outputs The transformed input expressions will be added to this
464 /// vector.
465 ///
466 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
467 /// due to transformation.
468 ///
469 /// \returns true if an error occurred, false otherwise.
470 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
472 bool *ArgChanged = nullptr);
473
474 /// Transform the given declaration, which is referenced from a type
475 /// or expression.
476 ///
477 /// By default, acts as the identity function on declarations, unless the
478 /// transformer has had to transform the declaration itself. Subclasses
479 /// may override this function to provide alternate behavior.
481 llvm::DenseMap<Decl *, Decl *>::iterator Known
482 = TransformedLocalDecls.find(D);
483 if (Known != TransformedLocalDecls.end())
484 return Known->second;
485
486 return D;
487 }
488
489 /// Transform the specified condition.
490 ///
491 /// By default, this transforms the variable and expression and rebuilds
492 /// the condition.
494 Expr *Expr,
496
497 /// Transform the attributes associated with the given declaration and
498 /// place them on the new declaration.
499 ///
500 /// By default, this operation does nothing. Subclasses may override this
501 /// behavior to transform attributes.
502 void transformAttrs(Decl *Old, Decl *New) { }
503
504 /// Note that a local declaration has been transformed by this
505 /// transformer.
506 ///
507 /// Local declarations are typically transformed via a call to
508 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
509 /// the transformer itself has to transform the declarations. This routine
510 /// can be overridden by a subclass that keeps track of such mappings.
512 assert(New.size() == 1 &&
513 "must override transformedLocalDecl if performing pack expansion");
514 TransformedLocalDecls[Old] = New.front();
515 }
516
517 /// Transform the definition of the given declaration.
518 ///
519 /// By default, invokes TransformDecl() to transform the declaration.
520 /// Subclasses may override this function to provide alternate behavior.
522 return getDerived().TransformDecl(Loc, D);
523 }
524
525 /// Transform the given declaration, which was the first part of a
526 /// nested-name-specifier in a member access expression.
527 ///
528 /// This specific declaration transformation only applies to the first
529 /// identifier in a nested-name-specifier of a member access expression, e.g.,
530 /// the \c T in \c x->T::member
531 ///
532 /// By default, invokes TransformDecl() to transform the declaration.
533 /// Subclasses may override this function to provide alternate behavior.
535 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
536 }
537
538 /// Transform the set of declarations in an OverloadExpr.
539 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
540 LookupResult &R);
541
542 /// Transform the given nested-name-specifier with source-location
543 /// information.
544 ///
545 /// By default, transforms all of the types and declarations within the
546 /// nested-name-specifier. Subclasses may override this function to provide
547 /// alternate behavior.
550 QualType ObjectType = QualType(),
551 NamedDecl *FirstQualifierInScope = nullptr);
552
553 /// Transform the given declaration name.
554 ///
555 /// By default, transforms the types of conversion function, constructor,
556 /// and destructor names and then (if needed) rebuilds the declaration name.
557 /// Identifiers and selectors are returned unmodified. Subclasses may
558 /// override this function to provide alternate behavior.
561
571
572 /// Transform the given template name.
573 ///
574 /// \param SS The nested-name-specifier that qualifies the template
575 /// name. This nested-name-specifier must already have been transformed.
576 ///
577 /// \param Name The template name to transform.
578 ///
579 /// \param NameLoc The source location of the template name.
580 ///
581 /// \param ObjectType If we're translating a template name within a member
582 /// access expression, this is the type of the object whose member template
583 /// is being referenced.
584 ///
585 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
586 /// also refers to a name within the current (lexical) scope, this is the
587 /// declaration it refers to.
588 ///
589 /// By default, transforms the template name by transforming the declarations
590 /// and nested-name-specifiers that occur within the template name.
591 /// Subclasses may override this function to provide alternate behavior.
594 SourceLocation NameLoc,
595 QualType ObjectType = QualType(),
596 NamedDecl *FirstQualifierInScope = nullptr,
597 bool AllowInjectedClassName = false);
598
599 /// Transform the given template argument.
600 ///
601 /// By default, this operation transforms the type, expression, or
602 /// declaration stored within the template argument and constructs a
603 /// new template argument from the transformed result. Subclasses may
604 /// override this function to provide alternate behavior.
605 ///
606 /// Returns true if there was an error.
608 TemplateArgumentLoc &Output,
609 bool Uneval = false);
610
611 /// Transform the given set of template arguments.
612 ///
613 /// By default, this operation transforms all of the template arguments
614 /// in the input set using \c TransformTemplateArgument(), and appends
615 /// the transformed arguments to the output list.
616 ///
617 /// Note that this overload of \c TransformTemplateArguments() is merely
618 /// a convenience function. Subclasses that wish to override this behavior
619 /// should override the iterator-based member template version.
620 ///
621 /// \param Inputs The set of template arguments to be transformed.
622 ///
623 /// \param NumInputs The number of template arguments in \p Inputs.
624 ///
625 /// \param Outputs The set of transformed template arguments output by this
626 /// routine.
627 ///
628 /// Returns true if an error occurred.
630 unsigned NumInputs,
632 bool Uneval = false) {
633 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
634 Uneval);
635 }
636
637 /// Transform the given set of template arguments.
638 ///
639 /// By default, this operation transforms all of the template arguments
640 /// in the input set using \c TransformTemplateArgument(), and appends
641 /// the transformed arguments to the output list.
642 ///
643 /// \param First An iterator to the first template argument.
644 ///
645 /// \param Last An iterator one step past the last template argument.
646 ///
647 /// \param Outputs The set of transformed template arguments output by this
648 /// routine.
649 ///
650 /// Returns true if an error occurred.
651 template<typename InputIterator>
653 InputIterator Last,
655 bool Uneval = false);
656
657 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
659 TemplateArgumentLoc &ArgLoc);
660
661 /// Fakes up a TypeSourceInfo for a type.
665 }
666
667#define ABSTRACT_TYPELOC(CLASS, PARENT)
668#define TYPELOC(CLASS, PARENT) \
669 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
670#include "clang/AST/TypeLocNodes.def"
671
674 bool SuppressObjCLifetime);
678 bool SuppressObjCLifetime);
679
680 template<typename Fn>
683 CXXRecordDecl *ThisContext,
684 Qualifiers ThisTypeQuals,
686
689 SmallVectorImpl<QualType> &Exceptions,
690 bool &Changed);
691
693
697 TemplateName Template);
698
702 TemplateName Template,
703 CXXScopeSpec &SS);
704
707 NestedNameSpecifierLoc QualifierLoc);
708
709 /// Transforms the parameters of a function type into the
710 /// given vectors.
711 ///
712 /// The result vectors should be kept in sync; null entries in the
713 /// variables vector are acceptable.
714 ///
715 /// LastParamTransformed, if non-null, will be set to the index of the last
716 /// parameter on which transfromation was started. In the event of an error,
717 /// this will contain the parameter which failed to instantiate.
718 ///
719 /// Return true on error.
722 const QualType *ParamTypes,
723 const FunctionProtoType::ExtParameterInfo *ParamInfos,
725 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
726
729 const QualType *ParamTypes,
730 const FunctionProtoType::ExtParameterInfo *ParamInfos,
733 return getDerived().TransformFunctionTypeParams(
734 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
735 }
736
737 /// Transforms the parameters of a requires expresison into the given vectors.
738 ///
739 /// The result vectors should be kept in sync; null entries in the
740 /// variables vector are acceptable.
741 ///
742 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
743 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
744 /// which are cases where transformation shouldn't continue.
746 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
752 KWLoc, Params, /*ParamTypes=*/nullptr,
753 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
754 return ExprError();
755
756 return ExprResult{};
757 }
758
759 /// Transforms a single function-type parameter. Return null
760 /// on error.
761 ///
762 /// \param indexAdjustment - A number to add to the parameter's
763 /// scope index; can be negative
765 int indexAdjustment,
766 std::optional<unsigned> NumExpansions,
767 bool ExpectParameterPack);
768
769 /// Transform the body of a lambda-expression.
771 /// Alternative implementation of TransformLambdaBody that skips transforming
772 /// the body.
774
777 return static_cast<CXXRecordDecl::LambdaDependencyKind>(
779 }
780
782
785
788 return TPL;
789 }
790
792
794 bool IsAddressOfOperand,
795 TypeSourceInfo **RecoveryTSI);
796
798 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
799 TypeSourceInfo **RecoveryTSI);
800
802 bool IsAddressOfOperand);
803
805
807
808// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
809// amount of stack usage with clang.
810#define STMT(Node, Parent) \
811 LLVM_ATTRIBUTE_NOINLINE \
812 StmtResult Transform##Node(Node *S);
813#define VALUESTMT(Node, Parent) \
814 LLVM_ATTRIBUTE_NOINLINE \
815 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
816#define EXPR(Node, Parent) \
817 LLVM_ATTRIBUTE_NOINLINE \
818 ExprResult Transform##Node(Node *E);
819#define ABSTRACT_STMT(Stmt)
820#include "clang/AST/StmtNodes.inc"
821
822#define GEN_CLANG_CLAUSE_CLASS
823#define CLAUSE_CLASS(Enum, Str, Class) \
824 LLVM_ATTRIBUTE_NOINLINE \
825 OMPClause *Transform##Class(Class *S);
826#include "llvm/Frontend/OpenMP/OMP.inc"
827
828 /// Build a new qualified type given its unqualified type and type location.
829 ///
830 /// By default, this routine adds type qualifiers only to types that can
831 /// have qualifiers, and silently suppresses those qualifiers that are not
832 /// permitted. Subclasses may override this routine to provide different
833 /// behavior.
835
836 /// Build a new pointer type given its pointee type.
837 ///
838 /// By default, performs semantic analysis when building the pointer type.
839 /// Subclasses may override this routine to provide different behavior.
841
842 /// Build a new block pointer type given its pointee type.
843 ///
844 /// By default, performs semantic analysis when building the block pointer
845 /// type. Subclasses may override this routine to provide different behavior.
847
848 /// Build a new reference type given the type it references.
849 ///
850 /// By default, performs semantic analysis when building the
851 /// reference type. Subclasses may override this routine to provide
852 /// different behavior.
853 ///
854 /// \param LValue whether the type was written with an lvalue sigil
855 /// or an rvalue sigil.
857 bool LValue,
858 SourceLocation Sigil);
859
860 /// Build a new member pointer type given the pointee type and the
861 /// class type it refers into.
862 ///
863 /// By default, performs semantic analysis when building the member pointer
864 /// type. Subclasses may override this routine to provide different behavior.
866 SourceLocation Sigil);
867
869 SourceLocation ProtocolLAngleLoc,
871 ArrayRef<SourceLocation> ProtocolLocs,
872 SourceLocation ProtocolRAngleLoc);
873
874 /// Build an Objective-C object type.
875 ///
876 /// By default, performs semantic analysis when building the object type.
877 /// Subclasses may override this routine to provide different behavior.
880 SourceLocation TypeArgsLAngleLoc,
882 SourceLocation TypeArgsRAngleLoc,
883 SourceLocation ProtocolLAngleLoc,
885 ArrayRef<SourceLocation> ProtocolLocs,
886 SourceLocation ProtocolRAngleLoc);
887
888 /// Build a new Objective-C object pointer type given the pointee type.
889 ///
890 /// By default, directly builds the pointer type, with no additional semantic
891 /// analysis.
894
895 /// Build a new array type given the element type, size
896 /// modifier, size of the array (if known), size expression, and index type
897 /// qualifiers.
898 ///
899 /// By default, performs semantic analysis when building the array type.
900 /// Subclasses may override this routine to provide different behavior.
901 /// Also by default, all of the other Rebuild*Array
903 const llvm::APInt *Size, Expr *SizeExpr,
904 unsigned IndexTypeQuals, SourceRange BracketsRange);
905
906 /// Build a new constant array type given the element type, size
907 /// modifier, (known) size of the array, and index type qualifiers.
908 ///
909 /// By default, performs semantic analysis when building the array type.
910 /// Subclasses may override this routine to provide different behavior.
912 ArraySizeModifier SizeMod,
913 const llvm::APInt &Size, Expr *SizeExpr,
914 unsigned IndexTypeQuals,
915 SourceRange BracketsRange);
916
917 /// Build a new incomplete array type given the element type, size
918 /// modifier, and index type qualifiers.
919 ///
920 /// By default, performs semantic analysis when building the array type.
921 /// Subclasses may override this routine to provide different behavior.
923 ArraySizeModifier SizeMod,
924 unsigned IndexTypeQuals,
925 SourceRange BracketsRange);
926
927 /// Build a new variable-length array type given the element type,
928 /// size modifier, size expression, and index type qualifiers.
929 ///
930 /// By default, performs semantic analysis when building the array type.
931 /// Subclasses may override this routine to provide different behavior.
933 ArraySizeModifier SizeMod, Expr *SizeExpr,
934 unsigned IndexTypeQuals,
935 SourceRange BracketsRange);
936
937 /// Build a new dependent-sized array type given the element type,
938 /// size modifier, size expression, and index type qualifiers.
939 ///
940 /// By default, performs semantic analysis when building the array type.
941 /// Subclasses may override this routine to provide different behavior.
943 ArraySizeModifier SizeMod,
944 Expr *SizeExpr,
945 unsigned IndexTypeQuals,
946 SourceRange BracketsRange);
947
948 /// Build a new 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 RebuildVectorType(QualType ElementType, unsigned NumElements,
954 VectorKind VecKind);
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.
962 SourceLocation AttributeLoc, VectorKind);
963
964 /// Build a new extended vector type given the element type and
965 /// number of elements.
966 ///
967 /// By default, performs semantic analysis when building the vector type.
968 /// Subclasses may override this routine to provide different behavior.
969 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
970 SourceLocation AttributeLoc);
971
972 /// Build a new potentially dependently-sized extended vector type
973 /// given the element type and number of elements.
974 ///
975 /// By default, performs semantic analysis when building the vector type.
976 /// Subclasses may override this routine to provide different behavior.
978 Expr *SizeExpr,
979 SourceLocation AttributeLoc);
980
981 /// Build a new matrix type given the element type and dimensions.
982 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
983 unsigned NumColumns);
984
985 /// Build a new matrix type given the type and dependently-defined
986 /// dimensions.
988 Expr *ColumnExpr,
989 SourceLocation AttributeLoc);
990
991 /// Build a new DependentAddressSpaceType or return the pointee
992 /// type variable with the correct address space (retrieved from
993 /// AddrSpaceExpr) applied to it. The former will be returned in cases
994 /// where the address space remains dependent.
995 ///
996 /// By default, performs semantic analysis when building the type with address
997 /// space applied. Subclasses may override this routine to provide different
998 /// behavior.
1000 Expr *AddrSpaceExpr,
1001 SourceLocation AttributeLoc);
1002
1003 /// Build a new function type.
1004 ///
1005 /// By default, performs semantic analysis when building the function type.
1006 /// Subclasses may override this routine to provide different behavior.
1008 MutableArrayRef<QualType> ParamTypes,
1010
1011 /// Build a new unprototyped function type.
1013
1014 /// Rebuild an unresolved typename type, given the decl that
1015 /// the UnresolvedUsingTypenameDecl was transformed to.
1017
1018 /// Build a new type found via an alias.
1020 return SemaRef.Context.getUsingType(Found, Underlying);
1021 }
1022
1023 /// Build a new typedef type.
1025 return SemaRef.Context.getTypeDeclType(Typedef);
1026 }
1027
1028 /// Build a new MacroDefined type.
1030 const IdentifierInfo *MacroII) {
1031 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1032 }
1033
1034 /// Build a new class/struct/union type.
1037 }
1038
1039 /// Build a new Enum type.
1042 }
1043
1044 /// Build a new typeof(expr) type.
1045 ///
1046 /// By default, performs semantic analysis when building the typeof type.
1047 /// Subclasses may override this routine to provide different behavior.
1049 TypeOfKind Kind);
1050
1051 /// Build a new typeof(type) type.
1052 ///
1053 /// By default, builds a new TypeOfType with the given underlying type.
1055
1056 /// Build a new unary transform type.
1060
1061 /// Build a new C++11 decltype type.
1062 ///
1063 /// By default, performs semantic analysis when building the decltype type.
1064 /// Subclasses may override this routine to provide different behavior.
1066
1069 SourceLocation EllipsisLoc,
1070 bool FullySubstituted,
1071 ArrayRef<QualType> Expansions = {});
1072
1073 /// Build a new C++11 auto type.
1074 ///
1075 /// By default, builds a new AutoType with the given deduced type.
1077 ConceptDecl *TypeConstraintConcept,
1078 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1079 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1080 // which has been deduced to a dependent type into an undeduced 'auto', so
1081 // that we'll retry deduction after the transformation.
1082 return SemaRef.Context.getAutoType(Deduced, Keyword,
1083 /*IsDependent*/ false, /*IsPack=*/false,
1084 TypeConstraintConcept,
1085 TypeConstraintArgs);
1086 }
1087
1088 /// By default, builds a new DeducedTemplateSpecializationType with the given
1089 /// deduced type.
1091 QualType Deduced) {
1093 Template, Deduced, /*IsDependent*/ false);
1094 }
1095
1096 /// Build a new template specialization type.
1097 ///
1098 /// By default, performs semantic analysis when building the template
1099 /// specialization type. Subclasses may override this routine to provide
1100 /// different behavior.
1102 SourceLocation TemplateLoc,
1104
1105 /// Build a new parenthesized type.
1106 ///
1107 /// By default, builds a new ParenType type from the inner type.
1108 /// Subclasses may override this routine to provide different behavior.
1110 return SemaRef.BuildParenType(InnerType);
1111 }
1112
1113 /// Build a new qualified name type.
1114 ///
1115 /// By default, builds a new ElaboratedType type from the keyword,
1116 /// the nested-name-specifier and the named type.
1117 /// Subclasses may override this routine to provide different behavior.
1119 ElaboratedTypeKeyword Keyword,
1120 NestedNameSpecifierLoc QualifierLoc,
1121 QualType Named) {
1122 return SemaRef.Context.getElaboratedType(Keyword,
1123 QualifierLoc.getNestedNameSpecifier(),
1124 Named);
1125 }
1126
1127 /// Build a new typename type that refers to a template-id.
1128 ///
1129 /// By default, builds a new DependentNameType type from the
1130 /// nested-name-specifier and the given type. Subclasses may override
1131 /// this routine to provide different behavior.
1133 ElaboratedTypeKeyword Keyword,
1134 NestedNameSpecifierLoc QualifierLoc,
1135 SourceLocation TemplateKWLoc,
1136 const IdentifierInfo *Name,
1137 SourceLocation NameLoc,
1139 bool AllowInjectedClassName) {
1140 // Rebuild the template name.
1141 // TODO: avoid TemplateName abstraction
1142 CXXScopeSpec SS;
1143 SS.Adopt(QualifierLoc);
1144 TemplateName InstName = getDerived().RebuildTemplateName(
1145 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1146 AllowInjectedClassName);
1147
1148 if (InstName.isNull())
1149 return QualType();
1150
1151 // If it's still dependent, make a dependent specialization.
1152 if (InstName.getAsDependentTemplateName())
1154 Keyword, QualifierLoc.getNestedNameSpecifier(), Name,
1155 Args.arguments());
1156
1157 // Otherwise, make an elaborated type wrapping a non-dependent
1158 // specialization.
1159 QualType T =
1160 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1161 if (T.isNull())
1162 return QualType();
1164 Keyword, QualifierLoc.getNestedNameSpecifier(), T);
1165 }
1166
1167 /// Build a new typename type that refers to an identifier.
1168 ///
1169 /// By default, performs semantic analysis when building the typename type
1170 /// (or elaborated type). Subclasses may override this routine to provide
1171 /// different behavior.
1173 SourceLocation KeywordLoc,
1174 NestedNameSpecifierLoc QualifierLoc,
1175 const IdentifierInfo *Id,
1176 SourceLocation IdLoc,
1177 bool DeducedTSTContext) {
1178 CXXScopeSpec SS;
1179 SS.Adopt(QualifierLoc);
1180
1181 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1182 // If the name is still dependent, just build a new dependent name type.
1183 if (!SemaRef.computeDeclContext(SS))
1184 return SemaRef.Context.getDependentNameType(Keyword,
1185 QualifierLoc.getNestedNameSpecifier(),
1186 Id);
1187 }
1188
1189 if (Keyword == ElaboratedTypeKeyword::None ||
1191 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1192 *Id, IdLoc, DeducedTSTContext);
1193 }
1194
1196
1197 // We had a dependent elaborated-type-specifier that has been transformed
1198 // into a non-dependent elaborated-type-specifier. Find the tag we're
1199 // referring to.
1201 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1202 if (!DC)
1203 return QualType();
1204
1206 return QualType();
1207
1208 TagDecl *Tag = nullptr;
1210 switch (Result.getResultKind()) {
1213 break;
1214
1216 Tag = Result.getAsSingle<TagDecl>();
1217 break;
1218
1221 llvm_unreachable("Tag lookup cannot find non-tags");
1222
1224 // Let the LookupResult structure handle ambiguities.
1225 return QualType();
1226 }
1227
1228 if (!Tag) {
1229 // Check where the name exists but isn't a tag type and use that to emit
1230 // better diagnostics.
1233 switch (Result.getResultKind()) {
1237 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1238 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1239 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1240 << SomeDecl << NTK << llvm::to_underlying(Kind);
1241 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1242 break;
1243 }
1244 default:
1245 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1246 << llvm::to_underlying(Kind) << Id << DC
1247 << QualifierLoc.getSourceRange();
1248 break;
1249 }
1250 return QualType();
1251 }
1252
1253 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1254 IdLoc, Id)) {
1255 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1256 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1257 return QualType();
1258 }
1259
1260 // Build the elaborated-type-specifier type.
1262 return SemaRef.Context.getElaboratedType(Keyword,
1263 QualifierLoc.getNestedNameSpecifier(),
1264 T);
1265 }
1266
1267 /// Build a new pack expansion type.
1268 ///
1269 /// By default, builds a new PackExpansionType type from the given pattern.
1270 /// Subclasses may override this routine to provide different behavior.
1272 SourceLocation EllipsisLoc,
1273 std::optional<unsigned> NumExpansions) {
1274 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1275 NumExpansions);
1276 }
1277
1278 /// Build a new atomic type given its value type.
1279 ///
1280 /// By default, performs semantic analysis when building the atomic type.
1281 /// Subclasses may override this routine to provide different behavior.
1283
1284 /// Build a new pipe type given its value type.
1286 bool isReadPipe);
1287
1288 /// Build a bit-precise int given its value type.
1289 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1291
1292 /// Build a dependent bit-precise int given its value type.
1293 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1295
1296 /// Build a new template name given a nested name specifier, a flag
1297 /// indicating whether the "template" keyword was provided, and the template
1298 /// that the template name refers to.
1299 ///
1300 /// By default, builds the new template name directly. Subclasses may override
1301 /// this routine to provide different behavior.
1303 bool TemplateKW,
1304 TemplateDecl *Template);
1305
1306 /// Build a new template name given a nested name specifier and the
1307 /// name that is referred to as a template.
1308 ///
1309 /// By default, performs semantic analysis to determine whether the name can
1310 /// be resolved to a specific template, then builds the appropriate kind of
1311 /// template name. Subclasses may override this routine to provide different
1312 /// behavior.
1314 SourceLocation TemplateKWLoc,
1315 const IdentifierInfo &Name,
1316 SourceLocation NameLoc, QualType ObjectType,
1317 NamedDecl *FirstQualifierInScope,
1318 bool AllowInjectedClassName);
1319
1320 /// Build a new template name given a nested name specifier and the
1321 /// overloaded operator name that is referred to as a template.
1322 ///
1323 /// By default, performs semantic analysis to determine whether the name can
1324 /// be resolved to a specific template, then builds the appropriate kind of
1325 /// template name. Subclasses may override this routine to provide different
1326 /// behavior.
1328 SourceLocation TemplateKWLoc,
1329 OverloadedOperatorKind Operator,
1330 SourceLocation NameLoc, QualType ObjectType,
1331 bool AllowInjectedClassName);
1332
1333 /// Build a new template name given a template template parameter pack
1334 /// and the
1335 ///
1336 /// By default, performs semantic analysis to determine whether the name can
1337 /// be resolved to a specific template, then builds the appropriate kind of
1338 /// template name. Subclasses may override this routine to provide different
1339 /// behavior.
1341 Decl *AssociatedDecl, unsigned Index,
1342 bool Final) {
1344 ArgPack, AssociatedDecl, Index, Final);
1345 }
1346
1347 /// Build a new compound statement.
1348 ///
1349 /// By default, performs semantic analysis to build the new statement.
1350 /// Subclasses may override this routine to provide different behavior.
1352 MultiStmtArg Statements,
1353 SourceLocation RBraceLoc,
1354 bool IsStmtExpr) {
1355 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1356 IsStmtExpr);
1357 }
1358
1359 /// Build a new case statement.
1360 ///
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
1364 Expr *LHS,
1365 SourceLocation EllipsisLoc,
1366 Expr *RHS,
1367 SourceLocation ColonLoc) {
1368 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1369 ColonLoc);
1370 }
1371
1372 /// Attach the body to a new case statement.
1373 ///
1374 /// By default, performs semantic analysis to build the new statement.
1375 /// Subclasses may override this routine to provide different behavior.
1377 getSema().ActOnCaseStmtBody(S, Body);
1378 return S;
1379 }
1380
1381 /// Build a new default statement.
1382 ///
1383 /// By default, performs semantic analysis to build the new statement.
1384 /// Subclasses may override this routine to provide different behavior.
1386 SourceLocation ColonLoc,
1387 Stmt *SubStmt) {
1388 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1389 /*CurScope=*/nullptr);
1390 }
1391
1392 /// Build a new label statement.
1393 ///
1394 /// By default, performs semantic analysis to build the new statement.
1395 /// Subclasses may override this routine to provide different behavior.
1397 SourceLocation ColonLoc, Stmt *SubStmt) {
1398 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1399 }
1400
1401 /// Build a new attributed statement.
1402 ///
1403 /// By default, performs semantic analysis to build the new statement.
1404 /// Subclasses may override this routine to provide different behavior.
1407 Stmt *SubStmt) {
1409 return StmtError();
1410 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1411 }
1412
1413 /// Build a new "if" statement.
1414 ///
1415 /// By default, performs semantic analysis to build the new statement.
1416 /// Subclasses may override this routine to provide different behavior.
1418 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1419 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1420 SourceLocation ElseLoc, Stmt *Else) {
1421 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1422 Then, ElseLoc, Else);
1423 }
1424
1425 /// Start building a new switch statement.
1426 ///
1427 /// By default, performs semantic analysis to build the new statement.
1428 /// Subclasses may override this routine to provide different behavior.
1430 SourceLocation LParenLoc, Stmt *Init,
1432 SourceLocation RParenLoc) {
1433 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1434 RParenLoc);
1435 }
1436
1437 /// Attach the body to the switch statement.
1438 ///
1439 /// By default, performs semantic analysis to build the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
1442 Stmt *Switch, Stmt *Body) {
1443 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1444 }
1445
1446 /// Build a new while statement.
1447 ///
1448 /// By default, performs semantic analysis to build the new statement.
1449 /// Subclasses may override this routine to provide different behavior.
1452 SourceLocation RParenLoc, Stmt *Body) {
1453 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1454 }
1455
1456 /// Build a new do-while statement.
1457 ///
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
1461 SourceLocation WhileLoc, SourceLocation LParenLoc,
1462 Expr *Cond, SourceLocation RParenLoc) {
1463 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1464 Cond, RParenLoc);
1465 }
1466
1467 /// Build a new for statement.
1468 ///
1469 /// By default, performs semantic analysis to build the new statement.
1470 /// Subclasses may override this routine to provide different behavior.
1473 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1474 Stmt *Body) {
1475 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1476 Inc, RParenLoc, Body);
1477 }
1478
1479 /// Build a new goto statement.
1480 ///
1481 /// By default, performs semantic analysis to build the new statement.
1482 /// Subclasses may override this routine to provide different behavior.
1484 LabelDecl *Label) {
1485 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1486 }
1487
1488 /// Build a new indirect goto statement.
1489 ///
1490 /// By default, performs semantic analysis to build the new statement.
1491 /// Subclasses may override this routine to provide different behavior.
1493 SourceLocation StarLoc,
1494 Expr *Target) {
1495 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1496 }
1497
1498 /// Build a new return statement.
1499 ///
1500 /// By default, performs semantic analysis to build the new statement.
1501 /// Subclasses may override this routine to provide different behavior.
1503 return getSema().BuildReturnStmt(ReturnLoc, Result);
1504 }
1505
1506 /// Build a new declaration statement.
1507 ///
1508 /// By default, performs semantic analysis to build the new statement.
1509 /// Subclasses may override this routine to provide different behavior.
1511 SourceLocation StartLoc, SourceLocation EndLoc) {
1513 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1514 }
1515
1516 /// Build a new inline asm statement.
1517 ///
1518 /// By default, performs semantic analysis to build the new statement.
1519 /// Subclasses may override this routine to provide different behavior.
1521 bool IsVolatile, unsigned NumOutputs,
1522 unsigned NumInputs, IdentifierInfo **Names,
1523 MultiExprArg Constraints, MultiExprArg Exprs,
1524 Expr *AsmString, MultiExprArg Clobbers,
1525 unsigned NumLabels,
1526 SourceLocation RParenLoc) {
1527 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1528 NumInputs, Names, Constraints, Exprs,
1529 AsmString, Clobbers, NumLabels, RParenLoc);
1530 }
1531
1532 /// Build a new MS style inline asm statement.
1533 ///
1534 /// By default, performs semantic analysis to build the new statement.
1535 /// Subclasses may override this routine to provide different behavior.
1537 ArrayRef<Token> AsmToks,
1538 StringRef AsmString,
1539 unsigned NumOutputs, unsigned NumInputs,
1540 ArrayRef<StringRef> Constraints,
1541 ArrayRef<StringRef> Clobbers,
1542 ArrayRef<Expr*> Exprs,
1543 SourceLocation EndLoc) {
1544 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1545 NumOutputs, NumInputs,
1546 Constraints, Clobbers, Exprs, EndLoc);
1547 }
1548
1549 /// Build a new co_return statement.
1550 ///
1551 /// By default, performs semantic analysis to build the new statement.
1552 /// Subclasses may override this routine to provide different behavior.
1554 bool IsImplicit) {
1555 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1556 }
1557
1558 /// Build a new co_await expression.
1559 ///
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
1563 UnresolvedLookupExpr *OpCoawaitLookup,
1564 bool IsImplicit) {
1565 // This function rebuilds a coawait-expr given its operator.
1566 // For an explicit coawait-expr, the rebuild involves the full set
1567 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1568 // including calling await_transform().
1569 // For an implicit coawait-expr, we need to rebuild the "operator
1570 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1571 // This mirrors how the implicit CoawaitExpr is originally created
1572 // in Sema::ActOnCoroutineBodyStart().
1573 if (IsImplicit) {
1575 CoawaitLoc, Operand, OpCoawaitLookup);
1576 if (Suspend.isInvalid())
1577 return ExprError();
1578 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1579 Suspend.get(), true);
1580 }
1581
1582 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1583 OpCoawaitLookup);
1584 }
1585
1586 /// Build a new co_await expression.
1587 ///
1588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
1591 Expr *Result,
1592 UnresolvedLookupExpr *Lookup) {
1593 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1594 }
1595
1596 /// Build a new co_yield expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
1601 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1602 }
1603
1605 return getSema().BuildCoroutineBodyStmt(Args);
1606 }
1607
1608 /// Build a new Objective-C \@try statement.
1609 ///
1610 /// By default, performs semantic analysis to build the new statement.
1611 /// Subclasses may override this routine to provide different behavior.
1613 Stmt *TryBody,
1614 MultiStmtArg CatchStmts,
1615 Stmt *Finally) {
1616 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1617 Finally);
1618 }
1619
1620 /// Rebuild an Objective-C exception declaration.
1621 ///
1622 /// By default, performs semantic analysis to build the new declaration.
1623 /// Subclasses may override this routine to provide different behavior.
1625 TypeSourceInfo *TInfo, QualType T) {
1627 TInfo, T, ExceptionDecl->getInnerLocStart(),
1628 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1629 }
1630
1631 /// Build a new Objective-C \@catch statement.
1632 ///
1633 /// By default, performs semantic analysis to build the new statement.
1634 /// Subclasses may override this routine to provide different behavior.
1636 SourceLocation RParenLoc,
1637 VarDecl *Var,
1638 Stmt *Body) {
1639 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1640 }
1641
1642 /// Build a new Objective-C \@finally statement.
1643 ///
1644 /// By default, performs semantic analysis to build the new statement.
1645 /// Subclasses may override this routine to provide different behavior.
1647 Stmt *Body) {
1648 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1649 }
1650
1651 /// Build a new Objective-C \@throw statement.
1652 ///
1653 /// By default, performs semantic analysis to build the new statement.
1654 /// Subclasses may override this routine to provide different behavior.
1656 Expr *Operand) {
1657 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1658 }
1659
1660 /// Build a new OpenMP Canonical loop.
1661 ///
1662 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1663 /// OMPCanonicalLoop.
1665 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1666 }
1667
1668 /// Build a new OpenMP executable directive.
1669 ///
1670 /// By default, performs semantic analysis to build the new statement.
1671 /// Subclasses may override this routine to provide different behavior.
1673 DeclarationNameInfo DirName,
1674 OpenMPDirectiveKind CancelRegion,
1675 ArrayRef<OMPClause *> Clauses,
1676 Stmt *AStmt, SourceLocation StartLoc,
1677 SourceLocation EndLoc) {
1678
1680 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1681 }
1682
1683 /// Build a new OpenMP informational directive.
1685 DeclarationNameInfo DirName,
1686 ArrayRef<OMPClause *> Clauses,
1687 Stmt *AStmt,
1688 SourceLocation StartLoc,
1689 SourceLocation EndLoc) {
1690
1692 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1693 }
1694
1695 /// Build a new OpenMP 'if' clause.
1696 ///
1697 /// By default, performs semantic analysis to build the new OpenMP clause.
1698 /// Subclasses may override this routine to provide different behavior.
1700 Expr *Condition, SourceLocation StartLoc,
1701 SourceLocation LParenLoc,
1702 SourceLocation NameModifierLoc,
1703 SourceLocation ColonLoc,
1704 SourceLocation EndLoc) {
1706 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1707 EndLoc);
1708 }
1709
1710 /// Build a new OpenMP 'final' clause.
1711 ///
1712 /// By default, performs semantic analysis to build the new OpenMP clause.
1713 /// Subclasses may override this routine to provide different behavior.
1715 SourceLocation LParenLoc,
1716 SourceLocation EndLoc) {
1717 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1718 LParenLoc, EndLoc);
1719 }
1720
1721 /// Build a new OpenMP 'num_threads' clause.
1722 ///
1723 /// By default, performs semantic analysis to build the new OpenMP clause.
1724 /// Subclasses may override this routine to provide different behavior.
1726 SourceLocation StartLoc,
1727 SourceLocation LParenLoc,
1728 SourceLocation EndLoc) {
1729 return getSema().OpenMP().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1730 LParenLoc, EndLoc);
1731 }
1732
1733 /// Build a new OpenMP 'safelen' clause.
1734 ///
1735 /// By default, performs semantic analysis to build the new OpenMP clause.
1736 /// Subclasses may override this routine to provide different behavior.
1738 SourceLocation LParenLoc,
1739 SourceLocation EndLoc) {
1740 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1741 EndLoc);
1742 }
1743
1744 /// Build a new OpenMP 'simdlen' clause.
1745 ///
1746 /// By default, performs semantic analysis to build the new OpenMP clause.
1747 /// Subclasses may override this routine to provide different behavior.
1749 SourceLocation LParenLoc,
1750 SourceLocation EndLoc) {
1751 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1752 EndLoc);
1753 }
1754
1756 SourceLocation StartLoc,
1757 SourceLocation LParenLoc,
1758 SourceLocation EndLoc) {
1759 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1760 EndLoc);
1761 }
1762
1763 /// Build a new OpenMP 'permutation' clause.
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation EndLoc) {
1768 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1769 LParenLoc, EndLoc);
1770 }
1771
1772 /// Build a new OpenMP 'full' clause.
1774 SourceLocation EndLoc) {
1775 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1776 }
1777
1778 /// Build a new OpenMP 'partial' clause.
1780 SourceLocation LParenLoc,
1781 SourceLocation EndLoc) {
1782 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1783 LParenLoc, EndLoc);
1784 }
1785
1786 /// Build a new OpenMP 'allocator' clause.
1787 ///
1788 /// By default, performs semantic analysis to build the new OpenMP clause.
1789 /// Subclasses may override this routine to provide different behavior.
1791 SourceLocation LParenLoc,
1792 SourceLocation EndLoc) {
1793 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1794 EndLoc);
1795 }
1796
1797 /// Build a new OpenMP 'collapse' clause.
1798 ///
1799 /// By default, performs semantic analysis to build the new OpenMP clause.
1800 /// Subclasses may override this routine to provide different behavior.
1802 SourceLocation LParenLoc,
1803 SourceLocation EndLoc) {
1804 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1805 LParenLoc, EndLoc);
1806 }
1807
1808 /// Build a new OpenMP 'default' clause.
1809 ///
1810 /// By default, performs semantic analysis to build the new OpenMP clause.
1811 /// Subclasses may override this routine to provide different behavior.
1813 SourceLocation StartLoc,
1814 SourceLocation LParenLoc,
1815 SourceLocation EndLoc) {
1817 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1818 }
1819
1820 /// Build a new OpenMP 'proc_bind' clause.
1821 ///
1822 /// By default, performs semantic analysis to build the new OpenMP clause.
1823 /// Subclasses may override this routine to provide different behavior.
1825 SourceLocation KindKwLoc,
1826 SourceLocation StartLoc,
1827 SourceLocation LParenLoc,
1828 SourceLocation EndLoc) {
1830 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1831 }
1832
1833 /// Build a new OpenMP 'schedule' clause.
1834 ///
1835 /// By default, performs semantic analysis to build the new OpenMP clause.
1836 /// Subclasses may override this routine to provide different behavior.
1839 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1840 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1841 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1843 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1844 CommaLoc, EndLoc);
1845 }
1846
1847 /// Build a new OpenMP 'ordered' clause.
1848 ///
1849 /// By default, performs semantic analysis to build the new OpenMP clause.
1850 /// Subclasses may override this routine to provide different behavior.
1852 SourceLocation EndLoc,
1853 SourceLocation LParenLoc, Expr *Num) {
1854 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1855 LParenLoc, Num);
1856 }
1857
1858 /// Build a new OpenMP 'private' clause.
1859 ///
1860 /// By default, performs semantic analysis to build the new OpenMP clause.
1861 /// Subclasses may override this routine to provide different behavior.
1863 SourceLocation StartLoc,
1864 SourceLocation LParenLoc,
1865 SourceLocation EndLoc) {
1866 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1867 LParenLoc, EndLoc);
1868 }
1869
1870 /// Build a new OpenMP 'firstprivate' clause.
1871 ///
1872 /// By default, performs semantic analysis to build the new OpenMP clause.
1873 /// Subclasses may override this routine to provide different behavior.
1875 SourceLocation StartLoc,
1876 SourceLocation LParenLoc,
1877 SourceLocation EndLoc) {
1878 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1879 LParenLoc, EndLoc);
1880 }
1881
1882 /// Build a new OpenMP 'lastprivate' clause.
1883 ///
1884 /// By default, performs semantic analysis to build the new OpenMP clause.
1885 /// Subclasses may override this routine to provide different behavior.
1888 SourceLocation LPKindLoc,
1889 SourceLocation ColonLoc,
1890 SourceLocation StartLoc,
1891 SourceLocation LParenLoc,
1892 SourceLocation EndLoc) {
1894 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1895 }
1896
1897 /// Build a new OpenMP 'shared' clause.
1898 ///
1899 /// By default, performs semantic analysis to build the new OpenMP clause.
1900 /// Subclasses may override this routine to provide different behavior.
1902 SourceLocation StartLoc,
1903 SourceLocation LParenLoc,
1904 SourceLocation EndLoc) {
1905 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1906 LParenLoc, EndLoc);
1907 }
1908
1909 /// Build a new OpenMP 'reduction' clause.
1910 ///
1911 /// By default, performs semantic analysis to build the new statement.
1912 /// Subclasses may override this routine to provide different behavior.
1915 SourceLocation StartLoc, SourceLocation LParenLoc,
1916 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1917 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1918 const DeclarationNameInfo &ReductionId,
1919 ArrayRef<Expr *> UnresolvedReductions) {
1921 VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1922 ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1923 }
1924
1925 /// Build a new OpenMP 'task_reduction' clause.
1926 ///
1927 /// By default, performs semantic analysis to build the new statement.
1928 /// Subclasses may override this routine to provide different behavior.
1930 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1931 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1932 CXXScopeSpec &ReductionIdScopeSpec,
1933 const DeclarationNameInfo &ReductionId,
1934 ArrayRef<Expr *> UnresolvedReductions) {
1936 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1937 ReductionId, UnresolvedReductions);
1938 }
1939
1940 /// Build a new OpenMP 'in_reduction' clause.
1941 ///
1942 /// By default, performs semantic analysis to build the new statement.
1943 /// Subclasses may override this routine to provide different behavior.
1944 OMPClause *
1946 SourceLocation LParenLoc, SourceLocation ColonLoc,
1947 SourceLocation EndLoc,
1948 CXXScopeSpec &ReductionIdScopeSpec,
1949 const DeclarationNameInfo &ReductionId,
1950 ArrayRef<Expr *> UnresolvedReductions) {
1952 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1953 ReductionId, UnresolvedReductions);
1954 }
1955
1956 /// Build a new OpenMP 'linear' clause.
1957 ///
1958 /// By default, performs semantic analysis to build the new OpenMP clause.
1959 /// Subclasses may override this routine to provide different behavior.
1961 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1962 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1963 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1964 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1966 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1967 StepModifierLoc, EndLoc);
1968 }
1969
1970 /// Build a new OpenMP 'aligned' clause.
1971 ///
1972 /// By default, performs semantic analysis to build the new OpenMP clause.
1973 /// Subclasses may override this routine to provide different behavior.
1975 SourceLocation StartLoc,
1976 SourceLocation LParenLoc,
1977 SourceLocation ColonLoc,
1978 SourceLocation EndLoc) {
1980 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
1981 }
1982
1983 /// Build a new OpenMP 'copyin' clause.
1984 ///
1985 /// By default, performs semantic analysis to build the new OpenMP clause.
1986 /// Subclasses may override this routine to provide different behavior.
1988 SourceLocation StartLoc,
1989 SourceLocation LParenLoc,
1990 SourceLocation EndLoc) {
1991 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
1992 LParenLoc, EndLoc);
1993 }
1994
1995 /// Build a new OpenMP 'copyprivate' clause.
1996 ///
1997 /// By default, performs semantic analysis to build the new OpenMP clause.
1998 /// Subclasses may override this routine to provide different behavior.
2000 SourceLocation StartLoc,
2001 SourceLocation LParenLoc,
2002 SourceLocation EndLoc) {
2003 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2004 LParenLoc, EndLoc);
2005 }
2006
2007 /// Build a new OpenMP 'flush' pseudo clause.
2008 ///
2009 /// By default, performs semantic analysis to build the new OpenMP clause.
2010 /// Subclasses may override this routine to provide different behavior.
2012 SourceLocation StartLoc,
2013 SourceLocation LParenLoc,
2014 SourceLocation EndLoc) {
2015 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2016 LParenLoc, EndLoc);
2017 }
2018
2019 /// Build a new OpenMP 'depobj' pseudo clause.
2020 ///
2021 /// By default, performs semantic analysis to build the new OpenMP clause.
2022 /// Subclasses may override this routine to provide different behavior.
2024 SourceLocation LParenLoc,
2025 SourceLocation EndLoc) {
2026 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2027 LParenLoc, EndLoc);
2028 }
2029
2030 /// Build a new OpenMP 'depend' pseudo clause.
2031 ///
2032 /// By default, performs semantic analysis to build the new OpenMP clause.
2033 /// Subclasses may override this routine to provide different behavior.
2035 Expr *DepModifier, ArrayRef<Expr *> VarList,
2036 SourceLocation StartLoc,
2037 SourceLocation LParenLoc,
2038 SourceLocation EndLoc) {
2040 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2041 }
2042
2043 /// Build a new OpenMP 'device' clause.
2044 ///
2045 /// By default, performs semantic analysis to build the new statement.
2046 /// Subclasses may override this routine to provide different behavior.
2048 Expr *Device, SourceLocation StartLoc,
2049 SourceLocation LParenLoc,
2050 SourceLocation ModifierLoc,
2051 SourceLocation EndLoc) {
2053 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2054 }
2055
2056 /// Build a new OpenMP 'map' clause.
2057 ///
2058 /// By default, performs semantic analysis to build the new OpenMP clause.
2059 /// Subclasses may override this routine to provide different behavior.
2061 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2062 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2063 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2064 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2065 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2066 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2068 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2069 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2070 ColonLoc, VarList, Locs,
2071 /*NoDiagnose=*/false, UnresolvedMappers);
2072 }
2073
2074 /// Build a new OpenMP 'allocate' clause.
2075 ///
2076 /// By default, performs semantic analysis to build the new OpenMP clause.
2077 /// Subclasses may override this routine to provide different behavior.
2080 ArrayRef<Expr *> VarList,
2081 SourceLocation StartLoc,
2082 SourceLocation LParenLoc,
2083 SourceLocation ColonLoc,
2084 SourceLocation EndLoc) {
2086 Allocate, ACModifier, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2087 }
2088
2089 /// Build a new OpenMP 'num_teams' clause.
2090 ///
2091 /// By default, performs semantic analysis to build the new statement.
2092 /// Subclasses may override this routine to provide different behavior.
2094 SourceLocation StartLoc,
2095 SourceLocation LParenLoc,
2096 SourceLocation EndLoc) {
2097 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc,
2098 LParenLoc, EndLoc);
2099 }
2100
2101 /// Build a new OpenMP 'thread_limit' clause.
2102 ///
2103 /// By default, performs semantic analysis to build the new statement.
2104 /// Subclasses may override this routine to provide different behavior.
2106 SourceLocation StartLoc,
2107 SourceLocation LParenLoc,
2108 SourceLocation EndLoc) {
2109 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2110 LParenLoc, EndLoc);
2111 }
2112
2113 /// Build a new OpenMP 'priority' clause.
2114 ///
2115 /// By default, performs semantic analysis to build the new statement.
2116 /// Subclasses may override this routine to provide different behavior.
2118 SourceLocation LParenLoc,
2119 SourceLocation EndLoc) {
2120 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2121 LParenLoc, EndLoc);
2122 }
2123
2124 /// Build a new OpenMP 'grainsize' clause.
2125 ///
2126 /// By default, performs semantic analysis to build the new statement.
2127 /// Subclasses may override this routine to provide different behavior.
2129 Expr *Device, SourceLocation StartLoc,
2130 SourceLocation LParenLoc,
2131 SourceLocation ModifierLoc,
2132 SourceLocation EndLoc) {
2134 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2135 }
2136
2137 /// Build a new OpenMP 'num_tasks' clause.
2138 ///
2139 /// By default, performs semantic analysis to build the new statement.
2140 /// Subclasses may override this routine to provide different behavior.
2142 Expr *NumTasks, SourceLocation StartLoc,
2143 SourceLocation LParenLoc,
2144 SourceLocation ModifierLoc,
2145 SourceLocation EndLoc) {
2147 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2148 }
2149
2150 /// Build a new OpenMP 'hint' clause.
2151 ///
2152 /// By default, performs semantic analysis to build the new statement.
2153 /// Subclasses may override this routine to provide different behavior.
2155 SourceLocation LParenLoc,
2156 SourceLocation EndLoc) {
2157 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2158 EndLoc);
2159 }
2160
2161 /// Build a new OpenMP 'detach' clause.
2162 ///
2163 /// By default, performs semantic analysis to build the new statement.
2164 /// Subclasses may override this routine to provide different behavior.
2166 SourceLocation LParenLoc,
2167 SourceLocation EndLoc) {
2168 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2169 EndLoc);
2170 }
2171
2172 /// Build a new OpenMP 'dist_schedule' 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 *
2178 Expr *ChunkSize, SourceLocation StartLoc,
2179 SourceLocation LParenLoc, SourceLocation KindLoc,
2180 SourceLocation CommaLoc, SourceLocation EndLoc) {
2182 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2183 }
2184
2185 /// Build a new OpenMP 'to' clause.
2186 ///
2187 /// By default, performs semantic analysis to build the new statement.
2188 /// Subclasses may override this routine to provide different behavior.
2189 OMPClause *
2191 ArrayRef<SourceLocation> MotionModifiersLoc,
2192 CXXScopeSpec &MapperIdScopeSpec,
2193 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2194 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2195 ArrayRef<Expr *> UnresolvedMappers) {
2197 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2198 ColonLoc, VarList, Locs, UnresolvedMappers);
2199 }
2200
2201 /// Build a new OpenMP 'from' clause.
2202 ///
2203 /// By default, performs semantic analysis to build the new statement.
2204 /// Subclasses may override this routine to provide different behavior.
2205 OMPClause *
2207 ArrayRef<SourceLocation> MotionModifiersLoc,
2208 CXXScopeSpec &MapperIdScopeSpec,
2209 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2210 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2211 ArrayRef<Expr *> UnresolvedMappers) {
2213 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2214 ColonLoc, VarList, Locs, UnresolvedMappers);
2215 }
2216
2217 /// Build a new OpenMP 'use_device_ptr' clause.
2218 ///
2219 /// By default, performs semantic analysis to build the new OpenMP clause.
2220 /// Subclasses may override this routine to provide different behavior.
2222 const OMPVarListLocTy &Locs) {
2223 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2224 }
2225
2226 /// Build a new OpenMP 'use_device_addr' clause.
2227 ///
2228 /// By default, performs semantic analysis to build the new OpenMP clause.
2229 /// Subclasses may override this routine to provide different behavior.
2231 const OMPVarListLocTy &Locs) {
2232 return getSema().OpenMP().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2233 }
2234
2235 /// Build a new OpenMP 'is_device_ptr' clause.
2236 ///
2237 /// By default, performs semantic analysis to build the new OpenMP clause.
2238 /// Subclasses may override this routine to provide different behavior.
2240 const OMPVarListLocTy &Locs) {
2241 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2242 }
2243
2244 /// Build a new OpenMP 'has_device_addr' clause.
2245 ///
2246 /// By default, performs semantic analysis to build the new OpenMP clause.
2247 /// Subclasses may override this routine to provide different behavior.
2249 const OMPVarListLocTy &Locs) {
2250 return getSema().OpenMP().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2251 }
2252
2253 /// Build a new OpenMP 'defaultmap' clause.
2254 ///
2255 /// By default, performs semantic analysis to build the new OpenMP clause.
2256 /// Subclasses may override this routine to provide different behavior.
2259 SourceLocation StartLoc,
2260 SourceLocation LParenLoc,
2261 SourceLocation MLoc,
2262 SourceLocation KindLoc,
2263 SourceLocation EndLoc) {
2265 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2266 }
2267
2268 /// Build a new OpenMP 'nontemporal' clause.
2269 ///
2270 /// By default, performs semantic analysis to build the new OpenMP clause.
2271 /// Subclasses may override this routine to provide different behavior.
2273 SourceLocation StartLoc,
2274 SourceLocation LParenLoc,
2275 SourceLocation EndLoc) {
2276 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2277 LParenLoc, EndLoc);
2278 }
2279
2280 /// Build a new OpenMP 'inclusive' clause.
2281 ///
2282 /// By default, performs semantic analysis to build the new OpenMP clause.
2283 /// Subclasses may override this routine to provide different behavior.
2285 SourceLocation StartLoc,
2286 SourceLocation LParenLoc,
2287 SourceLocation EndLoc) {
2288 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2289 LParenLoc, EndLoc);
2290 }
2291
2292 /// Build a new OpenMP 'exclusive' clause.
2293 ///
2294 /// By default, performs semantic analysis to build the new OpenMP clause.
2295 /// Subclasses may override this routine to provide different behavior.
2297 SourceLocation StartLoc,
2298 SourceLocation LParenLoc,
2299 SourceLocation EndLoc) {
2300 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2301 LParenLoc, EndLoc);
2302 }
2303
2304 /// Build a new OpenMP 'uses_allocators' clause.
2305 ///
2306 /// By default, performs semantic analysis to build the new OpenMP clause.
2307 /// Subclasses may override this routine to provide different behavior.
2310 SourceLocation LParenLoc, SourceLocation EndLoc) {
2312 StartLoc, LParenLoc, EndLoc, Data);
2313 }
2314
2315 /// Build a new OpenMP 'affinity' clause.
2316 ///
2317 /// By default, performs semantic analysis to build the new OpenMP clause.
2318 /// Subclasses may override this routine to provide different behavior.
2320 SourceLocation LParenLoc,
2321 SourceLocation ColonLoc,
2322 SourceLocation EndLoc, Expr *Modifier,
2323 ArrayRef<Expr *> Locators) {
2325 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2326 }
2327
2328 /// Build a new OpenMP 'order' clause.
2329 ///
2330 /// By default, performs semantic analysis to build the new OpenMP clause.
2331 /// Subclasses may override this routine to provide different behavior.
2333 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2334 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2335 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2337 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2338 }
2339
2340 /// Build a new OpenMP 'init' clause.
2341 ///
2342 /// By default, performs semantic analysis to build the new OpenMP clause.
2343 /// Subclasses may override this routine to provide different behavior.
2345 SourceLocation StartLoc,
2346 SourceLocation LParenLoc,
2347 SourceLocation VarLoc,
2348 SourceLocation EndLoc) {
2350 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2351 }
2352
2353 /// Build a new OpenMP 'use' clause.
2354 ///
2355 /// By default, performs semantic analysis to build the new OpenMP clause.
2356 /// Subclasses may override this routine to provide different behavior.
2358 SourceLocation LParenLoc,
2359 SourceLocation VarLoc, SourceLocation EndLoc) {
2360 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2361 LParenLoc, VarLoc, EndLoc);
2362 }
2363
2364 /// Build a new OpenMP 'destroy' clause.
2365 ///
2366 /// By default, performs semantic analysis to build the new OpenMP clause.
2367 /// Subclasses may override this routine to provide different behavior.
2369 SourceLocation LParenLoc,
2370 SourceLocation VarLoc,
2371 SourceLocation EndLoc) {
2373 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2374 }
2375
2376 /// Build a new OpenMP 'novariants' clause.
2377 ///
2378 /// By default, performs semantic analysis to build the new OpenMP clause.
2379 /// Subclasses may override this routine to provide different behavior.
2381 SourceLocation StartLoc,
2382 SourceLocation LParenLoc,
2383 SourceLocation EndLoc) {
2385 LParenLoc, EndLoc);
2386 }
2387
2388 /// Build a new OpenMP 'nocontext' clause.
2389 ///
2390 /// By default, performs semantic analysis to build the new OpenMP clause.
2391 /// Subclasses may override this routine to provide different behavior.
2393 SourceLocation LParenLoc,
2394 SourceLocation EndLoc) {
2396 LParenLoc, EndLoc);
2397 }
2398
2399 /// Build a new OpenMP 'filter' clause.
2400 ///
2401 /// By default, performs semantic analysis to build the new OpenMP clause.
2402 /// Subclasses may override this routine to provide different behavior.
2404 SourceLocation LParenLoc,
2405 SourceLocation EndLoc) {
2406 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2407 LParenLoc, EndLoc);
2408 }
2409
2410 /// Build a new OpenMP 'bind' clause.
2411 ///
2412 /// By default, performs semantic analysis to build the new OpenMP clause.
2413 /// Subclasses may override this routine to provide different behavior.
2415 SourceLocation KindLoc,
2416 SourceLocation StartLoc,
2417 SourceLocation LParenLoc,
2418 SourceLocation EndLoc) {
2419 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2420 LParenLoc, EndLoc);
2421 }
2422
2423 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2424 ///
2425 /// By default, performs semantic analysis to build the new OpenMP clause.
2426 /// Subclasses may override this routine to provide different behavior.
2428 SourceLocation LParenLoc,
2429 SourceLocation EndLoc) {
2430 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2431 LParenLoc, EndLoc);
2432 }
2433
2434 /// Build a new OpenMP 'ompx_attribute' clause.
2435 ///
2436 /// By default, performs semantic analysis to build the new OpenMP clause.
2437 /// Subclasses may override this routine to provide different behavior.
2439 SourceLocation StartLoc,
2440 SourceLocation LParenLoc,
2441 SourceLocation EndLoc) {
2442 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2443 LParenLoc, EndLoc);
2444 }
2445
2446 /// Build a new OpenMP 'ompx_bare' clause.
2447 ///
2448 /// By default, performs semantic analysis to build the new OpenMP clause.
2449 /// Subclasses may override this routine to provide different behavior.
2451 SourceLocation EndLoc) {
2452 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2453 }
2454
2455 /// Build a new OpenMP 'align' clause.
2456 ///
2457 /// By default, performs semantic analysis to build the new OpenMP clause.
2458 /// Subclasses may override this routine to provide different behavior.
2460 SourceLocation LParenLoc,
2461 SourceLocation EndLoc) {
2462 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2463 EndLoc);
2464 }
2465
2466 /// Build a new OpenMP 'at' clause.
2467 ///
2468 /// By default, performs semantic analysis to build the new OpenMP clause.
2469 /// Subclasses may override this routine to provide different behavior.
2471 SourceLocation StartLoc,
2472 SourceLocation LParenLoc,
2473 SourceLocation EndLoc) {
2474 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2475 LParenLoc, EndLoc);
2476 }
2477
2478 /// Build a new OpenMP 'severity' clause.
2479 ///
2480 /// By default, performs semantic analysis to build the new OpenMP clause.
2481 /// Subclasses may override this routine to provide different behavior.
2483 SourceLocation KwLoc,
2484 SourceLocation StartLoc,
2485 SourceLocation LParenLoc,
2486 SourceLocation EndLoc) {
2487 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2488 LParenLoc, EndLoc);
2489 }
2490
2491 /// Build a new OpenMP 'message' clause.
2492 ///
2493 /// By default, performs semantic analysis to build the new OpenMP clause.
2494 /// Subclasses may override this routine to provide different behavior.
2496 SourceLocation LParenLoc,
2497 SourceLocation EndLoc) {
2498 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2499 EndLoc);
2500 }
2501
2502 /// Build a new OpenMP 'doacross' clause.
2503 ///
2504 /// By default, performs semantic analysis to build the new OpenMP clause.
2505 /// Subclasses may override this routine to provide different behavior.
2506 OMPClause *
2508 SourceLocation DepLoc, SourceLocation ColonLoc,
2509 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2510 SourceLocation LParenLoc, SourceLocation EndLoc) {
2512 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2513 }
2514
2515 /// Build a new OpenMP 'holds' clause.
2517 SourceLocation LParenLoc,
2518 SourceLocation EndLoc) {
2519 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2520 EndLoc);
2521 }
2522
2523 /// Rebuild the operand to an Objective-C \@synchronized statement.
2524 ///
2525 /// By default, performs semantic analysis to build the new statement.
2526 /// Subclasses may override this routine to provide different behavior.
2528 Expr *object) {
2529 return getSema().ObjC().ActOnObjCAtSynchronizedOperand(atLoc, object);
2530 }
2531
2532 /// Build a new Objective-C \@synchronized statement.
2533 ///
2534 /// By default, performs semantic analysis to build the new statement.
2535 /// Subclasses may override this routine to provide different behavior.
2537 Expr *Object, Stmt *Body) {
2538 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2539 }
2540
2541 /// Build a new Objective-C \@autoreleasepool statement.
2542 ///
2543 /// By default, performs semantic analysis to build the new statement.
2544 /// Subclasses may override this routine to provide different behavior.
2546 Stmt *Body) {
2547 return getSema().ObjC().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2548 }
2549
2550 /// Build a new Objective-C fast enumeration statement.
2551 ///
2552 /// By default, performs semantic analysis to build the new statement.
2553 /// Subclasses may override this routine to provide different behavior.
2555 Stmt *Element,
2556 Expr *Collection,
2557 SourceLocation RParenLoc,
2558 Stmt *Body) {
2560 ForLoc, Element, Collection, RParenLoc);
2561 if (ForEachStmt.isInvalid())
2562 return StmtError();
2563
2564 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2565 Body);
2566 }
2567
2568 /// Build a new C++ exception declaration.
2569 ///
2570 /// By default, performs semantic analysis to build the new decaration.
2571 /// Subclasses may override this routine to provide different behavior.
2574 SourceLocation StartLoc,
2575 SourceLocation IdLoc,
2576 IdentifierInfo *Id) {
2578 StartLoc, IdLoc, Id);
2579 if (Var)
2580 getSema().CurContext->addDecl(Var);
2581 return Var;
2582 }
2583
2584 /// Build a new C++ catch statement.
2585 ///
2586 /// By default, performs semantic analysis to build the new statement.
2587 /// Subclasses may override this routine to provide different behavior.
2589 VarDecl *ExceptionDecl,
2590 Stmt *Handler) {
2591 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2592 Handler));
2593 }
2594
2595 /// Build a new C++ try statement.
2596 ///
2597 /// By default, performs semantic analysis to build the new statement.
2598 /// Subclasses may override this routine to provide different behavior.
2600 ArrayRef<Stmt *> Handlers) {
2601 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2602 }
2603
2604 /// Build a new C++0x range-based for statement.
2605 ///
2606 /// By default, performs semantic analysis to build the new statement.
2607 /// Subclasses may override this routine to provide different behavior.
2609 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2610 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2611 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2612 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2613 // If we've just learned that the range is actually an Objective-C
2614 // collection, treat this as an Objective-C fast enumeration loop.
2615 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2616 if (RangeStmt->isSingleDecl()) {
2617 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2618 if (RangeVar->isInvalidDecl())
2619 return StmtError();
2620
2621 Expr *RangeExpr = RangeVar->getInit();
2622 if (!RangeExpr->isTypeDependent() &&
2623 RangeExpr->getType()->isObjCObjectPointerType()) {
2624 // FIXME: Support init-statements in Objective-C++20 ranged for
2625 // statement.
2626 if (Init) {
2627 return SemaRef.Diag(Init->getBeginLoc(),
2628 diag::err_objc_for_range_init_stmt)
2629 << Init->getSourceRange();
2630 }
2632 ForLoc, LoopVar, RangeExpr, RParenLoc);
2633 }
2634 }
2635 }
2636 }
2637
2639 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2640 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2641 }
2642
2643 /// Build a new C++0x range-based for statement.
2644 ///
2645 /// By default, performs semantic analysis to build the new statement.
2646 /// Subclasses may override this routine to provide different behavior.
2648 bool IsIfExists,
2649 NestedNameSpecifierLoc QualifierLoc,
2650 DeclarationNameInfo NameInfo,
2651 Stmt *Nested) {
2652 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2653 QualifierLoc, NameInfo, Nested);
2654 }
2655
2656 /// Attach body to a C++0x range-based for statement.
2657 ///
2658 /// By default, performs semantic analysis to finish the new statement.
2659 /// Subclasses may override this routine to provide different behavior.
2661 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2662 }
2663
2665 Stmt *TryBlock, Stmt *Handler) {
2666 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2667 }
2668
2670 Stmt *Block) {
2671 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2672 }
2673
2675 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2676 }
2677
2679 SourceLocation LParen,
2680 SourceLocation RParen,
2681 TypeSourceInfo *TSI) {
2682 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2683 TSI);
2684 }
2685
2686 /// Build a new predefined expression.
2687 ///
2688 /// By default, performs semantic analysis to build the new expression.
2689 /// Subclasses may override this routine to provide different behavior.
2691 return getSema().BuildPredefinedExpr(Loc, IK);
2692 }
2693
2694 /// Build a new expression that references a declaration.
2695 ///
2696 /// By default, performs semantic analysis to build the new expression.
2697 /// Subclasses may override this routine to provide different behavior.
2699 LookupResult &R,
2700 bool RequiresADL) {
2701 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2702 }
2703
2704
2705 /// Build a new expression that references a declaration.
2706 ///
2707 /// By default, performs semantic analysis to build the new expression.
2708 /// Subclasses may override this routine to provide different behavior.
2710 ValueDecl *VD,
2711 const DeclarationNameInfo &NameInfo,
2713 TemplateArgumentListInfo *TemplateArgs) {
2714 CXXScopeSpec SS;
2715 SS.Adopt(QualifierLoc);
2716 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2717 TemplateArgs);
2718 }
2719
2720 /// Build a new expression in parentheses.
2721 ///
2722 /// By default, performs semantic analysis to build the new expression.
2723 /// Subclasses may override this routine to provide different behavior.
2725 SourceLocation RParen) {
2726 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2727 }
2728
2729 /// Build a new pseudo-destructor expression.
2730 ///
2731 /// By default, performs semantic analysis to build the new expression.
2732 /// Subclasses may override this routine to provide different behavior.
2734 SourceLocation OperatorLoc,
2735 bool isArrow,
2736 CXXScopeSpec &SS,
2737 TypeSourceInfo *ScopeType,
2738 SourceLocation CCLoc,
2739 SourceLocation TildeLoc,
2740 PseudoDestructorTypeStorage Destroyed);
2741
2742 /// Build a new unary operator expression.
2743 ///
2744 /// By default, performs semantic analysis to build the new expression.
2745 /// Subclasses may override this routine to provide different behavior.
2748 Expr *SubExpr) {
2749 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2750 }
2751
2752 /// Build a new builtin offsetof expression.
2753 ///
2754 /// By default, performs semantic analysis to build the new expression.
2755 /// Subclasses may override this routine to provide different behavior.
2759 SourceLocation RParenLoc) {
2760 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2761 RParenLoc);
2762 }
2763
2764 /// Build a new sizeof, alignof or vec_step expression with a
2765 /// type argument.
2766 ///
2767 /// By default, performs semantic analysis to build the new expression.
2768 /// Subclasses may override this routine to provide different behavior.
2770 SourceLocation OpLoc,
2771 UnaryExprOrTypeTrait ExprKind,
2772 SourceRange R) {
2773 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2774 }
2775
2776 /// Build a new sizeof, alignof or vec step expression with an
2777 /// expression argument.
2778 ///
2779 /// By default, performs semantic analysis to build the new expression.
2780 /// Subclasses may override this routine to provide different behavior.
2782 UnaryExprOrTypeTrait ExprKind,
2783 SourceRange R) {
2785 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2786 if (Result.isInvalid())
2787 return ExprError();
2788
2789 return Result;
2790 }
2791
2792 /// Build a new array subscript expression.
2793 ///
2794 /// By default, performs semantic analysis to build the new expression.
2795 /// Subclasses may override this routine to provide different behavior.
2797 SourceLocation LBracketLoc,
2798 Expr *RHS,
2799 SourceLocation RBracketLoc) {
2800 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2801 LBracketLoc, RHS,
2802 RBracketLoc);
2803 }
2804
2805 /// Build a new matrix subscript expression.
2806 ///
2807 /// By default, performs semantic analysis to build the new expression.
2808 /// Subclasses may override this routine to provide different behavior.
2810 Expr *ColumnIdx,
2811 SourceLocation RBracketLoc) {
2812 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2813 RBracketLoc);
2814 }
2815
2816 /// Build a new array section expression.
2817 ///
2818 /// By default, performs semantic analysis to build the new expression.
2819 /// Subclasses may override this routine to provide different behavior.
2821 SourceLocation LBracketLoc,
2822 Expr *LowerBound,
2823 SourceLocation ColonLocFirst,
2824 SourceLocation ColonLocSecond,
2825 Expr *Length, Expr *Stride,
2826 SourceLocation RBracketLoc) {
2827 if (IsOMPArraySection)
2829 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2830 Stride, RBracketLoc);
2831
2832 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2833 "Stride/second colon not allowed for OpenACC");
2834
2836 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2837 }
2838
2839 /// Build a new array shaping expression.
2840 ///
2841 /// By default, performs semantic analysis to build the new expression.
2842 /// Subclasses may override this routine to provide different behavior.
2844 SourceLocation RParenLoc,
2845 ArrayRef<Expr *> Dims,
2846 ArrayRef<SourceRange> BracketsRanges) {
2848 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2849 }
2850
2851 /// Build a new iterator expression.
2852 ///
2853 /// By default, performs semantic analysis to build the new expression.
2854 /// Subclasses may override this routine to provide different behavior.
2857 SourceLocation RLoc,
2860 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2861 }
2862
2863 /// Build a new call expression.
2864 ///
2865 /// By default, performs semantic analysis to build the new expression.
2866 /// Subclasses may override this routine to provide different behavior.
2868 MultiExprArg Args,
2869 SourceLocation RParenLoc,
2870 Expr *ExecConfig = nullptr) {
2871 return getSema().ActOnCallExpr(
2872 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2873 }
2874
2876 MultiExprArg Args,
2877 SourceLocation RParenLoc) {
2879 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2880 }
2881
2882 /// Build a new member access expression.
2883 ///
2884 /// By default, performs semantic analysis to build the new expression.
2885 /// Subclasses may override this routine to provide different behavior.
2887 bool isArrow,
2888 NestedNameSpecifierLoc QualifierLoc,
2889 SourceLocation TemplateKWLoc,
2890 const DeclarationNameInfo &MemberNameInfo,
2892 NamedDecl *FoundDecl,
2893 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2894 NamedDecl *FirstQualifierInScope) {
2896 isArrow);
2897 if (!Member->getDeclName()) {
2898 // We have a reference to an unnamed field. This is always the
2899 // base of an anonymous struct/union member access, i.e. the
2900 // field is always of record type.
2901 assert(Member->getType()->isRecordType() &&
2902 "unnamed member not of record type?");
2903
2904 BaseResult =
2906 QualifierLoc.getNestedNameSpecifier(),
2907 FoundDecl, Member);
2908 if (BaseResult.isInvalid())
2909 return ExprError();
2910 Base = BaseResult.get();
2911
2912 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2913 // from the AST, so we need to re-insert them if needed (since
2914 // `BuildFieldRefereneExpr()` doesn't do this).
2915 if (!isArrow && Base->isPRValue()) {
2917 if (BaseResult.isInvalid())
2918 return ExprError();
2919 Base = BaseResult.get();
2920 }
2921
2922 CXXScopeSpec EmptySS;
2924 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2925 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2926 MemberNameInfo);
2927 }
2928
2929 CXXScopeSpec SS;
2930 SS.Adopt(QualifierLoc);
2931
2932 Base = BaseResult.get();
2933 if (Base->containsErrors())
2934 return ExprError();
2935
2936 QualType BaseType = Base->getType();
2937
2938 if (isArrow && !BaseType->isPointerType())
2939 return ExprError();
2940
2941 // FIXME: this involves duplicating earlier analysis in a lot of
2942 // cases; we should avoid this when possible.
2943 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2944 R.addDecl(FoundDecl);
2945 R.resolveKind();
2946
2947 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2948 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2949 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2950 ->getType()
2951 ->getPointeeType()
2952 ->getAsCXXRecordDecl()) {
2953 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2954 // In unevaluated contexts, an expression supposed to be a member access
2955 // might reference a member in an unrelated class.
2956 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2957 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2958 VK_LValue, Member->getLocation());
2959 }
2960 }
2961
2962 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2963 SS, TemplateKWLoc,
2964 FirstQualifierInScope,
2965 R, ExplicitTemplateArgs,
2966 /*S*/nullptr);
2967 }
2968
2969 /// Build a new binary operator expression.
2970 ///
2971 /// By default, performs semantic analysis to build the new expression.
2972 /// Subclasses may override this routine to provide different behavior.
2975 Expr *LHS, Expr *RHS) {
2976 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2977 }
2978
2979 /// Build a new rewritten operator expression.
2980 ///
2981 /// By default, performs semantic analysis to build the new expression.
2982 /// Subclasses may override this routine to provide different behavior.
2984 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2985 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2986 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2987 RHS, /*RequiresADL*/false);
2988 }
2989
2990 /// Build a new conditional operator expression.
2991 ///
2992 /// By default, performs semantic analysis to build the new expression.
2993 /// Subclasses may override this routine to provide different behavior.
2995 SourceLocation QuestionLoc,
2996 Expr *LHS,
2997 SourceLocation ColonLoc,
2998 Expr *RHS) {
2999 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3000 LHS, RHS);
3001 }
3002
3003 /// Build a new C-style cast expression.
3004 ///
3005 /// By default, performs semantic analysis to build the new expression.
3006 /// Subclasses may override this routine to provide different behavior.
3008 TypeSourceInfo *TInfo,
3009 SourceLocation RParenLoc,
3010 Expr *SubExpr) {
3011 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3012 SubExpr);
3013 }
3014
3015 /// Build a new compound literal expression.
3016 ///
3017 /// By default, performs semantic analysis to build the new expression.
3018 /// Subclasses may override this routine to provide different behavior.
3020 TypeSourceInfo *TInfo,
3021 SourceLocation RParenLoc,
3022 Expr *Init) {
3023 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3024 Init);
3025 }
3026
3027 /// Build a new extended vector element access expression.
3028 ///
3029 /// By default, performs semantic analysis to build the new expression.
3030 /// Subclasses may override this routine to provide different behavior.
3032 bool IsArrow,
3033 SourceLocation AccessorLoc,
3034 IdentifierInfo &Accessor) {
3035
3036 CXXScopeSpec SS;
3037 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3039 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3040 /*FirstQualifierInScope*/ nullptr, NameInfo,
3041 /* TemplateArgs */ nullptr,
3042 /*S*/ nullptr);
3043 }
3044
3045 /// Build a new initializer list expression.
3046 ///
3047 /// By default, performs semantic analysis to build the new expression.
3048 /// Subclasses may override this routine to provide different behavior.
3050 MultiExprArg Inits,
3051 SourceLocation RBraceLoc) {
3052 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3053 }
3054
3055 /// Build a new designated initializer expression.
3056 ///
3057 /// By default, performs semantic analysis to build the new expression.
3058 /// Subclasses may override this routine to provide different behavior.
3060 MultiExprArg ArrayExprs,
3061 SourceLocation EqualOrColonLoc,
3062 bool GNUSyntax,
3063 Expr *Init) {
3065 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3066 Init);
3067 if (Result.isInvalid())
3068 return ExprError();
3069
3070 return Result;
3071 }
3072
3073 /// Build a new value-initialized expression.
3074 ///
3075 /// By default, builds the implicit value initialization without performing
3076 /// any semantic analysis. Subclasses may override this routine to provide
3077 /// different behavior.
3079 return new (SemaRef.Context) ImplicitValueInitExpr(T);
3080 }
3081
3082 /// Build a new \c va_arg expression.
3083 ///
3084 /// By default, performs semantic analysis to build the new expression.
3085 /// Subclasses may override this routine to provide different behavior.
3087 Expr *SubExpr, TypeSourceInfo *TInfo,
3088 SourceLocation RParenLoc) {
3089 return getSema().BuildVAArgExpr(BuiltinLoc,
3090 SubExpr, TInfo,
3091 RParenLoc);
3092 }
3093
3094 /// Build a new expression list in parentheses.
3095 ///
3096 /// By default, performs semantic analysis to build the new expression.
3097 /// Subclasses may override this routine to provide different behavior.
3099 MultiExprArg SubExprs,
3100 SourceLocation RParenLoc) {
3101 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3102 }
3103
3104 /// Build a new address-of-label expression.
3105 ///
3106 /// By default, performs semantic analysis, using the name of the label
3107 /// rather than attempting to map the label statement itself.
3108 /// Subclasses may override this routine to provide different behavior.
3110 SourceLocation LabelLoc, LabelDecl *Label) {
3111 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3112 }
3113
3114 /// Build a new GNU statement expression.
3115 ///
3116 /// By default, performs semantic analysis to build the new expression.
3117 /// Subclasses may override this routine to provide different behavior.
3119 SourceLocation RParenLoc, unsigned TemplateDepth) {
3120 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3121 TemplateDepth);
3122 }
3123
3124 /// Build a new __builtin_choose_expr expression.
3125 ///
3126 /// By default, performs semantic analysis to build the new expression.
3127 /// Subclasses may override this routine to provide different behavior.
3129 Expr *Cond, Expr *LHS, Expr *RHS,
3130 SourceLocation RParenLoc) {
3131 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3132 Cond, LHS, RHS,
3133 RParenLoc);
3134 }
3135
3136 /// Build a new generic selection expression with an expression predicate.
3137 ///
3138 /// By default, performs semantic analysis to build the new expression.
3139 /// Subclasses may override this routine to provide different behavior.
3141 SourceLocation DefaultLoc,
3142 SourceLocation RParenLoc,
3143 Expr *ControllingExpr,
3145 ArrayRef<Expr *> Exprs) {
3146 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3147 /*PredicateIsExpr=*/true,
3148 ControllingExpr, Types, Exprs);
3149 }
3150
3151 /// Build a new generic selection expression with a type predicate.
3152 ///
3153 /// By default, performs semantic analysis to build the new expression.
3154 /// Subclasses may override this routine to provide different behavior.
3156 SourceLocation DefaultLoc,
3157 SourceLocation RParenLoc,
3158 TypeSourceInfo *ControllingType,
3160 ArrayRef<Expr *> Exprs) {
3161 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3162 /*PredicateIsExpr=*/false,
3163 ControllingType, Types, Exprs);
3164 }
3165
3166 /// Build a new overloaded operator call expression.
3167 ///
3168 /// By default, performs semantic analysis to build the new expression.
3169 /// The semantic analysis provides the behavior of template instantiation,
3170 /// copying with transformations that turn what looks like an overloaded
3171 /// operator call into a use of a builtin operator, performing
3172 /// argument-dependent lookup, etc. Subclasses may override this routine to
3173 /// provide different behavior.
3175 SourceLocation OpLoc,
3176 SourceLocation CalleeLoc,
3177 bool RequiresADL,
3178 const UnresolvedSetImpl &Functions,
3179 Expr *First, Expr *Second);
3180
3181 /// Build a new C++ "named" cast expression, such as static_cast or
3182 /// reinterpret_cast.
3183 ///
3184 /// By default, this routine dispatches to one of the more-specific routines
3185 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3186 /// Subclasses may override this routine to provide different behavior.
3189 SourceLocation LAngleLoc,
3190 TypeSourceInfo *TInfo,
3191 SourceLocation RAngleLoc,
3192 SourceLocation LParenLoc,
3193 Expr *SubExpr,
3194 SourceLocation RParenLoc) {
3195 switch (Class) {
3196 case Stmt::CXXStaticCastExprClass:
3197 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3198 RAngleLoc, LParenLoc,
3199 SubExpr, RParenLoc);
3200
3201 case Stmt::CXXDynamicCastExprClass:
3202 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3203 RAngleLoc, LParenLoc,
3204 SubExpr, RParenLoc);
3205
3206 case Stmt::CXXReinterpretCastExprClass:
3207 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3208 RAngleLoc, LParenLoc,
3209 SubExpr,
3210 RParenLoc);
3211
3212 case Stmt::CXXConstCastExprClass:
3213 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3214 RAngleLoc, LParenLoc,
3215 SubExpr, RParenLoc);
3216
3217 case Stmt::CXXAddrspaceCastExprClass:
3218 return getDerived().RebuildCXXAddrspaceCastExpr(
3219 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3220
3221 default:
3222 llvm_unreachable("Invalid C++ named cast");
3223 }
3224 }
3225
3226 /// Build a new C++ static_cast expression.
3227 ///
3228 /// By default, performs semantic analysis to build the new expression.
3229 /// Subclasses may override this routine to provide different behavior.
3231 SourceLocation LAngleLoc,
3232 TypeSourceInfo *TInfo,
3233 SourceLocation RAngleLoc,
3234 SourceLocation LParenLoc,
3235 Expr *SubExpr,
3236 SourceLocation RParenLoc) {
3237 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3238 TInfo, SubExpr,
3239 SourceRange(LAngleLoc, RAngleLoc),
3240 SourceRange(LParenLoc, RParenLoc));
3241 }
3242
3243 /// Build a new C++ dynamic_cast expression.
3244 ///
3245 /// By default, performs semantic analysis to build the new expression.
3246 /// Subclasses may override this routine to provide different behavior.
3248 SourceLocation LAngleLoc,
3249 TypeSourceInfo *TInfo,
3250 SourceLocation RAngleLoc,
3251 SourceLocation LParenLoc,
3252 Expr *SubExpr,
3253 SourceLocation RParenLoc) {
3254 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3255 TInfo, SubExpr,
3256 SourceRange(LAngleLoc, RAngleLoc),
3257 SourceRange(LParenLoc, RParenLoc));
3258 }
3259
3260 /// Build a new C++ reinterpret_cast expression.
3261 ///
3262 /// By default, performs semantic analysis to build the new expression.
3263 /// Subclasses may override this routine to provide different behavior.
3265 SourceLocation LAngleLoc,
3266 TypeSourceInfo *TInfo,
3267 SourceLocation RAngleLoc,
3268 SourceLocation LParenLoc,
3269 Expr *SubExpr,
3270 SourceLocation RParenLoc) {
3271 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3272 TInfo, SubExpr,
3273 SourceRange(LAngleLoc, RAngleLoc),
3274 SourceRange(LParenLoc, RParenLoc));
3275 }
3276
3277 /// Build a new C++ const_cast expression.
3278 ///
3279 /// By default, performs semantic analysis to build the new expression.
3280 /// Subclasses may override this routine to provide different behavior.
3282 SourceLocation LAngleLoc,
3283 TypeSourceInfo *TInfo,
3284 SourceLocation RAngleLoc,
3285 SourceLocation LParenLoc,
3286 Expr *SubExpr,
3287 SourceLocation RParenLoc) {
3288 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3289 TInfo, SubExpr,
3290 SourceRange(LAngleLoc, RAngleLoc),
3291 SourceRange(LParenLoc, RParenLoc));
3292 }
3293
3296 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3297 SourceLocation LParenLoc, Expr *SubExpr,
3298 SourceLocation RParenLoc) {
3299 return getSema().BuildCXXNamedCast(
3300 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3301 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3302 }
3303
3304 /// Build a new C++ functional-style cast expression.
3305 ///
3306 /// By default, performs semantic analysis to build the new expression.
3307 /// Subclasses may override this routine to provide different behavior.
3309 SourceLocation LParenLoc,
3310 Expr *Sub,
3311 SourceLocation RParenLoc,
3312 bool ListInitialization) {
3313 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3314 // CXXParenListInitExpr. Pass its expanded arguments so that the
3315 // CXXParenListInitExpr can be rebuilt.
3316 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3318 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3319 RParenLoc, ListInitialization);
3320 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3321 MultiExprArg(&Sub, 1), RParenLoc,
3322 ListInitialization);
3323 }
3324
3325 /// Build a new C++ __builtin_bit_cast expression.
3326 ///
3327 /// By default, performs semantic analysis to build the new expression.
3328 /// Subclasses may override this routine to provide different behavior.
3330 TypeSourceInfo *TSI, Expr *Sub,
3331 SourceLocation RParenLoc) {
3332 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3333 }
3334
3335 /// Build a new C++ typeid(type) expression.
3336 ///
3337 /// By default, performs semantic analysis to build the new expression.
3338 /// Subclasses may override this routine to provide different behavior.
3340 SourceLocation TypeidLoc,
3341 TypeSourceInfo *Operand,
3342 SourceLocation RParenLoc) {
3343 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3344 RParenLoc);
3345 }
3346
3347
3348 /// Build a new C++ typeid(expr) expression.
3349 ///
3350 /// By default, performs semantic analysis to build the new expression.
3351 /// Subclasses may override this routine to provide different behavior.
3353 SourceLocation TypeidLoc,
3354 Expr *Operand,
3355 SourceLocation RParenLoc) {
3356 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3357 RParenLoc);
3358 }
3359
3360 /// Build a new C++ __uuidof(type) expression.
3361 ///
3362 /// By default, performs semantic analysis to build the new expression.
3363 /// Subclasses may override this routine to provide different behavior.
3365 TypeSourceInfo *Operand,
3366 SourceLocation RParenLoc) {
3367 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3368 }
3369
3370 /// Build a new C++ __uuidof(expr) expression.
3371 ///
3372 /// By default, performs semantic analysis to build the new expression.
3373 /// Subclasses may override this routine to provide different behavior.
3375 Expr *Operand, SourceLocation RParenLoc) {
3376 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3377 }
3378
3379 /// Build a new C++ "this" expression.
3380 ///
3381 /// By default, performs semantic analysis to build a new "this" expression.
3382 /// Subclasses may override this routine to provide different behavior.
3384 QualType ThisType,
3385 bool isImplicit) {
3386 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3387 return ExprError();
3388 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3389 }
3390
3391 /// Build a new C++ throw expression.
3392 ///
3393 /// By default, performs semantic analysis to build the new expression.
3394 /// Subclasses may override this routine to provide different behavior.
3396 bool IsThrownVariableInScope) {
3397 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3398 }
3399
3400 /// Build a new C++ default-argument expression.
3401 ///
3402 /// By default, builds a new default-argument expression, which does not
3403 /// require any semantic analysis. Subclasses may override this routine to
3404 /// provide different behavior.
3406 Expr *RewrittenExpr) {
3407 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3408 RewrittenExpr, getSema().CurContext);
3409 }
3410
3411 /// Build a new C++11 default-initialization expression.
3412 ///
3413 /// By default, builds a new default field initialization expression, which
3414 /// does not require any semantic analysis. Subclasses may override this
3415 /// routine to provide different behavior.
3417 FieldDecl *Field) {
3418 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3419 }
3420
3421 /// Build a new C++ zero-initialization expression.
3422 ///
3423 /// By default, performs semantic analysis to build the new expression.
3424 /// Subclasses may override this routine to provide different behavior.
3426 SourceLocation LParenLoc,
3427 SourceLocation RParenLoc) {
3428 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3429 /*ListInitialization=*/false);
3430 }
3431
3432 /// Build a new C++ "new" expression.
3433 ///
3434 /// By default, performs semantic analysis to build the new expression.
3435 /// Subclasses may override this routine to provide different behavior.
3437 SourceLocation PlacementLParen,
3438 MultiExprArg PlacementArgs,
3439 SourceLocation PlacementRParen,
3440 SourceRange TypeIdParens, QualType AllocatedType,
3441 TypeSourceInfo *AllocatedTypeInfo,
3442 std::optional<Expr *> ArraySize,
3443 SourceRange DirectInitRange, Expr *Initializer) {
3444 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3445 PlacementLParen,
3446 PlacementArgs,
3447 PlacementRParen,
3448 TypeIdParens,
3449 AllocatedType,
3450 AllocatedTypeInfo,
3451 ArraySize,
3452 DirectInitRange,
3453 Initializer);
3454 }
3455
3456 /// Build a new C++ "delete" expression.
3457 ///
3458 /// By default, performs semantic analysis to build the new expression.
3459 /// Subclasses may override this routine to provide different behavior.
3461 bool IsGlobalDelete,
3462 bool IsArrayForm,
3463 Expr *Operand) {
3464 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3465 Operand);
3466 }
3467
3468 /// Build a new type trait expression.
3469 ///
3470 /// By default, performs semantic analysis to build the new expression.
3471 /// Subclasses may override this routine to provide different behavior.
3473 SourceLocation StartLoc,
3475 SourceLocation RParenLoc) {
3476 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3477 }
3478
3479 /// Build a new array type trait expression.
3480 ///
3481 /// By default, performs semantic analysis to build the new expression.
3482 /// Subclasses may override this routine to provide different behavior.
3484 SourceLocation StartLoc,
3485 TypeSourceInfo *TSInfo,
3486 Expr *DimExpr,
3487 SourceLocation RParenLoc) {
3488 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3489 }
3490
3491 /// Build a new expression trait expression.
3492 ///
3493 /// By default, performs semantic analysis to build the new expression.
3494 /// Subclasses may override this routine to provide different behavior.
3496 SourceLocation StartLoc,
3497 Expr *Queried,
3498 SourceLocation RParenLoc) {
3499 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3500 }
3501
3502 /// Build a new (previously unresolved) declaration reference
3503 /// expression.
3504 ///
3505 /// By default, performs semantic analysis to build the new expression.
3506 /// Subclasses may override this routine to provide different behavior.
3508 NestedNameSpecifierLoc QualifierLoc,
3509 SourceLocation TemplateKWLoc,
3510 const DeclarationNameInfo &NameInfo,
3511 const TemplateArgumentListInfo *TemplateArgs,
3512 bool IsAddressOfOperand,
3513 TypeSourceInfo **RecoveryTSI) {
3514 CXXScopeSpec SS;
3515 SS.Adopt(QualifierLoc);
3516
3517 if (TemplateArgs || TemplateKWLoc.isValid())
3519 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3520
3522 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3523 }
3524
3525 /// Build a new template-id expression.
3526 ///
3527 /// By default, performs semantic analysis to build the new expression.
3528 /// Subclasses may override this routine to provide different behavior.
3530 SourceLocation TemplateKWLoc,
3531 LookupResult &R,
3532 bool RequiresADL,
3533 const TemplateArgumentListInfo *TemplateArgs) {
3534 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3535 TemplateArgs);
3536 }
3537
3538 /// Build a new object-construction expression.
3539 ///
3540 /// By default, performs semantic analysis to build the new expression.
3541 /// Subclasses may override this routine to provide different behavior.
3544 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3545 bool ListInitialization, bool StdInitListInitialization,
3546 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3547 SourceRange ParenRange) {
3548 // Reconstruct the constructor we originally found, which might be
3549 // different if this is a call to an inherited constructor.
3550 CXXConstructorDecl *FoundCtor = Constructor;
3551 if (Constructor->isInheritingConstructor())
3552 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3553
3554 SmallVector<Expr *, 8> ConvertedArgs;
3555 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3556 ConvertedArgs))
3557 return ExprError();
3558
3559 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3560 IsElidable,
3561 ConvertedArgs,
3562 HadMultipleCandidates,
3563 ListInitialization,
3564 StdInitListInitialization,
3565 RequiresZeroInit, ConstructKind,
3566 ParenRange);
3567 }
3568
3569 /// Build a new implicit construction via inherited constructor
3570 /// expression.
3572 CXXConstructorDecl *Constructor,
3573 bool ConstructsVBase,
3574 bool InheritedFromVBase) {
3576 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3577 }
3578
3579 /// Build a new object-construction expression.
3580 ///
3581 /// By default, performs semantic analysis to build the new expression.
3582 /// Subclasses may override this routine to provide different behavior.
3584 SourceLocation LParenOrBraceLoc,
3585 MultiExprArg Args,
3586 SourceLocation RParenOrBraceLoc,
3587 bool ListInitialization) {
3589 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3590 }
3591
3592 /// Build a new object-construction expression.
3593 ///
3594 /// By default, performs semantic analysis to build the new expression.
3595 /// Subclasses may override this routine to provide different behavior.
3597 SourceLocation LParenLoc,
3598 MultiExprArg Args,
3599 SourceLocation RParenLoc,
3600 bool ListInitialization) {
3601 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3602 RParenLoc, ListInitialization);
3603 }
3604
3605 /// Build a new member reference expression.
3606 ///
3607 /// By default, performs semantic analysis to build the new expression.
3608 /// Subclasses may override this routine to provide different behavior.
3610 QualType BaseType,
3611 bool IsArrow,
3612 SourceLocation OperatorLoc,
3613 NestedNameSpecifierLoc QualifierLoc,
3614 SourceLocation TemplateKWLoc,
3615 NamedDecl *FirstQualifierInScope,
3616 const DeclarationNameInfo &MemberNameInfo,
3617 const TemplateArgumentListInfo *TemplateArgs) {
3618 CXXScopeSpec SS;
3619 SS.Adopt(QualifierLoc);
3620
3621 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3622 OperatorLoc, IsArrow,
3623 SS, TemplateKWLoc,
3624 FirstQualifierInScope,
3625 MemberNameInfo,
3626 TemplateArgs, /*S*/nullptr);
3627 }
3628
3629 /// Build a new member reference expression.
3630 ///
3631 /// By default, performs semantic analysis to build the new expression.
3632 /// Subclasses may override this routine to provide different behavior.
3634 SourceLocation OperatorLoc,
3635 bool IsArrow,
3636 NestedNameSpecifierLoc QualifierLoc,
3637 SourceLocation TemplateKWLoc,
3638 NamedDecl *FirstQualifierInScope,
3639 LookupResult &R,
3640 const TemplateArgumentListInfo *TemplateArgs) {
3641 CXXScopeSpec SS;
3642 SS.Adopt(QualifierLoc);
3643
3644 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3645 OperatorLoc, IsArrow,
3646 SS, TemplateKWLoc,
3647 FirstQualifierInScope,
3648 R, TemplateArgs, /*S*/nullptr);
3649 }
3650
3651 /// Build a new noexcept expression.
3652 ///
3653 /// By default, performs semantic analysis to build the new expression.
3654 /// Subclasses may override this routine to provide different behavior.
3656 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3657 }
3658
3659 /// Build a new expression to compute the length of a parameter pack.
3661 SourceLocation PackLoc,
3662 SourceLocation RParenLoc,
3663 std::optional<unsigned> Length,
3664 ArrayRef<TemplateArgument> PartialArgs) {
3665 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3666 RParenLoc, Length, PartialArgs);
3667 }
3668
3670 SourceLocation RSquareLoc,
3671 Expr *PackIdExpression, Expr *IndexExpr,
3672 ArrayRef<Expr *> ExpandedExprs,
3673 bool FullySubstituted = false) {
3674 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3675 IndexExpr, RSquareLoc, ExpandedExprs,
3676 FullySubstituted);
3677 }
3678
3679 /// Build a new expression representing a call to a source location
3680 /// builtin.
3681 ///
3682 /// By default, performs semantic analysis to build the new expression.
3683 /// Subclasses may override this routine to provide different behavior.
3685 SourceLocation BuiltinLoc,
3686 SourceLocation RPLoc,
3687 DeclContext *ParentContext) {
3688 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3689 ParentContext);
3690 }
3691
3692 /// Build a new Objective-C boxed expression.
3693 ///
3694 /// By default, performs semantic analysis to build the new expression.
3695 /// Subclasses may override this routine to provide different behavior.
3697 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3698 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3700 CXXScopeSpec SS;
3701 SS.Adopt(NNS);
3702 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3703 ConceptNameInfo,
3704 FoundDecl,
3705 NamedConcept, TALI);
3706 if (Result.isInvalid())
3707 return ExprError();
3708 return Result;
3709 }
3710
3711 /// \brief Build a new requires expression.
3712 ///
3713 /// By default, performs semantic analysis to build the new expression.
3714 /// Subclasses may override this routine to provide different behavior.
3717 SourceLocation LParenLoc,
3718 ArrayRef<ParmVarDecl *> LocalParameters,
3719 SourceLocation RParenLoc,
3721 SourceLocation ClosingBraceLoc) {
3722 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3723 LocalParameters, RParenLoc, Requirements,
3724 ClosingBraceLoc);
3725 }
3726
3730 return SemaRef.BuildTypeRequirement(SubstDiag);
3731 }
3732
3735 }
3736
3739 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3740 SourceLocation NoexceptLoc,
3742 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3743 std::move(Ret));
3744 }
3745
3747 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3749 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3750 std::move(Ret));
3751 }
3752
3754 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3755 const ASTConstraintSatisfaction &Satisfaction) {
3756 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3757 Satisfaction);
3758 }
3759
3761 return SemaRef.BuildNestedRequirement(Constraint);
3762 }
3763
3764 /// \brief Build a new Objective-C boxed expression.
3765 ///
3766 /// By default, performs semantic analysis to build the new expression.
3767 /// Subclasses may override this routine to provide different behavior.
3769 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3770 }
3771
3772 /// Build a new Objective-C array literal.
3773 ///
3774 /// By default, performs semantic analysis to build the new expression.
3775 /// Subclasses may override this routine to provide different behavior.
3777 Expr **Elements, unsigned NumElements) {
3779 Range, MultiExprArg(Elements, NumElements));
3780 }
3781
3783 Expr *Base, Expr *Key,
3784 ObjCMethodDecl *getterMethod,
3785 ObjCMethodDecl *setterMethod) {
3787 RB, Base, Key, getterMethod, setterMethod);
3788 }
3789
3790 /// Build a new Objective-C dictionary literal.
3791 ///
3792 /// By default, performs semantic analysis to build the new expression.
3793 /// Subclasses may override this routine to provide different behavior.
3796 return getSema().ObjC().BuildObjCDictionaryLiteral(Range, Elements);
3797 }
3798
3799 /// Build a new Objective-C \@encode expression.
3800 ///
3801 /// By default, performs semantic analysis to build the new expression.
3802 /// Subclasses may override this routine to provide different behavior.
3804 TypeSourceInfo *EncodeTypeInfo,
3805 SourceLocation RParenLoc) {
3806 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3807 RParenLoc);
3808 }
3809
3810 /// Build a new Objective-C class message.
3812 Selector Sel,
3813 ArrayRef<SourceLocation> SelectorLocs,
3814 ObjCMethodDecl *Method,
3815 SourceLocation LBracLoc,
3816 MultiExprArg Args,
3817 SourceLocation RBracLoc) {
3819 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3820 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3821 RBracLoc, Args);
3822 }
3823
3824 /// Build a new Objective-C instance message.
3826 Selector Sel,
3827 ArrayRef<SourceLocation> SelectorLocs,
3828 ObjCMethodDecl *Method,
3829 SourceLocation LBracLoc,
3830 MultiExprArg Args,
3831 SourceLocation RBracLoc) {
3832 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3833 /*SuperLoc=*/SourceLocation(),
3834 Sel, Method, LBracLoc,
3835 SelectorLocs, RBracLoc, Args);
3836 }
3837
3838 /// Build a new Objective-C instance/class message to 'super'.
3840 Selector Sel,
3841 ArrayRef<SourceLocation> SelectorLocs,
3842 QualType SuperType,
3843 ObjCMethodDecl *Method,
3844 SourceLocation LBracLoc,
3845 MultiExprArg Args,
3846 SourceLocation RBracLoc) {
3847 return Method->isInstanceMethod()
3849 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3850 SelectorLocs, RBracLoc, Args)
3851 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3852 Sel, Method, LBracLoc,
3853 SelectorLocs, RBracLoc, Args);
3854 }
3855
3856 /// Build a new Objective-C ivar reference expression.
3857 ///
3858 /// By default, performs semantic analysis to build the new expression.
3859 /// Subclasses may override this routine to provide different behavior.
3861 SourceLocation IvarLoc,
3862 bool IsArrow, bool IsFreeIvar) {
3863 CXXScopeSpec SS;
3864 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3866 BaseArg, BaseArg->getType(),
3867 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3868 /*FirstQualifierInScope=*/nullptr, NameInfo,
3869 /*TemplateArgs=*/nullptr,
3870 /*S=*/nullptr);
3871 if (IsFreeIvar && Result.isUsable())
3872 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3873 return Result;
3874 }
3875
3876 /// Build a new Objective-C property reference expression.
3877 ///
3878 /// By default, performs semantic analysis to build the new expression.
3879 /// Subclasses may override this routine to provide different behavior.
3882 SourceLocation PropertyLoc) {
3883 CXXScopeSpec SS;
3884 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3885 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3886 /*FIXME:*/PropertyLoc,
3887 /*IsArrow=*/false,
3888 SS, SourceLocation(),
3889 /*FirstQualifierInScope=*/nullptr,
3890 NameInfo,
3891 /*TemplateArgs=*/nullptr,
3892 /*S=*/nullptr);
3893 }
3894
3895 /// Build a new Objective-C property reference expression.
3896 ///
3897 /// By default, performs semantic analysis to build the new expression.
3898 /// Subclasses may override this routine to provide different behavior.
3900 ObjCMethodDecl *Getter,
3901 ObjCMethodDecl *Setter,
3902 SourceLocation PropertyLoc) {
3903 // Since these expressions can only be value-dependent, we do not
3904 // need to perform semantic analysis again.
3905 return Owned(
3906 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3908 PropertyLoc, Base));
3909 }
3910
3911 /// Build a new Objective-C "isa" expression.
3912 ///
3913 /// By default, performs semantic analysis to build the new expression.
3914 /// Subclasses may override this routine to provide different behavior.
3916 SourceLocation OpLoc, bool IsArrow) {
3917 CXXScopeSpec SS;
3918 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3919 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3920 OpLoc, IsArrow,
3921 SS, SourceLocation(),
3922 /*FirstQualifierInScope=*/nullptr,
3923 NameInfo,
3924 /*TemplateArgs=*/nullptr,
3925 /*S=*/nullptr);
3926 }
3927
3928 /// Build a new shuffle vector expression.
3929 ///
3930 /// By default, performs semantic analysis to build the new expression.
3931 /// Subclasses may override this routine to provide different behavior.
3933 MultiExprArg SubExprs,
3934 SourceLocation RParenLoc) {
3935 // Find the declaration for __builtin_shufflevector
3936 const IdentifierInfo &Name
3937 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3939 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3940 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3941
3942 // Build a reference to the __builtin_shufflevector builtin
3943 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3944 Expr *Callee = new (SemaRef.Context)
3945 DeclRefExpr(SemaRef.Context, Builtin, false,
3946 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3947 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3948 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3949 CK_BuiltinFnToFnPtr).get();
3950
3951 // Build the CallExpr
3952 ExprResult TheCall = CallExpr::Create(
3953 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3954 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3956
3957 // Type-check the __builtin_shufflevector expression.
3958 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3959 }
3960
3961 /// Build a new convert vector expression.
3963 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3964 SourceLocation RParenLoc) {
3965 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3966 }
3967
3968 /// Build a new template argument pack expansion.
3969 ///
3970 /// By default, performs semantic analysis to build a new pack expansion
3971 /// for a template argument. Subclasses may override this routine to provide
3972 /// different behavior.
3975 std::optional<unsigned> NumExpansions) {
3976 switch (Pattern.getArgument().getKind()) {
3980 EllipsisLoc, NumExpansions);
3981 if (Result.isInvalid())
3982 return TemplateArgumentLoc();
3983
3984 return TemplateArgumentLoc(Result.get(), Result.get());
3985 }
3986
3988 return TemplateArgumentLoc(
3991 NumExpansions),
3992 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3993 EllipsisLoc);
3994
4002 llvm_unreachable("Pack expansion pattern has no parameter packs");
4003
4005 if (TypeSourceInfo *Expansion
4006 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4007 EllipsisLoc,
4008 NumExpansions))
4009 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4010 Expansion);
4011 break;
4012 }
4013
4014 return TemplateArgumentLoc();
4015 }
4016
4017 /// Build a new expression pack expansion.
4018 ///
4019 /// By default, performs semantic analysis to build a new pack expansion
4020 /// for an expression. Subclasses may override this routine to provide
4021 /// different behavior.
4023 std::optional<unsigned> NumExpansions) {
4024 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4025 }
4026
4027 /// Build a new C++1z fold-expression.
4028 ///
4029 /// By default, performs semantic analysis in order to build a new fold
4030 /// expression.
4032 SourceLocation LParenLoc, Expr *LHS,
4033 BinaryOperatorKind Operator,
4034 SourceLocation EllipsisLoc, Expr *RHS,
4035 SourceLocation RParenLoc,
4036 std::optional<unsigned> NumExpansions) {
4037 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4038 EllipsisLoc, RHS, RParenLoc,
4039 NumExpansions);
4040 }
4041
4043 LambdaScopeInfo *LSI) {
4044 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4045 if (Expr *Init = PVD->getInit())
4047 Init->containsUnexpandedParameterPack();
4048 else if (PVD->hasUninstantiatedDefaultArg())
4050 PVD->getUninstantiatedDefaultArg()
4051 ->containsUnexpandedParameterPack();
4052 }
4053 return getSema().BuildLambdaExpr(StartLoc, EndLoc, LSI);
4054 }
4055
4056 /// Build an empty C++1z fold-expression with the given operator.
4057 ///
4058 /// By default, produces the fallback value for the fold-expression, or
4059 /// produce an error if there is no fallback value.
4061 BinaryOperatorKind Operator) {
4062 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4063 }
4064
4065 /// Build a new atomic operation expression.
4066 ///
4067 /// By default, performs semantic analysis to build the new expression.
4068 /// Subclasses may override this routine to provide different behavior.
4071 SourceLocation RParenLoc) {
4072 // Use this for all of the locations, since we don't know the difference
4073 // between the call and the expr at this point.
4074 SourceRange Range{BuiltinLoc, RParenLoc};
4075 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4077 }
4078
4080 ArrayRef<Expr *> SubExprs, QualType Type) {
4081 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4082 }
4083
4085 SourceLocation BeginLoc,
4086 SourceLocation DirLoc,
4087 SourceLocation EndLoc,
4089 StmtResult StrBlock) {
4091 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4092 SourceLocation{}, EndLoc, Clauses, StrBlock);
4093 }
4094
4096 SourceLocation DirLoc,
4097 SourceLocation EndLoc,
4099 StmtResult Loop) {
4101 OpenACCDirectiveKind::Loop, BeginLoc, DirLoc, SourceLocation{},
4102 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, Loop);
4103 }
4104
4106 SourceLocation BeginLoc,
4107 SourceLocation DirLoc,
4108 SourceLocation EndLoc,
4110 StmtResult Loop) {
4112 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4113 SourceLocation{}, EndLoc, Clauses, Loop);
4114 }
4115
4117 SourceLocation DirLoc,
4118 SourceLocation EndLoc,
4120 StmtResult StrBlock) {
4122 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4123 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4124 }
4125
4128 SourceLocation DirLoc, SourceLocation EndLoc,
4129 ArrayRef<OpenACCClause *> Clauses) {
4132 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4133 }
4134
4137 SourceLocation DirLoc, SourceLocation EndLoc,
4138 ArrayRef<OpenACCClause *> Clauses) {
4141 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4142 }
4143
4145 SourceLocation DirLoc,
4146 SourceLocation EndLoc,
4148 StmtResult StrBlock) {
4151 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4152 }
4153
4155 SourceLocation DirLoc,
4156 SourceLocation EndLoc,
4157 ArrayRef<OpenACCClause *> Clauses) {
4159 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4160 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4161 }
4162
4165 SourceLocation DirLoc, SourceLocation EndLoc,
4166 ArrayRef<OpenACCClause *> Clauses) {
4169 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4170 }
4171
4173 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4174 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4175 SourceLocation RParenLoc, SourceLocation EndLoc,
4176 ArrayRef<OpenACCClause *> Clauses) {
4178 Exprs.push_back(DevNumExpr);
4179 Exprs.insert(Exprs.end(), QueueIdExprs.begin(), QueueIdExprs.end());
4181 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4182 Exprs, RParenLoc, EndLoc, Clauses, {});
4183 }
4184
4186 return getSema().OpenACC().ActOnOpenACCAsteriskSizeExpr(AsteriskLoc);
4187 }
4188
4189private:
4190 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
4191 QualType ObjectType,
4192 NamedDecl *FirstQualifierInScope,
4193 CXXScopeSpec &SS);
4194
4195 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4196 QualType ObjectType,
4197 NamedDecl *FirstQualifierInScope,
4198 CXXScopeSpec &SS);
4199
4200 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
4201 NamedDecl *FirstQualifierInScope,
4202 CXXScopeSpec &SS);
4203
4204 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4206 bool DeducibleTSTContext);
4207
4209 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4211
4213 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4214 OpenACCDirectiveKind DirKind,
4215 const OpenACCClause *OldClause);
4216};
4217
4218template <typename Derived>
4220 if (!S)
4221 return S;
4222
4223 switch (S->getStmtClass()) {
4224 case Stmt::NoStmtClass: break;
4225
4226 // Transform individual statement nodes
4227 // Pass SDK into statements that can produce a value
4228#define STMT(Node, Parent) \
4229 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4230#define VALUESTMT(Node, Parent) \
4231 case Stmt::Node##Class: \
4232 return getDerived().Transform##Node(cast<Node>(S), SDK);
4233#define ABSTRACT_STMT(Node)
4234#define EXPR(Node, Parent)
4235#include "clang/AST/StmtNodes.inc"
4236
4237 // Transform expressions by calling TransformExpr.
4238#define STMT(Node, Parent)
4239#define ABSTRACT_STMT(Stmt)
4240#define EXPR(Node, Parent) case Stmt::Node##Class:
4241#include "clang/AST/StmtNodes.inc"
4242 {
4243 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4244
4245 if (SDK == SDK_StmtExprResult)
4246 E = getSema().ActOnStmtExprResult(E);
4247 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
4248 }
4249 }
4250
4251 return S;
4252}
4253
4254template<typename Derived>
4256 if (!S)
4257 return S;
4258
4259 switch (S->getClauseKind()) {
4260 default: break;
4261 // Transform individual clause nodes
4262#define GEN_CLANG_CLAUSE_CLASS
4263#define CLAUSE_CLASS(Enum, Str, Class) \
4264 case Enum: \
4265 return getDerived().Transform##Class(cast<Class>(S));
4266#include "llvm/Frontend/OpenMP/OMP.inc"
4267 }
4268
4269 return S;
4270}
4271
4272
4273template<typename Derived>
4275 if (!E)
4276 return E;
4277
4278 switch (E->getStmtClass()) {
4279 case Stmt::NoStmtClass: break;
4280#define STMT(Node, Parent) case Stmt::Node##Class: break;
4281#define ABSTRACT_STMT(Stmt)
4282#define EXPR(Node, Parent) \
4283 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4284#include "clang/AST/StmtNodes.inc"
4285 }
4286
4287 return E;
4288}
4289
4290template<typename Derived>
4292 bool NotCopyInit) {
4293 // Initializers are instantiated like expressions, except that various outer
4294 // layers are stripped.
4295 if (!Init)
4296 return Init;
4297
4298 if (auto *FE = dyn_cast<FullExpr>(Init))
4299 Init = FE->getSubExpr();
4300
4301 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4302 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4303 Init = OVE->getSourceExpr();
4304 }
4305
4306 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4307 Init = MTE->getSubExpr();
4308
4309 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4310 Init = Binder->getSubExpr();
4311
4312 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4313 Init = ICE->getSubExprAsWritten();
4314
4315 if (CXXStdInitializerListExpr *ILE =
4316 dyn_cast<CXXStdInitializerListExpr>(Init))
4317 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4318
4319 // If this is copy-initialization, we only need to reconstruct
4320 // InitListExprs. Other forms of copy-initialization will be a no-op if
4321 // the initializer is already the right type.
4322 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4323 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4324 return getDerived().TransformExpr(Init);
4325
4326 // Revert value-initialization back to empty parens.
4327 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4328 SourceRange Parens = VIE->getSourceRange();
4329 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4330 Parens.getEnd());
4331 }
4332
4333 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4334 if (isa<ImplicitValueInitExpr>(Init))
4335 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4336 SourceLocation());
4337
4338 // Revert initialization by constructor back to a parenthesized or braced list
4339 // of expressions. Any other form of initializer can just be reused directly.
4340 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4341 return getDerived().TransformExpr(Init);
4342
4343 // If the initialization implicitly converted an initializer list to a
4344 // std::initializer_list object, unwrap the std::initializer_list too.
4345 if (Construct && Construct->isStdInitListInitialization())
4346 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4347
4348 // Enter a list-init context if this was list initialization.
4351 Construct->isListInitialization());
4352
4353 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4354 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4355 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4356 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4357 SmallVector<Expr*, 8> NewArgs;
4358 bool ArgChanged = false;
4359 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4360 /*IsCall*/true, NewArgs, &ArgChanged))
4361 return ExprError();
4362
4363 // If this was list initialization, revert to syntactic list form.
4364 if (Construct->isListInitialization())
4365 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4366 Construct->getEndLoc());
4367
4368 // Build a ParenListExpr to represent anything else.
4370 if (Parens.isInvalid()) {
4371 // This was a variable declaration's initialization for which no initializer
4372 // was specified.
4373 assert(NewArgs.empty() &&
4374 "no parens or braces but have direct init with arguments?");
4375 return ExprEmpty();
4376 }
4377 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4378 Parens.getEnd());
4379}
4380
4381template<typename Derived>
4383 unsigned NumInputs,
4384 bool IsCall,
4385 SmallVectorImpl<Expr *> &Outputs,
4386 bool *ArgChanged) {
4387 for (unsigned I = 0; I != NumInputs; ++I) {
4388 // If requested, drop call arguments that need to be dropped.
4389 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4390 if (ArgChanged)
4391 *ArgChanged = true;
4392
4393 break;
4394 }
4395
4396 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4397 Expr *Pattern = Expansion->getPattern();
4398
4400 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4401 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4402
4403 // Determine whether the set of unexpanded parameter packs can and should
4404 // be expanded.
4405 bool Expand = true;
4406 bool RetainExpansion = false;
4407 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4408 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4409 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4410 Pattern->getSourceRange(),
4411 Unexpanded,
4412 Expand, RetainExpansion,
4413 NumExpansions))
4414 return true;
4415
4416 if (!Expand) {
4417 // The transform has determined that we should perform a simple
4418 // transformation on the pack expansion, producing another pack
4419 // expansion.
4420 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4421 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4422 if (OutPattern.isInvalid())
4423 return true;
4424
4425 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4426 Expansion->getEllipsisLoc(),
4427 NumExpansions);
4428 if (Out.isInvalid())
4429 return true;
4430
4431 if (ArgChanged)
4432 *ArgChanged = true;
4433 Outputs.push_back(Out.get());
4434 continue;
4435 }
4436
4437 // Record right away that the argument was changed. This needs
4438 // to happen even if the array expands to nothing.
4439 if (ArgChanged) *ArgChanged = true;
4440
4441 // The transform has determined that we should perform an elementwise
4442 // expansion of the pattern. Do so.
4443 for (unsigned I = 0; I != *NumExpansions; ++I) {
4444 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4445 ExprResult Out = getDerived().TransformExpr(Pattern);
4446 if (Out.isInvalid())
4447 return true;
4448
4449 if (Out.get()->containsUnexpandedParameterPack()) {
4450 Out = getDerived().RebuildPackExpansion(
4451 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4452 if (Out.isInvalid())
4453 return true;
4454 }
4455
4456 Outputs.push_back(Out.get());
4457 }
4458
4459 // If we're supposed to retain a pack expansion, do so by temporarily
4460 // forgetting the partially-substituted parameter pack.
4461 if (RetainExpansion) {
4462 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4463
4464 ExprResult Out = getDerived().TransformExpr(Pattern);
4465 if (Out.isInvalid())
4466 return true;
4467
4468 Out = getDerived().RebuildPackExpansion(
4469 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4470 if (Out.isInvalid())
4471 return true;
4472
4473 Outputs.push_back(Out.get());
4474 }
4475
4476 continue;
4477 }
4478
4480 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4481 : getDerived().TransformExpr(Inputs[I]);
4482 if (Result.isInvalid())
4483 return true;
4484
4485 if (Result.get() != Inputs[I] && ArgChanged)
4486 *ArgChanged = true;
4487
4488 Outputs.push_back(Result.get());
4489 }
4490
4491 return false;
4492}
4493
4494template <typename Derived>
4497 if (Var) {
4498 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4499 getDerived().TransformDefinition(Var->getLocation(), Var));
4500
4501 if (!ConditionVar)
4502 return Sema::ConditionError();
4503
4504 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4505 }
4506
4507 if (Expr) {
4508 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4509
4510 if (CondExpr.isInvalid())
4511 return Sema::ConditionError();
4512
4513 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4514 /*MissingOK=*/true);
4515 }
4516
4517 return Sema::ConditionResult();
4518}
4519
4520template <typename Derived>
4522 NestedNameSpecifierLoc NNS, QualType ObjectType,
4523 NamedDecl *FirstQualifierInScope) {
4525
4526 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4527 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4528 Qualifier = Qualifier.getPrefix())
4529 Qualifiers.push_back(Qualifier);
4530 };
4531 insertNNS(NNS);
4532
4533 CXXScopeSpec SS;
4534 while (!Qualifiers.empty()) {
4535 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4537
4538 switch (QNNS->getKind()) {
4542 ObjectType);
4543 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4544 SS, FirstQualifierInScope, false))
4545 return NestedNameSpecifierLoc();
4546 break;
4547 }
4548
4550 NamespaceDecl *NS =
4551 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4552 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4553 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4554 break;
4555 }
4556
4558 NamespaceAliasDecl *Alias =
4559 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4561 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4562 Q.getLocalEndLoc());
4563 break;
4564 }
4565
4567 // There is no meaningful transformation that one could perform on the
4568 // global scope.
4569 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4570 break;
4571
4573 CXXRecordDecl *RD =
4574 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4575 SourceLocation(), QNNS->getAsRecordDecl()));
4576 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4577 break;
4578 }
4579
4582 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4583 FirstQualifierInScope, SS);
4584
4585 if (!TL)
4586 return NestedNameSpecifierLoc();
4587
4588 QualType T = TL.getType();
4589 if (T->isDependentType() || T->isRecordType() ||
4590 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4591 if (T->isEnumeralType())
4592 SemaRef.Diag(TL.getBeginLoc(),
4593 diag::warn_cxx98_compat_enum_nested_name_spec);
4594
4595 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) {
4596 SS.Adopt(ETL.getQualifierLoc());
4597 TL = ETL.getNamedTypeLoc();
4598 }
4599
4600 SS.Extend(SemaRef.Context, TL.getTemplateKeywordLoc(), TL,
4601 Q.getLocalEndLoc());
4602 break;
4603 }
4604 // If the nested-name-specifier is an invalid type def, don't emit an
4605 // error because a previous error should have already been emitted.
4607 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4608 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4609 << T << SS.getRange();
4610 }
4611 return NestedNameSpecifierLoc();
4612 }
4613 }
4614
4615 // The qualifier-in-scope and object type only apply to the leftmost entity.
4616 FirstQualifierInScope = nullptr;
4617 ObjectType = QualType();
4618 }
4619
4620 // Don't rebuild the nested-name-specifier if we don't have to.
4621 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4622 !getDerived().AlwaysRebuild())
4623 return NNS;
4624
4625 // If we can re-use the source-location data from the original
4626 // nested-name-specifier, do so.
4627 if (SS.location_size() == NNS.getDataLength() &&
4628 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4630
4631 // Allocate new nested-name-specifier location information.
4632 return SS.getWithLocInContext(SemaRef.Context);
4633}
4634
4635template<typename Derived>
4639 DeclarationName Name = NameInfo.getName();
4640 if (!Name)
4641 return DeclarationNameInfo();
4642
4643 switch (Name.getNameKind()) {
4651 return NameInfo;
4652
4654 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4655 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4656 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4657 if (!NewTemplate)
4658 return DeclarationNameInfo();
4659
4660 DeclarationNameInfo NewNameInfo(NameInfo);
4661 NewNameInfo.setName(
4663 return NewNameInfo;
4664 }
4665
4669 TypeSourceInfo *NewTInfo;
4670 CanQualType NewCanTy;
4671 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4672 NewTInfo = getDerived().TransformType(OldTInfo);
4673 if (!NewTInfo)
4674 return DeclarationNameInfo();
4675 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4676 }
4677 else {
4678 NewTInfo = nullptr;
4679 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4680 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4681 if (NewT.isNull())
4682 return DeclarationNameInfo();
4683 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4684 }
4685
4686 DeclarationName NewName
4687 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4688 NewCanTy);
4689 DeclarationNameInfo NewNameInfo(NameInfo);
4690 NewNameInfo.setName(NewName);
4691 NewNameInfo.setNamedTypeInfo(NewTInfo);
4692 return NewNameInfo;
4693 }
4694 }
4695
4696 llvm_unreachable("Unknown name kind.");
4697}
4698
4699template<typename Derived>
4702 TemplateName Name,
4703 SourceLocation NameLoc,
4704 QualType ObjectType,
4705 NamedDecl *FirstQualifierInScope,
4706 bool AllowInjectedClassName) {
4707 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4708 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
4709 assert(Template && "qualified template name must refer to a template");
4710
4711 TemplateDecl *TransTemplate
4712 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4713 Template));
4714 if (!TransTemplate)
4715 return TemplateName();
4716
4717 if (!getDerived().AlwaysRebuild() &&
4718 SS.getScopeRep() == QTN->getQualifier() &&
4719 TransTemplate == Template)
4720 return Name;
4721
4722 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4723 TransTemplate);
4724 }
4725
4726 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4727 if (SS.getScopeRep()) {
4728 // These apply to the scope specifier, not the template.
4729 ObjectType = QualType();
4730 FirstQualifierInScope = nullptr;
4731 }
4732
4733 if (!getDerived().AlwaysRebuild() &&
4734 SS.getScopeRep() == DTN->getQualifier() &&
4735 ObjectType.isNull())
4736 return Name;
4737
4738 // FIXME: Preserve the location of the "template" keyword.
4739 SourceLocation TemplateKWLoc = NameLoc;
4740
4741 if (DTN->isIdentifier()) {
4742 return getDerived().RebuildTemplateName(SS,
4743 TemplateKWLoc,
4744 *DTN->getIdentifier(),
4745 NameLoc,
4746 ObjectType,
4747 FirstQualifierInScope,
4748 AllowInjectedClassName);
4749 }
4750
4751 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4752 DTN->getOperator(), NameLoc,
4753 ObjectType, AllowInjectedClassName);
4754 }
4755
4756 // FIXME: Try to preserve more of the TemplateName.
4757 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4758 TemplateDecl *TransTemplate
4759 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4760 Template));
4761 if (!TransTemplate)
4762 return TemplateName();
4763
4764 return getDerived().RebuildTemplateName(SS, /*TemplateKeyword=*/false,
4765 TransTemplate);
4766 }
4767
4769 = Name.getAsSubstTemplateTemplateParmPack()) {
4770 return getDerived().RebuildTemplateName(
4771 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4772 SubstPack->getIndex(), SubstPack->getFinal());
4773 }
4774
4775 // These should be getting filtered out before they reach the AST.
4776 llvm_unreachable("overloaded function decl survived to here");
4777}
4778
4779template<typename Derived>
4781 const TemplateArgument &Arg,
4782 TemplateArgumentLoc &Output) {
4783 Output = getSema().getTrivialTemplateArgumentLoc(
4784 Arg, QualType(), getDerived().getBaseLocation());
4785}
4786
4787template <typename Derived>
4789 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4790 bool Uneval) {
4791 const TemplateArgument &Arg = Input.getArgument();
4792 switch (Arg.getKind()) {
4795 llvm_unreachable("Unexpected TemplateArgument");
4796
4801 // Transform a resolved template argument straight to a resolved template
4802 // argument. We get here when substituting into an already-substituted
4803 // template type argument during concept satisfaction checking.
4805 QualType NewT = getDerived().TransformType(T);
4806 if (NewT.isNull())
4807 return true;
4808
4810 ? Arg.getAsDecl()
4811 : nullptr;
4812 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4813 getDerived().getBaseLocation(), D))
4814 : nullptr;
4815 if (D && !NewD)
4816 return true;
4817
4818 if (NewT == T && D == NewD)
4819 Output = Input;
4820 else if (Arg.getKind() == TemplateArgument::Integral)
4821 Output = TemplateArgumentLoc(
4822 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4824 else if (Arg.getKind() == TemplateArgument::NullPtr)
4825 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4827 else if (Arg.getKind() == TemplateArgument::Declaration)
4828 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4831 Output = TemplateArgumentLoc(
4832 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4834 else
4835 llvm_unreachable("unexpected template argument kind");
4836
4837 return false;
4838 }
4839
4841 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4842 if (!DI)
4843 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4844
4845 DI = getDerived().TransformType(DI);
4846 if (!DI)
4847 return true;
4848
4849 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4850 return false;
4851 }
4852
4854 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4855 if (QualifierLoc) {
4856 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4857 if (!QualifierLoc)
4858 return true;
4859 }
4860
4861 CXXScopeSpec SS;
4862 SS.Adopt(QualifierLoc);
4863 TemplateName Template = getDerived().TransformTemplateName(
4864 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4865 if (Template.isNull())
4866 return true;
4867
4868 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4869 QualifierLoc, Input.getTemplateNameLoc());
4870 return false;
4871 }
4872
4874 llvm_unreachable("Caller should expand pack expansions");
4875
4877 // Template argument expressions are constant expressions.
4879 getSema(),
4882 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
4884
4885 Expr *InputExpr = Input.getSourceExpression();
4886 if (!InputExpr)
4887 InputExpr = Input.getArgument().getAsExpr();
4888
4889 ExprResult E = getDerived().TransformExpr(InputExpr);
4890 E = SemaRef.ActOnConstantExpression(E);
4891 if (E.isInvalid())
4892 return true;
4893 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4894 return false;
4895 }
4896 }
4897
4898 // Work around bogus GCC warning
4899 return true;
4900}
4901
4902/// Iterator adaptor that invents template argument location information
4903/// for each of the template arguments in its underlying iterator.
4904template<typename Derived, typename InputIterator>
4907 InputIterator Iter;
4908
4909public:
4912 typedef typename std::iterator_traits<InputIterator>::difference_type
4914 typedef std::input_iterator_tag iterator_category;
4915
4916 class pointer {
4918
4919 public:
4920 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4921
4922 const TemplateArgumentLoc *operator->() const { return &Arg; }
4923 };
4924
4926 InputIterator Iter)
4927 : Self(Self), Iter(Iter) { }
4928
4930 ++Iter;
4931 return *this;
4932 }
4933
4936 ++(*this);
4937 return Old;
4938 }
4939
4942 Self.InventTemplateArgumentLoc(*Iter, Result);
4943 return Result;
4944 }
4945
4946 pointer operator->() const { return pointer(**this); }
4947
4950 return X.Iter == Y.Iter;
4951 }
4952
4955 return X.Iter != Y.Iter;
4956 }
4957};
4958
4959template<typename Derived>
4960template<typename InputIterator>
4962 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4963 bool Uneval) {
4964 for (; First != Last; ++First) {
4967
4968 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4969 // Unpack argument packs, which we translate them into separate
4970 // arguments.
4971 // FIXME: We could do much better if we could guarantee that the
4972 // TemplateArgumentLocInfo for the pack expansion would be usable for
4973 // all of the template arguments in the argument pack.
4974 typedef TemplateArgumentLocInventIterator<Derived,
4976 PackLocIterator;
4977 if (TransformTemplateArguments(PackLocIterator(*this,
4978 In.getArgument().pack_begin()),
4979 PackLocIterator(*this,
4980 In.getArgument().pack_end()),
4981 Outputs, Uneval))
4982 return true;
4983
4984 continue;
4985 }
4986
4987 if (In.getArgument().isPackExpansion()) {
4988 // We have a pack expansion, for which we will be substituting into
4989 // the pattern.
4990 SourceLocation Ellipsis;
4991 std::optional<unsigned> OrigNumExpansions;
4992 TemplateArgumentLoc Pattern
4993 = getSema().getTemplateArgumentPackExpansionPattern(
4994 In, Ellipsis, OrigNumExpansions);
4995
4997 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4998 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4999
5000 // Determine whether the set of unexpanded parameter packs can and should
5001 // be expanded.
5002 bool Expand = true;
5003 bool RetainExpansion = false;
5004 std::optional<unsigned> NumExpansions = OrigNumExpansions;
5005 if (getDerived().TryExpandParameterPacks(Ellipsis,
5006 Pattern.getSourceRange(),
5007 Unexpanded,
5008 Expand,
5009 RetainExpansion,
5010 NumExpansions))
5011 return true;
5012
5013 if (!Expand) {
5014 // The transform has determined that we should perform a simple
5015 // transformation on the pack expansion, producing another pack
5016 // expansion.
5017 TemplateArgumentLoc OutPattern;
5018 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5019 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5020 return true;
5021
5022 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
5023 NumExpansions);
5024 if (Out.getArgument().isNull())
5025 return true;
5026
5027 Outputs.addArgument(Out);
5028 continue;
5029 }
5030
5031 // The transform has determined that we should perform an elementwise
5032 // expansion of the pattern. Do so.
5033 for (unsigned I = 0; I != *NumExpansions; ++I) {
5034 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5035
5036 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5037 return true;
5038
5039 if (Out.getArgument().containsUnexpandedParameterPack()) {
5040 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5041 OrigNumExpansions);
5042 if (Out.getArgument().isNull())
5043 return true;
5044 }
5045
5046 Outputs.addArgument(Out);
5047 }
5048
5049 // If we're supposed to retain a pack expansion, do so by temporarily
5050 // forgetting the partially-substituted parameter pack.
5051 if (RetainExpansion) {
5052 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5053
5054 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5055 return true;
5056
5057 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5058 OrigNumExpansions);
5059 if (Out.getArgument().isNull())
5060 return true;
5061
5062 Outputs.addArgument(Out);
5063 }
5064
5065 continue;
5066 }
5067
5068 // The simple case:
5069 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5070 return true;
5071
5072 Outputs.addArgument(Out);
5073 }
5074
5075 return false;
5076
5077}
5078
5079//===----------------------------------------------------------------------===//
5080// Type transformation
5081//===----------------------------------------------------------------------===//
5082
5083template<typename Derived>
5085 if (getDerived().AlreadyTransformed(T))
5086 return T;
5087
5088 // Temporary workaround. All of these transformations should
5089 // eventually turn into transformations on TypeLocs.
5090 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5091 getDerived().getBaseLocation());
5092
5093 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
5094
5095 if (!NewDI)
5096 return QualType();
5097
5098 return NewDI->getType();
5099}
5100
5101template<typename Derived>
5103 // Refine the base location to the type's location.
5104 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5105 getDerived().getBaseEntity());
5106 if (getDerived().AlreadyTransformed(DI->getType()))
5107 return DI;
5108
5109 TypeLocBuilder TLB;
5110
5111 TypeLoc TL = DI->getTypeLoc();
5112 TLB.reserve(TL.getFullDataSize());
5113
5114 QualType Result = getDerived().TransformType(TLB, TL);
5115 if (Result.isNull())
5116 return nullptr;
5117
5118 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5119}
5120
5121template<typename Derived>
5124 switch (T.getTypeLocClass()) {
5125#define ABSTRACT_TYPELOC(CLASS, PARENT)
5126#define TYPELOC(CLASS, PARENT) \
5127 case TypeLoc::CLASS: \
5128 return getDerived().Transform##CLASS##Type(TLB, \
5129 T.castAs<CLASS##TypeLoc>());
5130#include "clang/AST/TypeLocNodes.def"
5131 }
5132
5133 llvm_unreachable("unhandled type loc!");
5134}
5135
5136template<typename Derived>
5138 if (!isa<DependentNameType>(T))
5139 return TransformType(T);
5140
5141 if (getDerived().AlreadyTransformed(T))
5142 return T;
5143 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5144 getDerived().getBaseLocation());
5145 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5146 return NewDI ? NewDI->getType() : QualType();
5147}
5148
5149template<typename Derived>
5152 if (!isa<DependentNameType>(DI->getType()))
5153 return TransformType(DI);
5154
5155 // Refine the base location to the type's location.
5156 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5157 getDerived().getBaseEntity());
5158 if (getDerived().AlreadyTransformed(DI->getType()))
5159 return DI;
5160
5161 TypeLocBuilder TLB;
5162
5163 TypeLoc TL = DI->getTypeLoc();
5164 TLB.reserve(TL.getFullDataSize());
5165
5166 auto QTL = TL.getAs<QualifiedTypeLoc>();
5167 if (QTL)
5168 TL = QTL.getUnqualifiedLoc();
5169
5170 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5171
5172 QualType Result = getDerived().TransformDependentNameType(
5173 TLB, DNTL, /*DeducedTSTContext*/true);
5174 if (Result.isNull())
5175 return nullptr;
5176
5177 if (QTL) {
5178 Result = getDerived().RebuildQualifiedType(Result, QTL);
5179 if (Result.isNull())
5180 return nullptr;
5182 }
5183
5184 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5185}
5186
5187template<typename Derived>
5192 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5193 auto SuppressObjCLifetime =
5194 T.getType().getLocalQualifiers().hasObjCLifetime();
5195 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5196 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5197 SuppressObjCLifetime);
5198 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5199 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5200 TLB, STTP, SuppressObjCLifetime);
5201 } else {
5202 Result = getDerived().TransformType(TLB, UnqualTL);
5203 }
5204
5205 if (Result.isNull())
5206 return QualType();
5207
5208 Result = getDerived().RebuildQualifiedType(Result, T);
5209
5210 if (Result.isNull())
5211 return QualType();
5212
5213 // RebuildQualifiedType might have updated the type, but not in a way
5214 // that invalidates the TypeLoc. (There's no location information for
5215 // qualifiers.)
5217
5218 return Result;
5219}
5220
5221template <typename Derived>
5223 QualifiedTypeLoc TL) {
5224
5226 Qualifiers Quals = TL.getType().getLocalQualifiers();
5227
5228 if ((T.getAddressSpace() != LangAS::Default &&
5229 Quals.getAddressSpace() != LangAS::Default) &&
5230 T.getAddressSpace() != Quals.getAddressSpace()) {
5231 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5232 << TL.getType() << T;
5233 return QualType();
5234 }
5235
5236 // C++ [dcl.fct]p7:
5237 // [When] adding cv-qualifications on top of the function type [...] the
5238 // cv-qualifiers are ignored.
5239 if (T->isFunctionType()) {
5241 Quals.getAddressSpace());
5242 return T;
5243 }
5244
5245 // C++ [dcl.ref]p1:
5246 // when the cv-qualifiers are introduced through the use of a typedef-name
5247 // or decltype-specifier [...] the cv-qualifiers are ignored.
5248 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5249 // applied to a reference type.
5250 if (T->isReferenceType()) {
5251 // The only qualifier that applies to a reference type is restrict.
5252 if (!Quals.hasRestrict())
5253 return T;
5255 }
5256
5257 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5258 // resulting type.
5259 if (Quals.hasObjCLifetime()) {
5260 if (!T->isObjCLifetimeType() && !T->isDependentType())
5261 Quals.removeObjCLifetime();
5262 else if (T.getObjCLifetime()) {
5263 // Objective-C ARC:
5264 // A lifetime qualifier applied to a substituted template parameter
5265 // overrides the lifetime qualifier from the template argument.
5266 const AutoType *AutoTy;
5267 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5268 // 'auto' types behave the same way as template parameters.
5269 QualType Deduced = AutoTy->getDeducedType();
5270 Qualifiers Qs = Deduced.getQualifiers();
5271 Qs.removeObjCLifetime();
5272 Deduced =
5273 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5274 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5275 AutoTy->isDependentType(),
5276 /*isPack=*/false,
5277 AutoTy->getTypeConstraintConcept(),
5278 AutoTy->getTypeConstraintArguments());
5279 } else {
5280 // Otherwise, complain about the addition of a qualifier to an
5281 // already-qualified type.
5282 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5283 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5284 Quals.removeObjCLifetime();
5285 }
5286 }
5287 }
5288
5289 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5290}
5291
5292template<typename Derived>
5293TypeLoc
5295 QualType ObjectType,
5296 NamedDecl *UnqualLookup,
5297 CXXScopeSpec &SS) {
5298 if (getDerived().AlreadyTransformed(TL.getType()))
5299 return TL;
5300
5301 TypeSourceInfo *TSI =
5302 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
5303 if (TSI)
5304 return TSI->getTypeLoc();
5305 return TypeLoc();
5306}
5307
5308template<typename Derived>
5309TypeSourceInfo *
5310TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
5311 QualType ObjectType,
5312 NamedDecl *UnqualLookup,
5313 CXXScopeSpec &SS) {
5314 if (getDerived().AlreadyTransformed(TSInfo->getType()))
5315 return TSInfo;
5316
5317 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
5318 UnqualLookup, SS);
5319}
5320
5321template <typename Derived>
5322TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
5323 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
5324 CXXScopeSpec &SS) {
5325 QualType T = TL.getType();
5326 assert(!getDerived().AlreadyTransformed(T));
5327
5328 TypeLocBuilder TLB;
5329 QualType Result;
5330
5331 if (isa<TemplateSpecializationType>(T)) {
5332 TemplateSpecializationTypeLoc SpecTL =
5333 TL.castAs<TemplateSpecializationTypeLoc>();
5334
5335 TemplateName Template = getDerived().TransformTemplateName(
5336 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
5337 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
5338 if (Template.isNull())
5339 return nullptr;
5340
5341 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
5342 Template);
5343 } else if (isa<DependentTemplateSpecializationType>(T)) {
5344 DependentTemplateSpecializationTypeLoc SpecTL =
5345 TL.castAs<DependentTemplateSpecializationTypeLoc>();
5346
5347 TemplateName Template
5348 = getDerived().RebuildTemplateName(SS,
5349 SpecTL.getTemplateKeywordLoc(),
5350 *SpecTL.getTypePtr()->getIdentifier(),
5351 SpecTL.getTemplateNameLoc(),
5352 ObjectType, UnqualLookup,
5353 /*AllowInjectedClassName*/true);
5354 if (Template.isNull())
5355 return nullptr;
5356
5357 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
5358 SpecTL,
5359 Template,
5360 SS);
5361 } else {
5362 // Nothing special needs to be done for these.
5363 Result = getDerived().TransformType(TLB, TL);
5364 }
5365
5366 if (Result.isNull())
5367 return nullptr;
5368
5369 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5370}
5371
5372template <class TyLoc> static inline
5374 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5375 NewT.setNameLoc(T.getNameLoc());
5376 return T.getType();
5377}
5378
5379template<typename Derived>
5380QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5381 BuiltinTypeLoc T) {
5382 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5383 NewT.setBuiltinLoc(T.getBuiltinLoc());
5384 if (T.needsExtraLocalData())
5385 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5386 return T.getType();
5387}
5388
5389template<typename Derived>
5390QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
5391 ComplexTypeLoc T) {
5392 // FIXME: recurse?
5393 return TransformTypeSpecType(TLB, T);
5394}
5395
5396template <typename Derived>
5397QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
5398 AdjustedTypeLoc TL) {
5399 // Adjustments applied during transformation are handled elsewhere.
5400 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5401}
5402
5403template<typename Derived>
5404QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
5405 DecayedTypeLoc TL) {
5406 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5407 if (OriginalType.isNull())
5408 return QualType();
5409
5410 QualType Result = TL.getType();
5411 if (getDerived().AlwaysRebuild() ||
5412 OriginalType != TL.getOriginalLoc().getType())
5413 Result = SemaRef.Context.getDecayedType(OriginalType);
5414 TLB.push<DecayedTypeLoc>(Result);
5415 // Nothing to set for DecayedTypeLoc.
5416 return Result;
5417}
5418
5419template <typename Derived>
5420QualType
5421TreeTransform<Derived>::TransformArrayParameterType(TypeLocBuilder &TLB,
5422 ArrayParameterTypeLoc TL) {
5423 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5424 if (OriginalType.isNull())
5425 return QualType();
5426
5427 QualType Result = TL.getType();
5428 if (getDerived().AlwaysRebuild() ||
5429 OriginalType != TL.getElementLoc().getType())
5430 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5431 TLB.push<ArrayParameterTypeLoc>(Result);
5432 // Nothing to set for ArrayParameterTypeLoc.
5433 return Result;
5434}
5435
5436template<typename Derived>
5437QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
5438 PointerTypeLoc TL) {
5439 QualType PointeeType
5440 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5441 if (PointeeType.isNull())
5442 return QualType();
5443
5444 QualType Result = TL.getType();
5445 if (PointeeType->getAs<ObjCObjectType>()) {
5446 // A dependent pointer type 'T *' has is being transformed such
5447 // that an Objective-C class type is being replaced for 'T'. The
5448 // resulting pointer type is an ObjCObjectPointerType, not a
5449 // PointerType.
5450 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5451
5452 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5453 NewT.setStarLoc(TL.getStarLoc());
5454 return Result;
5455 }
5456
5457 if (getDerived().AlwaysRebuild() ||
5458 PointeeType != TL.getPointeeLoc().getType()) {
5459 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5460 if (Result.isNull())
5461 return QualType();
5462 }
5463
5464 // Objective-C ARC can add lifetime qualifiers to the type that we're
5465 // pointing to.
5466 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5467
5468 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5469 NewT.setSigilLoc(TL.getSigilLoc());
5470 return Result;
5471}
5472
5473template<typename Derived>
5474QualType
5475TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
5476 BlockPointerTypeLoc TL) {
5477 QualType PointeeType
5478 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5479 if (PointeeType.isNull())
5480 return QualType();
5481
5482 QualType Result = TL.getType();
5483 if (getDerived().AlwaysRebuild() ||
5484 PointeeType != TL.getPointeeLoc().getType()) {
5485 Result = getDerived().RebuildBlockPointerType(PointeeType,
5486 TL.getSigilLoc());
5487 if (Result.isNull())
5488 return QualType();
5489 }
5490
5491 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5492 NewT.setSigilLoc(TL.getSigilLoc());
5493 return Result;
5494}
5495
5496/// Transforms a reference type. Note that somewhat paradoxically we
5497/// don't care whether the type itself is an l-value type or an r-value
5498/// type; we only care if the type was *written* as an l-value type
5499/// or an r-value type.
5500template<typename Derived>
5501QualType
5503 ReferenceTypeLoc TL) {
5504 const ReferenceType *T = TL.getTypePtr();
5505
5506 // Note that this works with the pointee-as-written.
5507 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5508 if (PointeeType.isNull())
5509 return QualType();
5510
5511 QualType Result = TL.getType();
5512 if (getDerived().AlwaysRebuild() ||
5513 PointeeType != T->getPointeeTypeAsWritten()) {
5514 Result = getDerived().RebuildReferenceType(PointeeType,
5515 T->isSpelledAsLValue(),
5516 TL.getSigilLoc());
5517 if (Result.isNull())
5518 return QualType();
5519 }
5520
5521 // Objective-C ARC can add lifetime qualifiers to the type that we're
5522 // referring to.
5525
5526 // r-value references can be rebuilt as l-value references.
5527 ReferenceTypeLoc NewTL;
5528 if (isa<LValueReferenceType>(Result))
5529 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5530 else
5531 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5532 NewTL.setSigilLoc(TL.getSigilLoc());
5533
5534 return Result;
5535}
5536
5537template<typename Derived>
5541 return TransformReferenceType(TLB, TL);
5542}
5543
5544template<typename Derived>
5545QualType
5546TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5547 RValueReferenceTypeLoc TL) {
5548 return TransformReferenceType(TLB, TL);
5549}
5550
5551template<typename Derived>
5552QualType
5553TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5554 MemberPointerTypeLoc TL) {
5555 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5556 if (PointeeType.isNull())
5557 return QualType();
5558
5559 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
5560 TypeSourceInfo *NewClsTInfo = nullptr;
5561 if (OldClsTInfo) {
5562 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
5563 if (!NewClsTInfo)
5564 return QualType();
5565 }
5566
5567 const MemberPointerType *T = TL.getTypePtr();
5568 QualType OldClsType = QualType(T->getClass(), 0);
5569 QualType NewClsType;
5570 if (NewClsTInfo)
5571 NewClsType = NewClsTInfo->getType();
5572 else {
5573 NewClsType = getDerived().TransformType(OldClsType);
5574 if (NewClsType.isNull())
5575 return QualType();
5576 }
5577
5578 QualType Result = TL.getType();
5579 if (getDerived().AlwaysRebuild() ||
5580 PointeeType != T->getPointeeType() ||
5581 NewClsType != OldClsType) {
5582 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
5583 TL.getStarLoc());
5584 if (Result.isNull())
5585 return QualType();
5586 }
5587
5588 // If we had to adjust the pointee type when building a member pointer, make
5589 // sure to push TypeLoc info for it.
5590 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5591 if (MPT && PointeeType != MPT->getPointeeType()) {
5592 assert(isa<AdjustedType>(MPT->getPointeeType()));
5593 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5594 }
5595
5596 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
5597 NewTL.setSigilLoc(TL.getSigilLoc());
5598 NewTL.setClassTInfo(NewClsTInfo);
5599
5600 return Result;
5601}
5602
5603template<typename Derived>
5604QualType
5605TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
5606 ConstantArrayTypeLoc TL) {
5607 const ConstantArrayType *T = TL.getTypePtr();
5608 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5609 if (ElementType.isNull())
5610 return QualType();
5611
5612 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5613 Expr *OldSize = TL.getSizeExpr();
5614 if (!OldSize)
5615 OldSize = const_cast<Expr*>(T->getSizeExpr());
5616 Expr *NewSize = nullptr;
5617 if (OldSize) {
5618 EnterExpressionEvaluationContext Unevaluated(
5620 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5621 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5622 }
5623
5624 QualType Result = TL.getType();
5625 if (getDerived().AlwaysRebuild() ||
5626 ElementType != T->getElementType() ||
5627 (T->getSizeExpr() && NewSize != OldSize)) {
5628 Result = getDerived().RebuildConstantArrayType(ElementType,
5629 T->getSizeModifier(),
5630 T->getSize(), NewSize,
5631 T->getIndexTypeCVRQualifiers(),
5632 TL.getBracketsRange());
5633 if (Result.isNull())
5634 return QualType();
5635 }
5636
5637 // We might have either a ConstantArrayType or a VariableArrayType now:
5638 // a ConstantArrayType is allowed to have an element type which is a
5639 // VariableArrayType if the type is dependent. Fortunately, all array
5640 // types have the same location layout.
5641 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5642 NewTL.setLBracketLoc(TL.getLBracketLoc());
5643 NewTL.setRBracketLoc(TL.getRBracketLoc());
5644 NewTL.setSizeExpr(NewSize);
5645
5646 return Result;
5647}
5648
5649template<typename Derived>
5650QualType TreeTransform<Derived>::TransformIncompleteArrayType(
5651 TypeLocBuilder &TLB,
5652 IncompleteArrayTypeLoc TL) {
5653 const IncompleteArrayType *T = TL.getTypePtr();
5654 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5655 if (ElementType.isNull())
5656 return QualType();
5657
5658 QualType Result = TL.getType();
5659 if (getDerived().AlwaysRebuild() ||
5660 ElementType != T->getElementType()) {
5661 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5662 T->getSizeModifier(),
5663 T->getIndexTypeCVRQualifiers(),
5664 TL.getBracketsRange());
5665 if (Result.isNull())
5666 return QualType();
5667 }
5668
5669 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5670 NewTL.setLBracketLoc(TL.getLBracketLoc());
5671 NewTL.setRBracketLoc(TL.getRBracketLoc());
5672 NewTL.setSizeExpr(nullptr);
5673
5674 return Result;
5675}
5676
5677template<typename Derived>
5678QualType
5679TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
5680 VariableArrayTypeLoc TL) {
5681 const VariableArrayType *T = TL.getTypePtr();
5682 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5683 if (ElementType.isNull())
5684 return QualType();
5685
5686 ExprResult SizeResult;
5687 {
5688 EnterExpressionEvaluationContext Context(
5690 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5691 }
5692 if (SizeResult.isInvalid())
5693 return QualType();
5694 SizeResult =
5695 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5696 if (SizeResult.isInvalid())
5697 return QualType();
5698
5699 Expr *Size = SizeResult.get();
5700
5701 QualType Result = TL.getType();
5702 if (getDerived().AlwaysRebuild() ||
5703 ElementType != T->getElementType() ||
5704 Size != T->getSizeExpr()) {
5705 Result = getDerived().RebuildVariableArrayType(ElementType,
5706 T->getSizeModifier(),
5707 Size,
5708 T->getIndexTypeCVRQualifiers(),
5709 TL.getBracketsRange());
5710 if (Result.isNull())
5711 return QualType();
5712 }
5713
5714 // We might have constant size array now, but fortunately it has the same
5715 // location layout.
5716 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5717 NewTL.setLBracketLoc(TL.getLBracketLoc());
5718 NewTL.setRBracketLoc(TL.getRBracketLoc());
5719 NewTL.setSizeExpr(Size);
5720
5721 return Result;
5722}
5723
5724template<typename Derived>
5725QualType
5726TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
5727 DependentSizedArrayTypeLoc TL) {
5728 const DependentSizedArrayType *T = TL.getTypePtr();
5729 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5730 if (ElementType.isNull())
5731 return QualType();
5732
5733 // Array bounds are constant expressions.
5734 EnterExpressionEvaluationContext Unevaluated(
5736
5737 // If we have a VLA then it won't be a constant.
5738 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5739
5740 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5741 Expr *origSize = TL.getSizeExpr();
5742 if (!origSize) origSize = T->getSizeExpr();
5743
5744 ExprResult sizeResult
5745 = getDerived().TransformExpr(origSize);
5746 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5747 if (sizeResult.isInvalid())
5748 return QualType();
5749
5750 Expr *size = sizeResult.get();
5751
5752 QualType Result = TL.getType();
5753 if (getDerived().AlwaysRebuild() ||
5754 ElementType != T->getElementType() ||
5755 size != origSize) {
5756 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5757 T->getSizeModifier(),
5758 size,
5759 T->getIndexTypeCVRQualifiers(),
5760 TL.getBracketsRange());
5761 if (Result.isNull())
5762 return QualType();
5763 }
5764
5765 // We might have any sort of array type now, but fortunately they
5766 // all have the same location layout.
5767 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5768 NewTL.setLBracketLoc(TL.getLBracketLoc());
5769 NewTL.setRBracketLoc(TL.getRBracketLoc());
5770 NewTL.setSizeExpr(size);
5771
5772 return Result;
5773}
5774
5775template <typename Derived>
5776QualType TreeTransform<Derived>::TransformDependentVectorType(
5777 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
5778 const DependentVectorType *T = TL.getTypePtr();
5779 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5780 if (ElementType.isNull())
5781 return QualType();
5782
5783 EnterExpressionEvaluationContext Unevaluated(
5785
5786 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5787 Size = SemaRef.ActOnConstantExpression(Size);
5788 if (Size.isInvalid())
5789 return QualType();
5790
5791 QualType Result = TL.getType();
5792 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5793 Size.get() != T->getSizeExpr()) {
5794 Result = getDerived().RebuildDependentVectorType(
5795 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5796 if (Result.isNull())
5797 return QualType();
5798 }
5799
5800 // Result might be dependent or not.
5801 if (isa<DependentVectorType>(Result)) {
5802 DependentVectorTypeLoc NewTL =
5803 TLB.push<DependentVectorTypeLoc>(Result);
5804 NewTL.setNameLoc(TL.getNameLoc());
5805 } else {
5806 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5807 NewTL.setNameLoc(TL.getNameLoc());
5808 }
5809
5810 return Result;
5811}
5812
5813template<typename Derived>
5814QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
5815 TypeLocBuilder &TLB,
5816 DependentSizedExtVectorTypeLoc TL) {
5817 const DependentSizedExtVectorType *T = TL.getTypePtr();
5818
5819 // FIXME: ext vector locs should be nested
5820 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5821 if (ElementType.isNull())
5822 return QualType();
5823
5824 // Vector sizes are constant expressions.
5825 EnterExpressionEvaluationContext Unevaluated(
5827
5828 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5829 Size = SemaRef.ActOnConstantExpression(Size);
5830 if (Size.isInvalid())
5831 return QualType();
5832
5833 QualType Result = TL.getType();
5834 if (getDerived().AlwaysRebuild() ||
5835 ElementType != T->getElementType() ||
5836 Size.get() != T->getSizeExpr()) {
5837 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5838 Size.get(),
5839 T->getAttributeLoc());
5840 if (Result.isNull())
5841 return QualType();
5842 }
5843
5844 // Result might be dependent or not.
5845 if (isa<DependentSizedExtVectorType>(Result)) {
5846 DependentSizedExtVectorTypeLoc NewTL
5847 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
5848 NewTL.setNameLoc(TL.getNameLoc());
5849 } else {
5850 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5851 NewTL.setNameLoc(TL.getNameLoc());
5852 }
5853
5854 return Result;
5855}
5856
5857template <typename Derived>
5858QualType
5859TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
5860 ConstantMatrixTypeLoc TL) {
5861 const ConstantMatrixType *T = TL.getTypePtr();
5862 QualType ElementType = getDerived().TransformType(T->getElementType());
5863 if (ElementType.isNull())
5864 return QualType();
5865
5866 QualType Result = TL.getType();
5867 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
5868 Result = getDerived().RebuildConstantMatrixType(
5869 ElementType, T->getNumRows(), T->getNumColumns());
5870 if (Result.isNull())
5871 return QualType();
5872 }
5873
5874 ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
5875 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5876 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5877 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
5878 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
5879
5880 return Result;
5881}
5882
5883template <typename Derived>
5884QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
5885 TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
5886 const DependentSizedMatrixType *T = TL.getTypePtr();
5887
5888 QualType ElementType = getDerived().TransformType(T->getElementType());
5889 if (ElementType.isNull()) {
5890 return QualType();
5891 }
5892
5893 // Matrix dimensions are constant expressions.
5894 EnterExpressionEvaluationContext Unevaluated(
5896
5897 Expr *origRows = TL.getAttrRowOperand();
5898 if (!origRows)
5899 origRows = T->getRowExpr();
5900 Expr *origColumns = TL.getAttrColumnOperand();
5901 if (!origColumns)
5902 origColumns = T->getColumnExpr();
5903
5904 ExprResult rowResult = getDerived().TransformExpr(origRows);
5905 rowResult = SemaRef.ActOnConstantExpression(rowResult);
5906 if (rowResult.isInvalid())
5907 return QualType();
5908
5909 ExprResult columnResult = getDerived().TransformExpr(origColumns);
5910 columnResult = SemaRef.ActOnConstantExpression(columnResult);
5911 if (columnResult.isInvalid())
5912 return QualType();
5913
5914 Expr *rows = rowResult.get();
5915 Expr *columns = columnResult.get();
5916
5917 QualType Result = TL.getType();
5918 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5919 rows != origRows || columns != origColumns) {
5920 Result = getDerived().RebuildDependentSizedMatrixType(
5921 ElementType, rows, columns, T->getAttributeLoc());
5922
5923 if (Result.isNull())
5924 return QualType();
5925 }
5926
5927 // We might have any sort of matrix type now, but fortunately they
5928 // all have the same location layout.
5929 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
5930 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5931 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5932 NewTL.setAttrRowOperand(rows);
5933 NewTL.setAttrColumnOperand(columns);
5934 return Result;
5935}
5936
5937template <typename Derived>
5938QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
5939 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
5940 const DependentAddressSpaceType *T = TL.getTypePtr();
5941
5942 QualType pointeeType =
5943 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
5944
5945 if (pointeeType.isNull())
5946 return QualType();
5947
5948 // Address spaces are constant expressions.
5949 EnterExpressionEvaluationContext Unevaluated(
5951
5952 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
5953 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
5954 if (AddrSpace.isInvalid())
5955 return QualType();
5956
5957 QualType Result = TL.getType();
5958 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
5959 AddrSpace.get() != T->getAddrSpaceExpr()) {
5960 Result = getDerived().RebuildDependentAddressSpaceType(
5961 pointeeType, AddrSpace.get(), T->getAttributeLoc());
5962 if (Result.isNull())
5963 return QualType();
5964 }
5965
5966 // Result might be dependent or not.
5967 if (isa<DependentAddressSpaceType>(Result)) {
5968 DependentAddressSpaceTypeLoc NewTL =
5969 TLB.push<DependentAddressSpaceTypeLoc>(Result);
5970
5971 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5972 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5973 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5974
5975 } else {
5976 TLB.TypeWasModifiedSafely(Result);
5977 }
5978
5979 return Result;
5980}
5981
5982template <typename Derived>
5983QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
5984 VectorTypeLoc TL) {
5985 const VectorType *T = TL.getTypePtr();
5986 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5987 if (ElementType.isNull())
5988 return QualType();
5989
5990 QualType Result = TL.getType();
5991 if (getDerived().AlwaysRebuild() ||
5992 ElementType != T->getElementType()) {
5993 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
5994 T->getVectorKind());
5995 if (Result.isNull())
5996 return QualType();
5997 }
5998
5999 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6000 NewTL.setNameLoc(TL.getNameLoc());
6001
6002 return Result;
6003}
6004
6005template<typename Derived>
6006QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
6007 ExtVectorTypeLoc TL) {
6008 const VectorType *T = TL.getTypePtr();
6009 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6010 if (ElementType.isNull())
6011 return QualType();
6012
6013 QualType Result = TL.getType();
6014 if (getDerived().AlwaysRebuild() ||
6015 ElementType != T->getElementType()) {
6016 Result = getDerived().RebuildExtVectorType(ElementType,
6017 T->getNumElements(),
6018 /*FIXME*/ SourceLocation());
6019 if (Result.isNull())
6020 return QualType();
6021 }
6022
6023 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6024 NewTL.setNameLoc(TL.getNameLoc());
6025
6026 return Result;
6027}
6028
6029template <typename Derived>
6031 ParmVarDecl *OldParm, int indexAdjustment,
6032 std::optional<unsigned> NumExpansions, bool ExpectParameterPack) {
6033 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
6034 TypeSourceInfo *NewDI = nullptr;
6035
6036 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
6037 // If we're substituting into a pack expansion type and we know the
6038 // length we want to expand to, just substitute for the pattern.
6039 TypeLoc OldTL = OldDI->getTypeLoc();
6040 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6041
6042 TypeLocBuilder TLB;
6043 TypeLoc NewTL = OldDI->getTypeLoc();
6044 TLB.reserve(NewTL.getFullDataSize());
6045
6046 QualType Result = getDerived().TransformType(TLB,
6047 OldExpansionTL.getPatternLoc());
6048 if (Result.isNull())
6049 return nullptr;
6050
6051 Result = RebuildPackExpansionType(Result,
6052 OldExpansionTL.getPatternLoc().getSourceRange(),
6053 OldExpansionTL.getEllipsisLoc(),
6054 NumExpansions);
6055 if (Result.isNull())
6056 return nullptr;
6057
6058 PackExpansionTypeLoc NewExpansionTL
6059 = TLB.push<PackExpansionTypeLoc>(Result);
6060 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6061 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6062 } else
6063 NewDI = getDerived().TransformType(OldDI);
6064 if (!NewDI)
6065 return nullptr;
6066
6067 if (NewDI == OldDI && indexAdjustment == 0)
6068 return OldParm;
6069
6070 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
6071 OldParm->getDeclContext(),
6072 OldParm->getInnerLocStart(),
6073 OldParm->getLocation(),
6074 OldParm->getIdentifier(),
6075 NewDI->getType(),
6076 NewDI,
6077 OldParm->getStorageClass(),
6078 /* DefArg */ nullptr);
6079 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6080 OldParm->getFunctionScopeIndex() + indexAdjustment);
6081 transformedLocalDecl(OldParm, {newParm});
6082 return newParm;
6083}
6084
6085template <typename Derived>
6088 const QualType *ParamTypes,
6089 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6090 SmallVectorImpl<QualType> &OutParamTypes,
6093 unsigned *LastParamTransformed) {
6094 int indexAdjustment = 0;
6095
6096 unsigned NumParams = Params.size();
6097 for (unsigned i = 0; i != NumParams; ++i) {
6098 if (LastParamTransformed)
6099 *LastParamTransformed = i;
6100 if (ParmVarDecl *OldParm = Params[i]) {
6101 assert(OldParm->getFunctionScopeIndex() == i);
6102
6103 std::optional<unsigned> NumExpansions;
6104 ParmVarDecl *NewParm = nullptr;
6105 if (OldParm->isParameterPack()) {
6106 // We have a function parameter pack that may need to be expanded.
6108
6109 // Find the parameter packs that could be expanded.
6110 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6112 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6113 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6114
6115 // Determine whether we should expand the parameter packs.
6116 bool ShouldExpand = false;
6117 bool RetainExpansion = false;
6118 std::optional<unsigned> OrigNumExpansions;
6119 if (Unexpanded.size() > 0) {
6120 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6121 NumExpansions = OrigNumExpansions;
6122 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
6123 Pattern.getSourceRange(),
6124 Unexpanded,
6125 ShouldExpand,
6126 RetainExpansion,
6127 NumExpansions)) {
6128 return true;
6129 }
6130 } else {
6131#ifndef NDEBUG
6132 const AutoType *AT =
6133 Pattern.getType().getTypePtr()->getContainedAutoType();
6134 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6135 "Could not find parameter packs or undeduced auto type!");
6136#endif
6137 }
6138
6139 if (ShouldExpand) {
6140 // Expand the function parameter pack into multiple, separate
6141 // parameters.
6142 getDerived().ExpandingFunctionParameterPack(OldParm);
6143 for (unsigned I = 0; I != *NumExpansions; ++I) {
6144 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6145 ParmVarDecl *NewParm
6146 = getDerived().TransformFunctionTypeParam(OldParm,
6147 indexAdjustment++,
6148 OrigNumExpansions,
6149 /*ExpectParameterPack=*/false);
6150 if (!NewParm)
6151 return true;
6152
6153 if (ParamInfos)
6154 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6155 OutParamTypes.push_back(NewParm->getType());
6156 if (PVars)
6157 PVars->push_back(NewParm);
6158 }
6159
6160 // If we're supposed to retain a pack expansion, do so by temporarily
6161 // forgetting the partially-substituted parameter pack.
6162 if (RetainExpansion) {
6163 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6164 ParmVarDecl *NewParm
6165 = getDerived().TransformFunctionTypeParam(OldParm,
6166 indexAdjustment++,
6167 OrigNumExpansions,
6168 /*ExpectParameterPack=*/false);
6169 if (!NewParm)
6170 return true;
6171
6172 if (ParamInfos)
6173 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6174 OutParamTypes.push_back(NewParm->getType());
6175 if (PVars)
6176 PVars->push_back(NewParm);
6177 }
6178
6179 // The next parameter should have the same adjustment as the
6180 // last thing we pushed, but we post-incremented indexAdjustment
6181 // on every push. Also, if we push nothing, the adjustment should
6182 // go down by one.
6183 indexAdjustment--;
6184
6185 // We're done with the pack expansion.
6186 continue;
6187 }
6188
6189 // We'll substitute the parameter now without expanding the pack
6190 // expansion.
6191 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6192 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6193 indexAdjustment,
6194 NumExpansions,
6195 /*ExpectParameterPack=*/true);
6196 assert(NewParm->isParameterPack() &&
6197 "Parameter pack no longer a parameter pack after "
6198 "transformation.");
6199 } else {
6200 NewParm = getDerived().TransformFunctionTypeParam(
6201 OldParm, indexAdjustment, std::nullopt,
6202 /*ExpectParameterPack=*/false);
6203 }
6204
6205 if (!NewParm)
6206 return true;
6207
6208 if (ParamInfos)
6209 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6210 OutParamTypes.push_back(NewParm->getType());
6211 if (PVars)
6212 PVars->push_back(NewParm);
6213 continue;
6214 }
6215
6216 // Deal with the possibility that we don't have a parameter
6217 // declaration for this parameter.
6218 assert(ParamTypes);
6219 QualType OldType = ParamTypes[i];
6220 bool IsPackExpansion = false;
6221 std::optional<unsigned> NumExpansions;
6222 QualType NewType;
6223 if (const PackExpansionType *Expansion
6224 = dyn_cast<PackExpansionType>(OldType)) {
6225 // We have a function parameter pack that may need to be expanded.
6226 QualType Pattern = Expansion->getPattern();
6228 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6229
6230 // Determine whether we should expand the parameter packs.
6231 bool ShouldExpand = false;
6232 bool RetainExpansion = false;
6233 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
6234 Unexpanded,
6235 ShouldExpand,
6236 RetainExpansion,
6237 NumExpansions)) {
6238 return true;
6239 }
6240
6241 if (ShouldExpand) {
6242 // Expand the function parameter pack into multiple, separate
6243 // parameters.
6244 for (unsigned I = 0; I != *NumExpansions; ++I) {
6245 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6246 QualType NewType = getDerived().TransformType(Pattern);
6247 if (NewType.isNull())
6248 return true;
6249
6250 if (NewType->containsUnexpandedParameterPack()) {
6251 NewType = getSema().getASTContext().getPackExpansionType(
6252 NewType, std::nullopt);
6253
6254 if (NewType.isNull())
6255 return true;
6256 }
6257
6258 if (ParamInfos)
6259 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6260 OutParamTypes.push_back(NewType);
6261 if (PVars)
6262 PVars->push_back(nullptr);
6263 }
6264
6265 // We're done with the pack expansion.
6266 continue;
6267 }
6268
6269 // If we're supposed to retain a pack expansion, do so by temporarily
6270 // forgetting the partially-substituted parameter pack.
6271 if (RetainExpansion) {
6272 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6273 QualType NewType = getDerived().TransformType(Pattern);
6274 if (NewType.isNull())
6275 return true;
6276
6277 if (ParamInfos)
6278 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6279 OutParamTypes.push_back(NewType);
6280 if (PVars)
6281 PVars->push_back(nullptr);
6282 }
6283
6284 // We'll substitute the parameter now without expanding the pack
6285 // expansion.
6286 OldType = Expansion->getPattern();
6287 IsPackExpansion = true;
6288 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6289 NewType = getDerived().TransformType(OldType);
6290 } else {
6291 NewType = getDerived().TransformType(OldType);
6292 }
6293
6294 if (NewType.isNull())
6295 return true;
6296
6297 if (IsPackExpansion)
6298 NewType = getSema().Context.getPackExpansionType(NewType,
6299 NumExpansions);
6300
6301 if (ParamInfos)
6302 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6303 OutParamTypes.push_back(NewType);
6304 if (PVars)
6305 PVars->push_back(nullptr);
6306 }
6307
6308#ifndef NDEBUG
6309 if (PVars) {
6310 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6311 if (ParmVarDecl *parm = (*PVars)[i])
6312 assert(parm->getFunctionScopeIndex() == i);
6313 }
6314#endif
6315
6316 return false;
6317}
6318
6319template<typename Derived>
6323 SmallVector<QualType, 4> ExceptionStorage;
6324 return getDerived().TransformFunctionProtoType(
6325 TLB, TL, nullptr, Qualifiers(),
6326 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6327 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6328 ExceptionStorage, Changed);
6329 });
6330}
6331
6332template<typename Derived> template<typename Fn>
6334 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6335 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6336
6337 // Transform the parameters and return type.
6338 //
6339 // We are required to instantiate the params and return type in source order.
6340 // When the function has a trailing return type, we instantiate the
6341 // parameters before the return type, since the return type can then refer
6342 // to the parameters themselves (via decltype, sizeof, etc.).
6343 //
6344 SmallVector<QualType, 4> ParamTypes;
6346 Sema::ExtParameterInfoBuilder ExtParamInfos;
6347 const FunctionProtoType *T = TL.getTypePtr();
6348
6349 QualType ResultType;
6350
6351 if (T->hasTrailingReturn()) {
6352 if (getDerived().TransformFunctionTypeParams(
6353 TL.getBeginLoc(), TL.getParams(),
6356 ParamTypes, &ParamDecls, ExtParamInfos))
6357 return QualType();
6358
6359 {
6360 // C++11 [expr.prim.general]p3:
6361 // If a declaration declares a member function or member function
6362 // template of a class X, the expression this is a prvalue of type
6363 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6364 // and the end of the function-definition, member-declarator, or
6365 // declarator.
6366 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6367 Sema::CXXThisScopeRAII ThisScope(
6368 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6369
6370 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6371 if (ResultType.isNull())
6372 return QualType();
6373 }
6374 }
6375 else {
6376 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6377 if (ResultType.isNull())
6378 return QualType();
6379
6380 if (getDerived().TransformFunctionTypeParams(
6381 TL.getBeginLoc(), TL.getParams(),
6384 ParamTypes, &ParamDecls, ExtParamInfos))
6385 return QualType();
6386 }
6387
6389
6390 bool EPIChanged = false;
6391 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6392 return QualType();
6393
6394 // Handle extended parameter information.
6395 if (auto NewExtParamInfos =
6396 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6397 if (!EPI.ExtParameterInfos ||
6399 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6400 EPIChanged = true;
6401 }
6402 EPI.ExtParameterInfos = NewExtParamInfos;
6403 } else if (EPI.ExtParameterInfos) {
6404 EPIChanged = true;
6405 EPI.ExtParameterInfos = nullptr;
6406 }
6407
6408 // Transform any function effects with unevaluated conditions.
6409 // Hold this set in a local for the rest of this function, since EPI
6410 // may need to hold a FunctionEffectsRef pointing into it.
6411 std::optional<FunctionEffectSet> NewFX;
6412 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6413 NewFX.emplace();
6416
6417 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6418 FunctionEffectWithCondition NewEC = PrevEC;
6419 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6420 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6421 if (NewExpr.isInvalid())
6422 return QualType();
6423 std::optional<FunctionEffectMode> Mode =
6424 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6425 if (!Mode)
6426 return QualType();
6427
6428 // The condition expression has been transformed, and re-evaluated.
6429 // It may or may not have become constant.
6430 switch (*Mode) {
6432 NewEC.Cond = {};
6433 break;
6435 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6436 NewEC.Cond = {};
6437 break;
6439 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6440 break;
6442 llvm_unreachable(
6443 "FunctionEffectMode::None shouldn't be possible here");
6444 }
6445 }
6446 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6447 TL.getBeginLoc())) {
6449 NewFX->insert(NewEC, Errs);
6450 assert(Errs.empty());
6451 }
6452 }
6453 EPI.FunctionEffects = *NewFX;
6454 EPIChanged = true;
6455 }
6456
6457 QualType Result = TL.getType();
6458 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6459 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6460 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6461 if (Result.isNull())
6462 return QualType();
6463 }
6464
6467 NewTL.setLParenLoc(TL.getLParenLoc());
6468 NewTL.setRParenLoc(TL.getRParenLoc());
6471 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6472 NewTL.setParam(i, ParamDecls[i]);
6473
6474 return Result;
6475}
6476
6477template<typename Derived>
6480 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6481 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6482
6483 // Instantiate a dynamic noexcept expression, if any.
6484 if (isComputedNoexcept(ESI.Type)) {
6485 // Update this scrope because ContextDecl in Sema will be used in
6486 // TransformExpr.
6487 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6488 Sema::CXXThisScopeRAII ThisScope(
6489 SemaRef, Method ? Method->getParent() : nullptr,
6490 Method ? Method->getMethodQualifiers() : Qualifiers{},
6491 Method != nullptr);
6494 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6495 if (NoexceptExpr.isInvalid())
6496 return true;
6497
6499 NoexceptExpr =
6500 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6501 if (NoexceptExpr.isInvalid())
6502 return true;
6503
6504 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6505 Changed = true;
6506 ESI.NoexceptExpr = NoexceptExpr.get();
6507 ESI.Type = EST;
6508 }
6509
6510 if (ESI.Type != EST_Dynamic)
6511 return false;
6512
6513 // Instantiate a dynamic exception specification's type.
6514 for (QualType T : ESI.Exceptions) {
6515 if (const PackExpansionType *PackExpansion =
6517 Changed = true;
6518
6519 // We have a pack expansion. Instantiate it.
6521 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6522 Unexpanded);
6523 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6524
6525 // Determine whether the set of unexpanded parameter packs can and
6526 // should
6527 // be expanded.
6528 bool Expand = false;
6529 bool RetainExpansion = false;
6530 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6531 // FIXME: Track the location of the ellipsis (and track source location
6532 // information for the types in the exception specification in general).
6533 if (getDerived().TryExpandParameterPacks(
6534 Loc, SourceRange(), Unexpanded, Expand,
6535 RetainExpansion, NumExpansions))
6536 return true;
6537
6538 if (!Expand) {
6539 // We can't expand this pack expansion into separate arguments yet;
6540 // just substitute into the pattern and create a new pack expansion
6541 // type.
6542 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6543 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6544 if (U.isNull())
6545 return true;
6546
6547 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6548 Exceptions.push_back(U);
6549 continue;
6550 }
6551
6552 // Substitute into the pack expansion pattern for each slice of the
6553 // pack.
6554 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6555 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6556
6557 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6558 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6559 return true;
6560
6561 Exceptions.push_back(U);
6562 }
6563 } else {
6564 QualType U = getDerived().TransformType(T);
6565 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6566 return true;
6567 if (T != U)
6568 Changed = true;
6569
6570 Exceptions.push_back(U);
6571 }
6572 }
6573
6574 ESI.Exceptions = Exceptions;
6575 if (ESI.Exceptions.empty())
6576 ESI.Type = EST_DynamicNone;
6577 return false;
6578}
6579
6580template<typename Derived>
6582 TypeLocBuilder &TLB,
6584 const FunctionNoProtoType *T = TL.getTypePtr();
6585 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6586 if (ResultType.isNull())
6587 return QualType();
6588
6589 QualType Result = TL.getType();
6590 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6591 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6592
6595 NewTL.setLParenLoc(TL.getLParenLoc());
6596 NewTL.setRParenLoc(TL.getRParenLoc());
6598
6599 return Result;
6600}
6601
6602template <typename Derived>
6603QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6604 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6605 const UnresolvedUsingType *T = TL.getTypePtr();
6606 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6607 if (!D)
6608 return QualType();
6609
6610 QualType Result = TL.getType();
6611 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
6612 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
6613 if (Result.isNull())
6614 return QualType();
6615 }
6616
6617 // We might get an arbitrary type spec type back. We should at
6618 // least always get a type spec type, though.
6619 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
6620 NewTL.setNameLoc(TL.getNameLoc());
6621
6622 return Result;
6623}
6624
6625template <typename Derived>
6626QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
6627 UsingTypeLoc TL) {
6628 const UsingType *T = TL.getTypePtr();
6629
6630 auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl(
6631 TL.getLocalSourceRange().getBegin(), T->getFoundDecl()));
6632 if (!Found)
6633 return QualType();
6634
6635 QualType Underlying = getDerived().TransformType(T->desugar());
6636 if (Underlying.isNull())
6637 return QualType();
6638
6639 QualType Result = TL.getType();
6640 if (getDerived().AlwaysRebuild() || Found != T->getFoundDecl() ||
6641 Underlying != T->getUnderlyingType()) {
6642 Result = getDerived().RebuildUsingType(Found, Underlying);
6643 if (Result.isNull())
6644 return QualType();
6645 }
6646
6647 TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc());
6648 return Result;
6649}
6650
6651template<typename Derived>
6652QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
6653 TypedefTypeLoc TL) {
6654 const TypedefType *T = TL.getTypePtr();
6655 TypedefNameDecl *Typedef
6656 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6657 T->getDecl()));
6658 if (!Typedef)
6659 return QualType();
6660
6661 QualType Result = TL.getType();
6662 if (getDerived().AlwaysRebuild() ||
6663 Typedef != T->getDecl()) {
6664 Result = getDerived().RebuildTypedefType(Typedef);
6665 if (Result.isNull())
6666 return QualType();
6667 }
6668
6669 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
6670 NewTL.setNameLoc(TL.getNameLoc());
6671
6672 return Result;
6673}
6674
6675template<typename Derived>
6676QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
6677 TypeOfExprTypeLoc TL) {
6678 // typeof expressions are not potentially evaluated contexts
6679 EnterExpressionEvaluationContext Unevaluated(
6682
6683 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6684 if (E.isInvalid())
6685 return QualType();
6686
6687 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6688 if (E.isInvalid())
6689 return QualType();
6690
6691 QualType Result = TL.getType();
6692 TypeOfKind Kind = Result->castAs<TypeOfExprType>()->getKind();
6693 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6694 Result =
6695 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6696 if (Result.isNull())
6697 return QualType();
6698 }
6699
6700 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6701 NewTL.setTypeofLoc(TL.getTypeofLoc());
6702 NewTL.setLParenLoc(TL.getLParenLoc());
6703 NewTL.setRParenLoc(TL.getRParenLoc());
6704
6705 return Result;
6706}
6707
6708template<typename Derived>
6709QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
6710 TypeOfTypeLoc TL) {
6711 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6712 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6713 if (!New_Under_TI)
6714 return QualType();
6715
6716 QualType Result = TL.getType();
6717 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6718 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6719 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6720 if (Result.isNull())
6721 return QualType();
6722 }
6723
6724 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6725 NewTL.setTypeofLoc(TL.getTypeofLoc());
6726 NewTL.setLParenLoc(TL.getLParenLoc());
6727 NewTL.setRParenLoc(TL.getRParenLoc());
6728 NewTL.setUnmodifiedTInfo(New_Under_TI);
6729
6730 return Result;
6731}
6732
6733template<typename Derived>
6734QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
6735 DecltypeTypeLoc TL) {
6736 const DecltypeType *T = TL.getTypePtr();
6737
6738 // decltype expressions are not potentially evaluated contexts
6739 EnterExpressionEvaluationContext Unevaluated(
6742
6743 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6744 if (E.isInvalid())
6745 return QualType();
6746
6747 E = getSema().ActOnDecltypeExpression(E.get());
6748 if (E.isInvalid())
6749 return QualType();
6750
6751 QualType Result = TL.getType();
6752 if (getDerived().AlwaysRebuild() ||
6753 E.get() != T->getUnderlyingExpr()) {
6754 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6755 if (Result.isNull())
6756 return QualType();
6757 }
6758 else E.get();
6759
6760 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6761 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6762 NewTL.setRParenLoc(TL.getRParenLoc());
6763 return Result;
6764}
6765
6766template <typename Derived>
6767QualType
6768TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
6769 PackIndexingTypeLoc TL) {
6770 // Transform the index
6771 ExprResult IndexExpr;
6772 {
6773 EnterExpressionEvaluationContext ConstantContext(
6775
6776 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6777 if (IndexExpr.isInvalid())
6778 return QualType();
6779 }
6780 QualType Pattern = TL.getPattern();
6781
6782 const PackIndexingType *PIT = TL.getTypePtr();
6783 SmallVector<QualType, 5> SubtitutedTypes;
6784 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6785
6786 bool NotYetExpanded = Types.empty();
6787 bool FullySubstituted = true;
6788
6789 if (Types.empty() && !PIT->expandsToEmptyPack())
6790 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
6791
6792 for (QualType T : Types) {
6794 QualType Transformed = getDerived().TransformType(T);
6795 if (Transformed.isNull())
6796 return QualType();
6797 SubtitutedTypes.push_back(Transformed);
6798 continue;
6799 }
6800
6802 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
6803 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6804 // Determine whether the set of unexpanded parameter packs can and should
6805 // be expanded.
6806 bool ShouldExpand = true;
6807 bool RetainExpansion = false;
6808 std::optional<unsigned> OrigNumExpansions;
6809 std::optional<unsigned> NumExpansions = OrigNumExpansions;
6810 if (getDerived().TryExpandParameterPacks(TL.getEllipsisLoc(), SourceRange(),
6811 Unexpanded, ShouldExpand,
6812 RetainExpansion, NumExpansions))
6813 return QualType();
6814 if (!ShouldExpand) {
6815 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6816 // FIXME: should we keep TypeLoc for individual expansions in
6817 // PackIndexingTypeLoc?
6818 TypeSourceInfo *TI =
6819 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
6820 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
6821 if (Pack.isNull())
6822 return QualType();
6823 if (NotYetExpanded) {
6824 FullySubstituted = false;
6825 QualType Out = getDerived().RebuildPackIndexingType(
6826 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6827 FullySubstituted);
6828 if (Out.isNull())
6829 return QualType();
6830
6831 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6832 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6833 return Out;
6834 }
6835 SubtitutedTypes.push_back(Pack);
6836 continue;
6837 }
6838 for (unsigned I = 0; I != *NumExpansions; ++I) {
6839 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6840 QualType Out = getDerived().TransformType(T);
6841 if (Out.isNull())
6842 return QualType();
6843 SubtitutedTypes.push_back(Out);
6844 FullySubstituted &= !Out->containsUnexpandedParameterPack();
6845 }
6846 // If we're supposed to retain a pack expansion, do so by temporarily
6847 // forgetting the partially-substituted parameter pack.
6848 if (RetainExpansion) {
6849 FullySubstituted = false;
6850 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6851 QualType Out = getDerived().TransformType(T);
6852 if (Out.isNull())
6853 return QualType();
6854 SubtitutedTypes.push_back(Out);
6855 }
6856 }
6857
6858 // A pack indexing type can appear in a larger pack expansion,
6859 // e.g. `Pack...[pack_of_indexes]...`
6860 // so we need to temporarily disable substitution of pack elements
6861 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6862 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
6863
6864 QualType Out = getDerived().RebuildPackIndexingType(
6865 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6866 FullySubstituted, SubtitutedTypes);
6867 if (Out.isNull())
6868 return Out;
6869
6870 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6871 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6872 return Out;
6873}
6874
6875template<typename Derived>
6876QualType TreeTransform<Derived>::TransformUnaryTransformType(
6877 TypeLocBuilder &TLB,
6878 UnaryTransformTypeLoc TL) {
6879 QualType Result = TL.getType();
6880 if (Result->isDependentType()) {
6881 const UnaryTransformType *T = TL.getTypePtr();
6882
6883 TypeSourceInfo *NewBaseTSI =
6884 getDerived().TransformType(TL.getUnderlyingTInfo());
6885 if (!NewBaseTSI)
6886 return QualType();
6887 QualType NewBase = NewBaseTSI->getType();
6888
6889 Result = getDerived().RebuildUnaryTransformType(NewBase,
6890 T->getUTTKind(),
6891 TL.getKWLoc());
6892 if (Result.isNull())
6893 return QualType();
6894 }
6895
6896 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
6897 NewTL.setKWLoc(TL.getKWLoc());
6898 NewTL.setParensRange(TL.getParensRange());
6899 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
6900 return Result;
6901}
6902
6903template<typename Derived>
6904QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
6905 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
6906 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
6907
6908 CXXScopeSpec SS;
6909 TemplateName TemplateName = getDerived().TransformTemplateName(
6910 SS, T->getTemplateName(), TL.getTemplateNameLoc());
6911 if (TemplateName.isNull())
6912 return QualType();
6913
6914 QualType OldDeduced = T->getDeducedType();
6915 QualType NewDeduced;
6916 if (!OldDeduced.isNull()) {
6917 NewDeduced = getDerived().TransformType(OldDeduced);
6918 if (NewDeduced.isNull())
6919 return QualType();
6920 }
6921
6922 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
6923 TemplateName, NewDeduced);
6924 if (Result.isNull())
6925 return QualType();
6926
6927 DeducedTemplateSpecializationTypeLoc NewTL =
6928 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
6929 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6930
6931 return Result;
6932}
6933
6934template<typename Derived>
6935QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
6936 RecordTypeLoc TL) {
6937 const RecordType *T = TL.getTypePtr();
6938 RecordDecl *Record
6939 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6940 T->getDecl()));
6941 if (!Record)
6942 return QualType();
6943
6944 QualType Result = TL.getType();
6945 if (getDerived().AlwaysRebuild() ||
6946 Record != T->getDecl()) {
6947 Result = getDerived().RebuildRecordType(Record);
6948 if (Result.isNull())
6949 return QualType();
6950 }
6951
6952 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
6953 NewTL.setNameLoc(TL.getNameLoc());
6954
6955 return Result;
6956}
6957
6958template<typename Derived>
6959QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
6960 EnumTypeLoc TL) {
6961 const EnumType *T = TL.getTypePtr();
6962 EnumDecl *Enum
6963 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6964 T->getDecl()));
6965 if (!Enum)
6966 return QualType();
6967
6968 QualType Result = TL.getType();
6969 if (getDerived().AlwaysRebuild() ||
6970 Enum != T->getDecl()) {
6971 Result = getDerived().RebuildEnumType(Enum);
6972 if (Result.isNull())
6973 return QualType();
6974 }
6975
6976 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
6977 NewTL.setNameLoc(TL.getNameLoc());
6978
6979 return Result;
6980}
6981
6982template<typename Derived>
6983QualType TreeTransform<Derived>::TransformInjectedClassNameType(
6984 TypeLocBuilder &TLB,
6985 InjectedClassNameTypeLoc TL) {
6986 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
6987 TL.getTypePtr()->getDecl());
6988 if (!D) return QualType();
6989
6990 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
6991 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
6992 return T;
6993}
6994
6995template<typename Derived>
6997 TypeLocBuilder &TLB,
6999 return getDerived().TransformTemplateTypeParmType(
7000 TLB, TL,
7001 /*SuppressObjCLifetime=*/false);
7002}
7003
7004template <typename Derived>
7006 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7007 return TransformTypeSpecType(TLB, TL);
7008}
7009
7010template<typename Derived>
7011QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7012 TypeLocBuilder &TLB,
7013 SubstTemplateTypeParmTypeLoc TL) {
7014 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7015
7016 Decl *NewReplaced =
7017 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7018
7019 // Substitute into the replacement type, which itself might involve something
7020 // that needs to be transformed. This only tends to occur with default
7021 // template arguments of template template parameters.
7022 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7023 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7024 if (Replacement.isNull())
7025 return QualType();
7026
7027 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7028 Replacement, NewReplaced, T->getIndex(), T->getPackIndex());
7029
7030 // Propagate type-source information.
7031 SubstTemplateTypeParmTypeLoc NewTL
7032 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7033 NewTL.setNameLoc(TL.getNameLoc());
7034 return Result;
7035
7036}
7037
7038template<typename Derived>
7040 TypeLocBuilder &TLB,
7042 return getDerived().TransformSubstTemplateTypeParmPackType(
7043 TLB, TL, /*SuppressObjCLifetime=*/false);
7044}
7045
7046template <typename Derived>
7049 return TransformTypeSpecType(TLB, TL);
7050}
7051
7052template<typename Derived>
7054 TypeLocBuilder &TLB,
7057
7058 // The nested-name-specifier never matters in a TemplateSpecializationType,
7059 // because we can't have a dependent nested-name-specifier anyway.
7060 CXXScopeSpec SS;
7061 TemplateName Template
7062 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
7063 TL.getTemplateNameLoc());
7064 if (Template.isNull())
7065 return QualType();
7066
7067 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
7068}
7069
7070template<typename Derived>
7072 AtomicTypeLoc TL) {
7073 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7074 if (ValueType.isNull())
7075 return QualType();
7076
7077 QualType Result = TL.getType();
7078 if (getDerived().AlwaysRebuild() ||
7079 ValueType != TL.getValueLoc().getType()) {
7080 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7081 if (Result.isNull())
7082 return QualType();
7083 }
7084
7085 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7086 NewTL.setKWLoc(TL.getKWLoc());
7087 NewTL.setLParenLoc(TL.getLParenLoc());
7088 NewTL.setRParenLoc(TL.getRParenLoc());
7089
7090 return Result;
7091}
7092
7093template <typename Derived>
7094QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
7095 PipeTypeLoc TL) {
7096 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7097 if (ValueType.isNull())
7098 return QualType();
7099
7100 QualType Result = TL.getType();
7101 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7102 const PipeType *PT = Result->castAs<PipeType>();
7103 bool isReadPipe = PT->isReadOnly();
7104 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7105 if (Result.isNull())
7106 return QualType();
7107 }
7108
7109 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7110 NewTL.setKWLoc(TL.getKWLoc());
7111
7112 return Result;
7113}
7114
7115template <typename Derived>
7116QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
7117 BitIntTypeLoc TL) {
7118 const BitIntType *EIT = TL.getTypePtr();
7119 QualType Result = TL.getType();
7120
7121 if (getDerived().AlwaysRebuild()) {
7122 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7123 EIT->getNumBits(), TL.getNameLoc());
7124 if (Result.isNull())
7125 return QualType();
7126 }
7127
7128 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7129 NewTL.setNameLoc(TL.getNameLoc());
7130 return Result;
7131}
7132
7133template <typename Derived>
7134QualType TreeTransform<Derived>::TransformDependentBitIntType(
7135 TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) {
7136 const DependentBitIntType *EIT = TL.getTypePtr();
7137
7138 EnterExpressionEvaluationContext Unevaluated(
7140 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7141 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7142
7143 if (BitsExpr.isInvalid())
7144 return QualType();
7145
7146 QualType Result = TL.getType();
7147
7148 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7149 Result = getDerived().RebuildDependentBitIntType(
7150 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7151
7152 if (Result.isNull())
7153 return QualType();
7154 }
7155
7156 if (isa<DependentBitIntType>(Result)) {
7157 DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
7158 NewTL.setNameLoc(TL.getNameLoc());
7159 } else {
7160 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7161 NewTL.setNameLoc(TL.getNameLoc());
7162 }
7163 return Result;
7164}
7165
7166 /// Simple iterator that traverses the template arguments in a
7167 /// container that provides a \c getArgLoc() member function.
7168 ///
7169 /// This iterator is intended to be used with the iterator form of
7170 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7171 template<typename ArgLocContainer>
7173 ArgLocContainer *Container;
7174 unsigned Index;
7175
7176 public:
7179 typedef int difference_type;
7180 typedef std::input_iterator_tag iterator_category;
7181
7182 class pointer {
7184
7185 public:
7186 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7187
7189 return &Arg;
7190 }
7191 };
7192
7193
7195
7196 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7197 unsigned Index)
7198 : Container(&Container), Index(Index) { }
7199
7201 ++Index;
7202 return *this;
7203 }
7204
7207 ++(*this);
7208 return Old;
7209 }
7210
7212 return Container->getArgLoc(Index);
7213 }
7214
7216 return pointer(Container->getArgLoc(Index));
7217 }
7218
7221 return X.Container == Y.Container && X.Index == Y.Index;
7222 }
7223
7226 return !(X == Y);
7227 }
7228 };
7229
7230template<typename Derived>
7231QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7232 AutoTypeLoc TL) {
7233 const AutoType *T = TL.getTypePtr();
7234 QualType OldDeduced = T->getDeducedType();
7235 QualType NewDeduced;
7236 if (!OldDeduced.isNull()) {
7237 NewDeduced = getDerived().TransformType(OldDeduced);
7238 if (NewDeduced.isNull())
7239 return QualType();
7240 }
7241
7242 ConceptDecl *NewCD = nullptr;
7243 TemplateArgumentListInfo NewTemplateArgs;
7244 NestedNameSpecifierLoc NewNestedNameSpec;
7245 if (T->isConstrained()) {
7246 assert(TL.getConceptReference());
7247 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7248 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7249
7250 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7251 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7252 typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator;
7253 if (getDerived().TransformTemplateArguments(
7254 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7255 NewTemplateArgs))
7256 return QualType();
7257
7258 if (TL.getNestedNameSpecifierLoc()) {
7259 NewNestedNameSpec
7260 = getDerived().TransformNestedNameSpecifierLoc(
7261 TL.getNestedNameSpecifierLoc());
7262 if (!NewNestedNameSpec)
7263 return QualType();
7264 }
7265 }
7266
7267 QualType Result = TL.getType();
7268 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7269 T->isDependentType() || T->isConstrained()) {
7270 // FIXME: Maybe don't rebuild if all template arguments are the same.
7272 NewArgList.reserve(NewTemplateArgs.size());
7273 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7274 NewArgList.push_back(ArgLoc.getArgument());
7275 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7276 NewArgList);
7277 if (Result.isNull())
7278 return QualType();
7279 }
7280
7281 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7282 NewTL.setNameLoc(TL.getNameLoc());
7283 NewTL.setRParenLoc(TL.getRParenLoc());
7284 NewTL.setConceptReference(nullptr);
7285
7286 if (T->isConstrained()) {
7287 DeclarationNameInfo DNI = DeclarationNameInfo(
7288 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7289 TL.getConceptNameLoc(),
7290 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7291 auto *CR = ConceptReference::Create(
7292 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7293 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7294 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7295 NewTL.setConceptReference(CR);
7296 }
7297
7298 return Result;
7299}
7300
7301template <typename Derived>
7303 TypeLocBuilder &TLB,
7304 TemplateSpecializationTypeLoc TL,
7305 TemplateName Template) {
7306 TemplateArgumentListInfo NewTemplateArgs;
7307 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7308 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7309 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
7310 ArgIterator;
7311 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7312 ArgIterator(TL, TL.getNumArgs()),
7313 NewTemplateArgs))
7314 return QualType();
7315
7316 // FIXME: maybe don't rebuild if all the template arguments are the same.
7317
7318 QualType Result =
7319 getDerived().RebuildTemplateSpecializationType(Template,
7320 TL.getTemplateNameLoc(),
7321 NewTemplateArgs);
7322
7323 if (!Result.isNull()) {
7324 // Specializations of template template parameters are represented as
7325 // TemplateSpecializationTypes, and substitution of type alias templates
7326 // within a dependent context can transform them into
7327 // DependentTemplateSpecializationTypes.
7328 if (isa<DependentTemplateSpecializationType>(Result)) {
7329 DependentTemplateSpecializationTypeLoc NewTL
7330 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
7331 NewTL.setElaboratedKeywordLoc(SourceLocation());
7332 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
7333 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7334 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7335 NewTL.setLAngleLoc(TL.getLAngleLoc());
7336 NewTL.setRAngleLoc(TL.getRAngleLoc());
7337 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7338 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7339 return Result;
7340 }
7341
7342 TemplateSpecializationTypeLoc NewTL
7343 = TLB.push<TemplateSpecializationTypeLoc>(Result);
7344 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7345 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7346 NewTL.setLAngleLoc(TL.getLAngleLoc());
7347 NewTL.setRAngleLoc(TL.getRAngleLoc());
7348 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7349 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7350 }
7351
7352 return Result;
7353}
7354
7355template <typename Derived>
7357 TypeLocBuilder &TLB,
7359 TemplateName Template,
7360 CXXScopeSpec &SS) {
7361 TemplateArgumentListInfo NewTemplateArgs;
7362 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7363 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7366 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7367 ArgIterator(TL, TL.getNumArgs()),
7368 NewTemplateArgs))
7369 return QualType();
7370
7371 // FIXME: maybe don't rebuild if all the template arguments are the same.
7372
7373 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
7374 QualType Result = getSema().Context.getDependentTemplateSpecializationType(
7375 TL.getTypePtr()->getKeyword(), DTN->getQualifier(),
7376 DTN->getIdentifier(), NewTemplateArgs.arguments());
7377
7381 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
7384 NewTL.setLAngleLoc(TL.getLAngleLoc());
7385 NewTL.setRAngleLoc(TL.getRAngleLoc());
7386 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7387 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7388 return Result;
7389 }
7390
7392 = getDerived().RebuildTemplateSpecializationType(Template,
7393 TL.getTemplateNameLoc(),
7394 NewTemplateArgs);
7395
7396 if (!Result.isNull()) {
7397 /// FIXME: Wrap this in an elaborated-type-specifier?
7402 NewTL.setLAngleLoc(TL.getLAngleLoc());
7403 NewTL.setRAngleLoc(TL.getRAngleLoc());
7404 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7405 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7406 }
7407
7408 return Result;
7409}
7410
7411template<typename Derived>
7414 ElaboratedTypeLoc TL) {
7415 const ElaboratedType *T = TL.getTypePtr();
7416
7417 NestedNameSpecifierLoc QualifierLoc;
7418 // NOTE: the qualifier in an ElaboratedType is optional.
7419 if (TL.getQualifierLoc()) {
7420 QualifierLoc
7421 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7422 if (!QualifierLoc)
7423 return QualType();
7424 }
7425
7426 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
7427 if (NamedT.isNull())
7428 return QualType();
7429
7430 // C++0x [dcl.type.elab]p2:
7431 // If the identifier resolves to a typedef-name or the simple-template-id
7432 // resolves to an alias template specialization, the
7433 // elaborated-type-specifier is ill-formed.
7434 if (T->getKeyword() != ElaboratedTypeKeyword::None &&
7435 T->getKeyword() != ElaboratedTypeKeyword::Typename) {
7436 if (const TemplateSpecializationType *TST =
7437 NamedT->getAs<TemplateSpecializationType>()) {
7438 TemplateName Template = TST->getTemplateName();
7439 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
7440 Template.getAsTemplateDecl())) {
7441 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
7442 diag::err_tag_reference_non_tag)
7444 << llvm::to_underlying(
7446 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
7447 }
7448 }
7449 }
7450
7451 QualType Result = TL.getType();
7452 if (getDerived().AlwaysRebuild() ||
7453 QualifierLoc != TL.getQualifierLoc() ||
7454 NamedT != T->getNamedType()) {
7455 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
7456 T->getKeyword(),
7457 QualifierLoc, NamedT);
7458 if (Result.isNull())
7459 return QualType();
7460 }
7461
7462 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7463 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7464 NewTL.setQualifierLoc(QualifierLoc);
7465 return Result;
7466}
7467
7468template <typename Derived>
7469QualType TreeTransform<Derived>::TransformAttributedType(TypeLocBuilder &TLB,
7470 AttributedTypeLoc TL) {
7471 const AttributedType *oldType = TL.getTypePtr();
7472 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7473 if (modifiedType.isNull())
7474 return QualType();
7475
7476 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7477 const Attr *oldAttr = TL.getAttr();
7478 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7479 if (oldAttr && !newAttr)
7480 return QualType();
7481
7482 QualType result = TL.getType();
7483
7484 // FIXME: dependent operand expressions?
7485 if (getDerived().AlwaysRebuild() ||
7486 modifiedType != oldType->getModifiedType()) {
7487 // If the equivalent type is equal to the modified type, we don't want to
7488 // transform it as well because:
7489 //
7490 // 1. The transformation would yield the same result and is therefore
7491 // superfluous, and
7492 //
7493 // 2. Transforming the same type twice can cause problems, e.g. if it
7494 // is a FunctionProtoType, we may end up instantiating the function
7495 // parameters twice, which causes an assertion since the parameters
7496 // are already bound to their counterparts in the template for this
7497 // instantiation.
7498 //
7499 QualType equivalentType = modifiedType;
7500 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7501 TypeLocBuilder AuxiliaryTLB;
7502 AuxiliaryTLB.reserve(TL.getFullDataSize());
7503 equivalentType =
7504 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7505 if (equivalentType.isNull())
7506 return QualType();
7507 }
7508
7509 // Check whether we can add nullability; it is only represented as
7510 // type sugar, and therefore cannot be diagnosed in any other way.
7511 if (auto nullability = oldType->getImmediateNullability()) {
7512 if (!modifiedType->canHaveNullability()) {
7513 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7514 : TL.getModifiedLoc().getBeginLoc()),
7515 diag::err_nullability_nonpointer)
7516 << DiagNullabilityKind(*nullability, false) << modifiedType;
7517 return QualType();
7518 }
7519 }
7520
7521 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7522 modifiedType,
7523 equivalentType,
7524 TL.getAttr());
7525 }
7526
7527 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7528 newTL.setAttr(newAttr);
7529 return result;
7530}
7531
7532template <typename Derived>
7533QualType TreeTransform<Derived>::TransformCountAttributedType(
7534 TypeLocBuilder &TLB, CountAttributedTypeLoc TL) {
7535 const CountAttributedType *OldTy = TL.getTypePtr();
7536 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7537 if (InnerTy.isNull())
7538 return QualType();
7539
7540 Expr *OldCount = TL.getCountExpr();
7541 Expr *NewCount = nullptr;
7542 if (OldCount) {
7543 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7544 if (CountResult.isInvalid())
7545 return QualType();
7546 NewCount = CountResult.get();
7547 }
7548
7549 QualType Result = TL.getType();
7550 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7551 OldCount != NewCount) {
7552 // Currently, CountAttributedType can only wrap incomplete array types.
7554 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7555 }
7556
7557 TLB.push<CountAttributedTypeLoc>(Result);
7558 return Result;
7559}
7560
7561template <typename Derived>
7562QualType TreeTransform<Derived>::TransformBTFTagAttributedType(
7563 TypeLocBuilder &TLB, BTFTagAttributedTypeLoc TL) {
7564 // The BTFTagAttributedType is available for C only.
7565 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7566}
7567
7568template <typename Derived>
7569QualType TreeTransform<Derived>::TransformHLSLAttributedResourceType(
7570 TypeLocBuilder &TLB, HLSLAttributedResourceTypeLoc TL) {
7571
7572 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7573
7574 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7575 if (WrappedTy.isNull())
7576 return QualType();
7577
7578 QualType ContainedTy = QualType();
7579 QualType OldContainedTy = oldType->getContainedType();
7580 if (!OldContainedTy.isNull()) {
7581 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7582 if (!oldContainedTSI)
7583 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7584 OldContainedTy, SourceLocation());
7585 TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI);
7586 if (!ContainedTSI)
7587 return QualType();
7588 ContainedTy = ContainedTSI->getType();
7589 }
7590
7591 QualType Result = TL.getType();
7592 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7593 ContainedTy != oldType->getContainedType()) {
7595 WrappedTy, ContainedTy, oldType->getAttrs());
7596 }
7597
7598 TLB.push<HLSLAttributedResourceTypeLoc>(Result);
7599 return Result;
7600}
7601
7602template<typename Derived>
7603QualType
7604TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
7605 ParenTypeLoc TL) {
7606 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7607 if (Inner.isNull())
7608 return QualType();
7609
7610 QualType Result = TL.getType();
7611 if (getDerived().AlwaysRebuild() ||
7612 Inner != TL.getInnerLoc().getType()) {
7613 Result = getDerived().RebuildParenType(Inner);
7614 if (Result.isNull())
7615 return QualType();
7616 }
7617
7618 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7619 NewTL.setLParenLoc(TL.getLParenLoc());
7620 NewTL.setRParenLoc(TL.getRParenLoc());
7621 return Result;
7622}
7623
7624template <typename Derived>
7625QualType
7626TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
7627 MacroQualifiedTypeLoc TL) {
7628 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7629 if (Inner.isNull())
7630 return QualType();
7631
7632 QualType Result = TL.getType();
7633 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7634 Result =
7635 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7636 if (Result.isNull())
7637 return QualType();
7638 }
7639
7640 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
7641 NewTL.setExpansionLoc(TL.getExpansionLoc());
7642 return Result;
7643}
7644
7645template<typename Derived>
7646QualType TreeTransform<Derived>::TransformDependentNameType(
7647 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
7648 return TransformDependentNameType(TLB, TL, false);
7649}
7650
7651template<typename Derived>
7652QualType TreeTransform<Derived>::TransformDependentNameType(
7653 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
7654 const DependentNameType *T = TL.getTypePtr();
7655
7656 NestedNameSpecifierLoc QualifierLoc
7657 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7658 if (!QualifierLoc)
7659 return QualType();
7660
7661 QualType Result
7662 = getDerived().RebuildDependentNameType(T->getKeyword(),
7663 TL.getElaboratedKeywordLoc(),
7664 QualifierLoc,
7665 T->getIdentifier(),
7666 TL.getNameLoc(),
7667 DeducedTSTContext);
7668 if (Result.isNull())
7669 return QualType();
7670
7671 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
7672 QualType NamedT = ElabT->getNamedType();
7673 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
7674
7675 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7676 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7677 NewTL.setQualifierLoc(QualifierLoc);
7678 } else {
7679 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
7680 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7681 NewTL.setQualifierLoc(QualifierLoc);
7682 NewTL.setNameLoc(TL.getNameLoc());
7683 }
7684 return Result;
7685}
7686
7687template<typename Derived>
7690 DependentTemplateSpecializationTypeLoc TL) {
7691 NestedNameSpecifierLoc QualifierLoc;
7692 if (TL.getQualifierLoc()) {
7693 QualifierLoc
7694 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7695 if (!QualifierLoc)
7696 return QualType();
7697 }
7698
7699 return getDerived()
7700 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
7701}
7702
7703template<typename Derived>
7707 NestedNameSpecifierLoc QualifierLoc) {
7709
7710 TemplateArgumentListInfo NewTemplateArgs;
7711 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7712 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7713
7716 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7717 ArgIterator(TL, TL.getNumArgs()),
7718 NewTemplateArgs))
7719 return QualType();
7720
7721 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
7722 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
7723 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
7724 /*AllowInjectedClassName*/ false);
7725 if (Result.isNull())
7726 return QualType();
7727
7728 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
7729 QualType NamedT = ElabT->getNamedType();
7730
7731 // Copy information relevant to the template specialization.
7733 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
7736 NamedTL.setLAngleLoc(TL.getLAngleLoc());
7737 NamedTL.setRAngleLoc(TL.getRAngleLoc());
7738 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7739 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7740
7741 // Copy information relevant to the elaborated type.
7744 NewTL.setQualifierLoc(QualifierLoc);
7745 } else if (isa<DependentTemplateSpecializationType>(Result)) {
7749 SpecTL.setQualifierLoc(QualifierLoc);
7752 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7753 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7754 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7755 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7756 } else {
7761 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7762 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7763 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7764 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7765 }
7766 return Result;
7767}
7768
7769template<typename Derived>
7772 QualType Pattern
7773 = getDerived().TransformType(TLB, TL.getPatternLoc());
7774 if (Pattern.isNull())
7775 return QualType();
7776
7777 QualType Result = TL.getType();
7778 if (getDerived().AlwaysRebuild() ||
7779 Pattern != TL.getPatternLoc().getType()) {
7780 Result = getDerived().RebuildPackExpansionType(Pattern,
7782 TL.getEllipsisLoc(),
7784 if (Result.isNull())
7785 return QualType();
7786 }
7787
7788 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
7789 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7790 return Result;
7791}
7792
7793template<typename Derived>
7794QualType
7795TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
7796 ObjCInterfaceTypeLoc TL) {
7797 // ObjCInterfaceType is never dependent.
7798 TLB.pushFullCopy(TL);
7799 return TL.getType();
7800}
7801
7802template<typename Derived>
7803QualType
7804TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
7805 ObjCTypeParamTypeLoc TL) {
7806 const ObjCTypeParamType *T = TL.getTypePtr();
7807 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7808 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7809 if (!OTP)
7810 return QualType();
7811
7812 QualType Result = TL.getType();
7813 if (getDerived().AlwaysRebuild() ||
7814 OTP != T->getDecl()) {
7815 Result = getDerived().RebuildObjCTypeParamType(
7816 OTP, TL.getProtocolLAngleLoc(),
7817 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7818 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7819 if (Result.isNull())
7820 return QualType();
7821 }
7822
7823 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
7824 if (TL.getNumProtocols()) {
7825 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7826 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7827 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7828 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7829 }
7830 return Result;
7831}
7832
7833template<typename Derived>
7834QualType
7835TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
7836 ObjCObjectTypeLoc TL) {
7837 // Transform base type.
7838 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7839 if (BaseType.isNull())
7840 return QualType();
7841
7842 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7843
7844 // Transform type arguments.
7845 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7846 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7847 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7848 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7849 QualType TypeArg = TypeArgInfo->getType();
7850 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7851 AnyChanged = true;
7852
7853 // We have a pack expansion. Instantiate it.
7854 const auto *PackExpansion = PackExpansionLoc.getType()
7855 ->castAs<PackExpansionType>();
7857 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7858 Unexpanded);
7859 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7860
7861 // Determine whether the set of unexpanded parameter packs can
7862 // and should be expanded.
7863 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7864 bool Expand = false;
7865 bool RetainExpansion = false;
7866 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
7867 if (getDerived().TryExpandParameterPacks(
7868 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7869 Unexpanded, Expand, RetainExpansion, NumExpansions))
7870 return QualType();
7871
7872 if (!Expand) {
7873 // We can't expand this pack expansion into separate arguments yet;
7874 // just substitute into the pattern and create a new pack expansion
7875 // type.
7876 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7877
7878 TypeLocBuilder TypeArgBuilder;
7879 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7880 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7881 PatternLoc);
7882 if (NewPatternType.isNull())
7883 return QualType();
7884
7885 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7886 NewPatternType, NumExpansions);
7887 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7888 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7889 NewTypeArgInfos.push_back(
7890 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7891 continue;
7892 }
7893
7894 // Substitute into the pack expansion pattern for each slice of the
7895 // pack.
7896 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7897 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
7898
7899 TypeLocBuilder TypeArgBuilder;
7900 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7901
7902 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7903 PatternLoc);
7904 if (NewTypeArg.isNull())
7905 return QualType();
7906
7907 NewTypeArgInfos.push_back(
7908 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7909 }
7910
7911 continue;
7912 }
7913
7914 TypeLocBuilder TypeArgBuilder;
7915 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7916 QualType NewTypeArg =
7917 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7918 if (NewTypeArg.isNull())
7919 return QualType();
7920
7921 // If nothing changed, just keep the old TypeSourceInfo.
7922 if (NewTypeArg == TypeArg) {
7923 NewTypeArgInfos.push_back(TypeArgInfo);
7924 continue;
7925 }
7926
7927 NewTypeArgInfos.push_back(
7928 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7929 AnyChanged = true;
7930 }
7931
7932 QualType Result = TL.getType();
7933 if (getDerived().AlwaysRebuild() || AnyChanged) {
7934 // Rebuild the type.
7935 Result = getDerived().RebuildObjCObjectType(
7936 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
7937 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
7938 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7939 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7940
7941 if (Result.isNull())
7942 return QualType();
7943 }
7944
7945 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
7946 NewT.setHasBaseTypeAsWritten(true);
7947 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
7948 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
7949 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
7950 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
7951 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7952 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7953 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
7954 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7955 return Result;
7956}
7957
7958template<typename Derived>
7959QualType
7960TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
7961 ObjCObjectPointerTypeLoc TL) {
7962 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7963 if (PointeeType.isNull())
7964 return QualType();
7965
7966 QualType Result = TL.getType();
7967 if (getDerived().AlwaysRebuild() ||
7968 PointeeType != TL.getPointeeLoc().getType()) {
7969 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7970 TL.getStarLoc());
7971 if (Result.isNull())
7972 return QualType();
7973 }
7974
7975 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
7976 NewT.setStarLoc(TL.getStarLoc());
7977 return Result;
7978}
7979
7980//===----------------------------------------------------------------------===//
7981// Statement transformation
7982//===----------------------------------------------------------------------===//
7983template<typename Derived>
7985TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
7986 return S;
7987}
7988
7989template<typename Derived>
7992 return getDerived().TransformCompoundStmt(S, false);
7993}
7994
7995template<typename Derived>
7998 bool IsStmtExpr) {
7999 Sema::CompoundScopeRAII CompoundScope(getSema());
8000 Sema::FPFeaturesStateRAII FPSave(getSema());
8001 if (S->hasStoredFPFeatures())
8002 getSema().resetFPOptions(
8003 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8004
8005 const Stmt *ExprResult = S->getStmtExprResult();
8006 bool SubStmtInvalid = false;
8007 bool SubStmtChanged = false;
8008 SmallVector<Stmt*, 8> Statements;
8009 for (auto *B : S->body()) {
8010 StmtResult Result = getDerived().TransformStmt(
8011 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
8012
8013 if (Result.isInvalid()) {
8014 // Immediately fail if this was a DeclStmt, since it's very
8015 // likely that this will cause problems for future statements.
8016 if (isa<DeclStmt>(B))
8017 return StmtError();
8018
8019 // Otherwise, just keep processing substatements and fail later.
8020 SubStmtInvalid = true;
8021 continue;
8022 }
8023
8024 SubStmtChanged = SubStmtChanged || Result.get() != B;
8025 Statements.push_back(Result.getAs<Stmt>());
8026 }
8027
8028 if (SubStmtInvalid)
8029 return StmtError();
8030
8031 if (!getDerived().AlwaysRebuild() &&
8032 !SubStmtChanged)
8033 return S;
8034
8035 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8036 Statements,
8037 S->getRBracLoc(),
8038 IsStmtExpr);
8039}
8040
8041template<typename Derived>
8043TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
8044 ExprResult LHS, RHS;
8045 {
8046 EnterExpressionEvaluationContext Unevaluated(
8048
8049 // Transform the left-hand case value.
8050 LHS = getDerived().TransformExpr(S->getLHS());
8051 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8052 if (LHS.isInvalid())
8053 return StmtError();
8054
8055 // Transform the right-hand case value (for the GNU case-range extension).
8056 RHS = getDerived().TransformExpr(S->getRHS());
8057 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8058 if (RHS.isInvalid())
8059 return StmtError();
8060 }
8061
8062 // Build the case statement.
8063 // Case statements are always rebuilt so that they will attached to their
8064 // transformed switch statement.
8065 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8066 LHS.get(),
8067 S->getEllipsisLoc(),
8068 RHS.get(),
8069 S->getColonLoc());
8070 if (Case.isInvalid())
8071 return StmtError();
8072
8073 // Transform the statement following the case
8074 StmtResult SubStmt =
8075 getDerived().TransformStmt(S->getSubStmt());
8076 if (SubStmt.isInvalid())
8077 return StmtError();
8078
8079 // Attach the body to the case statement
8080 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8081}
8082
8083template <typename Derived>
8084StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
8085 // Transform the statement following the default case
8086 StmtResult SubStmt =
8087 getDerived().TransformStmt(S->getSubStmt());
8088 if (SubStmt.isInvalid())
8089 return StmtError();
8090
8091 // Default statements are always rebuilt
8092 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8093 SubStmt.get());
8094}
8095
8096template<typename Derived>
8098TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
8099 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8100 if (SubStmt.isInvalid())
8101 return StmtError();
8102
8103 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8104 S->getDecl());
8105 if (!LD)
8106 return StmtError();
8107
8108 // If we're transforming "in-place" (we're not creating new local
8109 // declarations), assume we're replacing the old label statement
8110 // and clear out the reference to it.
8111 if (LD == S->getDecl())
8112 S->getDecl()->setStmt(nullptr);
8113
8114 // FIXME: Pass the real colon location in.
8115 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8116 cast<LabelDecl>(LD), SourceLocation(),
8117 SubStmt.get());
8118}
8119
8120template <typename Derived>
8122 if (!R)
8123 return R;
8124
8125 switch (R->getKind()) {
8126// Transform attributes by calling TransformXXXAttr.
8127#define ATTR(X) \
8128 case attr::X: \
8129 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8130#include "clang/Basic/AttrList.inc"
8131 }
8132 return R;
8133}
8134
8135template <typename Derived>
8137 const Stmt *InstS,
8138 const Attr *R) {
8139 if (!R)
8140 return R;
8141
8142 switch (R->getKind()) {
8143// Transform attributes by calling TransformStmtXXXAttr.
8144#define ATTR(X) \
8145 case attr::X: \
8146 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8147#include "clang/Basic/AttrList.inc"
8148 }
8149 return TransformAttr(R);
8150}
8151
8152template <typename Derived>
8155 StmtDiscardKind SDK) {
8156 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8157 if (SubStmt.isInvalid())
8158 return StmtError();
8159
8160 bool AttrsChanged = false;
8162
8163 // Visit attributes and keep track if any are transformed.
8164 for (const auto *I : S->getAttrs()) {
8165 const Attr *R =
8166 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8167 AttrsChanged |= (I != R);
8168 if (R)
8169 Attrs.push_back(R);
8170 }
8171
8172 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8173 return S;
8174
8175 // If transforming the attributes failed for all of the attributes in the
8176 // statement, don't make an AttributedStmt without attributes.
8177 if (Attrs.empty())
8178 return SubStmt;
8179
8180 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8181 SubStmt.get());
8182}
8183
8184template<typename Derived>
8186TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
8187 // Transform the initialization statement
8188 StmtResult Init = getDerived().TransformStmt(S->getInit());
8189 if (Init.isInvalid())
8190 return StmtError();
8191
8192 Sema::ConditionResult Cond;
8193 if (!S->isConsteval()) {
8194 // Transform the condition
8195 Cond = getDerived().TransformCondition(
8196 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8197 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8199 if (Cond.isInvalid())
8200 return StmtError();
8201 }
8202
8203 // If this is a constexpr if, determine which arm we should instantiate.
8204 std::optional<bool> ConstexprConditionValue;
8205 if (S->isConstexpr())
8206 ConstexprConditionValue = Cond.getKnownValue();
8207
8208 // Transform the "then" branch.
8209 StmtResult Then;
8210 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8211 EnterExpressionEvaluationContext Ctx(
8214 S->isNonNegatedConsteval());
8215
8216 Then = getDerived().TransformStmt(S->getThen());
8217 if (Then.isInvalid())
8218 return StmtError();
8219 } else {
8220 // Discarded branch is replaced with empty CompoundStmt so we can keep
8221 // proper source location for start and end of original branch, so
8222 // subsequent transformations like CoverageMapping work properly
8223 Then = new (getSema().Context)
8224 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8225 }
8226
8227 // Transform the "else" branch.
8228 StmtResult Else;
8229 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8230 EnterExpressionEvaluationContext Ctx(
8233 S->isNegatedConsteval());
8234
8235 Else = getDerived().TransformStmt(S->getElse());
8236 if (Else.isInvalid())
8237 return StmtError();
8238 } else if (S->getElse() && ConstexprConditionValue &&
8239 *ConstexprConditionValue) {
8240 // Same thing here as with <then> branch, we are discarding it, we can't
8241 // replace it with NULL nor NullStmt as we need to keep for source location
8242 // range, for CoverageMapping
8243 Else = new (getSema().Context)
8244 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8245 }
8246
8247 if (!getDerived().AlwaysRebuild() &&
8248 Init.get() == S->getInit() &&
8249 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8250 Then.get() == S->getThen() &&
8251 Else.get() == S->getElse())
8252 return S;
8253
8254 return getDerived().RebuildIfStmt(
8255 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8256 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8257}
8258
8259template<typename Derived>
8261TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
8262 // Transform the initialization statement
8263 StmtResult Init = getDerived().TransformStmt(S->getInit());
8264 if (Init.isInvalid())
8265 return StmtError();
8266
8267 // Transform the condition.
8268 Sema::ConditionResult Cond = getDerived().TransformCondition(
8269 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8271 if (Cond.isInvalid())
8272 return StmtError();
8273
8274 // Rebuild the switch statement.
8276 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8277 Init.get(), Cond, S->getRParenLoc());
8278 if (Switch.isInvalid())
8279 return StmtError();
8280
8281 // Transform the body of the switch statement.
8282 StmtResult Body = getDerived().TransformStmt(S->getBody());
8283 if (Body.isInvalid())
8284 return StmtError();
8285
8286 // Complete the switch statement.
8287 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8288 Body.get());
8289}
8290
8291template<typename Derived>
8293TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
8294 // Transform the condition
8295 Sema::ConditionResult Cond = getDerived().TransformCondition(
8296 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8298 if (Cond.isInvalid())
8299 return StmtError();
8300
8301 // OpenACC Restricts a while-loop inside of certain construct/clause
8302 // combinations, so diagnose that here in OpenACC mode.
8303 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8304 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8305
8306 // Transform the body
8307 StmtResult Body = getDerived().TransformStmt(S->getBody());
8308 if (Body.isInvalid())
8309 return StmtError();
8310
8311 if (!getDerived().AlwaysRebuild() &&
8312 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8313 Body.get() == S->getBody())
8314 return Owned(S);
8315
8316 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8317 Cond, S->getRParenLoc(), Body.get());
8318}
8319
8320template<typename Derived>
8322TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
8323 // OpenACC Restricts a do-loop inside of certain construct/clause
8324 // combinations, so diagnose that here in OpenACC mode.
8325 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8326 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8327
8328 // Transform the body
8329 StmtResult Body = getDerived().TransformStmt(S->getBody());
8330 if (Body.isInvalid())
8331 return StmtError();
8332
8333 // Transform the condition
8334 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8335 if (Cond.isInvalid())
8336 return StmtError();
8337
8338 if (!getDerived().AlwaysRebuild() &&
8339 Cond.get() == S->getCond() &&
8340 Body.get() == S->getBody())
8341 return S;
8342
8343 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8344 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8345 S->getRParenLoc());
8346}
8347
8348template<typename Derived>
8350TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
8351 if (getSema().getLangOpts().OpenMP)
8352 getSema().OpenMP().startOpenMPLoop();
8353
8354 // Transform the initialization statement
8355 StmtResult Init = getDerived().TransformStmt(S->getInit());
8356 if (Init.isInvalid())
8357 return StmtError();
8358
8359 // In OpenMP loop region loop control variable must be captured and be
8360 // private. Perform analysis of first part (if any).
8361 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8362 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8363 Init.get());
8364
8365 // Transform the condition
8366 Sema::ConditionResult Cond = getDerived().TransformCondition(
8367 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8369 if (Cond.isInvalid())
8370 return StmtError();
8371
8372 // Transform the increment
8373 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8374 if (Inc.isInvalid())
8375 return StmtError();
8376
8377 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8378 if (S->getInc() && !FullInc.get())
8379 return StmtError();
8380
8381 // OpenACC Restricts a for-loop inside of certain construct/clause
8382 // combinations, so diagnose that here in OpenACC mode.
8383 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8384 SemaRef.OpenACC().ActOnForStmtBegin(
8385 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8386 Cond.get().second, S->getInc(), Inc.get());
8387
8388 // Transform the body
8389 StmtResult Body = getDerived().TransformStmt(S->getBody());
8390 if (Body.isInvalid())
8391 return StmtError();
8392
8393 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8394
8395 if (!getDerived().AlwaysRebuild() &&
8396 Init.get() == S->getInit() &&
8397 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8398 Inc.get() == S->getInc() &&
8399 Body.get() == S->getBody())
8400 return S;
8401
8402 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8403 Init.get(), Cond, FullInc,
8404 S->getRParenLoc(), Body.get());
8405}
8406
8407template<typename Derived>
8409TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
8410 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8411 S->getLabel());
8412 if (!LD)
8413 return StmtError();
8414
8415 // Goto statements must always be rebuilt, to resolve the label.
8416 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8417 cast<LabelDecl>(LD));
8418}
8419
8420template<typename Derived>
8422TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
8423 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8424 if (Target.isInvalid())
8425 return StmtError();
8426 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8427
8428 if (!getDerived().AlwaysRebuild() &&
8429 Target.get() == S->getTarget())
8430 return S;
8431
8432 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8433 Target.get());
8434}
8435
8436template<typename Derived>
8438TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
8439 return S;
8440}
8441
8442template<typename Derived>
8444TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
8445 return S;
8446}
8447
8448template<typename Derived>
8450TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
8451 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8452 /*NotCopyInit*/false);
8453 if (Result.isInvalid())
8454 return StmtError();
8455
8456 // FIXME: We always rebuild the return statement because there is no way
8457 // to tell whether the return type of the function has changed.
8458 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8459}
8460
8461template<typename Derived>
8463TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
8464 bool DeclChanged = false;
8466 LambdaScopeInfo *LSI = getSema().getCurLambda();
8467 for (auto *D : S->decls()) {
8468 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8469 if (!Transformed)
8470 return StmtError();
8471
8472 if (Transformed != D)
8473 DeclChanged = true;
8474
8475 if (LSI) {
8476 if (auto *TD = dyn_cast<TypeDecl>(Transformed))
8477 LSI->ContainsUnexpandedParameterPack |=
8478 getSema()
8479 .getASTContext()
8480 .getTypeDeclType(TD)
8481 .getCanonicalType()
8482 ->containsUnexpandedParameterPack();
8483
8484 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8485 LSI->ContainsUnexpandedParameterPack |=
8486 VD->getType()->containsUnexpandedParameterPack();
8487 }
8488
8489 Decls.push_back(Transformed);
8490 }
8491
8492 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8493 return S;
8494
8495 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8496}
8497
8498template<typename Derived>
8500TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
8501
8502 SmallVector<Expr*, 8> Constraints;
8505
8506 ExprResult AsmString;
8507 SmallVector<Expr*, 8> Clobbers;
8508
8509 bool ExprsChanged = false;
8510
8511 // Go through the outputs.
8512 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8513 Names.push_back(S->getOutputIdentifier(I));
8514
8515 // No need to transform the constraint literal.
8516 Constraints.push_back(S->getOutputConstraintLiteral(I));
8517
8518 // Transform the output expr.
8519 Expr *OutputExpr = S->getOutputExpr(I);
8520 ExprResult Result = getDerived().TransformExpr(OutputExpr);
8521 if (Result.isInvalid())
8522 return StmtError();
8523
8524 ExprsChanged |= Result.get() != OutputExpr;
8525
8526 Exprs.push_back(Result.get());
8527 }
8528
8529 // Go through the inputs.
8530 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8531 Names.push_back(S->getInputIdentifier(I));
8532
8533 // No need to transform the constraint literal.
8534 Constraints.push_back(S->getInputConstraintLiteral(I));
8535
8536 // Transform the input expr.
8537 Expr *InputExpr = S->getInputExpr(I);
8538 ExprResult Result = getDerived().TransformExpr(InputExpr);
8539 if (Result.isInvalid())
8540 return StmtError();
8541
8542 ExprsChanged |= Result.get() != InputExpr;
8543
8544 Exprs.push_back(Result.get());
8545 }
8546
8547 // Go through the Labels.
8548 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8549 Names.push_back(S->getLabelIdentifier(I));
8550
8551 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8552 if (Result.isInvalid())
8553 return StmtError();
8554 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8555 Exprs.push_back(Result.get());
8556 }
8557 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8558 return S;
8559
8560 // Go through the clobbers.
8561 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
8562 Clobbers.push_back(S->getClobberStringLiteral(I));
8563
8564 // No need to transform the asm string literal.
8565 AsmString = S->getAsmString();
8566 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8567 S->isVolatile(), S->getNumOutputs(),
8568 S->getNumInputs(), Names.data(),
8569 Constraints, Exprs, AsmString.get(),
8570 Clobbers, S->getNumLabels(),
8571 S->getRParenLoc());
8572}
8573
8574template<typename Derived>
8576TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
8577 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8578
8579 bool HadError = false, HadChange = false;
8580
8581 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8582 SmallVector<Expr*, 8> TransformedExprs;
8583 TransformedExprs.reserve(SrcExprs.size());
8584 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8585 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8586 if (!Result.isUsable()) {
8587 HadError = true;
8588 } else {
8589 HadChange |= (Result.get() != SrcExprs[i]);
8590 TransformedExprs.push_back(Result.get());
8591 }
8592 }
8593
8594 if (HadError) return StmtError();
8595 if (!HadChange && !getDerived().AlwaysRebuild())
8596 return Owned(S);
8597
8598 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8599 AsmToks, S->getAsmString(),
8600 S->getNumOutputs(), S->getNumInputs(),
8601 S->getAllConstraints(), S->getClobbers(),
8602 TransformedExprs, S->getEndLoc());
8603}
8604
8605// C++ Coroutines
8606template<typename Derived>
8608TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
8609 auto *ScopeInfo = SemaRef.getCurFunction();
8610 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8611 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8612 ScopeInfo->NeedsCoroutineSuspends &&
8613 ScopeInfo->CoroutineSuspends.first == nullptr &&
8614 ScopeInfo->CoroutineSuspends.second == nullptr &&
8615 "expected clean scope info");
8616
8617 // Set that we have (possibly-invalid) suspend points before we do anything
8618 // that may fail.
8619 ScopeInfo->setNeedsCoroutineSuspends(false);
8620
8621 // We re-build the coroutine promise object (and the coroutine parameters its
8622 // type and constructor depend on) based on the types used in our current
8623 // function. We must do so, and set it on the current FunctionScopeInfo,
8624 // before attempting to transform the other parts of the coroutine body
8625 // statement, such as the implicit suspend statements (because those
8626 // statements reference the FunctionScopeInfo::CoroutinePromise).
8627 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8628 return StmtError();
8629 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8630 if (!Promise)
8631 return StmtError();
8632 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8633 ScopeInfo->CoroutinePromise = Promise;
8634
8635 // Transform the implicit coroutine statements constructed using dependent
8636 // types during the previous parse: initial and final suspensions, the return
8637 // object, and others. We also transform the coroutine function's body.
8638 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8639 if (InitSuspend.isInvalid())
8640 return StmtError();
8641 StmtResult FinalSuspend =
8642 getDerived().TransformStmt(S->getFinalSuspendStmt());
8643 if (FinalSuspend.isInvalid() ||
8644 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8645 return StmtError();
8646 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8647 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8648
8649 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8650 if (BodyRes.isInvalid())
8651 return StmtError();
8652
8653 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8654 if (Builder.isInvalid())
8655 return StmtError();
8656
8657 Expr *ReturnObject = S->getReturnValueInit();
8658 assert(ReturnObject && "the return object is expected to be valid");
8659 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8660 /*NoCopyInit*/ false);
8661 if (Res.isInvalid())
8662 return StmtError();
8663 Builder.ReturnValue = Res.get();
8664
8665 // If during the previous parse the coroutine still had a dependent promise
8666 // statement, we may need to build some implicit coroutine statements
8667 // (such as exception and fallthrough handlers) for the first time.
8668 if (S->hasDependentPromiseType()) {
8669 // We can only build these statements, however, if the current promise type
8670 // is not dependent.
8671 if (!Promise->getType()->isDependentType()) {
8672 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8673 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8674 "these nodes should not have been built yet");
8675 if (!Builder.buildDependentStatements())
8676 return StmtError();
8677 }
8678 } else {
8679 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8680 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8681 if (Res.isInvalid())
8682 return StmtError();
8683 Builder.OnFallthrough = Res.get();
8684 }
8685
8686 if (auto *OnException = S->getExceptionHandler()) {
8687 StmtResult Res = getDerived().TransformStmt(OnException);
8688 if (Res.isInvalid())
8689 return StmtError();
8690 Builder.OnException = Res.get();
8691 }
8692
8693 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8694 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8695 if (Res.isInvalid())
8696 return StmtError();
8697 Builder.ReturnStmtOnAllocFailure = Res.get();
8698 }
8699
8700 // Transform any additional statements we may have already built
8701 assert(S->getAllocate() && S->getDeallocate() &&
8702 "allocation and deallocation calls must already be built");
8703 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8704 if (AllocRes.isInvalid())
8705 return StmtError();
8706 Builder.Allocate = AllocRes.get();
8707
8708 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8709 if (DeallocRes.isInvalid())
8710 return StmtError();
8711 Builder.Deallocate = DeallocRes.get();
8712
8713 if (auto *ResultDecl = S->getResultDecl()) {
8714 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8715 if (Res.isInvalid())
8716 return StmtError();
8717 Builder.ResultDecl = Res.get();
8718 }
8719
8720 if (auto *ReturnStmt = S->getReturnStmt()) {
8721 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8722 if (Res.isInvalid())
8723 return StmtError();
8724 Builder.ReturnStmt = Res.get();
8725 }
8726 }
8727
8728 return getDerived().RebuildCoroutineBodyStmt(Builder);
8729}
8730
8731template<typename Derived>
8733TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
8734 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8735 /*NotCopyInit*/false);
8736 if (Result.isInvalid())
8737 return StmtError();
8738
8739 // Always rebuild; we don't know if this needs to be injected into a new
8740 // context or if the promise type has changed.
8741 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8742 S->isImplicit());
8743}
8744
8745template <typename Derived>
8746ExprResult TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
8747 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8748 /*NotCopyInit*/ false);
8749 if (Operand.isInvalid())
8750 return ExprError();
8751
8752 // Rebuild the common-expr from the operand rather than transforming it
8753 // separately.
8754
8755 // FIXME: getCurScope() should not be used during template instantiation.
8756 // We should pick up the set of unqualified lookup results for operator
8757 // co_await during the initial parse.
8758 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8759 getSema().getCurScope(), E->getKeywordLoc());
8760
8761 // Always rebuild; we don't know if this needs to be injected into a new
8762 // context or if the promise type has changed.
8763 return getDerived().RebuildCoawaitExpr(
8764 E->getKeywordLoc(), Operand.get(),
8765 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8766}
8767
8768template <typename Derived>
8770TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
8771 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8772 /*NotCopyInit*/ false);
8773 if (OperandResult.isInvalid())
8774 return ExprError();
8775
8776 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8777 E->getOperatorCoawaitLookup());
8778
8779 if (LookupResult.isInvalid())
8780 return ExprError();
8781
8782 // Always rebuild; we don't know if this needs to be injected into a new
8783 // context or if the promise type has changed.
8784 return getDerived().RebuildDependentCoawaitExpr(
8785 E->getKeywordLoc(), OperandResult.get(),
8786 cast<UnresolvedLookupExpr>(LookupResult.get()));
8787}
8788
8789template<typename Derived>
8791TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
8792 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8793 /*NotCopyInit*/false);
8794 if (Result.isInvalid())
8795 return ExprError();
8796
8797 // Always rebuild; we don't know if this needs to be injected into a new
8798 // context or if the promise type has changed.
8799 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8800}
8801
8802// Objective-C Statements.
8803
8804template<typename Derived>
8806TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
8807 // Transform the body of the @try.
8808 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8809 if (TryBody.isInvalid())
8810 return StmtError();
8811
8812 // Transform the @catch statements (if present).
8813 bool AnyCatchChanged = false;
8814 SmallVector<Stmt*, 8> CatchStmts;
8815 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8816 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8817 if (Catch.isInvalid())
8818 return StmtError();
8819 if (Catch.get() != S->getCatchStmt(I))
8820 AnyCatchChanged = true;
8821 CatchStmts.push_back(Catch.get());
8822 }
8823
8824 // Transform the @finally statement (if present).
8825 StmtResult Finally;
8826 if (S->getFinallyStmt()) {
8827 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8828 if (Finally.isInvalid())
8829 return StmtError();
8830 }
8831
8832 // If nothing changed, just retain this statement.
8833 if (!getDerived().AlwaysRebuild() &&
8834 TryBody.get() == S->getTryBody() &&
8835 !AnyCatchChanged &&
8836 Finally.get() == S->getFinallyStmt())
8837 return S;
8838
8839 // Build a new statement.
8840 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8841 CatchStmts, Finally.get());
8842}
8843
8844template<typename Derived>
8846TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
8847 // Transform the @catch parameter, if there is one.
8848 VarDecl *Var = nullptr;
8849 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8850 TypeSourceInfo *TSInfo = nullptr;
8851 if (FromVar->getTypeSourceInfo()) {
8852 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8853 if (!TSInfo)
8854 return StmtError();
8855 }
8856
8857 QualType T;
8858 if (TSInfo)
8859 T = TSInfo->getType();
8860 else {
8861 T = getDerived().TransformType(FromVar->getType());
8862 if (T.isNull())
8863 return StmtError();
8864 }
8865
8866 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8867 if (!Var)
8868 return StmtError();
8869 }
8870
8871 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8872 if (Body.isInvalid())
8873 return StmtError();
8874
8875 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8876 S->getRParenLoc(),
8877 Var, Body.get());
8878}
8879
8880template<typename Derived>
8882TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
8883 // Transform the body.
8884 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8885 if (Body.isInvalid())
8886 return StmtError();
8887
8888 // If nothing changed, just retain this statement.
8889 if (!getDerived().AlwaysRebuild() &&
8890 Body.get() == S->getFinallyBody())
8891 return S;
8892
8893 // Build a new statement.
8894 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8895 Body.get());
8896}
8897
8898template<typename Derived>
8900TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
8902 if (S->getThrowExpr()) {
8903 Operand = getDerived().TransformExpr(S->getThrowExpr());
8904 if (Operand.isInvalid())
8905 return StmtError();
8906 }
8907
8908 if (!getDerived().AlwaysRebuild() &&
8909 Operand.get() == S->getThrowExpr())
8910 return S;
8911
8912 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8913}
8914
8915template<typename Derived>
8917TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
8918 ObjCAtSynchronizedStmt *S) {
8919 // Transform the object we are locking.
8920 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
8921 if (Object.isInvalid())
8922 return StmtError();
8923 Object =
8924 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8925 Object.get());
8926 if (Object.isInvalid())
8927 return StmtError();
8928
8929 // Transform the body.
8930 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8931 if (Body.isInvalid())
8932 return StmtError();
8933
8934 // If nothing change, just retain the current statement.
8935 if (!getDerived().AlwaysRebuild() &&
8936 Object.get() == S->getSynchExpr() &&
8937 Body.get() == S->getSynchBody())
8938 return S;
8939
8940 // Build a new statement.
8941 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
8942 Object.get(), Body.get());
8943}
8944
8945template<typename Derived>
8947TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
8948 ObjCAutoreleasePoolStmt *S) {
8949 // Transform the body.
8950 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
8951 if (Body.isInvalid())
8952 return StmtError();
8953
8954 // If nothing changed, just retain this statement.
8955 if (!getDerived().AlwaysRebuild() &&
8956 Body.get() == S->getSubStmt())
8957 return S;
8958
8959 // Build a new statement.
8960 return getDerived().RebuildObjCAutoreleasePoolStmt(
8961 S->getAtLoc(), Body.get());
8962}
8963
8964template<typename Derived>
8966TreeTransform<Derived>::TransformObjCForCollectionStmt(
8967 ObjCForCollectionStmt *S) {
8968 // Transform the element statement.
8969 StmtResult Element =
8970 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
8971 if (Element.isInvalid())
8972 return StmtError();
8973
8974 // Transform the collection expression.
8975 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
8976 if (Collection.isInvalid())
8977 return StmtError();
8978
8979 // Transform the body.
8980 StmtResult Body = getDerived().TransformStmt(S->getBody());
8981 if (Body.isInvalid())
8982 return StmtError();
8983
8984 // If nothing changed, just retain this statement.
8985 if (!getDerived().AlwaysRebuild() &&
8986 Element.get() == S->getElement() &&
8987 Collection.get() == S->getCollection() &&
8988 Body.get() == S->getBody())
8989 return S;
8990
8991 // Build a new statement.
8992 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
8993 Element.get(),
8994 Collection.get(),
8995 S->getRParenLoc(),
8996 Body.get());
8997}
8998
8999template <typename Derived>
9000StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
9001 // Transform the exception declaration, if any.
9002 VarDecl *Var = nullptr;
9003 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9004 TypeSourceInfo *T =
9005 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9006 if (!T)
9007 return StmtError();
9008
9009 Var = getDerived().RebuildExceptionDecl(
9010 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9011 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9012 if (!Var || Var->isInvalidDecl())
9013 return StmtError();
9014 }
9015
9016 // Transform the actual exception handler.
9017 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9018 if (Handler.isInvalid())
9019 return StmtError();
9020
9021 if (!getDerived().AlwaysRebuild() && !Var &&
9022 Handler.get() == S->getHandlerBlock())
9023 return S;
9024
9025 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9026}
9027
9028template <typename Derived>
9029StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
9030 // Transform the try block itself.
9031 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9032 if (TryBlock.isInvalid())
9033 return StmtError();
9034
9035 // Transform the handlers.
9036 bool HandlerChanged = false;
9037 SmallVector<Stmt *, 8> Handlers;
9038 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9039 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9040 if (Handler.isInvalid())
9041 return StmtError();
9042
9043 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9044 Handlers.push_back(Handler.getAs<Stmt>());
9045 }
9046
9047 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9048 !HandlerChanged)
9049 return S;
9050
9051 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9052 Handlers);
9053}
9054
9055template<typename Derived>
9057TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
9058 EnterExpressionEvaluationContext ForRangeInitContext(
9060 /*LambdaContextDecl=*/nullptr,
9062 getSema().getLangOpts().CPlusPlus23);
9063
9064 // P2718R0 - Lifetime extension in range-based for loops.
9065 if (getSema().getLangOpts().CPlusPlus23) {
9066 auto &LastRecord = getSema().currentEvaluationContext();
9067 LastRecord.InLifetimeExtendingContext = true;
9068 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9069 }
9071 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9072 if (Init.isInvalid())
9073 return StmtError();
9074
9075 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9076 if (Range.isInvalid())
9077 return StmtError();
9078
9079 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9080 assert(getSema().getLangOpts().CPlusPlus23 ||
9081 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9082 auto ForRangeLifetimeExtendTemps =
9083 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9084
9085 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9086 if (Begin.isInvalid())
9087 return StmtError();
9088 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9089 if (End.isInvalid())
9090 return StmtError();
9091
9092 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9093 if (Cond.isInvalid())
9094 return StmtError();
9095 if (Cond.get())
9096 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9097 if (Cond.isInvalid())
9098 return StmtError();
9099 if (Cond.get())
9100 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9101
9102 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9103 if (Inc.isInvalid())
9104 return StmtError();
9105 if (Inc.get())
9106 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9107
9108 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9109 if (LoopVar.isInvalid())
9110 return StmtError();
9111
9112 StmtResult NewStmt = S;
9113 if (getDerived().AlwaysRebuild() ||
9114 Init.get() != S->getInit() ||
9115 Range.get() != S->getRangeStmt() ||
9116 Begin.get() != S->getBeginStmt() ||
9117 End.get() != S->getEndStmt() ||
9118 Cond.get() != S->getCond() ||
9119 Inc.get() != S->getInc() ||
9120 LoopVar.get() != S->getLoopVarStmt()) {
9121 NewStmt = getDerived().RebuildCXXForRangeStmt(
9122 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9123 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9124 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9125 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9126 // Might not have attached any initializer to the loop variable.
9127 getSema().ActOnInitializerError(
9128 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9129 return StmtError();
9130 }
9131 }
9132
9133 // OpenACC Restricts a while-loop inside of certain construct/clause
9134 // combinations, so diagnose that here in OpenACC mode.
9135 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
9136 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9137
9138 StmtResult Body = getDerived().TransformStmt(S->getBody());
9139 if (Body.isInvalid())
9140 return StmtError();
9141
9142 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9143
9144 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9145 // it now so we have a new statement to attach the body to.
9146 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9147 NewStmt = getDerived().RebuildCXXForRangeStmt(
9148 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9149 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9150 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9151 if (NewStmt.isInvalid())
9152 return StmtError();
9153 }
9154
9155 if (NewStmt.get() == S)
9156 return S;
9157
9158 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9159}
9160
9161template<typename Derived>
9163TreeTransform<Derived>::TransformMSDependentExistsStmt(
9164 MSDependentExistsStmt *S) {
9165 // Transform the nested-name-specifier, if any.
9166 NestedNameSpecifierLoc QualifierLoc;
9167 if (S->getQualifierLoc()) {
9168 QualifierLoc
9169 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9170 if (!QualifierLoc)
9171 return StmtError();
9172 }
9173
9174 // Transform the declaration name.
9175 DeclarationNameInfo NameInfo = S->getNameInfo();
9176 if (NameInfo.getName()) {
9177 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9178 if (!NameInfo.getName())
9179 return StmtError();
9180 }
9181
9182 // Check whether anything changed.
9183 if (!getDerived().AlwaysRebuild() &&
9184 QualifierLoc == S->getQualifierLoc() &&
9185 NameInfo.getName() == S->getNameInfo().getName())
9186 return S;
9187
9188 // Determine whether this name exists, if we can.
9189 CXXScopeSpec SS;
9190 SS.Adopt(QualifierLoc);
9191 bool Dependent = false;
9192 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9193 case Sema::IER_Exists:
9194 if (S->isIfExists())
9195 break;
9196
9197 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9198
9200 if (S->isIfNotExists())
9201 break;
9202
9203 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9204
9206 Dependent = true;
9207 break;
9208
9209 case Sema::IER_Error:
9210 return StmtError();
9211 }
9212
9213 // We need to continue with the instantiation, so do so now.
9214 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9215 if (SubStmt.isInvalid())
9216 return StmtError();
9217
9218 // If we have resolved the name, just transform to the substatement.
9219 if (!Dependent)
9220 return SubStmt;
9221
9222 // The name is still dependent, so build a dependent expression again.
9223 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9224 S->isIfExists(),
9225 QualifierLoc,
9226 NameInfo,
9227 SubStmt.get());
9228}
9229
9230template<typename Derived>
9232TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
9233 NestedNameSpecifierLoc QualifierLoc;
9234 if (E->getQualifierLoc()) {
9235 QualifierLoc
9236 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9237 if (!QualifierLoc)
9238 return ExprError();
9239 }
9240
9241 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9242 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9243 if (!PD)
9244 return ExprError();
9245
9246 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9247 if (Base.isInvalid())
9248 return ExprError();
9249
9250 return new (SemaRef.getASTContext())
9251 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9253 QualifierLoc, E->getMemberLoc());
9254}
9255
9256template <typename Derived>
9257ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
9258 MSPropertySubscriptExpr *E) {
9259 auto BaseRes = getDerived().TransformExpr(E->getBase());
9260 if (BaseRes.isInvalid())
9261 return ExprError();
9262 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9263 if (IdxRes.isInvalid())
9264 return ExprError();
9265
9266 if (!getDerived().AlwaysRebuild() &&
9267 BaseRes.get() == E->getBase() &&
9268 IdxRes.get() == E->getIdx())
9269 return E;
9270
9271 return getDerived().RebuildArraySubscriptExpr(
9272 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9273}
9274
9275template <typename Derived>
9276StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
9277 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9278 if (TryBlock.isInvalid())
9279 return StmtError();
9280
9281 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9282 if (Handler.isInvalid())
9283 return StmtError();
9284
9285 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9286 Handler.get() == S->getHandler())
9287 return S;
9288
9289 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9290 TryBlock.get(), Handler.get());
9291}
9292
9293template <typename Derived>
9294StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
9295 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9296 if (Block.isInvalid())
9297 return StmtError();
9298
9299 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9300}
9301
9302template <typename Derived>
9303StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
9304 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9305 if (FilterExpr.isInvalid())
9306 return StmtError();
9307
9308 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9309 if (Block.isInvalid())
9310 return StmtError();
9311
9312 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9313 Block.get());
9314}
9315
9316template <typename Derived>
9318 if (isa<SEHFinallyStmt>(Handler))
9319 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9320 else
9321 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9322}
9323
9324template<typename Derived>
9327 return S;
9328}
9329
9330//===----------------------------------------------------------------------===//
9331// OpenMP directive transformation
9332//===----------------------------------------------------------------------===//
9333
9334template <typename Derived>
9336TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9337 // OMPCanonicalLoops are eliminated during transformation, since they will be
9338 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9339 // after transformation.
9340 return getDerived().TransformStmt(L->getLoopStmt());
9341}
9342
9343template <typename Derived>
9346
9347 // Transform the clauses
9349 ArrayRef<OMPClause *> Clauses = D->clauses();
9350 TClauses.reserve(Clauses.size());
9351 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9352 I != E; ++I) {
9353 if (*I) {
9354 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9355 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9356 getDerived().getSema().OpenMP().EndOpenMPClause();
9357 if (Clause)
9358 TClauses.push_back(Clause);
9359 } else {
9360 TClauses.push_back(nullptr);
9361 }
9362 }
9363 StmtResult AssociatedStmt;
9364 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9365 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9366 D->getDirectiveKind(),
9367 /*CurScope=*/nullptr);
9368 StmtResult Body;
9369 {
9370 Sema::CompoundScopeRAII CompoundScope(getSema());
9371 Stmt *CS;
9372 if (D->getDirectiveKind() == OMPD_atomic ||
9373 D->getDirectiveKind() == OMPD_critical ||
9374 D->getDirectiveKind() == OMPD_section ||
9375 D->getDirectiveKind() == OMPD_master)
9376 CS = D->getAssociatedStmt();
9377 else
9378 CS = D->getRawStmt();
9379 Body = getDerived().TransformStmt(CS);
9380 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9381 getSema().getLangOpts().OpenMPIRBuilder)
9382 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9383 }
9384 AssociatedStmt =
9385 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9386 if (AssociatedStmt.isInvalid()) {
9387 return StmtError();
9388 }
9389 }
9390 if (TClauses.size() != Clauses.size()) {
9391 return StmtError();
9392 }
9393
9394 // Transform directive name for 'omp critical' directive.
9395 DeclarationNameInfo DirName;
9396 if (D->getDirectiveKind() == OMPD_critical) {
9397 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9398 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9399 }
9400 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9401 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9402 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9403 } else if (D->getDirectiveKind() == OMPD_cancel) {
9404 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9405 }
9406
9407 return getDerived().RebuildOMPExecutableDirective(
9408 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9409 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9410}
9411
9412/// This is mostly the same as above, but allows 'informational' class
9413/// directives when rebuilding the stmt. It still takes an
9414/// OMPExecutableDirective-type argument because we're reusing that as the
9415/// superclass for the 'assume' directive at present, instead of defining a
9416/// mostly-identical OMPInformationalDirective parent class.
9417template <typename Derived>
9420
9421 // Transform the clauses
9423 ArrayRef<OMPClause *> Clauses = D->clauses();
9424 TClauses.reserve(Clauses.size());
9425 for (OMPClause *C : Clauses) {
9426 if (C) {
9427 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9428 OMPClause *Clause = getDerived().TransformOMPClause(C);
9429 getDerived().getSema().OpenMP().EndOpenMPClause();
9430 if (Clause)
9431 TClauses.push_back(Clause);
9432 } else {
9433 TClauses.push_back(nullptr);
9434 }
9435 }
9436 StmtResult AssociatedStmt;
9437 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9438 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9439 D->getDirectiveKind(),
9440 /*CurScope=*/nullptr);
9441 StmtResult Body;
9442 {
9443 Sema::CompoundScopeRAII CompoundScope(getSema());
9444 assert(D->getDirectiveKind() == OMPD_assume &&
9445 "Unexpected informational directive");
9446 Stmt *CS = D->getAssociatedStmt();
9447 Body = getDerived().TransformStmt(CS);
9448 }
9449 AssociatedStmt =
9450 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9451 if (AssociatedStmt.isInvalid())
9452 return StmtError();
9453 }
9454 if (TClauses.size() != Clauses.size())
9455 return StmtError();
9456
9457 DeclarationNameInfo DirName;
9458
9459 return getDerived().RebuildOMPInformationalDirective(
9460 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9461 D->getBeginLoc(), D->getEndLoc());
9462}
9463
9464template <typename Derived>
9467 // TODO: Fix This
9468 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9469 << getOpenMPDirectiveName(D->getDirectiveKind());
9470 return StmtError();
9471}
9472
9473template <typename Derived>
9475TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9476 DeclarationNameInfo DirName;
9477 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9478 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9479 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9480 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9481 return Res;
9482}
9483
9484template <typename Derived>
9486TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
9487 DeclarationNameInfo DirName;
9488 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9489 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9490 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9491 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9492 return Res;
9493}
9494
9495template <typename Derived>
9497TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
9498 DeclarationNameInfo DirName;
9499 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9500 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9501 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9502 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9503 return Res;
9504}
9505
9506template <typename Derived>
9508TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {
9509 DeclarationNameInfo DirName;
9510 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9511 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9512 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9513 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9514 return Res;
9515}
9516
9517template <typename Derived>
9519TreeTransform<Derived>::TransformOMPReverseDirective(OMPReverseDirective *D) {
9520 DeclarationNameInfo DirName;
9521 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9522 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9523 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9524 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9525 return Res;
9526}
9527
9528template <typename Derived>
9529StmtResult TreeTransform<Derived>::TransformOMPInterchangeDirective(
9530 OMPInterchangeDirective *D) {
9531 DeclarationNameInfo DirName;
9532 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9533 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9534 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9535 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9536 return Res;
9537}
9538
9539template <typename Derived>
9541TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
9542 DeclarationNameInfo DirName;
9543 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9544 OMPD_for, DirName, nullptr, D->getBeginLoc());
9545 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9546 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9547 return Res;
9548}
9549
9550template <typename Derived>
9552TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
9553 DeclarationNameInfo DirName;
9554 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9555 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9556 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9557 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9558 return Res;
9559}
9560
9561template <typename Derived>
9563TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
9564 DeclarationNameInfo DirName;
9565 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9566 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9567 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9568 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9569 return Res;
9570}
9571
9572template <typename Derived>
9574TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
9575 DeclarationNameInfo DirName;
9576 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9577 OMPD_section, DirName, nullptr, D->getBeginLoc());
9578 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9579 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9580 return Res;
9581}
9582
9583template <typename Derived>
9585TreeTransform<Derived>::TransformOMPScopeDirective(OMPScopeDirective *D) {
9586 DeclarationNameInfo DirName;
9587 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9588 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9589 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9590 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9591 return Res;
9592}
9593
9594template <typename Derived>
9596TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
9597 DeclarationNameInfo DirName;
9598 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9599 OMPD_single, DirName, nullptr, D->getBeginLoc());
9600 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9601 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9602 return Res;
9603}
9604
9605template <typename Derived>
9607TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
9608 DeclarationNameInfo DirName;
9609 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9610 OMPD_master, DirName, nullptr, D->getBeginLoc());
9611 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9612 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9613 return Res;
9614}
9615
9616template <typename Derived>
9618TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
9619 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9620 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9621 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9622 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9623 return Res;
9624}
9625
9626template <typename Derived>
9627StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
9628 OMPParallelForDirective *D) {
9629 DeclarationNameInfo DirName;
9630 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9631 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9632 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9633 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9634 return Res;
9635}
9636
9637template <typename Derived>
9638StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
9639 OMPParallelForSimdDirective *D) {
9640 DeclarationNameInfo DirName;
9641 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9642 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9643 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9644 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9645 return Res;
9646}
9647
9648template <typename Derived>
9649StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
9650 OMPParallelMasterDirective *D) {
9651 DeclarationNameInfo DirName;
9652 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9653 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9654 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9655 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9656 return Res;
9657}
9658
9659template <typename Derived>
9660StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective(
9661 OMPParallelMaskedDirective *D) {
9662 DeclarationNameInfo DirName;
9663 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9664 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9665 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9666 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9667 return Res;
9668}
9669
9670template <typename Derived>
9671StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
9672 OMPParallelSectionsDirective *D) {
9673 DeclarationNameInfo DirName;
9674 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9675 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9676 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9677 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9678 return Res;
9679}
9680
9681template <typename Derived>
9683TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
9684 DeclarationNameInfo DirName;
9685 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9686 OMPD_task, DirName, nullptr, D->getBeginLoc());
9687 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9688 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9689 return Res;
9690}
9691
9692template <typename Derived>
9693StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
9694 OMPTaskyieldDirective *D) {
9695 DeclarationNameInfo DirName;
9696 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9697 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9698 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9699 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9700 return Res;
9701}
9702
9703template <typename Derived>
9705TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
9706 DeclarationNameInfo DirName;
9707 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9708 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9709 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9710 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9711 return Res;
9712}
9713
9714template <typename Derived>
9716TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
9717 DeclarationNameInfo DirName;
9718 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9719 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9720 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9721 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9722 return Res;
9723}
9724
9725template <typename Derived>
9727TreeTransform<Derived>::TransformOMPAssumeDirective(OMPAssumeDirective *D) {
9728 DeclarationNameInfo DirName;
9729 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9730 OMPD_assume, DirName, nullptr, D->getBeginLoc());
9731 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
9732 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9733 return Res;
9734}
9735
9736template <typename Derived>
9738TreeTransform<Derived>::TransformOMPErrorDirective(OMPErrorDirective *D) {
9739 DeclarationNameInfo DirName;
9740 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9741 OMPD_error, DirName, nullptr, D->getBeginLoc());
9742 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9743 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9744 return Res;
9745}
9746
9747template <typename Derived>
9748StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
9749 OMPTaskgroupDirective *D) {
9750 DeclarationNameInfo DirName;
9751 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9752 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9753 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9754 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9755 return Res;
9756}
9757
9758template <typename Derived>
9760TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
9761 DeclarationNameInfo DirName;
9762 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9763 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9764 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9765 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9766 return Res;
9767}
9768
9769template <typename Derived>
9771TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
9772 DeclarationNameInfo DirName;
9773 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9774 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9775 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9776 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9777 return Res;
9778}
9779
9780template <typename Derived>
9782TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
9783 DeclarationNameInfo DirName;
9784 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9785 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9786 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9787 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9788 return Res;
9789}
9790
9791template <typename Derived>
9793TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
9794 DeclarationNameInfo DirName;
9795 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9796 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9797 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9798 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9799 return Res;
9800}
9801
9802template <typename Derived>
9804TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
9805 DeclarationNameInfo DirName;
9806 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9807 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9808 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9809 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9810 return Res;
9811}
9812
9813template <typename Derived>
9815TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
9816 DeclarationNameInfo DirName;
9817 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9818 OMPD_target, DirName, nullptr, D->getBeginLoc());
9819 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9820 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9821 return Res;
9822}
9823
9824template <typename Derived>
9825StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
9826 OMPTargetDataDirective *D) {
9827 DeclarationNameInfo DirName;
9828 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9829 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
9830 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9831 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9832 return Res;
9833}
9834
9835template <typename Derived>
9836StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
9837 OMPTargetEnterDataDirective *D) {
9838 DeclarationNameInfo DirName;
9839 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9840 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
9841 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9842 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9843 return Res;
9844}
9845
9846template <typename Derived>
9847StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
9848 OMPTargetExitDataDirective *D) {
9849 DeclarationNameInfo DirName;
9850 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9851 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
9852 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9853 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9854 return Res;
9855}
9856
9857template <typename Derived>
9858StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
9859 OMPTargetParallelDirective *D) {
9860 DeclarationNameInfo DirName;
9861 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9862 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
9863 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9864 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9865 return Res;
9866}
9867
9868template <typename Derived>
9869StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
9870 OMPTargetParallelForDirective *D) {
9871 DeclarationNameInfo DirName;
9872 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9873 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
9874 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9875 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9876 return Res;
9877}
9878
9879template <typename Derived>
9880StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
9881 OMPTargetUpdateDirective *D) {
9882 DeclarationNameInfo DirName;
9883 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9884 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
9885 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9886 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9887 return Res;
9888}
9889
9890template <typename Derived>
9892TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
9893 DeclarationNameInfo DirName;
9894 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9895 OMPD_teams, DirName, nullptr, D->getBeginLoc());
9896 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9897 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9898 return Res;
9899}
9900
9901template <typename Derived>
9902StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
9903 OMPCancellationPointDirective *D) {
9904 DeclarationNameInfo DirName;
9905 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9906 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
9907 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9908 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9909 return Res;
9910}
9911
9912template <typename Derived>
9914TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
9915 DeclarationNameInfo DirName;
9916 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9917 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
9918 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9919 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9920 return Res;
9921}
9922
9923template <typename Derived>
9925TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
9926 DeclarationNameInfo DirName;
9927 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9928 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
9929 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9930 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9931 return Res;
9932}
9933
9934template <typename Derived>
9935StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
9936 OMPTaskLoopSimdDirective *D) {
9937 DeclarationNameInfo DirName;
9938 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9939 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9940 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9941 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9942 return Res;
9943}
9944
9945template <typename Derived>
9946StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
9947 OMPMasterTaskLoopDirective *D) {
9948 DeclarationNameInfo DirName;
9949 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9950 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
9951 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9952 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9953 return Res;
9954}
9955
9956template <typename Derived>
9957StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopDirective(
9958 OMPMaskedTaskLoopDirective *D) {
9959 DeclarationNameInfo DirName;
9960 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9961 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
9962 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9963 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9964 return Res;
9965}
9966
9967template <typename Derived>
9968StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
9969 OMPMasterTaskLoopSimdDirective *D) {
9970 DeclarationNameInfo DirName;
9971 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9972 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9973 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9974 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9975 return Res;
9976}
9977
9978template <typename Derived>
9979StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopSimdDirective(
9980 OMPMaskedTaskLoopSimdDirective *D) {
9981 DeclarationNameInfo DirName;
9982 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9983 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9984 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9985 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9986 return Res;
9987}
9988
9989template <typename Derived>
9990StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
9991 OMPParallelMasterTaskLoopDirective *D) {
9992 DeclarationNameInfo DirName;
9993 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9994 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
9995 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9996 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9997 return Res;
9998}
9999
10000template <typename Derived>
10001StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopDirective(
10002 OMPParallelMaskedTaskLoopDirective *D) {
10003 DeclarationNameInfo DirName;
10004 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10005 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10006 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10007 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10008 return Res;
10009}
10010
10011template <typename Derived>
10013TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective(
10014 OMPParallelMasterTaskLoopSimdDirective *D) {
10015 DeclarationNameInfo DirName;
10016 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10017 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10018 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10019 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10020 return Res;
10021}
10022
10023template <typename Derived>
10025TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopSimdDirective(
10026 OMPParallelMaskedTaskLoopSimdDirective *D) {
10027 DeclarationNameInfo DirName;
10028 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10029 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10030 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10031 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10032 return Res;
10033}
10034
10035template <typename Derived>
10036StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
10037 OMPDistributeDirective *D) {
10038 DeclarationNameInfo DirName;
10039 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10040 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10041 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10042 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10043 return Res;
10044}
10045
10046template <typename Derived>
10047StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
10048 OMPDistributeParallelForDirective *D) {
10049 DeclarationNameInfo DirName;
10050 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10051 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10052 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10053 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10054 return Res;
10055}
10056
10057template <typename Derived>
10059TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
10060 OMPDistributeParallelForSimdDirective *D) {
10061 DeclarationNameInfo DirName;
10062 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10063 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10064 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10065 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10066 return Res;
10067}
10068
10069template <typename Derived>
10070StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
10071 OMPDistributeSimdDirective *D) {
10072 DeclarationNameInfo DirName;
10073 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10074 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10075 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10076 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10077 return Res;
10078}
10079
10080template <typename Derived>
10081StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
10082 OMPTargetParallelForSimdDirective *D) {
10083 DeclarationNameInfo DirName;
10084 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10085 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10086 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10087 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10088 return Res;
10089}
10090
10091template <typename Derived>
10092StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
10093 OMPTargetSimdDirective *D) {
10094 DeclarationNameInfo DirName;
10095 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10096 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10097 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10098 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10099 return Res;
10100}
10101
10102template <typename Derived>
10103StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
10104 OMPTeamsDistributeDirective *D) {
10105 DeclarationNameInfo DirName;
10106 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10107 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10108 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10109 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10110 return Res;
10111}
10112
10113template <typename Derived>
10114StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
10115 OMPTeamsDistributeSimdDirective *D) {
10116 DeclarationNameInfo DirName;
10117 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10118 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10119 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10120 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10121 return Res;
10122}
10123
10124template <typename Derived>
10125StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
10126 OMPTeamsDistributeParallelForSimdDirective *D) {
10127 DeclarationNameInfo DirName;
10128 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10129 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10130 D->getBeginLoc());
10131 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10132 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10133 return Res;
10134}
10135
10136template <typename Derived>
10137StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
10138 OMPTeamsDistributeParallelForDirective *D) {
10139 DeclarationNameInfo DirName;
10140 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10141 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10142 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10143 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10144 return Res;
10145}
10146
10147template <typename Derived>
10148StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
10149 OMPTargetTeamsDirective *D) {
10150 DeclarationNameInfo DirName;
10151 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10152 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10153 auto Res = getDerived().TransformOMPExecutableDirective(D);
10154 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10155 return Res;
10156}
10157
10158template <typename Derived>
10159StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
10160 OMPTargetTeamsDistributeDirective *D) {
10161 DeclarationNameInfo DirName;
10162 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10163 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10164 auto Res = getDerived().TransformOMPExecutableDirective(D);
10165 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10166 return Res;
10167}
10168
10169template <typename Derived>
10171TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
10172 OMPTargetTeamsDistributeParallelForDirective *D) {
10173 DeclarationNameInfo DirName;
10174 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10175 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10176 D->getBeginLoc());
10177 auto Res = getDerived().TransformOMPExecutableDirective(D);
10178 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10179 return Res;
10180}
10181
10182template <typename Derived>
10183StmtResult TreeTransform<Derived>::
10184 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
10185 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10186 DeclarationNameInfo DirName;
10187 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10188 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10189 D->getBeginLoc());
10190 auto Res = getDerived().TransformOMPExecutableDirective(D);
10191 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10192 return Res;
10193}
10194
10195template <typename Derived>
10197TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
10198 OMPTargetTeamsDistributeSimdDirective *D) {
10199 DeclarationNameInfo DirName;
10200 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10201 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10202 auto Res = getDerived().TransformOMPExecutableDirective(D);
10203 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10204 return Res;
10205}
10206
10207template <typename Derived>
10209TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
10210 DeclarationNameInfo DirName;
10211 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10212 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10213 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10214 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10215 return Res;
10216}
10217
10218template <typename Derived>
10220TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
10221 DeclarationNameInfo DirName;
10222 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10223 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10224 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10225 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10226 return Res;
10227}
10228
10229template <typename Derived>
10231TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
10232 DeclarationNameInfo DirName;
10233 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10234 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10235 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10236 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10237 return Res;
10238}
10239
10240template <typename Derived>
10241StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
10242 OMPGenericLoopDirective *D) {
10243 DeclarationNameInfo DirName;
10244 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10245 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10246 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10247 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10248 return Res;
10249}
10250
10251template <typename Derived>
10252StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective(
10253 OMPTeamsGenericLoopDirective *D) {
10254 DeclarationNameInfo DirName;
10255 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10256 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10257 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10258 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10259 return Res;
10260}
10261
10262template <typename Derived>
10263StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsGenericLoopDirective(
10264 OMPTargetTeamsGenericLoopDirective *D) {
10265 DeclarationNameInfo DirName;
10266 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10267 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10268 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10269 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10270 return Res;
10271}
10272
10273template <typename Derived>
10274StmtResult TreeTransform<Derived>::TransformOMPParallelGenericLoopDirective(
10275 OMPParallelGenericLoopDirective *D) {
10276 DeclarationNameInfo DirName;
10277 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10278 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10279 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10280 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10281 return Res;
10282}
10283
10284template <typename Derived>
10286TreeTransform<Derived>::TransformOMPTargetParallelGenericLoopDirective(
10287 OMPTargetParallelGenericLoopDirective *D) {
10288 DeclarationNameInfo DirName;
10289 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10290 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10291 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10292 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10293 return Res;
10294}
10295
10296//===----------------------------------------------------------------------===//
10297// OpenMP clause transformation
10298//===----------------------------------------------------------------------===//
10299template <typename Derived>
10300OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
10301 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10302 if (Cond.isInvalid())
10303 return nullptr;
10304 return getDerived().RebuildOMPIfClause(
10305 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10306 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10307}
10308
10309template <typename Derived>
10310OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
10311 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10312 if (Cond.isInvalid())
10313 return nullptr;
10314 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10315 C->getLParenLoc(), C->getEndLoc());
10316}
10317
10318template <typename Derived>
10319OMPClause *
10320TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
10321 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10322 if (NumThreads.isInvalid())
10323 return nullptr;
10324 return getDerived().RebuildOMPNumThreadsClause(
10325 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10326}
10327
10328template <typename Derived>
10329OMPClause *
10330TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
10331 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10332 if (E.isInvalid())
10333 return nullptr;
10334 return getDerived().RebuildOMPSafelenClause(
10335 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10336}
10337
10338template <typename Derived>
10339OMPClause *
10340TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
10341 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10342 if (E.isInvalid())
10343 return nullptr;
10344 return getDerived().RebuildOMPAllocatorClause(
10345 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10346}
10347
10348template <typename Derived>
10349OMPClause *
10350TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
10351 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10352 if (E.isInvalid())
10353 return nullptr;
10354 return getDerived().RebuildOMPSimdlenClause(
10355 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10356}
10357
10358template <typename Derived>
10359OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) {
10360 SmallVector<Expr *, 4> TransformedSizes;
10361 TransformedSizes.reserve(C->getNumSizes());
10362 bool Changed = false;
10363 for (Expr *E : C->getSizesRefs()) {
10364 if (!E) {
10365 TransformedSizes.push_back(nullptr);
10366 continue;
10367 }
10368
10369 ExprResult T = getDerived().TransformExpr(E);
10370 if (T.isInvalid())
10371 return nullptr;
10372 if (E != T.get())
10373 Changed = true;
10374 TransformedSizes.push_back(T.get());
10375 }
10376
10377 if (!Changed && !getDerived().AlwaysRebuild())
10378 return C;
10379 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10380 C->getLParenLoc(), C->getEndLoc());
10381}
10382
10383template <typename Derived>
10384OMPClause *
10385TreeTransform<Derived>::TransformOMPPermutationClause(OMPPermutationClause *C) {
10386 SmallVector<Expr *> TransformedArgs;
10387 TransformedArgs.reserve(C->getNumLoops());
10388 bool Changed = false;
10389 for (Expr *E : C->getArgsRefs()) {
10390 if (!E) {
10391 TransformedArgs.push_back(nullptr);
10392 continue;
10393 }
10394
10395 ExprResult T = getDerived().TransformExpr(E);
10396 if (T.isInvalid())
10397 return nullptr;
10398 if (E != T.get())
10399 Changed = true;
10400 TransformedArgs.push_back(T.get());
10401 }
10402
10403 if (!Changed && !getDerived().AlwaysRebuild())
10404 return C;
10405 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10406 C->getLParenLoc(), C->getEndLoc());
10407}
10408
10409template <typename Derived>
10410OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) {
10411 if (!getDerived().AlwaysRebuild())
10412 return C;
10413 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10414}
10415
10416template <typename Derived>
10417OMPClause *
10418TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
10419 ExprResult T = getDerived().TransformExpr(C->getFactor());
10420 if (T.isInvalid())
10421 return nullptr;
10422 Expr *Factor = T.get();
10423 bool Changed = Factor != C->getFactor();
10424
10425 if (!Changed && !getDerived().AlwaysRebuild())
10426 return C;
10427 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10428 C->getEndLoc());
10429}
10430
10431template <typename Derived>
10432OMPClause *
10433TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
10434 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10435 if (E.isInvalid())
10436 return nullptr;
10437 return getDerived().RebuildOMPCollapseClause(
10438 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10439}
10440
10441template <typename Derived>
10442OMPClause *
10443TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
10444 return getDerived().RebuildOMPDefaultClause(
10445 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
10446 C->getLParenLoc(), C->getEndLoc());
10447}
10448
10449template <typename Derived>
10450OMPClause *
10451TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
10452 return getDerived().RebuildOMPProcBindClause(
10453 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10454 C->getLParenLoc(), C->getEndLoc());
10455}
10456
10457template <typename Derived>
10458OMPClause *
10459TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
10460 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10461 if (E.isInvalid())
10462 return nullptr;
10463 return getDerived().RebuildOMPScheduleClause(
10464 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10465 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10466 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10467 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10468}
10469
10470template <typename Derived>
10471OMPClause *
10472TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
10473 ExprResult E;
10474 if (auto *Num = C->getNumForLoops()) {
10475 E = getDerived().TransformExpr(Num);
10476 if (E.isInvalid())
10477 return nullptr;
10478 }
10479 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10480 C->getLParenLoc(), E.get());
10481}
10482
10483template <typename Derived>
10484OMPClause *
10485TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
10486 ExprResult E;
10487 if (Expr *Evt = C->getEventHandler()) {
10488 E = getDerived().TransformExpr(Evt);
10489 if (E.isInvalid())
10490 return nullptr;
10491 }
10492 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10493 C->getLParenLoc(), C->getEndLoc());
10494}
10495
10496template <typename Derived>
10497OMPClause *
10498TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
10499 // No need to rebuild this clause, no template-dependent parameters.
10500 return C;
10501}
10502
10503template <typename Derived>
10504OMPClause *
10505TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
10506 // No need to rebuild this clause, no template-dependent parameters.
10507 return C;
10508}
10509
10510template <typename Derived>
10511OMPClause *
10512TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
10513 // No need to rebuild this clause, no template-dependent parameters.
10514 return C;
10515}
10516
10517template <typename Derived>
10518OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
10519 // No need to rebuild this clause, no template-dependent parameters.
10520 return C;
10521}
10522
10523template <typename Derived>
10524OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
10525 // No need to rebuild this clause, no template-dependent parameters.
10526 return C;
10527}
10528
10529template <typename Derived>
10530OMPClause *
10531TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
10532 // No need to rebuild this clause, no template-dependent parameters.
10533 return C;
10534}
10535
10536template <typename Derived>
10537OMPClause *
10538TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
10539 // No need to rebuild this clause, no template-dependent parameters.
10540 return C;
10541}
10542
10543template <typename Derived>
10544OMPClause *
10545TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
10546 // No need to rebuild this clause, no template-dependent parameters.
10547 return C;
10548}
10549
10550template <typename Derived>
10551OMPClause *TreeTransform<Derived>::TransformOMPFailClause(OMPFailClause *C) {
10552 // No need to rebuild this clause, no template-dependent parameters.
10553 return C;
10554}
10555
10556template <typename Derived>
10557OMPClause *
10558TreeTransform<Derived>::TransformOMPAbsentClause(OMPAbsentClause *C) {
10559 return C;
10560}
10561
10562template <typename Derived>
10563OMPClause *TreeTransform<Derived>::TransformOMPHoldsClause(OMPHoldsClause *C) {
10564 ExprResult E = getDerived().TransformExpr(C->getExpr());
10565 if (E.isInvalid())
10566 return nullptr;
10567 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
10568 C->getLParenLoc(), C->getEndLoc());
10569}
10570
10571template <typename Derived>
10572OMPClause *
10573TreeTransform<Derived>::TransformOMPContainsClause(OMPContainsClause *C) {
10574 return C;
10575}
10576
10577template <typename Derived>
10578OMPClause *
10579TreeTransform<Derived>::TransformOMPNoOpenMPClause(OMPNoOpenMPClause *C) {
10580 return C;
10581}
10582template <typename Derived>
10583OMPClause *TreeTransform<Derived>::TransformOMPNoOpenMPRoutinesClause(
10584 OMPNoOpenMPRoutinesClause *C) {
10585 return C;
10586}
10587template <typename Derived>
10588OMPClause *TreeTransform<Derived>::TransformOMPNoParallelismClause(
10589 OMPNoParallelismClause *C) {
10590 return C;
10591}
10592
10593template <typename Derived>
10594OMPClause *
10595TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
10596 // No need to rebuild this clause, no template-dependent parameters.
10597 return C;
10598}
10599
10600template <typename Derived>
10601OMPClause *
10602TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
10603 // No need to rebuild this clause, no template-dependent parameters.
10604 return C;
10605}
10606
10607template <typename Derived>
10608OMPClause *
10609TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
10610 // No need to rebuild this clause, no template-dependent parameters.
10611 return C;
10612}
10613
10614template <typename Derived>
10615OMPClause *
10616TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
10617 // No need to rebuild this clause, no template-dependent parameters.
10618 return C;
10619}
10620
10621template <typename Derived>
10622OMPClause *
10623TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
10624 // No need to rebuild this clause, no template-dependent parameters.
10625 return C;
10626}
10627
10628template <typename Derived>
10629OMPClause *TreeTransform<Derived>::TransformOMPWeakClause(OMPWeakClause *C) {
10630 // No need to rebuild this clause, no template-dependent parameters.
10631 return C;
10632}
10633
10634template <typename Derived>
10635OMPClause *
10636TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
10637 // No need to rebuild this clause, no template-dependent parameters.
10638 return C;
10639}
10640
10641template <typename Derived>
10642OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
10643 // No need to rebuild this clause, no template-dependent parameters.
10644 return C;
10645}
10646
10647template <typename Derived>
10648OMPClause *
10649TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
10650 // No need to rebuild this clause, no template-dependent parameters.
10651 return C;
10652}
10653
10654template <typename Derived>
10655OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
10656 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10657 if (IVR.isInvalid())
10658 return nullptr;
10659
10660 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10661 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10662 for (Expr *E : llvm::drop_begin(C->varlist())) {
10663 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10664 if (ER.isInvalid())
10665 return nullptr;
10666 InteropInfo.PreferTypes.push_back(ER.get());
10667 }
10668 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10669 C->getBeginLoc(), C->getLParenLoc(),
10670 C->getVarLoc(), C->getEndLoc());
10671}
10672
10673template <typename Derived>
10674OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) {
10675 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10676 if (ER.isInvalid())
10677 return nullptr;
10678 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10679 C->getLParenLoc(), C->getVarLoc(),
10680 C->getEndLoc());
10681}
10682
10683template <typename Derived>
10684OMPClause *
10685TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
10686 ExprResult ER;
10687 if (Expr *IV = C->getInteropVar()) {
10688 ER = getDerived().TransformExpr(IV);
10689 if (ER.isInvalid())
10690 return nullptr;
10691 }
10692 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10693 C->getLParenLoc(), C->getVarLoc(),
10694 C->getEndLoc());
10695}
10696
10697template <typename Derived>
10698OMPClause *
10699TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
10700 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10701 if (Cond.isInvalid())
10702 return nullptr;
10703 return getDerived().RebuildOMPNovariantsClause(
10704 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10705}
10706
10707template <typename Derived>
10708OMPClause *
10709TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
10710 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10711 if (Cond.isInvalid())
10712 return nullptr;
10713 return getDerived().RebuildOMPNocontextClause(
10714 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10715}
10716
10717template <typename Derived>
10718OMPClause *
10719TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
10720 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10721 if (ThreadID.isInvalid())
10722 return nullptr;
10723 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10724 C->getLParenLoc(), C->getEndLoc());
10725}
10726
10727template <typename Derived>
10728OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) {
10729 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10730 if (E.isInvalid())
10731 return nullptr;
10732 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10733 C->getLParenLoc(), C->getEndLoc());
10734}
10735
10736template <typename Derived>
10737OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
10738 OMPUnifiedAddressClause *C) {
10739 llvm_unreachable("unified_address clause cannot appear in dependent context");
10740}
10741
10742template <typename Derived>
10743OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
10744 OMPUnifiedSharedMemoryClause *C) {
10745 llvm_unreachable(
10746 "unified_shared_memory clause cannot appear in dependent context");
10747}
10748
10749template <typename Derived>
10750OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
10751 OMPReverseOffloadClause *C) {
10752 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10753}
10754
10755template <typename Derived>
10756OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
10757 OMPDynamicAllocatorsClause *C) {
10758 llvm_unreachable(
10759 "dynamic_allocators clause cannot appear in dependent context");
10760}
10761
10762template <typename Derived>
10763OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
10764 OMPAtomicDefaultMemOrderClause *C) {
10765 llvm_unreachable(
10766 "atomic_default_mem_order clause cannot appear in dependent context");
10767}
10768
10769template <typename Derived>
10770OMPClause *TreeTransform<Derived>::TransformOMPAtClause(OMPAtClause *C) {
10771 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10772 C->getBeginLoc(), C->getLParenLoc(),
10773 C->getEndLoc());
10774}
10775
10776template <typename Derived>
10777OMPClause *
10778TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) {
10779 return getDerived().RebuildOMPSeverityClause(
10780 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10781 C->getLParenLoc(), C->getEndLoc());
10782}
10783
10784template <typename Derived>
10785OMPClause *
10786TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) {
10787 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10788 if (E.isInvalid())
10789 return nullptr;
10790 return getDerived().RebuildOMPMessageClause(
10791 C->getMessageString(), C->getBeginLoc(), C->getLParenLoc(),
10792 C->getEndLoc());
10793}
10794
10795template <typename Derived>
10796OMPClause *
10797TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
10799 Vars.reserve(C->varlist_size());
10800 for (auto *VE : C->varlist()) {
10801 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10802 if (EVar.isInvalid())
10803 return nullptr;
10804 Vars.push_back(EVar.get());
10805 }
10806 return getDerived().RebuildOMPPrivateClause(
10807 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10808}
10809
10810template <typename Derived>
10811OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
10812 OMPFirstprivateClause *C) {
10814 Vars.reserve(C->varlist_size());
10815 for (auto *VE : C->varlist()) {
10816 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10817 if (EVar.isInvalid())
10818 return nullptr;
10819 Vars.push_back(EVar.get());
10820 }
10821 return getDerived().RebuildOMPFirstprivateClause(
10822 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10823}
10824
10825template <typename Derived>
10826OMPClause *
10827TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
10829 Vars.reserve(C->varlist_size());
10830 for (auto *VE : C->varlist()) {
10831 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10832 if (EVar.isInvalid())
10833 return nullptr;
10834 Vars.push_back(EVar.get());
10835 }
10836 return getDerived().RebuildOMPLastprivateClause(
10837 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
10838 C->getLParenLoc(), C->getEndLoc());
10839}
10840
10841template <typename Derived>
10842OMPClause *
10843TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
10845 Vars.reserve(C->varlist_size());
10846 for (auto *VE : C->varlist()) {
10847 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10848 if (EVar.isInvalid())
10849 return nullptr;
10850 Vars.push_back(EVar.get());
10851 }
10852 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
10853 C->getLParenLoc(), C->getEndLoc());
10854}
10855
10856template <typename Derived>
10857OMPClause *
10858TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
10860 Vars.reserve(C->varlist_size());
10861 for (auto *VE : C->varlist()) {
10862 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10863 if (EVar.isInvalid())
10864 return nullptr;
10865 Vars.push_back(EVar.get());
10866 }
10867 CXXScopeSpec ReductionIdScopeSpec;
10868 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10869
10870 DeclarationNameInfo NameInfo = C->getNameInfo();
10871 if (NameInfo.getName()) {
10872 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10873 if (!NameInfo.getName())
10874 return nullptr;
10875 }
10876 // Build a list of all UDR decls with the same names ranged by the Scopes.
10877 // The Scope boundary is a duplication of the previous decl.
10878 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10879 for (auto *E : C->reduction_ops()) {
10880 // Transform all the decls.
10881 if (E) {
10882 auto *ULE = cast<UnresolvedLookupExpr>(E);
10883 UnresolvedSet<8> Decls;
10884 for (auto *D : ULE->decls()) {
10885 NamedDecl *InstD =
10886 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10887 Decls.addDecl(InstD, InstD->getAccess());
10888 }
10889 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10890 SemaRef.Context, /*NamingClass=*/nullptr,
10891 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10892 /*ADL=*/true, Decls.begin(), Decls.end(),
10893 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10894 } else
10895 UnresolvedReductions.push_back(nullptr);
10896 }
10897 return getDerived().RebuildOMPReductionClause(
10898 Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(),
10899 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
10900 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10901}
10902
10903template <typename Derived>
10904OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
10905 OMPTaskReductionClause *C) {
10907 Vars.reserve(C->varlist_size());
10908 for (auto *VE : C->varlist()) {
10909 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10910 if (EVar.isInvalid())
10911 return nullptr;
10912 Vars.push_back(EVar.get());
10913 }
10914 CXXScopeSpec ReductionIdScopeSpec;
10915 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10916
10917 DeclarationNameInfo NameInfo = C->getNameInfo();
10918 if (NameInfo.getName()) {
10919 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10920 if (!NameInfo.getName())
10921 return nullptr;
10922 }
10923 // Build a list of all UDR decls with the same names ranged by the Scopes.
10924 // The Scope boundary is a duplication of the previous decl.
10925 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10926 for (auto *E : C->reduction_ops()) {
10927 // Transform all the decls.
10928 if (E) {
10929 auto *ULE = cast<UnresolvedLookupExpr>(E);
10930 UnresolvedSet<8> Decls;
10931 for (auto *D : ULE->decls()) {
10932 NamedDecl *InstD =
10933 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10934 Decls.addDecl(InstD, InstD->getAccess());
10935 }
10936 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10937 SemaRef.Context, /*NamingClass=*/nullptr,
10938 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10939 /*ADL=*/true, Decls.begin(), Decls.end(),
10940 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10941 } else
10942 UnresolvedReductions.push_back(nullptr);
10943 }
10944 return getDerived().RebuildOMPTaskReductionClause(
10945 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10946 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10947}
10948
10949template <typename Derived>
10950OMPClause *
10951TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
10953 Vars.reserve(C->varlist_size());
10954 for (auto *VE : C->varlist()) {
10955 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10956 if (EVar.isInvalid())
10957 return nullptr;
10958 Vars.push_back(EVar.get());
10959 }
10960 CXXScopeSpec ReductionIdScopeSpec;
10961 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10962
10963 DeclarationNameInfo NameInfo = C->getNameInfo();
10964 if (NameInfo.getName()) {
10965 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10966 if (!NameInfo.getName())
10967 return nullptr;
10968 }
10969 // Build a list of all UDR decls with the same names ranged by the Scopes.
10970 // The Scope boundary is a duplication of the previous decl.
10971 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10972 for (auto *E : C->reduction_ops()) {
10973 // Transform all the decls.
10974 if (E) {
10975 auto *ULE = cast<UnresolvedLookupExpr>(E);
10976 UnresolvedSet<8> Decls;
10977 for (auto *D : ULE->decls()) {
10978 NamedDecl *InstD =
10979 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10980 Decls.addDecl(InstD, InstD->getAccess());
10981 }
10982 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10983 SemaRef.Context, /*NamingClass=*/nullptr,
10984 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10985 /*ADL=*/true, Decls.begin(), Decls.end(),
10986 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10987 } else
10988 UnresolvedReductions.push_back(nullptr);
10989 }
10990 return getDerived().RebuildOMPInReductionClause(
10991 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10992 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10993}
10994
10995template <typename Derived>
10996OMPClause *
10997TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
10999 Vars.reserve(C->varlist_size());
11000 for (auto *VE : C->varlist()) {
11001 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11002 if (EVar.isInvalid())
11003 return nullptr;
11004 Vars.push_back(EVar.get());
11005 }
11006 ExprResult Step = getDerived().TransformExpr(C->getStep());
11007 if (Step.isInvalid())
11008 return nullptr;
11009 return getDerived().RebuildOMPLinearClause(
11010 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11011 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11012 C->getEndLoc());
11013}
11014
11015template <typename Derived>
11016OMPClause *
11017TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
11019 Vars.reserve(C->varlist_size());
11020 for (auto *VE : C->varlist()) {
11021 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11022 if (EVar.isInvalid())
11023 return nullptr;
11024 Vars.push_back(EVar.get());
11025 }
11026 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11027 if (Alignment.isInvalid())
11028 return nullptr;
11029 return getDerived().RebuildOMPAlignedClause(
11030 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11031 C->getColonLoc(), C->getEndLoc());
11032}
11033
11034template <typename Derived>
11035OMPClause *
11036TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
11038 Vars.reserve(C->varlist_size());
11039 for (auto *VE : C->varlist()) {
11040 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11041 if (EVar.isInvalid())
11042 return nullptr;
11043 Vars.push_back(EVar.get());
11044 }
11045 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11046 C->getLParenLoc(), C->getEndLoc());
11047}
11048
11049template <typename Derived>
11050OMPClause *
11051TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
11053 Vars.reserve(C->varlist_size());
11054 for (auto *VE : C->varlist()) {
11055 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11056 if (EVar.isInvalid())
11057 return nullptr;
11058 Vars.push_back(EVar.get());
11059 }
11060 return getDerived().RebuildOMPCopyprivateClause(
11061 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11062}
11063
11064template <typename Derived>
11065OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
11067 Vars.reserve(C->varlist_size());
11068 for (auto *VE : C->varlist()) {
11069 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11070 if (EVar.isInvalid())
11071 return nullptr;
11072 Vars.push_back(EVar.get());
11073 }
11074 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11075 C->getLParenLoc(), C->getEndLoc());
11076}
11077
11078template <typename Derived>
11079OMPClause *
11080TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
11081 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11082 if (E.isInvalid())
11083 return nullptr;
11084 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11085 C->getLParenLoc(), C->getEndLoc());
11086}
11087
11088template <typename Derived>
11089OMPClause *
11090TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
11092 Expr *DepModifier = C->getModifier();
11093 if (DepModifier) {
11094 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11095 if (DepModRes.isInvalid())
11096 return nullptr;
11097 DepModifier = DepModRes.get();
11098 }
11099 Vars.reserve(C->varlist_size());
11100 for (auto *VE : C->varlist()) {
11101 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11102 if (EVar.isInvalid())
11103 return nullptr;
11104 Vars.push_back(EVar.get());
11105 }
11106 return getDerived().RebuildOMPDependClause(
11107 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11108 C->getOmpAllMemoryLoc()},
11109 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11110}
11111
11112template <typename Derived>
11113OMPClause *
11114TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
11115 ExprResult E = getDerived().TransformExpr(C->getDevice());
11116 if (E.isInvalid())
11117 return nullptr;
11118 return getDerived().RebuildOMPDeviceClause(
11119 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11120 C->getModifierLoc(), C->getEndLoc());
11121}
11122
11123template <typename Derived, class T>
11126 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11127 DeclarationNameInfo &MapperIdInfo,
11128 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11129 // Transform expressions in the list.
11130 Vars.reserve(C->varlist_size());
11131 for (auto *VE : C->varlist()) {
11132 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11133 if (EVar.isInvalid())
11134 return true;
11135 Vars.push_back(EVar.get());
11136 }
11137 // Transform mapper scope specifier and identifier.
11138 NestedNameSpecifierLoc QualifierLoc;
11139 if (C->getMapperQualifierLoc()) {
11140 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11141 C->getMapperQualifierLoc());
11142 if (!QualifierLoc)
11143 return true;
11144 }
11145 MapperIdScopeSpec.Adopt(QualifierLoc);
11146 MapperIdInfo = C->getMapperIdInfo();
11147 if (MapperIdInfo.getName()) {
11148 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11149 if (!MapperIdInfo.getName())
11150 return true;
11151 }
11152 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11153 // the previous user-defined mapper lookup in dependent environment.
11154 for (auto *E : C->mapperlists()) {
11155 // Transform all the decls.
11156 if (E) {
11157 auto *ULE = cast<UnresolvedLookupExpr>(E);
11158 UnresolvedSet<8> Decls;
11159 for (auto *D : ULE->decls()) {
11160 NamedDecl *InstD =
11161 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11162 Decls.addDecl(InstD, InstD->getAccess());
11163 }
11164 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11165 TT.getSema().Context, /*NamingClass=*/nullptr,
11166 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11167 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11168 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11169 } else {
11170 UnresolvedMappers.push_back(nullptr);
11171 }
11172 }
11173 return false;
11174}
11175
11176template <typename Derived>
11177OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11178 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11180 Expr *IteratorModifier = C->getIteratorModifier();
11181 if (IteratorModifier) {
11182 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11183 if (MapModRes.isInvalid())
11184 return nullptr;
11185 IteratorModifier = MapModRes.get();
11186 }
11187 CXXScopeSpec MapperIdScopeSpec;
11188 DeclarationNameInfo MapperIdInfo;
11189 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11190 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
11191 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11192 return nullptr;
11193 return getDerived().RebuildOMPMapClause(
11194 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11195 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11196 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11197}
11198
11199template <typename Derived>
11200OMPClause *
11201TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
11202 Expr *Allocator = C->getAllocator();
11203 if (Allocator) {
11204 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11205 if (AllocatorRes.isInvalid())
11206 return nullptr;
11207 Allocator = AllocatorRes.get();
11208 }
11210 Vars.reserve(C->varlist_size());
11211 for (auto *VE : C->varlist()) {
11212 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11213 if (EVar.isInvalid())
11214 return nullptr;
11215 Vars.push_back(EVar.get());
11216 }
11217 return getDerived().RebuildOMPAllocateClause(
11218 Allocator, C->getAllocatorModifier(), Vars, C->getBeginLoc(),
11219 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11220}
11221
11222template <typename Derived>
11223OMPClause *
11224TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
11226 Vars.reserve(C->varlist_size());
11227 for (auto *VE : C->varlist()) {
11228 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11229 if (EVar.isInvalid())
11230 return nullptr;
11231 Vars.push_back(EVar.get());
11232 }
11233 return getDerived().RebuildOMPNumTeamsClause(
11234 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11235}
11236
11237template <typename Derived>
11238OMPClause *
11239TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
11241 Vars.reserve(C->varlist_size());
11242 for (auto *VE : C->varlist()) {
11243 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11244 if (EVar.isInvalid())
11245 return nullptr;
11246 Vars.push_back(EVar.get());
11247 }
11248 return getDerived().RebuildOMPThreadLimitClause(
11249 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11250}
11251
11252template <typename Derived>
11253OMPClause *
11254TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
11255 ExprResult E = getDerived().TransformExpr(C->getPriority());
11256 if (E.isInvalid())
11257 return nullptr;
11258 return getDerived().RebuildOMPPriorityClause(
11259 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11260}
11261
11262template <typename Derived>
11263OMPClause *
11264TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
11265 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11266 if (E.isInvalid())
11267 return nullptr;
11268 return getDerived().RebuildOMPGrainsizeClause(
11269 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11270 C->getModifierLoc(), C->getEndLoc());
11271}
11272
11273template <typename Derived>
11274OMPClause *
11275TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
11276 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11277 if (E.isInvalid())
11278 return nullptr;
11279 return getDerived().RebuildOMPNumTasksClause(
11280 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11281 C->getModifierLoc(), C->getEndLoc());
11282}
11283
11284template <typename Derived>
11285OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
11286 ExprResult E = getDerived().TransformExpr(C->getHint());
11287 if (E.isInvalid())
11288 return nullptr;
11289 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11290 C->getLParenLoc(), C->getEndLoc());
11291}
11292
11293template <typename Derived>
11294OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
11295 OMPDistScheduleClause *C) {
11296 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11297 if (E.isInvalid())
11298 return nullptr;
11299 return getDerived().RebuildOMPDistScheduleClause(
11300 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11301 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11302}
11303
11304template <typename Derived>
11305OMPClause *
11306TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
11307 // Rebuild Defaultmap Clause since we need to invoke the checking of
11308 // defaultmap(none:variable-category) after template initialization.
11309 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11310 C->getDefaultmapKind(),
11311 C->getBeginLoc(),
11312 C->getLParenLoc(),
11313 C->getDefaultmapModifierLoc(),
11314 C->getDefaultmapKindLoc(),
11315 C->getEndLoc());
11316}
11317
11318template <typename Derived>
11319OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
11320 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11322 CXXScopeSpec MapperIdScopeSpec;
11323 DeclarationNameInfo MapperIdInfo;
11324 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11325 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
11326 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11327 return nullptr;
11328 return getDerived().RebuildOMPToClause(
11329 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11330 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11331}
11332
11333template <typename Derived>
11334OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
11335 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11337 CXXScopeSpec MapperIdScopeSpec;
11338 DeclarationNameInfo MapperIdInfo;
11339 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11340 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
11341 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11342 return nullptr;
11343 return getDerived().RebuildOMPFromClause(
11344 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11345 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11346}
11347
11348template <typename Derived>
11349OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
11350 OMPUseDevicePtrClause *C) {
11352 Vars.reserve(C->varlist_size());
11353 for (auto *VE : C->varlist()) {
11354 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11355 if (EVar.isInvalid())
11356 return nullptr;
11357 Vars.push_back(EVar.get());
11358 }
11359 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11360 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
11361}
11362
11363template <typename Derived>
11364OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause(
11365 OMPUseDeviceAddrClause *C) {
11367 Vars.reserve(C->varlist_size());
11368 for (auto *VE : C->varlist()) {
11369 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11370 if (EVar.isInvalid())
11371 return nullptr;
11372 Vars.push_back(EVar.get());
11373 }
11374 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11375 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11376}
11377
11378template <typename Derived>
11379OMPClause *
11380TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
11382 Vars.reserve(C->varlist_size());
11383 for (auto *VE : C->varlist()) {
11384 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11385 if (EVar.isInvalid())
11386 return nullptr;
11387 Vars.push_back(EVar.get());
11388 }
11389 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11390 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11391}
11392
11393template <typename Derived>
11394OMPClause *TreeTransform<Derived>::TransformOMPHasDeviceAddrClause(
11395 OMPHasDeviceAddrClause *C) {
11397 Vars.reserve(C->varlist_size());
11398 for (auto *VE : C->varlist()) {
11399 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11400 if (EVar.isInvalid())
11401 return nullptr;
11402 Vars.push_back(EVar.get());
11403 }
11404 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11405 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11406}
11407
11408template <typename Derived>
11409OMPClause *
11410TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) {
11412 Vars.reserve(C->varlist_size());
11413 for (auto *VE : C->varlist()) {
11414 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11415 if (EVar.isInvalid())
11416 return nullptr;
11417 Vars.push_back(EVar.get());
11418 }
11419 return getDerived().RebuildOMPNontemporalClause(
11420 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11421}
11422
11423template <typename Derived>
11424OMPClause *
11425TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) {
11427 Vars.reserve(C->varlist_size());
11428 for (auto *VE : C->varlist()) {
11429 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11430 if (EVar.isInvalid())
11431 return nullptr;
11432 Vars.push_back(EVar.get());
11433 }
11434 return getDerived().RebuildOMPInclusiveClause(
11435 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11436}
11437
11438template <typename Derived>
11439OMPClause *
11440TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) {
11442 Vars.reserve(C->varlist_size());
11443 for (auto *VE : C->varlist()) {
11444 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11445 if (EVar.isInvalid())
11446 return nullptr;
11447 Vars.push_back(EVar.get());
11448 }
11449 return getDerived().RebuildOMPExclusiveClause(
11450 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11451}
11452
11453template <typename Derived>
11454OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause(
11455 OMPUsesAllocatorsClause *C) {
11457 Data.reserve(C->getNumberOfAllocators());
11458 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11459 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11460 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11461 if (Allocator.isInvalid())
11462 continue;
11463 ExprResult AllocatorTraits;
11464 if (Expr *AT = D.AllocatorTraits) {
11465 AllocatorTraits = getDerived().TransformExpr(AT);
11466 if (AllocatorTraits.isInvalid())
11467 continue;
11468 }
11469 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11470 NewD.Allocator = Allocator.get();
11471 NewD.AllocatorTraits = AllocatorTraits.get();
11472 NewD.LParenLoc = D.LParenLoc;
11473 NewD.RParenLoc = D.RParenLoc;
11474 }
11475 return getDerived().RebuildOMPUsesAllocatorsClause(
11476 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11477}
11478
11479template <typename Derived>
11480OMPClause *
11481TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) {
11482 SmallVector<Expr *, 4> Locators;
11483 Locators.reserve(C->varlist_size());
11484 ExprResult ModifierRes;
11485 if (Expr *Modifier = C->getModifier()) {
11486 ModifierRes = getDerived().TransformExpr(Modifier);
11487 if (ModifierRes.isInvalid())
11488 return nullptr;
11489 }
11490 for (Expr *E : C->varlist()) {
11491 ExprResult Locator = getDerived().TransformExpr(E);
11492 if (Locator.isInvalid())
11493 continue;
11494 Locators.push_back(Locator.get());
11495 }
11496 return getDerived().RebuildOMPAffinityClause(
11497 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11498 ModifierRes.get(), Locators);
11499}
11500
11501template <typename Derived>
11502OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) {
11503 return getDerived().RebuildOMPOrderClause(
11504 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11505 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11506}
11507
11508template <typename Derived>
11509OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) {
11510 return getDerived().RebuildOMPBindClause(
11511 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11512 C->getLParenLoc(), C->getEndLoc());
11513}
11514
11515template <typename Derived>
11516OMPClause *TreeTransform<Derived>::TransformOMPXDynCGroupMemClause(
11517 OMPXDynCGroupMemClause *C) {
11518 ExprResult Size = getDerived().TransformExpr(C->getSize());
11519 if (Size.isInvalid())
11520 return nullptr;
11521 return getDerived().RebuildOMPXDynCGroupMemClause(
11522 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11523}
11524
11525template <typename Derived>
11526OMPClause *
11527TreeTransform<Derived>::TransformOMPDoacrossClause(OMPDoacrossClause *C) {
11529 Vars.reserve(C->varlist_size());
11530 for (auto *VE : C->varlist()) {
11531 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11532 if (EVar.isInvalid())
11533 return nullptr;
11534 Vars.push_back(EVar.get());
11535 }
11536 return getDerived().RebuildOMPDoacrossClause(
11537 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11538 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11539}
11540
11541template <typename Derived>
11542OMPClause *
11543TreeTransform<Derived>::TransformOMPXAttributeClause(OMPXAttributeClause *C) {
11545 for (auto *A : C->getAttrs())
11546 NewAttrs.push_back(getDerived().TransformAttr(A));
11547 return getDerived().RebuildOMPXAttributeClause(
11548 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11549}
11550
11551template <typename Derived>
11552OMPClause *TreeTransform<Derived>::TransformOMPXBareClause(OMPXBareClause *C) {
11553 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11554}
11555
11556//===----------------------------------------------------------------------===//
11557// OpenACC transformation
11558//===----------------------------------------------------------------------===//
11559namespace {
11560template <typename Derived>
11561class OpenACCClauseTransform final
11562 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11563 TreeTransform<Derived> &Self;
11564 ArrayRef<const OpenACCClause *> ExistingClauses;
11565 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11566 OpenACCClause *NewClause = nullptr;
11567
11568 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11569 llvm::SmallVector<Expr *> InstantiatedVarList;
11570 for (Expr *CurVar : VarList) {
11571 ExprResult Res = Self.TransformExpr(CurVar);
11572
11573 if (!Res.isUsable())
11574 continue;
11575
11576 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getClauseKind(),
11577 Res.get());
11578
11579 if (Res.isUsable())
11580 InstantiatedVarList.push_back(Res.get());
11581 }
11582
11583 return InstantiatedVarList;
11584 }
11585
11586public:
11587 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11588 ArrayRef<const OpenACCClause *> ExistingClauses,
11589 SemaOpenACC::OpenACCParsedClause &PC)
11590 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11591
11592 OpenACCClause *CreatedClause() const { return NewClause; }
11593
11594#define VISIT_CLAUSE(CLAUSE_NAME) \
11595 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11596#include "clang/Basic/OpenACCClauses.def"
11597};
11598
11599template <typename Derived>
11600void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11601 const OpenACCDefaultClause &C) {
11602 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11603
11604 NewClause = OpenACCDefaultClause::Create(
11605 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11606 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11607 ParsedClause.getEndLoc());
11608}
11609
11610template <typename Derived>
11611void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11612 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11613 assert(Cond && "If constructed with invalid Condition");
11614 Sema::ConditionResult Res = Self.TransformCondition(
11615 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11616
11617 if (Res.isInvalid() || !Res.get().second)
11618 return;
11619
11620 ParsedClause.setConditionDetails(Res.get().second);
11621
11622 NewClause = OpenACCIfClause::Create(
11623 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11624 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11625 ParsedClause.getEndLoc());
11626}
11627
11628template <typename Derived>
11629void OpenACCClauseTransform<Derived>::VisitSelfClause(
11630 const OpenACCSelfClause &C) {
11631
11632 if (C.hasConditionExpr()) {
11633 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11634 Sema::ConditionResult Res =
11635 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11637
11638 if (Res.isInvalid() || !Res.get().second)
11639 return;
11640
11641 ParsedClause.setConditionDetails(Res.get().second);
11642 }
11643
11644 NewClause = OpenACCSelfClause::Create(
11645 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11646 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11647 ParsedClause.getEndLoc());
11648}
11649
11650template <typename Derived>
11651void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11652 const OpenACCNumGangsClause &C) {
11653 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11654
11655 for (Expr *CurIntExpr : C.getIntExprs()) {
11656 ExprResult Res = Self.TransformExpr(CurIntExpr);
11657
11658 if (!Res.isUsable())
11659 return;
11660
11661 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11662 C.getClauseKind(),
11663 C.getBeginLoc(), Res.get());
11664 if (!Res.isUsable())
11665 return;
11666
11667 InstantiatedIntExprs.push_back(Res.get());
11668 }
11669
11670 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11672 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11673 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11674 ParsedClause.getEndLoc());
11675}
11676
11677template <typename Derived>
11678void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11679 const OpenACCPrivateClause &C) {
11680 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11681 /*IsReadOnly=*/false, /*IsZero=*/false);
11682
11683 NewClause = OpenACCPrivateClause::Create(
11684 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11685 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11686 ParsedClause.getEndLoc());
11687}
11688
11689template <typename Derived>
11690void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11691 const OpenACCFirstPrivateClause &C) {
11692 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11693 /*IsReadOnly=*/false, /*IsZero=*/false);
11694
11696 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11697 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11698 ParsedClause.getEndLoc());
11699}
11700
11701template <typename Derived>
11702void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
11703 const OpenACCNoCreateClause &C) {
11704 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11705 /*IsReadOnly=*/false, /*IsZero=*/false);
11706
11708 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11709 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11710 ParsedClause.getEndLoc());
11711}
11712
11713template <typename Derived>
11714void OpenACCClauseTransform<Derived>::VisitPresentClause(
11715 const OpenACCPresentClause &C) {
11716 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11717 /*IsReadOnly=*/false, /*IsZero=*/false);
11718
11719 NewClause = OpenACCPresentClause::Create(
11720 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11721 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11722 ParsedClause.getEndLoc());
11723}
11724
11725template <typename Derived>
11726void OpenACCClauseTransform<Derived>::VisitCopyClause(
11727 const OpenACCCopyClause &C) {
11728 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11729 /*IsReadOnly=*/false, /*IsZero=*/false);
11730
11731 NewClause = OpenACCCopyClause::Create(
11732 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11733 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11734 ParsedClause.getVarList(), ParsedClause.getEndLoc());
11735}
11736
11737template <typename Derived>
11738void OpenACCClauseTransform<Derived>::VisitCopyInClause(
11739 const OpenACCCopyInClause &C) {
11740 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), C.isReadOnly(),
11741 /*IsZero=*/false);
11742
11743 NewClause = OpenACCCopyInClause::Create(
11744 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11745 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11746 ParsedClause.isReadOnly(), ParsedClause.getVarList(),
11747 ParsedClause.getEndLoc());
11748}
11749
11750template <typename Derived>
11751void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
11752 const OpenACCCopyOutClause &C) {
11753 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11754 /*IsReadOnly=*/false, C.isZero());
11755
11756 NewClause = OpenACCCopyOutClause::Create(
11757 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11758 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11759 ParsedClause.isZero(), ParsedClause.getVarList(),
11760 ParsedClause.getEndLoc());
11761}
11762
11763template <typename Derived>
11764void OpenACCClauseTransform<Derived>::VisitCreateClause(
11765 const OpenACCCreateClause &C) {
11766 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11767 /*IsReadOnly=*/false, C.isZero());
11768
11769 NewClause = OpenACCCreateClause::Create(
11770 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11771 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11772 ParsedClause.isZero(), ParsedClause.getVarList(),
11773 ParsedClause.getEndLoc());
11774}
11775template <typename Derived>
11776void OpenACCClauseTransform<Derived>::VisitAttachClause(
11777 const OpenACCAttachClause &C) {
11778 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11779
11780 // Ensure each var is a pointer type.
11781 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11782 return Self.getSema().OpenACC().CheckVarIsPointerType(
11783 OpenACCClauseKind::Attach, E);
11784 }), VarList.end());
11785
11786 ParsedClause.setVarListDetails(VarList,
11787 /*IsReadOnly=*/false, /*IsZero=*/false);
11788 NewClause = OpenACCAttachClause::Create(
11789 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11790 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11791 ParsedClause.getEndLoc());
11792}
11793
11794template <typename Derived>
11795void OpenACCClauseTransform<Derived>::VisitDetachClause(
11796 const OpenACCDetachClause &C) {
11797 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11798
11799 // Ensure each var is a pointer type.
11800 VarList.erase(
11801 std::remove_if(VarList.begin(), VarList.end(),
11802 [&](Expr *E) {
11803 return Self.getSema().OpenACC().CheckVarIsPointerType(
11804 OpenACCClauseKind::Detach, E);
11805 }),
11806 VarList.end());
11807
11808 ParsedClause.setVarListDetails(VarList,
11809 /*IsReadOnly=*/false, /*IsZero=*/false);
11810 NewClause = OpenACCDetachClause::Create(
11811 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11812 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11813 ParsedClause.getEndLoc());
11814}
11815
11816template <typename Derived>
11817void OpenACCClauseTransform<Derived>::VisitDeleteClause(
11818 const OpenACCDeleteClause &C) {
11819 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11820 /*IsReadOnly=*/false, /*IsZero=*/false);
11821 NewClause = OpenACCDeleteClause::Create(
11822 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11823 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11824 ParsedClause.getEndLoc());
11825}
11826
11827template <typename Derived>
11828void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
11829 const OpenACCUseDeviceClause &C) {
11830 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11831 /*IsReadOnly=*/false, /*IsZero=*/false);
11833 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11834 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11835 ParsedClause.getEndLoc());
11836}
11837
11838template <typename Derived>
11839void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
11840 const OpenACCDevicePtrClause &C) {
11841 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11842
11843 // Ensure each var is a pointer type.
11844 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11845 return Self.getSema().OpenACC().CheckVarIsPointerType(
11846 OpenACCClauseKind::DevicePtr, E);
11847 }), VarList.end());
11848
11849 ParsedClause.setVarListDetails(VarList,
11850 /*IsReadOnly=*/false, /*IsZero=*/false);
11852 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11853 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11854 ParsedClause.getEndLoc());
11855}
11856
11857template <typename Derived>
11858void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
11859 const OpenACCNumWorkersClause &C) {
11860 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11861 assert(IntExpr && "num_workers clause constructed with invalid int expr");
11862
11863 ExprResult Res = Self.TransformExpr(IntExpr);
11864 if (!Res.isUsable())
11865 return;
11866
11867 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11868 C.getClauseKind(),
11869 C.getBeginLoc(), Res.get());
11870 if (!Res.isUsable())
11871 return;
11872
11873 ParsedClause.setIntExprDetails(Res.get());
11875 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11876 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11877 ParsedClause.getEndLoc());
11878}
11879
11880template <typename Derived>
11881void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
11882 const OpenACCDeviceNumClause &C) {
11883 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11884 assert(IntExpr && "device_num clause constructed with invalid int expr");
11885
11886 ExprResult Res = Self.TransformExpr(IntExpr);
11887 if (!Res.isUsable())
11888 return;
11889
11890 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11891 C.getClauseKind(),
11892 C.getBeginLoc(), Res.get());
11893 if (!Res.isUsable())
11894 return;
11895
11896 ParsedClause.setIntExprDetails(Res.get());
11898 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11899 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11900 ParsedClause.getEndLoc());
11901}
11902
11903template <typename Derived>
11904void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
11905 const OpenACCVectorLengthClause &C) {
11906 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11907 assert(IntExpr && "vector_length clause constructed with invalid int expr");
11908
11909 ExprResult Res = Self.TransformExpr(IntExpr);
11910 if (!Res.isUsable())
11911 return;
11912
11913 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11914 C.getClauseKind(),
11915 C.getBeginLoc(), Res.get());
11916 if (!Res.isUsable())
11917 return;
11918
11919 ParsedClause.setIntExprDetails(Res.get());
11921 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11922 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11923 ParsedClause.getEndLoc());
11924}
11925
11926template <typename Derived>
11927void OpenACCClauseTransform<Derived>::VisitAsyncClause(
11928 const OpenACCAsyncClause &C) {
11929 if (C.hasIntExpr()) {
11930 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
11931 if (!Res.isUsable())
11932 return;
11933
11934 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11935 C.getClauseKind(),
11936 C.getBeginLoc(), Res.get());
11937 if (!Res.isUsable())
11938 return;
11939 ParsedClause.setIntExprDetails(Res.get());
11940 }
11941
11942 NewClause = OpenACCAsyncClause::Create(
11943 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11944 ParsedClause.getLParenLoc(),
11945 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
11946 : nullptr,
11947 ParsedClause.getEndLoc());
11948}
11949
11950template <typename Derived>
11951void OpenACCClauseTransform<Derived>::VisitWorkerClause(
11952 const OpenACCWorkerClause &C) {
11953 if (C.hasIntExpr()) {
11954 // restrictions on this expression are all "does it exist in certain
11955 // situations" that are not possible to be dependent, so the only check we
11956 // have is that it transforms, and is an int expression.
11957 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
11958 if (!Res.isUsable())
11959 return;
11960
11961 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11962 C.getClauseKind(),
11963 C.getBeginLoc(), Res.get());
11964 if (!Res.isUsable())
11965 return;
11966 ParsedClause.setIntExprDetails(Res.get());
11967 }
11968
11969 NewClause = OpenACCWorkerClause::Create(
11970 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11971 ParsedClause.getLParenLoc(),
11972 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
11973 : nullptr,
11974 ParsedClause.getEndLoc());
11975}
11976
11977template <typename Derived>
11978void OpenACCClauseTransform<Derived>::VisitVectorClause(
11979 const OpenACCVectorClause &C) {
11980 if (C.hasIntExpr()) {
11981 // restrictions on this expression are all "does it exist in certain
11982 // situations" that are not possible to be dependent, so the only check we
11983 // have is that it transforms, and is an int expression.
11984 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
11985 if (!Res.isUsable())
11986 return;
11987
11988 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11989 C.getClauseKind(),
11990 C.getBeginLoc(), Res.get());
11991 if (!Res.isUsable())
11992 return;
11993 ParsedClause.setIntExprDetails(Res.get());
11994 }
11995
11996 NewClause = OpenACCVectorClause::Create(
11997 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11998 ParsedClause.getLParenLoc(),
11999 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12000 : nullptr,
12001 ParsedClause.getEndLoc());
12002}
12003
12004template <typename Derived>
12005void OpenACCClauseTransform<Derived>::VisitWaitClause(
12006 const OpenACCWaitClause &C) {
12007 if (!C.getLParenLoc().isInvalid()) {
12008 Expr *DevNumExpr = nullptr;
12009 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12010
12011 // Instantiate devnum expr if it exists.
12012 if (C.getDevNumExpr()) {
12013 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12014 if (!Res.isUsable())
12015 return;
12016 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12017 C.getClauseKind(),
12018 C.getBeginLoc(), Res.get());
12019 if (!Res.isUsable())
12020 return;
12021
12022 DevNumExpr = Res.get();
12023 }
12024
12025 // Instantiate queue ids.
12026 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12027 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12028 if (!Res.isUsable())
12029 return;
12030 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12031 C.getClauseKind(),
12032 C.getBeginLoc(), Res.get());
12033 if (!Res.isUsable())
12034 return;
12035
12036 InstantiatedQueueIdExprs.push_back(Res.get());
12037 }
12038
12039 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12040 std::move(InstantiatedQueueIdExprs));
12041 }
12042
12043 NewClause = OpenACCWaitClause::Create(
12044 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12045 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12046 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12047 ParsedClause.getEndLoc());
12048}
12049
12050template <typename Derived>
12051void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12052 const OpenACCDeviceTypeClause &C) {
12053 // Nothing to transform here, just create a new version of 'C'.
12055 Self.getSema().getASTContext(), C.getClauseKind(),
12056 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12057 C.getArchitectures(), ParsedClause.getEndLoc());
12058}
12059
12060template <typename Derived>
12061void OpenACCClauseTransform<Derived>::VisitAutoClause(
12062 const OpenACCAutoClause &C) {
12063 // Nothing to do, so just create a new node.
12064 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12065 ParsedClause.getBeginLoc(),
12066 ParsedClause.getEndLoc());
12067}
12068
12069template <typename Derived>
12070void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12071 const OpenACCIndependentClause &C) {
12072 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12073 ParsedClause.getBeginLoc(),
12074 ParsedClause.getEndLoc());
12075}
12076
12077template <typename Derived>
12078void OpenACCClauseTransform<Derived>::VisitSeqClause(
12079 const OpenACCSeqClause &C) {
12080 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12081 ParsedClause.getBeginLoc(),
12082 ParsedClause.getEndLoc());
12083}
12084template <typename Derived>
12085void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12086 const OpenACCFinalizeClause &C) {
12087 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12088 ParsedClause.getBeginLoc(),
12089 ParsedClause.getEndLoc());
12090}
12091
12092template <typename Derived>
12093void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12094 const OpenACCIfPresentClause &C) {
12095 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12096 ParsedClause.getBeginLoc(),
12097 ParsedClause.getEndLoc());
12098}
12099
12100template <typename Derived>
12101void OpenACCClauseTransform<Derived>::VisitReductionClause(
12102 const OpenACCReductionClause &C) {
12103 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12104 SmallVector<Expr *> ValidVars;
12105
12106 for (Expr *Var : TransformedVars) {
12107 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12108 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12109 if (Res.isUsable())
12110 ValidVars.push_back(Res.get());
12111 }
12112
12113 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12114 ExistingClauses, ParsedClause.getDirectiveKind(),
12115 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12116 C.getReductionOp(), ValidVars, ParsedClause.getEndLoc());
12117}
12118
12119template <typename Derived>
12120void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12121 const OpenACCCollapseClause &C) {
12122 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12123 assert(LoopCount && "collapse clause constructed with invalid loop count");
12124
12125 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12126
12127 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12129 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12130
12131 NewLoopCount =
12132 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12133
12134 if (!NewLoopCount.isUsable())
12135 return;
12136
12137 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12139 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12140 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12141 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12142}
12143
12144template <typename Derived>
12145void OpenACCClauseTransform<Derived>::VisitTileClause(
12146 const OpenACCTileClause &C) {
12147
12148 llvm::SmallVector<Expr *> TransformedExprs;
12149
12150 for (Expr *E : C.getSizeExprs()) {
12151 ExprResult NewSizeExpr = Self.TransformExpr(E);
12152
12153 if (!NewSizeExpr.isUsable())
12154 return;
12155
12156 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12158 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12159
12160 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12161
12162 if (!NewSizeExpr.isUsable())
12163 return;
12164 TransformedExprs.push_back(NewSizeExpr.get());
12165 }
12166
12167 ParsedClause.setIntExprDetails(TransformedExprs);
12168 NewClause = OpenACCTileClause::Create(
12169 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12170 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12171 ParsedClause.getEndLoc());
12172}
12173template <typename Derived>
12174void OpenACCClauseTransform<Derived>::VisitGangClause(
12175 const OpenACCGangClause &C) {
12176 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12177 llvm::SmallVector<Expr *> TransformedIntExprs;
12178
12179 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12180 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12181 if (!ER.isUsable())
12182 continue;
12183
12184 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12185 ParsedClause.getDirectiveKind(),
12186 C.getExpr(I).first, ER.get());
12187 if (!ER.isUsable())
12188 continue;
12189 TransformedGangKinds.push_back(C.getExpr(I).first);
12190 TransformedIntExprs.push_back(ER.get());
12191 }
12192
12193 NewClause = Self.getSema().OpenACC().CheckGangClause(
12194 ParsedClause.getDirectiveKind(), ExistingClauses,
12195 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12196 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12197}
12198} // namespace
12199template <typename Derived>
12200OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12201 ArrayRef<const OpenACCClause *> ExistingClauses,
12202 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12203
12204 SemaOpenACC::OpenACCParsedClause ParsedClause(
12205 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12206 ParsedClause.setEndLoc(OldClause->getEndLoc());
12207
12208 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12209 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12210
12211 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12212 ParsedClause};
12213 Transform.Visit(OldClause);
12214
12215 return Transform.CreatedClause();
12216}
12217
12218template <typename Derived>
12220TreeTransform<Derived>::TransformOpenACCClauseList(
12222 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12223 for (const auto *Clause : OldClauses) {
12224 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12225 TransformedClauses, DirKind, Clause))
12226 TransformedClauses.push_back(TransformedClause);
12227 }
12228 return TransformedClauses;
12229}
12230
12231template <typename Derived>
12232StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
12233 OpenACCComputeConstruct *C) {
12234 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12235
12236 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12237 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12238 C->clauses());
12239
12240 if (getSema().OpenACC().ActOnStartStmtDirective(
12241 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12242 return StmtError();
12243
12244 // Transform Structured Block.
12245 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12246 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12247 C->clauses(), TransformedClauses);
12248 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12249 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12250 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12251
12252 return getDerived().RebuildOpenACCComputeConstruct(
12253 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12254 C->getEndLoc(), TransformedClauses, StrBlock);
12255}
12256
12257template <typename Derived>
12259TreeTransform<Derived>::TransformOpenACCLoopConstruct(OpenACCLoopConstruct *C) {
12260
12261 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12262
12263 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12264 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12265 C->clauses());
12266
12267 if (getSema().OpenACC().ActOnStartStmtDirective(
12268 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12269 return StmtError();
12270
12271 // Transform Loop.
12272 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12273 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12274 C->clauses(), TransformedClauses);
12275 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12276 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12277 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12278
12279 return getDerived().RebuildOpenACCLoopConstruct(
12280 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12281 TransformedClauses, Loop);
12282}
12283
12284template <typename Derived>
12285StmtResult TreeTransform<Derived>::TransformOpenACCCombinedConstruct(
12286 OpenACCCombinedConstruct *C) {
12287 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12288
12289 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12290 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12291 C->clauses());
12292
12293 if (getSema().OpenACC().ActOnStartStmtDirective(
12294 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12295 return StmtError();
12296
12297 // Transform Loop.
12298 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12299 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12300 C->clauses(), TransformedClauses);
12301 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12302 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12303 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12304
12305 return getDerived().RebuildOpenACCCombinedConstruct(
12306 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12307 C->getEndLoc(), TransformedClauses, Loop);
12308}
12309
12310template <typename Derived>
12312TreeTransform<Derived>::TransformOpenACCDataConstruct(OpenACCDataConstruct *C) {
12313 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12314
12315 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12316 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12317 C->clauses());
12318 if (getSema().OpenACC().ActOnStartStmtDirective(
12319 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12320 return StmtError();
12321
12322 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12323 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12324 C->clauses(), TransformedClauses);
12325 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12326 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12327 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12328
12329 return getDerived().RebuildOpenACCDataConstruct(
12330 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12331 TransformedClauses, StrBlock);
12332}
12333
12334template <typename Derived>
12335StmtResult TreeTransform<Derived>::TransformOpenACCEnterDataConstruct(
12336 OpenACCEnterDataConstruct *C) {
12337 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12338
12339 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12340 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12341 C->clauses());
12342 if (getSema().OpenACC().ActOnStartStmtDirective(
12343 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12344 return StmtError();
12345
12346 return getDerived().RebuildOpenACCEnterDataConstruct(
12347 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12348 TransformedClauses);
12349}
12350
12351template <typename Derived>
12352StmtResult TreeTransform<Derived>::TransformOpenACCExitDataConstruct(
12353 OpenACCExitDataConstruct *C) {
12354 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12355
12356 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12357 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12358 C->clauses());
12359 if (getSema().OpenACC().ActOnStartStmtDirective(
12360 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12361 return StmtError();
12362
12363 return getDerived().RebuildOpenACCExitDataConstruct(
12364 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12365 TransformedClauses);
12366}
12367
12368template <typename Derived>
12369StmtResult TreeTransform<Derived>::TransformOpenACCHostDataConstruct(
12370 OpenACCHostDataConstruct *C) {
12371 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12372
12373 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12374 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12375 C->clauses());
12376 if (getSema().OpenACC().ActOnStartStmtDirective(
12377 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12378 return StmtError();
12379
12380 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12381 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12382 C->clauses(), TransformedClauses);
12383 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12384 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12385 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12386
12387 return getDerived().RebuildOpenACCHostDataConstruct(
12388 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12389 TransformedClauses, StrBlock);
12390}
12391
12392template <typename Derived>
12394TreeTransform<Derived>::TransformOpenACCInitConstruct(OpenACCInitConstruct *C) {
12395 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12396
12397 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12398 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12399 C->clauses());
12400 if (getSema().OpenACC().ActOnStartStmtDirective(
12401 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12402 return StmtError();
12403
12404 return getDerived().RebuildOpenACCInitConstruct(
12405 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12406 TransformedClauses);
12407}
12408
12409template <typename Derived>
12410StmtResult TreeTransform<Derived>::TransformOpenACCShutdownConstruct(
12411 OpenACCShutdownConstruct *C) {
12412 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12413
12414 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12415 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12416 C->clauses());
12417 if (getSema().OpenACC().ActOnStartStmtDirective(
12418 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12419 return StmtError();
12420
12421 return getDerived().RebuildOpenACCShutdownConstruct(
12422 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12423 TransformedClauses);
12424}
12425
12426template <typename Derived>
12428TreeTransform<Derived>::TransformOpenACCWaitConstruct(OpenACCWaitConstruct *C) {
12429 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12430
12431 ExprResult DevNumExpr;
12432 if (C->hasDevNumExpr()) {
12433 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
12434
12435 if (DevNumExpr.isUsable())
12436 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
12438 C->getBeginLoc(), DevNumExpr.get());
12439 }
12440
12441 llvm::SmallVector<Expr *> QueueIdExprs;
12442
12443 for (Expr *QE : C->getQueueIdExprs()) {
12444 assert(QE && "Null queue id expr?");
12445 ExprResult NewEQ = getDerived().TransformExpr(QE);
12446
12447 if (!NewEQ.isUsable())
12448 break;
12449 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
12451 C->getBeginLoc(), NewEQ.get());
12452 if (NewEQ.isUsable())
12453 QueueIdExprs.push_back(NewEQ.get());
12454 }
12455
12456 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12457 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12458 C->clauses());
12459
12460 if (getSema().OpenACC().ActOnStartStmtDirective(
12461 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12462 return StmtError();
12463
12464 return getDerived().RebuildOpenACCWaitConstruct(
12465 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12466 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
12467 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
12468}
12469
12470template <typename Derived>
12471ExprResult TreeTransform<Derived>::TransformOpenACCAsteriskSizeExpr(
12472 OpenACCAsteriskSizeExpr *E) {
12473 if (getDerived().AlwaysRebuild())
12474 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
12475 // Nothing can ever change, so there is never anything to transform.
12476 return E;
12477}
12478
12479//===----------------------------------------------------------------------===//
12480// Expression transformation
12481//===----------------------------------------------------------------------===//
12482template<typename Derived>
12484TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
12485 return TransformExpr(E->getSubExpr());
12486}
12487
12488template <typename Derived>
12489ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
12490 SYCLUniqueStableNameExpr *E) {
12491 if (!E->isTypeDependent())
12492 return E;
12493
12494 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
12495
12496 if (!NewT)
12497 return ExprError();
12498
12499 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
12500 return E;
12501
12502 return getDerived().RebuildSYCLUniqueStableNameExpr(
12503 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
12504}
12505
12506template<typename Derived>
12508TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
12509 if (!E->isTypeDependent())
12510 return E;
12511
12512 return getDerived().RebuildPredefinedExpr(E->getLocation(),
12513 E->getIdentKind());
12514}
12515
12516template<typename Derived>
12518TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
12519 NestedNameSpecifierLoc QualifierLoc;
12520 if (E->getQualifierLoc()) {
12521 QualifierLoc
12522 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12523 if (!QualifierLoc)
12524 return ExprError();
12525 }
12526
12527 ValueDecl *ND
12528 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
12529 E->getDecl()));
12530 if (!ND)
12531 return ExprError();
12532
12533 NamedDecl *Found = ND;
12534 if (E->getFoundDecl() != E->getDecl()) {
12535 Found = cast_or_null<NamedDecl>(
12536 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
12537 if (!Found)
12538 return ExprError();
12539 }
12540
12541 DeclarationNameInfo NameInfo = E->getNameInfo();
12542 if (NameInfo.getName()) {
12543 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
12544 if (!NameInfo.getName())
12545 return ExprError();
12546 }
12547
12548 if (!getDerived().AlwaysRebuild() &&
12549 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
12550 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
12551 Found == E->getFoundDecl() &&
12552 NameInfo.getName() == E->getDecl()->getDeclName() &&
12553 !E->hasExplicitTemplateArgs()) {
12554
12555 // Mark it referenced in the new context regardless.
12556 // FIXME: this is a bit instantiation-specific.
12557 SemaRef.MarkDeclRefReferenced(E);
12558
12559 return E;
12560 }
12561
12562 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
12563 if (E->hasExplicitTemplateArgs()) {
12564 TemplateArgs = &TransArgs;
12565 TransArgs.setLAngleLoc(E->getLAngleLoc());
12566 TransArgs.setRAngleLoc(E->getRAngleLoc());
12567 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
12568 E->getNumTemplateArgs(),
12569 TransArgs))
12570 return ExprError();
12571 }
12572
12573 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
12574 Found, TemplateArgs);
12575}
12576
12577template<typename Derived>
12579TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
12580 return E;
12581}
12582
12583template <typename Derived>
12584ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
12585 FixedPointLiteral *E) {
12586 return E;
12587}
12588
12589template<typename Derived>
12591TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
12592 return E;
12593}
12594
12595template<typename Derived>
12597TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
12598 return E;
12599}
12600
12601template<typename Derived>
12603TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
12604 return E;
12605}
12606
12607template<typename Derived>
12609TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
12610 return E;
12611}
12612
12613template<typename Derived>
12615TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
12616 return getDerived().TransformCallExpr(E);
12617}
12618
12619template<typename Derived>
12621TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
12622 ExprResult ControllingExpr;
12623 TypeSourceInfo *ControllingType = nullptr;
12624 if (E->isExprPredicate())
12625 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
12626 else
12627 ControllingType = getDerived().TransformType(E->getControllingType());
12628
12629 if (ControllingExpr.isInvalid() && !ControllingType)
12630 return ExprError();
12631
12632 SmallVector<Expr *, 4> AssocExprs;
12634 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
12635 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
12636 if (TSI) {
12637 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
12638 if (!AssocType)
12639 return ExprError();
12640 AssocTypes.push_back(AssocType);
12641 } else {
12642 AssocTypes.push_back(nullptr);
12643 }
12644
12645 ExprResult AssocExpr =
12646 getDerived().TransformExpr(Assoc.getAssociationExpr());
12647 if (AssocExpr.isInvalid())
12648 return ExprError();
12649 AssocExprs.push_back(AssocExpr.get());
12650 }
12651
12652 if (!ControllingType)
12653 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
12654 E->getDefaultLoc(),
12655 E->getRParenLoc(),
12656 ControllingExpr.get(),
12657 AssocTypes,
12658 AssocExprs);
12659 return getDerived().RebuildGenericSelectionExpr(
12660 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
12661 ControllingType, AssocTypes, AssocExprs);
12662}
12663
12664template<typename Derived>
12666TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
12667 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12668 if (SubExpr.isInvalid())
12669 return ExprError();
12670
12671 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
12672 return E;
12673
12674 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
12675 E->getRParen());
12676}
12677
12678/// The operand of a unary address-of operator has special rules: it's
12679/// allowed to refer to a non-static member of a class even if there's no 'this'
12680/// object available.
12681template<typename Derived>
12684 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
12685 return getDerived().TransformDependentScopeDeclRefExpr(
12686 DRE, /*IsAddressOfOperand=*/true, nullptr);
12687 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
12688 return getDerived().TransformUnresolvedLookupExpr(
12689 ULE, /*IsAddressOfOperand=*/true);
12690 else
12691 return getDerived().TransformExpr(E);
12692}
12693
12694template<typename Derived>
12697 ExprResult SubExpr;
12698 if (E->getOpcode() == UO_AddrOf)
12699 SubExpr = TransformAddressOfOperand(E->getSubExpr());
12700 else
12701 SubExpr = TransformExpr(E->getSubExpr());
12702 if (SubExpr.isInvalid())
12703 return ExprError();
12704
12705 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
12706 return E;
12707
12708 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
12709 E->getOpcode(),
12710 SubExpr.get());
12711}
12712
12713template<typename Derived>
12715TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
12716 // Transform the type.
12717 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12718 if (!Type)
12719 return ExprError();
12720
12721 // Transform all of the components into components similar to what the
12722 // parser uses.
12723 // FIXME: It would be slightly more efficient in the non-dependent case to
12724 // just map FieldDecls, rather than requiring the rebuilder to look for
12725 // the fields again. However, __builtin_offsetof is rare enough in
12726 // template code that we don't care.
12727 bool ExprChanged = false;
12728 typedef Sema::OffsetOfComponent Component;
12729 SmallVector<Component, 4> Components;
12730 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
12731 const OffsetOfNode &ON = E->getComponent(I);
12732 Component Comp;
12733 Comp.isBrackets = true;
12734 Comp.LocStart = ON.getSourceRange().getBegin();
12735 Comp.LocEnd = ON.getSourceRange().getEnd();
12736 switch (ON.getKind()) {
12737 case OffsetOfNode::Array: {
12738 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
12739 ExprResult Index = getDerived().TransformExpr(FromIndex);
12740 if (Index.isInvalid())
12741 return ExprError();
12742
12743 ExprChanged = ExprChanged || Index.get() != FromIndex;
12744 Comp.isBrackets = true;
12745 Comp.U.E = Index.get();
12746 break;
12747 }
12748
12751 Comp.isBrackets = false;
12752 Comp.U.IdentInfo = ON.getFieldName();
12753 if (!Comp.U.IdentInfo)
12754 continue;
12755
12756 break;
12757
12758 case OffsetOfNode::Base:
12759 // Will be recomputed during the rebuild.
12760 continue;
12761 }
12762
12763 Components.push_back(Comp);
12764 }
12765
12766 // If nothing changed, retain the existing expression.
12767 if (!getDerived().AlwaysRebuild() &&
12768 Type == E->getTypeSourceInfo() &&
12769 !ExprChanged)
12770 return E;
12771
12772 // Build a new offsetof expression.
12773 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
12774 Components, E->getRParenLoc());
12775}
12776
12777template<typename Derived>
12779TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
12780 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
12781 "opaque value expression requires transformation");
12782 return E;
12783}
12784
12785template<typename Derived>
12787TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
12788 return E;
12789}
12790
12791template <typename Derived>
12792ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) {
12794 bool Changed = false;
12795 for (Expr *C : E->subExpressions()) {
12796 ExprResult NewC = getDerived().TransformExpr(C);
12797 if (NewC.isInvalid())
12798 return ExprError();
12799 Children.push_back(NewC.get());
12800
12801 Changed |= NewC.get() != C;
12802 }
12803 if (!getDerived().AlwaysRebuild() && !Changed)
12804 return E;
12805 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
12806 Children, E->getType());
12807}
12808
12809template<typename Derived>
12811TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
12812 // Rebuild the syntactic form. The original syntactic form has
12813 // opaque-value expressions in it, so strip those away and rebuild
12814 // the result. This is a really awful way of doing this, but the
12815 // better solution (rebuilding the semantic expressions and
12816 // rebinding OVEs as necessary) doesn't work; we'd need
12817 // TreeTransform to not strip away implicit conversions.
12818 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
12819 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
12820 if (result.isInvalid()) return ExprError();
12821
12822 // If that gives us a pseudo-object result back, the pseudo-object
12823 // expression must have been an lvalue-to-rvalue conversion which we
12824 // should reapply.
12825 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
12826 result = SemaRef.PseudoObject().checkRValue(result.get());
12827
12828 return result;
12829}
12830
12831template<typename Derived>
12833TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
12834 UnaryExprOrTypeTraitExpr *E) {
12835 if (E->isArgumentType()) {
12836 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
12837
12838 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
12839 if (!NewT)
12840 return ExprError();
12841
12842 if (!getDerived().AlwaysRebuild() && OldT == NewT)
12843 return E;
12844
12845 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
12846 E->getKind(),
12847 E->getSourceRange());
12848 }
12849
12850 // C++0x [expr.sizeof]p1:
12851 // The operand is either an expression, which is an unevaluated operand
12852 // [...]
12853 EnterExpressionEvaluationContext Unevaluated(
12856
12857 // Try to recover if we have something like sizeof(T::X) where X is a type.
12858 // Notably, there must be *exactly* one set of parens if X is a type.
12859 TypeSourceInfo *RecoveryTSI = nullptr;
12860 ExprResult SubExpr;
12861 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
12862 if (auto *DRE =
12863 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
12864 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
12865 PE, DRE, false, &RecoveryTSI);
12866 else
12867 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
12868
12869 if (RecoveryTSI) {
12870 return getDerived().RebuildUnaryExprOrTypeTrait(
12871 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
12872 } else if (SubExpr.isInvalid())
12873 return ExprError();
12874
12875 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
12876 return E;
12877
12878 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
12879 E->getOperatorLoc(),
12880 E->getKind(),
12881 E->getSourceRange());
12882}
12883
12884template<typename Derived>
12886TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
12887 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
12888 if (LHS.isInvalid())
12889 return ExprError();
12890
12891 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
12892 if (RHS.isInvalid())
12893 return ExprError();
12894
12895
12896 if (!getDerived().AlwaysRebuild() &&
12897 LHS.get() == E->getLHS() &&
12898 RHS.get() == E->getRHS())
12899 return E;
12900
12901 return getDerived().RebuildArraySubscriptExpr(
12902 LHS.get(),
12903 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
12904}
12905
12906template <typename Derived>
12908TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
12909 ExprResult Base = getDerived().TransformExpr(E->getBase());
12910 if (Base.isInvalid())
12911 return ExprError();
12912
12913 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
12914 if (RowIdx.isInvalid())
12915 return ExprError();
12916
12917 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
12918 if (ColumnIdx.isInvalid())
12919 return ExprError();
12920
12921 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
12922 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
12923 return E;
12924
12925 return getDerived().RebuildMatrixSubscriptExpr(
12926 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
12927}
12928
12929template <typename Derived>
12931TreeTransform<Derived>::TransformArraySectionExpr(ArraySectionExpr *E) {
12932 ExprResult Base = getDerived().TransformExpr(E->getBase());
12933 if (Base.isInvalid())
12934 return ExprError();
12935
12936 ExprResult LowerBound;
12937 if (E->getLowerBound()) {
12938 LowerBound = getDerived().TransformExpr(E->getLowerBound());
12939 if (LowerBound.isInvalid())
12940 return ExprError();
12941 }
12942
12943 ExprResult Length;
12944 if (E->getLength()) {
12945 Length = getDerived().TransformExpr(E->getLength());
12946 if (Length.isInvalid())
12947 return ExprError();
12948 }
12949
12950 ExprResult Stride;
12951 if (E->isOMPArraySection()) {
12952 if (Expr *Str = E->getStride()) {
12953 Stride = getDerived().TransformExpr(Str);
12954 if (Stride.isInvalid())
12955 return ExprError();
12956 }
12957 }
12958
12959 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
12960 LowerBound.get() == E->getLowerBound() &&
12961 Length.get() == E->getLength() &&
12962 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
12963 return E;
12964
12965 return getDerived().RebuildArraySectionExpr(
12966 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
12967 LowerBound.get(), E->getColonLocFirst(),
12968 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
12969 Length.get(), Stride.get(), E->getRBracketLoc());
12970}
12971
12972template <typename Derived>
12974TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
12975 ExprResult Base = getDerived().TransformExpr(E->getBase());
12976 if (Base.isInvalid())
12977 return ExprError();
12978
12980 bool ErrorFound = false;
12981 for (Expr *Dim : E->getDimensions()) {
12982 ExprResult DimRes = getDerived().TransformExpr(Dim);
12983 if (DimRes.isInvalid()) {
12984 ErrorFound = true;
12985 continue;
12986 }
12987 Dims.push_back(DimRes.get());
12988 }
12989
12990 if (ErrorFound)
12991 return ExprError();
12992 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
12993 E->getRParenLoc(), Dims,
12994 E->getBracketsRanges());
12995}
12996
12997template <typename Derived>
12999TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) {
13000 unsigned NumIterators = E->numOfIterators();
13002
13003 bool ErrorFound = false;
13004 bool NeedToRebuild = getDerived().AlwaysRebuild();
13005 for (unsigned I = 0; I < NumIterators; ++I) {
13006 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13007 Data[I].DeclIdent = D->getIdentifier();
13008 Data[I].DeclIdentLoc = D->getLocation();
13009 if (D->getLocation() == D->getBeginLoc()) {
13010 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13011 "Implicit type must be int.");
13012 } else {
13013 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13014 QualType DeclTy = getDerived().TransformType(D->getType());
13015 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13016 }
13017 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13018 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13019 ExprResult End = getDerived().TransformExpr(Range.End);
13020 ExprResult Step = getDerived().TransformExpr(Range.Step);
13021 ErrorFound = ErrorFound ||
13022 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13023 !Data[I].Type.get().isNull())) ||
13024 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13025 if (ErrorFound)
13026 continue;
13027 Data[I].Range.Begin = Begin.get();
13028 Data[I].Range.End = End.get();
13029 Data[I].Range.Step = Step.get();
13030 Data[I].AssignLoc = E->getAssignLoc(I);
13031 Data[I].ColonLoc = E->getColonLoc(I);
13032 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13033 NeedToRebuild =
13034 NeedToRebuild ||
13035 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13036 D->getType().getTypePtrOrNull()) ||
13037 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13038 Range.Step != Data[I].Range.Step;
13039 }
13040 if (ErrorFound)
13041 return ExprError();
13042 if (!NeedToRebuild)
13043 return E;
13044
13045 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13046 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13047 if (!Res.isUsable())
13048 return Res;
13049 auto *IE = cast<OMPIteratorExpr>(Res.get());
13050 for (unsigned I = 0; I < NumIterators; ++I)
13051 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13052 IE->getIteratorDecl(I));
13053 return Res;
13054}
13055
13056template<typename Derived>
13058TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
13059 // Transform the callee.
13060 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13061 if (Callee.isInvalid())
13062 return ExprError();
13063
13064 // Transform arguments.
13065 bool ArgChanged = false;
13067 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13068 &ArgChanged))
13069 return ExprError();
13070
13071 if (!getDerived().AlwaysRebuild() &&
13072 Callee.get() == E->getCallee() &&
13073 !ArgChanged)
13074 return SemaRef.MaybeBindToTemporary(E);
13075
13076 // FIXME: Wrong source location information for the '('.
13077 SourceLocation FakeLParenLoc
13078 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13079
13080 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13081 if (E->hasStoredFPFeatures()) {
13082 FPOptionsOverride NewOverrides = E->getFPFeatures();
13083 getSema().CurFPFeatures =
13084 NewOverrides.applyOverrides(getSema().getLangOpts());
13085 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13086 }
13087
13088 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13089 Args,
13090 E->getRParenLoc());
13091}
13092
13093template<typename Derived>
13095TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
13096 ExprResult Base = getDerived().TransformExpr(E->getBase());
13097 if (Base.isInvalid())
13098 return ExprError();
13099
13100 NestedNameSpecifierLoc QualifierLoc;
13101 if (E->hasQualifier()) {
13102 QualifierLoc
13103 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13104
13105 if (!QualifierLoc)
13106 return ExprError();
13107 }
13108 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13109
13110 ValueDecl *Member
13111 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
13112 E->getMemberDecl()));
13113 if (!Member)
13114 return ExprError();
13115
13116 NamedDecl *FoundDecl = E->getFoundDecl();
13117 if (FoundDecl == E->getMemberDecl()) {
13118 FoundDecl = Member;
13119 } else {
13120 FoundDecl = cast_or_null<NamedDecl>(
13121 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
13122 if (!FoundDecl)
13123 return ExprError();
13124 }
13125
13126 if (!getDerived().AlwaysRebuild() &&
13127 Base.get() == E->getBase() &&
13128 QualifierLoc == E->getQualifierLoc() &&
13129 Member == E->getMemberDecl() &&
13130 FoundDecl == E->getFoundDecl() &&
13131 !E->hasExplicitTemplateArgs()) {
13132
13133 // Skip for member expression of (this->f), rebuilt thisi->f is needed
13134 // for Openmp where the field need to be privatizized in the case.
13135 if (!(isa<CXXThisExpr>(E->getBase()) &&
13136 getSema().OpenMP().isOpenMPRebuildMemberExpr(
13137 cast<ValueDecl>(Member)))) {
13138 // Mark it referenced in the new context regardless.
13139 // FIXME: this is a bit instantiation-specific.
13140 SemaRef.MarkMemberReferenced(E);
13141 return E;
13142 }
13143 }
13144
13145 TemplateArgumentListInfo TransArgs;
13146 if (E->hasExplicitTemplateArgs()) {
13147 TransArgs.setLAngleLoc(E->getLAngleLoc());
13148 TransArgs.setRAngleLoc(E->getRAngleLoc());
13149 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13150 E->getNumTemplateArgs(),
13151 TransArgs))
13152 return ExprError();
13153 }
13154
13155 // FIXME: Bogus source location for the operator
13156 SourceLocation FakeOperatorLoc =
13157 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
13158
13159 // FIXME: to do this check properly, we will need to preserve the
13160 // first-qualifier-in-scope here, just in case we had a dependent
13161 // base (and therefore couldn't do the check) and a
13162 // nested-name-qualifier (and therefore could do the lookup).
13163 NamedDecl *FirstQualifierInScope = nullptr;
13164 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
13165 if (MemberNameInfo.getName()) {
13166 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
13167 if (!MemberNameInfo.getName())
13168 return ExprError();
13169 }
13170
13171 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
13172 E->isArrow(),
13173 QualifierLoc,
13174 TemplateKWLoc,
13175 MemberNameInfo,
13176 Member,
13177 FoundDecl,
13178 (E->hasExplicitTemplateArgs()
13179 ? &TransArgs : nullptr),
13180 FirstQualifierInScope);
13181}
13182
13183template<typename Derived>
13185TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
13186 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13187 if (LHS.isInvalid())
13188 return ExprError();
13189
13190 ExprResult RHS =
13191 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
13192 if (RHS.isInvalid())
13193 return ExprError();
13194
13195 if (!getDerived().AlwaysRebuild() &&
13196 LHS.get() == E->getLHS() &&
13197 RHS.get() == E->getRHS())
13198 return E;
13199
13200 if (E->isCompoundAssignmentOp())
13201 // FPFeatures has already been established from trailing storage
13202 return getDerived().RebuildBinaryOperator(
13203 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
13204 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13205 FPOptionsOverride NewOverrides(E->getFPFeatures());
13206 getSema().CurFPFeatures =
13207 NewOverrides.applyOverrides(getSema().getLangOpts());
13208 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13209 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
13210 LHS.get(), RHS.get());
13211}
13212
13213template <typename Derived>
13214ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
13215 CXXRewrittenBinaryOperator *E) {
13216 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
13217
13218 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
13219 if (LHS.isInvalid())
13220 return ExprError();
13221
13222 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
13223 if (RHS.isInvalid())
13224 return ExprError();
13225
13226 // Extract the already-resolved callee declarations so that we can restrict
13227 // ourselves to using them as the unqualified lookup results when rebuilding.
13228 UnresolvedSet<2> UnqualLookups;
13229 bool ChangedAnyLookups = false;
13230 Expr *PossibleBinOps[] = {E->getSemanticForm(),
13231 const_cast<Expr *>(Decomp.InnerBinOp)};
13232 for (Expr *PossibleBinOp : PossibleBinOps) {
13233 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
13234 if (!Op)
13235 continue;
13236 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
13237 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
13238 continue;
13239
13240 // Transform the callee in case we built a call to a local extern
13241 // declaration.
13242 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
13243 E->getOperatorLoc(), Callee->getFoundDecl()));
13244 if (!Found)
13245 return ExprError();
13246 if (Found != Callee->getFoundDecl())
13247 ChangedAnyLookups = true;
13248 UnqualLookups.addDecl(Found);
13249 }
13250
13251 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
13252 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
13253 // Mark all functions used in the rewrite as referenced. Note that when
13254 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
13255 // function calls, and/or there might be a user-defined conversion sequence
13256 // applied to the operands of the <.
13257 // FIXME: this is a bit instantiation-specific.
13258 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
13259 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
13260 return E;
13261 }
13262
13263 return getDerived().RebuildCXXRewrittenBinaryOperator(
13264 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
13265}
13266
13267template<typename Derived>
13269TreeTransform<Derived>::TransformCompoundAssignOperator(
13270 CompoundAssignOperator *E) {
13271 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13272 FPOptionsOverride NewOverrides(E->getFPFeatures());
13273 getSema().CurFPFeatures =
13274 NewOverrides.applyOverrides(getSema().getLangOpts());
13275 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13276 return getDerived().TransformBinaryOperator(E);
13277}
13278
13279template<typename Derived>
13280ExprResult TreeTransform<Derived>::
13281TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
13282 // Just rebuild the common and RHS expressions and see whether we
13283 // get any changes.
13284
13285 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
13286 if (commonExpr.isInvalid())
13287 return ExprError();
13288
13289 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
13290 if (rhs.isInvalid())
13291 return ExprError();
13292
13293 if (!getDerived().AlwaysRebuild() &&
13294 commonExpr.get() == e->getCommon() &&
13295 rhs.get() == e->getFalseExpr())
13296 return e;
13297
13298 return getDerived().RebuildConditionalOperator(commonExpr.get(),
13299 e->getQuestionLoc(),
13300 nullptr,
13301 e->getColonLoc(),
13302 rhs.get());
13303}
13304
13305template<typename Derived>
13307TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
13308 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13309 if (Cond.isInvalid())
13310 return ExprError();
13311
13312 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13313 if (LHS.isInvalid())
13314 return ExprError();
13315
13316 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13317 if (RHS.isInvalid())
13318 return ExprError();
13319
13320 if (!getDerived().AlwaysRebuild() &&
13321 Cond.get() == E->getCond() &&
13322 LHS.get() == E->getLHS() &&
13323 RHS.get() == E->getRHS())
13324 return E;
13325
13326 return getDerived().RebuildConditionalOperator(Cond.get(),
13327 E->getQuestionLoc(),
13328 LHS.get(),
13329 E->getColonLoc(),
13330 RHS.get());
13331}
13332
13333template<typename Derived>
13335TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
13336 // Implicit casts are eliminated during transformation, since they
13337 // will be recomputed by semantic analysis after transformation.
13338 return getDerived().TransformExpr(E->getSubExprAsWritten());
13339}
13340
13341template<typename Derived>
13343TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
13344 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13345 if (!Type)
13346 return ExprError();
13347
13348 ExprResult SubExpr
13349 = getDerived().TransformExpr(E->getSubExprAsWritten());
13350 if (SubExpr.isInvalid())
13351 return ExprError();
13352
13353 if (!getDerived().AlwaysRebuild() &&
13354 Type == E->getTypeInfoAsWritten() &&
13355 SubExpr.get() == E->getSubExpr())
13356 return E;
13357
13358 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
13359 Type,
13360 E->getRParenLoc(),
13361 SubExpr.get());
13362}
13363
13364template<typename Derived>
13366TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
13367 TypeSourceInfo *OldT = E->getTypeSourceInfo();
13368 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13369 if (!NewT)
13370 return ExprError();
13371
13372 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
13373 if (Init.isInvalid())
13374 return ExprError();
13375
13376 if (!getDerived().AlwaysRebuild() &&
13377 OldT == NewT &&
13378 Init.get() == E->getInitializer())
13379 return SemaRef.MaybeBindToTemporary(E);
13380
13381 // Note: the expression type doesn't necessarily match the
13382 // type-as-written, but that's okay, because it should always be
13383 // derivable from the initializer.
13384
13385 return getDerived().RebuildCompoundLiteralExpr(
13386 E->getLParenLoc(), NewT,
13387 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
13388}
13389
13390template<typename Derived>
13392TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
13393 ExprResult Base = getDerived().TransformExpr(E->getBase());
13394 if (Base.isInvalid())
13395 return ExprError();
13396
13397 if (!getDerived().AlwaysRebuild() &&
13398 Base.get() == E->getBase())
13399 return E;
13400
13401 // FIXME: Bad source location
13402 SourceLocation FakeOperatorLoc =
13403 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
13404 return getDerived().RebuildExtVectorElementExpr(
13405 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
13406 E->getAccessor());
13407}
13408
13409template<typename Derived>
13411TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
13412 if (InitListExpr *Syntactic = E->getSyntacticForm())
13413 E = Syntactic;
13414
13415 bool InitChanged = false;
13416
13417 EnterExpressionEvaluationContext Context(
13419
13421 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
13422 Inits, &InitChanged))
13423 return ExprError();
13424
13425 if (!getDerived().AlwaysRebuild() && !InitChanged) {
13426 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
13427 // in some cases. We can't reuse it in general, because the syntactic and
13428 // semantic forms are linked, and we can't know that semantic form will
13429 // match even if the syntactic form does.
13430 }
13431
13432 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
13433 E->getRBraceLoc());
13434}
13435
13436template<typename Derived>
13438TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
13439 Designation Desig;
13440
13441 // transform the initializer value
13442 ExprResult Init = getDerived().TransformExpr(E->getInit());
13443 if (Init.isInvalid())
13444 return ExprError();
13445
13446 // transform the designators.
13447 SmallVector<Expr*, 4> ArrayExprs;
13448 bool ExprChanged = false;
13449 for (const DesignatedInitExpr::Designator &D : E->designators()) {
13450 if (D.isFieldDesignator()) {
13451 if (D.getFieldDecl()) {
13452 FieldDecl *Field = cast_or_null<FieldDecl>(
13453 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
13454 if (Field != D.getFieldDecl())
13455 // Rebuild the expression when the transformed FieldDecl is
13456 // different to the already assigned FieldDecl.
13457 ExprChanged = true;
13458 if (Field->isAnonymousStructOrUnion())
13459 continue;
13460 } else {
13461 // Ensure that the designator expression is rebuilt when there isn't
13462 // a resolved FieldDecl in the designator as we don't want to assign
13463 // a FieldDecl to a pattern designator that will be instantiated again.
13464 ExprChanged = true;
13465 }
13466 Desig.AddDesignator(Designator::CreateFieldDesignator(
13467 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
13468 continue;
13469 }
13470
13471 if (D.isArrayDesignator()) {
13472 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
13473 if (Index.isInvalid())
13474 return ExprError();
13475
13476 Desig.AddDesignator(
13477 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
13478
13479 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
13480 ArrayExprs.push_back(Index.get());
13481 continue;
13482 }
13483
13484 assert(D.isArrayRangeDesignator() && "New kind of designator?");
13485 ExprResult Start
13486 = getDerived().TransformExpr(E->getArrayRangeStart(D));
13487 if (Start.isInvalid())
13488 return ExprError();
13489
13490 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
13491 if (End.isInvalid())
13492 return ExprError();
13493
13494 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
13495 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
13496
13497 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
13498 End.get() != E->getArrayRangeEnd(D);
13499
13500 ArrayExprs.push_back(Start.get());
13501 ArrayExprs.push_back(End.get());
13502 }
13503
13504 if (!getDerived().AlwaysRebuild() &&
13505 Init.get() == E->getInit() &&
13506 !ExprChanged)
13507 return E;
13508
13509 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
13510 E->getEqualOrColonLoc(),
13511 E->usesGNUSyntax(), Init.get());
13512}
13513
13514// Seems that if TransformInitListExpr() only works on the syntactic form of an
13515// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
13516template<typename Derived>
13518TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
13519 DesignatedInitUpdateExpr *E) {
13520 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
13521 "initializer");
13522 return ExprError();
13523}
13524
13525template<typename Derived>
13527TreeTransform<Derived>::TransformNoInitExpr(
13528 NoInitExpr *E) {
13529 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
13530 return ExprError();
13531}
13532
13533template<typename Derived>
13535TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
13536 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
13537 return ExprError();
13538}
13539
13540template<typename Derived>
13542TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
13543 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
13544 return ExprError();
13545}
13546
13547template<typename Derived>
13549TreeTransform<Derived>::TransformImplicitValueInitExpr(
13550 ImplicitValueInitExpr *E) {
13551 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
13552
13553 // FIXME: Will we ever have proper type location here? Will we actually
13554 // need to transform the type?
13555 QualType T = getDerived().TransformType(E->getType());
13556 if (T.isNull())
13557 return ExprError();
13558
13559 if (!getDerived().AlwaysRebuild() &&
13560 T == E->getType())
13561 return E;
13562
13563 return getDerived().RebuildImplicitValueInitExpr(T);
13564}
13565
13566template<typename Derived>
13568TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
13569 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
13570 if (!TInfo)
13571 return ExprError();
13572
13573 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13574 if (SubExpr.isInvalid())
13575 return ExprError();
13576
13577 if (!getDerived().AlwaysRebuild() &&
13578 TInfo == E->getWrittenTypeInfo() &&
13579 SubExpr.get() == E->getSubExpr())
13580 return E;
13581
13582 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
13583 TInfo, E->getRParenLoc());
13584}
13585
13586template<typename Derived>
13588TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
13589 bool ArgumentChanged = false;
13591 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
13592 &ArgumentChanged))
13593 return ExprError();
13594
13595 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
13596 Inits,
13597 E->getRParenLoc());
13598}
13599
13600/// Transform an address-of-label expression.
13601///
13602/// By default, the transformation of an address-of-label expression always
13603/// rebuilds the expression, so that the label identifier can be resolved to
13604/// the corresponding label statement by semantic analysis.
13605template<typename Derived>
13607TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
13608 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
13609 E->getLabel());
13610 if (!LD)
13611 return ExprError();
13612
13613 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
13614 cast<LabelDecl>(LD));
13615}
13616
13617template<typename Derived>
13619TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
13620 SemaRef.ActOnStartStmtExpr();
13621 StmtResult SubStmt
13622 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
13623 if (SubStmt.isInvalid()) {
13624 SemaRef.ActOnStmtExprError();
13625 return ExprError();
13626 }
13627
13628 unsigned OldDepth = E->getTemplateDepth();
13629 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
13630
13631 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
13632 SubStmt.get() == E->getSubStmt()) {
13633 // Calling this an 'error' is unintuitive, but it does the right thing.
13634 SemaRef.ActOnStmtExprError();
13635 return SemaRef.MaybeBindToTemporary(E);
13636 }
13637
13638 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
13639 E->getRParenLoc(), NewDepth);
13640}
13641
13642template<typename Derived>
13644TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
13645 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13646 if (Cond.isInvalid())
13647 return ExprError();
13648
13649 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13650 if (LHS.isInvalid())
13651 return ExprError();
13652
13653 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13654 if (RHS.isInvalid())
13655 return ExprError();
13656
13657 if (!getDerived().AlwaysRebuild() &&
13658 Cond.get() == E->getCond() &&
13659 LHS.get() == E->getLHS() &&
13660 RHS.get() == E->getRHS())
13661 return E;
13662
13663 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
13664 Cond.get(), LHS.get(), RHS.get(),
13665 E->getRParenLoc());
13666}
13667
13668template<typename Derived>
13670TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
13671 return E;
13672}
13673
13674template<typename Derived>
13676TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
13677 switch (E->getOperator()) {
13678 case OO_New:
13679 case OO_Delete:
13680 case OO_Array_New:
13681 case OO_Array_Delete:
13682 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
13683
13684 case OO_Subscript:
13685 case OO_Call: {
13686 // This is a call to an object's operator().
13687 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
13688
13689 // Transform the object itself.
13690 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
13691 if (Object.isInvalid())
13692 return ExprError();
13693
13694 // FIXME: Poor location information
13695 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
13696 static_cast<Expr *>(Object.get())->getEndLoc());
13697
13698 // Transform the call arguments.
13700 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
13701 Args))
13702 return ExprError();
13703
13704 if (E->getOperator() == OO_Subscript)
13705 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
13706 Args, E->getEndLoc());
13707
13708 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
13709 E->getEndLoc());
13710 }
13711
13712#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
13713 case OO_##Name: \
13714 break;
13715
13716#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
13717#include "clang/Basic/OperatorKinds.def"
13718
13719 case OO_Conditional:
13720 llvm_unreachable("conditional operator is not actually overloadable");
13721
13722 case OO_None:
13724 llvm_unreachable("not an overloaded operator?");
13725 }
13726
13728 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
13729 First = getDerived().TransformAddressOfOperand(E->getArg(0));
13730 else
13731 First = getDerived().TransformExpr(E->getArg(0));
13732 if (First.isInvalid())
13733 return ExprError();
13734
13735 ExprResult Second;
13736 if (E->getNumArgs() == 2) {
13737 Second =
13738 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
13739 if (Second.isInvalid())
13740 return ExprError();
13741 }
13742
13743 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13744 FPOptionsOverride NewOverrides(E->getFPFeatures());
13745 getSema().CurFPFeatures =
13746 NewOverrides.applyOverrides(getSema().getLangOpts());
13747 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13748
13749 Expr *Callee = E->getCallee();
13750 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
13751 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
13753 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
13754 return ExprError();
13755
13756 return getDerived().RebuildCXXOperatorCallExpr(
13757 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
13758 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
13759 }
13760
13761 UnresolvedSet<1> Functions;
13762 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
13763 Callee = ICE->getSubExprAsWritten();
13764 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
13765 ValueDecl *VD = cast_or_null<ValueDecl>(
13766 getDerived().TransformDecl(DR->getLocation(), DR));
13767 if (!VD)
13768 return ExprError();
13769
13770 if (!isa<CXXMethodDecl>(VD))
13771 Functions.addDecl(VD);
13772
13773 return getDerived().RebuildCXXOperatorCallExpr(
13774 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
13775 /*RequiresADL=*/false, Functions, First.get(), Second.get());
13776}
13777
13778template<typename Derived>
13780TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
13781 return getDerived().TransformCallExpr(E);
13782}
13783
13784template <typename Derived>
13785ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
13786 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
13787 getSema().CurContext != E->getParentContext();
13788
13789 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
13790 return E;
13791
13792 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
13793 E->getBeginLoc(), E->getEndLoc(),
13794 getSema().CurContext);
13795}
13796
13797template <typename Derived>
13798ExprResult TreeTransform<Derived>::TransformEmbedExpr(EmbedExpr *E) {
13799 return E;
13800}
13801
13802template<typename Derived>
13804TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
13805 // Transform the callee.
13806 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13807 if (Callee.isInvalid())
13808 return ExprError();
13809
13810 // Transform exec config.
13811 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
13812 if (EC.isInvalid())
13813 return ExprError();
13814
13815 // Transform arguments.
13816 bool ArgChanged = false;
13818 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13819 &ArgChanged))
13820 return ExprError();
13821
13822 if (!getDerived().AlwaysRebuild() &&
13823 Callee.get() == E->getCallee() &&
13824 !ArgChanged)
13825 return SemaRef.MaybeBindToTemporary(E);
13826
13827 // FIXME: Wrong source location information for the '('.
13828 SourceLocation FakeLParenLoc
13829 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13830 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13831 Args,
13832 E->getRParenLoc(), EC.get());
13833}
13834
13835template<typename Derived>
13838 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13839 if (!Type)
13840 return ExprError();
13841
13842 ExprResult SubExpr
13843 = getDerived().TransformExpr(E->getSubExprAsWritten());
13844 if (SubExpr.isInvalid())
13845 return ExprError();
13846
13847 if (!getDerived().AlwaysRebuild() &&
13848 Type == E->getTypeInfoAsWritten() &&
13849 SubExpr.get() == E->getSubExpr())
13850 return E;
13851 return getDerived().RebuildCXXNamedCastExpr(
13852 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
13853 Type, E->getAngleBrackets().getEnd(),
13854 // FIXME. this should be '(' location
13855 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
13856}
13857
13858template<typename Derived>
13861 TypeSourceInfo *TSI =
13862 getDerived().TransformType(BCE->getTypeInfoAsWritten());
13863 if (!TSI)
13864 return ExprError();
13865
13866 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
13867 if (Sub.isInvalid())
13868 return ExprError();
13869
13870 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
13871 Sub.get(), BCE->getEndLoc());
13872}
13873
13874template<typename Derived>
13876TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
13877 return getDerived().TransformCXXNamedCastExpr(E);
13878}
13879
13880template<typename Derived>
13882TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
13883 return getDerived().TransformCXXNamedCastExpr(E);
13884}
13885
13886template<typename Derived>
13888TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
13889 CXXReinterpretCastExpr *E) {
13890 return getDerived().TransformCXXNamedCastExpr(E);
13891}
13892
13893template<typename Derived>
13895TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
13896 return getDerived().TransformCXXNamedCastExpr(E);
13897}
13898
13899template<typename Derived>
13901TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
13902 return getDerived().TransformCXXNamedCastExpr(E);
13903}
13904
13905template<typename Derived>
13907TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
13908 CXXFunctionalCastExpr *E) {
13909 TypeSourceInfo *Type =
13910 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
13911 if (!Type)
13912 return ExprError();
13913
13914 ExprResult SubExpr
13915 = getDerived().TransformExpr(E->getSubExprAsWritten());
13916 if (SubExpr.isInvalid())
13917 return ExprError();
13918
13919 if (!getDerived().AlwaysRebuild() &&
13920 Type == E->getTypeInfoAsWritten() &&
13921 SubExpr.get() == E->getSubExpr())
13922 return E;
13923
13924 return getDerived().RebuildCXXFunctionalCastExpr(Type,
13925 E->getLParenLoc(),
13926 SubExpr.get(),
13927 E->getRParenLoc(),
13928 E->isListInitialization());
13929}
13930
13931template<typename Derived>
13933TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
13934 if (E->isTypeOperand()) {
13935 TypeSourceInfo *TInfo
13936 = getDerived().TransformType(E->getTypeOperandSourceInfo());
13937 if (!TInfo)
13938 return ExprError();
13939
13940 if (!getDerived().AlwaysRebuild() &&
13941 TInfo == E->getTypeOperandSourceInfo())
13942 return E;
13943
13944 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
13945 TInfo, E->getEndLoc());
13946 }
13947
13948 // Typeid's operand is an unevaluated context, unless it's a polymorphic
13949 // type. We must not unilaterally enter unevaluated context here, as then
13950 // semantic processing can re-transform an already transformed operand.
13951 Expr *Op = E->getExprOperand();
13953 if (E->isGLValue())
13954 if (auto *RecordT = Op->getType()->getAs<RecordType>())
13955 if (cast<CXXRecordDecl>(RecordT->getDecl())->isPolymorphic())
13956 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
13957
13958 EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx,
13960
13961 ExprResult SubExpr = getDerived().TransformExpr(Op);
13962 if (SubExpr.isInvalid())
13963 return ExprError();
13964
13965 if (!getDerived().AlwaysRebuild() &&
13966 SubExpr.get() == E->getExprOperand())
13967 return E;
13968
13969 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
13970 SubExpr.get(), E->getEndLoc());
13971}
13972
13973template<typename Derived>
13975TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
13976 if (E->isTypeOperand()) {
13977 TypeSourceInfo *TInfo
13978 = getDerived().TransformType(E->getTypeOperandSourceInfo());
13979 if (!TInfo)
13980 return ExprError();
13981
13982 if (!getDerived().AlwaysRebuild() &&
13983 TInfo == E->getTypeOperandSourceInfo())
13984 return E;
13985
13986 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
13987 TInfo, E->getEndLoc());
13988 }
13989
13990 EnterExpressionEvaluationContext Unevaluated(
13992
13993 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
13994 if (SubExpr.isInvalid())
13995 return ExprError();
13996
13997 if (!getDerived().AlwaysRebuild() &&
13998 SubExpr.get() == E->getExprOperand())
13999 return E;
14000
14001 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14002 SubExpr.get(), E->getEndLoc());
14003}
14004
14005template<typename Derived>
14007TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
14008 return E;
14009}
14010
14011template<typename Derived>
14013TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
14014 CXXNullPtrLiteralExpr *E) {
14015 return E;
14016}
14017
14018template<typename Derived>
14020TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
14021
14022 // In lambdas, the qualifiers of the type depends of where in
14023 // the call operator `this` appear, and we do not have a good way to
14024 // rebuild this information, so we transform the type.
14025 //
14026 // In other contexts, the type of `this` may be overrided
14027 // for type deduction, so we need to recompute it.
14028 //
14029 // Always recompute the type if we're in the body of a lambda, and
14030 // 'this' is dependent on a lambda's explicit object parameter.
14031 QualType T = [&]() {
14032 auto &S = getSema();
14033 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14034 return S.getCurrentThisType();
14035 if (S.getCurLambda())
14036 return getDerived().TransformType(E->getType());
14037 return S.getCurrentThisType();
14038 }();
14039
14040 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
14041 // Mark it referenced in the new context regardless.
14042 // FIXME: this is a bit instantiation-specific.
14043 getSema().MarkThisReferenced(E);
14044 return E;
14045 }
14046
14047 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14048}
14049
14050template<typename Derived>
14052TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
14053 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14054 if (SubExpr.isInvalid())
14055 return ExprError();
14056
14057 if (!getDerived().AlwaysRebuild() &&
14058 SubExpr.get() == E->getSubExpr())
14059 return E;
14060
14061 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
14062 E->isThrownVariableInScope());
14063}
14064
14065template<typename Derived>
14067TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
14068 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
14069 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
14070 if (!Param)
14071 return ExprError();
14072
14073 ExprResult InitRes;
14074 if (E->hasRewrittenInit()) {
14075 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
14076 if (InitRes.isInvalid())
14077 return ExprError();
14078 }
14079
14080 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
14081 E->getUsedContext() == SemaRef.CurContext &&
14082 InitRes.get() == E->getRewrittenExpr())
14083 return E;
14084
14085 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
14086 InitRes.get());
14087}
14088
14089template<typename Derived>
14091TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
14092 FieldDecl *Field = cast_or_null<FieldDecl>(
14093 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
14094 if (!Field)
14095 return ExprError();
14096
14097 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
14098 E->getUsedContext() == SemaRef.CurContext)
14099 return E;
14100
14101 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
14102}
14103
14104template<typename Derived>
14106TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
14107 CXXScalarValueInitExpr *E) {
14108 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
14109 if (!T)
14110 return ExprError();
14111
14112 if (!getDerived().AlwaysRebuild() &&
14113 T == E->getTypeSourceInfo())
14114 return E;
14115
14116 return getDerived().RebuildCXXScalarValueInitExpr(T,
14117 /*FIXME:*/T->getTypeLoc().getEndLoc(),
14118 E->getRParenLoc());
14119}
14120
14121template<typename Derived>
14123TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
14124 // Transform the type that we're allocating
14125 TypeSourceInfo *AllocTypeInfo =
14126 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
14127 if (!AllocTypeInfo)
14128 return ExprError();
14129
14130 // Transform the size of the array we're allocating (if any).
14131 std::optional<Expr *> ArraySize;
14132 if (E->isArray()) {
14133 ExprResult NewArraySize;
14134 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
14135 NewArraySize = getDerived().TransformExpr(*OldArraySize);
14136 if (NewArraySize.isInvalid())
14137 return ExprError();
14138 }
14139 ArraySize = NewArraySize.get();
14140 }
14141
14142 // Transform the placement arguments (if any).
14143 bool ArgumentChanged = false;
14144 SmallVector<Expr*, 8> PlacementArgs;
14145 if (getDerived().TransformExprs(E->getPlacementArgs(),
14146 E->getNumPlacementArgs(), true,
14147 PlacementArgs, &ArgumentChanged))
14148 return ExprError();
14149
14150 // Transform the initializer (if any).
14151 Expr *OldInit = E->getInitializer();
14152 ExprResult NewInit;
14153 if (OldInit)
14154 NewInit = getDerived().TransformInitializer(OldInit, true);
14155 if (NewInit.isInvalid())
14156 return ExprError();
14157
14158 // Transform new operator and delete operator.
14159 FunctionDecl *OperatorNew = nullptr;
14160 if (E->getOperatorNew()) {
14161 OperatorNew = cast_or_null<FunctionDecl>(
14162 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
14163 if (!OperatorNew)
14164 return ExprError();
14165 }
14166
14167 FunctionDecl *OperatorDelete = nullptr;
14168 if (E->getOperatorDelete()) {
14169 OperatorDelete = cast_or_null<FunctionDecl>(
14170 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14171 if (!OperatorDelete)
14172 return ExprError();
14173 }
14174
14175 if (!getDerived().AlwaysRebuild() &&
14176 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
14177 ArraySize == E->getArraySize() &&
14178 NewInit.get() == OldInit &&
14179 OperatorNew == E->getOperatorNew() &&
14180 OperatorDelete == E->getOperatorDelete() &&
14181 !ArgumentChanged) {
14182 // Mark any declarations we need as referenced.
14183 // FIXME: instantiation-specific.
14184 if (OperatorNew)
14185 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
14186 if (OperatorDelete)
14187 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14188
14189 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
14190 QualType ElementType
14191 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
14192 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
14193 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
14194 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
14196 }
14197 }
14198 }
14199
14200 return E;
14201 }
14202
14203 QualType AllocType = AllocTypeInfo->getType();
14204 if (!ArraySize) {
14205 // If no array size was specified, but the new expression was
14206 // instantiated with an array type (e.g., "new T" where T is
14207 // instantiated with "int[4]"), extract the outer bound from the
14208 // array type as our array size. We do this with constant and
14209 // dependently-sized array types.
14210 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
14211 if (!ArrayT) {
14212 // Do nothing
14213 } else if (const ConstantArrayType *ConsArrayT
14214 = dyn_cast<ConstantArrayType>(ArrayT)) {
14215 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
14216 SemaRef.Context.getSizeType(),
14217 /*FIXME:*/ E->getBeginLoc());
14218 AllocType = ConsArrayT->getElementType();
14219 } else if (const DependentSizedArrayType *DepArrayT
14220 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
14221 if (DepArrayT->getSizeExpr()) {
14222 ArraySize = DepArrayT->getSizeExpr();
14223 AllocType = DepArrayT->getElementType();
14224 }
14225 }
14226 }
14227
14228 return getDerived().RebuildCXXNewExpr(
14229 E->getBeginLoc(), E->isGlobalNew(),
14230 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
14231 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
14232 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
14233}
14234
14235template<typename Derived>
14237TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
14238 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
14239 if (Operand.isInvalid())
14240 return ExprError();
14241
14242 // Transform the delete operator, if known.
14243 FunctionDecl *OperatorDelete = nullptr;
14244 if (E->getOperatorDelete()) {
14245 OperatorDelete = cast_or_null<FunctionDecl>(
14246 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14247 if (!OperatorDelete)
14248 return ExprError();
14249 }
14250
14251 if (!getDerived().AlwaysRebuild() &&
14252 Operand.get() == E->getArgument() &&
14253 OperatorDelete == E->getOperatorDelete()) {
14254 // Mark any declarations we need as referenced.
14255 // FIXME: instantiation-specific.
14256 if (OperatorDelete)
14257 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14258
14259 if (!E->getArgument()->isTypeDependent()) {
14260 QualType Destroyed = SemaRef.Context.getBaseElementType(
14261 E->getDestroyedType());
14262 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
14263 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
14265 SemaRef.LookupDestructor(Record));
14266 }
14267 }
14268
14269 return E;
14270 }
14271
14272 return getDerived().RebuildCXXDeleteExpr(
14273 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
14274}
14275
14276template<typename Derived>
14278TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
14279 CXXPseudoDestructorExpr *E) {
14280 ExprResult Base = getDerived().TransformExpr(E->getBase());
14281 if (Base.isInvalid())
14282 return ExprError();
14283
14284 ParsedType ObjectTypePtr;
14285 bool MayBePseudoDestructor = false;
14286 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14287 E->getOperatorLoc(),
14288 E->isArrow()? tok::arrow : tok::period,
14289 ObjectTypePtr,
14290 MayBePseudoDestructor);
14291 if (Base.isInvalid())
14292 return ExprError();
14293
14294 QualType ObjectType = ObjectTypePtr.get();
14295 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
14296 if (QualifierLoc) {
14297 QualifierLoc
14298 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
14299 if (!QualifierLoc)
14300 return ExprError();
14301 }
14302 CXXScopeSpec SS;
14303 SS.Adopt(QualifierLoc);
14304
14305 PseudoDestructorTypeStorage Destroyed;
14306 if (E->getDestroyedTypeInfo()) {
14307 TypeSourceInfo *DestroyedTypeInfo
14308 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
14309 ObjectType, nullptr, SS);
14310 if (!DestroyedTypeInfo)
14311 return ExprError();
14312 Destroyed = DestroyedTypeInfo;
14313 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
14314 // We aren't likely to be able to resolve the identifier down to a type
14315 // now anyway, so just retain the identifier.
14316 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
14317 E->getDestroyedTypeLoc());
14318 } else {
14319 // Look for a destructor known with the given name.
14320 ParsedType T = SemaRef.getDestructorName(
14321 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
14322 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
14323 if (!T)
14324 return ExprError();
14325
14326 Destroyed
14328 E->getDestroyedTypeLoc());
14329 }
14330
14331 TypeSourceInfo *ScopeTypeInfo = nullptr;
14332 if (E->getScopeTypeInfo()) {
14333 CXXScopeSpec EmptySS;
14334 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
14335 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
14336 if (!ScopeTypeInfo)
14337 return ExprError();
14338 }
14339
14340 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
14341 E->getOperatorLoc(),
14342 E->isArrow(),
14343 SS,
14344 ScopeTypeInfo,
14345 E->getColonColonLoc(),
14346 E->getTildeLoc(),
14347 Destroyed);
14348}
14349
14350template <typename Derived>
14352 bool RequiresADL,
14353 LookupResult &R) {
14354 // Transform all the decls.
14355 bool AllEmptyPacks = true;
14356 for (auto *OldD : Old->decls()) {
14357 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
14358 if (!InstD) {
14359 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
14360 // This can happen because of dependent hiding.
14361 if (isa<UsingShadowDecl>(OldD))
14362 continue;
14363 else {
14364 R.clear();
14365 return true;
14366 }
14367 }
14368
14369 // Expand using pack declarations.
14370 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
14371 ArrayRef<NamedDecl*> Decls = SingleDecl;
14372 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
14373 Decls = UPD->expansions();
14374
14375 // Expand using declarations.
14376 for (auto *D : Decls) {
14377 if (auto *UD = dyn_cast<UsingDecl>(D)) {
14378 for (auto *SD : UD->shadows())
14379 R.addDecl(SD);
14380 } else {
14381 R.addDecl(D);
14382 }
14383 }
14384
14385 AllEmptyPacks &= Decls.empty();
14386 }
14387
14388 // C++ [temp.res]/8.4.2:
14389 // The program is ill-formed, no diagnostic required, if [...] lookup for
14390 // a name in the template definition found a using-declaration, but the
14391 // lookup in the corresponding scope in the instantiation odoes not find
14392 // any declarations because the using-declaration was a pack expansion and
14393 // the corresponding pack is empty
14394 if (AllEmptyPacks && !RequiresADL) {
14395 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
14396 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
14397 return true;
14398 }
14399
14400 // Resolve a kind, but don't do any further analysis. If it's
14401 // ambiguous, the callee needs to deal with it.
14402 R.resolveKind();
14403
14404 if (Old->hasTemplateKeyword() && !R.empty()) {
14406 getSema().FilterAcceptableTemplateNames(R,
14407 /*AllowFunctionTemplates=*/true,
14408 /*AllowDependent=*/true);
14409 if (R.empty()) {
14410 // If a 'template' keyword was used, a lookup that finds only non-template
14411 // names is an error.
14412 getSema().Diag(R.getNameLoc(),
14413 diag::err_template_kw_refers_to_non_template)
14415 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
14416 getSema().Diag(FoundDecl->getLocation(),
14417 diag::note_template_kw_refers_to_non_template)
14418 << R.getLookupName();
14419 return true;
14420 }
14421 }
14422
14423 return false;
14424}
14425
14426template <typename Derived>
14428 UnresolvedLookupExpr *Old) {
14429 return TransformUnresolvedLookupExpr(Old, /*IsAddressOfOperand=*/false);
14430}
14431
14432template <typename Derived>
14435 bool IsAddressOfOperand) {
14436 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
14438
14439 // Transform the declaration set.
14440 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
14441 return ExprError();
14442
14443 // Rebuild the nested-name qualifier, if present.
14444 CXXScopeSpec SS;
14445 if (Old->getQualifierLoc()) {
14446 NestedNameSpecifierLoc QualifierLoc
14447 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14448 if (!QualifierLoc)
14449 return ExprError();
14450
14451 SS.Adopt(QualifierLoc);
14452 }
14453
14454 if (Old->getNamingClass()) {
14455 CXXRecordDecl *NamingClass
14456 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
14457 Old->getNameLoc(),
14458 Old->getNamingClass()));
14459 if (!NamingClass) {
14460 R.clear();
14461 return ExprError();
14462 }
14463
14464 R.setNamingClass(NamingClass);
14465 }
14466
14467 // Rebuild the template arguments, if any.
14468 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14469 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
14470 if (Old->hasExplicitTemplateArgs() &&
14471 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14472 Old->getNumTemplateArgs(),
14473 TransArgs)) {
14474 R.clear();
14475 return ExprError();
14476 }
14477
14478 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
14479 // a non-static data member is named in an unevaluated operand, or when
14480 // a member is named in a dependent class scope function template explicit
14481 // specialization that is neither declared static nor with an explicit object
14482 // parameter.
14483 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
14484 return SemaRef.BuildPossibleImplicitMemberExpr(
14485 SS, TemplateKWLoc, R,
14486 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
14487 /*S=*/nullptr);
14488
14489 // If we have neither explicit template arguments, nor the template keyword,
14490 // it's a normal declaration name or member reference.
14491 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
14492 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
14493
14494 // If we have template arguments, then rebuild the template-id expression.
14495 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
14496 Old->requiresADL(), &TransArgs);
14497}
14498
14499template<typename Derived>
14501TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
14502 bool ArgChanged = false;
14504 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
14505 TypeSourceInfo *From = E->getArg(I);
14506 TypeLoc FromTL = From->getTypeLoc();
14507 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
14508 TypeLocBuilder TLB;
14509 TLB.reserve(FromTL.getFullDataSize());
14510 QualType To = getDerived().TransformType(TLB, FromTL);
14511 if (To.isNull())
14512 return ExprError();
14513
14514 if (To == From->getType())
14515 Args.push_back(From);
14516 else {
14517 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14518 ArgChanged = true;
14519 }
14520 continue;
14521 }
14522
14523 ArgChanged = true;
14524
14525 // We have a pack expansion. Instantiate it.
14526 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
14527 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
14529 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
14530
14531 // Determine whether the set of unexpanded parameter packs can and should
14532 // be expanded.
14533 bool Expand = true;
14534 bool RetainExpansion = false;
14535 std::optional<unsigned> OrigNumExpansions =
14536 ExpansionTL.getTypePtr()->getNumExpansions();
14537 std::optional<unsigned> NumExpansions = OrigNumExpansions;
14538 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
14539 PatternTL.getSourceRange(),
14540 Unexpanded,
14541 Expand, RetainExpansion,
14542 NumExpansions))
14543 return ExprError();
14544
14545 if (!Expand) {
14546 // The transform has determined that we should perform a simple
14547 // transformation on the pack expansion, producing another pack
14548 // expansion.
14549 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
14550
14551 TypeLocBuilder TLB;
14552 TLB.reserve(From->getTypeLoc().getFullDataSize());
14553
14554 QualType To = getDerived().TransformType(TLB, PatternTL);
14555 if (To.isNull())
14556 return ExprError();
14557
14558 To = getDerived().RebuildPackExpansionType(To,
14559 PatternTL.getSourceRange(),
14560 ExpansionTL.getEllipsisLoc(),
14561 NumExpansions);
14562 if (To.isNull())
14563 return ExprError();
14564
14565 PackExpansionTypeLoc ToExpansionTL
14566 = TLB.push<PackExpansionTypeLoc>(To);
14567 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14568 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14569 continue;
14570 }
14571
14572 // Expand the pack expansion by substituting for each argument in the
14573 // pack(s).
14574 for (unsigned I = 0; I != *NumExpansions; ++I) {
14575 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
14576 TypeLocBuilder TLB;
14577 TLB.reserve(PatternTL.getFullDataSize());
14578 QualType To = getDerived().TransformType(TLB, PatternTL);
14579 if (To.isNull())
14580 return ExprError();
14581
14582 if (To->containsUnexpandedParameterPack()) {
14583 To = getDerived().RebuildPackExpansionType(To,
14584 PatternTL.getSourceRange(),
14585 ExpansionTL.getEllipsisLoc(),
14586 NumExpansions);
14587 if (To.isNull())
14588 return ExprError();
14589
14590 PackExpansionTypeLoc ToExpansionTL
14591 = TLB.push<PackExpansionTypeLoc>(To);
14592 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14593 }
14594
14595 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14596 }
14597
14598 if (!RetainExpansion)
14599 continue;
14600
14601 // If we're supposed to retain a pack expansion, do so by temporarily
14602 // forgetting the partially-substituted parameter pack.
14603 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14604
14605 TypeLocBuilder TLB;
14606 TLB.reserve(From->getTypeLoc().getFullDataSize());
14607
14608 QualType To = getDerived().TransformType(TLB, PatternTL);
14609 if (To.isNull())
14610 return ExprError();
14611
14612 To = getDerived().RebuildPackExpansionType(To,
14613 PatternTL.getSourceRange(),
14614 ExpansionTL.getEllipsisLoc(),
14615 NumExpansions);
14616 if (To.isNull())
14617 return ExprError();
14618
14619 PackExpansionTypeLoc ToExpansionTL
14620 = TLB.push<PackExpansionTypeLoc>(To);
14621 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14622 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14623 }
14624
14625 if (!getDerived().AlwaysRebuild() && !ArgChanged)
14626 return E;
14627
14628 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
14629 E->getEndLoc());
14630}
14631
14632template<typename Derived>
14634TreeTransform<Derived>::TransformConceptSpecializationExpr(
14635 ConceptSpecializationExpr *E) {
14636 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
14637 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
14638 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14639 Old->NumTemplateArgs, TransArgs))
14640 return ExprError();
14641
14642 return getDerived().RebuildConceptSpecializationExpr(
14643 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
14644 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
14645 &TransArgs);
14646}
14647
14648template<typename Derived>
14650TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) {
14651 SmallVector<ParmVarDecl*, 4> TransParams;
14652 SmallVector<QualType, 4> TransParamTypes;
14653 Sema::ExtParameterInfoBuilder ExtParamInfos;
14654
14655 // C++2a [expr.prim.req]p2
14656 // Expressions appearing within a requirement-body are unevaluated operands.
14657 EnterExpressionEvaluationContext Ctx(
14660
14661 RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
14662 getSema().Context, getSema().CurContext,
14663 E->getBody()->getBeginLoc());
14664
14665 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
14666
14667 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
14668 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
14669 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
14670
14671 for (ParmVarDecl *Param : TransParams)
14672 if (Param)
14673 Param->setDeclContext(Body);
14674
14675 // On failure to transform, TransformRequiresTypeParams returns an expression
14676 // in the event that the transformation of the type params failed in some way.
14677 // It is expected that this will result in a 'not satisfied' Requires clause
14678 // when instantiating.
14679 if (!TypeParamResult.isUnset())
14680 return TypeParamResult;
14681
14683 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
14684 TransReqs))
14685 return ExprError();
14686
14687 for (concepts::Requirement *Req : TransReqs) {
14688 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
14689 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
14690 ER->getReturnTypeRequirement()
14691 .getTypeConstraintTemplateParameterList()->getParam(0)
14692 ->setDeclContext(Body);
14693 }
14694 }
14695 }
14696
14697 return getDerived().RebuildRequiresExpr(
14698 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
14699 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
14700}
14701
14702template<typename Derived>
14706 for (concepts::Requirement *Req : Reqs) {
14707 concepts::Requirement *TransReq = nullptr;
14708 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
14709 TransReq = getDerived().TransformTypeRequirement(TypeReq);
14710 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
14711 TransReq = getDerived().TransformExprRequirement(ExprReq);
14712 else
14713 TransReq = getDerived().TransformNestedRequirement(
14714 cast<concepts::NestedRequirement>(Req));
14715 if (!TransReq)
14716 return true;
14717 Transformed.push_back(TransReq);
14718 }
14719 return false;
14720}
14721
14722template<typename Derived>
14726 if (Req->isSubstitutionFailure()) {
14727 if (getDerived().AlwaysRebuild())
14728 return getDerived().RebuildTypeRequirement(
14730 return Req;
14731 }
14732 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
14733 if (!TransType)
14734 return nullptr;
14735 return getDerived().RebuildTypeRequirement(TransType);
14736}
14737
14738template<typename Derived>
14741 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
14742 if (Req->isExprSubstitutionFailure())
14743 TransExpr = Req->getExprSubstitutionDiagnostic();
14744 else {
14745 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
14746 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
14747 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
14748 if (TransExprRes.isInvalid())
14749 return nullptr;
14750 TransExpr = TransExprRes.get();
14751 }
14752
14753 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
14754 const auto &RetReq = Req->getReturnTypeRequirement();
14755 if (RetReq.isEmpty())
14756 TransRetReq.emplace();
14757 else if (RetReq.isSubstitutionFailure())
14758 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
14759 else if (RetReq.isTypeConstraint()) {
14760 TemplateParameterList *OrigTPL =
14761 RetReq.getTypeConstraintTemplateParameterList();
14763 getDerived().TransformTemplateParameterList(OrigTPL);
14764 if (!TPL)
14765 return nullptr;
14766 TransRetReq.emplace(TPL);
14767 }
14768 assert(TransRetReq && "All code paths leading here must set TransRetReq");
14769 if (Expr *E = TransExpr.dyn_cast<Expr *>())
14770 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
14771 Req->getNoexceptLoc(),
14772 std::move(*TransRetReq));
14773 return getDerived().RebuildExprRequirement(
14774 cast<concepts::Requirement::SubstitutionDiagnostic *>(TransExpr),
14775 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
14776}
14777
14778template<typename Derived>
14782 if (Req->hasInvalidConstraint()) {
14783 if (getDerived().AlwaysRebuild())
14784 return getDerived().RebuildNestedRequirement(
14786 return Req;
14787 }
14788 ExprResult TransConstraint =
14789 getDerived().TransformExpr(Req->getConstraintExpr());
14790 if (TransConstraint.isInvalid())
14791 return nullptr;
14792 return getDerived().RebuildNestedRequirement(TransConstraint.get());
14793}
14794
14795template<typename Derived>
14798 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
14799 if (!T)
14800 return ExprError();
14801
14802 if (!getDerived().AlwaysRebuild() &&
14803 T == E->getQueriedTypeSourceInfo())
14804 return E;
14805
14806 ExprResult SubExpr;
14807 {
14810 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
14811 if (SubExpr.isInvalid())
14812 return ExprError();
14813
14814 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
14815 return E;
14816 }
14817
14818 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
14819 SubExpr.get(), E->getEndLoc());
14820}
14821
14822template<typename Derived>
14824TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
14825 ExprResult SubExpr;
14826 {
14827 EnterExpressionEvaluationContext Unevaluated(
14829 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
14830 if (SubExpr.isInvalid())
14831 return ExprError();
14832
14833 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
14834 return E;
14835 }
14836
14837 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
14838 SubExpr.get(), E->getEndLoc());
14839}
14840
14841template <typename Derived>
14843 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
14844 TypeSourceInfo **RecoveryTSI) {
14845 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
14846 DRE, AddrTaken, RecoveryTSI);
14847
14848 // Propagate both errors and recovered types, which return ExprEmpty.
14849 if (!NewDRE.isUsable())
14850 return NewDRE;
14851
14852 // We got an expr, wrap it up in parens.
14853 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
14854 return PE;
14855 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
14856 PE->getRParen());
14857}
14858
14859template <typename Derived>
14862 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
14863 nullptr);
14864}
14865
14866template <typename Derived>
14868 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
14869 TypeSourceInfo **RecoveryTSI) {
14870 assert(E->getQualifierLoc());
14871 NestedNameSpecifierLoc QualifierLoc =
14872 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
14873 if (!QualifierLoc)
14874 return ExprError();
14875 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14876
14877 // TODO: If this is a conversion-function-id, verify that the
14878 // destination type name (if present) resolves the same way after
14879 // instantiation as it did in the local scope.
14880
14881 DeclarationNameInfo NameInfo =
14882 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
14883 if (!NameInfo.getName())
14884 return ExprError();
14885
14886 if (!E->hasExplicitTemplateArgs()) {
14887 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
14888 // Note: it is sufficient to compare the Name component of NameInfo:
14889 // if name has not changed, DNLoc has not changed either.
14890 NameInfo.getName() == E->getDeclName())
14891 return E;
14892
14893 return getDerived().RebuildDependentScopeDeclRefExpr(
14894 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
14895 IsAddressOfOperand, RecoveryTSI);
14896 }
14897
14898 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
14899 if (getDerived().TransformTemplateArguments(
14900 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
14901 return ExprError();
14902
14903 return getDerived().RebuildDependentScopeDeclRefExpr(
14904 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
14905 RecoveryTSI);
14906}
14907
14908template<typename Derived>
14910TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
14911 // CXXConstructExprs other than for list-initialization and
14912 // CXXTemporaryObjectExpr are always implicit, so when we have
14913 // a 1-argument construction we just transform that argument.
14914 if (getDerived().AllowSkippingCXXConstructExpr() &&
14915 ((E->getNumArgs() == 1 ||
14916 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
14917 (!getDerived().DropCallArgument(E->getArg(0))) &&
14918 !E->isListInitialization()))
14919 return getDerived().TransformInitializer(E->getArg(0),
14920 /*DirectInit*/ false);
14921
14922 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
14923
14924 QualType T = getDerived().TransformType(E->getType());
14925 if (T.isNull())
14926 return ExprError();
14927
14928 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
14929 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
14930 if (!Constructor)
14931 return ExprError();
14932
14933 bool ArgumentChanged = false;
14935 {
14936 EnterExpressionEvaluationContext Context(
14938 E->isListInitialization());
14939 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14940 &ArgumentChanged))
14941 return ExprError();
14942 }
14943
14944 if (!getDerived().AlwaysRebuild() &&
14945 T == E->getType() &&
14946 Constructor == E->getConstructor() &&
14947 !ArgumentChanged) {
14948 // Mark the constructor as referenced.
14949 // FIXME: Instantiation-specific
14950 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
14951 return E;
14952 }
14953
14954 return getDerived().RebuildCXXConstructExpr(
14955 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
14956 E->hadMultipleCandidates(), E->isListInitialization(),
14957 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
14958 E->getConstructionKind(), E->getParenOrBraceRange());
14959}
14960
14961template<typename Derived>
14962ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
14963 CXXInheritedCtorInitExpr *E) {
14964 QualType T = getDerived().TransformType(E->getType());
14965 if (T.isNull())
14966 return ExprError();
14967
14968 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
14969 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
14970 if (!Constructor)
14971 return ExprError();
14972
14973 if (!getDerived().AlwaysRebuild() &&
14974 T == E->getType() &&
14975 Constructor == E->getConstructor()) {
14976 // Mark the constructor as referenced.
14977 // FIXME: Instantiation-specific
14978 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
14979 return E;
14980 }
14981
14982 return getDerived().RebuildCXXInheritedCtorInitExpr(
14983 T, E->getLocation(), Constructor,
14984 E->constructsVBase(), E->inheritedFromVBase());
14985}
14986
14987/// Transform a C++ temporary-binding expression.
14988///
14989/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
14990/// transform the subexpression and return that.
14991template<typename Derived>
14993TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
14994 if (auto *Dtor = E->getTemporary()->getDestructor())
14996 const_cast<CXXDestructorDecl *>(Dtor));
14997 return getDerived().TransformExpr(E->getSubExpr());
14998}
14999
15000/// Transform a C++ expression that contains cleanups that should
15001/// be run after the expression is evaluated.
15002///
15003/// Since ExprWithCleanups nodes are implicitly generated, we
15004/// just transform the subexpression and return that.
15005template<typename Derived>
15007TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
15008 return getDerived().TransformExpr(E->getSubExpr());
15009}
15010
15011template<typename Derived>
15013TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
15014 CXXTemporaryObjectExpr *E) {
15015 TypeSourceInfo *T =
15016 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15017 if (!T)
15018 return ExprError();
15019
15020 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15021 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15022 if (!Constructor)
15023 return ExprError();
15024
15025 bool ArgumentChanged = false;
15027 Args.reserve(E->getNumArgs());
15028 {
15029 EnterExpressionEvaluationContext Context(
15031 E->isListInitialization());
15032 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15033 &ArgumentChanged))
15034 return ExprError();
15035
15036 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15037 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc());
15038 if (Res.isInvalid())
15039 return ExprError();
15040 Args = {Res.get()};
15041 }
15042 }
15043
15044 if (!getDerived().AlwaysRebuild() &&
15045 T == E->getTypeSourceInfo() &&
15046 Constructor == E->getConstructor() &&
15047 !ArgumentChanged) {
15048 // FIXME: Instantiation-specific
15049 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15050 return SemaRef.MaybeBindToTemporary(E);
15051 }
15052
15053 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15054 return getDerived().RebuildCXXTemporaryObjectExpr(
15055 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15056}
15057
15058template<typename Derived>
15060TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
15061 // Transform any init-capture expressions before entering the scope of the
15062 // lambda body, because they are not semantically within that scope.
15063 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15064 struct TransformedInitCapture {
15065 // The location of the ... if the result is retaining a pack expansion.
15066 SourceLocation EllipsisLoc;
15067 // Zero or more expansions of the init-capture.
15069 };
15071 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
15072 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15073 CEnd = E->capture_end();
15074 C != CEnd; ++C) {
15075 if (!E->isInitCapture(C))
15076 continue;
15077
15078 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
15079 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15080
15081 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
15082 std::optional<unsigned> NumExpansions) {
15083 ExprResult NewExprInitResult = getDerived().TransformInitializer(
15084 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
15085
15086 if (NewExprInitResult.isInvalid()) {
15087 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
15088 return;
15089 }
15090 Expr *NewExprInit = NewExprInitResult.get();
15091
15092 QualType NewInitCaptureType =
15093 getSema().buildLambdaInitCaptureInitialization(
15094 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
15095 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
15096 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
15098 NewExprInit);
15099 Result.Expansions.push_back(
15100 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
15101 };
15102
15103 // If this is an init-capture pack, consider expanding the pack now.
15104 if (OldVD->isParameterPack()) {
15105 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
15106 ->getTypeLoc()
15107 .castAs<PackExpansionTypeLoc>();
15109 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
15110
15111 // Determine whether the set of unexpanded parameter packs can and should
15112 // be expanded.
15113 bool Expand = true;
15114 bool RetainExpansion = false;
15115 std::optional<unsigned> OrigNumExpansions =
15116 ExpansionTL.getTypePtr()->getNumExpansions();
15117 std::optional<unsigned> NumExpansions = OrigNumExpansions;
15118 if (getDerived().TryExpandParameterPacks(
15119 ExpansionTL.getEllipsisLoc(),
15120 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
15121 RetainExpansion, NumExpansions))
15122 return ExprError();
15123 assert(!RetainExpansion && "Should not need to retain expansion after a "
15124 "capture since it cannot be extended");
15125 if (Expand) {
15126 for (unsigned I = 0; I != *NumExpansions; ++I) {
15127 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15128 SubstInitCapture(SourceLocation(), std::nullopt);
15129 }
15130 } else {
15131 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
15132 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
15133 }
15134 } else {
15135 SubstInitCapture(SourceLocation(), std::nullopt);
15136 }
15137 }
15138
15139 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
15140 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
15141
15142 // Create the local class that will describe the lambda.
15143
15144 // FIXME: DependencyKind below is wrong when substituting inside a templated
15145 // context that isn't a DeclContext (such as a variable template), or when
15146 // substituting an unevaluated lambda inside of a function's parameter's type
15147 // - as parameter types are not instantiated from within a function's DC. We
15148 // use evaluation contexts to distinguish the function parameter case.
15151 DeclContext *DC = getSema().CurContext;
15152 // A RequiresExprBodyDecl is not interesting for dependencies.
15153 // For the following case,
15154 //
15155 // template <typename>
15156 // concept C = requires { [] {}; };
15157 //
15158 // template <class F>
15159 // struct Widget;
15160 //
15161 // template <C F>
15162 // struct Widget<F> {};
15163 //
15164 // While we are substituting Widget<F>, the parent of DC would be
15165 // the template specialization itself. Thus, the lambda expression
15166 // will be deemed as dependent even if there are no dependent template
15167 // arguments.
15168 // (A ClassTemplateSpecializationDecl is always a dependent context.)
15169 while (DC->isRequiresExprBody())
15170 DC = DC->getParent();
15171 if ((getSema().isUnevaluatedContext() ||
15172 getSema().isConstantEvaluatedContext()) &&
15173 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
15174 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
15175
15176 CXXRecordDecl *OldClass = E->getLambdaClass();
15177 CXXRecordDecl *Class = getSema().createLambdaClosureType(
15178 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
15179 E->getCaptureDefault());
15180 getDerived().transformedLocalDecl(OldClass, {Class});
15181
15182 CXXMethodDecl *NewCallOperator =
15183 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
15184
15185 // Enter the scope of the lambda.
15186 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
15187 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
15188 E->hasExplicitParameters(), E->isMutable());
15189
15190 // Introduce the context of the call operator.
15191 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
15192 /*NewThisContext*/false);
15193
15194 bool Invalid = false;
15195
15196 // Transform captures.
15197 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15198 CEnd = E->capture_end();
15199 C != CEnd; ++C) {
15200 // When we hit the first implicit capture, tell Sema that we've finished
15201 // the list of explicit captures.
15202 if (C->isImplicit())
15203 break;
15204
15205 // Capturing 'this' is trivial.
15206 if (C->capturesThis()) {
15207 // If this is a lambda that is part of a default member initialiser
15208 // and which we're instantiating outside the class that 'this' is
15209 // supposed to refer to, adjust the type of 'this' accordingly.
15210 //
15211 // Otherwise, leave the type of 'this' as-is.
15212 Sema::CXXThisScopeRAII ThisScope(
15213 getSema(),
15214 dyn_cast_if_present<CXXRecordDecl>(
15215 getSema().getFunctionLevelDeclContext()),
15216 Qualifiers());
15217 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15218 /*BuildAndDiagnose*/ true, nullptr,
15219 C->getCaptureKind() == LCK_StarThis);
15220 continue;
15221 }
15222 // Captured expression will be recaptured during captured variables
15223 // rebuilding.
15224 if (C->capturesVLAType())
15225 continue;
15226
15227 // Rebuild init-captures, including the implied field declaration.
15228 if (E->isInitCapture(C)) {
15229 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
15230
15231 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15233
15234 for (InitCaptureInfoTy &Info : NewC.Expansions) {
15235 ExprResult Init = Info.first;
15236 QualType InitQualType = Info.second;
15237 if (Init.isInvalid() || InitQualType.isNull()) {
15238 Invalid = true;
15239 break;
15240 }
15241 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
15242 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
15243 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
15244 getSema().CurContext);
15245 if (!NewVD) {
15246 Invalid = true;
15247 break;
15248 }
15249 NewVDs.push_back(NewVD);
15250 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
15251 // Cases we want to tackle:
15252 // ([C(Pack)] {}, ...)
15253 // But rule out cases e.g.
15254 // [...C = Pack()] {}
15255 if (NewC.EllipsisLoc.isInvalid())
15256 LSI->ContainsUnexpandedParameterPack |=
15257 Init.get()->containsUnexpandedParameterPack();
15258 }
15259
15260 if (Invalid)
15261 break;
15262
15263 getDerived().transformedLocalDecl(OldVD, NewVDs);
15264 continue;
15265 }
15266
15267 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15268
15269 // Determine the capture kind for Sema.
15271 = C->isImplicit()? Sema::TryCapture_Implicit
15272 : C->getCaptureKind() == LCK_ByCopy
15275 SourceLocation EllipsisLoc;
15276 if (C->isPackExpansion()) {
15277 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
15278 bool ShouldExpand = false;
15279 bool RetainExpansion = false;
15280 std::optional<unsigned> NumExpansions;
15281 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
15282 C->getLocation(),
15283 Unexpanded,
15284 ShouldExpand, RetainExpansion,
15285 NumExpansions)) {
15286 Invalid = true;
15287 continue;
15288 }
15289
15290 if (ShouldExpand) {
15291 // The transform has determined that we should perform an expansion;
15292 // transform and capture each of the arguments.
15293 // expansion of the pattern. Do so.
15294 auto *Pack = cast<VarDecl>(C->getCapturedVar());
15295 for (unsigned I = 0; I != *NumExpansions; ++I) {
15296 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15297 VarDecl *CapturedVar
15298 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
15299 Pack));
15300 if (!CapturedVar) {
15301 Invalid = true;
15302 continue;
15303 }
15304
15305 // Capture the transformed variable.
15306 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
15307 }
15308
15309 // FIXME: Retain a pack expansion if RetainExpansion is true.
15310
15311 continue;
15312 }
15313
15314 EllipsisLoc = C->getEllipsisLoc();
15315 }
15316
15317 // Transform the captured variable.
15318 auto *CapturedVar = cast_or_null<ValueDecl>(
15319 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15320 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
15321 Invalid = true;
15322 continue;
15323 }
15324
15325 // This is not an init-capture; however it contains an unexpanded pack e.g.
15326 // ([Pack] {}(), ...)
15327 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
15328 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
15329
15330 // Capture the transformed variable.
15331 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
15332 EllipsisLoc);
15333 }
15334 getSema().finishLambdaExplicitCaptures(LSI);
15335
15336 // Transform the template parameters, and add them to the current
15337 // instantiation scope. The null case is handled correctly.
15338 auto TPL = getDerived().TransformTemplateParameterList(
15339 E->getTemplateParameterList());
15340 LSI->GLTemplateParameterList = TPL;
15341 if (TPL) {
15342 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
15343 TPL);
15344 LSI->ContainsUnexpandedParameterPack |=
15345 TPL->containsUnexpandedParameterPack();
15346 }
15347
15348 TypeLocBuilder NewCallOpTLBuilder;
15349 TypeLoc OldCallOpTypeLoc =
15350 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
15351 QualType NewCallOpType =
15352 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
15353 if (NewCallOpType.isNull())
15354 return ExprError();
15355 LSI->ContainsUnexpandedParameterPack |=
15356 NewCallOpType->containsUnexpandedParameterPack();
15357 TypeSourceInfo *NewCallOpTSI =
15358 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
15359
15360 // The type may be an AttributedType or some other kind of sugar;
15361 // get the actual underlying FunctionProtoType.
15362 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
15363 assert(FPTL && "Not a FunctionProtoType?");
15364
15365 getSema().CompleteLambdaCallOperator(
15366 NewCallOperator, E->getCallOperator()->getLocation(),
15367 E->getCallOperator()->getInnerLocStart(),
15368 E->getCallOperator()->getTrailingRequiresClause(), NewCallOpTSI,
15369 E->getCallOperator()->getConstexprKind(),
15370 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
15371 E->hasExplicitResultType());
15372
15373 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
15374 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
15375
15376 {
15377 // Number the lambda for linkage purposes if necessary.
15378 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
15379
15380 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
15381 if (getDerived().ReplacingOriginal()) {
15382 Numbering = OldClass->getLambdaNumbering();
15383 }
15384
15385 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
15386 }
15387
15388 // FIXME: Sema's lambda-building mechanism expects us to push an expression
15389 // evaluation context even if we're not transforming the function body.
15390 getSema().PushExpressionEvaluationContext(
15391 E->getCallOperator()->isConsteval() ?
15394 getSema().currentEvaluationContext().InImmediateEscalatingFunctionContext =
15395 getSema().getLangOpts().CPlusPlus20 &&
15396 E->getCallOperator()->isImmediateEscalating();
15397
15398 Sema::CodeSynthesisContext C;
15400 C.PointOfInstantiation = E->getBody()->getBeginLoc();
15401 getSema().pushCodeSynthesisContext(C);
15402
15403 // Instantiate the body of the lambda expression.
15404 StmtResult Body =
15405 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
15406
15407 getSema().popCodeSynthesisContext();
15408
15409 // ActOnLambda* will pop the function scope for us.
15410 FuncScopeCleanup.disable();
15411
15412 if (Body.isInvalid()) {
15413 SavedContext.pop();
15414 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
15415 /*IsInstantiation=*/true);
15416 return ExprError();
15417 }
15418
15419 // Copy the LSI before ActOnFinishFunctionBody removes it.
15420 // FIXME: This is dumb. Store the lambda information somewhere that outlives
15421 // the call operator.
15422 auto LSICopy = *LSI;
15423 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15424 /*IsInstantiation*/ true);
15425 SavedContext.pop();
15426
15427 // Recompute the dependency of the lambda so that we can defer the lambda call
15428 // construction until after we have all the necessary template arguments. For
15429 // example, given
15430 //
15431 // template <class> struct S {
15432 // template <class U>
15433 // using Type = decltype([](U){}(42.0));
15434 // };
15435 // void foo() {
15436 // using T = S<int>::Type<float>;
15437 // ^~~~~~
15438 // }
15439 //
15440 // We would end up here from instantiating S<int> when ensuring its
15441 // completeness. That would transform the lambda call expression regardless of
15442 // the absence of the corresponding argument for U.
15443 //
15444 // Going ahead with unsubstituted type U makes things worse: we would soon
15445 // compare the argument type (which is float) against the parameter U
15446 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
15447 // error suggesting unmatched types 'U' and 'float'!
15448 //
15449 // That said, everything will be fine if we defer that semantic checking.
15450 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
15451 // dependent. Since the CallExpr's dependency boils down to the lambda's
15452 // dependency in this case, we can harness that by recomputing the dependency
15453 // from the instantiation arguments.
15454 //
15455 // FIXME: Creating the type of a lambda requires us to have a dependency
15456 // value, which happens before its substitution. We update its dependency
15457 // *after* the substitution in case we can't decide the dependency
15458 // so early, e.g. because we want to see if any of the *substituted*
15459 // parameters are dependent.
15460 DependencyKind = getDerived().ComputeLambdaDependency(&LSICopy);
15461 Class->setLambdaDependencyKind(DependencyKind);
15462 // Clean up the type cache created previously. Then, we re-create a type for
15463 // such Decl with the new DependencyKind.
15464 Class->setTypeForDecl(nullptr);
15465 getSema().Context.getTypeDeclType(Class);
15466
15467 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15468 Body.get()->getEndLoc(), &LSICopy);
15469}
15470
15471template<typename Derived>
15474 return TransformStmt(S);
15475}
15476
15477template<typename Derived>
15480 // Transform captures.
15481 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15482 CEnd = E->capture_end();
15483 C != CEnd; ++C) {
15484 // When we hit the first implicit capture, tell Sema that we've finished
15485 // the list of explicit captures.
15486 if (!C->isImplicit())
15487 continue;
15488
15489 // Capturing 'this' is trivial.
15490 if (C->capturesThis()) {
15491 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15492 /*BuildAndDiagnose*/ true, nullptr,
15493 C->getCaptureKind() == LCK_StarThis);
15494 continue;
15495 }
15496 // Captured expression will be recaptured during captured variables
15497 // rebuilding.
15498 if (C->capturesVLAType())
15499 continue;
15500
15501 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15502 assert(!E->isInitCapture(C) && "implicit init-capture?");
15503
15504 // Transform the captured variable.
15505 VarDecl *CapturedVar = cast_or_null<VarDecl>(
15506 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15507 if (!CapturedVar || CapturedVar->isInvalidDecl())
15508 return StmtError();
15509
15510 // Capture the transformed variable.
15511 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
15512 }
15513
15514 return S;
15515}
15516
15517template<typename Derived>
15521 TypeSourceInfo *T =
15522 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15523 if (!T)
15524 return ExprError();
15525
15526 bool ArgumentChanged = false;
15528 Args.reserve(E->getNumArgs());
15529 {
15532 E->isListInitialization());
15533 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
15534 &ArgumentChanged))
15535 return ExprError();
15536 }
15537
15538 if (!getDerived().AlwaysRebuild() &&
15539 T == E->getTypeSourceInfo() &&
15540 !ArgumentChanged)
15541 return E;
15542
15543 // FIXME: we're faking the locations of the commas
15544 return getDerived().RebuildCXXUnresolvedConstructExpr(
15545 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
15546}
15547
15548template<typename Derived>
15550TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
15551 CXXDependentScopeMemberExpr *E) {
15552 // Transform the base of the expression.
15553 ExprResult Base((Expr*) nullptr);
15554 Expr *OldBase;
15555 QualType BaseType;
15556 QualType ObjectType;
15557 if (!E->isImplicitAccess()) {
15558 OldBase = E->getBase();
15559 Base = getDerived().TransformExpr(OldBase);
15560 if (Base.isInvalid())
15561 return ExprError();
15562
15563 // Start the member reference and compute the object's type.
15564 ParsedType ObjectTy;
15565 bool MayBePseudoDestructor = false;
15566 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15567 E->getOperatorLoc(),
15568 E->isArrow()? tok::arrow : tok::period,
15569 ObjectTy,
15570 MayBePseudoDestructor);
15571 if (Base.isInvalid())
15572 return ExprError();
15573
15574 ObjectType = ObjectTy.get();
15575 BaseType = ((Expr*) Base.get())->getType();
15576 } else {
15577 OldBase = nullptr;
15578 BaseType = getDerived().TransformType(E->getBaseType());
15579 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
15580 }
15581
15582 // Transform the first part of the nested-name-specifier that qualifies
15583 // the member name.
15584 NamedDecl *FirstQualifierInScope
15585 = getDerived().TransformFirstQualifierInScope(
15586 E->getFirstQualifierFoundInScope(),
15587 E->getQualifierLoc().getBeginLoc());
15588
15589 NestedNameSpecifierLoc QualifierLoc;
15590 if (E->getQualifier()) {
15591 QualifierLoc
15592 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
15593 ObjectType,
15594 FirstQualifierInScope);
15595 if (!QualifierLoc)
15596 return ExprError();
15597 }
15598
15599 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15600
15601 // TODO: If this is a conversion-function-id, verify that the
15602 // destination type name (if present) resolves the same way after
15603 // instantiation as it did in the local scope.
15604
15605 DeclarationNameInfo NameInfo
15606 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
15607 if (!NameInfo.getName())
15608 return ExprError();
15609
15610 if (!E->hasExplicitTemplateArgs()) {
15611 // This is a reference to a member without an explicitly-specified
15612 // template argument list. Optimize for this common case.
15613 if (!getDerived().AlwaysRebuild() &&
15614 Base.get() == OldBase &&
15615 BaseType == E->getBaseType() &&
15616 QualifierLoc == E->getQualifierLoc() &&
15617 NameInfo.getName() == E->getMember() &&
15618 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
15619 return E;
15620
15621 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15622 BaseType,
15623 E->isArrow(),
15624 E->getOperatorLoc(),
15625 QualifierLoc,
15626 TemplateKWLoc,
15627 FirstQualifierInScope,
15628 NameInfo,
15629 /*TemplateArgs*/nullptr);
15630 }
15631
15632 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15633 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
15634 E->getNumTemplateArgs(),
15635 TransArgs))
15636 return ExprError();
15637
15638 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15639 BaseType,
15640 E->isArrow(),
15641 E->getOperatorLoc(),
15642 QualifierLoc,
15643 TemplateKWLoc,
15644 FirstQualifierInScope,
15645 NameInfo,
15646 &TransArgs);
15647}
15648
15649template <typename Derived>
15650ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
15651 UnresolvedMemberExpr *Old) {
15652 // Transform the base of the expression.
15653 ExprResult Base((Expr *)nullptr);
15654 QualType BaseType;
15655 if (!Old->isImplicitAccess()) {
15656 Base = getDerived().TransformExpr(Old->getBase());
15657 if (Base.isInvalid())
15658 return ExprError();
15659 Base =
15660 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
15661 if (Base.isInvalid())
15662 return ExprError();
15663 BaseType = Base.get()->getType();
15664 } else {
15665 BaseType = getDerived().TransformType(Old->getBaseType());
15666 }
15667
15668 NestedNameSpecifierLoc QualifierLoc;
15669 if (Old->getQualifierLoc()) {
15670 QualifierLoc =
15671 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15672 if (!QualifierLoc)
15673 return ExprError();
15674 }
15675
15676 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15677
15678 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
15679
15680 // Transform the declaration set.
15681 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
15682 return ExprError();
15683
15684 // Determine the naming class.
15685 if (Old->getNamingClass()) {
15686 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
15687 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
15688 if (!NamingClass)
15689 return ExprError();
15690
15691 R.setNamingClass(NamingClass);
15692 }
15693
15694 TemplateArgumentListInfo TransArgs;
15695 if (Old->hasExplicitTemplateArgs()) {
15696 TransArgs.setLAngleLoc(Old->getLAngleLoc());
15697 TransArgs.setRAngleLoc(Old->getRAngleLoc());
15698 if (getDerived().TransformTemplateArguments(
15699 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
15700 return ExprError();
15701 }
15702
15703 // FIXME: to do this check properly, we will need to preserve the
15704 // first-qualifier-in-scope here, just in case we had a dependent
15705 // base (and therefore couldn't do the check) and a
15706 // nested-name-qualifier (and therefore could do the lookup).
15707 NamedDecl *FirstQualifierInScope = nullptr;
15708
15709 return getDerived().RebuildUnresolvedMemberExpr(
15710 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
15711 TemplateKWLoc, FirstQualifierInScope, R,
15712 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
15713}
15714
15715template<typename Derived>
15717TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
15718 EnterExpressionEvaluationContext Unevaluated(
15720 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
15721 if (SubExpr.isInvalid())
15722 return ExprError();
15723
15724 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
15725 return E;
15726
15727 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
15728}
15729
15730template<typename Derived>
15732TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
15733 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
15734 if (Pattern.isInvalid())
15735 return ExprError();
15736
15737 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
15738 return E;
15739
15740 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
15741 E->getNumExpansions());
15742}
15743
15744template<typename Derived>
15746TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
15747 // If E is not value-dependent, then nothing will change when we transform it.
15748 // Note: This is an instantiation-centric view.
15749 if (!E->isValueDependent())
15750 return E;
15751
15752 EnterExpressionEvaluationContext Unevaluated(
15754
15756 TemplateArgument ArgStorage;
15757
15758 // Find the argument list to transform.
15759 if (E->isPartiallySubstituted()) {
15760 PackArgs = E->getPartialArguments();
15761 } else if (E->isValueDependent()) {
15762 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
15763 bool ShouldExpand = false;
15764 bool RetainExpansion = false;
15765 std::optional<unsigned> NumExpansions;
15766 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
15767 Unexpanded,
15768 ShouldExpand, RetainExpansion,
15769 NumExpansions))
15770 return ExprError();
15771
15772 // If we need to expand the pack, build a template argument from it and
15773 // expand that.
15774 if (ShouldExpand) {
15775 auto *Pack = E->getPack();
15776 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
15777 ArgStorage = getSema().Context.getPackExpansionType(
15778 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
15779 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
15780 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
15781 } else {
15782 auto *VD = cast<ValueDecl>(Pack);
15783 ExprResult DRE = getSema().BuildDeclRefExpr(
15784 VD, VD->getType().getNonLValueExprType(getSema().Context),
15785 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
15786 E->getPackLoc());
15787 if (DRE.isInvalid())
15788 return ExprError();
15789 ArgStorage = new (getSema().Context)
15790 PackExpansionExpr(getSema().Context.DependentTy, DRE.get(),
15791 E->getPackLoc(), std::nullopt);
15792 }
15793 PackArgs = ArgStorage;
15794 }
15795 }
15796
15797 // If we're not expanding the pack, just transform the decl.
15798 if (!PackArgs.size()) {
15799 auto *Pack = cast_or_null<NamedDecl>(
15800 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
15801 if (!Pack)
15802 return ExprError();
15803 return getDerived().RebuildSizeOfPackExpr(
15804 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
15805 std::nullopt, {});
15806 }
15807
15808 // Try to compute the result without performing a partial substitution.
15809 std::optional<unsigned> Result = 0;
15810 for (const TemplateArgument &Arg : PackArgs) {
15811 if (!Arg.isPackExpansion()) {
15812 Result = *Result + 1;
15813 continue;
15814 }
15815
15816 TemplateArgumentLoc ArgLoc;
15817 InventTemplateArgumentLoc(Arg, ArgLoc);
15818
15819 // Find the pattern of the pack expansion.
15820 SourceLocation Ellipsis;
15821 std::optional<unsigned> OrigNumExpansions;
15822 TemplateArgumentLoc Pattern =
15823 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
15824 OrigNumExpansions);
15825
15826 // Substitute under the pack expansion. Do not expand the pack (yet).
15827 TemplateArgumentLoc OutPattern;
15828 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15829 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
15830 /*Uneval*/ true))
15831 return true;
15832
15833 // See if we can determine the number of arguments from the result.
15834 std::optional<unsigned> NumExpansions =
15835 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
15836 if (!NumExpansions) {
15837 // No: we must be in an alias template expansion, and we're going to need
15838 // to actually expand the packs.
15839 Result = std::nullopt;
15840 break;
15841 }
15842
15843 Result = *Result + *NumExpansions;
15844 }
15845
15846 // Common case: we could determine the number of expansions without
15847 // substituting.
15848 if (Result)
15849 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
15850 E->getPackLoc(),
15851 E->getRParenLoc(), *Result, {});
15852
15853 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
15854 E->getPackLoc());
15855 {
15856 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
15857 typedef TemplateArgumentLocInventIterator<
15858 Derived, const TemplateArgument*> PackLocIterator;
15859 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
15860 PackLocIterator(*this, PackArgs.end()),
15861 TransformedPackArgs, /*Uneval*/true))
15862 return ExprError();
15863 }
15864
15865 // Check whether we managed to fully-expand the pack.
15866 // FIXME: Is it possible for us to do so and not hit the early exit path?
15868 bool PartialSubstitution = false;
15869 for (auto &Loc : TransformedPackArgs.arguments()) {
15870 Args.push_back(Loc.getArgument());
15871 if (Loc.getArgument().isPackExpansion())
15872 PartialSubstitution = true;
15873 }
15874
15875 if (PartialSubstitution)
15876 return getDerived().RebuildSizeOfPackExpr(
15877 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
15878 std::nullopt, Args);
15879
15880 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
15881 E->getPackLoc(), E->getRParenLoc(),
15882 Args.size(), {});
15883}
15884
15885template <typename Derived>
15887TreeTransform<Derived>::TransformPackIndexingExpr(PackIndexingExpr *E) {
15888 if (!E->isValueDependent())
15889 return E;
15890
15891 // Transform the index
15892 ExprResult IndexExpr;
15893 {
15894 EnterExpressionEvaluationContext ConstantContext(
15896 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
15897 if (IndexExpr.isInvalid())
15898 return ExprError();
15899 }
15900
15901 SmallVector<Expr *, 5> ExpandedExprs;
15902 bool FullySubstituted = true;
15903 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
15904 Expr *Pattern = E->getPackIdExpression();
15906 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
15907 Unexpanded);
15908 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
15909
15910 // Determine whether the set of unexpanded parameter packs can and should
15911 // be expanded.
15912 bool ShouldExpand = true;
15913 bool RetainExpansion = false;
15914 std::optional<unsigned> OrigNumExpansions;
15915 std::optional<unsigned> NumExpansions = OrigNumExpansions;
15916 if (getDerived().TryExpandParameterPacks(
15917 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
15918 ShouldExpand, RetainExpansion, NumExpansions))
15919 return true;
15920 if (!ShouldExpand) {
15921 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15922 ExprResult Pack = getDerived().TransformExpr(Pattern);
15923 if (Pack.isInvalid())
15924 return ExprError();
15925 return getDerived().RebuildPackIndexingExpr(
15926 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
15927 {}, /*FullySubstituted=*/false);
15928 }
15929 for (unsigned I = 0; I != *NumExpansions; ++I) {
15930 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15931 ExprResult Out = getDerived().TransformExpr(Pattern);
15932 if (Out.isInvalid())
15933 return true;
15934 if (Out.get()->containsUnexpandedParameterPack()) {
15935 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
15936 OrigNumExpansions);
15937 if (Out.isInvalid())
15938 return true;
15939 FullySubstituted = false;
15940 }
15941 ExpandedExprs.push_back(Out.get());
15942 }
15943 // If we're supposed to retain a pack expansion, do so by temporarily
15944 // forgetting the partially-substituted parameter pack.
15945 if (RetainExpansion) {
15946 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15947
15948 ExprResult Out = getDerived().TransformExpr(Pattern);
15949 if (Out.isInvalid())
15950 return true;
15951
15952 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
15953 OrigNumExpansions);
15954 if (Out.isInvalid())
15955 return true;
15956 FullySubstituted = false;
15957 ExpandedExprs.push_back(Out.get());
15958 }
15959 } else if (!E->expandsToEmptyPack()) {
15960 if (getDerived().TransformExprs(E->getExpressions().data(),
15961 E->getExpressions().size(), false,
15962 ExpandedExprs))
15963 return ExprError();
15964 }
15965
15966 return getDerived().RebuildPackIndexingExpr(
15967 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
15968 IndexExpr.get(), ExpandedExprs, FullySubstituted);
15969}
15970
15971template<typename Derived>
15973TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
15974 SubstNonTypeTemplateParmPackExpr *E) {
15975 // Default behavior is to do nothing with this transformation.
15976 return E;
15977}
15978
15979template<typename Derived>
15981TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
15982 SubstNonTypeTemplateParmExpr *E) {
15983 // Default behavior is to do nothing with this transformation.
15984 return E;
15985}
15986
15987template<typename Derived>
15989TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
15990 // Default behavior is to do nothing with this transformation.
15991 return E;
15992}
15993
15994template<typename Derived>
15996TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
15997 MaterializeTemporaryExpr *E) {
15998 return getDerived().TransformExpr(E->getSubExpr());
15999}
16000
16001template<typename Derived>
16003TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
16004 UnresolvedLookupExpr *Callee = nullptr;
16005 if (Expr *OldCallee = E->getCallee()) {
16006 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
16007 if (CalleeResult.isInvalid())
16008 return ExprError();
16009 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
16010 }
16011
16012 Expr *Pattern = E->getPattern();
16013
16015 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
16016 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16017
16018 // Determine whether the set of unexpanded parameter packs can and should
16019 // be expanded.
16020 bool Expand = true;
16021 bool RetainExpansion = false;
16022 std::optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
16023 NumExpansions = OrigNumExpansions;
16024 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
16025 Pattern->getSourceRange(),
16026 Unexpanded,
16027 Expand, RetainExpansion,
16028 NumExpansions))
16029 return true;
16030
16031 if (!Expand) {
16032 // Do not expand any packs here, just transform and rebuild a fold
16033 // expression.
16034 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16035
16036 ExprResult LHS =
16037 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
16038 if (LHS.isInvalid())
16039 return true;
16040
16041 ExprResult RHS =
16042 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
16043 if (RHS.isInvalid())
16044 return true;
16045
16046 if (!getDerived().AlwaysRebuild() &&
16047 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
16048 return E;
16049
16050 return getDerived().RebuildCXXFoldExpr(
16051 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
16052 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
16053 }
16054
16055 // Formally a fold expression expands to nested parenthesized expressions.
16056 // Enforce this limit to avoid creating trees so deep we can't safely traverse
16057 // them.
16058 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) {
16059 SemaRef.Diag(E->getEllipsisLoc(),
16060 clang::diag::err_fold_expression_limit_exceeded)
16061 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
16062 << E->getSourceRange();
16063 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
16064 return ExprError();
16065 }
16066
16067 // The transform has determined that we should perform an elementwise
16068 // expansion of the pattern. Do so.
16069 ExprResult Result = getDerived().TransformExpr(E->getInit());
16070 if (Result.isInvalid())
16071 return true;
16072 bool LeftFold = E->isLeftFold();
16073
16074 // If we're retaining an expansion for a right fold, it is the innermost
16075 // component and takes the init (if any).
16076 if (!LeftFold && RetainExpansion) {
16077 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16078
16079 ExprResult Out = getDerived().TransformExpr(Pattern);
16080 if (Out.isInvalid())
16081 return true;
16082
16083 Result = getDerived().RebuildCXXFoldExpr(
16084 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
16085 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
16086 if (Result.isInvalid())
16087 return true;
16088 }
16089
16090 for (unsigned I = 0; I != *NumExpansions; ++I) {
16091 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
16092 getSema(), LeftFold ? I : *NumExpansions - I - 1);
16093 ExprResult Out = getDerived().TransformExpr(Pattern);
16094 if (Out.isInvalid())
16095 return true;
16096
16097 if (Out.get()->containsUnexpandedParameterPack()) {
16098 // We still have a pack; retain a pack expansion for this slice.
16099 Result = getDerived().RebuildCXXFoldExpr(
16100 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
16101 E->getOperator(), E->getEllipsisLoc(),
16102 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
16103 OrigNumExpansions);
16104 } else if (Result.isUsable()) {
16105 // We've got down to a single element; build a binary operator.
16106 Expr *LHS = LeftFold ? Result.get() : Out.get();
16107 Expr *RHS = LeftFold ? Out.get() : Result.get();
16108 if (Callee) {
16109 UnresolvedSet<16> Functions;
16110 Functions.append(Callee->decls_begin(), Callee->decls_end());
16111 Result = getDerived().RebuildCXXOperatorCallExpr(
16113 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
16114 Functions, LHS, RHS);
16115 } else {
16116 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
16117 E->getOperator(), LHS, RHS);
16118 }
16119 } else
16120 Result = Out;
16121
16122 if (Result.isInvalid())
16123 return true;
16124 }
16125
16126 // If we're retaining an expansion for a left fold, it is the outermost
16127 // component and takes the complete expansion so far as its init (if any).
16128 if (LeftFold && RetainExpansion) {
16129 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16130
16131 ExprResult Out = getDerived().TransformExpr(Pattern);
16132 if (Out.isInvalid())
16133 return true;
16134
16135 Result = getDerived().RebuildCXXFoldExpr(
16136 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
16137 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
16138 if (Result.isInvalid())
16139 return true;
16140 }
16141
16142 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
16143 PE->setIsProducedByFoldExpansion();
16144
16145 // If we had no init and an empty pack, and we're not retaining an expansion,
16146 // then produce a fallback value or error.
16147 if (Result.isUnset())
16148 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
16149 E->getOperator());
16150 return Result;
16151}
16152
16153template <typename Derived>
16155TreeTransform<Derived>::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) {
16156 SmallVector<Expr *, 4> TransformedInits;
16157 ArrayRef<Expr *> InitExprs = E->getInitExprs();
16158 if (TransformExprs(InitExprs.data(), InitExprs.size(), true,
16159 TransformedInits))
16160 return ExprError();
16161
16162 return getDerived().RebuildParenListExpr(E->getBeginLoc(), TransformedInits,
16163 E->getEndLoc());
16164}
16165
16166template<typename Derived>
16168TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
16169 CXXStdInitializerListExpr *E) {
16170 return getDerived().TransformExpr(E->getSubExpr());
16171}
16172
16173template<typename Derived>
16175TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
16176 return SemaRef.MaybeBindToTemporary(E);
16177}
16178
16179template<typename Derived>
16181TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
16182 return E;
16183}
16184
16185template<typename Derived>
16187TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
16188 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
16189 if (SubExpr.isInvalid())
16190 return ExprError();
16191
16192 if (!getDerived().AlwaysRebuild() &&
16193 SubExpr.get() == E->getSubExpr())
16194 return E;
16195
16196 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
16197}
16198
16199template<typename Derived>
16201TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
16202 // Transform each of the elements.
16203 SmallVector<Expr *, 8> Elements;
16204 bool ArgChanged = false;
16205 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
16206 /*IsCall=*/false, Elements, &ArgChanged))
16207 return ExprError();
16208
16209 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16210 return SemaRef.MaybeBindToTemporary(E);
16211
16212 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
16213 Elements.data(),
16214 Elements.size());
16215}
16216
16217template<typename Derived>
16219TreeTransform<Derived>::TransformObjCDictionaryLiteral(
16220 ObjCDictionaryLiteral *E) {
16221 // Transform each of the elements.
16223 bool ArgChanged = false;
16224 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
16225 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
16226
16227 if (OrigElement.isPackExpansion()) {
16228 // This key/value element is a pack expansion.
16230 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
16231 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
16232 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16233
16234 // Determine whether the set of unexpanded parameter packs can
16235 // and should be expanded.
16236 bool Expand = true;
16237 bool RetainExpansion = false;
16238 std::optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
16239 std::optional<unsigned> NumExpansions = OrigNumExpansions;
16240 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
16241 OrigElement.Value->getEndLoc());
16242 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
16243 PatternRange, Unexpanded, Expand,
16244 RetainExpansion, NumExpansions))
16245 return ExprError();
16246
16247 if (!Expand) {
16248 // The transform has determined that we should perform a simple
16249 // transformation on the pack expansion, producing another pack
16250 // expansion.
16251 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16252 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16253 if (Key.isInvalid())
16254 return ExprError();
16255
16256 if (Key.get() != OrigElement.Key)
16257 ArgChanged = true;
16258
16259 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16260 if (Value.isInvalid())
16261 return ExprError();
16262
16263 if (Value.get() != OrigElement.Value)
16264 ArgChanged = true;
16265
16266 ObjCDictionaryElement Expansion = {
16267 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
16268 };
16269 Elements.push_back(Expansion);
16270 continue;
16271 }
16272
16273 // Record right away that the argument was changed. This needs
16274 // to happen even if the array expands to nothing.
16275 ArgChanged = true;
16276
16277 // The transform has determined that we should perform an elementwise
16278 // expansion of the pattern. Do so.
16279 for (unsigned I = 0; I != *NumExpansions; ++I) {
16280 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
16281 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16282 if (Key.isInvalid())
16283 return ExprError();
16284
16285 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16286 if (Value.isInvalid())
16287 return ExprError();
16288
16289 ObjCDictionaryElement Element = {
16290 Key.get(), Value.get(), SourceLocation(), NumExpansions
16291 };
16292
16293 // If any unexpanded parameter packs remain, we still have a
16294 // pack expansion.
16295 // FIXME: Can this really happen?
16296 if (Key.get()->containsUnexpandedParameterPack() ||
16297 Value.get()->containsUnexpandedParameterPack())
16298 Element.EllipsisLoc = OrigElement.EllipsisLoc;
16299
16300 Elements.push_back(Element);
16301 }
16302
16303 // FIXME: Retain a pack expansion if RetainExpansion is true.
16304
16305 // We've finished with this pack expansion.
16306 continue;
16307 }
16308
16309 // Transform and check key.
16310 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16311 if (Key.isInvalid())
16312 return ExprError();
16313
16314 if (Key.get() != OrigElement.Key)
16315 ArgChanged = true;
16316
16317 // Transform and check value.
16319 = getDerived().TransformExpr(OrigElement.Value);
16320 if (Value.isInvalid())
16321 return ExprError();
16322
16323 if (Value.get() != OrigElement.Value)
16324 ArgChanged = true;
16325
16326 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
16327 std::nullopt};
16328 Elements.push_back(Element);
16329 }
16330
16331 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16332 return SemaRef.MaybeBindToTemporary(E);
16333
16334 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
16335 Elements);
16336}
16337
16338template<typename Derived>
16340TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
16341 TypeSourceInfo *EncodedTypeInfo
16342 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
16343 if (!EncodedTypeInfo)
16344 return ExprError();
16345
16346 if (!getDerived().AlwaysRebuild() &&
16347 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
16348 return E;
16349
16350 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
16351 EncodedTypeInfo,
16352 E->getRParenLoc());
16353}
16354
16355template<typename Derived>
16356ExprResult TreeTransform<Derived>::
16357TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
16358 // This is a kind of implicit conversion, and it needs to get dropped
16359 // and recomputed for the same general reasons that ImplicitCastExprs
16360 // do, as well a more specific one: this expression is only valid when
16361 // it appears *immediately* as an argument expression.
16362 return getDerived().TransformExpr(E->getSubExpr());
16363}
16364
16365template<typename Derived>
16366ExprResult TreeTransform<Derived>::
16367TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
16368 TypeSourceInfo *TSInfo
16369 = getDerived().TransformType(E->getTypeInfoAsWritten());
16370 if (!TSInfo)
16371 return ExprError();
16372
16373 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
16374 if (Result.isInvalid())
16375 return ExprError();
16376
16377 if (!getDerived().AlwaysRebuild() &&
16378 TSInfo == E->getTypeInfoAsWritten() &&
16379 Result.get() == E->getSubExpr())
16380 return E;
16381
16382 return SemaRef.ObjC().BuildObjCBridgedCast(
16383 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
16384 Result.get());
16385}
16386
16387template <typename Derived>
16388ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
16389 ObjCAvailabilityCheckExpr *E) {
16390 return E;
16391}
16392
16393template<typename Derived>
16395TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
16396 // Transform arguments.
16397 bool ArgChanged = false;
16399 Args.reserve(E->getNumArgs());
16400 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
16401 &ArgChanged))
16402 return ExprError();
16403
16404 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
16405 // Class message: transform the receiver type.
16406 TypeSourceInfo *ReceiverTypeInfo
16407 = getDerived().TransformType(E->getClassReceiverTypeInfo());
16408 if (!ReceiverTypeInfo)
16409 return ExprError();
16410
16411 // If nothing changed, just retain the existing message send.
16412 if (!getDerived().AlwaysRebuild() &&
16413 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
16414 return SemaRef.MaybeBindToTemporary(E);
16415
16416 // Build a new class message send.
16418 E->getSelectorLocs(SelLocs);
16419 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
16420 E->getSelector(),
16421 SelLocs,
16422 E->getMethodDecl(),
16423 E->getLeftLoc(),
16424 Args,
16425 E->getRightLoc());
16426 }
16427 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
16428 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16429 if (!E->getMethodDecl())
16430 return ExprError();
16431
16432 // Build a new class message send to 'super'.
16434 E->getSelectorLocs(SelLocs);
16435 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
16436 E->getSelector(),
16437 SelLocs,
16438 E->getReceiverType(),
16439 E->getMethodDecl(),
16440 E->getLeftLoc(),
16441 Args,
16442 E->getRightLoc());
16443 }
16444
16445 // Instance message: transform the receiver
16446 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
16447 "Only class and instance messages may be instantiated");
16448 ExprResult Receiver
16449 = getDerived().TransformExpr(E->getInstanceReceiver());
16450 if (Receiver.isInvalid())
16451 return ExprError();
16452
16453 // If nothing changed, just retain the existing message send.
16454 if (!getDerived().AlwaysRebuild() &&
16455 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
16456 return SemaRef.MaybeBindToTemporary(E);
16457
16458 // Build a new instance message send.
16460 E->getSelectorLocs(SelLocs);
16461 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
16462 E->getSelector(),
16463 SelLocs,
16464 E->getMethodDecl(),
16465 E->getLeftLoc(),
16466 Args,
16467 E->getRightLoc());
16468}
16469
16470template<typename Derived>
16472TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
16473 return E;
16474}
16475
16476template<typename Derived>
16478TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
16479 return E;
16480}
16481
16482template<typename Derived>
16484TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
16485 // Transform the base expression.
16486 ExprResult Base = getDerived().TransformExpr(E->getBase());
16487 if (Base.isInvalid())
16488 return ExprError();
16489
16490 // We don't need to transform the ivar; it will never change.
16491
16492 // If nothing changed, just retain the existing expression.
16493 if (!getDerived().AlwaysRebuild() &&
16494 Base.get() == E->getBase())
16495 return E;
16496
16497 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
16498 E->getLocation(),
16499 E->isArrow(), E->isFreeIvar());
16500}
16501
16502template<typename Derived>
16504TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
16505 // 'super' and types never change. Property never changes. Just
16506 // retain the existing expression.
16507 if (!E->isObjectReceiver())
16508 return E;
16509
16510 // Transform the base expression.
16511 ExprResult Base = getDerived().TransformExpr(E->getBase());
16512 if (Base.isInvalid())
16513 return ExprError();
16514
16515 // We don't need to transform the property; it will never change.
16516
16517 // If nothing changed, just retain the existing expression.
16518 if (!getDerived().AlwaysRebuild() &&
16519 Base.get() == E->getBase())
16520 return E;
16521
16522 if (E->isExplicitProperty())
16523 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16524 E->getExplicitProperty(),
16525 E->getLocation());
16526
16527 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16528 SemaRef.Context.PseudoObjectTy,
16529 E->getImplicitPropertyGetter(),
16530 E->getImplicitPropertySetter(),
16531 E->getLocation());
16532}
16533
16534template<typename Derived>
16536TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
16537 // Transform the base expression.
16538 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
16539 if (Base.isInvalid())
16540 return ExprError();
16541
16542 // Transform the key expression.
16543 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
16544 if (Key.isInvalid())
16545 return ExprError();
16546
16547 // If nothing changed, just retain the existing expression.
16548 if (!getDerived().AlwaysRebuild() &&
16549 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
16550 return E;
16551
16552 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
16553 Base.get(), Key.get(),
16554 E->getAtIndexMethodDecl(),
16555 E->setAtIndexMethodDecl());
16556}
16557
16558template<typename Derived>
16560TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
16561 // Transform the base expression.
16562 ExprResult Base = getDerived().TransformExpr(E->getBase());
16563 if (Base.isInvalid())
16564 return ExprError();
16565
16566 // If nothing changed, just retain the existing expression.
16567 if (!getDerived().AlwaysRebuild() &&
16568 Base.get() == E->getBase())
16569 return E;
16570
16571 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
16572 E->getOpLoc(),
16573 E->isArrow());
16574}
16575
16576template<typename Derived>
16578TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
16579 bool ArgumentChanged = false;
16580 SmallVector<Expr*, 8> SubExprs;
16581 SubExprs.reserve(E->getNumSubExprs());
16582 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
16583 SubExprs, &ArgumentChanged))
16584 return ExprError();
16585
16586 if (!getDerived().AlwaysRebuild() &&
16587 !ArgumentChanged)
16588 return E;
16589
16590 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
16591 SubExprs,
16592 E->getRParenLoc());
16593}
16594
16595template<typename Derived>
16597TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
16598 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
16599 if (SrcExpr.isInvalid())
16600 return ExprError();
16601
16602 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
16603 if (!Type)
16604 return ExprError();
16605
16606 if (!getDerived().AlwaysRebuild() &&
16607 Type == E->getTypeSourceInfo() &&
16608 SrcExpr.get() == E->getSrcExpr())
16609 return E;
16610
16611 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
16612 SrcExpr.get(), Type,
16613 E->getRParenLoc());
16614}
16615
16616template<typename Derived>
16618TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
16619 BlockDecl *oldBlock = E->getBlockDecl();
16620
16621 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
16622 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
16623
16624 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
16625 blockScope->TheDecl->setBlockMissingReturnType(
16626 oldBlock->blockMissingReturnType());
16627
16629 SmallVector<QualType, 4> paramTypes;
16630
16631 const FunctionProtoType *exprFunctionType = E->getFunctionType();
16632
16633 // Parameter substitution.
16634 Sema::ExtParameterInfoBuilder extParamInfos;
16635 if (getDerived().TransformFunctionTypeParams(
16636 E->getCaretLocation(), oldBlock->parameters(), nullptr,
16637 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
16638 extParamInfos)) {
16639 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
16640 return ExprError();
16641 }
16642
16643 QualType exprResultType =
16644 getDerived().TransformType(exprFunctionType->getReturnType());
16645
16646 auto epi = exprFunctionType->getExtProtoInfo();
16647 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
16648
16649 QualType functionType =
16650 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
16651 blockScope->FunctionType = functionType;
16652
16653 // Set the parameters on the block decl.
16654 if (!params.empty())
16655 blockScope->TheDecl->setParams(params);
16656
16657 if (!oldBlock->blockMissingReturnType()) {
16658 blockScope->HasImplicitReturnType = false;
16659 blockScope->ReturnType = exprResultType;
16660 }
16661
16662 // Transform the body
16663 StmtResult body = getDerived().TransformStmt(E->getBody());
16664 if (body.isInvalid()) {
16665 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
16666 return ExprError();
16667 }
16668
16669#ifndef NDEBUG
16670 // In builds with assertions, make sure that we captured everything we
16671 // captured before.
16672 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
16673 for (const auto &I : oldBlock->captures()) {
16674 VarDecl *oldCapture = I.getVariable();
16675
16676 // Ignore parameter packs.
16677 if (oldCapture->isParameterPack())
16678 continue;
16679
16680 VarDecl *newCapture =
16681 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
16682 oldCapture));
16683 assert(blockScope->CaptureMap.count(newCapture));
16684 }
16685
16686 // The this pointer may not be captured by the instantiated block, even when
16687 // it's captured by the original block, if the expression causing the
16688 // capture is in the discarded branch of a constexpr if statement.
16689 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
16690 "this pointer isn't captured in the old block");
16691 }
16692#endif
16693
16694 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
16695 /*Scope=*/nullptr);
16696}
16697
16698template<typename Derived>
16700TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
16701 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
16702 if (SrcExpr.isInvalid())
16703 return ExprError();
16704
16705 QualType Type = getDerived().TransformType(E->getType());
16706
16707 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
16708 E->getRParenLoc());
16709}
16710
16711template<typename Derived>
16713TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
16714 bool ArgumentChanged = false;
16715 SmallVector<Expr*, 8> SubExprs;
16716 SubExprs.reserve(E->getNumSubExprs());
16717 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
16718 SubExprs, &ArgumentChanged))
16719 return ExprError();
16720
16721 if (!getDerived().AlwaysRebuild() &&
16722 !ArgumentChanged)
16723 return E;
16724
16725 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
16726 E->getOp(), E->getRParenLoc());
16727}
16728
16729//===----------------------------------------------------------------------===//
16730// Type reconstruction
16731//===----------------------------------------------------------------------===//
16732
16733template<typename Derived>
16736 return SemaRef.BuildPointerType(PointeeType, Star,
16737 getDerived().getBaseEntity());
16738}
16739
16740template<typename Derived>
16743 return SemaRef.BuildBlockPointerType(PointeeType, Star,
16744 getDerived().getBaseEntity());
16745}
16746
16747template<typename Derived>
16750 bool WrittenAsLValue,
16751 SourceLocation Sigil) {
16752 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
16753 Sigil, getDerived().getBaseEntity());
16754}
16755
16756template<typename Derived>
16759 QualType ClassType,
16760 SourceLocation Sigil) {
16761 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
16762 getDerived().getBaseEntity());
16763}
16764
16765template<typename Derived>
16767 const ObjCTypeParamDecl *Decl,
16768 SourceLocation ProtocolLAngleLoc,
16770 ArrayRef<SourceLocation> ProtocolLocs,
16771 SourceLocation ProtocolRAngleLoc) {
16772 return SemaRef.ObjC().BuildObjCTypeParamType(
16773 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16774 /*FailOnError=*/true);
16775}
16776
16777template<typename Derived>
16779 QualType BaseType,
16781 SourceLocation TypeArgsLAngleLoc,
16783 SourceLocation TypeArgsRAngleLoc,
16784 SourceLocation ProtocolLAngleLoc,
16786 ArrayRef<SourceLocation> ProtocolLocs,
16787 SourceLocation ProtocolRAngleLoc) {
16788 return SemaRef.ObjC().BuildObjCObjectType(
16789 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
16790 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16791 /*FailOnError=*/true,
16792 /*Rebuilding=*/true);
16793}
16794
16795template<typename Derived>
16797 QualType PointeeType,
16799 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
16800}
16801
16802template <typename Derived>
16804 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
16805 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16806 if (SizeExpr || !Size)
16807 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
16808 IndexTypeQuals, BracketsRange,
16809 getDerived().getBaseEntity());
16810
16811 QualType Types[] = {
16815 };
16816 QualType SizeType;
16817 for (const auto &T : Types)
16818 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
16819 SizeType = T;
16820 break;
16821 }
16822
16823 // Note that we can return a VariableArrayType here in the case where
16824 // the element type was a dependent VariableArrayType.
16825 IntegerLiteral *ArraySize
16826 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
16827 /*FIXME*/BracketsRange.getBegin());
16828 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
16829 IndexTypeQuals, BracketsRange,
16830 getDerived().getBaseEntity());
16831}
16832
16833template <typename Derived>
16835 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
16836 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16837 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
16838 IndexTypeQuals, BracketsRange);
16839}
16840
16841template <typename Derived>
16843 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
16844 SourceRange BracketsRange) {
16845 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
16846 IndexTypeQuals, BracketsRange);
16847}
16848
16849template <typename Derived>
16851 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16852 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16853 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16854 SizeExpr,
16855 IndexTypeQuals, BracketsRange);
16856}
16857
16858template <typename Derived>
16860 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16861 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16862 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16863 SizeExpr,
16864 IndexTypeQuals, BracketsRange);
16865}
16866
16867template <typename Derived>
16869 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
16870 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
16871 AttributeLoc);
16872}
16873
16874template <typename Derived>
16876 unsigned NumElements,
16877 VectorKind VecKind) {
16878 // FIXME: semantic checking!
16879 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
16880}
16881
16882template <typename Derived>
16884 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
16885 VectorKind VecKind) {
16886 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
16887}
16888
16889template<typename Derived>
16891 unsigned NumElements,
16892 SourceLocation AttributeLoc) {
16893 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
16894 NumElements, true);
16895 IntegerLiteral *VectorSize
16896 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
16897 AttributeLoc);
16898 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
16899}
16900
16901template<typename Derived>
16904 Expr *SizeExpr,
16905 SourceLocation AttributeLoc) {
16906 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
16907}
16908
16909template <typename Derived>
16911 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
16912 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
16913 NumColumns);
16914}
16915
16916template <typename Derived>
16918 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
16919 SourceLocation AttributeLoc) {
16920 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
16921 AttributeLoc);
16922}
16923
16924template<typename Derived>
16926 QualType T,
16927 MutableArrayRef<QualType> ParamTypes,
16929 return SemaRef.BuildFunctionType(T, ParamTypes,
16930 getDerived().getBaseLocation(),
16931 getDerived().getBaseEntity(),
16932 EPI);
16933}
16934
16935template<typename Derived>
16937 return SemaRef.Context.getFunctionNoProtoType(T);
16938}
16939
16940template<typename Derived>
16942 Decl *D) {
16943 assert(D && "no decl found");
16944 if (D->isInvalidDecl()) return QualType();
16945
16946 // FIXME: Doesn't account for ObjCInterfaceDecl!
16947 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
16948 // A valid resolved using typename pack expansion decl can have multiple
16949 // UsingDecls, but they must each have exactly one type, and it must be
16950 // the same type in every case. But we must have at least one expansion!
16951 if (UPD->expansions().empty()) {
16952 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
16953 << UPD->isCXXClassMember() << UPD;
16954 return QualType();
16955 }
16956
16957 // We might still have some unresolved types. Try to pick a resolved type
16958 // if we can. The final instantiation will check that the remaining
16959 // unresolved types instantiate to the type we pick.
16960 QualType FallbackT;
16961 QualType T;
16962 for (auto *E : UPD->expansions()) {
16963 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
16964 if (ThisT.isNull())
16965 continue;
16966 else if (ThisT->getAs<UnresolvedUsingType>())
16967 FallbackT = ThisT;
16968 else if (T.isNull())
16969 T = ThisT;
16970 else
16971 assert(getSema().Context.hasSameType(ThisT, T) &&
16972 "mismatched resolved types in using pack expansion");
16973 }
16974 return T.isNull() ? FallbackT : T;
16975 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
16976 assert(Using->hasTypename() &&
16977 "UnresolvedUsingTypenameDecl transformed to non-typename using");
16978
16979 // A valid resolved using typename decl points to exactly one type decl.
16980 assert(++Using->shadow_begin() == Using->shadow_end());
16981
16982 UsingShadowDecl *Shadow = *Using->shadow_begin();
16983 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), Loc))
16984 return QualType();
16985 return SemaRef.Context.getUsingType(
16986 Shadow, SemaRef.Context.getTypeDeclType(
16987 cast<TypeDecl>(Shadow->getTargetDecl())));
16988 } else {
16989 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
16990 "UnresolvedUsingTypenameDecl transformed to non-using decl");
16991 return SemaRef.Context.getTypeDeclType(
16992 cast<UnresolvedUsingTypenameDecl>(D));
16993 }
16994}
16995
16996template <typename Derived>
16998 TypeOfKind Kind) {
16999 return SemaRef.BuildTypeofExprType(E, Kind);
17000}
17001
17002template<typename Derived>
17004 TypeOfKind Kind) {
17005 return SemaRef.Context.getTypeOfType(Underlying, Kind);
17006}
17007
17008template <typename Derived>
17010 return SemaRef.BuildDecltypeType(E);
17011}
17012
17013template <typename Derived>
17015 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
17016 SourceLocation EllipsisLoc, bool FullySubstituted,
17017 ArrayRef<QualType> Expansions) {
17018 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
17019 FullySubstituted, Expansions);
17020}
17021
17022template<typename Derived>
17026 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
17027}
17028
17029template<typename Derived>
17031 TemplateName Template,
17032 SourceLocation TemplateNameLoc,
17033 TemplateArgumentListInfo &TemplateArgs) {
17034 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
17035}
17036
17037template<typename Derived>
17039 SourceLocation KWLoc) {
17040 return SemaRef.BuildAtomicType(ValueType, KWLoc);
17041}
17042
17043template<typename Derived>
17045 SourceLocation KWLoc,
17046 bool isReadPipe) {
17047 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
17048 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
17049}
17050
17051template <typename Derived>
17053 unsigned NumBits,
17055 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17056 NumBits, true);
17057 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
17058 SemaRef.Context.IntTy, Loc);
17059 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
17060}
17061
17062template <typename Derived>
17064 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
17065 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
17066}
17067
17068template<typename Derived>
17071 bool TemplateKW,
17072 TemplateDecl *Template) {
17073 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
17074 TemplateName(Template));
17075}
17076
17077template<typename Derived>
17080 SourceLocation TemplateKWLoc,
17081 const IdentifierInfo &Name,
17082 SourceLocation NameLoc,
17083 QualType ObjectType,
17084 NamedDecl *FirstQualifierInScope,
17085 bool AllowInjectedClassName) {
17087 TemplateName.setIdentifier(&Name, NameLoc);
17088 Sema::TemplateTy Template;
17089 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
17090 TemplateName, ParsedType::make(ObjectType),
17091 /*EnteringContext=*/false, Template,
17092 AllowInjectedClassName);
17093 return Template.get();
17094}
17095
17096template<typename Derived>
17099 SourceLocation TemplateKWLoc,
17100 OverloadedOperatorKind Operator,
17101 SourceLocation NameLoc,
17102 QualType ObjectType,
17103 bool AllowInjectedClassName) {
17104 UnqualifiedId Name;
17105 // FIXME: Bogus location information.
17106 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
17107 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
17108 Sema::TemplateTy Template;
17109 getSema().ActOnTemplateName(
17110 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
17111 /*EnteringContext=*/false, Template, AllowInjectedClassName);
17112 return Template.get();
17113}
17114
17115template <typename Derived>
17118 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
17119 Expr *Second) {
17120 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
17121
17122 if (First->getObjectKind() == OK_ObjCProperty) {
17125 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
17126 Opc, First, Second);
17128 if (Result.isInvalid())
17129 return ExprError();
17130 First = Result.get();
17131 }
17132
17133 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
17134 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
17135 if (Result.isInvalid())
17136 return ExprError();
17137 Second = Result.get();
17138 }
17139
17140 // Determine whether this should be a builtin operation.
17141 if (Op == OO_Subscript) {
17142 if (!First->getType()->isOverloadableType() &&
17143 !Second->getType()->isOverloadableType())
17144 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
17145 OpLoc);
17146 } else if (Op == OO_Arrow) {
17147 // It is possible that the type refers to a RecoveryExpr created earlier
17148 // in the tree transformation.
17149 if (First->getType()->isDependentType())
17150 return ExprError();
17151 // -> is never a builtin operation.
17152 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
17153 } else if (Second == nullptr || isPostIncDec) {
17154 if (!First->getType()->isOverloadableType() ||
17155 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
17156 // The argument is not of overloadable type, or this is an expression
17157 // of the form &Class::member, so try to create a built-in unary
17158 // operation.
17160 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17161
17162 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
17163 }
17164 } else {
17165 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
17166 !First->getType()->isOverloadableType() &&
17167 !Second->getType()->isOverloadableType()) {
17168 // Neither of the arguments is type-dependent or has an overloadable
17169 // type, so try to create a built-in binary operation.
17172 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
17173 if (Result.isInvalid())
17174 return ExprError();
17175
17176 return Result;
17177 }
17178 }
17179
17180 // Create the overloaded operator invocation for unary operators.
17181 if (!Second || isPostIncDec) {
17183 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17184 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
17185 RequiresADL);
17186 }
17187
17188 // Create the overloaded operator invocation for binary operators.
17190 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
17191 First, Second, RequiresADL);
17192 if (Result.isInvalid())
17193 return ExprError();
17194
17195 return Result;
17196}
17197
17198template<typename Derived>
17201 SourceLocation OperatorLoc,
17202 bool isArrow,
17203 CXXScopeSpec &SS,
17204 TypeSourceInfo *ScopeType,
17205 SourceLocation CCLoc,
17206 SourceLocation TildeLoc,
17207 PseudoDestructorTypeStorage Destroyed) {
17208 QualType BaseType = Base->getType();
17209 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
17210 (!isArrow && !BaseType->getAs<RecordType>()) ||
17211 (isArrow && BaseType->getAs<PointerType>() &&
17212 !BaseType->castAs<PointerType>()->getPointeeType()
17213 ->template getAs<RecordType>())){
17214 // This pseudo-destructor expression is still a pseudo-destructor.
17215 return SemaRef.BuildPseudoDestructorExpr(
17216 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
17217 CCLoc, TildeLoc, Destroyed);
17218 }
17219
17220 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
17222 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
17223 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
17224 NameInfo.setNamedTypeInfo(DestroyedType);
17225
17226 // The scope type is now known to be a valid nested name specifier
17227 // component. Tack it on to the end of the nested name specifier.
17228 if (ScopeType) {
17229 if (!ScopeType->getType()->getAs<TagType>()) {
17230 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
17231 diag::err_expected_class_or_namespace)
17232 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
17233 return ExprError();
17234 }
17235 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
17236 CCLoc);
17237 }
17238
17239 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
17240 return getSema().BuildMemberReferenceExpr(Base, BaseType,
17241 OperatorLoc, isArrow,
17242 SS, TemplateKWLoc,
17243 /*FIXME: FirstQualifier*/ nullptr,
17244 NameInfo,
17245 /*TemplateArgs*/ nullptr,
17246 /*S*/nullptr);
17247}
17248
17249template<typename Derived>
17252 SourceLocation Loc = S->getBeginLoc();
17253 CapturedDecl *CD = S->getCapturedDecl();
17254 unsigned NumParams = CD->getNumParams();
17255 unsigned ContextParamPos = CD->getContextParamPosition();
17257 for (unsigned I = 0; I < NumParams; ++I) {
17258 if (I != ContextParamPos) {
17259 Params.push_back(
17260 std::make_pair(
17261 CD->getParam(I)->getName(),
17262 getDerived().TransformType(CD->getParam(I)->getType())));
17263 } else {
17264 Params.push_back(std::make_pair(StringRef(), QualType()));
17265 }
17266 }
17267 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
17268 S->getCapturedRegionKind(), Params);
17269 StmtResult Body;
17270 {
17271 Sema::CompoundScopeRAII CompoundScope(getSema());
17272 Body = getDerived().TransformStmt(S->getCapturedStmt());
17273 }
17274
17275 if (Body.isInvalid()) {
17276 getSema().ActOnCapturedRegionError();
17277 return StmtError();
17278 }
17279
17280 return getSema().ActOnCapturedRegionEnd(Body.get());
17281}
17282
17283template <typename Derived>
17284ExprResult TreeTransform<Derived>::TransformHLSLOutArgExpr(HLSLOutArgExpr *E) {
17285 // We can transform the base expression and allow argument resolution to fill
17286 // in the rest.
17287 return getDerived().TransformExpr(E->getArgLValue());
17288}
17289
17290} // end namespace clang
17291
17292#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
MatchType Type
const Decl * D
Expr * E
unsigned OldSize
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1172
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
int Priority
Definition: Format.cpp:3036
unsigned Iter
Definition: HTMLLogger.cpp:153
#define X(type, name)
Definition: Value.h:144
llvm::MachO::Target Target
Definition: MachO.h:51
llvm::MachO::Record Record
Definition: MachO.h:31
This file defines OpenMP AST classes for clauses.
Defines some OpenMP-specific enums and functions.
uint32_t Id
Definition: SemaARM.cpp:1134
SourceRange Range
Definition: SemaObjC.cpp:758
SourceLocation Loc
Definition: SemaObjC.cpp:759
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenACC constructs and clauses.
This file declares semantic analysis for OpenMP constructs and clauses.
This file declares semantic analysis for expressions involving.
This file declares semantic analysis for SYCL constructs.
Defines the Objective-C statement AST node classes.
This file defines OpenACC AST classes for statement-level contructs.
This file defines OpenMP AST classes for executable directives and clauses.
static QualType getPointeeType(const MemRegion *R)
SourceLocation Begin
std::string Label
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1141
unsigned getIntWidth(QualType T) const
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, ConceptDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgumentLoc > Args) const
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:684
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2716
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2732
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex, SubstTemplateTypeParmTypeFlag Flag=SubstTemplateTypeParmTypeFlag::None) const
Retrieve a substitution-result type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1703
IdentifierTable & Idents
Definition: ASTContext.h:680
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
CanQualType UnsignedLongTy
Definition: ASTContext.h:1170
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
CanQualType IntTy
Definition: ASTContext.h:1169
CanQualType PseudoObjectTy
Definition: ASTContext.h:1191
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2289
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
CanQualType UnsignedInt128Ty
Definition: ASTContext.h:1171
CanQualType BuiltinFnTy
Definition: ASTContext.h:1190
CanQualType UnsignedCharTy
Definition: ASTContext.h:1170
CanQualType UnsignedIntTy
Definition: ASTContext.h:1170
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1171
CanQualType UnsignedShortTy
Definition: ASTContext.h:1170
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
QualType getHLSLAttributedResourceType(QualType Wrapped, QualType Contained, const HLSLAttributedResourceType::Attributes &Attrs)
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
QualType getConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns) const
Return the unique reference to the matrix type of the specified element type and size.
PtrTy get() const
Definition: Ownership.h:170
bool isInvalid() const
Definition: Ownership.h:166
bool isUsable() const
Definition: Ownership.h:168
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2853
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2665
TypeLoc getValueLoc() const
Definition: TypeLoc.h:2641
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2649
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2657
Attr - This represents one attribute.
Definition: Attr.h:43
attr::Kind getKind() const
Definition: Attr.h:89
Represents an attribute applied to a statement.
Definition: Stmt.h:2117
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:6556
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:6566
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:6571
AutoTypeKeyword getKeyword() const
Definition: Type.h:6587
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2189
bool isAssignmentOp() const
Definition: Expr.h:4048
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:2151
void setIsVariadic(bool value)
Definition: Decl.h:4550
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5298
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:5317
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:5316
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1491
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1546
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1714
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1689
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition: ExprCXX.h:1639
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:568
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:562
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1628
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1686
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2553
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:1018
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1737
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
unsigned getLambdaDependencyKind() const
Definition: DeclCXX.h:1871
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2182
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:74
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:236
SourceRange getRange() const
Definition: DeclSpec.h:80
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition: DeclSpec.cpp:101
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition: DeclSpec.cpp:149
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:95
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:240
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:111
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
Definition: DeclSpec.cpp:51
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:129
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:797
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3557
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1492
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4673
unsigned getNumParams() const
Definition: Decl.h:4715
unsigned getContextParamPosition() const
Definition: Decl.h:4744
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4717
This captures a statement into a function.
Definition: Stmt.h:3794
Expr * getSubExpr()
Definition: Expr.h:3597
SourceLocation getBegin() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1638
Declaration of a C++20 concept.
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:87
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:421
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1368
reference front() const
Definition: DeclBase.h:1391
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1435
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1854
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1768
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1529
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:438
bool isInvalidDecl() const
Definition: DeclBase.h:591
SourceLocation getLocation() const
Definition: DeclBase.h:442
DeclContext * getDeclContext()
Definition: DeclBase.h:451
AccessSpecifier getAccess() const
Definition: DeclBase.h:510
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:434
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind, CanQualType Ty)
Returns a declaration name for special kind of C++ name, e.g., for a constructor, destructor,...
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
The name of a declaration.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:777
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:764
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1903
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:6543
bool isDeduced() const
Definition: Type.h:6544
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3323
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:548
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2503
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2527
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2523
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:2519
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2491
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2547
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2487
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2539
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2555
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2531
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:7076
Designation - Represent a full designation, which is a sequence of designators.
Definition: Designator.h:208
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
Definition: Designator.h:172
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
Definition: Designator.h:142
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Designator.h:115
bool hasErrorOccurred() const
Definition: Diagnostic.h:866
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition: Type.h:4823
Expr * getCondition() const
Definition: Type.h:4830
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2350
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2362
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2354
TypeLoc getNamedTypeLoc() const
Definition: TypeLoc.h:2392
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2368
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6943
RAII object that enters a new expression evaluation context.
Represents an enum.
Definition: Decl.h:3847
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3821
This represents one expression.
Definition: Expr.h:110
bool isGLValue() const
Definition: Expr.h:280
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition: Expr.h:516
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition: Expr.h:427
Represents difference between two FPOptions values.
Definition: LangOptions.h:978
Represents a member of a struct/union/class.
Definition: Decl.h:3033
Represents a function declaration or definition.
Definition: Decl.h:1935
QualType getReturnType() const
Definition: Decl.h:2720
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2649
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Definition: Decl.h:2756
Represents an abstract function effect, using just an enumeration describing its kind.
Definition: Type.h:4716
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition: Type.cpp:5223
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition: Type.cpp:5209
ArrayRef< EffectConditionExpr > conditions() const
Definition: Type.h:4937
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4681
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5102
QualType desugar() const
Definition: Type.h:5646
param_type_iterator param_type_begin() const
Definition: Type.h:5515
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:5553
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:5495
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5366
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:5362
unsigned getNumParams() const
Definition: TypeLoc.h:1531
SourceLocation getLocalRangeEnd() const
Definition: TypeLoc.h:1483
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1479
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1495
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1511
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1538
ArrayRef< ParmVarDecl * > getParams() const
Definition: TypeLoc.h:1522
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1503
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1487
void setExceptionSpecRange(SourceRange R)
Definition: TypeLoc.h:1517
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1540
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1475
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1491
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1499
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:4347
QualType getReturnType() const
Definition: Type.h:4643
AssociationTy< false > Association
Definition: Expr.h:6197
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3724
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5841
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:514
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:973
Represents the declaration of a label.
Definition: Decl.h:503
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1954
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition: ExprCXX.h:2019
Represents the results of name lookup.
Definition: Lookup.h:46
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
Definition: Lookup.h:63
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:68
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition: Lookup.h:73
@ NotFound
No entity found met the criteria.
Definition: Lookup.h:50
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition: Lookup.h:55
@ Found
Name lookup found a single declaration that met the criteria.
Definition: Lookup.h:59
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition: Lookup.h:605
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:475
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:362
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition: SemaLookup.cpp:484
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Lookup.h:664
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Lookup.h:575
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Lookup.h:265
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4734
This represents a decl that may have a name.
Definition: Decl.h:253
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:466
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:274
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:280
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:319
Represents a C++ namespace alias.
Definition: DeclCXX.h:3138
Represent a C++ namespace.
Definition: Decl.h:551
A C++ nested-name-specifier augmented with source location information.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:55
This is a basic class for representing single OpenMP executable directive.
Definition: StmtOpenMP.h:266
This represents clauses with a list of expressions that are mappable.
This represents '#pragma omp metadirective' directive.
Definition: StmtOpenMP.h:6064
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1951
@ SuperInstance
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:955
@ Instance
The receiver is an object instance.
Definition: ExprObjC.h:949
@ SuperClass
The receiver is a superclass.
Definition: ExprObjC.h:952
@ Class
The receiver is a class.
Definition: ExprObjC.h:946
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
bool isInstanceMethod() const
Definition: DeclObjC.h:426
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:617
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
@ Array
An index into an array.
Definition: Expr.h:2418
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2422
@ Field
A field.
Definition: Expr.h:2420
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2425
Wrapper for void* pointer.
Definition: Ownership.h:50
PtrTy get() const
Definition: Ownership.h:80
static OpaquePtr make(QualType P)
Definition: Ownership.h:60
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1173
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1223
static OpenACCAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCAttachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCAutoClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
This is the base type for all OpenACC Clauses.
Definition: OpenACCClause.h:24
static OpenACCCollapseClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, bool HasForce, Expr *LoopCount, SourceLocation EndLoc)
static OpenACCCopyClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyInClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsReadOnly, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyOutClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCreateClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDefaultClause * Create(const ASTContext &C, OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static OpenACCDeleteClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDetachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceNumClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCDevicePtrClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceTypeClause * Create(const ASTContext &C, OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< DeviceTypeArgument > Archs, SourceLocation EndLoc)
static OpenACCFinalizeClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCFirstPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCIfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCIfPresentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCIndependentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCNoCreateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCNumGangsClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
static OpenACCNumWorkersClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCPresentClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCSelfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCSeqClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCTileClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > SizeExprs, SourceLocation EndLoc)
static OpenACCUseDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCVectorClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCVectorLengthClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCWaitClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation EndLoc)
static OpenACCWorkerClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition: ExprCXX.h:2983
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:3135
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3117
SourceLocation getNameLoc() const
Gets the location of the name.
Definition: ExprCXX.h:3096
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3109
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition: ExprCXX.h:3105
TemplateArgumentLoc const * getTemplateArgs() const
Definition: ExprCXX.h:3137
llvm::iterator_range< decls_iterator > decls() const
Definition: ExprCXX.h:3082
unsigned getNumTemplateArgs() const
Definition: ExprCXX.h:3143
DeclarationName getName() const
Gets the name looked up.
Definition: ExprCXX.h:3093
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3125
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition: ExprCXX.h:3132
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4180
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2613
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2609
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2625
Represents a pack expansion of types.
Definition: Type.h:7141
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:7166
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2170
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2195
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2199
Represents a parameter to a function.
Definition: Decl.h:1725
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1785
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1758
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2922
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1775
void setSigilLoc(SourceLocation Loc)
Definition: TypeLoc.h:1309
TypeLoc getPointeeLoc() const
Definition: TypeLoc.h:1313
SourceLocation getSigilLoc() const
Definition: TypeLoc.h:1305
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3198
QualType getPointeeType() const
Definition: Type.h:3208
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2566
const IdentifierInfo * getIdentifier() const
Definition: ExprCXX.h:2586
SourceLocation getLocation() const
Definition: ExprCXX.h:2590
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2582
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7931
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:7971
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:8025
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7963
Represents a template name as written in source code.
Definition: TemplateName.h:491
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition: TypeLoc.h:289
The collection of all-type qualifiers we support.
Definition: Type.h:324
void removeObjCLifetime()
Definition: Type.h:544
bool hasRestrict() const
Definition: Type.h:470
static Qualifiers fromCVRMask(unsigned CVR)
Definition: Type.h:428
bool hasObjCLifetime() const
Definition: Type.h:537
bool empty() const
Definition: Type.h:640
LangAS getAddressSpace() const
Definition: Type.h:564
Represents a struct/union/class.
Definition: Decl.h:4148
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6072
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3439
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3455
Represents the body of a requires-expression.
Definition: DeclCXX.h:2047
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition: DeclCXX.cpp:2268
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:502
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition: Stmt.cpp:1273
Represents a __leave statement.
Definition: Stmt.h:3755
Smart pointer class that efficiently represents Objective-C method names.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:60
VarDecl * BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, bool Invalid=false)
Build a type-check a new Objective-C exception variable declaration.
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
Definition: SemaObjC.cpp:36
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement.
Definition: SemaObjC.cpp:198
ExprResult BuildObjCDictionaryLiteral(SourceRange SR, MutableArrayRef< ObjCDictionaryElement > Elements)
ExprResult BuildInstanceMessage(Expr *Receiver, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C instance message expression.
QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc, bool FailOnError=false)
Build an Objective-C type parameter type.
Definition: SemaObjC.cpp:485
ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C class message expression.
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
Definition: SemaObjC.cpp:325
ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, TypeSourceInfo *EncodedTypeInfo, SourceLocation RParenLoc)
ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements)
ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the '@' prefixed parenthesized expression.
StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, MultiStmtArg Catch, Stmt *Finally)
Definition: SemaObjC.cpp:223
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Definition: SemaObjC.cpp:218
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
Definition: SemaObjC.cpp:243
QualType BuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc, bool FailOnError, bool Rebuilding)
Build an Objective-C object pointer type.
Definition: SemaObjC.cpp:712
ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *operand)
Definition: SemaObjC.cpp:287
ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, TypeSourceInfo *TSInfo, Expr *SubExpr)
StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, Decl *Parm, Stmt *Body)
Definition: SemaObjC.cpp:207
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Definition: SemaObjC.cpp:334
ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, Expr *IndexExpr, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
Build an ObjC subscript pseudo-object expression, given that that's supported by the runtime.
ArrayRef< Expr * > getQueueIdExprs() const
Definition: SemaOpenACC.h:337
OpenACCDirectiveKind getDirectiveKind() const
Definition: SemaOpenACC.h:260
void setLParenLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:461
void setConditionDetails(Expr *ConditionExpr)
Definition: SemaOpenACC.h:470
void setCollapseDetails(bool IsForce, Expr *LoopCount)
Definition: SemaOpenACC.h:626
OpenACCClauseKind getClauseKind() const
Definition: SemaOpenACC.h:262
SourceLocation getLParenLoc() const
Definition: SemaOpenACC.h:266
SourceLocation getBeginLoc() const
Definition: SemaOpenACC.h:264
void setDefaultDetails(OpenACCDefaultClauseKind DefKind)
Definition: SemaOpenACC.h:464
SourceLocation getQueuesLoc() const
Definition: SemaOpenACC.h:317
void setVarListDetails(ArrayRef< Expr * > VarList, bool IsReadOnly, bool IsZero)
Definition: SemaOpenACC.h:528
void setWaitDetails(Expr *DevNum, SourceLocation QueuesLoc, llvm::SmallVector< Expr * > &&IntExprs)
Definition: SemaOpenACC.h:612
void setEndLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:462
void setIntExprDetails(ArrayRef< Expr * > IntExprs)
Definition: SemaOpenACC.h:484
OpenACCDefaultClauseKind getDefaultClauseKind() const
Definition: SemaOpenACC.h:270
void ActOnWhileStmt(SourceLocation WhileLoc)
StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation MiscLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssocStmt)
Called after the directive has been completely parsed, including the declaration group or associated ...
ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
void ActOnDoStmt(SourceLocation DoLoc)
void ActOnRangeForStmtBegin(SourceLocation ForLoc, const Stmt *OldRangeFor, const Stmt *RangeFor)
void ActOnForStmtEnd(SourceLocation ForLoc, StmtResult Body)
void ActOnForStmtBegin(SourceLocation ForLoc, const Stmt *First, const Stmt *Second, const Stmt *Third)
ExprResult ActOnArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, Expr *Length, SourceLocation RBLoc)
Checks and creates an Array Section used in an OpenACC construct/clause.
OMPClause * ActOnOpenMPNocontextClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nocontext' clause.
OMPClause * ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_dyn_cgroup_mem' clause.
OMPClause * ActOnOpenMPSafelenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'safelen' clause.
OMPClause * ActOnOpenMPHoldsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'holds' clause.
OMPClause * ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'default' clause.
OMPClause * ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'filter' clause.
OMPClause * ActOnOpenMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on well-form 'full' clauses.
OMPClause * ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'detach' clause.
OMPClause * ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'use' clause.
OMPClause * ActOnOpenMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'to' clause.
OMPClause * ActOnOpenMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'private' clause.
OMPClause * ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc=SourceLocation(), Expr *NumForLoops=nullptr)
Called on well-formed 'ordered' clause.
OMPClause * ActOnOpenMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'is_device_ptr' clause.
OMPClause * ActOnOpenMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'has_device_addr' clause.
OMPClause * ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'partial' clauses.
OMPClause * ActOnOpenMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'lastprivate' clause.
OMPClause * ActOnOpenMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'firstprivate' clause.
OMPClause * ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'priority' clause.
OMPClause * ActOnOpenMPAllocateClause(Expr *Allocator, OpenMPAllocateClauseModifier ACModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' clause.
OMPClause * ActOnOpenMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'dist_schedule' clause.
OMPClause * ActOnOpenMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'permutation' clause after parsing its arguments.
OMPClause * ActOnOpenMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nontemporal' clause.
OMPClause * ActOnOpenMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'from' clause.
OMPClause * ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'bind' clause.
OMPClause * ActOnOpenMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'thread_limit' clause.
OMPClause * ActOnOpenMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'shared' clause.
OMPClause * ActOnOpenMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyin' clause.
OMPClause * ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'destroy' clause.
OMPClause * ActOnOpenMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Called on well-formed 'affinity' clause.
OMPClause * ActOnOpenMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' clause.
OMPClause * ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depend' clause.
OMPClause * ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'doacross' clause.
OMPClause * ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'grainsize' clause.
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< OMPIteratorData > Data)
OMPClause * ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< UsesAllocatorsData > Data)
Called on well-formed 'uses_allocators' clause.
OMPClause * ActOnOpenMPAllocatorClause(Expr *Allocator, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocator' clause.
OMPClause * ActOnOpenMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'inclusive' clause.
OMPClause * ActOnOpenMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'task_reduction' clause.
OMPClause * ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, OpenMPOrderClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'order' clause.
OMPClause * ActOnOpenMPReductionClause(ArrayRef< Expr * > VarList, OpenMPReductionClauseModifier Modifier, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'reduction' clause.
OMPClause * ActOnOpenMPSizesClause(ArrayRef< Expr * > SizeExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'sizes' clause.
OMPClause * ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'device' clause.
OMPClause * ActOnOpenMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_threads' clause.
OMPClause * ActOnOpenMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'in_reduction' clause.
OMPClause * ActOnOpenMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'flush' pseudo clause.
StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
OMPClause * ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'message' clause.
OMPClause * ActOnOpenMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'schedule' clause.
OMPClause * ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'simdlen' clause.
OMPClause * ActOnOpenMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_ptr' clause.
OMPClause * ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'proc_bind' clause.
OMPClause * ActOnOpenMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_bare' clause.
StmtResult ActOnOpenMPInformationalDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Process an OpenMP informational directive.
StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt)
Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to an OpenMP loop directive.
OMPClause * ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'hint' clause.
ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > Brackets)
OMPClause * ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'at' clause.
OMPClause * ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'init' clause.
OMPClause * ActOnOpenMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_addr' clause.
OMPClause * ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'final' clause.
OMPClause * ActOnOpenMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, bool NoDiagnose=false, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'map' clause.
OMPClause * ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_tasks' clause.
OMPClause * ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'severity' clause.
OMPClause * ActOnOpenMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc)
Called on well-formed 'linear' clause.
OMPClause * ActOnOpenMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'defaultmap' clause.
OMPClause * ActOnOpenMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'aligned' clause.
OMPClause * ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depobj' pseudo clause.
OMPClause * ActOnOpenMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'novariants' clause.
OMPClause * ActOnOpenMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyprivate' clause.
OMPClause * ActOnOpenMPCollapseClause(Expr *NumForLoops, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'collapse' clause.
OMPClause * ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'align' clause.
OMPClause * ActOnOpenMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_attribute' clause.
OMPClause * ActOnOpenMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'exclusive' clause.
OMPClause * ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'if' clause.
ExprResult checkAssignment(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opcode, Expr *LHS, Expr *RHS)
Expr * recreateSyntacticForm(PseudoObjectExpr *E)
Given a pseudo-object expression, recreate what it looks like syntactically without the attendant Opa...
ExprResult checkRValue(Expr *E)
ExprResult BuildUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition: SemaSYCL.cpp:139
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:13193
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:8041
A RAII object to enter scope of a compound statement.
Definition: Sema.h:915
A helper class for building up ExtParameterInfos.
Definition: Sema.h:12607
const FunctionProtoType::ExtParameterInfo * getPointerOrNull(unsigned numParams)
Return a pointer (suitable for setting in an ExtProtoInfo) to the ExtParameterInfo array we've built ...
Definition: Sema.h:12626
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition: Sema.h:12614
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition: Sema.h:13562
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:463
QualType BuildParenType(QualType T)
Build a paren type including T.
Definition: SemaType.cpp:1674
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:6394
QualType getCurrentThisType()
Try to retrieve the type of the 'this' pointer.
bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range)
CheckSpecifiedExceptionType - Check if the given type is valid in an exception specification.
ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, UnresolvedLookupExpr *Lookup)
Build a call to 'operator co_await' if there is a suitable operator for the given expression.
ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, const Scope *S, ActOnMemberAccessExtraArgs *ExtraArgs=nullptr)
StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Definition: SemaStmt.cpp:4433
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:8983
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:8991
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:8986
bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend)
Check that the expression co_await promise.final_suspend() shall not be potentially-throwing.
QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, SourceLocation AttrLoc)
BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an expression is uninstantiated.
Definition: SemaType.cpp:6497
ExprResult ActOnConstantExpression(ExprResult Res)
Definition: SemaExpr.cpp:19638
StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef< Token > AsmToks, StringRef AsmString, unsigned NumOutputs, unsigned NumInputs, ArrayRef< StringRef > Constraints, ArrayRef< StringRef > Clobbers, ArrayRef< Expr * > Exprs, SourceLocation EndLoc)
StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs)
ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E)
static std::enable_if_t< std::is_base_of_v< Attr, AttrInfo >, SourceLocation > getAttrLoc(const AttrInfo &AL)
A helper function to provide Attribute Location for the Attr types AND the ParsedAttr.
Definition: Sema.h:4405
QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc)
Definition: SemaType.cpp:2326
StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: SemaStmt.cpp:642
SemaOpenMP & OpenMP()
Definition: Sema.h:1125
@ IER_DoesNotExist
The symbol does not exist.
Definition: Sema.h:8458
@ IER_Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition: Sema.h:8462
@ IER_Error
An error occurred.
Definition: Sema.h:8465
@ IER_Exists
The symbol exists.
Definition: Sema.h:8455
void ActOnStartStmtExpr()
Definition: SemaExpr.cpp:15833
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, sema::LambdaScopeInfo *LSI)
Complete a lambda-expression having processed and attached the lambda body.
void ActOnStmtExprError()
Definition: SemaExpr.cpp:15839
void MarkDeclarationsReferencedInExpr(Expr *E, bool SkipLocalVariables=false, ArrayRef< const Expr * > StopAt={})
Mark any declarations that appear within this expression or any potentially-evaluated subexpressions ...
Definition: SemaExpr.cpp:20155
std::optional< FunctionEffectMode > ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName)
Try to parse the conditional expression attached to an effect attribute (e.g.
Definition: SemaType.cpp:7624
VarDecl * buildCoroutinePromise(SourceLocation Loc)
ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr=false)
CheckBooleanCondition - Diagnose problems involving the use of the given expression as a boolean cond...
Definition: SemaExpr.cpp:20371
ConditionKind
Definition: Sema.h:7344
@ Boolean
A boolean condition, from 'if', 'while', 'for', or 'do'.
@ Switch
An integral condition for a 'switch' statement.
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
Definition: SemaCast.cpp:394
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
Definition: SemaStmt.cpp:3171
ExprResult MaybeBindToTemporary(Expr *E)
MaybeBindToTemporary - If the passed in expression has a record type with a non-trivial destructor,...
StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, bool IsImplicit=false)
ExprResult ActOnStartCXXMemberReference(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, ParsedType &ObjectType, bool &MayBePseudoDestructor)
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
Definition: SemaStmt.cpp:500
QualType BuildExtVectorType(QualType T, Expr *ArraySize, SourceLocation AttrLoc)
Build an ext-vector type.
Definition: SemaType.cpp:2392
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
Definition: SemaInit.cpp:3493
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth)
Definition: SemaExpr.cpp:15852
ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc, bool *NoArrowOperatorFound=nullptr)
BuildOverloadedArrowExpr - Build a call to an overloaded operator-> (if one exists),...
ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, Expr *Awaiter, bool IsImplicit=false)
SemaSYCL & SYCL()
Definition: Sema.h:1145
ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16495
ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, bool ArrayForm, Expr *Operand)
ActOnCXXDelete - Parsed a C++ 'delete' expression (C++ 5.3.5), as in:
ASTContext & Context
Definition: Sema.h:908
ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a C++ typeid expression with a type operand.
QualType BuildFunctionType(QualType T, MutableArrayRef< QualType > ParamTypes, SourceLocation Loc, DeclarationName Entity, const FunctionProtoType::ExtProtoInfo &EPI)
Build a function type.
Definition: SemaType.cpp:2632
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:528
concepts::TypeRequirement * BuildTypeRequirement(TypeSourceInfo *Type)
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
SemaObjC & ObjC()
Definition: Sema.h:1110
ExprResult BuildPackIndexingExpr(Expr *PackExpression, SourceLocation EllipsisLoc, Expr *IndexExpr, SourceLocation RSquareLoc, ArrayRef< Expr * > ExpandedExprs={}, bool FullySubstituted=false)
ParsedType getDestructorName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, ParsedType ObjectType, bool EnteringContext)
ASTContext & getASTContext() const
Definition: Sema.h:531
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input, bool IsAfterAmp=false)
Definition: SemaExpr.cpp:15770
ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *LHS, Expr *RHS, bool RequiresADL=true, bool AllowRewrittenCandidates=true, FunctionDecl *DefaultedFn=nullptr)
Create a binary operation that may resolve to an overloaded operator.
StmtResult ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
Definition: SemaStmt.cpp:4357
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Definition: Sema.cpp:690
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Definition: SemaExpr.cpp:3492
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
Definition: SemaExpr.cpp:7060
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Definition: SemaExpr.cpp:15820
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
Definition: SemaExpr.cpp:7915
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
Definition: SemaType.cpp:9563
ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocType, TypeSourceInfo *AllocTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, bool isDefinition, SourceLocation NewTagLoc, const IdentifierInfo *Name)
Determine whether a tag with a given kind is acceptable as a redeclaration of the given tag declarati...
Definition: SemaDecl.cpp:16951
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
Definition: SemaExpr.cpp:2204
QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc)
Build a bit-precise integer type.
Definition: SemaType.cpp:1939
ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16108
ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
ControllingExprOrType is either a TypeSourceInfo * or an Expr *.
Definition: SemaExpr.cpp:1671
QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, const DeclSpec *DS=nullptr)
Definition: SemaType.cpp:1580
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Definition: SemaStmt.cpp:1290
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:81
const LangOptions & getLangOpts() const
Definition: Sema.h:524
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:1764
SemaOpenACC & OpenACC()
Definition: Sema.h:1115
@ ReuseLambdaContextDecl
Definition: Sema.h:6524
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, std::optional< unsigned > NumExpansions)
bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R, bool IsAddressOfOperand)
Check whether an expression might be an implicit class member access.
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument.
ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
Definition: SemaExpr.cpp:16769
ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, SourceLocation LParenLoc, MultiExprArg Exprs, SourceLocation RParenLoc, bool ListInitialization)
ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, ArrayRef< OffsetOfComponent > Components, SourceLocation RParenLoc)
__builtin_offsetof(type, a.b[123][456].c)
Definition: SemaExpr.cpp:15922
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Definition: Sema.cpp:2404
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
Definition: SemaInit.cpp:7547
ExprResult ConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
ConvertVectorExpr - Handle __builtin_convertvector.
QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo &II, SourceLocation IILoc, TypeSourceInfo **TSI, bool DeducedTSTContext)
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
DeclContext * getCurLexicalContext() const
Definition: Sema.h:735
ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, UnresolvedLookupExpr *Lookup)
NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK)
Given a non-tag type declaration, returns an enum useful for indicating what kind of non-tag type thi...
Definition: SemaDecl.cpp:16926
ExprResult BuildExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, Expr *Queried, SourceLocation RParen)
bool buildCoroutineParameterMoves(SourceLocation Loc)
ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, SourceLocation RParenLoc, Expr *Op)
Definition: SemaCast.cpp:3351
ExprResult BuildCXXUuidof(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a Microsoft __uuidof expression with a type operand.
sema::FunctionScopeInfo * getCurFunction() const
Definition: Sema.h:939
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
Definition: SemaDecl.cpp:14909
Expr * BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit)
Build a CXXThisExpr and mark it referenced in the current context.
QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, DeclarationName Entity)
Build a reference type.
Definition: SemaType.cpp:1856
ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *input, bool RequiresADL=true)
Create a unary operation that may resolve to an overloaded operator.
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition: Sema.h:13187
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
Definition: SemaExpr.cpp:3189
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition: Sema.cpp:2359
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:1043
VarDecl * BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id)
Perform semantic analysis for the variable declaration that occurs within a C++ catch clause,...
bool BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, bool EnteringContext, CXXScopeSpec &SS, NamedDecl *ScopeLookupResult, bool ErrorRecoveryLookup, bool *IsCorrectedToColon=nullptr, bool OnlyNamespace=false)
Build a new nested-name-specifier for "identifier::", as described by ActOnCXXNestedNameSpecifier.
void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base=nullptr)
Perform reference-marking and odr-use handling for a DeclRefExpr.
Definition: SemaExpr.cpp:19999
ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, SourceLocation RParen)
ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI=nullptr)
BuildQualifiedDeclarationNameExpr - Build a C++ qualified declaration name, generally during template...
Definition: SemaExpr.cpp:2896
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:2209
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
Definition: SemaStmt.cpp:3186
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
Definition: SemaExpr.cpp:4115
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Definition: SemaExpr.cpp:20955
ExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, CXXConstructorDecl *Constructor, MultiExprArg Exprs, bool HadMultipleCandidates, bool IsListInitialization, bool IsStdInitListInitialization, bool RequiresZeroInit, CXXConstructionKind ConstructKind, SourceRange ParenRange)
BuildCXXConstructExpr - Creates a complete call to a constructor, including handling of its default a...
NonTagKind
Common ways to introduce type names without a tag for use in diagnostics.
Definition: Sema.h:3835
@ NTK_TypeAliasTemplate
Definition: Sema.h:3843
TryCaptureKind
Definition: Sema.h:6586
@ TryCapture_Implicit
Definition: Sema.h:6587
@ TryCapture_ExplicitByVal
Definition: Sema.h:6588
@ TryCapture_ExplicitByRef
Definition: Sema.h:6589
ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Create a new AsTypeExpr node (bitcast) from the arguments.
Definition: SemaExpr.cpp:6716
ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, FieldDecl *Field, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo)
bool CheckRebuiltStmtAttributes(ArrayRef< const Attr * > Attrs)
ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr)
ActOnConditionalOp - Parse a ?: operation.
Definition: SemaExpr.cpp:8782
QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted=false, ArrayRef< QualType > Expansions={})
Definition: SemaType.cpp:9685
ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs, const Scope *S)
Builds an expression which might be an implicit member expression.
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
concepts::ExprRequirement * BuildExprRequirement(Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement)
QualType BuildAtomicType(QualType T, SourceLocation Loc)
Definition: SemaType.cpp:9968
QualType CheckTemplateIdType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
void ActOnInitializerError(Decl *Dcl)
ActOnInitializerError - Given that there was an error parsing an initializer for the given declaratio...
Definition: SemaDecl.cpp:13903
bool diagnoseConflictingFunctionEffect(const FunctionEffectsRef &FX, const FunctionEffectWithCondition &EC, SourceLocation NewAttrLoc)
Warn and return true if adding a function effect to a set would create a conflict.
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr, bool SkipTrailingRequiresClause=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics.
Definition: SemaExpr.cpp:216
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
Definition: SemaStmt.cpp:3837
ExprResult BuildPseudoDestructorExpr(Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, const CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
QualType BuildPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a pointer type.
Definition: SemaType.cpp:1804
StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, BuildForRangeKind Kind, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
Definition: SemaStmt.cpp:2637
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
Definition: SemaStmt.cpp:1785
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
Definition: SemaStmt.cpp:1166
ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand)
ExprResult BuiltinShuffleVector(CallExpr *TheCall)
BuiltinShuffleVector - Handle __builtin_shufflevector.
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
QualType BuildDecltypeType(Expr *E, bool AsUnevaluated=true)
If AsUnevaluated is false, E is treated as though it were an evaluated context, such as when building...
Definition: SemaType.cpp:9653
QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, SourceLocation Loc)
Definition: SemaType.cpp:9912
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
Definition: SemaStmt.cpp:4395
ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a sizeof or alignof expression given a type operand.
Definition: SemaExpr.cpp:4623
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition: SemaStmt.cpp:76
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition: Sema.h:7910
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, bool IsThrownVarInScope)
QualType BuildArrayType(QualType T, ArraySizeModifier ASM, Expr *ArraySize, unsigned Quals, SourceRange Brackets, DeclarationName Entity)
Build an array type.
Definition: SemaType.cpp:2047
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Definition: SemaExpr.cpp:5587
QualType BuildReadPipeType(QualType T, SourceLocation Loc)
Build a Read-only Pipe type.
Definition: SemaType.cpp:1931
concepts::NestedRequirement * BuildNestedRequirement(Expr *E)
QualType BuildWritePipeType(QualType T, SourceLocation Loc)
Build a Write-only Pipe type.
Definition: SemaType.cpp:1935
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h:10750
ExprResult CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs)
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition: SemaStmt.cpp:583
ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, Scope *CurScope)
ActOnBlockStmtExpr - This is called when the body of a block statement literal was successfully compl...
Definition: SemaExpr.cpp:16294
QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind)
Definition: SemaType.cpp:9540
ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParen)
void MarkMemberReferenced(MemberExpr *E)
Perform reference-marking and odr-use handling for a MemberExpr.
Definition: SemaExpr.cpp:20021
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
Definition: SemaCast.cpp:296
void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, bool MightBeOdrUse=true)
Mark a function referenced, and check whether it is odr-used (C++ [basic.def.odr]p2,...
Definition: SemaExpr.cpp:18071
QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, SourceLocation AttrLoc)
Definition: SemaType.cpp:2446
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
Definition: SemaExpr.cpp:21152
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
Definition: SemaExpr.cpp:15338
ExprResult PerformObjectMemberConversion(Expr *From, NestedNameSpecifier *Qualifier, NamedDecl *FoundDecl, NamedDecl *Member)
Cast a base object to a member's actual type.
Definition: SemaExpr.cpp:2969
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
Definition: SemaStmt.cpp:953
ExprResult BuildInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, SourceLocation RBraceLoc)
Definition: SemaExpr.cpp:7260
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
Definition: SemaExpr.cpp:16146
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
Definition: SemaExpr.cpp:4835
ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
CreateBuiltinBinOp - Creates a new built-in binary operation with operator Opc at location TokLoc.
Definition: SemaExpr.cpp:14761
ExprResult BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, SourceLocation RParenLoc, MultiExprArg Args, AtomicExpr::AtomicOp Op, AtomicArgumentOrder ArgOrder=AtomicArgumentOrder::API)
ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Definition: SemaExpr.cpp:6443
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:2750
static ConditionResult ConditionError()
Definition: Sema.h:7331
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition: SemaStmt.cpp:451
SemaPseudoObject & PseudoObject()
Definition: Sema.h:1135
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
Definition: SemaStmt.cpp:608
StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
ActOnCXXTryBlock - Takes a try compound-statement and a number of handlers and creates a try statemen...
Definition: SemaStmt.cpp:4244
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition: SemaStmt.cpp:588
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
Definition: SemaExpr.cpp:17898
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition: SemaStmt.cpp:552
QualType BuildMemberPointerType(QualType T, QualType Class, SourceLocation Loc, DeclarationName Entity)
Build a member pointer type T Class::*.
Definition: SemaType.cpp:2681
QualType BuildBlockPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a block pointer type.
Definition: SemaType.cpp:2733
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
Definition: SemaStmt.cpp:3153
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition: Sema.h:8261
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
Definition: SemaExpr.cpp:5012
StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition: ExprCXX.cpp:1693
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition: Expr.h:4870
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
bool isInvalid() const
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
StmtClass
Definition: Stmt.h:86
@ NoStmtClass
Definition: Stmt.h:87
StmtClass getStmtClass() const
Definition: Stmt.h:1390
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:324
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:336
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:149
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:864
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3564
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:650
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:651
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:667
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
const TemplateArgumentLoc * operator->() const
Simple iterator that traverses the template arguments in a container that provides a getArgLoc() memb...
TemplateArgumentLocContainerIterator operator++(int)
friend bool operator!=(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator(ArgLocContainer &Container, unsigned Index)
friend bool operator==(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator & operator++()
const TemplateArgumentLoc * operator->() const
Iterator adaptor that invents template argument location information for each of the template argumen...
TemplateArgumentLocInventIterator & operator++()
std::iterator_traits< InputIterator >::difference_type difference_type
TemplateArgumentLocInventIterator operator++(int)
friend bool operator==(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
TemplateArgumentLocInventIterator(TreeTransform< Derived > &Self, InputIterator Iter)
friend bool operator!=(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
std::input_iterator_tag iterator_category
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:616
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:578
SourceRange getSourceRange() const LLVM_READONLY
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:609
Expr * getSourceExpression() const
Definition: TemplateBase.h:584
Represents a template argument.
Definition: TemplateBase.h:61
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:319
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:363
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:343
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
Represents a C++ template name within the type system.
Definition: TemplateName.h:220
bool isNull() const
Determine whether this template name is NULL.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1718
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1694
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1735
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1702
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1731
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1710
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6661
Wrapper for template type parameters.
Definition: TypeLoc.h:758
The top declaration context.
Definition: Decl.h:84
RAII object that temporarily sets the base location and entity used for reporting diagnostics in type...
TemporaryBase(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
A semantic tree transformation that allows one to transform one abstract syntax tree into another.
ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *object)
Rebuild the operand to an Objective-C @synchronized statement.
OMPClause * RebuildOMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nontemporal' clause.
StmtResult RebuildOpenACCDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit)
Transform the given initializer.
StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new label statement.
StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args)
StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @autoreleasepool statement.
OMPClause * RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'dist_schedule' clause.
ExprResult RebuildUnaryOperator(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *SubExpr)
Build a new unary operator expression.
OMPClause * RebuildOMPProcBindClause(ProcBindKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'proc_bind' clause.
StmtResult RebuildOMPInformationalDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP informational directive.
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Build a new C++11 default-initialization expression.
OMPClause * RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'priority' clause.
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, TypeSourceInfo *EncodeTypeInfo, SourceLocation RParenLoc)
Build a new Objective-C @encode expression.
StmtResult RebuildOpenACCCombinedConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body)
Alternative implementation of TransformLambdaBody that skips transforming the body.
StmtResult RebuildOpenACCExitDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
StmtResult RebuildOpenACCShutdownConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, SourceLocation OpLoc, bool IsArrow)
Build a new Objective-C "isa" expression.
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @finally statement.
SourceLocation getBaseLocation()
Returns the location of the entity being transformed, if that information was not available elsewhere...
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
Build a new call expression.
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, SourceLocation IvarLoc, bool IsArrow, bool IsFreeIvar)
Build a new Objective-C ivar reference expression.
OMPClause * RebuildOMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'at' clause.
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, bool IsImplicit)
Build a new co_return statement.
OMPClause * RebuildOMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'in_reduction' clause.
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *Init)
Build a new compound literal expression.
ExprResult TransformAddressOfOperand(Expr *E)
The operand of a unary address-of operator has special rules: it's allowed to refer to a non-static m...
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, QualType ThisType, bool isImplicit)
Build a new C++ "this" expression.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(expr) expression.
TreeTransform(Sema &SemaRef)
Initializes a new tree transformer.
QualType RebuildDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const IdentifierInfo *Name, SourceLocation NameLoc, TemplateArgumentListInfo &Args, bool AllowInjectedClassName)
Build a new typename type that refers to a template-id.
QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, SourceLocation AttributeLoc)
Build a new matrix type given the type and dependently-defined dimensions.
QualType RebuildUnaryTransformType(QualType BaseType, UnaryTransformType::UTTKind UKind, SourceLocation Loc)
Build a new unary transform type.
ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, ObjCPropertyDecl *Property, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
void InventTemplateArgumentLoc(const TemplateArgument &Arg, TemplateArgumentLoc &ArgLoc)
Fakes up a TemplateArgumentLoc for a given TemplateArgument.
OMPClause * RebuildOMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'use' clause.
StmtResult RebuildOpenACCEnterDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL)
Transform the given type-with-location into a new type, collecting location information in the given ...
ExprResult RebuildCXXRewrittenBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opcode, const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS)
Build a new rewritten operator expression.
ExprResult TransformUnresolvedLookupExpr(UnresolvedLookupExpr *E, bool IsAddressOfOperand)
ExprResult RebuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
Build a new expression representing a call to a source location builtin.
QualType RebuildEnumType(EnumDecl *Enum)
Build a new Enum type.
TemplateName RebuildTemplateName(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final)
Build a new template name given a template template parameter pack and the.
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Build a new expression pack expansion.
QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL)
Transforms a reference type.
OMPClause * RebuildOMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'message' clause.
ExprResult RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
QualType RebuildTypeOfType(QualType Underlying, TypeOfKind Kind)
Build a new typeof(type) type.
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, Expr *SubExpr, TypeSourceInfo *TInfo, SourceLocation RParenLoc)
Build a new va_arg expression.
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, SourceLocation RParenLoc)
Build a new C++ zero-initialization expression.
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr)
OMPClause * RebuildOMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'thread_limit' clause.
StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block)
OMPClause * RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'simdlen' clause.
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
Build a new C++ try statement.
StmtDiscardKind
The reason why the value of a statement is not discarded, if any.
ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, UnresolvedLookupExpr *OpCoawaitLookup, bool IsImplicit)
Build a new co_await expression.
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, unsigned NumInputs, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
ExprResult RebuildDesignatedInitExpr(Designation &Desig, MultiExprArg ArrayExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Build a new designated initializer expression.
OMPClause * RebuildOMPSizesClause(ArrayRef< Expr * > Sizes, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Build a new predefined expression.
QualType RebuildElaboratedType(SourceLocation KeywordLoc, ElaboratedTypeKeyword Keyword, NestedNameSpecifierLoc QualifierLoc, QualType Named)
Build a new qualified name type.
ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ static_cast expression.
StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, Sema::FullExprArg Inc, SourceLocation RParenLoc, Stmt *Body)
Build a new for statement.
StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Build a new C++0x range-based for statement.
ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, SourceLocation RParenLoc, unsigned TemplateDepth)
Build a new GNU statement expression.
QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo *Id, SourceLocation IdLoc, bool DeducedTSTContext)
Build a new typename type that refers to an identifier.
QualType RebuildTemplateSpecializationType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &Args)
Build a new template specialization type.
bool TryExpandParameterPacks(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, bool &ShouldExpand, bool &RetainExpansion, std::optional< unsigned > &NumExpansions)
Determine whether we should expand a pack expansion with the given set of parameter packs into separa...
Sema & getSema() const
Retrieves a reference to the semantic analysis object used for this tree transform.
ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new shuffle vector expression.
QualType TransformType(QualType T)
Transforms the given type into another type.
OMPClause * RebuildOMPOrderClause(OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc)
Build a new OpenMP 'order' clause.
QualType RebuildReferenceType(QualType ReferentType, bool LValue, SourceLocation Sigil)
Build a new reference type given the type it references.
ExprResult TransformRequiresTypeParams(SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE, RequiresExprBodyDecl *Body, ArrayRef< ParmVarDecl * > Params, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > &TransParams, Sema::ExtParameterInfoBuilder &PInfos)
Transforms the parameters of a requires expresison into the given vectors.
ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, SourceLocation RBraceLoc)
Build a new initializer list expression.
QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Operand)
Build a new Objective-C @throw statement.
OMPClause * RebuildOMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'task_reduction' clause.
StmtResult RebuildOpenACCWaitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
OMPClause * RebuildOMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyin' clause.
QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, bool isReadPipe)
Build a new pipe type given its value type.
StmtResult RebuildCaseStmt(SourceLocation CaseLoc, Expr *LHS, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation ColonLoc)
Build a new case statement.
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
Build a new template-id expression.
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, VarDecl *ExceptionDecl, Stmt *Handler)
Build a new C++ catch statement.
OMPClause * RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'destroy' clause.
ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec step expression with an expression argument.
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new address-of-label expression.
ExprResult RebuildCxxSubscriptExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
TemplateName TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr, bool AllowInjectedClassName=false)
Transform the given template name.
OMPClause * RebuildOMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_bare' clause.
const Attr * TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS, const Attr *A)
ExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, Expr *LHS, SourceLocation ColonLoc, Expr *RHS)
Build a new conditional operator expression.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
Attach body to a C++0x range-based for statement.
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *Object, Stmt *Body)
Build a new Objective-C @synchronized statement.
ExprResult RebuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
TemplateName RebuildTemplateName(CXXScopeSpec &SS, bool TemplateKW, TemplateDecl *Template)
Build a new template name given a nested name specifier, a flag indicating whether the "template" key...
OMPClause * RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'device' clause.
QualType TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, TemplateName Template, CXXScopeSpec &SS)
OMPClause * RebuildOMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'has_device_addr' clause.
QualType RebuildDependentSizedExtVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
void RememberPartiallySubstitutedPack(TemplateArgument Arg)
"Remember" the partially-substituted pack template argument after performing an instantiation that mu...
Decl * TransformDefinition(SourceLocation Loc, Decl *D)
Transform the definition of the given declaration.
OMPClause * RebuildOMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'from' clause.
ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, UnresolvedLookupExpr *Lookup)
Build a new co_await expression.
QualType RebuildTypedefType(TypedefNameDecl *Typedef)
Build a new typedef type.
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result)
Build a new return statement.
TemplateArgument ForgetPartiallySubstitutedPack()
"Forget" about the partially-substituted pack template argument, when performing an instantiation tha...
OMPClause * RebuildOMPNocontextClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nocontext' clause.
ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ reinterpret_cast expression.
QualType RebuildVectorType(QualType ElementType, unsigned NumElements, VectorKind VecKind)
Build a new vector type given the element type and number of elements.
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, TypeSourceInfo *Type, ArrayRef< Sema::OffsetOfComponent > Components, SourceLocation RParenLoc)
Build a new builtin offsetof expression.
QualType RebuildParenType(QualType InnerType)
Build a new parenthesized type.
QualType RebuildRecordType(RecordDecl *Record)
Build a new class/struct/union type.
static StmtResult Owned(Stmt *S)
OMPClause * RebuildOMPReductionClause(ArrayRef< Expr * > VarList, OpenMPReductionClauseModifier Modifier, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'reduction' clause.
OMPClause * RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'partial' clause.
OMPClause * RebuildOMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'schedule' clause.
StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body)
Transform the body of a lambda-expression.
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
OMPClause * RebuildOMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'exclusive' clause.
QualType RebuildDependentAddressSpaceType(QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc)
Build a new DependentAddressSpaceType or return the pointee type variable with the correct address sp...
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Build a new attributed statement.
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, TemplateArgumentListInfo *TALI)
Build a new Objective-C boxed expression.
OMPClause * RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Build a new OpenMP 'defaultmap' clause.
StmtResult RebuildOpenACCLoopConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr)
Build a new C++ default-argument expression.
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Build a new while statement.
OMPClause * RebuildOMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' clause.
ExprResult RebuildImplicitValueInitExpr(QualType T)
Build a new value-initialized expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed)
Transforms the parameters of a function type into the given vectors.
StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
Build a new inline asm statement.
StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S)
ExprResult RebuildObjCMessageExpr(Expr *Receiver, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance message.
QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL, bool SuppressObjCLifetime)
ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool RequiresADL)
Build a new expression that references a declaration.
bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, SmallVectorImpl< Expr * > &Outputs, bool *ArgChanged=nullptr)
Transform the given list of expressions.
StmtResult TransformSEHHandler(Stmt *Handler)
NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr)
Transform the given nested-name-specifier with source-location information.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, OverloadedOperatorKind Operator, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the overloaded operator name that is refe...
StmtResult RebuildOpenACCHostDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc)
Build a new C++11 decltype type.
OMPClause * RebuildOMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_ptr' clause.
QualType TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, NestedNameSpecifierLoc QualifierLoc)
void ExpandingFunctionParameterPack(ParmVarDecl *Pack)
Note to the derived class when a function parameter pack is being expanded.
void setBase(SourceLocation Loc, DeclarationName Entity)
Sets the "base" location and entity when that information is known based on another transformation.
concepts::TypeRequirement * TransformTypeRequirement(concepts::TypeRequirement *Req)
const Derived & getDerived() const
Retrieves a reference to the derived class.
ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, SourceLocation RParen)
Build a new expression in parentheses.
OMPClause * RebuildOMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_threads' clause.
QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new block pointer type given its pointee type.
ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, bool isArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, ValueDecl *Member, NamedDecl *FoundDecl, const TemplateArgumentListInfo *ExplicitTemplateArgs, NamedDecl *FirstQualifierInScope)
Build a new member access expression.
OMPClause * RebuildOMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'shared' clause.
ExprResult RebuildCXXConstructExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool RequiresZeroInit, CXXConstructionKind ConstructKind, SourceRange ParenRange)
Build a new object-construction expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos)
OMPClause * RebuildOMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'linear' clause.
VarDecl * RebuildExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *Declarator, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id)
Build a new C++ exception declaration.
ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg)
Build a new noexcept expression.
QualType RebuildFunctionProtoType(QualType T, MutableArrayRef< QualType > ParamTypes, const FunctionProtoType::ExtProtoInfo &EPI)
Build a new function type.
ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, Expr *Base, Expr *Key, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef< Expr * > SubExprs, QualType Type)
ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, LambdaScopeInfo *LSI)
QualType RebuildIncompleteArrayType(QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new incomplete array type given the element type, size modifier, and index type qualifiers.
TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Build a new template argument pack expansion.
CXXRecordDecl::LambdaDependencyKind ComputeLambdaDependency(LambdaScopeInfo *LSI)
ExprResult RebuildPackIndexingExpr(SourceLocation EllipsisLoc, SourceLocation RSquareLoc, Expr *PackIdExpression, Expr *IndexExpr, ArrayRef< Expr * > ExpandedExprs, bool FullySubstituted=false)
StmtResult RebuildOpenACCInitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, SourceLocation LParenLoc, Expr *Sub, SourceLocation RParenLoc, bool ListInitialization)
Build a new C++ functional-style cast expression.
TypeSourceInfo * TransformType(TypeSourceInfo *DI)
Transforms the given type-with-location into a new type-with-location.
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, MutableArrayRef< ObjCDictionaryElement > Elements)
Build a new Objective-C dictionary literal.
StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK=SDK_Discarded)
Transform the given statement.
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *Target)
Build a new indirect goto statement.
ExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, bool IsArrow, SourceLocation AccessorLoc, IdentifierInfo &Accessor)
Build a new extended vector element access expression.
ExprResult RebuildParenListExpr(SourceLocation LParenLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new expression list in parentheses.
OMPClause * RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocator' clause.
QualType RebuildDependentSizedArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new dependent-sized array type given the element type, size modifier, size expression,...
NamedDecl * TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc)
Transform the given declaration, which was the first part of a nested-name-specifier in a member acce...
OMPClause * RebuildOMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'inclusive' clause.
StmtResult TransformOMPInformationalDirective(OMPExecutableDirective *S)
This is mostly the same as above, but allows 'informational' class directives when rebuilding the stm...
concepts::ExprRequirement * RebuildExprRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
OMPClause * TransformOMPClause(OMPClause *S)
Transform the given statement.
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc)
Build a new atomic type given its value type.
ExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS)
Build a new binary operator expression.
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *SubExpr)
Build a new C-style cast expression.
OMPClause * RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
OMPClause * RebuildOMPAllocateClause(Expr *Allocate, OpenMPAllocateClauseModifier ACModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocate' clause.
ExprResult TransformExpr(Expr *E)
Transform the given expression.
bool AlreadyTransformed(QualType T)
Determine whether the given type T has already been transformed.
concepts::TypeRequirement * RebuildTypeRequirement(TypeSourceInfo *T)
ExprResult RebuildOMPIteratorExpr(SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< SemaOpenMP::OMPIteratorData > Data)
Build a new iterator expression.
ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
OMPClause * RebuildOMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'grainsize' clause.
OMPClause * RebuildOMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
bool TransformTemplateArguments(InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
static ExprResult Owned(Expr *E)
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(expr) expression.
OMPClause * RebuildOMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_tasks' clause.
OMPClause * RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depobj' pseudo clause.
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc)
Build a new __builtin_choose_expr expression.
OMPClause * RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'align' clause.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C class message.
bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, LookupResult &R)
Transform the set of declarations in an OverloadExpr.
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, SourceLocation LParenOrBraceLoc, MultiExprArg Args, SourceLocation RParenOrBraceLoc, bool ListInitialization)
Build a new object-construction expression.
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init, SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps)
Build a new C++0x range-based for statement.
OMPClause * RebuildOMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Num)
Build a new OpenMP 'ordered' clause.
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
QualType RebuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build an Objective-C object type.
llvm::DenseMap< Decl *, Decl * > TransformedLocalDecls
The set of local declarations that have been transformed, for cases where we are forced to build new ...
OMPClause * RebuildOMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'novariants' clause.
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E)
ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocatedType, TypeSourceInfo *AllocatedTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
Build a new C++ "new" expression.
StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, Stmt *Element, Expr *Collection, SourceLocation RParenLoc, Stmt *Body)
Build a new Objective-C fast enumeration statement.
ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
Build a new (previously unresolved) declaration reference expression.
StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, Stmt *TryBody, MultiStmtArg CatchStmts, Stmt *Finally)
Build a new Objective-C @try statement.
DeclarationName getBaseEntity()
Returns the name of the entity being transformed, if that information was not available elsewhere in ...
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, bool ListInitialization)
Build a new object-construction expression.
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length, ArrayRef< TemplateArgument > PartialArgs)
Build a new expression to compute the length of a parameter pack.
ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, SourceLocation CalleeLoc, bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First, Expr *Second)
Build a new overloaded operator call expression.
OMPClause * RebuildOMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_addr' clause.
QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc)
Build a dependent bit-precise int given its value type.
OMPClause * RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'hint' clause.
Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind)
Transform the specified condition.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name, SourceLocation NameLoc, QualType ObjectType, NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the name that is referred to as a templat...
OMPClause * RebuildOMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'severity' clause.
OMPClause * RebuildOMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'firstprivate' clause.
StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef< Token > AsmToks, StringRef AsmString, unsigned NumOutputs, unsigned NumInputs, ArrayRef< StringRef > Constraints, ArrayRef< StringRef > Clobbers, ArrayRef< Expr * > Exprs, SourceLocation EndLoc)
Build a new MS style inline asm statement.
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, TemplateName Template)
VarDecl * RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *TInfo, QualType T)
Rebuild an Objective-C exception declaration.
concepts::NestedRequirement * TransformNestedRequirement(concepts::NestedRequirement *Req)
QualType RebuildConstantArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new constant array type given the element type, size modifier, (known) size of the array,...
ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > BracketsRanges)
Build a new array shaping expression.
ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, bool IsGlobalDelete, bool IsArrayForm, Expr *Operand)
Build a new C++ "delete" expression.
bool TransformExceptionSpec(SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, SmallVectorImpl< QualType > &Exceptions, bool &Changed)
QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, SourceLocation StartLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParenLoc)
Build a new array type trait expression.
OMPClause * RebuildOMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'is_device_ptr' clause.
QualType RebuildMacroQualifiedType(QualType T, const IdentifierInfo *MacroII)
Build a new MacroDefined type.
concepts::NestedRequirement * RebuildNestedRequirement(Expr *Constraint)
ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBracketLoc)
Build a new matrix subscript expression.
ExprResult TransformParenDependentScopeDeclRefExpr(ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
TemplateParameterList * TransformTemplateParameterList(TemplateParameterList *TPL)
QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the class type it refers into.
void transformAttrs(Decl *Old, Decl *New)
Transform the attributes associated with the given declaration and place them on the new declaration.
Decl * TransformDecl(SourceLocation Loc, Decl *D)
Transform the given declaration, which is referenced from a type or expression.
bool AlwaysRebuild()
Whether the transformation should always rebuild AST nodes, even if none of the children have changed...
ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, QualType SuperType, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance/class message to 'super'.
OMPClause * RebuildOMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'lastprivate' clause.
QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, VectorKind)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
bool AllowSkippingCXXConstructExpr()
Wether CXXConstructExpr can be skipped when they are implicit.
OMPClause * RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'safelen' clause.
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, SourceLocation RParenLoc)
Start building a new switch statement.
StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new default statement.
StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParenLoc, VarDecl *Var, Stmt *Body)
Build a new Objective-C @catch statement.
OMPClause * RebuildOMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'filter' clause.
ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, SourceLocation OperatorLoc, bool isArrow, CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage Destroyed)
Build a new pseudo-destructor expression.
QualType RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Build a new pack expansion type.
QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits, SourceLocation Loc)
Build a bit-precise int given its value type.
ExprResult RebuildObjCArrayLiteral(SourceRange Range, Expr **Elements, unsigned NumElements)
Build a new Objective-C array literal.
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(type) expression.
ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, SourceLocation OperatorLoc, bool IsArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
OMPClause * RebuildOMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'bind' clause.
concepts::NestedRequirement * RebuildNestedRequirement(StringRef InvalidConstraintEntity, const ASTConstraintSatisfaction &Satisfaction)
OMPClause * RebuildOMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyprivate' clause.
QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, ConceptDecl *TypeConstraintConcept, ArrayRef< TemplateArgument > TypeConstraintArgs)
Build a new C++11 auto type.
QualType RebuildVariableArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new variable-length array type given the element type, size modifier, size expression,...
ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ dynamic_cast expression.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, TypeSourceInfo *ControllingType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with a type predicate.
QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new pointer type given its pointee type.
concepts::TypeRequirement * RebuildTypeRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag)
OMPClause * RebuildOMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'permutation' clause.
OMPClause * RebuildOMPUsesAllocatorsClause(ArrayRef< SemaOpenMP::UsesAllocatorsData > Data, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'uses_allocators' clause.
ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool ConstructsVBase, bool InheritedFromVBase)
Build a new implicit construction via inherited constructor expression.
ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ const_cast expression.
ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, AtomicExpr::AtomicOp Op, SourceLocation RParenLoc)
Build a new atomic operation expression.
DeclarationNameInfo TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Transform the given declaration name.
OMPClause * RebuildOMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_attribute' clause.
ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, std::optional< unsigned > NumExpansions)
Build a new C++1z fold-expression.
OMPClause * RebuildOMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'to' clause.
StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation LParenLoc, Expr *Cond, SourceLocation RParenLoc)
Build a new do-while statement.
OMPClause * RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'if' clause.
StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body)
Attach the body to a new case statement.
ExprResult RebuildTypeTrait(TypeTrait Trait, SourceLocation StartLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
Build a new type trait expression.
ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
Build an empty C++1z fold-expression with the given operator.
QualType TransformTypeWithDeducedTST(QualType T)
Transform a type that is permitted to produce a DeducedTemplateSpecializationType.
OMPClause * RebuildOMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'init' clause.
OMPClause * RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'detach' clause.
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, MultiStmtArg Statements, SourceLocation RBraceLoc, bool IsStmtExpr)
Build a new compound statement.
ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, ValueDecl *VD, const DeclarationNameInfo &NameInfo, NamedDecl *Found, TemplateArgumentListInfo *TemplateArgs)
Build a new expression that references a declaration.
QualType RebuildArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new array type given the element type, size modifier, size of the array (if known),...
StmtResult RebuildDeclStmt(MutableArrayRef< Decl * > Decls, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new declaration statement.
QualType RebuildUsingType(UsingShadowDecl *Found, QualType Underlying)
Build a new type found via an alias.
ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, Expr *SrcExpr, TypeSourceInfo *DstTInfo, SourceLocation RParenLoc)
Build a new convert vector expression.
QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL)
Build a new qualified type given its unqualified type and type location.
OMPClause * RebuildOMPDependClause(OMPDependClause::DependDataTy Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depend' pseudo clause.
OMPClause * RebuildOMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'aligned' clause.
unsigned TransformTemplateDepth(unsigned Depth)
Transform a template parameter depth level.
QualType RebuildFunctionNoProtoType(QualType ResultType)
Build a new unprototyped function type.
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals, Fn TransformExceptionSpec)
const Attr * TransformAttr(const Attr *S)
Transform the given attribute.
QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns)
Build a new matrix type given the element type and dimensions.
OMPClause * RebuildOMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'map' clause.
ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Sub, SourceLocation RParenLoc)
Build a new C++ __builtin_bit_cast expression.
QualType RebuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted, ArrayRef< QualType > Expansions={})
StmtResult RebuildOMPCanonicalLoop(Stmt *LoopStmt)
Build a new OpenMP Canonical loop.
StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP executable directive.
concepts::ExprRequirement * RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
OMPClause * RebuildOMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'full' clause.
StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
OMPClause * RebuildOMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Build a new OpenMP 'affinity' clause.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(type) expression.
TypeSourceInfo * TransformTypeWithDeducedTST(TypeSourceInfo *DI)
ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, Stmt::StmtClass Class, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ "named" cast expression, such as static_cast or reinterpret_cast.
StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Attach the body to the switch statement.
TypeSourceInfo * InventTypeSourceInfo(QualType T)
Fakes up a TypeSourceInfo for a type.
ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec_step expression with a type argument.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with an expression predicate.
QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool SuppressObjCLifetime)
Derived & getDerived()
Retrieves a reference to the derived class.
OMPClause * RebuildOMPHoldsClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'holds' clause.
ExprResult RebuildArraySectionExpr(bool IsOMPArraySection, Expr *Base, SourceLocation LBracketLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBracketLoc)
Build a new array section expression.
concepts::ExprRequirement * TransformExprRequirement(concepts::ExprRequirement *Req)
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc, TypeOfKind Kind)
Build a new typeof(expr) type.
ParmVarDecl * TransformFunctionTypeParam(ParmVarDecl *OldParm, int indexAdjustment, std::optional< unsigned > NumExpansions, bool ExpectParameterPack)
Transforms a single function-type parameter.
bool ReplacingOriginal()
Whether the transformation is forming an expression or statement that replaces the original.
OMPClause * RebuildOMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'flush' pseudo clause.
bool TransformTemplateArgument(const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, bool Uneval=false)
Transform the given template argument.
QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, QualType Deduced)
By default, builds a new DeducedTemplateSpecializationType with the given deduced type.
ExprResult RebuildArraySubscriptExpr(Expr *LHS, SourceLocation LBracketLoc, Expr *RHS, SourceLocation RBracketLoc)
Build a new array subscript expression.
QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, SourceLocation AttributeLoc)
Build a new extended vector type given the element type and number of elements.
void transformedLocalDecl(Decl *Old, ArrayRef< Decl * > New)
Note that a local declaration has been transformed by this transformer.
ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
Build a new Objective-C boxed expression.
ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, bool IsThrownVariableInScope)
Build a new C++ throw expression.
bool TransformRequiresExprRequirements(ArrayRef< concepts::Requirement * > Reqs, llvm::SmallVectorImpl< concepts::Requirement * > &Transformed)
bool DropCallArgument(Expr *E)
Determine whether the given call argument should be dropped, e.g., because it is a default argument.
StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new goto statement.
OMPClause * RebuildOMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'private' clause.
ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation ClosingBraceLoc)
Build a new requires expression.
ExprResult RebuildExpressionTrait(ExpressionTrait Trait, SourceLocation StartLoc, Expr *Queried, SourceLocation RParenLoc)
Build a new expression trait expression.
OMPClause * RebuildOMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'doacross' clause.
OMPClause * RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'final' clause.
StmtResult RebuildIfStmt(SourceLocation IfLoc, IfStatementKind Kind, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Init, Stmt *Then, SourceLocation ElseLoc, Stmt *Else)
Build a new "if" statement.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
void TypeWasModifiedSafely(QualType T)
Tell the TypeLocBuilder that the type it is storing has been modified in some safe way that doesn't a...
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
Definition: TypeLoc.h:338
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:133
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:89
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
Definition: TypeLoc.h:78
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:153
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition: TypeLoc.h:164
SourceLocation getTemplateKeywordLoc() const
Get the SourceLocation of the template keyword (if any).
Definition: TypeLoc.cpp:756
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:2715
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
A container of type source information.
Definition: Type.h:7902
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7913
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:3213
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:6901
The base class of the type hierarchy.
Definition: Type.h:1828
bool isPointerType() const
Definition: Type.h:8186
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8800
bool isReferenceType() const
Definition: Type.h:8204
bool isEnumeralType() const
Definition: Type.h:8290
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:738
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2811
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2706
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2361
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: Type.h:8651
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:5048
bool isFunctionType() const
Definition: Type.h:8182
bool isObjCObjectPointerType() const
Definition: Type.h:8328
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
bool isRecordType() const
Definition: Type.h:8286
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3413
Wrapper for source info for typedefs.
Definition: TypeLoc.h:693
TypedefNameDecl * getTypedefNameDecl() const
Definition: TypeLoc.h:695
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2232
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1410
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:1028
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3203
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:3277
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:3272
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition: ExprCXX.cpp:419
A set of unresolved declarations.
Definition: UnresolvedSet.h:62
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:92
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5667
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3338
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3402
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
QualType getType() const
Definition: Decl.h:682
Represents a variable declaration or definition.
Definition: Decl.h:882
@ CInit
C-style initialization with assignment.
Definition: Decl.h:887
@ CallInit
Call-style initialization (C++98)
Definition: Decl.h:890
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1119
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Definition: Decl.cpp:2662
A requires-expression requirement which queries the validity and properties of an expression ('simple...
Definition: ExprConcepts.h:280
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
Definition: ExprConcepts.h:408
const ReturnTypeRequirement & getReturnTypeRequirement() const
Definition: ExprConcepts.h:398
SourceLocation getNoexceptLoc() const
Definition: ExprConcepts.h:390
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
Definition: ExprConcepts.h:429
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
Definition: ExprConcepts.h:484
A static requirement that can be used in a requires-expression to check properties of types and expre...
Definition: ExprConcepts.h:168
A requires-expression requirement which queries the existence of a type name or type template special...
Definition: ExprConcepts.h:225
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition: ExprConcepts.h:260
TypeSourceInfo * getType() const
Definition: ExprConcepts.h:267
bool ContainsUnexpandedParameterPack
Whether this contains an unexpanded parameter pack.
Definition: ScopeInfo.h:728
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition: ScopeInfo.h:871
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Definition: ScopeInfo.h:874
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const AstTypeMatcher< FunctionType > functionType
Matches FunctionType nodes.
bool Inc(InterpState &S, CodePtr OpPC)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
Definition: Interp.h:824
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
Definition: Interp.h:925
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition: Descriptor.h:29
CharSourceRange getSourceRange(const SourceRange &Range)
Returns the token CharSourceRange corresponding to Range.
Definition: FixIt.h:32
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
@ OO_None
Not an overloaded operator.
Definition: OperatorKinds.h:22
@ NUM_OVERLOADED_OPERATORS
Definition: OperatorKinds.h:26
OpenACCDirectiveKind
Definition: OpenACCKinds.h:25
ArrayTypeTrait
Names for the array type traits.
Definition: TypeTraits.h:42
@ CPlusPlus23
Definition: LangStandard.h:60
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1778
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:25
OpenMPDefaultmapClauseModifier
OpenMP modifiers for 'defaultmap' clause.
Definition: OpenMPKinds.h:119
OpenMPOrderClauseModifier
OpenMP modifiers for 'order' clause.
Definition: OpenMPKinds.h:172
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
Definition: Specifiers.h:39
CXXConstructionKind
Definition: ExprCXX.h:1538
@ OK_ObjCProperty
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:161
OpenMPAtClauseKind
OpenMP attributes for 'at' clause.
Definition: OpenMPKinds.h:136
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
Definition: Lambda.h:36
@ LCK_ByRef
Capturing by reference.
Definition: Lambda.h:37
@ LCK_StarThis
Capturing the *this object by copy.
Definition: Lambda.h:35
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
Definition: OpenMPKinds.h:187
BinaryOperatorKind
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
TypeOfKind
The kind of 'typeof' expression we're after.
Definition: Type.h:910
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition: OpenMPKinds.h:39
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Definition: OpenMPKinds.h:104
OpenMPDoacrossClauseModifier
OpenMP dependence types for 'doacross' clause.
Definition: OpenMPKinds.h:220
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:51
ExprResult ExprEmpty()
Definition: Ownership.h:271
StmtResult StmtError()
Definition: Ownership.h:265
@ Property
The type of a property.
@ Result
The result type of a method or function.
OpenMPBindClauseKind
OpenMP bindings for the 'bind' clause.
Definition: OpenMPKinds.h:201
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:3574
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
Definition: OpenMPKinds.h:158
OpenMPGrainsizeClauseModifier
Definition: OpenMPKinds.h:207
OpenMPNumTasksClauseModifier
Definition: OpenMPKinds.h:213
UnaryOperatorKind
ActionResult< Expr * > ExprResult
Definition: Ownership.h:248
TagTypeKind
The kind of a tag type.
Definition: Type.h:6871
bool transformOMPMappableExprListClause(TreeTransform< Derived > &TT, OMPMappableExprListClause< T > *C, llvm::SmallVectorImpl< Expr * > &Vars, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperIdInfo, llvm::SmallVectorImpl< Expr * > &UnresolvedMappers)
ExprResult ExprError()
Definition: Ownership.h:264
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
Definition: Diagnostic.h:1488
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
Definition: OpenMPKinds.h:143
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:249
OpenMPDefaultmapClauseKind
OpenMP attributes for 'defaultmap' clause.
Definition: OpenMPKinds.h:111
OpenMPAllocateClauseModifier
OpenMP modifiers for 'allocate' clause.
Definition: OpenMPKinds.h:227
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition: OpenMPKinds.h:63
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:135
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:139
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition: Ownership.h:229
const FunctionProtoType * T
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
Definition: Sema.h:235
VectorKind
Definition: Type.h:3993
OpenMPDeviceClauseModifier
OpenMP modifiers for 'device' clause.
Definition: OpenMPKinds.h:48
SourceLocIdentKind
Definition: Expr.h:4797
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:6846
@ None
No keyword precedes the qualified type name.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
OpenMPOrderClauseKind
OpenMP attributes for 'order' clause.
Definition: OpenMPKinds.h:165
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
@ Parens
New-expression has a C++98 paren-delimited initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DynamicNone
throw()
@ EST_Uninstantiated
not instantiated yet
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_Dynamic
throw(T1, T2)
PredefinedIdentKind
Definition: Expr.h:1975
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition: OpenMPKinds.h:31
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:258
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition: OpenMPKinds.h:71
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:89
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition: Type.h:4840
EffectConditionExpr Cond
Definition: Type.h:4842
Holds information about the various types of exception specification.
Definition: Type.h:5159
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:5175
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5161
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5164
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:5167
Extra information about a function prototype.
Definition: Type.h:5187
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5194
FunctionEffectsRef FunctionEffects
Definition: Type.h:5197
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:5195
This structure contains most locations needed for by an OMPVarListClause.
Definition: OpenMPClause.h:259
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition: Sema.h:12684
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:2803
Location information for a TemplateArgument.
Definition: TemplateBase.h:472