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.
2078 OMPClause *
2079 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2080 OpenMPAllocateClauseModifier FirstModifier,
2081 SourceLocation FirstModifierLoc,
2082 OpenMPAllocateClauseModifier SecondModifier,
2083 SourceLocation SecondModifierLoc,
2084 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2085 SourceLocation LParenLoc, SourceLocation ColonLoc,
2086 SourceLocation EndLoc) {
2088 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2089 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2090 }
2091
2092 /// Build a new OpenMP 'num_teams' clause.
2093 ///
2094 /// By default, performs semantic analysis to build the new statement.
2095 /// Subclasses may override this routine to provide different behavior.
2097 SourceLocation StartLoc,
2098 SourceLocation LParenLoc,
2099 SourceLocation EndLoc) {
2100 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc,
2101 LParenLoc, EndLoc);
2102 }
2103
2104 /// Build a new OpenMP 'thread_limit' clause.
2105 ///
2106 /// By default, performs semantic analysis to build the new statement.
2107 /// Subclasses may override this routine to provide different behavior.
2109 SourceLocation StartLoc,
2110 SourceLocation LParenLoc,
2111 SourceLocation EndLoc) {
2112 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2113 LParenLoc, EndLoc);
2114 }
2115
2116 /// Build a new OpenMP 'priority' clause.
2117 ///
2118 /// By default, performs semantic analysis to build the new statement.
2119 /// Subclasses may override this routine to provide different behavior.
2121 SourceLocation LParenLoc,
2122 SourceLocation EndLoc) {
2123 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2124 LParenLoc, EndLoc);
2125 }
2126
2127 /// Build a new OpenMP 'grainsize' clause.
2128 ///
2129 /// By default, performs semantic analysis to build the new statement.
2130 /// Subclasses may override this routine to provide different behavior.
2132 Expr *Device, SourceLocation StartLoc,
2133 SourceLocation LParenLoc,
2134 SourceLocation ModifierLoc,
2135 SourceLocation EndLoc) {
2137 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2138 }
2139
2140 /// Build a new OpenMP 'num_tasks' clause.
2141 ///
2142 /// By default, performs semantic analysis to build the new statement.
2143 /// Subclasses may override this routine to provide different behavior.
2145 Expr *NumTasks, SourceLocation StartLoc,
2146 SourceLocation LParenLoc,
2147 SourceLocation ModifierLoc,
2148 SourceLocation EndLoc) {
2150 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2151 }
2152
2153 /// Build a new OpenMP 'hint' clause.
2154 ///
2155 /// By default, performs semantic analysis to build the new statement.
2156 /// Subclasses may override this routine to provide different behavior.
2158 SourceLocation LParenLoc,
2159 SourceLocation EndLoc) {
2160 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2161 EndLoc);
2162 }
2163
2164 /// Build a new OpenMP 'detach' clause.
2165 ///
2166 /// By default, performs semantic analysis to build the new statement.
2167 /// Subclasses may override this routine to provide different behavior.
2169 SourceLocation LParenLoc,
2170 SourceLocation EndLoc) {
2171 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2172 EndLoc);
2173 }
2174
2175 /// Build a new OpenMP 'dist_schedule' clause.
2176 ///
2177 /// By default, performs semantic analysis to build the new OpenMP clause.
2178 /// Subclasses may override this routine to provide different behavior.
2179 OMPClause *
2181 Expr *ChunkSize, SourceLocation StartLoc,
2182 SourceLocation LParenLoc, SourceLocation KindLoc,
2183 SourceLocation CommaLoc, SourceLocation EndLoc) {
2185 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2186 }
2187
2188 /// Build a new OpenMP 'to' clause.
2189 ///
2190 /// By default, performs semantic analysis to build the new statement.
2191 /// Subclasses may override this routine to provide different behavior.
2192 OMPClause *
2194 ArrayRef<SourceLocation> MotionModifiersLoc,
2195 CXXScopeSpec &MapperIdScopeSpec,
2196 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2197 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2198 ArrayRef<Expr *> UnresolvedMappers) {
2200 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2201 ColonLoc, VarList, Locs, UnresolvedMappers);
2202 }
2203
2204 /// Build a new OpenMP 'from' clause.
2205 ///
2206 /// By default, performs semantic analysis to build the new statement.
2207 /// Subclasses may override this routine to provide different behavior.
2208 OMPClause *
2210 ArrayRef<SourceLocation> MotionModifiersLoc,
2211 CXXScopeSpec &MapperIdScopeSpec,
2212 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2213 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2214 ArrayRef<Expr *> UnresolvedMappers) {
2216 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2217 ColonLoc, VarList, Locs, UnresolvedMappers);
2218 }
2219
2220 /// Build a new OpenMP 'use_device_ptr' clause.
2221 ///
2222 /// By default, performs semantic analysis to build the new OpenMP clause.
2223 /// Subclasses may override this routine to provide different behavior.
2225 const OMPVarListLocTy &Locs) {
2226 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2227 }
2228
2229 /// Build a new OpenMP 'use_device_addr' clause.
2230 ///
2231 /// By default, performs semantic analysis to build the new OpenMP clause.
2232 /// Subclasses may override this routine to provide different behavior.
2234 const OMPVarListLocTy &Locs) {
2235 return getSema().OpenMP().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2236 }
2237
2238 /// Build a new OpenMP 'is_device_ptr' clause.
2239 ///
2240 /// By default, performs semantic analysis to build the new OpenMP clause.
2241 /// Subclasses may override this routine to provide different behavior.
2243 const OMPVarListLocTy &Locs) {
2244 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2245 }
2246
2247 /// Build a new OpenMP 'has_device_addr' clause.
2248 ///
2249 /// By default, performs semantic analysis to build the new OpenMP clause.
2250 /// Subclasses may override this routine to provide different behavior.
2252 const OMPVarListLocTy &Locs) {
2253 return getSema().OpenMP().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2254 }
2255
2256 /// Build a new OpenMP 'defaultmap' clause.
2257 ///
2258 /// By default, performs semantic analysis to build the new OpenMP clause.
2259 /// Subclasses may override this routine to provide different behavior.
2262 SourceLocation StartLoc,
2263 SourceLocation LParenLoc,
2264 SourceLocation MLoc,
2265 SourceLocation KindLoc,
2266 SourceLocation EndLoc) {
2268 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2269 }
2270
2271 /// Build a new OpenMP 'nontemporal' clause.
2272 ///
2273 /// By default, performs semantic analysis to build the new OpenMP clause.
2274 /// Subclasses may override this routine to provide different behavior.
2276 SourceLocation StartLoc,
2277 SourceLocation LParenLoc,
2278 SourceLocation EndLoc) {
2279 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2280 LParenLoc, EndLoc);
2281 }
2282
2283 /// Build a new OpenMP 'inclusive' clause.
2284 ///
2285 /// By default, performs semantic analysis to build the new OpenMP clause.
2286 /// Subclasses may override this routine to provide different behavior.
2288 SourceLocation StartLoc,
2289 SourceLocation LParenLoc,
2290 SourceLocation EndLoc) {
2291 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2292 LParenLoc, EndLoc);
2293 }
2294
2295 /// Build a new OpenMP 'exclusive' clause.
2296 ///
2297 /// By default, performs semantic analysis to build the new OpenMP clause.
2298 /// Subclasses may override this routine to provide different behavior.
2300 SourceLocation StartLoc,
2301 SourceLocation LParenLoc,
2302 SourceLocation EndLoc) {
2303 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2304 LParenLoc, EndLoc);
2305 }
2306
2307 /// Build a new OpenMP 'uses_allocators' clause.
2308 ///
2309 /// By default, performs semantic analysis to build the new OpenMP clause.
2310 /// Subclasses may override this routine to provide different behavior.
2313 SourceLocation LParenLoc, SourceLocation EndLoc) {
2315 StartLoc, LParenLoc, EndLoc, Data);
2316 }
2317
2318 /// Build a new OpenMP 'affinity' clause.
2319 ///
2320 /// By default, performs semantic analysis to build the new OpenMP clause.
2321 /// Subclasses may override this routine to provide different behavior.
2323 SourceLocation LParenLoc,
2324 SourceLocation ColonLoc,
2325 SourceLocation EndLoc, Expr *Modifier,
2326 ArrayRef<Expr *> Locators) {
2328 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2329 }
2330
2331 /// Build a new OpenMP 'order' clause.
2332 ///
2333 /// By default, performs semantic analysis to build the new OpenMP clause.
2334 /// Subclasses may override this routine to provide different behavior.
2336 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2337 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2338 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2340 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2341 }
2342
2343 /// Build a new OpenMP 'init' clause.
2344 ///
2345 /// By default, performs semantic analysis to build the new OpenMP clause.
2346 /// Subclasses may override this routine to provide different behavior.
2348 SourceLocation StartLoc,
2349 SourceLocation LParenLoc,
2350 SourceLocation VarLoc,
2351 SourceLocation EndLoc) {
2353 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2354 }
2355
2356 /// Build a new OpenMP 'use' clause.
2357 ///
2358 /// By default, performs semantic analysis to build the new OpenMP clause.
2359 /// Subclasses may override this routine to provide different behavior.
2361 SourceLocation LParenLoc,
2362 SourceLocation VarLoc, SourceLocation EndLoc) {
2363 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2364 LParenLoc, VarLoc, EndLoc);
2365 }
2366
2367 /// Build a new OpenMP 'destroy' clause.
2368 ///
2369 /// By default, performs semantic analysis to build the new OpenMP clause.
2370 /// Subclasses may override this routine to provide different behavior.
2372 SourceLocation LParenLoc,
2373 SourceLocation VarLoc,
2374 SourceLocation EndLoc) {
2376 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2377 }
2378
2379 /// Build a new OpenMP 'novariants' clause.
2380 ///
2381 /// By default, performs semantic analysis to build the new OpenMP clause.
2382 /// Subclasses may override this routine to provide different behavior.
2384 SourceLocation StartLoc,
2385 SourceLocation LParenLoc,
2386 SourceLocation EndLoc) {
2388 LParenLoc, EndLoc);
2389 }
2390
2391 /// Build a new OpenMP 'nocontext' clause.
2392 ///
2393 /// By default, performs semantic analysis to build the new OpenMP clause.
2394 /// Subclasses may override this routine to provide different behavior.
2396 SourceLocation LParenLoc,
2397 SourceLocation EndLoc) {
2399 LParenLoc, EndLoc);
2400 }
2401
2402 /// Build a new OpenMP 'filter' clause.
2403 ///
2404 /// By default, performs semantic analysis to build the new OpenMP clause.
2405 /// Subclasses may override this routine to provide different behavior.
2407 SourceLocation LParenLoc,
2408 SourceLocation EndLoc) {
2409 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2410 LParenLoc, EndLoc);
2411 }
2412
2413 /// Build a new OpenMP 'bind' clause.
2414 ///
2415 /// By default, performs semantic analysis to build the new OpenMP clause.
2416 /// Subclasses may override this routine to provide different behavior.
2418 SourceLocation KindLoc,
2419 SourceLocation StartLoc,
2420 SourceLocation LParenLoc,
2421 SourceLocation EndLoc) {
2422 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2423 LParenLoc, EndLoc);
2424 }
2425
2426 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2427 ///
2428 /// By default, performs semantic analysis to build the new OpenMP clause.
2429 /// Subclasses may override this routine to provide different behavior.
2431 SourceLocation LParenLoc,
2432 SourceLocation EndLoc) {
2433 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2434 LParenLoc, EndLoc);
2435 }
2436
2437 /// Build a new OpenMP 'ompx_attribute' clause.
2438 ///
2439 /// By default, performs semantic analysis to build the new OpenMP clause.
2440 /// Subclasses may override this routine to provide different behavior.
2442 SourceLocation StartLoc,
2443 SourceLocation LParenLoc,
2444 SourceLocation EndLoc) {
2445 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2446 LParenLoc, EndLoc);
2447 }
2448
2449 /// Build a new OpenMP 'ompx_bare' clause.
2450 ///
2451 /// By default, performs semantic analysis to build the new OpenMP clause.
2452 /// Subclasses may override this routine to provide different behavior.
2454 SourceLocation EndLoc) {
2455 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2456 }
2457
2458 /// Build a new OpenMP 'align' clause.
2459 ///
2460 /// By default, performs semantic analysis to build the new OpenMP clause.
2461 /// Subclasses may override this routine to provide different behavior.
2463 SourceLocation LParenLoc,
2464 SourceLocation EndLoc) {
2465 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2466 EndLoc);
2467 }
2468
2469 /// Build a new OpenMP 'at' clause.
2470 ///
2471 /// By default, performs semantic analysis to build the new OpenMP clause.
2472 /// Subclasses may override this routine to provide different behavior.
2474 SourceLocation StartLoc,
2475 SourceLocation LParenLoc,
2476 SourceLocation EndLoc) {
2477 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2478 LParenLoc, EndLoc);
2479 }
2480
2481 /// Build a new OpenMP 'severity' clause.
2482 ///
2483 /// By default, performs semantic analysis to build the new OpenMP clause.
2484 /// Subclasses may override this routine to provide different behavior.
2486 SourceLocation KwLoc,
2487 SourceLocation StartLoc,
2488 SourceLocation LParenLoc,
2489 SourceLocation EndLoc) {
2490 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2491 LParenLoc, EndLoc);
2492 }
2493
2494 /// Build a new OpenMP 'message' clause.
2495 ///
2496 /// By default, performs semantic analysis to build the new OpenMP clause.
2497 /// Subclasses may override this routine to provide different behavior.
2499 SourceLocation LParenLoc,
2500 SourceLocation EndLoc) {
2501 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2502 EndLoc);
2503 }
2504
2505 /// Build a new OpenMP 'doacross' clause.
2506 ///
2507 /// By default, performs semantic analysis to build the new OpenMP clause.
2508 /// Subclasses may override this routine to provide different behavior.
2509 OMPClause *
2511 SourceLocation DepLoc, SourceLocation ColonLoc,
2512 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2513 SourceLocation LParenLoc, SourceLocation EndLoc) {
2515 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2516 }
2517
2518 /// Build a new OpenMP 'holds' clause.
2520 SourceLocation LParenLoc,
2521 SourceLocation EndLoc) {
2522 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2523 EndLoc);
2524 }
2525
2526 /// Rebuild the operand to an Objective-C \@synchronized statement.
2527 ///
2528 /// By default, performs semantic analysis to build the new statement.
2529 /// Subclasses may override this routine to provide different behavior.
2531 Expr *object) {
2532 return getSema().ObjC().ActOnObjCAtSynchronizedOperand(atLoc, object);
2533 }
2534
2535 /// Build a new Objective-C \@synchronized statement.
2536 ///
2537 /// By default, performs semantic analysis to build the new statement.
2538 /// Subclasses may override this routine to provide different behavior.
2540 Expr *Object, Stmt *Body) {
2541 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2542 }
2543
2544 /// Build a new Objective-C \@autoreleasepool statement.
2545 ///
2546 /// By default, performs semantic analysis to build the new statement.
2547 /// Subclasses may override this routine to provide different behavior.
2549 Stmt *Body) {
2550 return getSema().ObjC().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2551 }
2552
2553 /// Build a new Objective-C fast enumeration statement.
2554 ///
2555 /// By default, performs semantic analysis to build the new statement.
2556 /// Subclasses may override this routine to provide different behavior.
2558 Stmt *Element,
2559 Expr *Collection,
2560 SourceLocation RParenLoc,
2561 Stmt *Body) {
2563 ForLoc, Element, Collection, RParenLoc);
2564 if (ForEachStmt.isInvalid())
2565 return StmtError();
2566
2567 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2568 Body);
2569 }
2570
2571 /// Build a new C++ exception declaration.
2572 ///
2573 /// By default, performs semantic analysis to build the new decaration.
2574 /// Subclasses may override this routine to provide different behavior.
2577 SourceLocation StartLoc,
2578 SourceLocation IdLoc,
2579 IdentifierInfo *Id) {
2581 StartLoc, IdLoc, Id);
2582 if (Var)
2583 getSema().CurContext->addDecl(Var);
2584 return Var;
2585 }
2586
2587 /// Build a new C++ catch statement.
2588 ///
2589 /// By default, performs semantic analysis to build the new statement.
2590 /// Subclasses may override this routine to provide different behavior.
2592 VarDecl *ExceptionDecl,
2593 Stmt *Handler) {
2594 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2595 Handler));
2596 }
2597
2598 /// Build a new C++ try statement.
2599 ///
2600 /// By default, performs semantic analysis to build the new statement.
2601 /// Subclasses may override this routine to provide different behavior.
2603 ArrayRef<Stmt *> Handlers) {
2604 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2605 }
2606
2607 /// Build a new C++0x range-based for statement.
2608 ///
2609 /// By default, performs semantic analysis to build the new statement.
2610 /// Subclasses may override this routine to provide different behavior.
2612 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2613 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2614 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2615 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2616 // If we've just learned that the range is actually an Objective-C
2617 // collection, treat this as an Objective-C fast enumeration loop.
2618 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2619 if (RangeStmt->isSingleDecl()) {
2620 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2621 if (RangeVar->isInvalidDecl())
2622 return StmtError();
2623
2624 Expr *RangeExpr = RangeVar->getInit();
2625 if (!RangeExpr->isTypeDependent() &&
2626 RangeExpr->getType()->isObjCObjectPointerType()) {
2627 // FIXME: Support init-statements in Objective-C++20 ranged for
2628 // statement.
2629 if (Init) {
2630 return SemaRef.Diag(Init->getBeginLoc(),
2631 diag::err_objc_for_range_init_stmt)
2632 << Init->getSourceRange();
2633 }
2635 ForLoc, LoopVar, RangeExpr, RParenLoc);
2636 }
2637 }
2638 }
2639 }
2640
2642 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2643 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2644 }
2645
2646 /// Build a new C++0x range-based for statement.
2647 ///
2648 /// By default, performs semantic analysis to build the new statement.
2649 /// Subclasses may override this routine to provide different behavior.
2651 bool IsIfExists,
2652 NestedNameSpecifierLoc QualifierLoc,
2653 DeclarationNameInfo NameInfo,
2654 Stmt *Nested) {
2655 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2656 QualifierLoc, NameInfo, Nested);
2657 }
2658
2659 /// Attach body to a C++0x range-based for statement.
2660 ///
2661 /// By default, performs semantic analysis to finish the new statement.
2662 /// Subclasses may override this routine to provide different behavior.
2664 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2665 }
2666
2668 Stmt *TryBlock, Stmt *Handler) {
2669 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2670 }
2671
2673 Stmt *Block) {
2674 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2675 }
2676
2678 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2679 }
2680
2682 SourceLocation LParen,
2683 SourceLocation RParen,
2684 TypeSourceInfo *TSI) {
2685 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2686 TSI);
2687 }
2688
2689 /// Build a new predefined expression.
2690 ///
2691 /// By default, performs semantic analysis to build the new expression.
2692 /// Subclasses may override this routine to provide different behavior.
2694 return getSema().BuildPredefinedExpr(Loc, IK);
2695 }
2696
2697 /// Build a new expression that references a declaration.
2698 ///
2699 /// By default, performs semantic analysis to build the new expression.
2700 /// Subclasses may override this routine to provide different behavior.
2702 LookupResult &R,
2703 bool RequiresADL) {
2704 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2705 }
2706
2707
2708 /// Build a new expression that references a declaration.
2709 ///
2710 /// By default, performs semantic analysis to build the new expression.
2711 /// Subclasses may override this routine to provide different behavior.
2713 ValueDecl *VD,
2714 const DeclarationNameInfo &NameInfo,
2716 TemplateArgumentListInfo *TemplateArgs) {
2717 CXXScopeSpec SS;
2718 SS.Adopt(QualifierLoc);
2719 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2720 TemplateArgs);
2721 }
2722
2723 /// Build a new expression in parentheses.
2724 ///
2725 /// By default, performs semantic analysis to build the new expression.
2726 /// Subclasses may override this routine to provide different behavior.
2728 SourceLocation RParen) {
2729 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2730 }
2731
2732 /// Build a new pseudo-destructor expression.
2733 ///
2734 /// By default, performs semantic analysis to build the new expression.
2735 /// Subclasses may override this routine to provide different behavior.
2737 SourceLocation OperatorLoc,
2738 bool isArrow,
2739 CXXScopeSpec &SS,
2740 TypeSourceInfo *ScopeType,
2741 SourceLocation CCLoc,
2742 SourceLocation TildeLoc,
2743 PseudoDestructorTypeStorage Destroyed);
2744
2745 /// Build a new unary operator expression.
2746 ///
2747 /// By default, performs semantic analysis to build the new expression.
2748 /// Subclasses may override this routine to provide different behavior.
2751 Expr *SubExpr) {
2752 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2753 }
2754
2755 /// Build a new builtin offsetof expression.
2756 ///
2757 /// By default, performs semantic analysis to build the new expression.
2758 /// Subclasses may override this routine to provide different behavior.
2762 SourceLocation RParenLoc) {
2763 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2764 RParenLoc);
2765 }
2766
2767 /// Build a new sizeof, alignof or vec_step expression with a
2768 /// type argument.
2769 ///
2770 /// By default, performs semantic analysis to build the new expression.
2771 /// Subclasses may override this routine to provide different behavior.
2773 SourceLocation OpLoc,
2774 UnaryExprOrTypeTrait ExprKind,
2775 SourceRange R) {
2776 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2777 }
2778
2779 /// Build a new sizeof, alignof or vec step expression with an
2780 /// expression argument.
2781 ///
2782 /// By default, performs semantic analysis to build the new expression.
2783 /// Subclasses may override this routine to provide different behavior.
2785 UnaryExprOrTypeTrait ExprKind,
2786 SourceRange R) {
2788 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2789 if (Result.isInvalid())
2790 return ExprError();
2791
2792 return Result;
2793 }
2794
2795 /// Build a new array subscript expression.
2796 ///
2797 /// By default, performs semantic analysis to build the new expression.
2798 /// Subclasses may override this routine to provide different behavior.
2800 SourceLocation LBracketLoc,
2801 Expr *RHS,
2802 SourceLocation RBracketLoc) {
2803 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2804 LBracketLoc, RHS,
2805 RBracketLoc);
2806 }
2807
2808 /// Build a new matrix subscript expression.
2809 ///
2810 /// By default, performs semantic analysis to build the new expression.
2811 /// Subclasses may override this routine to provide different behavior.
2813 Expr *ColumnIdx,
2814 SourceLocation RBracketLoc) {
2815 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2816 RBracketLoc);
2817 }
2818
2819 /// Build a new array section expression.
2820 ///
2821 /// By default, performs semantic analysis to build the new expression.
2822 /// Subclasses may override this routine to provide different behavior.
2824 SourceLocation LBracketLoc,
2825 Expr *LowerBound,
2826 SourceLocation ColonLocFirst,
2827 SourceLocation ColonLocSecond,
2828 Expr *Length, Expr *Stride,
2829 SourceLocation RBracketLoc) {
2830 if (IsOMPArraySection)
2832 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2833 Stride, RBracketLoc);
2834
2835 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2836 "Stride/second colon not allowed for OpenACC");
2837
2839 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2840 }
2841
2842 /// Build a new array shaping expression.
2843 ///
2844 /// By default, performs semantic analysis to build the new expression.
2845 /// Subclasses may override this routine to provide different behavior.
2847 SourceLocation RParenLoc,
2848 ArrayRef<Expr *> Dims,
2849 ArrayRef<SourceRange> BracketsRanges) {
2851 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2852 }
2853
2854 /// Build a new iterator expression.
2855 ///
2856 /// By default, performs semantic analysis to build the new expression.
2857 /// Subclasses may override this routine to provide different behavior.
2860 SourceLocation RLoc,
2863 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2864 }
2865
2866 /// Build a new call expression.
2867 ///
2868 /// By default, performs semantic analysis to build the new expression.
2869 /// Subclasses may override this routine to provide different behavior.
2871 MultiExprArg Args,
2872 SourceLocation RParenLoc,
2873 Expr *ExecConfig = nullptr) {
2874 return getSema().ActOnCallExpr(
2875 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2876 }
2877
2879 MultiExprArg Args,
2880 SourceLocation RParenLoc) {
2882 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2883 }
2884
2885 /// Build a new member access expression.
2886 ///
2887 /// By default, performs semantic analysis to build the new expression.
2888 /// Subclasses may override this routine to provide different behavior.
2890 bool isArrow,
2891 NestedNameSpecifierLoc QualifierLoc,
2892 SourceLocation TemplateKWLoc,
2893 const DeclarationNameInfo &MemberNameInfo,
2895 NamedDecl *FoundDecl,
2896 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2897 NamedDecl *FirstQualifierInScope) {
2899 isArrow);
2900 if (!Member->getDeclName()) {
2901 // We have a reference to an unnamed field. This is always the
2902 // base of an anonymous struct/union member access, i.e. the
2903 // field is always of record type.
2904 assert(Member->getType()->isRecordType() &&
2905 "unnamed member not of record type?");
2906
2907 BaseResult =
2909 QualifierLoc.getNestedNameSpecifier(),
2910 FoundDecl, Member);
2911 if (BaseResult.isInvalid())
2912 return ExprError();
2913 Base = BaseResult.get();
2914
2915 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2916 // from the AST, so we need to re-insert them if needed (since
2917 // `BuildFieldRefereneExpr()` doesn't do this).
2918 if (!isArrow && Base->isPRValue()) {
2920 if (BaseResult.isInvalid())
2921 return ExprError();
2922 Base = BaseResult.get();
2923 }
2924
2925 CXXScopeSpec EmptySS;
2927 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2928 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2929 MemberNameInfo);
2930 }
2931
2932 CXXScopeSpec SS;
2933 SS.Adopt(QualifierLoc);
2934
2935 Base = BaseResult.get();
2936 if (Base->containsErrors())
2937 return ExprError();
2938
2939 QualType BaseType = Base->getType();
2940
2941 if (isArrow && !BaseType->isPointerType())
2942 return ExprError();
2943
2944 // FIXME: this involves duplicating earlier analysis in a lot of
2945 // cases; we should avoid this when possible.
2946 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2947 R.addDecl(FoundDecl);
2948 R.resolveKind();
2949
2950 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2951 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2952 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2953 ->getType()
2954 ->getPointeeType()
2955 ->getAsCXXRecordDecl()) {
2956 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2957 // In unevaluated contexts, an expression supposed to be a member access
2958 // might reference a member in an unrelated class.
2959 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2960 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2961 VK_LValue, Member->getLocation());
2962 }
2963 }
2964
2965 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2966 SS, TemplateKWLoc,
2967 FirstQualifierInScope,
2968 R, ExplicitTemplateArgs,
2969 /*S*/nullptr);
2970 }
2971
2972 /// Build a new binary operator expression.
2973 ///
2974 /// By default, performs semantic analysis to build the new expression.
2975 /// Subclasses may override this routine to provide different behavior.
2978 Expr *LHS, Expr *RHS) {
2979 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2980 }
2981
2982 /// Build a new rewritten operator expression.
2983 ///
2984 /// By default, performs semantic analysis to build the new expression.
2985 /// Subclasses may override this routine to provide different behavior.
2987 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2988 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2989 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2990 RHS, /*RequiresADL*/false);
2991 }
2992
2993 /// Build a new conditional operator expression.
2994 ///
2995 /// By default, performs semantic analysis to build the new expression.
2996 /// Subclasses may override this routine to provide different behavior.
2998 SourceLocation QuestionLoc,
2999 Expr *LHS,
3000 SourceLocation ColonLoc,
3001 Expr *RHS) {
3002 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3003 LHS, RHS);
3004 }
3005
3006 /// Build a new C-style cast expression.
3007 ///
3008 /// By default, performs semantic analysis to build the new expression.
3009 /// Subclasses may override this routine to provide different behavior.
3011 TypeSourceInfo *TInfo,
3012 SourceLocation RParenLoc,
3013 Expr *SubExpr) {
3014 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3015 SubExpr);
3016 }
3017
3018 /// Build a new compound literal expression.
3019 ///
3020 /// By default, performs semantic analysis to build the new expression.
3021 /// Subclasses may override this routine to provide different behavior.
3023 TypeSourceInfo *TInfo,
3024 SourceLocation RParenLoc,
3025 Expr *Init) {
3026 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3027 Init);
3028 }
3029
3030 /// Build a new extended vector element access expression.
3031 ///
3032 /// By default, performs semantic analysis to build the new expression.
3033 /// Subclasses may override this routine to provide different behavior.
3035 bool IsArrow,
3036 SourceLocation AccessorLoc,
3037 IdentifierInfo &Accessor) {
3038
3039 CXXScopeSpec SS;
3040 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3042 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3043 /*FirstQualifierInScope*/ nullptr, NameInfo,
3044 /* TemplateArgs */ nullptr,
3045 /*S*/ nullptr);
3046 }
3047
3048 /// Build a new initializer list expression.
3049 ///
3050 /// By default, performs semantic analysis to build the new expression.
3051 /// Subclasses may override this routine to provide different behavior.
3053 MultiExprArg Inits,
3054 SourceLocation RBraceLoc) {
3055 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3056 }
3057
3058 /// Build a new designated initializer expression.
3059 ///
3060 /// By default, performs semantic analysis to build the new expression.
3061 /// Subclasses may override this routine to provide different behavior.
3063 MultiExprArg ArrayExprs,
3064 SourceLocation EqualOrColonLoc,
3065 bool GNUSyntax,
3066 Expr *Init) {
3068 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3069 Init);
3070 if (Result.isInvalid())
3071 return ExprError();
3072
3073 return Result;
3074 }
3075
3076 /// Build a new value-initialized expression.
3077 ///
3078 /// By default, builds the implicit value initialization without performing
3079 /// any semantic analysis. Subclasses may override this routine to provide
3080 /// different behavior.
3082 return new (SemaRef.Context) ImplicitValueInitExpr(T);
3083 }
3084
3085 /// Build a new \c va_arg expression.
3086 ///
3087 /// By default, performs semantic analysis to build the new expression.
3088 /// Subclasses may override this routine to provide different behavior.
3090 Expr *SubExpr, TypeSourceInfo *TInfo,
3091 SourceLocation RParenLoc) {
3092 return getSema().BuildVAArgExpr(BuiltinLoc,
3093 SubExpr, TInfo,
3094 RParenLoc);
3095 }
3096
3097 /// Build a new expression list in parentheses.
3098 ///
3099 /// By default, performs semantic analysis to build the new expression.
3100 /// Subclasses may override this routine to provide different behavior.
3102 MultiExprArg SubExprs,
3103 SourceLocation RParenLoc) {
3104 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3105 }
3106
3107 /// Build a new address-of-label expression.
3108 ///
3109 /// By default, performs semantic analysis, using the name of the label
3110 /// rather than attempting to map the label statement itself.
3111 /// Subclasses may override this routine to provide different behavior.
3113 SourceLocation LabelLoc, LabelDecl *Label) {
3114 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3115 }
3116
3117 /// Build a new GNU statement expression.
3118 ///
3119 /// By default, performs semantic analysis to build the new expression.
3120 /// Subclasses may override this routine to provide different behavior.
3122 SourceLocation RParenLoc, unsigned TemplateDepth) {
3123 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3124 TemplateDepth);
3125 }
3126
3127 /// Build a new __builtin_choose_expr expression.
3128 ///
3129 /// By default, performs semantic analysis to build the new expression.
3130 /// Subclasses may override this routine to provide different behavior.
3132 Expr *Cond, Expr *LHS, Expr *RHS,
3133 SourceLocation RParenLoc) {
3134 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3135 Cond, LHS, RHS,
3136 RParenLoc);
3137 }
3138
3139 /// Build a new generic selection expression with an expression predicate.
3140 ///
3141 /// By default, performs semantic analysis to build the new expression.
3142 /// Subclasses may override this routine to provide different behavior.
3144 SourceLocation DefaultLoc,
3145 SourceLocation RParenLoc,
3146 Expr *ControllingExpr,
3148 ArrayRef<Expr *> Exprs) {
3149 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3150 /*PredicateIsExpr=*/true,
3151 ControllingExpr, Types, Exprs);
3152 }
3153
3154 /// Build a new generic selection expression with a type predicate.
3155 ///
3156 /// By default, performs semantic analysis to build the new expression.
3157 /// Subclasses may override this routine to provide different behavior.
3159 SourceLocation DefaultLoc,
3160 SourceLocation RParenLoc,
3161 TypeSourceInfo *ControllingType,
3163 ArrayRef<Expr *> Exprs) {
3164 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3165 /*PredicateIsExpr=*/false,
3166 ControllingType, Types, Exprs);
3167 }
3168
3169 /// Build a new overloaded operator call expression.
3170 ///
3171 /// By default, performs semantic analysis to build the new expression.
3172 /// The semantic analysis provides the behavior of template instantiation,
3173 /// copying with transformations that turn what looks like an overloaded
3174 /// operator call into a use of a builtin operator, performing
3175 /// argument-dependent lookup, etc. Subclasses may override this routine to
3176 /// provide different behavior.
3178 SourceLocation OpLoc,
3179 SourceLocation CalleeLoc,
3180 bool RequiresADL,
3181 const UnresolvedSetImpl &Functions,
3182 Expr *First, Expr *Second);
3183
3184 /// Build a new C++ "named" cast expression, such as static_cast or
3185 /// reinterpret_cast.
3186 ///
3187 /// By default, this routine dispatches to one of the more-specific routines
3188 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3189 /// Subclasses may override this routine to provide different behavior.
3192 SourceLocation LAngleLoc,
3193 TypeSourceInfo *TInfo,
3194 SourceLocation RAngleLoc,
3195 SourceLocation LParenLoc,
3196 Expr *SubExpr,
3197 SourceLocation RParenLoc) {
3198 switch (Class) {
3199 case Stmt::CXXStaticCastExprClass:
3200 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3201 RAngleLoc, LParenLoc,
3202 SubExpr, RParenLoc);
3203
3204 case Stmt::CXXDynamicCastExprClass:
3205 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3206 RAngleLoc, LParenLoc,
3207 SubExpr, RParenLoc);
3208
3209 case Stmt::CXXReinterpretCastExprClass:
3210 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3211 RAngleLoc, LParenLoc,
3212 SubExpr,
3213 RParenLoc);
3214
3215 case Stmt::CXXConstCastExprClass:
3216 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3217 RAngleLoc, LParenLoc,
3218 SubExpr, RParenLoc);
3219
3220 case Stmt::CXXAddrspaceCastExprClass:
3221 return getDerived().RebuildCXXAddrspaceCastExpr(
3222 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3223
3224 default:
3225 llvm_unreachable("Invalid C++ named cast");
3226 }
3227 }
3228
3229 /// Build a new C++ static_cast expression.
3230 ///
3231 /// By default, performs semantic analysis to build the new expression.
3232 /// Subclasses may override this routine to provide different behavior.
3234 SourceLocation LAngleLoc,
3235 TypeSourceInfo *TInfo,
3236 SourceLocation RAngleLoc,
3237 SourceLocation LParenLoc,
3238 Expr *SubExpr,
3239 SourceLocation RParenLoc) {
3240 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3241 TInfo, SubExpr,
3242 SourceRange(LAngleLoc, RAngleLoc),
3243 SourceRange(LParenLoc, RParenLoc));
3244 }
3245
3246 /// Build a new C++ dynamic_cast expression.
3247 ///
3248 /// By default, performs semantic analysis to build the new expression.
3249 /// Subclasses may override this routine to provide different behavior.
3251 SourceLocation LAngleLoc,
3252 TypeSourceInfo *TInfo,
3253 SourceLocation RAngleLoc,
3254 SourceLocation LParenLoc,
3255 Expr *SubExpr,
3256 SourceLocation RParenLoc) {
3257 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3258 TInfo, SubExpr,
3259 SourceRange(LAngleLoc, RAngleLoc),
3260 SourceRange(LParenLoc, RParenLoc));
3261 }
3262
3263 /// Build a new C++ reinterpret_cast expression.
3264 ///
3265 /// By default, performs semantic analysis to build the new expression.
3266 /// Subclasses may override this routine to provide different behavior.
3268 SourceLocation LAngleLoc,
3269 TypeSourceInfo *TInfo,
3270 SourceLocation RAngleLoc,
3271 SourceLocation LParenLoc,
3272 Expr *SubExpr,
3273 SourceLocation RParenLoc) {
3274 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3275 TInfo, SubExpr,
3276 SourceRange(LAngleLoc, RAngleLoc),
3277 SourceRange(LParenLoc, RParenLoc));
3278 }
3279
3280 /// Build a new C++ const_cast expression.
3281 ///
3282 /// By default, performs semantic analysis to build the new expression.
3283 /// Subclasses may override this routine to provide different behavior.
3285 SourceLocation LAngleLoc,
3286 TypeSourceInfo *TInfo,
3287 SourceLocation RAngleLoc,
3288 SourceLocation LParenLoc,
3289 Expr *SubExpr,
3290 SourceLocation RParenLoc) {
3291 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3292 TInfo, SubExpr,
3293 SourceRange(LAngleLoc, RAngleLoc),
3294 SourceRange(LParenLoc, RParenLoc));
3295 }
3296
3299 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3300 SourceLocation LParenLoc, Expr *SubExpr,
3301 SourceLocation RParenLoc) {
3302 return getSema().BuildCXXNamedCast(
3303 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3304 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3305 }
3306
3307 /// Build a new C++ functional-style cast expression.
3308 ///
3309 /// By default, performs semantic analysis to build the new expression.
3310 /// Subclasses may override this routine to provide different behavior.
3312 SourceLocation LParenLoc,
3313 Expr *Sub,
3314 SourceLocation RParenLoc,
3315 bool ListInitialization) {
3316 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3317 // CXXParenListInitExpr. Pass its expanded arguments so that the
3318 // CXXParenListInitExpr can be rebuilt.
3319 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3321 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3322 RParenLoc, ListInitialization);
3323 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3324 MultiExprArg(&Sub, 1), RParenLoc,
3325 ListInitialization);
3326 }
3327
3328 /// Build a new C++ __builtin_bit_cast expression.
3329 ///
3330 /// By default, performs semantic analysis to build the new expression.
3331 /// Subclasses may override this routine to provide different behavior.
3333 TypeSourceInfo *TSI, Expr *Sub,
3334 SourceLocation RParenLoc) {
3335 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3336 }
3337
3338 /// Build a new C++ typeid(type) expression.
3339 ///
3340 /// By default, performs semantic analysis to build the new expression.
3341 /// Subclasses may override this routine to provide different behavior.
3343 SourceLocation TypeidLoc,
3344 TypeSourceInfo *Operand,
3345 SourceLocation RParenLoc) {
3346 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3347 RParenLoc);
3348 }
3349
3350
3351 /// Build a new C++ typeid(expr) expression.
3352 ///
3353 /// By default, performs semantic analysis to build the new expression.
3354 /// Subclasses may override this routine to provide different behavior.
3356 SourceLocation TypeidLoc,
3357 Expr *Operand,
3358 SourceLocation RParenLoc) {
3359 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3360 RParenLoc);
3361 }
3362
3363 /// Build a new C++ __uuidof(type) expression.
3364 ///
3365 /// By default, performs semantic analysis to build the new expression.
3366 /// Subclasses may override this routine to provide different behavior.
3368 TypeSourceInfo *Operand,
3369 SourceLocation RParenLoc) {
3370 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3371 }
3372
3373 /// Build a new C++ __uuidof(expr) expression.
3374 ///
3375 /// By default, performs semantic analysis to build the new expression.
3376 /// Subclasses may override this routine to provide different behavior.
3378 Expr *Operand, SourceLocation RParenLoc) {
3379 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3380 }
3381
3382 /// Build a new C++ "this" expression.
3383 ///
3384 /// By default, performs semantic analysis to build a new "this" expression.
3385 /// Subclasses may override this routine to provide different behavior.
3387 QualType ThisType,
3388 bool isImplicit) {
3389 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3390 return ExprError();
3391 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3392 }
3393
3394 /// Build a new C++ throw expression.
3395 ///
3396 /// By default, performs semantic analysis to build the new expression.
3397 /// Subclasses may override this routine to provide different behavior.
3399 bool IsThrownVariableInScope) {
3400 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3401 }
3402
3403 /// Build a new C++ default-argument expression.
3404 ///
3405 /// By default, builds a new default-argument expression, which does not
3406 /// require any semantic analysis. Subclasses may override this routine to
3407 /// provide different behavior.
3409 Expr *RewrittenExpr) {
3410 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3411 RewrittenExpr, getSema().CurContext);
3412 }
3413
3414 /// Build a new C++11 default-initialization expression.
3415 ///
3416 /// By default, builds a new default field initialization expression, which
3417 /// does not require any semantic analysis. Subclasses may override this
3418 /// routine to provide different behavior.
3420 FieldDecl *Field) {
3421 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3422 }
3423
3424 /// Build a new C++ zero-initialization expression.
3425 ///
3426 /// By default, performs semantic analysis to build the new expression.
3427 /// Subclasses may override this routine to provide different behavior.
3429 SourceLocation LParenLoc,
3430 SourceLocation RParenLoc) {
3431 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3432 /*ListInitialization=*/false);
3433 }
3434
3435 /// Build a new C++ "new" expression.
3436 ///
3437 /// By default, performs semantic analysis to build the new expression.
3438 /// Subclasses may override this routine to provide different behavior.
3440 SourceLocation PlacementLParen,
3441 MultiExprArg PlacementArgs,
3442 SourceLocation PlacementRParen,
3443 SourceRange TypeIdParens, QualType AllocatedType,
3444 TypeSourceInfo *AllocatedTypeInfo,
3445 std::optional<Expr *> ArraySize,
3446 SourceRange DirectInitRange, Expr *Initializer) {
3447 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3448 PlacementLParen,
3449 PlacementArgs,
3450 PlacementRParen,
3451 TypeIdParens,
3452 AllocatedType,
3453 AllocatedTypeInfo,
3454 ArraySize,
3455 DirectInitRange,
3456 Initializer);
3457 }
3458
3459 /// Build a new C++ "delete" expression.
3460 ///
3461 /// By default, performs semantic analysis to build the new expression.
3462 /// Subclasses may override this routine to provide different behavior.
3464 bool IsGlobalDelete,
3465 bool IsArrayForm,
3466 Expr *Operand) {
3467 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3468 Operand);
3469 }
3470
3471 /// Build a new type trait expression.
3472 ///
3473 /// By default, performs semantic analysis to build the new expression.
3474 /// Subclasses may override this routine to provide different behavior.
3476 SourceLocation StartLoc,
3478 SourceLocation RParenLoc) {
3479 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3480 }
3481
3482 /// Build a new array type trait expression.
3483 ///
3484 /// By default, performs semantic analysis to build the new expression.
3485 /// Subclasses may override this routine to provide different behavior.
3487 SourceLocation StartLoc,
3488 TypeSourceInfo *TSInfo,
3489 Expr *DimExpr,
3490 SourceLocation RParenLoc) {
3491 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3492 }
3493
3494 /// Build a new expression trait expression.
3495 ///
3496 /// By default, performs semantic analysis to build the new expression.
3497 /// Subclasses may override this routine to provide different behavior.
3499 SourceLocation StartLoc,
3500 Expr *Queried,
3501 SourceLocation RParenLoc) {
3502 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3503 }
3504
3505 /// Build a new (previously unresolved) declaration reference
3506 /// expression.
3507 ///
3508 /// By default, performs semantic analysis to build the new expression.
3509 /// Subclasses may override this routine to provide different behavior.
3511 NestedNameSpecifierLoc QualifierLoc,
3512 SourceLocation TemplateKWLoc,
3513 const DeclarationNameInfo &NameInfo,
3514 const TemplateArgumentListInfo *TemplateArgs,
3515 bool IsAddressOfOperand,
3516 TypeSourceInfo **RecoveryTSI) {
3517 CXXScopeSpec SS;
3518 SS.Adopt(QualifierLoc);
3519
3520 if (TemplateArgs || TemplateKWLoc.isValid())
3522 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3523
3525 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3526 }
3527
3528 /// Build a new template-id expression.
3529 ///
3530 /// By default, performs semantic analysis to build the new expression.
3531 /// Subclasses may override this routine to provide different behavior.
3533 SourceLocation TemplateKWLoc,
3534 LookupResult &R,
3535 bool RequiresADL,
3536 const TemplateArgumentListInfo *TemplateArgs) {
3537 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3538 TemplateArgs);
3539 }
3540
3541 /// Build a new object-construction expression.
3542 ///
3543 /// By default, performs semantic analysis to build the new expression.
3544 /// Subclasses may override this routine to provide different behavior.
3547 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3548 bool ListInitialization, bool StdInitListInitialization,
3549 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3550 SourceRange ParenRange) {
3551 // Reconstruct the constructor we originally found, which might be
3552 // different if this is a call to an inherited constructor.
3553 CXXConstructorDecl *FoundCtor = Constructor;
3554 if (Constructor->isInheritingConstructor())
3555 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3556
3557 SmallVector<Expr *, 8> ConvertedArgs;
3558 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3559 ConvertedArgs))
3560 return ExprError();
3561
3562 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3563 IsElidable,
3564 ConvertedArgs,
3565 HadMultipleCandidates,
3566 ListInitialization,
3567 StdInitListInitialization,
3568 RequiresZeroInit, ConstructKind,
3569 ParenRange);
3570 }
3571
3572 /// Build a new implicit construction via inherited constructor
3573 /// expression.
3575 CXXConstructorDecl *Constructor,
3576 bool ConstructsVBase,
3577 bool InheritedFromVBase) {
3579 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3580 }
3581
3582 /// Build a new object-construction expression.
3583 ///
3584 /// By default, performs semantic analysis to build the new expression.
3585 /// Subclasses may override this routine to provide different behavior.
3587 SourceLocation LParenOrBraceLoc,
3588 MultiExprArg Args,
3589 SourceLocation RParenOrBraceLoc,
3590 bool ListInitialization) {
3592 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3593 }
3594
3595 /// Build a new object-construction expression.
3596 ///
3597 /// By default, performs semantic analysis to build the new expression.
3598 /// Subclasses may override this routine to provide different behavior.
3600 SourceLocation LParenLoc,
3601 MultiExprArg Args,
3602 SourceLocation RParenLoc,
3603 bool ListInitialization) {
3604 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3605 RParenLoc, ListInitialization);
3606 }
3607
3608 /// Build a new member reference expression.
3609 ///
3610 /// By default, performs semantic analysis to build the new expression.
3611 /// Subclasses may override this routine to provide different behavior.
3613 QualType BaseType,
3614 bool IsArrow,
3615 SourceLocation OperatorLoc,
3616 NestedNameSpecifierLoc QualifierLoc,
3617 SourceLocation TemplateKWLoc,
3618 NamedDecl *FirstQualifierInScope,
3619 const DeclarationNameInfo &MemberNameInfo,
3620 const TemplateArgumentListInfo *TemplateArgs) {
3621 CXXScopeSpec SS;
3622 SS.Adopt(QualifierLoc);
3623
3624 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3625 OperatorLoc, IsArrow,
3626 SS, TemplateKWLoc,
3627 FirstQualifierInScope,
3628 MemberNameInfo,
3629 TemplateArgs, /*S*/nullptr);
3630 }
3631
3632 /// Build a new member reference expression.
3633 ///
3634 /// By default, performs semantic analysis to build the new expression.
3635 /// Subclasses may override this routine to provide different behavior.
3637 SourceLocation OperatorLoc,
3638 bool IsArrow,
3639 NestedNameSpecifierLoc QualifierLoc,
3640 SourceLocation TemplateKWLoc,
3641 NamedDecl *FirstQualifierInScope,
3642 LookupResult &R,
3643 const TemplateArgumentListInfo *TemplateArgs) {
3644 CXXScopeSpec SS;
3645 SS.Adopt(QualifierLoc);
3646
3647 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3648 OperatorLoc, IsArrow,
3649 SS, TemplateKWLoc,
3650 FirstQualifierInScope,
3651 R, TemplateArgs, /*S*/nullptr);
3652 }
3653
3654 /// Build a new noexcept expression.
3655 ///
3656 /// By default, performs semantic analysis to build the new expression.
3657 /// Subclasses may override this routine to provide different behavior.
3659 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3660 }
3661
3662 /// Build a new expression to compute the length of a parameter pack.
3664 SourceLocation PackLoc,
3665 SourceLocation RParenLoc,
3666 std::optional<unsigned> Length,
3667 ArrayRef<TemplateArgument> PartialArgs) {
3668 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3669 RParenLoc, Length, PartialArgs);
3670 }
3671
3673 SourceLocation RSquareLoc,
3674 Expr *PackIdExpression, Expr *IndexExpr,
3675 ArrayRef<Expr *> ExpandedExprs,
3676 bool FullySubstituted = false) {
3677 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3678 IndexExpr, RSquareLoc, ExpandedExprs,
3679 FullySubstituted);
3680 }
3681
3682 /// Build a new expression representing a call to a source location
3683 /// builtin.
3684 ///
3685 /// By default, performs semantic analysis to build the new expression.
3686 /// Subclasses may override this routine to provide different behavior.
3688 SourceLocation BuiltinLoc,
3689 SourceLocation RPLoc,
3690 DeclContext *ParentContext) {
3691 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3692 ParentContext);
3693 }
3694
3695 /// Build a new Objective-C boxed expression.
3696 ///
3697 /// By default, performs semantic analysis to build the new expression.
3698 /// Subclasses may override this routine to provide different behavior.
3700 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3701 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3703 CXXScopeSpec SS;
3704 SS.Adopt(NNS);
3705 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3706 ConceptNameInfo,
3707 FoundDecl,
3708 NamedConcept, TALI);
3709 if (Result.isInvalid())
3710 return ExprError();
3711 return Result;
3712 }
3713
3714 /// \brief Build a new requires expression.
3715 ///
3716 /// By default, performs semantic analysis to build the new expression.
3717 /// Subclasses may override this routine to provide different behavior.
3720 SourceLocation LParenLoc,
3721 ArrayRef<ParmVarDecl *> LocalParameters,
3722 SourceLocation RParenLoc,
3724 SourceLocation ClosingBraceLoc) {
3725 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3726 LocalParameters, RParenLoc, Requirements,
3727 ClosingBraceLoc);
3728 }
3729
3733 return SemaRef.BuildTypeRequirement(SubstDiag);
3734 }
3735
3738 }
3739
3742 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3743 SourceLocation NoexceptLoc,
3745 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3746 std::move(Ret));
3747 }
3748
3750 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3752 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3753 std::move(Ret));
3754 }
3755
3757 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3758 const ASTConstraintSatisfaction &Satisfaction) {
3759 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3760 Satisfaction);
3761 }
3762
3764 return SemaRef.BuildNestedRequirement(Constraint);
3765 }
3766
3767 /// \brief Build a new Objective-C boxed expression.
3768 ///
3769 /// By default, performs semantic analysis to build the new expression.
3770 /// Subclasses may override this routine to provide different behavior.
3772 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3773 }
3774
3775 /// Build a new Objective-C array literal.
3776 ///
3777 /// By default, performs semantic analysis to build the new expression.
3778 /// Subclasses may override this routine to provide different behavior.
3780 Expr **Elements, unsigned NumElements) {
3782 Range, MultiExprArg(Elements, NumElements));
3783 }
3784
3786 Expr *Base, Expr *Key,
3787 ObjCMethodDecl *getterMethod,
3788 ObjCMethodDecl *setterMethod) {
3790 RB, Base, Key, getterMethod, setterMethod);
3791 }
3792
3793 /// Build a new Objective-C dictionary literal.
3794 ///
3795 /// By default, performs semantic analysis to build the new expression.
3796 /// Subclasses may override this routine to provide different behavior.
3799 return getSema().ObjC().BuildObjCDictionaryLiteral(Range, Elements);
3800 }
3801
3802 /// Build a new Objective-C \@encode expression.
3803 ///
3804 /// By default, performs semantic analysis to build the new expression.
3805 /// Subclasses may override this routine to provide different behavior.
3807 TypeSourceInfo *EncodeTypeInfo,
3808 SourceLocation RParenLoc) {
3809 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3810 RParenLoc);
3811 }
3812
3813 /// Build a new Objective-C class message.
3815 Selector Sel,
3816 ArrayRef<SourceLocation> SelectorLocs,
3817 ObjCMethodDecl *Method,
3818 SourceLocation LBracLoc,
3819 MultiExprArg Args,
3820 SourceLocation RBracLoc) {
3822 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3823 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3824 RBracLoc, Args);
3825 }
3826
3827 /// Build a new Objective-C instance message.
3829 Selector Sel,
3830 ArrayRef<SourceLocation> SelectorLocs,
3831 ObjCMethodDecl *Method,
3832 SourceLocation LBracLoc,
3833 MultiExprArg Args,
3834 SourceLocation RBracLoc) {
3835 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3836 /*SuperLoc=*/SourceLocation(),
3837 Sel, Method, LBracLoc,
3838 SelectorLocs, RBracLoc, Args);
3839 }
3840
3841 /// Build a new Objective-C instance/class message to 'super'.
3843 Selector Sel,
3844 ArrayRef<SourceLocation> SelectorLocs,
3845 QualType SuperType,
3846 ObjCMethodDecl *Method,
3847 SourceLocation LBracLoc,
3848 MultiExprArg Args,
3849 SourceLocation RBracLoc) {
3850 return Method->isInstanceMethod()
3852 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3853 SelectorLocs, RBracLoc, Args)
3854 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3855 Sel, Method, LBracLoc,
3856 SelectorLocs, RBracLoc, Args);
3857 }
3858
3859 /// Build a new Objective-C ivar reference expression.
3860 ///
3861 /// By default, performs semantic analysis to build the new expression.
3862 /// Subclasses may override this routine to provide different behavior.
3864 SourceLocation IvarLoc,
3865 bool IsArrow, bool IsFreeIvar) {
3866 CXXScopeSpec SS;
3867 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3869 BaseArg, BaseArg->getType(),
3870 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3871 /*FirstQualifierInScope=*/nullptr, NameInfo,
3872 /*TemplateArgs=*/nullptr,
3873 /*S=*/nullptr);
3874 if (IsFreeIvar && Result.isUsable())
3875 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3876 return Result;
3877 }
3878
3879 /// Build a new Objective-C property reference expression.
3880 ///
3881 /// By default, performs semantic analysis to build the new expression.
3882 /// Subclasses may override this routine to provide different behavior.
3885 SourceLocation PropertyLoc) {
3886 CXXScopeSpec SS;
3887 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3888 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3889 /*FIXME:*/PropertyLoc,
3890 /*IsArrow=*/false,
3891 SS, SourceLocation(),
3892 /*FirstQualifierInScope=*/nullptr,
3893 NameInfo,
3894 /*TemplateArgs=*/nullptr,
3895 /*S=*/nullptr);
3896 }
3897
3898 /// Build a new Objective-C property reference expression.
3899 ///
3900 /// By default, performs semantic analysis to build the new expression.
3901 /// Subclasses may override this routine to provide different behavior.
3903 ObjCMethodDecl *Getter,
3904 ObjCMethodDecl *Setter,
3905 SourceLocation PropertyLoc) {
3906 // Since these expressions can only be value-dependent, we do not
3907 // need to perform semantic analysis again.
3908 return Owned(
3909 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3911 PropertyLoc, Base));
3912 }
3913
3914 /// Build a new Objective-C "isa" expression.
3915 ///
3916 /// By default, performs semantic analysis to build the new expression.
3917 /// Subclasses may override this routine to provide different behavior.
3919 SourceLocation OpLoc, bool IsArrow) {
3920 CXXScopeSpec SS;
3921 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3922 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3923 OpLoc, IsArrow,
3924 SS, SourceLocation(),
3925 /*FirstQualifierInScope=*/nullptr,
3926 NameInfo,
3927 /*TemplateArgs=*/nullptr,
3928 /*S=*/nullptr);
3929 }
3930
3931 /// Build a new shuffle vector expression.
3932 ///
3933 /// By default, performs semantic analysis to build the new expression.
3934 /// Subclasses may override this routine to provide different behavior.
3936 MultiExprArg SubExprs,
3937 SourceLocation RParenLoc) {
3938 // Find the declaration for __builtin_shufflevector
3939 const IdentifierInfo &Name
3940 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3942 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3943 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3944
3945 // Build a reference to the __builtin_shufflevector builtin
3946 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3947 Expr *Callee = new (SemaRef.Context)
3948 DeclRefExpr(SemaRef.Context, Builtin, false,
3949 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3950 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3951 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3952 CK_BuiltinFnToFnPtr).get();
3953
3954 // Build the CallExpr
3955 ExprResult TheCall = CallExpr::Create(
3956 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3957 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3959
3960 // Type-check the __builtin_shufflevector expression.
3961 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3962 }
3963
3964 /// Build a new convert vector expression.
3966 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3967 SourceLocation RParenLoc) {
3968 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3969 }
3970
3971 /// Build a new template argument pack expansion.
3972 ///
3973 /// By default, performs semantic analysis to build a new pack expansion
3974 /// for a template argument. Subclasses may override this routine to provide
3975 /// different behavior.
3978 std::optional<unsigned> NumExpansions) {
3979 switch (Pattern.getArgument().getKind()) {
3983 EllipsisLoc, NumExpansions);
3984 if (Result.isInvalid())
3985 return TemplateArgumentLoc();
3986
3987 return TemplateArgumentLoc(Result.get(), Result.get());
3988 }
3989
3991 return TemplateArgumentLoc(
3994 NumExpansions),
3995 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3996 EllipsisLoc);
3997
4005 llvm_unreachable("Pack expansion pattern has no parameter packs");
4006
4008 if (TypeSourceInfo *Expansion
4009 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4010 EllipsisLoc,
4011 NumExpansions))
4012 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4013 Expansion);
4014 break;
4015 }
4016
4017 return TemplateArgumentLoc();
4018 }
4019
4020 /// Build a new expression pack expansion.
4021 ///
4022 /// By default, performs semantic analysis to build a new pack expansion
4023 /// for an expression. Subclasses may override this routine to provide
4024 /// different behavior.
4026 std::optional<unsigned> NumExpansions) {
4027 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4028 }
4029
4030 /// Build a new C++1z fold-expression.
4031 ///
4032 /// By default, performs semantic analysis in order to build a new fold
4033 /// expression.
4035 SourceLocation LParenLoc, Expr *LHS,
4036 BinaryOperatorKind Operator,
4037 SourceLocation EllipsisLoc, Expr *RHS,
4038 SourceLocation RParenLoc,
4039 std::optional<unsigned> NumExpansions) {
4040 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4041 EllipsisLoc, RHS, RParenLoc,
4042 NumExpansions);
4043 }
4044
4046 LambdaScopeInfo *LSI) {
4047 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4048 if (Expr *Init = PVD->getInit())
4050 Init->containsUnexpandedParameterPack();
4051 else if (PVD->hasUninstantiatedDefaultArg())
4053 PVD->getUninstantiatedDefaultArg()
4054 ->containsUnexpandedParameterPack();
4055 }
4056 return getSema().BuildLambdaExpr(StartLoc, EndLoc, LSI);
4057 }
4058
4059 /// Build an empty C++1z fold-expression with the given operator.
4060 ///
4061 /// By default, produces the fallback value for the fold-expression, or
4062 /// produce an error if there is no fallback value.
4064 BinaryOperatorKind Operator) {
4065 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4066 }
4067
4068 /// Build a new atomic operation expression.
4069 ///
4070 /// By default, performs semantic analysis to build the new expression.
4071 /// Subclasses may override this routine to provide different behavior.
4074 SourceLocation RParenLoc) {
4075 // Use this for all of the locations, since we don't know the difference
4076 // between the call and the expr at this point.
4077 SourceRange Range{BuiltinLoc, RParenLoc};
4078 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4080 }
4081
4083 ArrayRef<Expr *> SubExprs, QualType Type) {
4084 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4085 }
4086
4088 SourceLocation BeginLoc,
4089 SourceLocation DirLoc,
4090 SourceLocation EndLoc,
4092 StmtResult StrBlock) {
4094 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4095 SourceLocation{}, EndLoc, Clauses, StrBlock);
4096 }
4097
4099 SourceLocation DirLoc,
4100 SourceLocation EndLoc,
4102 StmtResult Loop) {
4104 OpenACCDirectiveKind::Loop, BeginLoc, DirLoc, SourceLocation{},
4105 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, Loop);
4106 }
4107
4109 SourceLocation BeginLoc,
4110 SourceLocation DirLoc,
4111 SourceLocation EndLoc,
4113 StmtResult Loop) {
4115 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4116 SourceLocation{}, EndLoc, Clauses, Loop);
4117 }
4118
4120 SourceLocation DirLoc,
4121 SourceLocation EndLoc,
4123 StmtResult StrBlock) {
4125 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4126 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4127 }
4128
4131 SourceLocation DirLoc, SourceLocation EndLoc,
4132 ArrayRef<OpenACCClause *> Clauses) {
4135 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4136 }
4137
4140 SourceLocation DirLoc, SourceLocation EndLoc,
4141 ArrayRef<OpenACCClause *> Clauses) {
4144 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4145 }
4146
4148 SourceLocation DirLoc,
4149 SourceLocation EndLoc,
4151 StmtResult StrBlock) {
4154 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4155 }
4156
4158 SourceLocation DirLoc,
4159 SourceLocation EndLoc,
4160 ArrayRef<OpenACCClause *> Clauses) {
4162 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4163 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4164 }
4165
4168 SourceLocation DirLoc, SourceLocation EndLoc,
4169 ArrayRef<OpenACCClause *> Clauses) {
4172 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4173 }
4174
4176 SourceLocation DirLoc,
4177 SourceLocation EndLoc,
4178 ArrayRef<OpenACCClause *> Clauses) {
4180 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4181 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4182 }
4183
4185 SourceLocation DirLoc,
4186 SourceLocation EndLoc,
4187 ArrayRef<OpenACCClause *> Clauses) {
4189 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4190 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4191 }
4192
4194 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4195 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4196 SourceLocation RParenLoc, SourceLocation EndLoc,
4197 ArrayRef<OpenACCClause *> Clauses) {
4199 Exprs.push_back(DevNumExpr);
4200 Exprs.insert(Exprs.end(), QueueIdExprs.begin(), QueueIdExprs.end());
4202 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4203 Exprs, RParenLoc, EndLoc, Clauses, {});
4204 }
4205
4207 return getSema().OpenACC().ActOnOpenACCAsteriskSizeExpr(AsteriskLoc);
4208 }
4209
4210private:
4211 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
4212 QualType ObjectType,
4213 NamedDecl *FirstQualifierInScope,
4214 CXXScopeSpec &SS);
4215
4216 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4217 QualType ObjectType,
4218 NamedDecl *FirstQualifierInScope,
4219 CXXScopeSpec &SS);
4220
4221 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
4222 NamedDecl *FirstQualifierInScope,
4223 CXXScopeSpec &SS);
4224
4225 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4227 bool DeducibleTSTContext);
4228
4230 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4232
4234 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4235 OpenACCDirectiveKind DirKind,
4236 const OpenACCClause *OldClause);
4237};
4238
4239template <typename Derived>
4241 if (!S)
4242 return S;
4243
4244 switch (S->getStmtClass()) {
4245 case Stmt::NoStmtClass: break;
4246
4247 // Transform individual statement nodes
4248 // Pass SDK into statements that can produce a value
4249#define STMT(Node, Parent) \
4250 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4251#define VALUESTMT(Node, Parent) \
4252 case Stmt::Node##Class: \
4253 return getDerived().Transform##Node(cast<Node>(S), SDK);
4254#define ABSTRACT_STMT(Node)
4255#define EXPR(Node, Parent)
4256#include "clang/AST/StmtNodes.inc"
4257
4258 // Transform expressions by calling TransformExpr.
4259#define STMT(Node, Parent)
4260#define ABSTRACT_STMT(Stmt)
4261#define EXPR(Node, Parent) case Stmt::Node##Class:
4262#include "clang/AST/StmtNodes.inc"
4263 {
4264 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4265
4266 if (SDK == SDK_StmtExprResult)
4267 E = getSema().ActOnStmtExprResult(E);
4268 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
4269 }
4270 }
4271
4272 return S;
4273}
4274
4275template<typename Derived>
4277 if (!S)
4278 return S;
4279
4280 switch (S->getClauseKind()) {
4281 default: break;
4282 // Transform individual clause nodes
4283#define GEN_CLANG_CLAUSE_CLASS
4284#define CLAUSE_CLASS(Enum, Str, Class) \
4285 case Enum: \
4286 return getDerived().Transform##Class(cast<Class>(S));
4287#include "llvm/Frontend/OpenMP/OMP.inc"
4288 }
4289
4290 return S;
4291}
4292
4293
4294template<typename Derived>
4296 if (!E)
4297 return E;
4298
4299 switch (E->getStmtClass()) {
4300 case Stmt::NoStmtClass: break;
4301#define STMT(Node, Parent) case Stmt::Node##Class: break;
4302#define ABSTRACT_STMT(Stmt)
4303#define EXPR(Node, Parent) \
4304 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4305#include "clang/AST/StmtNodes.inc"
4306 }
4307
4308 return E;
4309}
4310
4311template<typename Derived>
4313 bool NotCopyInit) {
4314 // Initializers are instantiated like expressions, except that various outer
4315 // layers are stripped.
4316 if (!Init)
4317 return Init;
4318
4319 if (auto *FE = dyn_cast<FullExpr>(Init))
4320 Init = FE->getSubExpr();
4321
4322 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4323 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4324 Init = OVE->getSourceExpr();
4325 }
4326
4327 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4328 Init = MTE->getSubExpr();
4329
4330 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4331 Init = Binder->getSubExpr();
4332
4333 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4334 Init = ICE->getSubExprAsWritten();
4335
4336 if (CXXStdInitializerListExpr *ILE =
4337 dyn_cast<CXXStdInitializerListExpr>(Init))
4338 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4339
4340 // If this is copy-initialization, we only need to reconstruct
4341 // InitListExprs. Other forms of copy-initialization will be a no-op if
4342 // the initializer is already the right type.
4343 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4344 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4345 return getDerived().TransformExpr(Init);
4346
4347 // Revert value-initialization back to empty parens.
4348 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4349 SourceRange Parens = VIE->getSourceRange();
4350 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4351 Parens.getEnd());
4352 }
4353
4354 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4355 if (isa<ImplicitValueInitExpr>(Init))
4356 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4357 SourceLocation());
4358
4359 // Revert initialization by constructor back to a parenthesized or braced list
4360 // of expressions. Any other form of initializer can just be reused directly.
4361 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4362 return getDerived().TransformExpr(Init);
4363
4364 // If the initialization implicitly converted an initializer list to a
4365 // std::initializer_list object, unwrap the std::initializer_list too.
4366 if (Construct && Construct->isStdInitListInitialization())
4367 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4368
4369 // Enter a list-init context if this was list initialization.
4372 Construct->isListInitialization());
4373
4374 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4375 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4376 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4377 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4378 SmallVector<Expr*, 8> NewArgs;
4379 bool ArgChanged = false;
4380 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4381 /*IsCall*/true, NewArgs, &ArgChanged))
4382 return ExprError();
4383
4384 // If this was list initialization, revert to syntactic list form.
4385 if (Construct->isListInitialization())
4386 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4387 Construct->getEndLoc());
4388
4389 // Build a ParenListExpr to represent anything else.
4391 if (Parens.isInvalid()) {
4392 // This was a variable declaration's initialization for which no initializer
4393 // was specified.
4394 assert(NewArgs.empty() &&
4395 "no parens or braces but have direct init with arguments?");
4396 return ExprEmpty();
4397 }
4398 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4399 Parens.getEnd());
4400}
4401
4402template<typename Derived>
4404 unsigned NumInputs,
4405 bool IsCall,
4406 SmallVectorImpl<Expr *> &Outputs,
4407 bool *ArgChanged) {
4408 for (unsigned I = 0; I != NumInputs; ++I) {
4409 // If requested, drop call arguments that need to be dropped.
4410 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4411 if (ArgChanged)
4412 *ArgChanged = true;
4413
4414 break;
4415 }
4416
4417 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4418 Expr *Pattern = Expansion->getPattern();
4419
4421 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4422 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4423
4424 // Determine whether the set of unexpanded parameter packs can and should
4425 // be expanded.
4426 bool Expand = true;
4427 bool RetainExpansion = false;
4428 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4429 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4430 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4431 Pattern->getSourceRange(),
4432 Unexpanded,
4433 Expand, RetainExpansion,
4434 NumExpansions))
4435 return true;
4436
4437 if (!Expand) {
4438 // The transform has determined that we should perform a simple
4439 // transformation on the pack expansion, producing another pack
4440 // expansion.
4441 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4442 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4443 if (OutPattern.isInvalid())
4444 return true;
4445
4446 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4447 Expansion->getEllipsisLoc(),
4448 NumExpansions);
4449 if (Out.isInvalid())
4450 return true;
4451
4452 if (ArgChanged)
4453 *ArgChanged = true;
4454 Outputs.push_back(Out.get());
4455 continue;
4456 }
4457
4458 // Record right away that the argument was changed. This needs
4459 // to happen even if the array expands to nothing.
4460 if (ArgChanged) *ArgChanged = true;
4461
4462 // The transform has determined that we should perform an elementwise
4463 // expansion of the pattern. Do so.
4464 for (unsigned I = 0; I != *NumExpansions; ++I) {
4465 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4466 ExprResult Out = getDerived().TransformExpr(Pattern);
4467 if (Out.isInvalid())
4468 return true;
4469
4470 if (Out.get()->containsUnexpandedParameterPack()) {
4471 Out = getDerived().RebuildPackExpansion(
4472 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4473 if (Out.isInvalid())
4474 return true;
4475 }
4476
4477 Outputs.push_back(Out.get());
4478 }
4479
4480 // If we're supposed to retain a pack expansion, do so by temporarily
4481 // forgetting the partially-substituted parameter pack.
4482 if (RetainExpansion) {
4483 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4484
4485 ExprResult Out = getDerived().TransformExpr(Pattern);
4486 if (Out.isInvalid())
4487 return true;
4488
4489 Out = getDerived().RebuildPackExpansion(
4490 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4491 if (Out.isInvalid())
4492 return true;
4493
4494 Outputs.push_back(Out.get());
4495 }
4496
4497 continue;
4498 }
4499
4501 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4502 : getDerived().TransformExpr(Inputs[I]);
4503 if (Result.isInvalid())
4504 return true;
4505
4506 if (Result.get() != Inputs[I] && ArgChanged)
4507 *ArgChanged = true;
4508
4509 Outputs.push_back(Result.get());
4510 }
4511
4512 return false;
4513}
4514
4515template <typename Derived>
4518 if (Var) {
4519 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4520 getDerived().TransformDefinition(Var->getLocation(), Var));
4521
4522 if (!ConditionVar)
4523 return Sema::ConditionError();
4524
4525 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4526 }
4527
4528 if (Expr) {
4529 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4530
4531 if (CondExpr.isInvalid())
4532 return Sema::ConditionError();
4533
4534 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4535 /*MissingOK=*/true);
4536 }
4537
4538 return Sema::ConditionResult();
4539}
4540
4541template <typename Derived>
4543 NestedNameSpecifierLoc NNS, QualType ObjectType,
4544 NamedDecl *FirstQualifierInScope) {
4546
4547 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4548 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4549 Qualifier = Qualifier.getPrefix())
4550 Qualifiers.push_back(Qualifier);
4551 };
4552 insertNNS(NNS);
4553
4554 CXXScopeSpec SS;
4555 while (!Qualifiers.empty()) {
4556 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4558
4559 switch (QNNS->getKind()) {
4563 ObjectType);
4564 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4565 SS, FirstQualifierInScope, false))
4566 return NestedNameSpecifierLoc();
4567 break;
4568 }
4569
4571 NamespaceDecl *NS =
4572 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4573 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4574 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4575 break;
4576 }
4577
4579 NamespaceAliasDecl *Alias =
4580 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4582 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4583 Q.getLocalEndLoc());
4584 break;
4585 }
4586
4588 // There is no meaningful transformation that one could perform on the
4589 // global scope.
4590 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4591 break;
4592
4594 CXXRecordDecl *RD =
4595 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4596 SourceLocation(), QNNS->getAsRecordDecl()));
4597 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4598 break;
4599 }
4600
4603 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4604 FirstQualifierInScope, SS);
4605
4606 if (!TL)
4607 return NestedNameSpecifierLoc();
4608
4609 QualType T = TL.getType();
4610 if (T->isDependentType() || T->isRecordType() ||
4611 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4612 if (T->isEnumeralType())
4613 SemaRef.Diag(TL.getBeginLoc(),
4614 diag::warn_cxx98_compat_enum_nested_name_spec);
4615
4616 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) {
4617 SS.Adopt(ETL.getQualifierLoc());
4618 TL = ETL.getNamedTypeLoc();
4619 }
4620
4621 SS.Extend(SemaRef.Context, TL.getTemplateKeywordLoc(), TL,
4622 Q.getLocalEndLoc());
4623 break;
4624 }
4625 // If the nested-name-specifier is an invalid type def, don't emit an
4626 // error because a previous error should have already been emitted.
4628 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4629 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4630 << T << SS.getRange();
4631 }
4632 return NestedNameSpecifierLoc();
4633 }
4634 }
4635
4636 // The qualifier-in-scope and object type only apply to the leftmost entity.
4637 FirstQualifierInScope = nullptr;
4638 ObjectType = QualType();
4639 }
4640
4641 // Don't rebuild the nested-name-specifier if we don't have to.
4642 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4643 !getDerived().AlwaysRebuild())
4644 return NNS;
4645
4646 // If we can re-use the source-location data from the original
4647 // nested-name-specifier, do so.
4648 if (SS.location_size() == NNS.getDataLength() &&
4649 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4651
4652 // Allocate new nested-name-specifier location information.
4653 return SS.getWithLocInContext(SemaRef.Context);
4654}
4655
4656template<typename Derived>
4660 DeclarationName Name = NameInfo.getName();
4661 if (!Name)
4662 return DeclarationNameInfo();
4663
4664 switch (Name.getNameKind()) {
4672 return NameInfo;
4673
4675 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4676 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4677 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4678 if (!NewTemplate)
4679 return DeclarationNameInfo();
4680
4681 DeclarationNameInfo NewNameInfo(NameInfo);
4682 NewNameInfo.setName(
4684 return NewNameInfo;
4685 }
4686
4690 TypeSourceInfo *NewTInfo;
4691 CanQualType NewCanTy;
4692 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4693 NewTInfo = getDerived().TransformType(OldTInfo);
4694 if (!NewTInfo)
4695 return DeclarationNameInfo();
4696 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4697 }
4698 else {
4699 NewTInfo = nullptr;
4700 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4701 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4702 if (NewT.isNull())
4703 return DeclarationNameInfo();
4704 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4705 }
4706
4707 DeclarationName NewName
4708 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4709 NewCanTy);
4710 DeclarationNameInfo NewNameInfo(NameInfo);
4711 NewNameInfo.setName(NewName);
4712 NewNameInfo.setNamedTypeInfo(NewTInfo);
4713 return NewNameInfo;
4714 }
4715 }
4716
4717 llvm_unreachable("Unknown name kind.");
4718}
4719
4720template<typename Derived>
4723 TemplateName Name,
4724 SourceLocation NameLoc,
4725 QualType ObjectType,
4726 NamedDecl *FirstQualifierInScope,
4727 bool AllowInjectedClassName) {
4728 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4729 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
4730 assert(Template && "qualified template name must refer to a template");
4731
4732 TemplateDecl *TransTemplate
4733 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4734 Template));
4735 if (!TransTemplate)
4736 return TemplateName();
4737
4738 if (!getDerived().AlwaysRebuild() &&
4739 SS.getScopeRep() == QTN->getQualifier() &&
4740 TransTemplate == Template)
4741 return Name;
4742
4743 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4744 TransTemplate);
4745 }
4746
4747 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4748 if (SS.getScopeRep()) {
4749 // These apply to the scope specifier, not the template.
4750 ObjectType = QualType();
4751 FirstQualifierInScope = nullptr;
4752 }
4753
4754 if (!getDerived().AlwaysRebuild() &&
4755 SS.getScopeRep() == DTN->getQualifier() &&
4756 ObjectType.isNull())
4757 return Name;
4758
4759 // FIXME: Preserve the location of the "template" keyword.
4760 SourceLocation TemplateKWLoc = NameLoc;
4761
4762 if (DTN->isIdentifier()) {
4763 return getDerived().RebuildTemplateName(SS,
4764 TemplateKWLoc,
4765 *DTN->getIdentifier(),
4766 NameLoc,
4767 ObjectType,
4768 FirstQualifierInScope,
4769 AllowInjectedClassName);
4770 }
4771
4772 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4773 DTN->getOperator(), NameLoc,
4774 ObjectType, AllowInjectedClassName);
4775 }
4776
4777 // FIXME: Try to preserve more of the TemplateName.
4778 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4779 TemplateDecl *TransTemplate
4780 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4781 Template));
4782 if (!TransTemplate)
4783 return TemplateName();
4784
4785 return getDerived().RebuildTemplateName(SS, /*TemplateKeyword=*/false,
4786 TransTemplate);
4787 }
4788
4790 = Name.getAsSubstTemplateTemplateParmPack()) {
4791 return getDerived().RebuildTemplateName(
4792 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4793 SubstPack->getIndex(), SubstPack->getFinal());
4794 }
4795
4796 // These should be getting filtered out before they reach the AST.
4797 llvm_unreachable("overloaded function decl survived to here");
4798}
4799
4800template<typename Derived>
4802 const TemplateArgument &Arg,
4803 TemplateArgumentLoc &Output) {
4804 Output = getSema().getTrivialTemplateArgumentLoc(
4805 Arg, QualType(), getDerived().getBaseLocation());
4806}
4807
4808template <typename Derived>
4810 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4811 bool Uneval) {
4812 const TemplateArgument &Arg = Input.getArgument();
4813 switch (Arg.getKind()) {
4816 llvm_unreachable("Unexpected TemplateArgument");
4817
4822 // Transform a resolved template argument straight to a resolved template
4823 // argument. We get here when substituting into an already-substituted
4824 // template type argument during concept satisfaction checking.
4826 QualType NewT = getDerived().TransformType(T);
4827 if (NewT.isNull())
4828 return true;
4829
4831 ? Arg.getAsDecl()
4832 : nullptr;
4833 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4834 getDerived().getBaseLocation(), D))
4835 : nullptr;
4836 if (D && !NewD)
4837 return true;
4838
4839 if (NewT == T && D == NewD)
4840 Output = Input;
4841 else if (Arg.getKind() == TemplateArgument::Integral)
4842 Output = TemplateArgumentLoc(
4843 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4845 else if (Arg.getKind() == TemplateArgument::NullPtr)
4846 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4848 else if (Arg.getKind() == TemplateArgument::Declaration)
4849 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4852 Output = TemplateArgumentLoc(
4853 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4855 else
4856 llvm_unreachable("unexpected template argument kind");
4857
4858 return false;
4859 }
4860
4862 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4863 if (!DI)
4864 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4865
4866 DI = getDerived().TransformType(DI);
4867 if (!DI)
4868 return true;
4869
4870 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4871 return false;
4872 }
4873
4875 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4876 if (QualifierLoc) {
4877 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4878 if (!QualifierLoc)
4879 return true;
4880 }
4881
4882 CXXScopeSpec SS;
4883 SS.Adopt(QualifierLoc);
4884 TemplateName Template = getDerived().TransformTemplateName(
4885 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4886 if (Template.isNull())
4887 return true;
4888
4889 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4890 QualifierLoc, Input.getTemplateNameLoc());
4891 return false;
4892 }
4893
4895 llvm_unreachable("Caller should expand pack expansions");
4896
4898 // Template argument expressions are constant expressions.
4900 getSema(),
4903 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
4905
4906 Expr *InputExpr = Input.getSourceExpression();
4907 if (!InputExpr)
4908 InputExpr = Input.getArgument().getAsExpr();
4909
4910 ExprResult E = getDerived().TransformExpr(InputExpr);
4911 E = SemaRef.ActOnConstantExpression(E);
4912 if (E.isInvalid())
4913 return true;
4914 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4915 return false;
4916 }
4917 }
4918
4919 // Work around bogus GCC warning
4920 return true;
4921}
4922
4923/// Iterator adaptor that invents template argument location information
4924/// for each of the template arguments in its underlying iterator.
4925template<typename Derived, typename InputIterator>
4928 InputIterator Iter;
4929
4930public:
4933 typedef typename std::iterator_traits<InputIterator>::difference_type
4935 typedef std::input_iterator_tag iterator_category;
4936
4937 class pointer {
4939
4940 public:
4941 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4942
4943 const TemplateArgumentLoc *operator->() const { return &Arg; }
4944 };
4945
4947 InputIterator Iter)
4948 : Self(Self), Iter(Iter) { }
4949
4951 ++Iter;
4952 return *this;
4953 }
4954
4957 ++(*this);
4958 return Old;
4959 }
4960
4963 Self.InventTemplateArgumentLoc(*Iter, Result);
4964 return Result;
4965 }
4966
4967 pointer operator->() const { return pointer(**this); }
4968
4971 return X.Iter == Y.Iter;
4972 }
4973
4976 return X.Iter != Y.Iter;
4977 }
4978};
4979
4980template<typename Derived>
4981template<typename InputIterator>
4983 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4984 bool Uneval) {
4985 for (; First != Last; ++First) {
4988
4989 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4990 // Unpack argument packs, which we translate them into separate
4991 // arguments.
4992 // FIXME: We could do much better if we could guarantee that the
4993 // TemplateArgumentLocInfo for the pack expansion would be usable for
4994 // all of the template arguments in the argument pack.
4995 typedef TemplateArgumentLocInventIterator<Derived,
4997 PackLocIterator;
4998 if (TransformTemplateArguments(PackLocIterator(*this,
4999 In.getArgument().pack_begin()),
5000 PackLocIterator(*this,
5001 In.getArgument().pack_end()),
5002 Outputs, Uneval))
5003 return true;
5004
5005 continue;
5006 }
5007
5008 if (In.getArgument().isPackExpansion()) {
5009 // We have a pack expansion, for which we will be substituting into
5010 // the pattern.
5011 SourceLocation Ellipsis;
5012 std::optional<unsigned> OrigNumExpansions;
5013 TemplateArgumentLoc Pattern
5014 = getSema().getTemplateArgumentPackExpansionPattern(
5015 In, Ellipsis, OrigNumExpansions);
5016
5018 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5019 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5020
5021 // Determine whether the set of unexpanded parameter packs can and should
5022 // be expanded.
5023 bool Expand = true;
5024 bool RetainExpansion = false;
5025 std::optional<unsigned> NumExpansions = OrigNumExpansions;
5026 if (getDerived().TryExpandParameterPacks(Ellipsis,
5027 Pattern.getSourceRange(),
5028 Unexpanded,
5029 Expand,
5030 RetainExpansion,
5031 NumExpansions))
5032 return true;
5033
5034 if (!Expand) {
5035 // The transform has determined that we should perform a simple
5036 // transformation on the pack expansion, producing another pack
5037 // expansion.
5038 TemplateArgumentLoc OutPattern;
5039 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5040 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5041 return true;
5042
5043 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
5044 NumExpansions);
5045 if (Out.getArgument().isNull())
5046 return true;
5047
5048 Outputs.addArgument(Out);
5049 continue;
5050 }
5051
5052 // The transform has determined that we should perform an elementwise
5053 // expansion of the pattern. Do so.
5054 for (unsigned I = 0; I != *NumExpansions; ++I) {
5055 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5056
5057 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5058 return true;
5059
5060 if (Out.getArgument().containsUnexpandedParameterPack()) {
5061 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5062 OrigNumExpansions);
5063 if (Out.getArgument().isNull())
5064 return true;
5065 }
5066
5067 Outputs.addArgument(Out);
5068 }
5069
5070 // If we're supposed to retain a pack expansion, do so by temporarily
5071 // forgetting the partially-substituted parameter pack.
5072 if (RetainExpansion) {
5073 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5074
5075 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5076 return true;
5077
5078 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5079 OrigNumExpansions);
5080 if (Out.getArgument().isNull())
5081 return true;
5082
5083 Outputs.addArgument(Out);
5084 }
5085
5086 continue;
5087 }
5088
5089 // The simple case:
5090 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5091 return true;
5092
5093 Outputs.addArgument(Out);
5094 }
5095
5096 return false;
5097
5098}
5099
5100//===----------------------------------------------------------------------===//
5101// Type transformation
5102//===----------------------------------------------------------------------===//
5103
5104template<typename Derived>
5106 if (getDerived().AlreadyTransformed(T))
5107 return T;
5108
5109 // Temporary workaround. All of these transformations should
5110 // eventually turn into transformations on TypeLocs.
5111 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5112 getDerived().getBaseLocation());
5113
5114 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
5115
5116 if (!NewDI)
5117 return QualType();
5118
5119 return NewDI->getType();
5120}
5121
5122template<typename Derived>
5124 // Refine the base location to the type's location.
5125 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5126 getDerived().getBaseEntity());
5127 if (getDerived().AlreadyTransformed(DI->getType()))
5128 return DI;
5129
5130 TypeLocBuilder TLB;
5131
5132 TypeLoc TL = DI->getTypeLoc();
5133 TLB.reserve(TL.getFullDataSize());
5134
5135 QualType Result = getDerived().TransformType(TLB, TL);
5136 if (Result.isNull())
5137 return nullptr;
5138
5139 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5140}
5141
5142template<typename Derived>
5145 switch (T.getTypeLocClass()) {
5146#define ABSTRACT_TYPELOC(CLASS, PARENT)
5147#define TYPELOC(CLASS, PARENT) \
5148 case TypeLoc::CLASS: \
5149 return getDerived().Transform##CLASS##Type(TLB, \
5150 T.castAs<CLASS##TypeLoc>());
5151#include "clang/AST/TypeLocNodes.def"
5152 }
5153
5154 llvm_unreachable("unhandled type loc!");
5155}
5156
5157template<typename Derived>
5159 if (!isa<DependentNameType>(T))
5160 return TransformType(T);
5161
5162 if (getDerived().AlreadyTransformed(T))
5163 return T;
5164 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5165 getDerived().getBaseLocation());
5166 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5167 return NewDI ? NewDI->getType() : QualType();
5168}
5169
5170template<typename Derived>
5173 if (!isa<DependentNameType>(DI->getType()))
5174 return TransformType(DI);
5175
5176 // Refine the base location to the type's location.
5177 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5178 getDerived().getBaseEntity());
5179 if (getDerived().AlreadyTransformed(DI->getType()))
5180 return DI;
5181
5182 TypeLocBuilder TLB;
5183
5184 TypeLoc TL = DI->getTypeLoc();
5185 TLB.reserve(TL.getFullDataSize());
5186
5187 auto QTL = TL.getAs<QualifiedTypeLoc>();
5188 if (QTL)
5189 TL = QTL.getUnqualifiedLoc();
5190
5191 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5192
5193 QualType Result = getDerived().TransformDependentNameType(
5194 TLB, DNTL, /*DeducedTSTContext*/true);
5195 if (Result.isNull())
5196 return nullptr;
5197
5198 if (QTL) {
5199 Result = getDerived().RebuildQualifiedType(Result, QTL);
5200 if (Result.isNull())
5201 return nullptr;
5203 }
5204
5205 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5206}
5207
5208template<typename Derived>
5213 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5214 auto SuppressObjCLifetime =
5215 T.getType().getLocalQualifiers().hasObjCLifetime();
5216 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5217 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5218 SuppressObjCLifetime);
5219 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5220 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5221 TLB, STTP, SuppressObjCLifetime);
5222 } else {
5223 Result = getDerived().TransformType(TLB, UnqualTL);
5224 }
5225
5226 if (Result.isNull())
5227 return QualType();
5228
5229 Result = getDerived().RebuildQualifiedType(Result, T);
5230
5231 if (Result.isNull())
5232 return QualType();
5233
5234 // RebuildQualifiedType might have updated the type, but not in a way
5235 // that invalidates the TypeLoc. (There's no location information for
5236 // qualifiers.)
5238
5239 return Result;
5240}
5241
5242template <typename Derived>
5244 QualifiedTypeLoc TL) {
5245
5247 Qualifiers Quals = TL.getType().getLocalQualifiers();
5248
5249 if ((T.getAddressSpace() != LangAS::Default &&
5250 Quals.getAddressSpace() != LangAS::Default) &&
5251 T.getAddressSpace() != Quals.getAddressSpace()) {
5252 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5253 << TL.getType() << T;
5254 return QualType();
5255 }
5256
5257 // C++ [dcl.fct]p7:
5258 // [When] adding cv-qualifications on top of the function type [...] the
5259 // cv-qualifiers are ignored.
5260 if (T->isFunctionType()) {
5262 Quals.getAddressSpace());
5263 return T;
5264 }
5265
5266 // C++ [dcl.ref]p1:
5267 // when the cv-qualifiers are introduced through the use of a typedef-name
5268 // or decltype-specifier [...] the cv-qualifiers are ignored.
5269 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5270 // applied to a reference type.
5271 if (T->isReferenceType()) {
5272 // The only qualifier that applies to a reference type is restrict.
5273 if (!Quals.hasRestrict())
5274 return T;
5276 }
5277
5278 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5279 // resulting type.
5280 if (Quals.hasObjCLifetime()) {
5281 if (!T->isObjCLifetimeType() && !T->isDependentType())
5282 Quals.removeObjCLifetime();
5283 else if (T.getObjCLifetime()) {
5284 // Objective-C ARC:
5285 // A lifetime qualifier applied to a substituted template parameter
5286 // overrides the lifetime qualifier from the template argument.
5287 const AutoType *AutoTy;
5288 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5289 // 'auto' types behave the same way as template parameters.
5290 QualType Deduced = AutoTy->getDeducedType();
5291 Qualifiers Qs = Deduced.getQualifiers();
5292 Qs.removeObjCLifetime();
5293 Deduced =
5294 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5295 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5296 AutoTy->isDependentType(),
5297 /*isPack=*/false,
5298 AutoTy->getTypeConstraintConcept(),
5299 AutoTy->getTypeConstraintArguments());
5300 } else {
5301 // Otherwise, complain about the addition of a qualifier to an
5302 // already-qualified type.
5303 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5304 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5305 Quals.removeObjCLifetime();
5306 }
5307 }
5308 }
5309
5310 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5311}
5312
5313template<typename Derived>
5314TypeLoc
5316 QualType ObjectType,
5317 NamedDecl *UnqualLookup,
5318 CXXScopeSpec &SS) {
5319 if (getDerived().AlreadyTransformed(TL.getType()))
5320 return TL;
5321
5322 TypeSourceInfo *TSI =
5323 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
5324 if (TSI)
5325 return TSI->getTypeLoc();
5326 return TypeLoc();
5327}
5328
5329template<typename Derived>
5330TypeSourceInfo *
5331TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
5332 QualType ObjectType,
5333 NamedDecl *UnqualLookup,
5334 CXXScopeSpec &SS) {
5335 if (getDerived().AlreadyTransformed(TSInfo->getType()))
5336 return TSInfo;
5337
5338 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
5339 UnqualLookup, SS);
5340}
5341
5342template <typename Derived>
5343TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
5344 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
5345 CXXScopeSpec &SS) {
5346 QualType T = TL.getType();
5347 assert(!getDerived().AlreadyTransformed(T));
5348
5349 TypeLocBuilder TLB;
5350 QualType Result;
5351
5352 if (isa<TemplateSpecializationType>(T)) {
5353 TemplateSpecializationTypeLoc SpecTL =
5354 TL.castAs<TemplateSpecializationTypeLoc>();
5355
5356 TemplateName Template = getDerived().TransformTemplateName(
5357 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
5358 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
5359 if (Template.isNull())
5360 return nullptr;
5361
5362 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
5363 Template);
5364 } else if (isa<DependentTemplateSpecializationType>(T)) {
5365 DependentTemplateSpecializationTypeLoc SpecTL =
5366 TL.castAs<DependentTemplateSpecializationTypeLoc>();
5367
5368 TemplateName Template
5369 = getDerived().RebuildTemplateName(SS,
5370 SpecTL.getTemplateKeywordLoc(),
5371 *SpecTL.getTypePtr()->getIdentifier(),
5372 SpecTL.getTemplateNameLoc(),
5373 ObjectType, UnqualLookup,
5374 /*AllowInjectedClassName*/true);
5375 if (Template.isNull())
5376 return nullptr;
5377
5378 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
5379 SpecTL,
5380 Template,
5381 SS);
5382 } else {
5383 // Nothing special needs to be done for these.
5384 Result = getDerived().TransformType(TLB, TL);
5385 }
5386
5387 if (Result.isNull())
5388 return nullptr;
5389
5390 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5391}
5392
5393template <class TyLoc> static inline
5395 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5396 NewT.setNameLoc(T.getNameLoc());
5397 return T.getType();
5398}
5399
5400template<typename Derived>
5401QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5402 BuiltinTypeLoc T) {
5403 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5404 NewT.setBuiltinLoc(T.getBuiltinLoc());
5405 if (T.needsExtraLocalData())
5406 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5407 return T.getType();
5408}
5409
5410template<typename Derived>
5411QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
5412 ComplexTypeLoc T) {
5413 // FIXME: recurse?
5414 return TransformTypeSpecType(TLB, T);
5415}
5416
5417template <typename Derived>
5418QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
5419 AdjustedTypeLoc TL) {
5420 // Adjustments applied during transformation are handled elsewhere.
5421 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5422}
5423
5424template<typename Derived>
5425QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
5426 DecayedTypeLoc TL) {
5427 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5428 if (OriginalType.isNull())
5429 return QualType();
5430
5431 QualType Result = TL.getType();
5432 if (getDerived().AlwaysRebuild() ||
5433 OriginalType != TL.getOriginalLoc().getType())
5434 Result = SemaRef.Context.getDecayedType(OriginalType);
5435 TLB.push<DecayedTypeLoc>(Result);
5436 // Nothing to set for DecayedTypeLoc.
5437 return Result;
5438}
5439
5440template <typename Derived>
5441QualType
5442TreeTransform<Derived>::TransformArrayParameterType(TypeLocBuilder &TLB,
5443 ArrayParameterTypeLoc TL) {
5444 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5445 if (OriginalType.isNull())
5446 return QualType();
5447
5448 QualType Result = TL.getType();
5449 if (getDerived().AlwaysRebuild() ||
5450 OriginalType != TL.getElementLoc().getType())
5451 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5452 TLB.push<ArrayParameterTypeLoc>(Result);
5453 // Nothing to set for ArrayParameterTypeLoc.
5454 return Result;
5455}
5456
5457template<typename Derived>
5458QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
5459 PointerTypeLoc TL) {
5460 QualType PointeeType
5461 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5462 if (PointeeType.isNull())
5463 return QualType();
5464
5465 QualType Result = TL.getType();
5466 if (PointeeType->getAs<ObjCObjectType>()) {
5467 // A dependent pointer type 'T *' has is being transformed such
5468 // that an Objective-C class type is being replaced for 'T'. The
5469 // resulting pointer type is an ObjCObjectPointerType, not a
5470 // PointerType.
5471 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5472
5473 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5474 NewT.setStarLoc(TL.getStarLoc());
5475 return Result;
5476 }
5477
5478 if (getDerived().AlwaysRebuild() ||
5479 PointeeType != TL.getPointeeLoc().getType()) {
5480 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5481 if (Result.isNull())
5482 return QualType();
5483 }
5484
5485 // Objective-C ARC can add lifetime qualifiers to the type that we're
5486 // pointing to.
5487 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5488
5489 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5490 NewT.setSigilLoc(TL.getSigilLoc());
5491 return Result;
5492}
5493
5494template<typename Derived>
5495QualType
5496TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
5497 BlockPointerTypeLoc TL) {
5498 QualType PointeeType
5499 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5500 if (PointeeType.isNull())
5501 return QualType();
5502
5503 QualType Result = TL.getType();
5504 if (getDerived().AlwaysRebuild() ||
5505 PointeeType != TL.getPointeeLoc().getType()) {
5506 Result = getDerived().RebuildBlockPointerType(PointeeType,
5507 TL.getSigilLoc());
5508 if (Result.isNull())
5509 return QualType();
5510 }
5511
5512 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5513 NewT.setSigilLoc(TL.getSigilLoc());
5514 return Result;
5515}
5516
5517/// Transforms a reference type. Note that somewhat paradoxically we
5518/// don't care whether the type itself is an l-value type or an r-value
5519/// type; we only care if the type was *written* as an l-value type
5520/// or an r-value type.
5521template<typename Derived>
5522QualType
5524 ReferenceTypeLoc TL) {
5525 const ReferenceType *T = TL.getTypePtr();
5526
5527 // Note that this works with the pointee-as-written.
5528 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5529 if (PointeeType.isNull())
5530 return QualType();
5531
5532 QualType Result = TL.getType();
5533 if (getDerived().AlwaysRebuild() ||
5534 PointeeType != T->getPointeeTypeAsWritten()) {
5535 Result = getDerived().RebuildReferenceType(PointeeType,
5536 T->isSpelledAsLValue(),
5537 TL.getSigilLoc());
5538 if (Result.isNull())
5539 return QualType();
5540 }
5541
5542 // Objective-C ARC can add lifetime qualifiers to the type that we're
5543 // referring to.
5546
5547 // r-value references can be rebuilt as l-value references.
5548 ReferenceTypeLoc NewTL;
5549 if (isa<LValueReferenceType>(Result))
5550 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5551 else
5552 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5553 NewTL.setSigilLoc(TL.getSigilLoc());
5554
5555 return Result;
5556}
5557
5558template<typename Derived>
5562 return TransformReferenceType(TLB, TL);
5563}
5564
5565template<typename Derived>
5566QualType
5567TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5568 RValueReferenceTypeLoc TL) {
5569 return TransformReferenceType(TLB, TL);
5570}
5571
5572template<typename Derived>
5573QualType
5574TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5575 MemberPointerTypeLoc TL) {
5576 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5577 if (PointeeType.isNull())
5578 return QualType();
5579
5580 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
5581 TypeSourceInfo *NewClsTInfo = nullptr;
5582 if (OldClsTInfo) {
5583 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
5584 if (!NewClsTInfo)
5585 return QualType();
5586 }
5587
5588 const MemberPointerType *T = TL.getTypePtr();
5589 QualType OldClsType = QualType(T->getClass(), 0);
5590 QualType NewClsType;
5591 if (NewClsTInfo)
5592 NewClsType = NewClsTInfo->getType();
5593 else {
5594 NewClsType = getDerived().TransformType(OldClsType);
5595 if (NewClsType.isNull())
5596 return QualType();
5597 }
5598
5599 QualType Result = TL.getType();
5600 if (getDerived().AlwaysRebuild() ||
5601 PointeeType != T->getPointeeType() ||
5602 NewClsType != OldClsType) {
5603 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
5604 TL.getStarLoc());
5605 if (Result.isNull())
5606 return QualType();
5607 }
5608
5609 // If we had to adjust the pointee type when building a member pointer, make
5610 // sure to push TypeLoc info for it.
5611 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5612 if (MPT && PointeeType != MPT->getPointeeType()) {
5613 assert(isa<AdjustedType>(MPT->getPointeeType()));
5614 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5615 }
5616
5617 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
5618 NewTL.setSigilLoc(TL.getSigilLoc());
5619 NewTL.setClassTInfo(NewClsTInfo);
5620
5621 return Result;
5622}
5623
5624template<typename Derived>
5625QualType
5626TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
5627 ConstantArrayTypeLoc TL) {
5628 const ConstantArrayType *T = TL.getTypePtr();
5629 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5630 if (ElementType.isNull())
5631 return QualType();
5632
5633 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5634 Expr *OldSize = TL.getSizeExpr();
5635 if (!OldSize)
5636 OldSize = const_cast<Expr*>(T->getSizeExpr());
5637 Expr *NewSize = nullptr;
5638 if (OldSize) {
5639 EnterExpressionEvaluationContext Unevaluated(
5641 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5642 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5643 }
5644
5645 QualType Result = TL.getType();
5646 if (getDerived().AlwaysRebuild() ||
5647 ElementType != T->getElementType() ||
5648 (T->getSizeExpr() && NewSize != OldSize)) {
5649 Result = getDerived().RebuildConstantArrayType(ElementType,
5650 T->getSizeModifier(),
5651 T->getSize(), NewSize,
5652 T->getIndexTypeCVRQualifiers(),
5653 TL.getBracketsRange());
5654 if (Result.isNull())
5655 return QualType();
5656 }
5657
5658 // We might have either a ConstantArrayType or a VariableArrayType now:
5659 // a ConstantArrayType is allowed to have an element type which is a
5660 // VariableArrayType if the type is dependent. Fortunately, all array
5661 // types have the same location layout.
5662 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5663 NewTL.setLBracketLoc(TL.getLBracketLoc());
5664 NewTL.setRBracketLoc(TL.getRBracketLoc());
5665 NewTL.setSizeExpr(NewSize);
5666
5667 return Result;
5668}
5669
5670template<typename Derived>
5671QualType TreeTransform<Derived>::TransformIncompleteArrayType(
5672 TypeLocBuilder &TLB,
5673 IncompleteArrayTypeLoc TL) {
5674 const IncompleteArrayType *T = TL.getTypePtr();
5675 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5676 if (ElementType.isNull())
5677 return QualType();
5678
5679 QualType Result = TL.getType();
5680 if (getDerived().AlwaysRebuild() ||
5681 ElementType != T->getElementType()) {
5682 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5683 T->getSizeModifier(),
5684 T->getIndexTypeCVRQualifiers(),
5685 TL.getBracketsRange());
5686 if (Result.isNull())
5687 return QualType();
5688 }
5689
5690 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5691 NewTL.setLBracketLoc(TL.getLBracketLoc());
5692 NewTL.setRBracketLoc(TL.getRBracketLoc());
5693 NewTL.setSizeExpr(nullptr);
5694
5695 return Result;
5696}
5697
5698template<typename Derived>
5699QualType
5700TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
5701 VariableArrayTypeLoc TL) {
5702 const VariableArrayType *T = TL.getTypePtr();
5703 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5704 if (ElementType.isNull())
5705 return QualType();
5706
5707 ExprResult SizeResult;
5708 {
5709 EnterExpressionEvaluationContext Context(
5711 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5712 }
5713 if (SizeResult.isInvalid())
5714 return QualType();
5715 SizeResult =
5716 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5717 if (SizeResult.isInvalid())
5718 return QualType();
5719
5720 Expr *Size = SizeResult.get();
5721
5722 QualType Result = TL.getType();
5723 if (getDerived().AlwaysRebuild() ||
5724 ElementType != T->getElementType() ||
5725 Size != T->getSizeExpr()) {
5726 Result = getDerived().RebuildVariableArrayType(ElementType,
5727 T->getSizeModifier(),
5728 Size,
5729 T->getIndexTypeCVRQualifiers(),
5730 TL.getBracketsRange());
5731 if (Result.isNull())
5732 return QualType();
5733 }
5734
5735 // We might have constant size array now, but fortunately it has the same
5736 // location layout.
5737 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5738 NewTL.setLBracketLoc(TL.getLBracketLoc());
5739 NewTL.setRBracketLoc(TL.getRBracketLoc());
5740 NewTL.setSizeExpr(Size);
5741
5742 return Result;
5743}
5744
5745template<typename Derived>
5746QualType
5747TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
5748 DependentSizedArrayTypeLoc TL) {
5749 const DependentSizedArrayType *T = TL.getTypePtr();
5750 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5751 if (ElementType.isNull())
5752 return QualType();
5753
5754 // Array bounds are constant expressions.
5755 EnterExpressionEvaluationContext Unevaluated(
5757
5758 // If we have a VLA then it won't be a constant.
5759 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5760
5761 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5762 Expr *origSize = TL.getSizeExpr();
5763 if (!origSize) origSize = T->getSizeExpr();
5764
5765 ExprResult sizeResult
5766 = getDerived().TransformExpr(origSize);
5767 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5768 if (sizeResult.isInvalid())
5769 return QualType();
5770
5771 Expr *size = sizeResult.get();
5772
5773 QualType Result = TL.getType();
5774 if (getDerived().AlwaysRebuild() ||
5775 ElementType != T->getElementType() ||
5776 size != origSize) {
5777 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5778 T->getSizeModifier(),
5779 size,
5780 T->getIndexTypeCVRQualifiers(),
5781 TL.getBracketsRange());
5782 if (Result.isNull())
5783 return QualType();
5784 }
5785
5786 // We might have any sort of array type now, but fortunately they
5787 // all have the same location layout.
5788 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5789 NewTL.setLBracketLoc(TL.getLBracketLoc());
5790 NewTL.setRBracketLoc(TL.getRBracketLoc());
5791 NewTL.setSizeExpr(size);
5792
5793 return Result;
5794}
5795
5796template <typename Derived>
5797QualType TreeTransform<Derived>::TransformDependentVectorType(
5798 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
5799 const DependentVectorType *T = TL.getTypePtr();
5800 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5801 if (ElementType.isNull())
5802 return QualType();
5803
5804 EnterExpressionEvaluationContext Unevaluated(
5806
5807 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5808 Size = SemaRef.ActOnConstantExpression(Size);
5809 if (Size.isInvalid())
5810 return QualType();
5811
5812 QualType Result = TL.getType();
5813 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5814 Size.get() != T->getSizeExpr()) {
5815 Result = getDerived().RebuildDependentVectorType(
5816 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5817 if (Result.isNull())
5818 return QualType();
5819 }
5820
5821 // Result might be dependent or not.
5822 if (isa<DependentVectorType>(Result)) {
5823 DependentVectorTypeLoc NewTL =
5824 TLB.push<DependentVectorTypeLoc>(Result);
5825 NewTL.setNameLoc(TL.getNameLoc());
5826 } else {
5827 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5828 NewTL.setNameLoc(TL.getNameLoc());
5829 }
5830
5831 return Result;
5832}
5833
5834template<typename Derived>
5835QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
5836 TypeLocBuilder &TLB,
5837 DependentSizedExtVectorTypeLoc TL) {
5838 const DependentSizedExtVectorType *T = TL.getTypePtr();
5839
5840 // FIXME: ext vector locs should be nested
5841 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5842 if (ElementType.isNull())
5843 return QualType();
5844
5845 // Vector sizes are constant expressions.
5846 EnterExpressionEvaluationContext Unevaluated(
5848
5849 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5850 Size = SemaRef.ActOnConstantExpression(Size);
5851 if (Size.isInvalid())
5852 return QualType();
5853
5854 QualType Result = TL.getType();
5855 if (getDerived().AlwaysRebuild() ||
5856 ElementType != T->getElementType() ||
5857 Size.get() != T->getSizeExpr()) {
5858 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5859 Size.get(),
5860 T->getAttributeLoc());
5861 if (Result.isNull())
5862 return QualType();
5863 }
5864
5865 // Result might be dependent or not.
5866 if (isa<DependentSizedExtVectorType>(Result)) {
5867 DependentSizedExtVectorTypeLoc NewTL
5868 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
5869 NewTL.setNameLoc(TL.getNameLoc());
5870 } else {
5871 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5872 NewTL.setNameLoc(TL.getNameLoc());
5873 }
5874
5875 return Result;
5876}
5877
5878template <typename Derived>
5879QualType
5880TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
5881 ConstantMatrixTypeLoc TL) {
5882 const ConstantMatrixType *T = TL.getTypePtr();
5883 QualType ElementType = getDerived().TransformType(T->getElementType());
5884 if (ElementType.isNull())
5885 return QualType();
5886
5887 QualType Result = TL.getType();
5888 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
5889 Result = getDerived().RebuildConstantMatrixType(
5890 ElementType, T->getNumRows(), T->getNumColumns());
5891 if (Result.isNull())
5892 return QualType();
5893 }
5894
5895 ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
5896 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5897 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5898 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
5899 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
5900
5901 return Result;
5902}
5903
5904template <typename Derived>
5905QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
5906 TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
5907 const DependentSizedMatrixType *T = TL.getTypePtr();
5908
5909 QualType ElementType = getDerived().TransformType(T->getElementType());
5910 if (ElementType.isNull()) {
5911 return QualType();
5912 }
5913
5914 // Matrix dimensions are constant expressions.
5915 EnterExpressionEvaluationContext Unevaluated(
5917
5918 Expr *origRows = TL.getAttrRowOperand();
5919 if (!origRows)
5920 origRows = T->getRowExpr();
5921 Expr *origColumns = TL.getAttrColumnOperand();
5922 if (!origColumns)
5923 origColumns = T->getColumnExpr();
5924
5925 ExprResult rowResult = getDerived().TransformExpr(origRows);
5926 rowResult = SemaRef.ActOnConstantExpression(rowResult);
5927 if (rowResult.isInvalid())
5928 return QualType();
5929
5930 ExprResult columnResult = getDerived().TransformExpr(origColumns);
5931 columnResult = SemaRef.ActOnConstantExpression(columnResult);
5932 if (columnResult.isInvalid())
5933 return QualType();
5934
5935 Expr *rows = rowResult.get();
5936 Expr *columns = columnResult.get();
5937
5938 QualType Result = TL.getType();
5939 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5940 rows != origRows || columns != origColumns) {
5941 Result = getDerived().RebuildDependentSizedMatrixType(
5942 ElementType, rows, columns, T->getAttributeLoc());
5943
5944 if (Result.isNull())
5945 return QualType();
5946 }
5947
5948 // We might have any sort of matrix type now, but fortunately they
5949 // all have the same location layout.
5950 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
5951 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5952 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5953 NewTL.setAttrRowOperand(rows);
5954 NewTL.setAttrColumnOperand(columns);
5955 return Result;
5956}
5957
5958template <typename Derived>
5959QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
5960 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
5961 const DependentAddressSpaceType *T = TL.getTypePtr();
5962
5963 QualType pointeeType =
5964 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
5965
5966 if (pointeeType.isNull())
5967 return QualType();
5968
5969 // Address spaces are constant expressions.
5970 EnterExpressionEvaluationContext Unevaluated(
5972
5973 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
5974 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
5975 if (AddrSpace.isInvalid())
5976 return QualType();
5977
5978 QualType Result = TL.getType();
5979 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
5980 AddrSpace.get() != T->getAddrSpaceExpr()) {
5981 Result = getDerived().RebuildDependentAddressSpaceType(
5982 pointeeType, AddrSpace.get(), T->getAttributeLoc());
5983 if (Result.isNull())
5984 return QualType();
5985 }
5986
5987 // Result might be dependent or not.
5988 if (isa<DependentAddressSpaceType>(Result)) {
5989 DependentAddressSpaceTypeLoc NewTL =
5990 TLB.push<DependentAddressSpaceTypeLoc>(Result);
5991
5992 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5993 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5994 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5995
5996 } else {
5997 TLB.TypeWasModifiedSafely(Result);
5998 }
5999
6000 return Result;
6001}
6002
6003template <typename Derived>
6004QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
6005 VectorTypeLoc TL) {
6006 const VectorType *T = TL.getTypePtr();
6007 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6008 if (ElementType.isNull())
6009 return QualType();
6010
6011 QualType Result = TL.getType();
6012 if (getDerived().AlwaysRebuild() ||
6013 ElementType != T->getElementType()) {
6014 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6015 T->getVectorKind());
6016 if (Result.isNull())
6017 return QualType();
6018 }
6019
6020 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6021 NewTL.setNameLoc(TL.getNameLoc());
6022
6023 return Result;
6024}
6025
6026template<typename Derived>
6027QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
6028 ExtVectorTypeLoc TL) {
6029 const VectorType *T = TL.getTypePtr();
6030 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6031 if (ElementType.isNull())
6032 return QualType();
6033
6034 QualType Result = TL.getType();
6035 if (getDerived().AlwaysRebuild() ||
6036 ElementType != T->getElementType()) {
6037 Result = getDerived().RebuildExtVectorType(ElementType,
6038 T->getNumElements(),
6039 /*FIXME*/ SourceLocation());
6040 if (Result.isNull())
6041 return QualType();
6042 }
6043
6044 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6045 NewTL.setNameLoc(TL.getNameLoc());
6046
6047 return Result;
6048}
6049
6050template <typename Derived>
6052 ParmVarDecl *OldParm, int indexAdjustment,
6053 std::optional<unsigned> NumExpansions, bool ExpectParameterPack) {
6054 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
6055 TypeSourceInfo *NewDI = nullptr;
6056
6057 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
6058 // If we're substituting into a pack expansion type and we know the
6059 // length we want to expand to, just substitute for the pattern.
6060 TypeLoc OldTL = OldDI->getTypeLoc();
6061 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6062
6063 TypeLocBuilder TLB;
6064 TypeLoc NewTL = OldDI->getTypeLoc();
6065 TLB.reserve(NewTL.getFullDataSize());
6066
6067 QualType Result = getDerived().TransformType(TLB,
6068 OldExpansionTL.getPatternLoc());
6069 if (Result.isNull())
6070 return nullptr;
6071
6072 Result = RebuildPackExpansionType(Result,
6073 OldExpansionTL.getPatternLoc().getSourceRange(),
6074 OldExpansionTL.getEllipsisLoc(),
6075 NumExpansions);
6076 if (Result.isNull())
6077 return nullptr;
6078
6079 PackExpansionTypeLoc NewExpansionTL
6080 = TLB.push<PackExpansionTypeLoc>(Result);
6081 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6082 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6083 } else
6084 NewDI = getDerived().TransformType(OldDI);
6085 if (!NewDI)
6086 return nullptr;
6087
6088 if (NewDI == OldDI && indexAdjustment == 0)
6089 return OldParm;
6090
6091 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
6092 OldParm->getDeclContext(),
6093 OldParm->getInnerLocStart(),
6094 OldParm->getLocation(),
6095 OldParm->getIdentifier(),
6096 NewDI->getType(),
6097 NewDI,
6098 OldParm->getStorageClass(),
6099 /* DefArg */ nullptr);
6100 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6101 OldParm->getFunctionScopeIndex() + indexAdjustment);
6102 transformedLocalDecl(OldParm, {newParm});
6103 return newParm;
6104}
6105
6106template <typename Derived>
6109 const QualType *ParamTypes,
6110 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6111 SmallVectorImpl<QualType> &OutParamTypes,
6114 unsigned *LastParamTransformed) {
6115 int indexAdjustment = 0;
6116
6117 unsigned NumParams = Params.size();
6118 for (unsigned i = 0; i != NumParams; ++i) {
6119 if (LastParamTransformed)
6120 *LastParamTransformed = i;
6121 if (ParmVarDecl *OldParm = Params[i]) {
6122 assert(OldParm->getFunctionScopeIndex() == i);
6123
6124 std::optional<unsigned> NumExpansions;
6125 ParmVarDecl *NewParm = nullptr;
6126 if (OldParm->isParameterPack()) {
6127 // We have a function parameter pack that may need to be expanded.
6129
6130 // Find the parameter packs that could be expanded.
6131 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6133 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6134 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6135
6136 // Determine whether we should expand the parameter packs.
6137 bool ShouldExpand = false;
6138 bool RetainExpansion = false;
6139 std::optional<unsigned> OrigNumExpansions;
6140 if (Unexpanded.size() > 0) {
6141 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6142 NumExpansions = OrigNumExpansions;
6143 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
6144 Pattern.getSourceRange(),
6145 Unexpanded,
6146 ShouldExpand,
6147 RetainExpansion,
6148 NumExpansions)) {
6149 return true;
6150 }
6151 } else {
6152#ifndef NDEBUG
6153 const AutoType *AT =
6154 Pattern.getType().getTypePtr()->getContainedAutoType();
6155 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6156 "Could not find parameter packs or undeduced auto type!");
6157#endif
6158 }
6159
6160 if (ShouldExpand) {
6161 // Expand the function parameter pack into multiple, separate
6162 // parameters.
6163 getDerived().ExpandingFunctionParameterPack(OldParm);
6164 for (unsigned I = 0; I != *NumExpansions; ++I) {
6165 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6166 ParmVarDecl *NewParm
6167 = getDerived().TransformFunctionTypeParam(OldParm,
6168 indexAdjustment++,
6169 OrigNumExpansions,
6170 /*ExpectParameterPack=*/false);
6171 if (!NewParm)
6172 return true;
6173
6174 if (ParamInfos)
6175 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6176 OutParamTypes.push_back(NewParm->getType());
6177 if (PVars)
6178 PVars->push_back(NewParm);
6179 }
6180
6181 // If we're supposed to retain a pack expansion, do so by temporarily
6182 // forgetting the partially-substituted parameter pack.
6183 if (RetainExpansion) {
6184 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6185 ParmVarDecl *NewParm
6186 = getDerived().TransformFunctionTypeParam(OldParm,
6187 indexAdjustment++,
6188 OrigNumExpansions,
6189 /*ExpectParameterPack=*/false);
6190 if (!NewParm)
6191 return true;
6192
6193 if (ParamInfos)
6194 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6195 OutParamTypes.push_back(NewParm->getType());
6196 if (PVars)
6197 PVars->push_back(NewParm);
6198 }
6199
6200 // The next parameter should have the same adjustment as the
6201 // last thing we pushed, but we post-incremented indexAdjustment
6202 // on every push. Also, if we push nothing, the adjustment should
6203 // go down by one.
6204 indexAdjustment--;
6205
6206 // We're done with the pack expansion.
6207 continue;
6208 }
6209
6210 // We'll substitute the parameter now without expanding the pack
6211 // expansion.
6212 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6213 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6214 indexAdjustment,
6215 NumExpansions,
6216 /*ExpectParameterPack=*/true);
6217 assert(NewParm->isParameterPack() &&
6218 "Parameter pack no longer a parameter pack after "
6219 "transformation.");
6220 } else {
6221 NewParm = getDerived().TransformFunctionTypeParam(
6222 OldParm, indexAdjustment, std::nullopt,
6223 /*ExpectParameterPack=*/false);
6224 }
6225
6226 if (!NewParm)
6227 return true;
6228
6229 if (ParamInfos)
6230 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6231 OutParamTypes.push_back(NewParm->getType());
6232 if (PVars)
6233 PVars->push_back(NewParm);
6234 continue;
6235 }
6236
6237 // Deal with the possibility that we don't have a parameter
6238 // declaration for this parameter.
6239 assert(ParamTypes);
6240 QualType OldType = ParamTypes[i];
6241 bool IsPackExpansion = false;
6242 std::optional<unsigned> NumExpansions;
6243 QualType NewType;
6244 if (const PackExpansionType *Expansion
6245 = dyn_cast<PackExpansionType>(OldType)) {
6246 // We have a function parameter pack that may need to be expanded.
6247 QualType Pattern = Expansion->getPattern();
6249 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6250
6251 // Determine whether we should expand the parameter packs.
6252 bool ShouldExpand = false;
6253 bool RetainExpansion = false;
6254 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
6255 Unexpanded,
6256 ShouldExpand,
6257 RetainExpansion,
6258 NumExpansions)) {
6259 return true;
6260 }
6261
6262 if (ShouldExpand) {
6263 // Expand the function parameter pack into multiple, separate
6264 // parameters.
6265 for (unsigned I = 0; I != *NumExpansions; ++I) {
6266 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6267 QualType NewType = getDerived().TransformType(Pattern);
6268 if (NewType.isNull())
6269 return true;
6270
6271 if (NewType->containsUnexpandedParameterPack()) {
6272 NewType = getSema().getASTContext().getPackExpansionType(
6273 NewType, std::nullopt);
6274
6275 if (NewType.isNull())
6276 return true;
6277 }
6278
6279 if (ParamInfos)
6280 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6281 OutParamTypes.push_back(NewType);
6282 if (PVars)
6283 PVars->push_back(nullptr);
6284 }
6285
6286 // We're done with the pack expansion.
6287 continue;
6288 }
6289
6290 // If we're supposed to retain a pack expansion, do so by temporarily
6291 // forgetting the partially-substituted parameter pack.
6292 if (RetainExpansion) {
6293 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6294 QualType NewType = getDerived().TransformType(Pattern);
6295 if (NewType.isNull())
6296 return true;
6297
6298 if (ParamInfos)
6299 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6300 OutParamTypes.push_back(NewType);
6301 if (PVars)
6302 PVars->push_back(nullptr);
6303 }
6304
6305 // We'll substitute the parameter now without expanding the pack
6306 // expansion.
6307 OldType = Expansion->getPattern();
6308 IsPackExpansion = true;
6309 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6310 NewType = getDerived().TransformType(OldType);
6311 } else {
6312 NewType = getDerived().TransformType(OldType);
6313 }
6314
6315 if (NewType.isNull())
6316 return true;
6317
6318 if (IsPackExpansion)
6319 NewType = getSema().Context.getPackExpansionType(NewType,
6320 NumExpansions);
6321
6322 if (ParamInfos)
6323 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6324 OutParamTypes.push_back(NewType);
6325 if (PVars)
6326 PVars->push_back(nullptr);
6327 }
6328
6329#ifndef NDEBUG
6330 if (PVars) {
6331 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6332 if (ParmVarDecl *parm = (*PVars)[i])
6333 assert(parm->getFunctionScopeIndex() == i);
6334 }
6335#endif
6336
6337 return false;
6338}
6339
6340template<typename Derived>
6344 SmallVector<QualType, 4> ExceptionStorage;
6345 return getDerived().TransformFunctionProtoType(
6346 TLB, TL, nullptr, Qualifiers(),
6347 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6348 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6349 ExceptionStorage, Changed);
6350 });
6351}
6352
6353template<typename Derived> template<typename Fn>
6355 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6356 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6357
6358 // Transform the parameters and return type.
6359 //
6360 // We are required to instantiate the params and return type in source order.
6361 // When the function has a trailing return type, we instantiate the
6362 // parameters before the return type, since the return type can then refer
6363 // to the parameters themselves (via decltype, sizeof, etc.).
6364 //
6365 SmallVector<QualType, 4> ParamTypes;
6367 Sema::ExtParameterInfoBuilder ExtParamInfos;
6368 const FunctionProtoType *T = TL.getTypePtr();
6369
6370 QualType ResultType;
6371
6372 if (T->hasTrailingReturn()) {
6373 if (getDerived().TransformFunctionTypeParams(
6374 TL.getBeginLoc(), TL.getParams(),
6377 ParamTypes, &ParamDecls, ExtParamInfos))
6378 return QualType();
6379
6380 {
6381 // C++11 [expr.prim.general]p3:
6382 // If a declaration declares a member function or member function
6383 // template of a class X, the expression this is a prvalue of type
6384 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6385 // and the end of the function-definition, member-declarator, or
6386 // declarator.
6387 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6388 Sema::CXXThisScopeRAII ThisScope(
6389 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6390
6391 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6392 if (ResultType.isNull())
6393 return QualType();
6394 }
6395 }
6396 else {
6397 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6398 if (ResultType.isNull())
6399 return QualType();
6400
6401 if (getDerived().TransformFunctionTypeParams(
6402 TL.getBeginLoc(), TL.getParams(),
6405 ParamTypes, &ParamDecls, ExtParamInfos))
6406 return QualType();
6407 }
6408
6410
6411 bool EPIChanged = false;
6412 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6413 return QualType();
6414
6415 // Handle extended parameter information.
6416 if (auto NewExtParamInfos =
6417 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6418 if (!EPI.ExtParameterInfos ||
6420 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6421 EPIChanged = true;
6422 }
6423 EPI.ExtParameterInfos = NewExtParamInfos;
6424 } else if (EPI.ExtParameterInfos) {
6425 EPIChanged = true;
6426 EPI.ExtParameterInfos = nullptr;
6427 }
6428
6429 // Transform any function effects with unevaluated conditions.
6430 // Hold this set in a local for the rest of this function, since EPI
6431 // may need to hold a FunctionEffectsRef pointing into it.
6432 std::optional<FunctionEffectSet> NewFX;
6433 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6434 NewFX.emplace();
6437
6438 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6439 FunctionEffectWithCondition NewEC = PrevEC;
6440 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6441 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6442 if (NewExpr.isInvalid())
6443 return QualType();
6444 std::optional<FunctionEffectMode> Mode =
6445 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6446 if (!Mode)
6447 return QualType();
6448
6449 // The condition expression has been transformed, and re-evaluated.
6450 // It may or may not have become constant.
6451 switch (*Mode) {
6453 NewEC.Cond = {};
6454 break;
6456 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6457 NewEC.Cond = {};
6458 break;
6460 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6461 break;
6463 llvm_unreachable(
6464 "FunctionEffectMode::None shouldn't be possible here");
6465 }
6466 }
6467 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6468 TL.getBeginLoc())) {
6470 NewFX->insert(NewEC, Errs);
6471 assert(Errs.empty());
6472 }
6473 }
6474 EPI.FunctionEffects = *NewFX;
6475 EPIChanged = true;
6476 }
6477
6478 QualType Result = TL.getType();
6479 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6480 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6481 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6482 if (Result.isNull())
6483 return QualType();
6484 }
6485
6488 NewTL.setLParenLoc(TL.getLParenLoc());
6489 NewTL.setRParenLoc(TL.getRParenLoc());
6492 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6493 NewTL.setParam(i, ParamDecls[i]);
6494
6495 return Result;
6496}
6497
6498template<typename Derived>
6501 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6502 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6503
6504 // Instantiate a dynamic noexcept expression, if any.
6505 if (isComputedNoexcept(ESI.Type)) {
6506 // Update this scrope because ContextDecl in Sema will be used in
6507 // TransformExpr.
6508 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6509 Sema::CXXThisScopeRAII ThisScope(
6510 SemaRef, Method ? Method->getParent() : nullptr,
6511 Method ? Method->getMethodQualifiers() : Qualifiers{},
6512 Method != nullptr);
6515 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6516 if (NoexceptExpr.isInvalid())
6517 return true;
6518
6520 NoexceptExpr =
6521 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6522 if (NoexceptExpr.isInvalid())
6523 return true;
6524
6525 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6526 Changed = true;
6527 ESI.NoexceptExpr = NoexceptExpr.get();
6528 ESI.Type = EST;
6529 }
6530
6531 if (ESI.Type != EST_Dynamic)
6532 return false;
6533
6534 // Instantiate a dynamic exception specification's type.
6535 for (QualType T : ESI.Exceptions) {
6536 if (const PackExpansionType *PackExpansion =
6538 Changed = true;
6539
6540 // We have a pack expansion. Instantiate it.
6542 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6543 Unexpanded);
6544 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6545
6546 // Determine whether the set of unexpanded parameter packs can and
6547 // should
6548 // be expanded.
6549 bool Expand = false;
6550 bool RetainExpansion = false;
6551 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6552 // FIXME: Track the location of the ellipsis (and track source location
6553 // information for the types in the exception specification in general).
6554 if (getDerived().TryExpandParameterPacks(
6555 Loc, SourceRange(), Unexpanded, Expand,
6556 RetainExpansion, NumExpansions))
6557 return true;
6558
6559 if (!Expand) {
6560 // We can't expand this pack expansion into separate arguments yet;
6561 // just substitute into the pattern and create a new pack expansion
6562 // type.
6563 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6564 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6565 if (U.isNull())
6566 return true;
6567
6568 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6569 Exceptions.push_back(U);
6570 continue;
6571 }
6572
6573 // Substitute into the pack expansion pattern for each slice of the
6574 // pack.
6575 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6576 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6577
6578 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6579 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6580 return true;
6581
6582 Exceptions.push_back(U);
6583 }
6584 } else {
6585 QualType U = getDerived().TransformType(T);
6586 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6587 return true;
6588 if (T != U)
6589 Changed = true;
6590
6591 Exceptions.push_back(U);
6592 }
6593 }
6594
6595 ESI.Exceptions = Exceptions;
6596 if (ESI.Exceptions.empty())
6597 ESI.Type = EST_DynamicNone;
6598 return false;
6599}
6600
6601template<typename Derived>
6603 TypeLocBuilder &TLB,
6605 const FunctionNoProtoType *T = TL.getTypePtr();
6606 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6607 if (ResultType.isNull())
6608 return QualType();
6609
6610 QualType Result = TL.getType();
6611 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6612 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6613
6616 NewTL.setLParenLoc(TL.getLParenLoc());
6617 NewTL.setRParenLoc(TL.getRParenLoc());
6619
6620 return Result;
6621}
6622
6623template <typename Derived>
6624QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6625 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6626 const UnresolvedUsingType *T = TL.getTypePtr();
6627 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6628 if (!D)
6629 return QualType();
6630
6631 QualType Result = TL.getType();
6632 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
6633 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
6634 if (Result.isNull())
6635 return QualType();
6636 }
6637
6638 // We might get an arbitrary type spec type back. We should at
6639 // least always get a type spec type, though.
6640 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
6641 NewTL.setNameLoc(TL.getNameLoc());
6642
6643 return Result;
6644}
6645
6646template <typename Derived>
6647QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
6648 UsingTypeLoc TL) {
6649 const UsingType *T = TL.getTypePtr();
6650
6651 auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl(
6652 TL.getLocalSourceRange().getBegin(), T->getFoundDecl()));
6653 if (!Found)
6654 return QualType();
6655
6656 QualType Underlying = getDerived().TransformType(T->desugar());
6657 if (Underlying.isNull())
6658 return QualType();
6659
6660 QualType Result = TL.getType();
6661 if (getDerived().AlwaysRebuild() || Found != T->getFoundDecl() ||
6662 Underlying != T->getUnderlyingType()) {
6663 Result = getDerived().RebuildUsingType(Found, Underlying);
6664 if (Result.isNull())
6665 return QualType();
6666 }
6667
6668 TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc());
6669 return Result;
6670}
6671
6672template<typename Derived>
6673QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
6674 TypedefTypeLoc TL) {
6675 const TypedefType *T = TL.getTypePtr();
6676 TypedefNameDecl *Typedef
6677 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6678 T->getDecl()));
6679 if (!Typedef)
6680 return QualType();
6681
6682 QualType Result = TL.getType();
6683 if (getDerived().AlwaysRebuild() ||
6684 Typedef != T->getDecl()) {
6685 Result = getDerived().RebuildTypedefType(Typedef);
6686 if (Result.isNull())
6687 return QualType();
6688 }
6689
6690 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
6691 NewTL.setNameLoc(TL.getNameLoc());
6692
6693 return Result;
6694}
6695
6696template<typename Derived>
6697QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
6698 TypeOfExprTypeLoc TL) {
6699 // typeof expressions are not potentially evaluated contexts
6700 EnterExpressionEvaluationContext Unevaluated(
6703
6704 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6705 if (E.isInvalid())
6706 return QualType();
6707
6708 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6709 if (E.isInvalid())
6710 return QualType();
6711
6712 QualType Result = TL.getType();
6713 TypeOfKind Kind = Result->castAs<TypeOfExprType>()->getKind();
6714 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6715 Result =
6716 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6717 if (Result.isNull())
6718 return QualType();
6719 }
6720
6721 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6722 NewTL.setTypeofLoc(TL.getTypeofLoc());
6723 NewTL.setLParenLoc(TL.getLParenLoc());
6724 NewTL.setRParenLoc(TL.getRParenLoc());
6725
6726 return Result;
6727}
6728
6729template<typename Derived>
6730QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
6731 TypeOfTypeLoc TL) {
6732 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6733 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6734 if (!New_Under_TI)
6735 return QualType();
6736
6737 QualType Result = TL.getType();
6738 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6739 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6740 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6741 if (Result.isNull())
6742 return QualType();
6743 }
6744
6745 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6746 NewTL.setTypeofLoc(TL.getTypeofLoc());
6747 NewTL.setLParenLoc(TL.getLParenLoc());
6748 NewTL.setRParenLoc(TL.getRParenLoc());
6749 NewTL.setUnmodifiedTInfo(New_Under_TI);
6750
6751 return Result;
6752}
6753
6754template<typename Derived>
6755QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
6756 DecltypeTypeLoc TL) {
6757 const DecltypeType *T = TL.getTypePtr();
6758
6759 // decltype expressions are not potentially evaluated contexts
6760 EnterExpressionEvaluationContext Unevaluated(
6763
6764 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6765 if (E.isInvalid())
6766 return QualType();
6767
6768 E = getSema().ActOnDecltypeExpression(E.get());
6769 if (E.isInvalid())
6770 return QualType();
6771
6772 QualType Result = TL.getType();
6773 if (getDerived().AlwaysRebuild() ||
6774 E.get() != T->getUnderlyingExpr()) {
6775 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6776 if (Result.isNull())
6777 return QualType();
6778 }
6779 else E.get();
6780
6781 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6782 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6783 NewTL.setRParenLoc(TL.getRParenLoc());
6784 return Result;
6785}
6786
6787template <typename Derived>
6788QualType
6789TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
6790 PackIndexingTypeLoc TL) {
6791 // Transform the index
6792 ExprResult IndexExpr;
6793 {
6794 EnterExpressionEvaluationContext ConstantContext(
6796
6797 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6798 if (IndexExpr.isInvalid())
6799 return QualType();
6800 }
6801 QualType Pattern = TL.getPattern();
6802
6803 const PackIndexingType *PIT = TL.getTypePtr();
6804 SmallVector<QualType, 5> SubtitutedTypes;
6805 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6806
6807 bool NotYetExpanded = Types.empty();
6808 bool FullySubstituted = true;
6809
6810 if (Types.empty() && !PIT->expandsToEmptyPack())
6811 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
6812
6813 for (QualType T : Types) {
6815 QualType Transformed = getDerived().TransformType(T);
6816 if (Transformed.isNull())
6817 return QualType();
6818 SubtitutedTypes.push_back(Transformed);
6819 continue;
6820 }
6821
6823 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
6824 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6825 // Determine whether the set of unexpanded parameter packs can and should
6826 // be expanded.
6827 bool ShouldExpand = true;
6828 bool RetainExpansion = false;
6829 std::optional<unsigned> OrigNumExpansions;
6830 std::optional<unsigned> NumExpansions = OrigNumExpansions;
6831 if (getDerived().TryExpandParameterPacks(TL.getEllipsisLoc(), SourceRange(),
6832 Unexpanded, ShouldExpand,
6833 RetainExpansion, NumExpansions))
6834 return QualType();
6835 if (!ShouldExpand) {
6836 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6837 // FIXME: should we keep TypeLoc for individual expansions in
6838 // PackIndexingTypeLoc?
6839 TypeSourceInfo *TI =
6840 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
6841 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
6842 if (Pack.isNull())
6843 return QualType();
6844 if (NotYetExpanded) {
6845 FullySubstituted = false;
6846 QualType Out = getDerived().RebuildPackIndexingType(
6847 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6848 FullySubstituted);
6849 if (Out.isNull())
6850 return QualType();
6851
6852 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6853 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6854 return Out;
6855 }
6856 SubtitutedTypes.push_back(Pack);
6857 continue;
6858 }
6859 for (unsigned I = 0; I != *NumExpansions; ++I) {
6860 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6861 QualType Out = getDerived().TransformType(T);
6862 if (Out.isNull())
6863 return QualType();
6864 SubtitutedTypes.push_back(Out);
6865 FullySubstituted &= !Out->containsUnexpandedParameterPack();
6866 }
6867 // If we're supposed to retain a pack expansion, do so by temporarily
6868 // forgetting the partially-substituted parameter pack.
6869 if (RetainExpansion) {
6870 FullySubstituted = false;
6871 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6872 QualType Out = getDerived().TransformType(T);
6873 if (Out.isNull())
6874 return QualType();
6875 SubtitutedTypes.push_back(Out);
6876 }
6877 }
6878
6879 // A pack indexing type can appear in a larger pack expansion,
6880 // e.g. `Pack...[pack_of_indexes]...`
6881 // so we need to temporarily disable substitution of pack elements
6882 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6883 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
6884
6885 QualType Out = getDerived().RebuildPackIndexingType(
6886 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6887 FullySubstituted, SubtitutedTypes);
6888 if (Out.isNull())
6889 return Out;
6890
6891 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6892 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6893 return Out;
6894}
6895
6896template<typename Derived>
6897QualType TreeTransform<Derived>::TransformUnaryTransformType(
6898 TypeLocBuilder &TLB,
6899 UnaryTransformTypeLoc TL) {
6900 QualType Result = TL.getType();
6901 if (Result->isDependentType()) {
6902 const UnaryTransformType *T = TL.getTypePtr();
6903
6904 TypeSourceInfo *NewBaseTSI =
6905 getDerived().TransformType(TL.getUnderlyingTInfo());
6906 if (!NewBaseTSI)
6907 return QualType();
6908 QualType NewBase = NewBaseTSI->getType();
6909
6910 Result = getDerived().RebuildUnaryTransformType(NewBase,
6911 T->getUTTKind(),
6912 TL.getKWLoc());
6913 if (Result.isNull())
6914 return QualType();
6915 }
6916
6917 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
6918 NewTL.setKWLoc(TL.getKWLoc());
6919 NewTL.setParensRange(TL.getParensRange());
6920 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
6921 return Result;
6922}
6923
6924template<typename Derived>
6925QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
6926 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
6927 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
6928
6929 CXXScopeSpec SS;
6930 TemplateName TemplateName = getDerived().TransformTemplateName(
6931 SS, T->getTemplateName(), TL.getTemplateNameLoc());
6932 if (TemplateName.isNull())
6933 return QualType();
6934
6935 QualType OldDeduced = T->getDeducedType();
6936 QualType NewDeduced;
6937 if (!OldDeduced.isNull()) {
6938 NewDeduced = getDerived().TransformType(OldDeduced);
6939 if (NewDeduced.isNull())
6940 return QualType();
6941 }
6942
6943 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
6944 TemplateName, NewDeduced);
6945 if (Result.isNull())
6946 return QualType();
6947
6948 DeducedTemplateSpecializationTypeLoc NewTL =
6949 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
6950 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6951
6952 return Result;
6953}
6954
6955template<typename Derived>
6956QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
6957 RecordTypeLoc TL) {
6958 const RecordType *T = TL.getTypePtr();
6959 RecordDecl *Record
6960 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6961 T->getDecl()));
6962 if (!Record)
6963 return QualType();
6964
6965 QualType Result = TL.getType();
6966 if (getDerived().AlwaysRebuild() ||
6967 Record != T->getDecl()) {
6968 Result = getDerived().RebuildRecordType(Record);
6969 if (Result.isNull())
6970 return QualType();
6971 }
6972
6973 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
6974 NewTL.setNameLoc(TL.getNameLoc());
6975
6976 return Result;
6977}
6978
6979template<typename Derived>
6980QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
6981 EnumTypeLoc TL) {
6982 const EnumType *T = TL.getTypePtr();
6983 EnumDecl *Enum
6984 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6985 T->getDecl()));
6986 if (!Enum)
6987 return QualType();
6988
6989 QualType Result = TL.getType();
6990 if (getDerived().AlwaysRebuild() ||
6991 Enum != T->getDecl()) {
6992 Result = getDerived().RebuildEnumType(Enum);
6993 if (Result.isNull())
6994 return QualType();
6995 }
6996
6997 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
6998 NewTL.setNameLoc(TL.getNameLoc());
6999
7000 return Result;
7001}
7002
7003template<typename Derived>
7004QualType TreeTransform<Derived>::TransformInjectedClassNameType(
7005 TypeLocBuilder &TLB,
7006 InjectedClassNameTypeLoc TL) {
7007 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
7008 TL.getTypePtr()->getDecl());
7009 if (!D) return QualType();
7010
7011 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
7012 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
7013 return T;
7014}
7015
7016template<typename Derived>
7018 TypeLocBuilder &TLB,
7020 return getDerived().TransformTemplateTypeParmType(
7021 TLB, TL,
7022 /*SuppressObjCLifetime=*/false);
7023}
7024
7025template <typename Derived>
7027 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7028 return TransformTypeSpecType(TLB, TL);
7029}
7030
7031template<typename Derived>
7032QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7033 TypeLocBuilder &TLB,
7034 SubstTemplateTypeParmTypeLoc TL) {
7035 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7036
7037 Decl *NewReplaced =
7038 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7039
7040 // Substitute into the replacement type, which itself might involve something
7041 // that needs to be transformed. This only tends to occur with default
7042 // template arguments of template template parameters.
7043 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7044 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7045 if (Replacement.isNull())
7046 return QualType();
7047
7048 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7049 Replacement, NewReplaced, T->getIndex(), T->getPackIndex());
7050
7051 // Propagate type-source information.
7052 SubstTemplateTypeParmTypeLoc NewTL
7053 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7054 NewTL.setNameLoc(TL.getNameLoc());
7055 return Result;
7056
7057}
7058
7059template<typename Derived>
7061 TypeLocBuilder &TLB,
7063 return getDerived().TransformSubstTemplateTypeParmPackType(
7064 TLB, TL, /*SuppressObjCLifetime=*/false);
7065}
7066
7067template <typename Derived>
7070 return TransformTypeSpecType(TLB, TL);
7071}
7072
7073template<typename Derived>
7075 TypeLocBuilder &TLB,
7078
7079 // The nested-name-specifier never matters in a TemplateSpecializationType,
7080 // because we can't have a dependent nested-name-specifier anyway.
7081 CXXScopeSpec SS;
7082 TemplateName Template
7083 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
7084 TL.getTemplateNameLoc());
7085 if (Template.isNull())
7086 return QualType();
7087
7088 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
7089}
7090
7091template<typename Derived>
7093 AtomicTypeLoc TL) {
7094 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7095 if (ValueType.isNull())
7096 return QualType();
7097
7098 QualType Result = TL.getType();
7099 if (getDerived().AlwaysRebuild() ||
7100 ValueType != TL.getValueLoc().getType()) {
7101 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7102 if (Result.isNull())
7103 return QualType();
7104 }
7105
7106 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7107 NewTL.setKWLoc(TL.getKWLoc());
7108 NewTL.setLParenLoc(TL.getLParenLoc());
7109 NewTL.setRParenLoc(TL.getRParenLoc());
7110
7111 return Result;
7112}
7113
7114template <typename Derived>
7115QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
7116 PipeTypeLoc TL) {
7117 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7118 if (ValueType.isNull())
7119 return QualType();
7120
7121 QualType Result = TL.getType();
7122 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7123 const PipeType *PT = Result->castAs<PipeType>();
7124 bool isReadPipe = PT->isReadOnly();
7125 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7126 if (Result.isNull())
7127 return QualType();
7128 }
7129
7130 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7131 NewTL.setKWLoc(TL.getKWLoc());
7132
7133 return Result;
7134}
7135
7136template <typename Derived>
7137QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
7138 BitIntTypeLoc TL) {
7139 const BitIntType *EIT = TL.getTypePtr();
7140 QualType Result = TL.getType();
7141
7142 if (getDerived().AlwaysRebuild()) {
7143 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7144 EIT->getNumBits(), TL.getNameLoc());
7145 if (Result.isNull())
7146 return QualType();
7147 }
7148
7149 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7150 NewTL.setNameLoc(TL.getNameLoc());
7151 return Result;
7152}
7153
7154template <typename Derived>
7155QualType TreeTransform<Derived>::TransformDependentBitIntType(
7156 TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) {
7157 const DependentBitIntType *EIT = TL.getTypePtr();
7158
7159 EnterExpressionEvaluationContext Unevaluated(
7161 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7162 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7163
7164 if (BitsExpr.isInvalid())
7165 return QualType();
7166
7167 QualType Result = TL.getType();
7168
7169 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7170 Result = getDerived().RebuildDependentBitIntType(
7171 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7172
7173 if (Result.isNull())
7174 return QualType();
7175 }
7176
7177 if (isa<DependentBitIntType>(Result)) {
7178 DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
7179 NewTL.setNameLoc(TL.getNameLoc());
7180 } else {
7181 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7182 NewTL.setNameLoc(TL.getNameLoc());
7183 }
7184 return Result;
7185}
7186
7187 /// Simple iterator that traverses the template arguments in a
7188 /// container that provides a \c getArgLoc() member function.
7189 ///
7190 /// This iterator is intended to be used with the iterator form of
7191 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7192 template<typename ArgLocContainer>
7194 ArgLocContainer *Container;
7195 unsigned Index;
7196
7197 public:
7200 typedef int difference_type;
7201 typedef std::input_iterator_tag iterator_category;
7202
7203 class pointer {
7205
7206 public:
7207 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7208
7210 return &Arg;
7211 }
7212 };
7213
7214
7216
7217 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7218 unsigned Index)
7219 : Container(&Container), Index(Index) { }
7220
7222 ++Index;
7223 return *this;
7224 }
7225
7228 ++(*this);
7229 return Old;
7230 }
7231
7233 return Container->getArgLoc(Index);
7234 }
7235
7237 return pointer(Container->getArgLoc(Index));
7238 }
7239
7242 return X.Container == Y.Container && X.Index == Y.Index;
7243 }
7244
7247 return !(X == Y);
7248 }
7249 };
7250
7251template<typename Derived>
7252QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7253 AutoTypeLoc TL) {
7254 const AutoType *T = TL.getTypePtr();
7255 QualType OldDeduced = T->getDeducedType();
7256 QualType NewDeduced;
7257 if (!OldDeduced.isNull()) {
7258 NewDeduced = getDerived().TransformType(OldDeduced);
7259 if (NewDeduced.isNull())
7260 return QualType();
7261 }
7262
7263 ConceptDecl *NewCD = nullptr;
7264 TemplateArgumentListInfo NewTemplateArgs;
7265 NestedNameSpecifierLoc NewNestedNameSpec;
7266 if (T->isConstrained()) {
7267 assert(TL.getConceptReference());
7268 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7269 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7270
7271 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7272 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7273 typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator;
7274 if (getDerived().TransformTemplateArguments(
7275 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7276 NewTemplateArgs))
7277 return QualType();
7278
7279 if (TL.getNestedNameSpecifierLoc()) {
7280 NewNestedNameSpec
7281 = getDerived().TransformNestedNameSpecifierLoc(
7282 TL.getNestedNameSpecifierLoc());
7283 if (!NewNestedNameSpec)
7284 return QualType();
7285 }
7286 }
7287
7288 QualType Result = TL.getType();
7289 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7290 T->isDependentType() || T->isConstrained()) {
7291 // FIXME: Maybe don't rebuild if all template arguments are the same.
7293 NewArgList.reserve(NewTemplateArgs.size());
7294 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7295 NewArgList.push_back(ArgLoc.getArgument());
7296 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7297 NewArgList);
7298 if (Result.isNull())
7299 return QualType();
7300 }
7301
7302 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7303 NewTL.setNameLoc(TL.getNameLoc());
7304 NewTL.setRParenLoc(TL.getRParenLoc());
7305 NewTL.setConceptReference(nullptr);
7306
7307 if (T->isConstrained()) {
7308 DeclarationNameInfo DNI = DeclarationNameInfo(
7309 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7310 TL.getConceptNameLoc(),
7311 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7312 auto *CR = ConceptReference::Create(
7313 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7314 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7315 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7316 NewTL.setConceptReference(CR);
7317 }
7318
7319 return Result;
7320}
7321
7322template <typename Derived>
7324 TypeLocBuilder &TLB,
7325 TemplateSpecializationTypeLoc TL,
7326 TemplateName Template) {
7327 TemplateArgumentListInfo NewTemplateArgs;
7328 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7329 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7330 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
7331 ArgIterator;
7332 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7333 ArgIterator(TL, TL.getNumArgs()),
7334 NewTemplateArgs))
7335 return QualType();
7336
7337 // FIXME: maybe don't rebuild if all the template arguments are the same.
7338
7339 QualType Result =
7340 getDerived().RebuildTemplateSpecializationType(Template,
7341 TL.getTemplateNameLoc(),
7342 NewTemplateArgs);
7343
7344 if (!Result.isNull()) {
7345 // Specializations of template template parameters are represented as
7346 // TemplateSpecializationTypes, and substitution of type alias templates
7347 // within a dependent context can transform them into
7348 // DependentTemplateSpecializationTypes.
7349 if (isa<DependentTemplateSpecializationType>(Result)) {
7350 DependentTemplateSpecializationTypeLoc NewTL
7351 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
7352 NewTL.setElaboratedKeywordLoc(SourceLocation());
7353 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
7354 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7355 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7356 NewTL.setLAngleLoc(TL.getLAngleLoc());
7357 NewTL.setRAngleLoc(TL.getRAngleLoc());
7358 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7359 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7360 return Result;
7361 }
7362
7363 TemplateSpecializationTypeLoc NewTL
7364 = TLB.push<TemplateSpecializationTypeLoc>(Result);
7365 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7366 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7367 NewTL.setLAngleLoc(TL.getLAngleLoc());
7368 NewTL.setRAngleLoc(TL.getRAngleLoc());
7369 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7370 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7371 }
7372
7373 return Result;
7374}
7375
7376template <typename Derived>
7378 TypeLocBuilder &TLB,
7380 TemplateName Template,
7381 CXXScopeSpec &SS) {
7382 TemplateArgumentListInfo NewTemplateArgs;
7383 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7384 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7387 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7388 ArgIterator(TL, TL.getNumArgs()),
7389 NewTemplateArgs))
7390 return QualType();
7391
7392 // FIXME: maybe don't rebuild if all the template arguments are the same.
7393
7394 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
7395 QualType Result = getSema().Context.getDependentTemplateSpecializationType(
7396 TL.getTypePtr()->getKeyword(), DTN->getQualifier(),
7397 DTN->getIdentifier(), NewTemplateArgs.arguments());
7398
7402 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
7405 NewTL.setLAngleLoc(TL.getLAngleLoc());
7406 NewTL.setRAngleLoc(TL.getRAngleLoc());
7407 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7408 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7409 return Result;
7410 }
7411
7413 = getDerived().RebuildTemplateSpecializationType(Template,
7414 TL.getTemplateNameLoc(),
7415 NewTemplateArgs);
7416
7417 if (!Result.isNull()) {
7418 /// FIXME: Wrap this in an elaborated-type-specifier?
7423 NewTL.setLAngleLoc(TL.getLAngleLoc());
7424 NewTL.setRAngleLoc(TL.getRAngleLoc());
7425 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7426 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7427 }
7428
7429 return Result;
7430}
7431
7432template<typename Derived>
7435 ElaboratedTypeLoc TL) {
7436 const ElaboratedType *T = TL.getTypePtr();
7437
7438 NestedNameSpecifierLoc QualifierLoc;
7439 // NOTE: the qualifier in an ElaboratedType is optional.
7440 if (TL.getQualifierLoc()) {
7441 QualifierLoc
7442 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7443 if (!QualifierLoc)
7444 return QualType();
7445 }
7446
7447 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
7448 if (NamedT.isNull())
7449 return QualType();
7450
7451 // C++0x [dcl.type.elab]p2:
7452 // If the identifier resolves to a typedef-name or the simple-template-id
7453 // resolves to an alias template specialization, the
7454 // elaborated-type-specifier is ill-formed.
7455 if (T->getKeyword() != ElaboratedTypeKeyword::None &&
7456 T->getKeyword() != ElaboratedTypeKeyword::Typename) {
7457 if (const TemplateSpecializationType *TST =
7458 NamedT->getAs<TemplateSpecializationType>()) {
7459 TemplateName Template = TST->getTemplateName();
7460 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
7461 Template.getAsTemplateDecl())) {
7462 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
7463 diag::err_tag_reference_non_tag)
7465 << llvm::to_underlying(
7467 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
7468 }
7469 }
7470 }
7471
7472 QualType Result = TL.getType();
7473 if (getDerived().AlwaysRebuild() ||
7474 QualifierLoc != TL.getQualifierLoc() ||
7475 NamedT != T->getNamedType()) {
7476 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
7477 T->getKeyword(),
7478 QualifierLoc, NamedT);
7479 if (Result.isNull())
7480 return QualType();
7481 }
7482
7483 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7484 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7485 NewTL.setQualifierLoc(QualifierLoc);
7486 return Result;
7487}
7488
7489template <typename Derived>
7490QualType TreeTransform<Derived>::TransformAttributedType(TypeLocBuilder &TLB,
7491 AttributedTypeLoc TL) {
7492 const AttributedType *oldType = TL.getTypePtr();
7493 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7494 if (modifiedType.isNull())
7495 return QualType();
7496
7497 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7498 const Attr *oldAttr = TL.getAttr();
7499 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7500 if (oldAttr && !newAttr)
7501 return QualType();
7502
7503 QualType result = TL.getType();
7504
7505 // FIXME: dependent operand expressions?
7506 if (getDerived().AlwaysRebuild() ||
7507 modifiedType != oldType->getModifiedType()) {
7508 // If the equivalent type is equal to the modified type, we don't want to
7509 // transform it as well because:
7510 //
7511 // 1. The transformation would yield the same result and is therefore
7512 // superfluous, and
7513 //
7514 // 2. Transforming the same type twice can cause problems, e.g. if it
7515 // is a FunctionProtoType, we may end up instantiating the function
7516 // parameters twice, which causes an assertion since the parameters
7517 // are already bound to their counterparts in the template for this
7518 // instantiation.
7519 //
7520 QualType equivalentType = modifiedType;
7521 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7522 TypeLocBuilder AuxiliaryTLB;
7523 AuxiliaryTLB.reserve(TL.getFullDataSize());
7524 equivalentType =
7525 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7526 if (equivalentType.isNull())
7527 return QualType();
7528 }
7529
7530 // Check whether we can add nullability; it is only represented as
7531 // type sugar, and therefore cannot be diagnosed in any other way.
7532 if (auto nullability = oldType->getImmediateNullability()) {
7533 if (!modifiedType->canHaveNullability()) {
7534 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7535 : TL.getModifiedLoc().getBeginLoc()),
7536 diag::err_nullability_nonpointer)
7537 << DiagNullabilityKind(*nullability, false) << modifiedType;
7538 return QualType();
7539 }
7540 }
7541
7542 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7543 modifiedType,
7544 equivalentType,
7545 TL.getAttr());
7546 }
7547
7548 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7549 newTL.setAttr(newAttr);
7550 return result;
7551}
7552
7553template <typename Derived>
7554QualType TreeTransform<Derived>::TransformCountAttributedType(
7555 TypeLocBuilder &TLB, CountAttributedTypeLoc TL) {
7556 const CountAttributedType *OldTy = TL.getTypePtr();
7557 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7558 if (InnerTy.isNull())
7559 return QualType();
7560
7561 Expr *OldCount = TL.getCountExpr();
7562 Expr *NewCount = nullptr;
7563 if (OldCount) {
7564 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7565 if (CountResult.isInvalid())
7566 return QualType();
7567 NewCount = CountResult.get();
7568 }
7569
7570 QualType Result = TL.getType();
7571 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7572 OldCount != NewCount) {
7573 // Currently, CountAttributedType can only wrap incomplete array types.
7575 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7576 }
7577
7578 TLB.push<CountAttributedTypeLoc>(Result);
7579 return Result;
7580}
7581
7582template <typename Derived>
7583QualType TreeTransform<Derived>::TransformBTFTagAttributedType(
7584 TypeLocBuilder &TLB, BTFTagAttributedTypeLoc TL) {
7585 // The BTFTagAttributedType is available for C only.
7586 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7587}
7588
7589template <typename Derived>
7590QualType TreeTransform<Derived>::TransformHLSLAttributedResourceType(
7591 TypeLocBuilder &TLB, HLSLAttributedResourceTypeLoc TL) {
7592
7593 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7594
7595 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7596 if (WrappedTy.isNull())
7597 return QualType();
7598
7599 QualType ContainedTy = QualType();
7600 QualType OldContainedTy = oldType->getContainedType();
7601 if (!OldContainedTy.isNull()) {
7602 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7603 if (!oldContainedTSI)
7604 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7605 OldContainedTy, SourceLocation());
7606 TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI);
7607 if (!ContainedTSI)
7608 return QualType();
7609 ContainedTy = ContainedTSI->getType();
7610 }
7611
7612 QualType Result = TL.getType();
7613 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7614 ContainedTy != oldType->getContainedType()) {
7616 WrappedTy, ContainedTy, oldType->getAttrs());
7617 }
7618
7619 TLB.push<HLSLAttributedResourceTypeLoc>(Result);
7620 return Result;
7621}
7622
7623template<typename Derived>
7624QualType
7625TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
7626 ParenTypeLoc TL) {
7627 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7628 if (Inner.isNull())
7629 return QualType();
7630
7631 QualType Result = TL.getType();
7632 if (getDerived().AlwaysRebuild() ||
7633 Inner != TL.getInnerLoc().getType()) {
7634 Result = getDerived().RebuildParenType(Inner);
7635 if (Result.isNull())
7636 return QualType();
7637 }
7638
7639 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7640 NewTL.setLParenLoc(TL.getLParenLoc());
7641 NewTL.setRParenLoc(TL.getRParenLoc());
7642 return Result;
7643}
7644
7645template <typename Derived>
7646QualType
7647TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
7648 MacroQualifiedTypeLoc TL) {
7649 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7650 if (Inner.isNull())
7651 return QualType();
7652
7653 QualType Result = TL.getType();
7654 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7655 Result =
7656 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7657 if (Result.isNull())
7658 return QualType();
7659 }
7660
7661 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
7662 NewTL.setExpansionLoc(TL.getExpansionLoc());
7663 return Result;
7664}
7665
7666template<typename Derived>
7667QualType TreeTransform<Derived>::TransformDependentNameType(
7668 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
7669 return TransformDependentNameType(TLB, TL, false);
7670}
7671
7672template<typename Derived>
7673QualType TreeTransform<Derived>::TransformDependentNameType(
7674 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
7675 const DependentNameType *T = TL.getTypePtr();
7676
7677 NestedNameSpecifierLoc QualifierLoc
7678 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7679 if (!QualifierLoc)
7680 return QualType();
7681
7682 QualType Result
7683 = getDerived().RebuildDependentNameType(T->getKeyword(),
7684 TL.getElaboratedKeywordLoc(),
7685 QualifierLoc,
7686 T->getIdentifier(),
7687 TL.getNameLoc(),
7688 DeducedTSTContext);
7689 if (Result.isNull())
7690 return QualType();
7691
7692 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
7693 QualType NamedT = ElabT->getNamedType();
7694 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
7695
7696 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7697 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7698 NewTL.setQualifierLoc(QualifierLoc);
7699 } else {
7700 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
7701 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7702 NewTL.setQualifierLoc(QualifierLoc);
7703 NewTL.setNameLoc(TL.getNameLoc());
7704 }
7705 return Result;
7706}
7707
7708template<typename Derived>
7711 DependentTemplateSpecializationTypeLoc TL) {
7712 NestedNameSpecifierLoc QualifierLoc;
7713 if (TL.getQualifierLoc()) {
7714 QualifierLoc
7715 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7716 if (!QualifierLoc)
7717 return QualType();
7718 }
7719
7720 return getDerived()
7721 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
7722}
7723
7724template<typename Derived>
7728 NestedNameSpecifierLoc QualifierLoc) {
7730
7731 TemplateArgumentListInfo NewTemplateArgs;
7732 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7733 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7734
7737 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7738 ArgIterator(TL, TL.getNumArgs()),
7739 NewTemplateArgs))
7740 return QualType();
7741
7742 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
7743 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
7744 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
7745 /*AllowInjectedClassName*/ false);
7746 if (Result.isNull())
7747 return QualType();
7748
7749 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
7750 QualType NamedT = ElabT->getNamedType();
7751
7752 // Copy information relevant to the template specialization.
7754 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
7757 NamedTL.setLAngleLoc(TL.getLAngleLoc());
7758 NamedTL.setRAngleLoc(TL.getRAngleLoc());
7759 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7760 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7761
7762 // Copy information relevant to the elaborated type.
7765 NewTL.setQualifierLoc(QualifierLoc);
7766 } else if (isa<DependentTemplateSpecializationType>(Result)) {
7770 SpecTL.setQualifierLoc(QualifierLoc);
7773 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7774 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7775 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7776 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7777 } else {
7782 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7783 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7784 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7785 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7786 }
7787 return Result;
7788}
7789
7790template<typename Derived>
7793 QualType Pattern
7794 = getDerived().TransformType(TLB, TL.getPatternLoc());
7795 if (Pattern.isNull())
7796 return QualType();
7797
7798 QualType Result = TL.getType();
7799 if (getDerived().AlwaysRebuild() ||
7800 Pattern != TL.getPatternLoc().getType()) {
7801 Result = getDerived().RebuildPackExpansionType(Pattern,
7803 TL.getEllipsisLoc(),
7805 if (Result.isNull())
7806 return QualType();
7807 }
7808
7809 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
7810 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7811 return Result;
7812}
7813
7814template<typename Derived>
7815QualType
7816TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
7817 ObjCInterfaceTypeLoc TL) {
7818 // ObjCInterfaceType is never dependent.
7819 TLB.pushFullCopy(TL);
7820 return TL.getType();
7821}
7822
7823template<typename Derived>
7824QualType
7825TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
7826 ObjCTypeParamTypeLoc TL) {
7827 const ObjCTypeParamType *T = TL.getTypePtr();
7828 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7829 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7830 if (!OTP)
7831 return QualType();
7832
7833 QualType Result = TL.getType();
7834 if (getDerived().AlwaysRebuild() ||
7835 OTP != T->getDecl()) {
7836 Result = getDerived().RebuildObjCTypeParamType(
7837 OTP, TL.getProtocolLAngleLoc(),
7838 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7839 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7840 if (Result.isNull())
7841 return QualType();
7842 }
7843
7844 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
7845 if (TL.getNumProtocols()) {
7846 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7847 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7848 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7849 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7850 }
7851 return Result;
7852}
7853
7854template<typename Derived>
7855QualType
7856TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
7857 ObjCObjectTypeLoc TL) {
7858 // Transform base type.
7859 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7860 if (BaseType.isNull())
7861 return QualType();
7862
7863 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7864
7865 // Transform type arguments.
7866 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7867 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7868 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7869 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7870 QualType TypeArg = TypeArgInfo->getType();
7871 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7872 AnyChanged = true;
7873
7874 // We have a pack expansion. Instantiate it.
7875 const auto *PackExpansion = PackExpansionLoc.getType()
7876 ->castAs<PackExpansionType>();
7878 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7879 Unexpanded);
7880 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7881
7882 // Determine whether the set of unexpanded parameter packs can
7883 // and should be expanded.
7884 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7885 bool Expand = false;
7886 bool RetainExpansion = false;
7887 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
7888 if (getDerived().TryExpandParameterPacks(
7889 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7890 Unexpanded, Expand, RetainExpansion, NumExpansions))
7891 return QualType();
7892
7893 if (!Expand) {
7894 // We can't expand this pack expansion into separate arguments yet;
7895 // just substitute into the pattern and create a new pack expansion
7896 // type.
7897 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7898
7899 TypeLocBuilder TypeArgBuilder;
7900 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7901 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7902 PatternLoc);
7903 if (NewPatternType.isNull())
7904 return QualType();
7905
7906 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7907 NewPatternType, NumExpansions);
7908 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7909 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7910 NewTypeArgInfos.push_back(
7911 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7912 continue;
7913 }
7914
7915 // Substitute into the pack expansion pattern for each slice of the
7916 // pack.
7917 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7918 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
7919
7920 TypeLocBuilder TypeArgBuilder;
7921 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7922
7923 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7924 PatternLoc);
7925 if (NewTypeArg.isNull())
7926 return QualType();
7927
7928 NewTypeArgInfos.push_back(
7929 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7930 }
7931
7932 continue;
7933 }
7934
7935 TypeLocBuilder TypeArgBuilder;
7936 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7937 QualType NewTypeArg =
7938 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7939 if (NewTypeArg.isNull())
7940 return QualType();
7941
7942 // If nothing changed, just keep the old TypeSourceInfo.
7943 if (NewTypeArg == TypeArg) {
7944 NewTypeArgInfos.push_back(TypeArgInfo);
7945 continue;
7946 }
7947
7948 NewTypeArgInfos.push_back(
7949 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7950 AnyChanged = true;
7951 }
7952
7953 QualType Result = TL.getType();
7954 if (getDerived().AlwaysRebuild() || AnyChanged) {
7955 // Rebuild the type.
7956 Result = getDerived().RebuildObjCObjectType(
7957 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
7958 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
7959 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7960 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7961
7962 if (Result.isNull())
7963 return QualType();
7964 }
7965
7966 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
7967 NewT.setHasBaseTypeAsWritten(true);
7968 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
7969 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
7970 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
7971 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
7972 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7973 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7974 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
7975 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7976 return Result;
7977}
7978
7979template<typename Derived>
7980QualType
7981TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
7982 ObjCObjectPointerTypeLoc TL) {
7983 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7984 if (PointeeType.isNull())
7985 return QualType();
7986
7987 QualType Result = TL.getType();
7988 if (getDerived().AlwaysRebuild() ||
7989 PointeeType != TL.getPointeeLoc().getType()) {
7990 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7991 TL.getStarLoc());
7992 if (Result.isNull())
7993 return QualType();
7994 }
7995
7996 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
7997 NewT.setStarLoc(TL.getStarLoc());
7998 return Result;
7999}
8000
8001//===----------------------------------------------------------------------===//
8002// Statement transformation
8003//===----------------------------------------------------------------------===//
8004template<typename Derived>
8006TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
8007 return S;
8008}
8009
8010template<typename Derived>
8013 return getDerived().TransformCompoundStmt(S, false);
8014}
8015
8016template<typename Derived>
8019 bool IsStmtExpr) {
8020 Sema::CompoundScopeRAII CompoundScope(getSema());
8021 Sema::FPFeaturesStateRAII FPSave(getSema());
8022 if (S->hasStoredFPFeatures())
8023 getSema().resetFPOptions(
8024 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8025
8026 const Stmt *ExprResult = S->getStmtExprResult();
8027 bool SubStmtInvalid = false;
8028 bool SubStmtChanged = false;
8029 SmallVector<Stmt*, 8> Statements;
8030 for (auto *B : S->body()) {
8031 StmtResult Result = getDerived().TransformStmt(
8032 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
8033
8034 if (Result.isInvalid()) {
8035 // Immediately fail if this was a DeclStmt, since it's very
8036 // likely that this will cause problems for future statements.
8037 if (isa<DeclStmt>(B))
8038 return StmtError();
8039
8040 // Otherwise, just keep processing substatements and fail later.
8041 SubStmtInvalid = true;
8042 continue;
8043 }
8044
8045 SubStmtChanged = SubStmtChanged || Result.get() != B;
8046 Statements.push_back(Result.getAs<Stmt>());
8047 }
8048
8049 if (SubStmtInvalid)
8050 return StmtError();
8051
8052 if (!getDerived().AlwaysRebuild() &&
8053 !SubStmtChanged)
8054 return S;
8055
8056 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8057 Statements,
8058 S->getRBracLoc(),
8059 IsStmtExpr);
8060}
8061
8062template<typename Derived>
8064TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
8065 ExprResult LHS, RHS;
8066 {
8067 EnterExpressionEvaluationContext Unevaluated(
8069
8070 // Transform the left-hand case value.
8071 LHS = getDerived().TransformExpr(S->getLHS());
8072 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8073 if (LHS.isInvalid())
8074 return StmtError();
8075
8076 // Transform the right-hand case value (for the GNU case-range extension).
8077 RHS = getDerived().TransformExpr(S->getRHS());
8078 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8079 if (RHS.isInvalid())
8080 return StmtError();
8081 }
8082
8083 // Build the case statement.
8084 // Case statements are always rebuilt so that they will attached to their
8085 // transformed switch statement.
8086 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8087 LHS.get(),
8088 S->getEllipsisLoc(),
8089 RHS.get(),
8090 S->getColonLoc());
8091 if (Case.isInvalid())
8092 return StmtError();
8093
8094 // Transform the statement following the case
8095 StmtResult SubStmt =
8096 getDerived().TransformStmt(S->getSubStmt());
8097 if (SubStmt.isInvalid())
8098 return StmtError();
8099
8100 // Attach the body to the case statement
8101 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8102}
8103
8104template <typename Derived>
8105StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
8106 // Transform the statement following the default case
8107 StmtResult SubStmt =
8108 getDerived().TransformStmt(S->getSubStmt());
8109 if (SubStmt.isInvalid())
8110 return StmtError();
8111
8112 // Default statements are always rebuilt
8113 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8114 SubStmt.get());
8115}
8116
8117template<typename Derived>
8119TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
8120 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8121 if (SubStmt.isInvalid())
8122 return StmtError();
8123
8124 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8125 S->getDecl());
8126 if (!LD)
8127 return StmtError();
8128
8129 // If we're transforming "in-place" (we're not creating new local
8130 // declarations), assume we're replacing the old label statement
8131 // and clear out the reference to it.
8132 if (LD == S->getDecl())
8133 S->getDecl()->setStmt(nullptr);
8134
8135 // FIXME: Pass the real colon location in.
8136 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8137 cast<LabelDecl>(LD), SourceLocation(),
8138 SubStmt.get());
8139}
8140
8141template <typename Derived>
8143 if (!R)
8144 return R;
8145
8146 switch (R->getKind()) {
8147// Transform attributes by calling TransformXXXAttr.
8148#define ATTR(X) \
8149 case attr::X: \
8150 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8151#include "clang/Basic/AttrList.inc"
8152 }
8153 return R;
8154}
8155
8156template <typename Derived>
8158 const Stmt *InstS,
8159 const Attr *R) {
8160 if (!R)
8161 return R;
8162
8163 switch (R->getKind()) {
8164// Transform attributes by calling TransformStmtXXXAttr.
8165#define ATTR(X) \
8166 case attr::X: \
8167 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8168#include "clang/Basic/AttrList.inc"
8169 }
8170 return TransformAttr(R);
8171}
8172
8173template <typename Derived>
8176 StmtDiscardKind SDK) {
8177 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8178 if (SubStmt.isInvalid())
8179 return StmtError();
8180
8181 bool AttrsChanged = false;
8183
8184 // Visit attributes and keep track if any are transformed.
8185 for (const auto *I : S->getAttrs()) {
8186 const Attr *R =
8187 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8188 AttrsChanged |= (I != R);
8189 if (R)
8190 Attrs.push_back(R);
8191 }
8192
8193 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8194 return S;
8195
8196 // If transforming the attributes failed for all of the attributes in the
8197 // statement, don't make an AttributedStmt without attributes.
8198 if (Attrs.empty())
8199 return SubStmt;
8200
8201 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8202 SubStmt.get());
8203}
8204
8205template<typename Derived>
8207TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
8208 // Transform the initialization statement
8209 StmtResult Init = getDerived().TransformStmt(S->getInit());
8210 if (Init.isInvalid())
8211 return StmtError();
8212
8213 Sema::ConditionResult Cond;
8214 if (!S->isConsteval()) {
8215 // Transform the condition
8216 Cond = getDerived().TransformCondition(
8217 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8218 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8220 if (Cond.isInvalid())
8221 return StmtError();
8222 }
8223
8224 // If this is a constexpr if, determine which arm we should instantiate.
8225 std::optional<bool> ConstexprConditionValue;
8226 if (S->isConstexpr())
8227 ConstexprConditionValue = Cond.getKnownValue();
8228
8229 // Transform the "then" branch.
8230 StmtResult Then;
8231 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8232 EnterExpressionEvaluationContext Ctx(
8235 S->isNonNegatedConsteval());
8236
8237 Then = getDerived().TransformStmt(S->getThen());
8238 if (Then.isInvalid())
8239 return StmtError();
8240 } else {
8241 // Discarded branch is replaced with empty CompoundStmt so we can keep
8242 // proper source location for start and end of original branch, so
8243 // subsequent transformations like CoverageMapping work properly
8244 Then = new (getSema().Context)
8245 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8246 }
8247
8248 // Transform the "else" branch.
8249 StmtResult Else;
8250 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8251 EnterExpressionEvaluationContext Ctx(
8254 S->isNegatedConsteval());
8255
8256 Else = getDerived().TransformStmt(S->getElse());
8257 if (Else.isInvalid())
8258 return StmtError();
8259 } else if (S->getElse() && ConstexprConditionValue &&
8260 *ConstexprConditionValue) {
8261 // Same thing here as with <then> branch, we are discarding it, we can't
8262 // replace it with NULL nor NullStmt as we need to keep for source location
8263 // range, for CoverageMapping
8264 Else = new (getSema().Context)
8265 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8266 }
8267
8268 if (!getDerived().AlwaysRebuild() &&
8269 Init.get() == S->getInit() &&
8270 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8271 Then.get() == S->getThen() &&
8272 Else.get() == S->getElse())
8273 return S;
8274
8275 return getDerived().RebuildIfStmt(
8276 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8277 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8278}
8279
8280template<typename Derived>
8282TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
8283 // Transform the initialization statement
8284 StmtResult Init = getDerived().TransformStmt(S->getInit());
8285 if (Init.isInvalid())
8286 return StmtError();
8287
8288 // Transform the condition.
8289 Sema::ConditionResult Cond = getDerived().TransformCondition(
8290 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8292 if (Cond.isInvalid())
8293 return StmtError();
8294
8295 // Rebuild the switch statement.
8297 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8298 Init.get(), Cond, S->getRParenLoc());
8299 if (Switch.isInvalid())
8300 return StmtError();
8301
8302 // Transform the body of the switch statement.
8303 StmtResult Body = getDerived().TransformStmt(S->getBody());
8304 if (Body.isInvalid())
8305 return StmtError();
8306
8307 // Complete the switch statement.
8308 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8309 Body.get());
8310}
8311
8312template<typename Derived>
8314TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
8315 // Transform the condition
8316 Sema::ConditionResult Cond = getDerived().TransformCondition(
8317 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8319 if (Cond.isInvalid())
8320 return StmtError();
8321
8322 // OpenACC Restricts a while-loop inside of certain construct/clause
8323 // combinations, so diagnose that here in OpenACC mode.
8324 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8325 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8326
8327 // Transform the body
8328 StmtResult Body = getDerived().TransformStmt(S->getBody());
8329 if (Body.isInvalid())
8330 return StmtError();
8331
8332 if (!getDerived().AlwaysRebuild() &&
8333 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8334 Body.get() == S->getBody())
8335 return Owned(S);
8336
8337 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8338 Cond, S->getRParenLoc(), Body.get());
8339}
8340
8341template<typename Derived>
8343TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
8344 // OpenACC Restricts a do-loop inside of certain construct/clause
8345 // combinations, so diagnose that here in OpenACC mode.
8346 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8347 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8348
8349 // Transform the body
8350 StmtResult Body = getDerived().TransformStmt(S->getBody());
8351 if (Body.isInvalid())
8352 return StmtError();
8353
8354 // Transform the condition
8355 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8356 if (Cond.isInvalid())
8357 return StmtError();
8358
8359 if (!getDerived().AlwaysRebuild() &&
8360 Cond.get() == S->getCond() &&
8361 Body.get() == S->getBody())
8362 return S;
8363
8364 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8365 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8366 S->getRParenLoc());
8367}
8368
8369template<typename Derived>
8371TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
8372 if (getSema().getLangOpts().OpenMP)
8373 getSema().OpenMP().startOpenMPLoop();
8374
8375 // Transform the initialization statement
8376 StmtResult Init = getDerived().TransformStmt(S->getInit());
8377 if (Init.isInvalid())
8378 return StmtError();
8379
8380 // In OpenMP loop region loop control variable must be captured and be
8381 // private. Perform analysis of first part (if any).
8382 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8383 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8384 Init.get());
8385
8386 // Transform the condition
8387 Sema::ConditionResult Cond = getDerived().TransformCondition(
8388 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8390 if (Cond.isInvalid())
8391 return StmtError();
8392
8393 // Transform the increment
8394 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8395 if (Inc.isInvalid())
8396 return StmtError();
8397
8398 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8399 if (S->getInc() && !FullInc.get())
8400 return StmtError();
8401
8402 // OpenACC Restricts a for-loop inside of certain construct/clause
8403 // combinations, so diagnose that here in OpenACC mode.
8404 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8405 SemaRef.OpenACC().ActOnForStmtBegin(
8406 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8407 Cond.get().second, S->getInc(), Inc.get());
8408
8409 // Transform the body
8410 StmtResult Body = getDerived().TransformStmt(S->getBody());
8411 if (Body.isInvalid())
8412 return StmtError();
8413
8414 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8415
8416 if (!getDerived().AlwaysRebuild() &&
8417 Init.get() == S->getInit() &&
8418 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8419 Inc.get() == S->getInc() &&
8420 Body.get() == S->getBody())
8421 return S;
8422
8423 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8424 Init.get(), Cond, FullInc,
8425 S->getRParenLoc(), Body.get());
8426}
8427
8428template<typename Derived>
8430TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
8431 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8432 S->getLabel());
8433 if (!LD)
8434 return StmtError();
8435
8436 // Goto statements must always be rebuilt, to resolve the label.
8437 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8438 cast<LabelDecl>(LD));
8439}
8440
8441template<typename Derived>
8443TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
8444 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8445 if (Target.isInvalid())
8446 return StmtError();
8447 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8448
8449 if (!getDerived().AlwaysRebuild() &&
8450 Target.get() == S->getTarget())
8451 return S;
8452
8453 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8454 Target.get());
8455}
8456
8457template<typename Derived>
8459TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
8460 return S;
8461}
8462
8463template<typename Derived>
8465TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
8466 return S;
8467}
8468
8469template<typename Derived>
8471TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
8472 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8473 /*NotCopyInit*/false);
8474 if (Result.isInvalid())
8475 return StmtError();
8476
8477 // FIXME: We always rebuild the return statement because there is no way
8478 // to tell whether the return type of the function has changed.
8479 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8480}
8481
8482template<typename Derived>
8484TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
8485 bool DeclChanged = false;
8487 LambdaScopeInfo *LSI = getSema().getCurLambda();
8488 for (auto *D : S->decls()) {
8489 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8490 if (!Transformed)
8491 return StmtError();
8492
8493 if (Transformed != D)
8494 DeclChanged = true;
8495
8496 if (LSI) {
8497 if (auto *TD = dyn_cast<TypeDecl>(Transformed))
8498 LSI->ContainsUnexpandedParameterPack |=
8499 getSema()
8500 .getASTContext()
8501 .getTypeDeclType(TD)
8502 .getCanonicalType()
8503 ->containsUnexpandedParameterPack();
8504
8505 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8506 LSI->ContainsUnexpandedParameterPack |=
8507 VD->getType()->containsUnexpandedParameterPack();
8508 }
8509
8510 Decls.push_back(Transformed);
8511 }
8512
8513 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8514 return S;
8515
8516 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8517}
8518
8519template<typename Derived>
8521TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
8522
8523 SmallVector<Expr*, 8> Constraints;
8526
8527 ExprResult AsmString;
8528 SmallVector<Expr*, 8> Clobbers;
8529
8530 bool ExprsChanged = false;
8531
8532 // Go through the outputs.
8533 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8534 Names.push_back(S->getOutputIdentifier(I));
8535
8536 // No need to transform the constraint literal.
8537 Constraints.push_back(S->getOutputConstraintLiteral(I));
8538
8539 // Transform the output expr.
8540 Expr *OutputExpr = S->getOutputExpr(I);
8541 ExprResult Result = getDerived().TransformExpr(OutputExpr);
8542 if (Result.isInvalid())
8543 return StmtError();
8544
8545 ExprsChanged |= Result.get() != OutputExpr;
8546
8547 Exprs.push_back(Result.get());
8548 }
8549
8550 // Go through the inputs.
8551 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8552 Names.push_back(S->getInputIdentifier(I));
8553
8554 // No need to transform the constraint literal.
8555 Constraints.push_back(S->getInputConstraintLiteral(I));
8556
8557 // Transform the input expr.
8558 Expr *InputExpr = S->getInputExpr(I);
8559 ExprResult Result = getDerived().TransformExpr(InputExpr);
8560 if (Result.isInvalid())
8561 return StmtError();
8562
8563 ExprsChanged |= Result.get() != InputExpr;
8564
8565 Exprs.push_back(Result.get());
8566 }
8567
8568 // Go through the Labels.
8569 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8570 Names.push_back(S->getLabelIdentifier(I));
8571
8572 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8573 if (Result.isInvalid())
8574 return StmtError();
8575 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8576 Exprs.push_back(Result.get());
8577 }
8578 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8579 return S;
8580
8581 // Go through the clobbers.
8582 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
8583 Clobbers.push_back(S->getClobberStringLiteral(I));
8584
8585 // No need to transform the asm string literal.
8586 AsmString = S->getAsmString();
8587 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8588 S->isVolatile(), S->getNumOutputs(),
8589 S->getNumInputs(), Names.data(),
8590 Constraints, Exprs, AsmString.get(),
8591 Clobbers, S->getNumLabels(),
8592 S->getRParenLoc());
8593}
8594
8595template<typename Derived>
8597TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
8598 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8599
8600 bool HadError = false, HadChange = false;
8601
8602 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8603 SmallVector<Expr*, 8> TransformedExprs;
8604 TransformedExprs.reserve(SrcExprs.size());
8605 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8606 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8607 if (!Result.isUsable()) {
8608 HadError = true;
8609 } else {
8610 HadChange |= (Result.get() != SrcExprs[i]);
8611 TransformedExprs.push_back(Result.get());
8612 }
8613 }
8614
8615 if (HadError) return StmtError();
8616 if (!HadChange && !getDerived().AlwaysRebuild())
8617 return Owned(S);
8618
8619 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8620 AsmToks, S->getAsmString(),
8621 S->getNumOutputs(), S->getNumInputs(),
8622 S->getAllConstraints(), S->getClobbers(),
8623 TransformedExprs, S->getEndLoc());
8624}
8625
8626// C++ Coroutines
8627template<typename Derived>
8629TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
8630 auto *ScopeInfo = SemaRef.getCurFunction();
8631 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8632 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8633 ScopeInfo->NeedsCoroutineSuspends &&
8634 ScopeInfo->CoroutineSuspends.first == nullptr &&
8635 ScopeInfo->CoroutineSuspends.second == nullptr &&
8636 "expected clean scope info");
8637
8638 // Set that we have (possibly-invalid) suspend points before we do anything
8639 // that may fail.
8640 ScopeInfo->setNeedsCoroutineSuspends(false);
8641
8642 // We re-build the coroutine promise object (and the coroutine parameters its
8643 // type and constructor depend on) based on the types used in our current
8644 // function. We must do so, and set it on the current FunctionScopeInfo,
8645 // before attempting to transform the other parts of the coroutine body
8646 // statement, such as the implicit suspend statements (because those
8647 // statements reference the FunctionScopeInfo::CoroutinePromise).
8648 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8649 return StmtError();
8650 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8651 if (!Promise)
8652 return StmtError();
8653 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8654 ScopeInfo->CoroutinePromise = Promise;
8655
8656 // Transform the implicit coroutine statements constructed using dependent
8657 // types during the previous parse: initial and final suspensions, the return
8658 // object, and others. We also transform the coroutine function's body.
8659 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8660 if (InitSuspend.isInvalid())
8661 return StmtError();
8662 StmtResult FinalSuspend =
8663 getDerived().TransformStmt(S->getFinalSuspendStmt());
8664 if (FinalSuspend.isInvalid() ||
8665 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8666 return StmtError();
8667 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8668 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8669
8670 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8671 if (BodyRes.isInvalid())
8672 return StmtError();
8673
8674 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8675 if (Builder.isInvalid())
8676 return StmtError();
8677
8678 Expr *ReturnObject = S->getReturnValueInit();
8679 assert(ReturnObject && "the return object is expected to be valid");
8680 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8681 /*NoCopyInit*/ false);
8682 if (Res.isInvalid())
8683 return StmtError();
8684 Builder.ReturnValue = Res.get();
8685
8686 // If during the previous parse the coroutine still had a dependent promise
8687 // statement, we may need to build some implicit coroutine statements
8688 // (such as exception and fallthrough handlers) for the first time.
8689 if (S->hasDependentPromiseType()) {
8690 // We can only build these statements, however, if the current promise type
8691 // is not dependent.
8692 if (!Promise->getType()->isDependentType()) {
8693 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8694 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8695 "these nodes should not have been built yet");
8696 if (!Builder.buildDependentStatements())
8697 return StmtError();
8698 }
8699 } else {
8700 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8701 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8702 if (Res.isInvalid())
8703 return StmtError();
8704 Builder.OnFallthrough = Res.get();
8705 }
8706
8707 if (auto *OnException = S->getExceptionHandler()) {
8708 StmtResult Res = getDerived().TransformStmt(OnException);
8709 if (Res.isInvalid())
8710 return StmtError();
8711 Builder.OnException = Res.get();
8712 }
8713
8714 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8715 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8716 if (Res.isInvalid())
8717 return StmtError();
8718 Builder.ReturnStmtOnAllocFailure = Res.get();
8719 }
8720
8721 // Transform any additional statements we may have already built
8722 assert(S->getAllocate() && S->getDeallocate() &&
8723 "allocation and deallocation calls must already be built");
8724 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8725 if (AllocRes.isInvalid())
8726 return StmtError();
8727 Builder.Allocate = AllocRes.get();
8728
8729 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8730 if (DeallocRes.isInvalid())
8731 return StmtError();
8732 Builder.Deallocate = DeallocRes.get();
8733
8734 if (auto *ResultDecl = S->getResultDecl()) {
8735 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8736 if (Res.isInvalid())
8737 return StmtError();
8738 Builder.ResultDecl = Res.get();
8739 }
8740
8741 if (auto *ReturnStmt = S->getReturnStmt()) {
8742 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8743 if (Res.isInvalid())
8744 return StmtError();
8745 Builder.ReturnStmt = Res.get();
8746 }
8747 }
8748
8749 return getDerived().RebuildCoroutineBodyStmt(Builder);
8750}
8751
8752template<typename Derived>
8754TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
8755 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8756 /*NotCopyInit*/false);
8757 if (Result.isInvalid())
8758 return StmtError();
8759
8760 // Always rebuild; we don't know if this needs to be injected into a new
8761 // context or if the promise type has changed.
8762 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8763 S->isImplicit());
8764}
8765
8766template <typename Derived>
8767ExprResult TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
8768 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8769 /*NotCopyInit*/ false);
8770 if (Operand.isInvalid())
8771 return ExprError();
8772
8773 // Rebuild the common-expr from the operand rather than transforming it
8774 // separately.
8775
8776 // FIXME: getCurScope() should not be used during template instantiation.
8777 // We should pick up the set of unqualified lookup results for operator
8778 // co_await during the initial parse.
8779 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8780 getSema().getCurScope(), E->getKeywordLoc());
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().RebuildCoawaitExpr(
8785 E->getKeywordLoc(), Operand.get(),
8786 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8787}
8788
8789template <typename Derived>
8791TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
8792 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8793 /*NotCopyInit*/ false);
8794 if (OperandResult.isInvalid())
8795 return ExprError();
8796
8797 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8798 E->getOperatorCoawaitLookup());
8799
8800 if (LookupResult.isInvalid())
8801 return ExprError();
8802
8803 // Always rebuild; we don't know if this needs to be injected into a new
8804 // context or if the promise type has changed.
8805 return getDerived().RebuildDependentCoawaitExpr(
8806 E->getKeywordLoc(), OperandResult.get(),
8807 cast<UnresolvedLookupExpr>(LookupResult.get()));
8808}
8809
8810template<typename Derived>
8812TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
8813 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8814 /*NotCopyInit*/false);
8815 if (Result.isInvalid())
8816 return ExprError();
8817
8818 // Always rebuild; we don't know if this needs to be injected into a new
8819 // context or if the promise type has changed.
8820 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8821}
8822
8823// Objective-C Statements.
8824
8825template<typename Derived>
8827TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
8828 // Transform the body of the @try.
8829 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8830 if (TryBody.isInvalid())
8831 return StmtError();
8832
8833 // Transform the @catch statements (if present).
8834 bool AnyCatchChanged = false;
8835 SmallVector<Stmt*, 8> CatchStmts;
8836 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8837 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8838 if (Catch.isInvalid())
8839 return StmtError();
8840 if (Catch.get() != S->getCatchStmt(I))
8841 AnyCatchChanged = true;
8842 CatchStmts.push_back(Catch.get());
8843 }
8844
8845 // Transform the @finally statement (if present).
8846 StmtResult Finally;
8847 if (S->getFinallyStmt()) {
8848 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8849 if (Finally.isInvalid())
8850 return StmtError();
8851 }
8852
8853 // If nothing changed, just retain this statement.
8854 if (!getDerived().AlwaysRebuild() &&
8855 TryBody.get() == S->getTryBody() &&
8856 !AnyCatchChanged &&
8857 Finally.get() == S->getFinallyStmt())
8858 return S;
8859
8860 // Build a new statement.
8861 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8862 CatchStmts, Finally.get());
8863}
8864
8865template<typename Derived>
8867TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
8868 // Transform the @catch parameter, if there is one.
8869 VarDecl *Var = nullptr;
8870 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8871 TypeSourceInfo *TSInfo = nullptr;
8872 if (FromVar->getTypeSourceInfo()) {
8873 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8874 if (!TSInfo)
8875 return StmtError();
8876 }
8877
8878 QualType T;
8879 if (TSInfo)
8880 T = TSInfo->getType();
8881 else {
8882 T = getDerived().TransformType(FromVar->getType());
8883 if (T.isNull())
8884 return StmtError();
8885 }
8886
8887 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8888 if (!Var)
8889 return StmtError();
8890 }
8891
8892 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8893 if (Body.isInvalid())
8894 return StmtError();
8895
8896 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8897 S->getRParenLoc(),
8898 Var, Body.get());
8899}
8900
8901template<typename Derived>
8903TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
8904 // Transform the body.
8905 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8906 if (Body.isInvalid())
8907 return StmtError();
8908
8909 // If nothing changed, just retain this statement.
8910 if (!getDerived().AlwaysRebuild() &&
8911 Body.get() == S->getFinallyBody())
8912 return S;
8913
8914 // Build a new statement.
8915 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8916 Body.get());
8917}
8918
8919template<typename Derived>
8921TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
8923 if (S->getThrowExpr()) {
8924 Operand = getDerived().TransformExpr(S->getThrowExpr());
8925 if (Operand.isInvalid())
8926 return StmtError();
8927 }
8928
8929 if (!getDerived().AlwaysRebuild() &&
8930 Operand.get() == S->getThrowExpr())
8931 return S;
8932
8933 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8934}
8935
8936template<typename Derived>
8938TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
8939 ObjCAtSynchronizedStmt *S) {
8940 // Transform the object we are locking.
8941 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
8942 if (Object.isInvalid())
8943 return StmtError();
8944 Object =
8945 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8946 Object.get());
8947 if (Object.isInvalid())
8948 return StmtError();
8949
8950 // Transform the body.
8951 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8952 if (Body.isInvalid())
8953 return StmtError();
8954
8955 // If nothing change, just retain the current statement.
8956 if (!getDerived().AlwaysRebuild() &&
8957 Object.get() == S->getSynchExpr() &&
8958 Body.get() == S->getSynchBody())
8959 return S;
8960
8961 // Build a new statement.
8962 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
8963 Object.get(), Body.get());
8964}
8965
8966template<typename Derived>
8968TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
8969 ObjCAutoreleasePoolStmt *S) {
8970 // Transform the body.
8971 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
8972 if (Body.isInvalid())
8973 return StmtError();
8974
8975 // If nothing changed, just retain this statement.
8976 if (!getDerived().AlwaysRebuild() &&
8977 Body.get() == S->getSubStmt())
8978 return S;
8979
8980 // Build a new statement.
8981 return getDerived().RebuildObjCAutoreleasePoolStmt(
8982 S->getAtLoc(), Body.get());
8983}
8984
8985template<typename Derived>
8987TreeTransform<Derived>::TransformObjCForCollectionStmt(
8988 ObjCForCollectionStmt *S) {
8989 // Transform the element statement.
8990 StmtResult Element =
8991 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
8992 if (Element.isInvalid())
8993 return StmtError();
8994
8995 // Transform the collection expression.
8996 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
8997 if (Collection.isInvalid())
8998 return StmtError();
8999
9000 // Transform the body.
9001 StmtResult Body = getDerived().TransformStmt(S->getBody());
9002 if (Body.isInvalid())
9003 return StmtError();
9004
9005 // If nothing changed, just retain this statement.
9006 if (!getDerived().AlwaysRebuild() &&
9007 Element.get() == S->getElement() &&
9008 Collection.get() == S->getCollection() &&
9009 Body.get() == S->getBody())
9010 return S;
9011
9012 // Build a new statement.
9013 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9014 Element.get(),
9015 Collection.get(),
9016 S->getRParenLoc(),
9017 Body.get());
9018}
9019
9020template <typename Derived>
9021StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
9022 // Transform the exception declaration, if any.
9023 VarDecl *Var = nullptr;
9024 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9025 TypeSourceInfo *T =
9026 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9027 if (!T)
9028 return StmtError();
9029
9030 Var = getDerived().RebuildExceptionDecl(
9031 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9032 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9033 if (!Var || Var->isInvalidDecl())
9034 return StmtError();
9035 }
9036
9037 // Transform the actual exception handler.
9038 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9039 if (Handler.isInvalid())
9040 return StmtError();
9041
9042 if (!getDerived().AlwaysRebuild() && !Var &&
9043 Handler.get() == S->getHandlerBlock())
9044 return S;
9045
9046 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9047}
9048
9049template <typename Derived>
9050StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
9051 // Transform the try block itself.
9052 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9053 if (TryBlock.isInvalid())
9054 return StmtError();
9055
9056 // Transform the handlers.
9057 bool HandlerChanged = false;
9058 SmallVector<Stmt *, 8> Handlers;
9059 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9060 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9061 if (Handler.isInvalid())
9062 return StmtError();
9063
9064 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9065 Handlers.push_back(Handler.getAs<Stmt>());
9066 }
9067
9068 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9069 !HandlerChanged)
9070 return S;
9071
9072 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9073 Handlers);
9074}
9075
9076template<typename Derived>
9078TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
9079 EnterExpressionEvaluationContext ForRangeInitContext(
9081 /*LambdaContextDecl=*/nullptr,
9083 getSema().getLangOpts().CPlusPlus23);
9084
9085 // P2718R0 - Lifetime extension in range-based for loops.
9086 if (getSema().getLangOpts().CPlusPlus23) {
9087 auto &LastRecord = getSema().currentEvaluationContext();
9088 LastRecord.InLifetimeExtendingContext = true;
9089 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9090 }
9092 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9093 if (Init.isInvalid())
9094 return StmtError();
9095
9096 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9097 if (Range.isInvalid())
9098 return StmtError();
9099
9100 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9101 assert(getSema().getLangOpts().CPlusPlus23 ||
9102 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9103 auto ForRangeLifetimeExtendTemps =
9104 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9105
9106 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9107 if (Begin.isInvalid())
9108 return StmtError();
9109 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9110 if (End.isInvalid())
9111 return StmtError();
9112
9113 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9114 if (Cond.isInvalid())
9115 return StmtError();
9116 if (Cond.get())
9117 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9118 if (Cond.isInvalid())
9119 return StmtError();
9120 if (Cond.get())
9121 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9122
9123 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9124 if (Inc.isInvalid())
9125 return StmtError();
9126 if (Inc.get())
9127 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9128
9129 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9130 if (LoopVar.isInvalid())
9131 return StmtError();
9132
9133 StmtResult NewStmt = S;
9134 if (getDerived().AlwaysRebuild() ||
9135 Init.get() != S->getInit() ||
9136 Range.get() != S->getRangeStmt() ||
9137 Begin.get() != S->getBeginStmt() ||
9138 End.get() != S->getEndStmt() ||
9139 Cond.get() != S->getCond() ||
9140 Inc.get() != S->getInc() ||
9141 LoopVar.get() != S->getLoopVarStmt()) {
9142 NewStmt = getDerived().RebuildCXXForRangeStmt(
9143 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9144 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9145 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9146 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9147 // Might not have attached any initializer to the loop variable.
9148 getSema().ActOnInitializerError(
9149 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9150 return StmtError();
9151 }
9152 }
9153
9154 // OpenACC Restricts a while-loop inside of certain construct/clause
9155 // combinations, so diagnose that here in OpenACC mode.
9156 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
9157 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9158
9159 StmtResult Body = getDerived().TransformStmt(S->getBody());
9160 if (Body.isInvalid())
9161 return StmtError();
9162
9163 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9164
9165 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9166 // it now so we have a new statement to attach the body to.
9167 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9168 NewStmt = getDerived().RebuildCXXForRangeStmt(
9169 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9170 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9171 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9172 if (NewStmt.isInvalid())
9173 return StmtError();
9174 }
9175
9176 if (NewStmt.get() == S)
9177 return S;
9178
9179 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9180}
9181
9182template<typename Derived>
9184TreeTransform<Derived>::TransformMSDependentExistsStmt(
9185 MSDependentExistsStmt *S) {
9186 // Transform the nested-name-specifier, if any.
9187 NestedNameSpecifierLoc QualifierLoc;
9188 if (S->getQualifierLoc()) {
9189 QualifierLoc
9190 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9191 if (!QualifierLoc)
9192 return StmtError();
9193 }
9194
9195 // Transform the declaration name.
9196 DeclarationNameInfo NameInfo = S->getNameInfo();
9197 if (NameInfo.getName()) {
9198 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9199 if (!NameInfo.getName())
9200 return StmtError();
9201 }
9202
9203 // Check whether anything changed.
9204 if (!getDerived().AlwaysRebuild() &&
9205 QualifierLoc == S->getQualifierLoc() &&
9206 NameInfo.getName() == S->getNameInfo().getName())
9207 return S;
9208
9209 // Determine whether this name exists, if we can.
9210 CXXScopeSpec SS;
9211 SS.Adopt(QualifierLoc);
9212 bool Dependent = false;
9213 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9214 case Sema::IER_Exists:
9215 if (S->isIfExists())
9216 break;
9217
9218 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9219
9221 if (S->isIfNotExists())
9222 break;
9223
9224 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9225
9227 Dependent = true;
9228 break;
9229
9230 case Sema::IER_Error:
9231 return StmtError();
9232 }
9233
9234 // We need to continue with the instantiation, so do so now.
9235 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9236 if (SubStmt.isInvalid())
9237 return StmtError();
9238
9239 // If we have resolved the name, just transform to the substatement.
9240 if (!Dependent)
9241 return SubStmt;
9242
9243 // The name is still dependent, so build a dependent expression again.
9244 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9245 S->isIfExists(),
9246 QualifierLoc,
9247 NameInfo,
9248 SubStmt.get());
9249}
9250
9251template<typename Derived>
9253TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
9254 NestedNameSpecifierLoc QualifierLoc;
9255 if (E->getQualifierLoc()) {
9256 QualifierLoc
9257 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9258 if (!QualifierLoc)
9259 return ExprError();
9260 }
9261
9262 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9263 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9264 if (!PD)
9265 return ExprError();
9266
9267 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9268 if (Base.isInvalid())
9269 return ExprError();
9270
9271 return new (SemaRef.getASTContext())
9272 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9274 QualifierLoc, E->getMemberLoc());
9275}
9276
9277template <typename Derived>
9278ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
9279 MSPropertySubscriptExpr *E) {
9280 auto BaseRes = getDerived().TransformExpr(E->getBase());
9281 if (BaseRes.isInvalid())
9282 return ExprError();
9283 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9284 if (IdxRes.isInvalid())
9285 return ExprError();
9286
9287 if (!getDerived().AlwaysRebuild() &&
9288 BaseRes.get() == E->getBase() &&
9289 IdxRes.get() == E->getIdx())
9290 return E;
9291
9292 return getDerived().RebuildArraySubscriptExpr(
9293 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9294}
9295
9296template <typename Derived>
9297StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
9298 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9299 if (TryBlock.isInvalid())
9300 return StmtError();
9301
9302 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9303 if (Handler.isInvalid())
9304 return StmtError();
9305
9306 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9307 Handler.get() == S->getHandler())
9308 return S;
9309
9310 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9311 TryBlock.get(), Handler.get());
9312}
9313
9314template <typename Derived>
9315StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
9316 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9317 if (Block.isInvalid())
9318 return StmtError();
9319
9320 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9321}
9322
9323template <typename Derived>
9324StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
9325 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9326 if (FilterExpr.isInvalid())
9327 return StmtError();
9328
9329 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9330 if (Block.isInvalid())
9331 return StmtError();
9332
9333 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9334 Block.get());
9335}
9336
9337template <typename Derived>
9339 if (isa<SEHFinallyStmt>(Handler))
9340 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9341 else
9342 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9343}
9344
9345template<typename Derived>
9348 return S;
9349}
9350
9351//===----------------------------------------------------------------------===//
9352// OpenMP directive transformation
9353//===----------------------------------------------------------------------===//
9354
9355template <typename Derived>
9357TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9358 // OMPCanonicalLoops are eliminated during transformation, since they will be
9359 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9360 // after transformation.
9361 return getDerived().TransformStmt(L->getLoopStmt());
9362}
9363
9364template <typename Derived>
9367
9368 // Transform the clauses
9370 ArrayRef<OMPClause *> Clauses = D->clauses();
9371 TClauses.reserve(Clauses.size());
9372 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9373 I != E; ++I) {
9374 if (*I) {
9375 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9376 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9377 getDerived().getSema().OpenMP().EndOpenMPClause();
9378 if (Clause)
9379 TClauses.push_back(Clause);
9380 } else {
9381 TClauses.push_back(nullptr);
9382 }
9383 }
9384 StmtResult AssociatedStmt;
9385 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9386 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9387 D->getDirectiveKind(),
9388 /*CurScope=*/nullptr);
9389 StmtResult Body;
9390 {
9391 Sema::CompoundScopeRAII CompoundScope(getSema());
9392 Stmt *CS;
9393 if (D->getDirectiveKind() == OMPD_atomic ||
9394 D->getDirectiveKind() == OMPD_critical ||
9395 D->getDirectiveKind() == OMPD_section ||
9396 D->getDirectiveKind() == OMPD_master)
9397 CS = D->getAssociatedStmt();
9398 else
9399 CS = D->getRawStmt();
9400 Body = getDerived().TransformStmt(CS);
9401 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9402 getSema().getLangOpts().OpenMPIRBuilder)
9403 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9404 }
9405 AssociatedStmt =
9406 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9407 if (AssociatedStmt.isInvalid()) {
9408 return StmtError();
9409 }
9410 }
9411 if (TClauses.size() != Clauses.size()) {
9412 return StmtError();
9413 }
9414
9415 // Transform directive name for 'omp critical' directive.
9416 DeclarationNameInfo DirName;
9417 if (D->getDirectiveKind() == OMPD_critical) {
9418 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9419 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9420 }
9421 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9422 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9423 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9424 } else if (D->getDirectiveKind() == OMPD_cancel) {
9425 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9426 }
9427
9428 return getDerived().RebuildOMPExecutableDirective(
9429 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9430 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9431}
9432
9433/// This is mostly the same as above, but allows 'informational' class
9434/// directives when rebuilding the stmt. It still takes an
9435/// OMPExecutableDirective-type argument because we're reusing that as the
9436/// superclass for the 'assume' directive at present, instead of defining a
9437/// mostly-identical OMPInformationalDirective parent class.
9438template <typename Derived>
9441
9442 // Transform the clauses
9444 ArrayRef<OMPClause *> Clauses = D->clauses();
9445 TClauses.reserve(Clauses.size());
9446 for (OMPClause *C : Clauses) {
9447 if (C) {
9448 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9449 OMPClause *Clause = getDerived().TransformOMPClause(C);
9450 getDerived().getSema().OpenMP().EndOpenMPClause();
9451 if (Clause)
9452 TClauses.push_back(Clause);
9453 } else {
9454 TClauses.push_back(nullptr);
9455 }
9456 }
9457 StmtResult AssociatedStmt;
9458 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9459 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9460 D->getDirectiveKind(),
9461 /*CurScope=*/nullptr);
9462 StmtResult Body;
9463 {
9464 Sema::CompoundScopeRAII CompoundScope(getSema());
9465 assert(D->getDirectiveKind() == OMPD_assume &&
9466 "Unexpected informational directive");
9467 Stmt *CS = D->getAssociatedStmt();
9468 Body = getDerived().TransformStmt(CS);
9469 }
9470 AssociatedStmt =
9471 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9472 if (AssociatedStmt.isInvalid())
9473 return StmtError();
9474 }
9475 if (TClauses.size() != Clauses.size())
9476 return StmtError();
9477
9478 DeclarationNameInfo DirName;
9479
9480 return getDerived().RebuildOMPInformationalDirective(
9481 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9482 D->getBeginLoc(), D->getEndLoc());
9483}
9484
9485template <typename Derived>
9488 // TODO: Fix This
9489 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9490 << getOpenMPDirectiveName(D->getDirectiveKind());
9491 return StmtError();
9492}
9493
9494template <typename Derived>
9496TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9497 DeclarationNameInfo DirName;
9498 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9499 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9500 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9501 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9502 return Res;
9503}
9504
9505template <typename Derived>
9507TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
9508 DeclarationNameInfo DirName;
9509 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9510 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9511 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9512 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9513 return Res;
9514}
9515
9516template <typename Derived>
9518TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
9519 DeclarationNameInfo DirName;
9520 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9521 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9522 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9523 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9524 return Res;
9525}
9526
9527template <typename Derived>
9529TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {
9530 DeclarationNameInfo DirName;
9531 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9532 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9533 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9534 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9535 return Res;
9536}
9537
9538template <typename Derived>
9540TreeTransform<Derived>::TransformOMPReverseDirective(OMPReverseDirective *D) {
9541 DeclarationNameInfo DirName;
9542 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9543 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9544 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9545 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9546 return Res;
9547}
9548
9549template <typename Derived>
9550StmtResult TreeTransform<Derived>::TransformOMPInterchangeDirective(
9551 OMPInterchangeDirective *D) {
9552 DeclarationNameInfo DirName;
9553 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9554 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9555 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9556 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9557 return Res;
9558}
9559
9560template <typename Derived>
9562TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
9563 DeclarationNameInfo DirName;
9564 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9565 OMPD_for, DirName, nullptr, D->getBeginLoc());
9566 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9567 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9568 return Res;
9569}
9570
9571template <typename Derived>
9573TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
9574 DeclarationNameInfo DirName;
9575 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9576 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9577 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9578 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9579 return Res;
9580}
9581
9582template <typename Derived>
9584TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
9585 DeclarationNameInfo DirName;
9586 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9587 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9588 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9589 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9590 return Res;
9591}
9592
9593template <typename Derived>
9595TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
9596 DeclarationNameInfo DirName;
9597 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9598 OMPD_section, DirName, nullptr, D->getBeginLoc());
9599 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9600 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9601 return Res;
9602}
9603
9604template <typename Derived>
9606TreeTransform<Derived>::TransformOMPScopeDirective(OMPScopeDirective *D) {
9607 DeclarationNameInfo DirName;
9608 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9609 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9610 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9611 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9612 return Res;
9613}
9614
9615template <typename Derived>
9617TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
9618 DeclarationNameInfo DirName;
9619 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9620 OMPD_single, DirName, nullptr, D->getBeginLoc());
9621 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9622 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9623 return Res;
9624}
9625
9626template <typename Derived>
9628TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
9629 DeclarationNameInfo DirName;
9630 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9631 OMPD_master, 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>
9639TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
9640 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9641 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9642 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9643 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9644 return Res;
9645}
9646
9647template <typename Derived>
9648StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
9649 OMPParallelForDirective *D) {
9650 DeclarationNameInfo DirName;
9651 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9652 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9653 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9654 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9655 return Res;
9656}
9657
9658template <typename Derived>
9659StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
9660 OMPParallelForSimdDirective *D) {
9661 DeclarationNameInfo DirName;
9662 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9663 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9664 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9665 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9666 return Res;
9667}
9668
9669template <typename Derived>
9670StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
9671 OMPParallelMasterDirective *D) {
9672 DeclarationNameInfo DirName;
9673 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9674 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9675 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9676 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9677 return Res;
9678}
9679
9680template <typename Derived>
9681StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective(
9682 OMPParallelMaskedDirective *D) {
9683 DeclarationNameInfo DirName;
9684 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9685 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9686 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9687 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9688 return Res;
9689}
9690
9691template <typename Derived>
9692StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
9693 OMPParallelSectionsDirective *D) {
9694 DeclarationNameInfo DirName;
9695 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9696 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9697 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9698 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9699 return Res;
9700}
9701
9702template <typename Derived>
9704TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
9705 DeclarationNameInfo DirName;
9706 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9707 OMPD_task, DirName, nullptr, D->getBeginLoc());
9708 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9709 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9710 return Res;
9711}
9712
9713template <typename Derived>
9714StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
9715 OMPTaskyieldDirective *D) {
9716 DeclarationNameInfo DirName;
9717 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9718 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9719 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9720 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9721 return Res;
9722}
9723
9724template <typename Derived>
9726TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
9727 DeclarationNameInfo DirName;
9728 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9729 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9730 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9731 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9732 return Res;
9733}
9734
9735template <typename Derived>
9737TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
9738 DeclarationNameInfo DirName;
9739 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9740 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9741 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9742 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9743 return Res;
9744}
9745
9746template <typename Derived>
9748TreeTransform<Derived>::TransformOMPAssumeDirective(OMPAssumeDirective *D) {
9749 DeclarationNameInfo DirName;
9750 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9751 OMPD_assume, DirName, nullptr, D->getBeginLoc());
9752 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
9753 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9754 return Res;
9755}
9756
9757template <typename Derived>
9759TreeTransform<Derived>::TransformOMPErrorDirective(OMPErrorDirective *D) {
9760 DeclarationNameInfo DirName;
9761 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9762 OMPD_error, DirName, nullptr, D->getBeginLoc());
9763 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9764 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9765 return Res;
9766}
9767
9768template <typename Derived>
9769StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
9770 OMPTaskgroupDirective *D) {
9771 DeclarationNameInfo DirName;
9772 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9773 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9774 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9775 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9776 return Res;
9777}
9778
9779template <typename Derived>
9781TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
9782 DeclarationNameInfo DirName;
9783 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9784 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9785 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9786 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9787 return Res;
9788}
9789
9790template <typename Derived>
9792TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
9793 DeclarationNameInfo DirName;
9794 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9795 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9796 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9797 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9798 return Res;
9799}
9800
9801template <typename Derived>
9803TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
9804 DeclarationNameInfo DirName;
9805 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9806 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9807 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9808 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9809 return Res;
9810}
9811
9812template <typename Derived>
9814TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
9815 DeclarationNameInfo DirName;
9816 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9817 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9818 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9819 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9820 return Res;
9821}
9822
9823template <typename Derived>
9825TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
9826 DeclarationNameInfo DirName;
9827 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9828 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9829 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9830 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9831 return Res;
9832}
9833
9834template <typename Derived>
9836TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
9837 DeclarationNameInfo DirName;
9838 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9839 OMPD_target, DirName, nullptr, D->getBeginLoc());
9840 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9841 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9842 return Res;
9843}
9844
9845template <typename Derived>
9846StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
9847 OMPTargetDataDirective *D) {
9848 DeclarationNameInfo DirName;
9849 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9850 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
9851 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9852 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9853 return Res;
9854}
9855
9856template <typename Derived>
9857StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
9858 OMPTargetEnterDataDirective *D) {
9859 DeclarationNameInfo DirName;
9860 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9861 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
9862 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9863 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9864 return Res;
9865}
9866
9867template <typename Derived>
9868StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
9869 OMPTargetExitDataDirective *D) {
9870 DeclarationNameInfo DirName;
9871 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9872 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
9873 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9874 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9875 return Res;
9876}
9877
9878template <typename Derived>
9879StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
9880 OMPTargetParallelDirective *D) {
9881 DeclarationNameInfo DirName;
9882 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9883 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
9884 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9885 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9886 return Res;
9887}
9888
9889template <typename Derived>
9890StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
9891 OMPTargetParallelForDirective *D) {
9892 DeclarationNameInfo DirName;
9893 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9894 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
9895 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9896 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9897 return Res;
9898}
9899
9900template <typename Derived>
9901StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
9902 OMPTargetUpdateDirective *D) {
9903 DeclarationNameInfo DirName;
9904 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9905 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
9906 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9907 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9908 return Res;
9909}
9910
9911template <typename Derived>
9913TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
9914 DeclarationNameInfo DirName;
9915 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9916 OMPD_teams, DirName, nullptr, D->getBeginLoc());
9917 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9918 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9919 return Res;
9920}
9921
9922template <typename Derived>
9923StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
9924 OMPCancellationPointDirective *D) {
9925 DeclarationNameInfo DirName;
9926 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9927 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
9928 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9929 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9930 return Res;
9931}
9932
9933template <typename Derived>
9935TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
9936 DeclarationNameInfo DirName;
9937 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9938 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
9939 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9940 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9941 return Res;
9942}
9943
9944template <typename Derived>
9946TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
9947 DeclarationNameInfo DirName;
9948 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9949 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
9950 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9951 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9952 return Res;
9953}
9954
9955template <typename Derived>
9956StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
9957 OMPTaskLoopSimdDirective *D) {
9958 DeclarationNameInfo DirName;
9959 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9960 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9961 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9962 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9963 return Res;
9964}
9965
9966template <typename Derived>
9967StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
9968 OMPMasterTaskLoopDirective *D) {
9969 DeclarationNameInfo DirName;
9970 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9971 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
9972 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9973 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9974 return Res;
9975}
9976
9977template <typename Derived>
9978StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopDirective(
9979 OMPMaskedTaskLoopDirective *D) {
9980 DeclarationNameInfo DirName;
9981 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9982 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
9983 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9984 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9985 return Res;
9986}
9987
9988template <typename Derived>
9989StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
9990 OMPMasterTaskLoopSimdDirective *D) {
9991 DeclarationNameInfo DirName;
9992 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9993 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9994 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9995 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9996 return Res;
9997}
9998
9999template <typename Derived>
10000StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopSimdDirective(
10001 OMPMaskedTaskLoopSimdDirective *D) {
10002 DeclarationNameInfo DirName;
10003 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10004 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10005 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10006 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10007 return Res;
10008}
10009
10010template <typename Derived>
10011StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
10012 OMPParallelMasterTaskLoopDirective *D) {
10013 DeclarationNameInfo DirName;
10014 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10015 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10016 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10017 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10018 return Res;
10019}
10020
10021template <typename Derived>
10022StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopDirective(
10023 OMPParallelMaskedTaskLoopDirective *D) {
10024 DeclarationNameInfo DirName;
10025 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10026 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10027 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10028 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10029 return Res;
10030}
10031
10032template <typename Derived>
10034TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective(
10035 OMPParallelMasterTaskLoopSimdDirective *D) {
10036 DeclarationNameInfo DirName;
10037 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10038 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10039 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10040 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10041 return Res;
10042}
10043
10044template <typename Derived>
10046TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopSimdDirective(
10047 OMPParallelMaskedTaskLoopSimdDirective *D) {
10048 DeclarationNameInfo DirName;
10049 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10050 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10051 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10052 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10053 return Res;
10054}
10055
10056template <typename Derived>
10057StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
10058 OMPDistributeDirective *D) {
10059 DeclarationNameInfo DirName;
10060 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10061 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10062 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10063 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10064 return Res;
10065}
10066
10067template <typename Derived>
10068StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
10069 OMPDistributeParallelForDirective *D) {
10070 DeclarationNameInfo DirName;
10071 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10072 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10073 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10074 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10075 return Res;
10076}
10077
10078template <typename Derived>
10080TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
10081 OMPDistributeParallelForSimdDirective *D) {
10082 DeclarationNameInfo DirName;
10083 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10084 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10085 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10086 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10087 return Res;
10088}
10089
10090template <typename Derived>
10091StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
10092 OMPDistributeSimdDirective *D) {
10093 DeclarationNameInfo DirName;
10094 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10095 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10096 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10097 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10098 return Res;
10099}
10100
10101template <typename Derived>
10102StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
10103 OMPTargetParallelForSimdDirective *D) {
10104 DeclarationNameInfo DirName;
10105 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10106 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10107 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10108 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10109 return Res;
10110}
10111
10112template <typename Derived>
10113StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
10114 OMPTargetSimdDirective *D) {
10115 DeclarationNameInfo DirName;
10116 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10117 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10118 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10119 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10120 return Res;
10121}
10122
10123template <typename Derived>
10124StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
10125 OMPTeamsDistributeDirective *D) {
10126 DeclarationNameInfo DirName;
10127 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10128 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10129 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10130 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10131 return Res;
10132}
10133
10134template <typename Derived>
10135StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
10136 OMPTeamsDistributeSimdDirective *D) {
10137 DeclarationNameInfo DirName;
10138 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10139 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10140 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10141 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10142 return Res;
10143}
10144
10145template <typename Derived>
10146StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
10147 OMPTeamsDistributeParallelForSimdDirective *D) {
10148 DeclarationNameInfo DirName;
10149 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10150 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10151 D->getBeginLoc());
10152 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10153 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10154 return Res;
10155}
10156
10157template <typename Derived>
10158StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
10159 OMPTeamsDistributeParallelForDirective *D) {
10160 DeclarationNameInfo DirName;
10161 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10162 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10163 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10164 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10165 return Res;
10166}
10167
10168template <typename Derived>
10169StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
10170 OMPTargetTeamsDirective *D) {
10171 DeclarationNameInfo DirName;
10172 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10173 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10174 auto Res = getDerived().TransformOMPExecutableDirective(D);
10175 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10176 return Res;
10177}
10178
10179template <typename Derived>
10180StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
10181 OMPTargetTeamsDistributeDirective *D) {
10182 DeclarationNameInfo DirName;
10183 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10184 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10185 auto Res = getDerived().TransformOMPExecutableDirective(D);
10186 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10187 return Res;
10188}
10189
10190template <typename Derived>
10192TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
10193 OMPTargetTeamsDistributeParallelForDirective *D) {
10194 DeclarationNameInfo DirName;
10195 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10196 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10197 D->getBeginLoc());
10198 auto Res = getDerived().TransformOMPExecutableDirective(D);
10199 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10200 return Res;
10201}
10202
10203template <typename Derived>
10204StmtResult TreeTransform<Derived>::
10205 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
10206 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10207 DeclarationNameInfo DirName;
10208 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10209 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10210 D->getBeginLoc());
10211 auto Res = getDerived().TransformOMPExecutableDirective(D);
10212 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10213 return Res;
10214}
10215
10216template <typename Derived>
10218TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
10219 OMPTargetTeamsDistributeSimdDirective *D) {
10220 DeclarationNameInfo DirName;
10221 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10222 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10223 auto Res = getDerived().TransformOMPExecutableDirective(D);
10224 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10225 return Res;
10226}
10227
10228template <typename Derived>
10230TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
10231 DeclarationNameInfo DirName;
10232 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10233 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10234 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10235 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10236 return Res;
10237}
10238
10239template <typename Derived>
10241TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
10242 DeclarationNameInfo DirName;
10243 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10244 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10245 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10246 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10247 return Res;
10248}
10249
10250template <typename Derived>
10252TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
10253 DeclarationNameInfo DirName;
10254 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10255 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10256 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10257 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10258 return Res;
10259}
10260
10261template <typename Derived>
10262StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
10263 OMPGenericLoopDirective *D) {
10264 DeclarationNameInfo DirName;
10265 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10266 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10267 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10268 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10269 return Res;
10270}
10271
10272template <typename Derived>
10273StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective(
10274 OMPTeamsGenericLoopDirective *D) {
10275 DeclarationNameInfo DirName;
10276 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10277 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10278 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10279 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10280 return Res;
10281}
10282
10283template <typename Derived>
10284StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsGenericLoopDirective(
10285 OMPTargetTeamsGenericLoopDirective *D) {
10286 DeclarationNameInfo DirName;
10287 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10288 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10289 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10290 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10291 return Res;
10292}
10293
10294template <typename Derived>
10295StmtResult TreeTransform<Derived>::TransformOMPParallelGenericLoopDirective(
10296 OMPParallelGenericLoopDirective *D) {
10297 DeclarationNameInfo DirName;
10298 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10299 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10300 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10301 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10302 return Res;
10303}
10304
10305template <typename Derived>
10307TreeTransform<Derived>::TransformOMPTargetParallelGenericLoopDirective(
10308 OMPTargetParallelGenericLoopDirective *D) {
10309 DeclarationNameInfo DirName;
10310 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10311 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10312 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10313 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10314 return Res;
10315}
10316
10317//===----------------------------------------------------------------------===//
10318// OpenMP clause transformation
10319//===----------------------------------------------------------------------===//
10320template <typename Derived>
10321OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
10322 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10323 if (Cond.isInvalid())
10324 return nullptr;
10325 return getDerived().RebuildOMPIfClause(
10326 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10327 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10328}
10329
10330template <typename Derived>
10331OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
10332 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10333 if (Cond.isInvalid())
10334 return nullptr;
10335 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10336 C->getLParenLoc(), C->getEndLoc());
10337}
10338
10339template <typename Derived>
10340OMPClause *
10341TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
10342 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10343 if (NumThreads.isInvalid())
10344 return nullptr;
10345 return getDerived().RebuildOMPNumThreadsClause(
10346 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10347}
10348
10349template <typename Derived>
10350OMPClause *
10351TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
10352 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10353 if (E.isInvalid())
10354 return nullptr;
10355 return getDerived().RebuildOMPSafelenClause(
10356 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10357}
10358
10359template <typename Derived>
10360OMPClause *
10361TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
10362 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10363 if (E.isInvalid())
10364 return nullptr;
10365 return getDerived().RebuildOMPAllocatorClause(
10366 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10367}
10368
10369template <typename Derived>
10370OMPClause *
10371TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
10372 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10373 if (E.isInvalid())
10374 return nullptr;
10375 return getDerived().RebuildOMPSimdlenClause(
10376 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10377}
10378
10379template <typename Derived>
10380OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) {
10381 SmallVector<Expr *, 4> TransformedSizes;
10382 TransformedSizes.reserve(C->getNumSizes());
10383 bool Changed = false;
10384 for (Expr *E : C->getSizesRefs()) {
10385 if (!E) {
10386 TransformedSizes.push_back(nullptr);
10387 continue;
10388 }
10389
10390 ExprResult T = getDerived().TransformExpr(E);
10391 if (T.isInvalid())
10392 return nullptr;
10393 if (E != T.get())
10394 Changed = true;
10395 TransformedSizes.push_back(T.get());
10396 }
10397
10398 if (!Changed && !getDerived().AlwaysRebuild())
10399 return C;
10400 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10401 C->getLParenLoc(), C->getEndLoc());
10402}
10403
10404template <typename Derived>
10405OMPClause *
10406TreeTransform<Derived>::TransformOMPPermutationClause(OMPPermutationClause *C) {
10407 SmallVector<Expr *> TransformedArgs;
10408 TransformedArgs.reserve(C->getNumLoops());
10409 bool Changed = false;
10410 for (Expr *E : C->getArgsRefs()) {
10411 if (!E) {
10412 TransformedArgs.push_back(nullptr);
10413 continue;
10414 }
10415
10416 ExprResult T = getDerived().TransformExpr(E);
10417 if (T.isInvalid())
10418 return nullptr;
10419 if (E != T.get())
10420 Changed = true;
10421 TransformedArgs.push_back(T.get());
10422 }
10423
10424 if (!Changed && !getDerived().AlwaysRebuild())
10425 return C;
10426 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10427 C->getLParenLoc(), C->getEndLoc());
10428}
10429
10430template <typename Derived>
10431OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) {
10432 if (!getDerived().AlwaysRebuild())
10433 return C;
10434 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10435}
10436
10437template <typename Derived>
10438OMPClause *
10439TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
10440 ExprResult T = getDerived().TransformExpr(C->getFactor());
10441 if (T.isInvalid())
10442 return nullptr;
10443 Expr *Factor = T.get();
10444 bool Changed = Factor != C->getFactor();
10445
10446 if (!Changed && !getDerived().AlwaysRebuild())
10447 return C;
10448 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10449 C->getEndLoc());
10450}
10451
10452template <typename Derived>
10453OMPClause *
10454TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
10455 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10456 if (E.isInvalid())
10457 return nullptr;
10458 return getDerived().RebuildOMPCollapseClause(
10459 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10460}
10461
10462template <typename Derived>
10463OMPClause *
10464TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
10465 return getDerived().RebuildOMPDefaultClause(
10466 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
10467 C->getLParenLoc(), C->getEndLoc());
10468}
10469
10470template <typename Derived>
10471OMPClause *
10472TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
10473 return getDerived().RebuildOMPProcBindClause(
10474 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10475 C->getLParenLoc(), C->getEndLoc());
10476}
10477
10478template <typename Derived>
10479OMPClause *
10480TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
10481 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10482 if (E.isInvalid())
10483 return nullptr;
10484 return getDerived().RebuildOMPScheduleClause(
10485 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10486 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10487 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10488 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10489}
10490
10491template <typename Derived>
10492OMPClause *
10493TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
10494 ExprResult E;
10495 if (auto *Num = C->getNumForLoops()) {
10496 E = getDerived().TransformExpr(Num);
10497 if (E.isInvalid())
10498 return nullptr;
10499 }
10500 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10501 C->getLParenLoc(), E.get());
10502}
10503
10504template <typename Derived>
10505OMPClause *
10506TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
10507 ExprResult E;
10508 if (Expr *Evt = C->getEventHandler()) {
10509 E = getDerived().TransformExpr(Evt);
10510 if (E.isInvalid())
10511 return nullptr;
10512 }
10513 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10514 C->getLParenLoc(), C->getEndLoc());
10515}
10516
10517template <typename Derived>
10518OMPClause *
10519TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
10520 // No need to rebuild this clause, no template-dependent parameters.
10521 return C;
10522}
10523
10524template <typename Derived>
10525OMPClause *
10526TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
10527 // No need to rebuild this clause, no template-dependent parameters.
10528 return C;
10529}
10530
10531template <typename Derived>
10532OMPClause *
10533TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
10534 // No need to rebuild this clause, no template-dependent parameters.
10535 return C;
10536}
10537
10538template <typename Derived>
10539OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
10540 // No need to rebuild this clause, no template-dependent parameters.
10541 return C;
10542}
10543
10544template <typename Derived>
10545OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
10546 // No need to rebuild this clause, no template-dependent parameters.
10547 return C;
10548}
10549
10550template <typename Derived>
10551OMPClause *
10552TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
10553 // No need to rebuild this clause, no template-dependent parameters.
10554 return C;
10555}
10556
10557template <typename Derived>
10558OMPClause *
10559TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
10560 // No need to rebuild this clause, no template-dependent parameters.
10561 return C;
10562}
10563
10564template <typename Derived>
10565OMPClause *
10566TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
10567 // No need to rebuild this clause, no template-dependent parameters.
10568 return C;
10569}
10570
10571template <typename Derived>
10572OMPClause *TreeTransform<Derived>::TransformOMPFailClause(OMPFailClause *C) {
10573 // No need to rebuild this clause, no template-dependent parameters.
10574 return C;
10575}
10576
10577template <typename Derived>
10578OMPClause *
10579TreeTransform<Derived>::TransformOMPAbsentClause(OMPAbsentClause *C) {
10580 return C;
10581}
10582
10583template <typename Derived>
10584OMPClause *TreeTransform<Derived>::TransformOMPHoldsClause(OMPHoldsClause *C) {
10585 ExprResult E = getDerived().TransformExpr(C->getExpr());
10586 if (E.isInvalid())
10587 return nullptr;
10588 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
10589 C->getLParenLoc(), C->getEndLoc());
10590}
10591
10592template <typename Derived>
10593OMPClause *
10594TreeTransform<Derived>::TransformOMPContainsClause(OMPContainsClause *C) {
10595 return C;
10596}
10597
10598template <typename Derived>
10599OMPClause *
10600TreeTransform<Derived>::TransformOMPNoOpenMPClause(OMPNoOpenMPClause *C) {
10601 return C;
10602}
10603template <typename Derived>
10604OMPClause *TreeTransform<Derived>::TransformOMPNoOpenMPRoutinesClause(
10605 OMPNoOpenMPRoutinesClause *C) {
10606 return C;
10607}
10608template <typename Derived>
10609OMPClause *TreeTransform<Derived>::TransformOMPNoParallelismClause(
10610 OMPNoParallelismClause *C) {
10611 return C;
10612}
10613
10614template <typename Derived>
10615OMPClause *
10616TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
10617 // No need to rebuild this clause, no template-dependent parameters.
10618 return C;
10619}
10620
10621template <typename Derived>
10622OMPClause *
10623TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
10624 // No need to rebuild this clause, no template-dependent parameters.
10625 return C;
10626}
10627
10628template <typename Derived>
10629OMPClause *
10630TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
10631 // No need to rebuild this clause, no template-dependent parameters.
10632 return C;
10633}
10634
10635template <typename Derived>
10636OMPClause *
10637TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
10638 // No need to rebuild this clause, no template-dependent parameters.
10639 return C;
10640}
10641
10642template <typename Derived>
10643OMPClause *
10644TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
10645 // No need to rebuild this clause, no template-dependent parameters.
10646 return C;
10647}
10648
10649template <typename Derived>
10650OMPClause *TreeTransform<Derived>::TransformOMPWeakClause(OMPWeakClause *C) {
10651 // No need to rebuild this clause, no template-dependent parameters.
10652 return C;
10653}
10654
10655template <typename Derived>
10656OMPClause *
10657TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
10658 // No need to rebuild this clause, no template-dependent parameters.
10659 return C;
10660}
10661
10662template <typename Derived>
10663OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
10664 // No need to rebuild this clause, no template-dependent parameters.
10665 return C;
10666}
10667
10668template <typename Derived>
10669OMPClause *
10670TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
10671 // No need to rebuild this clause, no template-dependent parameters.
10672 return C;
10673}
10674
10675template <typename Derived>
10676OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
10677 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10678 if (IVR.isInvalid())
10679 return nullptr;
10680
10681 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10682 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10683 for (Expr *E : llvm::drop_begin(C->varlist())) {
10684 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10685 if (ER.isInvalid())
10686 return nullptr;
10687 InteropInfo.PreferTypes.push_back(ER.get());
10688 }
10689 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10690 C->getBeginLoc(), C->getLParenLoc(),
10691 C->getVarLoc(), C->getEndLoc());
10692}
10693
10694template <typename Derived>
10695OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) {
10696 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10697 if (ER.isInvalid())
10698 return nullptr;
10699 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10700 C->getLParenLoc(), C->getVarLoc(),
10701 C->getEndLoc());
10702}
10703
10704template <typename Derived>
10705OMPClause *
10706TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
10707 ExprResult ER;
10708 if (Expr *IV = C->getInteropVar()) {
10709 ER = getDerived().TransformExpr(IV);
10710 if (ER.isInvalid())
10711 return nullptr;
10712 }
10713 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10714 C->getLParenLoc(), C->getVarLoc(),
10715 C->getEndLoc());
10716}
10717
10718template <typename Derived>
10719OMPClause *
10720TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
10721 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10722 if (Cond.isInvalid())
10723 return nullptr;
10724 return getDerived().RebuildOMPNovariantsClause(
10725 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10726}
10727
10728template <typename Derived>
10729OMPClause *
10730TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
10731 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10732 if (Cond.isInvalid())
10733 return nullptr;
10734 return getDerived().RebuildOMPNocontextClause(
10735 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10736}
10737
10738template <typename Derived>
10739OMPClause *
10740TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
10741 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10742 if (ThreadID.isInvalid())
10743 return nullptr;
10744 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10745 C->getLParenLoc(), C->getEndLoc());
10746}
10747
10748template <typename Derived>
10749OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) {
10750 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10751 if (E.isInvalid())
10752 return nullptr;
10753 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10754 C->getLParenLoc(), C->getEndLoc());
10755}
10756
10757template <typename Derived>
10758OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
10759 OMPUnifiedAddressClause *C) {
10760 llvm_unreachable("unified_address clause cannot appear in dependent context");
10761}
10762
10763template <typename Derived>
10764OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
10765 OMPUnifiedSharedMemoryClause *C) {
10766 llvm_unreachable(
10767 "unified_shared_memory clause cannot appear in dependent context");
10768}
10769
10770template <typename Derived>
10771OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
10772 OMPReverseOffloadClause *C) {
10773 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10774}
10775
10776template <typename Derived>
10777OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
10778 OMPDynamicAllocatorsClause *C) {
10779 llvm_unreachable(
10780 "dynamic_allocators clause cannot appear in dependent context");
10781}
10782
10783template <typename Derived>
10784OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
10785 OMPAtomicDefaultMemOrderClause *C) {
10786 llvm_unreachable(
10787 "atomic_default_mem_order clause cannot appear in dependent context");
10788}
10789
10790template <typename Derived>
10791OMPClause *TreeTransform<Derived>::TransformOMPAtClause(OMPAtClause *C) {
10792 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10793 C->getBeginLoc(), C->getLParenLoc(),
10794 C->getEndLoc());
10795}
10796
10797template <typename Derived>
10798OMPClause *
10799TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) {
10800 return getDerived().RebuildOMPSeverityClause(
10801 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10802 C->getLParenLoc(), C->getEndLoc());
10803}
10804
10805template <typename Derived>
10806OMPClause *
10807TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) {
10808 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10809 if (E.isInvalid())
10810 return nullptr;
10811 return getDerived().RebuildOMPMessageClause(
10812 C->getMessageString(), C->getBeginLoc(), C->getLParenLoc(),
10813 C->getEndLoc());
10814}
10815
10816template <typename Derived>
10817OMPClause *
10818TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
10820 Vars.reserve(C->varlist_size());
10821 for (auto *VE : C->varlist()) {
10822 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10823 if (EVar.isInvalid())
10824 return nullptr;
10825 Vars.push_back(EVar.get());
10826 }
10827 return getDerived().RebuildOMPPrivateClause(
10828 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10829}
10830
10831template <typename Derived>
10832OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
10833 OMPFirstprivateClause *C) {
10835 Vars.reserve(C->varlist_size());
10836 for (auto *VE : C->varlist()) {
10837 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10838 if (EVar.isInvalid())
10839 return nullptr;
10840 Vars.push_back(EVar.get());
10841 }
10842 return getDerived().RebuildOMPFirstprivateClause(
10843 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10844}
10845
10846template <typename Derived>
10847OMPClause *
10848TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
10850 Vars.reserve(C->varlist_size());
10851 for (auto *VE : C->varlist()) {
10852 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10853 if (EVar.isInvalid())
10854 return nullptr;
10855 Vars.push_back(EVar.get());
10856 }
10857 return getDerived().RebuildOMPLastprivateClause(
10858 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
10859 C->getLParenLoc(), C->getEndLoc());
10860}
10861
10862template <typename Derived>
10863OMPClause *
10864TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
10866 Vars.reserve(C->varlist_size());
10867 for (auto *VE : C->varlist()) {
10868 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10869 if (EVar.isInvalid())
10870 return nullptr;
10871 Vars.push_back(EVar.get());
10872 }
10873 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
10874 C->getLParenLoc(), C->getEndLoc());
10875}
10876
10877template <typename Derived>
10878OMPClause *
10879TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
10881 Vars.reserve(C->varlist_size());
10882 for (auto *VE : C->varlist()) {
10883 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10884 if (EVar.isInvalid())
10885 return nullptr;
10886 Vars.push_back(EVar.get());
10887 }
10888 CXXScopeSpec ReductionIdScopeSpec;
10889 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10890
10891 DeclarationNameInfo NameInfo = C->getNameInfo();
10892 if (NameInfo.getName()) {
10893 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10894 if (!NameInfo.getName())
10895 return nullptr;
10896 }
10897 // Build a list of all UDR decls with the same names ranged by the Scopes.
10898 // The Scope boundary is a duplication of the previous decl.
10899 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10900 for (auto *E : C->reduction_ops()) {
10901 // Transform all the decls.
10902 if (E) {
10903 auto *ULE = cast<UnresolvedLookupExpr>(E);
10904 UnresolvedSet<8> Decls;
10905 for (auto *D : ULE->decls()) {
10906 NamedDecl *InstD =
10907 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10908 Decls.addDecl(InstD, InstD->getAccess());
10909 }
10910 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10911 SemaRef.Context, /*NamingClass=*/nullptr,
10912 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10913 /*ADL=*/true, Decls.begin(), Decls.end(),
10914 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10915 } else
10916 UnresolvedReductions.push_back(nullptr);
10917 }
10918 return getDerived().RebuildOMPReductionClause(
10919 Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(),
10920 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
10921 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10922}
10923
10924template <typename Derived>
10925OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
10926 OMPTaskReductionClause *C) {
10928 Vars.reserve(C->varlist_size());
10929 for (auto *VE : C->varlist()) {
10930 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10931 if (EVar.isInvalid())
10932 return nullptr;
10933 Vars.push_back(EVar.get());
10934 }
10935 CXXScopeSpec ReductionIdScopeSpec;
10936 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10937
10938 DeclarationNameInfo NameInfo = C->getNameInfo();
10939 if (NameInfo.getName()) {
10940 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10941 if (!NameInfo.getName())
10942 return nullptr;
10943 }
10944 // Build a list of all UDR decls with the same names ranged by the Scopes.
10945 // The Scope boundary is a duplication of the previous decl.
10946 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10947 for (auto *E : C->reduction_ops()) {
10948 // Transform all the decls.
10949 if (E) {
10950 auto *ULE = cast<UnresolvedLookupExpr>(E);
10951 UnresolvedSet<8> Decls;
10952 for (auto *D : ULE->decls()) {
10953 NamedDecl *InstD =
10954 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10955 Decls.addDecl(InstD, InstD->getAccess());
10956 }
10957 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10958 SemaRef.Context, /*NamingClass=*/nullptr,
10959 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10960 /*ADL=*/true, Decls.begin(), Decls.end(),
10961 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10962 } else
10963 UnresolvedReductions.push_back(nullptr);
10964 }
10965 return getDerived().RebuildOMPTaskReductionClause(
10966 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10967 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10968}
10969
10970template <typename Derived>
10971OMPClause *
10972TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
10974 Vars.reserve(C->varlist_size());
10975 for (auto *VE : C->varlist()) {
10976 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10977 if (EVar.isInvalid())
10978 return nullptr;
10979 Vars.push_back(EVar.get());
10980 }
10981 CXXScopeSpec ReductionIdScopeSpec;
10982 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10983
10984 DeclarationNameInfo NameInfo = C->getNameInfo();
10985 if (NameInfo.getName()) {
10986 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10987 if (!NameInfo.getName())
10988 return nullptr;
10989 }
10990 // Build a list of all UDR decls with the same names ranged by the Scopes.
10991 // The Scope boundary is a duplication of the previous decl.
10992 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10993 for (auto *E : C->reduction_ops()) {
10994 // Transform all the decls.
10995 if (E) {
10996 auto *ULE = cast<UnresolvedLookupExpr>(E);
10997 UnresolvedSet<8> Decls;
10998 for (auto *D : ULE->decls()) {
10999 NamedDecl *InstD =
11000 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11001 Decls.addDecl(InstD, InstD->getAccess());
11002 }
11003 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11004 SemaRef.Context, /*NamingClass=*/nullptr,
11005 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11006 /*ADL=*/true, Decls.begin(), Decls.end(),
11007 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11008 } else
11009 UnresolvedReductions.push_back(nullptr);
11010 }
11011 return getDerived().RebuildOMPInReductionClause(
11012 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11013 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11014}
11015
11016template <typename Derived>
11017OMPClause *
11018TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
11020 Vars.reserve(C->varlist_size());
11021 for (auto *VE : C->varlist()) {
11022 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11023 if (EVar.isInvalid())
11024 return nullptr;
11025 Vars.push_back(EVar.get());
11026 }
11027 ExprResult Step = getDerived().TransformExpr(C->getStep());
11028 if (Step.isInvalid())
11029 return nullptr;
11030 return getDerived().RebuildOMPLinearClause(
11031 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11032 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11033 C->getEndLoc());
11034}
11035
11036template <typename Derived>
11037OMPClause *
11038TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
11040 Vars.reserve(C->varlist_size());
11041 for (auto *VE : C->varlist()) {
11042 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11043 if (EVar.isInvalid())
11044 return nullptr;
11045 Vars.push_back(EVar.get());
11046 }
11047 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11048 if (Alignment.isInvalid())
11049 return nullptr;
11050 return getDerived().RebuildOMPAlignedClause(
11051 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11052 C->getColonLoc(), C->getEndLoc());
11053}
11054
11055template <typename Derived>
11056OMPClause *
11057TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
11059 Vars.reserve(C->varlist_size());
11060 for (auto *VE : C->varlist()) {
11061 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11062 if (EVar.isInvalid())
11063 return nullptr;
11064 Vars.push_back(EVar.get());
11065 }
11066 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11067 C->getLParenLoc(), C->getEndLoc());
11068}
11069
11070template <typename Derived>
11071OMPClause *
11072TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
11074 Vars.reserve(C->varlist_size());
11075 for (auto *VE : C->varlist()) {
11076 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11077 if (EVar.isInvalid())
11078 return nullptr;
11079 Vars.push_back(EVar.get());
11080 }
11081 return getDerived().RebuildOMPCopyprivateClause(
11082 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11083}
11084
11085template <typename Derived>
11086OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
11088 Vars.reserve(C->varlist_size());
11089 for (auto *VE : C->varlist()) {
11090 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11091 if (EVar.isInvalid())
11092 return nullptr;
11093 Vars.push_back(EVar.get());
11094 }
11095 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11096 C->getLParenLoc(), C->getEndLoc());
11097}
11098
11099template <typename Derived>
11100OMPClause *
11101TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
11102 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11103 if (E.isInvalid())
11104 return nullptr;
11105 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11106 C->getLParenLoc(), C->getEndLoc());
11107}
11108
11109template <typename Derived>
11110OMPClause *
11111TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
11113 Expr *DepModifier = C->getModifier();
11114 if (DepModifier) {
11115 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11116 if (DepModRes.isInvalid())
11117 return nullptr;
11118 DepModifier = DepModRes.get();
11119 }
11120 Vars.reserve(C->varlist_size());
11121 for (auto *VE : C->varlist()) {
11122 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11123 if (EVar.isInvalid())
11124 return nullptr;
11125 Vars.push_back(EVar.get());
11126 }
11127 return getDerived().RebuildOMPDependClause(
11128 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11129 C->getOmpAllMemoryLoc()},
11130 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11131}
11132
11133template <typename Derived>
11134OMPClause *
11135TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
11136 ExprResult E = getDerived().TransformExpr(C->getDevice());
11137 if (E.isInvalid())
11138 return nullptr;
11139 return getDerived().RebuildOMPDeviceClause(
11140 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11141 C->getModifierLoc(), C->getEndLoc());
11142}
11143
11144template <typename Derived, class T>
11147 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11148 DeclarationNameInfo &MapperIdInfo,
11149 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11150 // Transform expressions in the list.
11151 Vars.reserve(C->varlist_size());
11152 for (auto *VE : C->varlist()) {
11153 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11154 if (EVar.isInvalid())
11155 return true;
11156 Vars.push_back(EVar.get());
11157 }
11158 // Transform mapper scope specifier and identifier.
11159 NestedNameSpecifierLoc QualifierLoc;
11160 if (C->getMapperQualifierLoc()) {
11161 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11162 C->getMapperQualifierLoc());
11163 if (!QualifierLoc)
11164 return true;
11165 }
11166 MapperIdScopeSpec.Adopt(QualifierLoc);
11167 MapperIdInfo = C->getMapperIdInfo();
11168 if (MapperIdInfo.getName()) {
11169 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11170 if (!MapperIdInfo.getName())
11171 return true;
11172 }
11173 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11174 // the previous user-defined mapper lookup in dependent environment.
11175 for (auto *E : C->mapperlists()) {
11176 // Transform all the decls.
11177 if (E) {
11178 auto *ULE = cast<UnresolvedLookupExpr>(E);
11179 UnresolvedSet<8> Decls;
11180 for (auto *D : ULE->decls()) {
11181 NamedDecl *InstD =
11182 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11183 Decls.addDecl(InstD, InstD->getAccess());
11184 }
11185 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11186 TT.getSema().Context, /*NamingClass=*/nullptr,
11187 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11188 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11189 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11190 } else {
11191 UnresolvedMappers.push_back(nullptr);
11192 }
11193 }
11194 return false;
11195}
11196
11197template <typename Derived>
11198OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11199 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11201 Expr *IteratorModifier = C->getIteratorModifier();
11202 if (IteratorModifier) {
11203 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11204 if (MapModRes.isInvalid())
11205 return nullptr;
11206 IteratorModifier = MapModRes.get();
11207 }
11208 CXXScopeSpec MapperIdScopeSpec;
11209 DeclarationNameInfo MapperIdInfo;
11210 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11211 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
11212 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11213 return nullptr;
11214 return getDerived().RebuildOMPMapClause(
11215 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11216 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11217 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11218}
11219
11220template <typename Derived>
11221OMPClause *
11222TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
11223 Expr *Allocator = C->getAllocator();
11224 if (Allocator) {
11225 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11226 if (AllocatorRes.isInvalid())
11227 return nullptr;
11228 Allocator = AllocatorRes.get();
11229 }
11230 Expr *Alignment = C->getAlignment();
11231 if (Alignment) {
11232 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
11233 if (AlignmentRes.isInvalid())
11234 return nullptr;
11235 Alignment = AlignmentRes.get();
11236 }
11238 Vars.reserve(C->varlist_size());
11239 for (auto *VE : C->varlist()) {
11240 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11241 if (EVar.isInvalid())
11242 return nullptr;
11243 Vars.push_back(EVar.get());
11244 }
11245 return getDerived().RebuildOMPAllocateClause(
11246 Allocator, Alignment, C->getFirstAllocateModifier(),
11247 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
11248 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
11249 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11250}
11251
11252template <typename Derived>
11253OMPClause *
11254TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
11256 Vars.reserve(C->varlist_size());
11257 for (auto *VE : C->varlist()) {
11258 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11259 if (EVar.isInvalid())
11260 return nullptr;
11261 Vars.push_back(EVar.get());
11262 }
11263 return getDerived().RebuildOMPNumTeamsClause(
11264 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11265}
11266
11267template <typename Derived>
11268OMPClause *
11269TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
11271 Vars.reserve(C->varlist_size());
11272 for (auto *VE : C->varlist()) {
11273 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11274 if (EVar.isInvalid())
11275 return nullptr;
11276 Vars.push_back(EVar.get());
11277 }
11278 return getDerived().RebuildOMPThreadLimitClause(
11279 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11280}
11281
11282template <typename Derived>
11283OMPClause *
11284TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
11285 ExprResult E = getDerived().TransformExpr(C->getPriority());
11286 if (E.isInvalid())
11287 return nullptr;
11288 return getDerived().RebuildOMPPriorityClause(
11289 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11290}
11291
11292template <typename Derived>
11293OMPClause *
11294TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
11295 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11296 if (E.isInvalid())
11297 return nullptr;
11298 return getDerived().RebuildOMPGrainsizeClause(
11299 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11300 C->getModifierLoc(), C->getEndLoc());
11301}
11302
11303template <typename Derived>
11304OMPClause *
11305TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
11306 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11307 if (E.isInvalid())
11308 return nullptr;
11309 return getDerived().RebuildOMPNumTasksClause(
11310 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11311 C->getModifierLoc(), C->getEndLoc());
11312}
11313
11314template <typename Derived>
11315OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
11316 ExprResult E = getDerived().TransformExpr(C->getHint());
11317 if (E.isInvalid())
11318 return nullptr;
11319 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11320 C->getLParenLoc(), C->getEndLoc());
11321}
11322
11323template <typename Derived>
11324OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
11325 OMPDistScheduleClause *C) {
11326 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11327 if (E.isInvalid())
11328 return nullptr;
11329 return getDerived().RebuildOMPDistScheduleClause(
11330 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11331 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11332}
11333
11334template <typename Derived>
11335OMPClause *
11336TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
11337 // Rebuild Defaultmap Clause since we need to invoke the checking of
11338 // defaultmap(none:variable-category) after template initialization.
11339 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11340 C->getDefaultmapKind(),
11341 C->getBeginLoc(),
11342 C->getLParenLoc(),
11343 C->getDefaultmapModifierLoc(),
11344 C->getDefaultmapKindLoc(),
11345 C->getEndLoc());
11346}
11347
11348template <typename Derived>
11349OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
11350 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11352 CXXScopeSpec MapperIdScopeSpec;
11353 DeclarationNameInfo MapperIdInfo;
11354 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11355 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
11356 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11357 return nullptr;
11358 return getDerived().RebuildOMPToClause(
11359 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11360 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11361}
11362
11363template <typename Derived>
11364OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
11365 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11367 CXXScopeSpec MapperIdScopeSpec;
11368 DeclarationNameInfo MapperIdInfo;
11369 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11370 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
11371 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11372 return nullptr;
11373 return getDerived().RebuildOMPFromClause(
11374 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11375 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11376}
11377
11378template <typename Derived>
11379OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
11380 OMPUseDevicePtrClause *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().RebuildOMPUseDevicePtrClause(Vars, Locs);
11391}
11392
11393template <typename Derived>
11394OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause(
11395 OMPUseDeviceAddrClause *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().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11406}
11407
11408template <typename Derived>
11409OMPClause *
11410TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *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 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11420 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11421}
11422
11423template <typename Derived>
11424OMPClause *TreeTransform<Derived>::TransformOMPHasDeviceAddrClause(
11425 OMPHasDeviceAddrClause *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 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11435 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11436}
11437
11438template <typename Derived>
11439OMPClause *
11440TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *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().RebuildOMPNontemporalClause(
11450 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11451}
11452
11453template <typename Derived>
11454OMPClause *
11455TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) {
11457 Vars.reserve(C->varlist_size());
11458 for (auto *VE : C->varlist()) {
11459 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11460 if (EVar.isInvalid())
11461 return nullptr;
11462 Vars.push_back(EVar.get());
11463 }
11464 return getDerived().RebuildOMPInclusiveClause(
11465 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11466}
11467
11468template <typename Derived>
11469OMPClause *
11470TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) {
11472 Vars.reserve(C->varlist_size());
11473 for (auto *VE : C->varlist()) {
11474 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11475 if (EVar.isInvalid())
11476 return nullptr;
11477 Vars.push_back(EVar.get());
11478 }
11479 return getDerived().RebuildOMPExclusiveClause(
11480 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11481}
11482
11483template <typename Derived>
11484OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause(
11485 OMPUsesAllocatorsClause *C) {
11487 Data.reserve(C->getNumberOfAllocators());
11488 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11489 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11490 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11491 if (Allocator.isInvalid())
11492 continue;
11493 ExprResult AllocatorTraits;
11494 if (Expr *AT = D.AllocatorTraits) {
11495 AllocatorTraits = getDerived().TransformExpr(AT);
11496 if (AllocatorTraits.isInvalid())
11497 continue;
11498 }
11499 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11500 NewD.Allocator = Allocator.get();
11501 NewD.AllocatorTraits = AllocatorTraits.get();
11502 NewD.LParenLoc = D.LParenLoc;
11503 NewD.RParenLoc = D.RParenLoc;
11504 }
11505 return getDerived().RebuildOMPUsesAllocatorsClause(
11506 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11507}
11508
11509template <typename Derived>
11510OMPClause *
11511TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) {
11512 SmallVector<Expr *, 4> Locators;
11513 Locators.reserve(C->varlist_size());
11514 ExprResult ModifierRes;
11515 if (Expr *Modifier = C->getModifier()) {
11516 ModifierRes = getDerived().TransformExpr(Modifier);
11517 if (ModifierRes.isInvalid())
11518 return nullptr;
11519 }
11520 for (Expr *E : C->varlist()) {
11521 ExprResult Locator = getDerived().TransformExpr(E);
11522 if (Locator.isInvalid())
11523 continue;
11524 Locators.push_back(Locator.get());
11525 }
11526 return getDerived().RebuildOMPAffinityClause(
11527 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11528 ModifierRes.get(), Locators);
11529}
11530
11531template <typename Derived>
11532OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) {
11533 return getDerived().RebuildOMPOrderClause(
11534 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11535 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11536}
11537
11538template <typename Derived>
11539OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) {
11540 return getDerived().RebuildOMPBindClause(
11541 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11542 C->getLParenLoc(), C->getEndLoc());
11543}
11544
11545template <typename Derived>
11546OMPClause *TreeTransform<Derived>::TransformOMPXDynCGroupMemClause(
11547 OMPXDynCGroupMemClause *C) {
11548 ExprResult Size = getDerived().TransformExpr(C->getSize());
11549 if (Size.isInvalid())
11550 return nullptr;
11551 return getDerived().RebuildOMPXDynCGroupMemClause(
11552 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11553}
11554
11555template <typename Derived>
11556OMPClause *
11557TreeTransform<Derived>::TransformOMPDoacrossClause(OMPDoacrossClause *C) {
11559 Vars.reserve(C->varlist_size());
11560 for (auto *VE : C->varlist()) {
11561 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11562 if (EVar.isInvalid())
11563 return nullptr;
11564 Vars.push_back(EVar.get());
11565 }
11566 return getDerived().RebuildOMPDoacrossClause(
11567 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11568 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11569}
11570
11571template <typename Derived>
11572OMPClause *
11573TreeTransform<Derived>::TransformOMPXAttributeClause(OMPXAttributeClause *C) {
11575 for (auto *A : C->getAttrs())
11576 NewAttrs.push_back(getDerived().TransformAttr(A));
11577 return getDerived().RebuildOMPXAttributeClause(
11578 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11579}
11580
11581template <typename Derived>
11582OMPClause *TreeTransform<Derived>::TransformOMPXBareClause(OMPXBareClause *C) {
11583 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11584}
11585
11586//===----------------------------------------------------------------------===//
11587// OpenACC transformation
11588//===----------------------------------------------------------------------===//
11589namespace {
11590template <typename Derived>
11591class OpenACCClauseTransform final
11592 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11593 TreeTransform<Derived> &Self;
11594 ArrayRef<const OpenACCClause *> ExistingClauses;
11595 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11596 OpenACCClause *NewClause = nullptr;
11597
11598 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11599 llvm::SmallVector<Expr *> InstantiatedVarList;
11600 for (Expr *CurVar : VarList) {
11601 ExprResult Res = Self.TransformExpr(CurVar);
11602
11603 if (!Res.isUsable())
11604 continue;
11605
11606 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getClauseKind(),
11607 Res.get());
11608
11609 if (Res.isUsable())
11610 InstantiatedVarList.push_back(Res.get());
11611 }
11612
11613 return InstantiatedVarList;
11614 }
11615
11616public:
11617 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11618 ArrayRef<const OpenACCClause *> ExistingClauses,
11619 SemaOpenACC::OpenACCParsedClause &PC)
11620 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11621
11622 OpenACCClause *CreatedClause() const { return NewClause; }
11623
11624#define VISIT_CLAUSE(CLAUSE_NAME) \
11625 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11626#include "clang/Basic/OpenACCClauses.def"
11627};
11628
11629template <typename Derived>
11630void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11631 const OpenACCDefaultClause &C) {
11632 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11633
11634 NewClause = OpenACCDefaultClause::Create(
11635 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11636 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11637 ParsedClause.getEndLoc());
11638}
11639
11640template <typename Derived>
11641void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11642 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11643 assert(Cond && "If constructed with invalid Condition");
11644 Sema::ConditionResult Res = Self.TransformCondition(
11645 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11646
11647 if (Res.isInvalid() || !Res.get().second)
11648 return;
11649
11650 ParsedClause.setConditionDetails(Res.get().second);
11651
11652 NewClause = OpenACCIfClause::Create(
11653 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11654 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11655 ParsedClause.getEndLoc());
11656}
11657
11658template <typename Derived>
11659void OpenACCClauseTransform<Derived>::VisitSelfClause(
11660 const OpenACCSelfClause &C) {
11661
11662 // If this is an 'update' 'self' clause, this is actually a var list instead.
11663 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
11664 llvm::SmallVector<Expr *> InstantiatedVarList;
11665 for (Expr *CurVar : C.getVarList()) {
11666 ExprResult Res = Self.TransformExpr(CurVar);
11667
11668 if (!Res.isUsable())
11669 continue;
11670
11671 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getClauseKind(),
11672 Res.get());
11673
11674 if (Res.isUsable())
11675 InstantiatedVarList.push_back(Res.get());
11676 }
11677
11678 ParsedClause.setVarListDetails(InstantiatedVarList,
11679 /*IsReadOnly=*/false, /*IsZero=*/false);
11680
11681 NewClause = OpenACCSelfClause::Create(
11682 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11683 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11684 ParsedClause.getEndLoc());
11685 } else {
11686
11687 if (C.hasConditionExpr()) {
11688 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11689 Sema::ConditionResult Res =
11690 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11692
11693 if (Res.isInvalid() || !Res.get().second)
11694 return;
11695
11696 ParsedClause.setConditionDetails(Res.get().second);
11697 }
11698
11699 NewClause = OpenACCSelfClause::Create(
11700 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11701 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11702 ParsedClause.getEndLoc());
11703 }
11704}
11705
11706template <typename Derived>
11707void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11708 const OpenACCNumGangsClause &C) {
11709 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11710
11711 for (Expr *CurIntExpr : C.getIntExprs()) {
11712 ExprResult Res = Self.TransformExpr(CurIntExpr);
11713
11714 if (!Res.isUsable())
11715 return;
11716
11717 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11718 C.getClauseKind(),
11719 C.getBeginLoc(), Res.get());
11720 if (!Res.isUsable())
11721 return;
11722
11723 InstantiatedIntExprs.push_back(Res.get());
11724 }
11725
11726 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11728 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11729 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11730 ParsedClause.getEndLoc());
11731}
11732
11733template <typename Derived>
11734void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11735 const OpenACCPrivateClause &C) {
11736 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11737 /*IsReadOnly=*/false, /*IsZero=*/false);
11738
11739 NewClause = OpenACCPrivateClause::Create(
11740 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11741 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11742 ParsedClause.getEndLoc());
11743}
11744
11745template <typename Derived>
11746void OpenACCClauseTransform<Derived>::VisitHostClause(
11747 const OpenACCHostClause &C) {
11748 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11749 /*IsReadOnly=*/false, /*IsZero=*/false);
11750
11751 NewClause = OpenACCHostClause::Create(
11752 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11753 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11754 ParsedClause.getEndLoc());
11755}
11756
11757template <typename Derived>
11758void OpenACCClauseTransform<Derived>::VisitDeviceClause(
11759 const OpenACCDeviceClause &C) {
11760 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11761 /*IsReadOnly=*/false, /*IsZero=*/false);
11762
11763 NewClause = OpenACCDeviceClause::Create(
11764 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11765 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11766 ParsedClause.getEndLoc());
11767}
11768
11769template <typename Derived>
11770void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11771 const OpenACCFirstPrivateClause &C) {
11772 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11773 /*IsReadOnly=*/false, /*IsZero=*/false);
11774
11776 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11777 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11778 ParsedClause.getEndLoc());
11779}
11780
11781template <typename Derived>
11782void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
11783 const OpenACCNoCreateClause &C) {
11784 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11785 /*IsReadOnly=*/false, /*IsZero=*/false);
11786
11788 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11789 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11790 ParsedClause.getEndLoc());
11791}
11792
11793template <typename Derived>
11794void OpenACCClauseTransform<Derived>::VisitPresentClause(
11795 const OpenACCPresentClause &C) {
11796 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11797 /*IsReadOnly=*/false, /*IsZero=*/false);
11798
11799 NewClause = OpenACCPresentClause::Create(
11800 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11801 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11802 ParsedClause.getEndLoc());
11803}
11804
11805template <typename Derived>
11806void OpenACCClauseTransform<Derived>::VisitCopyClause(
11807 const OpenACCCopyClause &C) {
11808 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11809 /*IsReadOnly=*/false, /*IsZero=*/false);
11810
11811 NewClause = OpenACCCopyClause::Create(
11812 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11813 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11814 ParsedClause.getVarList(), ParsedClause.getEndLoc());
11815}
11816
11817template <typename Derived>
11818void OpenACCClauseTransform<Derived>::VisitCopyInClause(
11819 const OpenACCCopyInClause &C) {
11820 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), C.isReadOnly(),
11821 /*IsZero=*/false);
11822
11823 NewClause = OpenACCCopyInClause::Create(
11824 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11825 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11826 ParsedClause.isReadOnly(), ParsedClause.getVarList(),
11827 ParsedClause.getEndLoc());
11828}
11829
11830template <typename Derived>
11831void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
11832 const OpenACCCopyOutClause &C) {
11833 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11834 /*IsReadOnly=*/false, C.isZero());
11835
11836 NewClause = OpenACCCopyOutClause::Create(
11837 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11838 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11839 ParsedClause.isZero(), ParsedClause.getVarList(),
11840 ParsedClause.getEndLoc());
11841}
11842
11843template <typename Derived>
11844void OpenACCClauseTransform<Derived>::VisitCreateClause(
11845 const OpenACCCreateClause &C) {
11846 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11847 /*IsReadOnly=*/false, C.isZero());
11848
11849 NewClause = OpenACCCreateClause::Create(
11850 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11851 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11852 ParsedClause.isZero(), ParsedClause.getVarList(),
11853 ParsedClause.getEndLoc());
11854}
11855template <typename Derived>
11856void OpenACCClauseTransform<Derived>::VisitAttachClause(
11857 const OpenACCAttachClause &C) {
11858 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11859
11860 // Ensure each var is a pointer type.
11861 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11862 return Self.getSema().OpenACC().CheckVarIsPointerType(
11863 OpenACCClauseKind::Attach, E);
11864 }), VarList.end());
11865
11866 ParsedClause.setVarListDetails(VarList,
11867 /*IsReadOnly=*/false, /*IsZero=*/false);
11868 NewClause = OpenACCAttachClause::Create(
11869 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11870 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11871 ParsedClause.getEndLoc());
11872}
11873
11874template <typename Derived>
11875void OpenACCClauseTransform<Derived>::VisitDetachClause(
11876 const OpenACCDetachClause &C) {
11877 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11878
11879 // Ensure each var is a pointer type.
11880 VarList.erase(
11881 std::remove_if(VarList.begin(), VarList.end(),
11882 [&](Expr *E) {
11883 return Self.getSema().OpenACC().CheckVarIsPointerType(
11884 OpenACCClauseKind::Detach, E);
11885 }),
11886 VarList.end());
11887
11888 ParsedClause.setVarListDetails(VarList,
11889 /*IsReadOnly=*/false, /*IsZero=*/false);
11890 NewClause = OpenACCDetachClause::Create(
11891 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11892 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11893 ParsedClause.getEndLoc());
11894}
11895
11896template <typename Derived>
11897void OpenACCClauseTransform<Derived>::VisitDeleteClause(
11898 const OpenACCDeleteClause &C) {
11899 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11900 /*IsReadOnly=*/false, /*IsZero=*/false);
11901 NewClause = OpenACCDeleteClause::Create(
11902 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11903 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11904 ParsedClause.getEndLoc());
11905}
11906
11907template <typename Derived>
11908void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
11909 const OpenACCUseDeviceClause &C) {
11910 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11911 /*IsReadOnly=*/false, /*IsZero=*/false);
11913 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11914 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11915 ParsedClause.getEndLoc());
11916}
11917
11918template <typename Derived>
11919void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
11920 const OpenACCDevicePtrClause &C) {
11921 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11922
11923 // Ensure each var is a pointer type.
11924 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11925 return Self.getSema().OpenACC().CheckVarIsPointerType(
11926 OpenACCClauseKind::DevicePtr, E);
11927 }), VarList.end());
11928
11929 ParsedClause.setVarListDetails(VarList,
11930 /*IsReadOnly=*/false, /*IsZero=*/false);
11932 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11933 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11934 ParsedClause.getEndLoc());
11935}
11936
11937template <typename Derived>
11938void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
11939 const OpenACCNumWorkersClause &C) {
11940 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11941 assert(IntExpr && "num_workers clause constructed with invalid int expr");
11942
11943 ExprResult Res = Self.TransformExpr(IntExpr);
11944 if (!Res.isUsable())
11945 return;
11946
11947 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11948 C.getClauseKind(),
11949 C.getBeginLoc(), Res.get());
11950 if (!Res.isUsable())
11951 return;
11952
11953 ParsedClause.setIntExprDetails(Res.get());
11955 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11956 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11957 ParsedClause.getEndLoc());
11958}
11959
11960template <typename Derived>
11961void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
11962 const OpenACCDeviceNumClause &C) {
11963 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11964 assert(IntExpr && "device_num clause constructed with invalid int expr");
11965
11966 ExprResult Res = Self.TransformExpr(IntExpr);
11967 if (!Res.isUsable())
11968 return;
11969
11970 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11971 C.getClauseKind(),
11972 C.getBeginLoc(), Res.get());
11973 if (!Res.isUsable())
11974 return;
11975
11976 ParsedClause.setIntExprDetails(Res.get());
11978 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11979 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11980 ParsedClause.getEndLoc());
11981}
11982
11983template <typename Derived>
11984void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
11985 const OpenACCDefaultAsyncClause &C) {
11986 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11987 assert(IntExpr && "default_async clause constructed with invalid int expr");
11988
11989 ExprResult Res = Self.TransformExpr(IntExpr);
11990 if (!Res.isUsable())
11991 return;
11992
11993 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11994 C.getClauseKind(),
11995 C.getBeginLoc(), Res.get());
11996 if (!Res.isUsable())
11997 return;
11998
11999 ParsedClause.setIntExprDetails(Res.get());
12001 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12002 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12003 ParsedClause.getEndLoc());
12004}
12005
12006template <typename Derived>
12007void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12008 const OpenACCVectorLengthClause &C) {
12009 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12010 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12011
12012 ExprResult Res = Self.TransformExpr(IntExpr);
12013 if (!Res.isUsable())
12014 return;
12015
12016 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12017 C.getClauseKind(),
12018 C.getBeginLoc(), Res.get());
12019 if (!Res.isUsable())
12020 return;
12021
12022 ParsedClause.setIntExprDetails(Res.get());
12024 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12025 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12026 ParsedClause.getEndLoc());
12027}
12028
12029template <typename Derived>
12030void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12031 const OpenACCAsyncClause &C) {
12032 if (C.hasIntExpr()) {
12033 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12034 if (!Res.isUsable())
12035 return;
12036
12037 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12038 C.getClauseKind(),
12039 C.getBeginLoc(), Res.get());
12040 if (!Res.isUsable())
12041 return;
12042 ParsedClause.setIntExprDetails(Res.get());
12043 }
12044
12045 NewClause = OpenACCAsyncClause::Create(
12046 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12047 ParsedClause.getLParenLoc(),
12048 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12049 : nullptr,
12050 ParsedClause.getEndLoc());
12051}
12052
12053template <typename Derived>
12054void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12055 const OpenACCWorkerClause &C) {
12056 if (C.hasIntExpr()) {
12057 // restrictions on this expression are all "does it exist in certain
12058 // situations" that are not possible to be dependent, so the only check we
12059 // have is that it transforms, and is an int expression.
12060 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12061 if (!Res.isUsable())
12062 return;
12063
12064 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12065 C.getClauseKind(),
12066 C.getBeginLoc(), Res.get());
12067 if (!Res.isUsable())
12068 return;
12069 ParsedClause.setIntExprDetails(Res.get());
12070 }
12071
12072 NewClause = OpenACCWorkerClause::Create(
12073 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12074 ParsedClause.getLParenLoc(),
12075 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12076 : nullptr,
12077 ParsedClause.getEndLoc());
12078}
12079
12080template <typename Derived>
12081void OpenACCClauseTransform<Derived>::VisitVectorClause(
12082 const OpenACCVectorClause &C) {
12083 if (C.hasIntExpr()) {
12084 // restrictions on this expression are all "does it exist in certain
12085 // situations" that are not possible to be dependent, so the only check we
12086 // have is that it transforms, and is an int expression.
12087 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12088 if (!Res.isUsable())
12089 return;
12090
12091 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12092 C.getClauseKind(),
12093 C.getBeginLoc(), Res.get());
12094 if (!Res.isUsable())
12095 return;
12096 ParsedClause.setIntExprDetails(Res.get());
12097 }
12098
12099 NewClause = OpenACCVectorClause::Create(
12100 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12101 ParsedClause.getLParenLoc(),
12102 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12103 : nullptr,
12104 ParsedClause.getEndLoc());
12105}
12106
12107template <typename Derived>
12108void OpenACCClauseTransform<Derived>::VisitWaitClause(
12109 const OpenACCWaitClause &C) {
12110 if (!C.getLParenLoc().isInvalid()) {
12111 Expr *DevNumExpr = nullptr;
12112 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12113
12114 // Instantiate devnum expr if it exists.
12115 if (C.getDevNumExpr()) {
12116 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12117 if (!Res.isUsable())
12118 return;
12119 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12120 C.getClauseKind(),
12121 C.getBeginLoc(), Res.get());
12122 if (!Res.isUsable())
12123 return;
12124
12125 DevNumExpr = Res.get();
12126 }
12127
12128 // Instantiate queue ids.
12129 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12130 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12131 if (!Res.isUsable())
12132 return;
12133 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12134 C.getClauseKind(),
12135 C.getBeginLoc(), Res.get());
12136 if (!Res.isUsable())
12137 return;
12138
12139 InstantiatedQueueIdExprs.push_back(Res.get());
12140 }
12141
12142 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12143 std::move(InstantiatedQueueIdExprs));
12144 }
12145
12146 NewClause = OpenACCWaitClause::Create(
12147 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12148 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12149 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12150 ParsedClause.getEndLoc());
12151}
12152
12153template <typename Derived>
12154void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12155 const OpenACCDeviceTypeClause &C) {
12156 // Nothing to transform here, just create a new version of 'C'.
12158 Self.getSema().getASTContext(), C.getClauseKind(),
12159 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12160 C.getArchitectures(), ParsedClause.getEndLoc());
12161}
12162
12163template <typename Derived>
12164void OpenACCClauseTransform<Derived>::VisitAutoClause(
12165 const OpenACCAutoClause &C) {
12166 // Nothing to do, so just create a new node.
12167 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12168 ParsedClause.getBeginLoc(),
12169 ParsedClause.getEndLoc());
12170}
12171
12172template <typename Derived>
12173void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12174 const OpenACCIndependentClause &C) {
12175 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12176 ParsedClause.getBeginLoc(),
12177 ParsedClause.getEndLoc());
12178}
12179
12180template <typename Derived>
12181void OpenACCClauseTransform<Derived>::VisitSeqClause(
12182 const OpenACCSeqClause &C) {
12183 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12184 ParsedClause.getBeginLoc(),
12185 ParsedClause.getEndLoc());
12186}
12187template <typename Derived>
12188void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12189 const OpenACCFinalizeClause &C) {
12190 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12191 ParsedClause.getBeginLoc(),
12192 ParsedClause.getEndLoc());
12193}
12194
12195template <typename Derived>
12196void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12197 const OpenACCIfPresentClause &C) {
12198 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12199 ParsedClause.getBeginLoc(),
12200 ParsedClause.getEndLoc());
12201}
12202
12203template <typename Derived>
12204void OpenACCClauseTransform<Derived>::VisitReductionClause(
12205 const OpenACCReductionClause &C) {
12206 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12207 SmallVector<Expr *> ValidVars;
12208
12209 for (Expr *Var : TransformedVars) {
12210 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12211 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12212 if (Res.isUsable())
12213 ValidVars.push_back(Res.get());
12214 }
12215
12216 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12217 ExistingClauses, ParsedClause.getDirectiveKind(),
12218 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12219 C.getReductionOp(), ValidVars, ParsedClause.getEndLoc());
12220}
12221
12222template <typename Derived>
12223void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12224 const OpenACCCollapseClause &C) {
12225 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12226 assert(LoopCount && "collapse clause constructed with invalid loop count");
12227
12228 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12229
12230 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12232 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12233
12234 NewLoopCount =
12235 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12236
12237 if (!NewLoopCount.isUsable())
12238 return;
12239
12240 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12242 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12243 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12244 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12245}
12246
12247template <typename Derived>
12248void OpenACCClauseTransform<Derived>::VisitTileClause(
12249 const OpenACCTileClause &C) {
12250
12251 llvm::SmallVector<Expr *> TransformedExprs;
12252
12253 for (Expr *E : C.getSizeExprs()) {
12254 ExprResult NewSizeExpr = Self.TransformExpr(E);
12255
12256 if (!NewSizeExpr.isUsable())
12257 return;
12258
12259 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12261 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12262
12263 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12264
12265 if (!NewSizeExpr.isUsable())
12266 return;
12267 TransformedExprs.push_back(NewSizeExpr.get());
12268 }
12269
12270 ParsedClause.setIntExprDetails(TransformedExprs);
12271 NewClause = OpenACCTileClause::Create(
12272 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12273 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12274 ParsedClause.getEndLoc());
12275}
12276template <typename Derived>
12277void OpenACCClauseTransform<Derived>::VisitGangClause(
12278 const OpenACCGangClause &C) {
12279 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12280 llvm::SmallVector<Expr *> TransformedIntExprs;
12281
12282 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12283 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12284 if (!ER.isUsable())
12285 continue;
12286
12287 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12288 ParsedClause.getDirectiveKind(),
12289 C.getExpr(I).first, ER.get());
12290 if (!ER.isUsable())
12291 continue;
12292 TransformedGangKinds.push_back(C.getExpr(I).first);
12293 TransformedIntExprs.push_back(ER.get());
12294 }
12295
12296 NewClause = Self.getSema().OpenACC().CheckGangClause(
12297 ParsedClause.getDirectiveKind(), ExistingClauses,
12298 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12299 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12300}
12301} // namespace
12302template <typename Derived>
12303OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12304 ArrayRef<const OpenACCClause *> ExistingClauses,
12305 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12306
12307 SemaOpenACC::OpenACCParsedClause ParsedClause(
12308 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12309 ParsedClause.setEndLoc(OldClause->getEndLoc());
12310
12311 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12312 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12313
12314 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12315 ParsedClause};
12316 Transform.Visit(OldClause);
12317
12318 return Transform.CreatedClause();
12319}
12320
12321template <typename Derived>
12323TreeTransform<Derived>::TransformOpenACCClauseList(
12325 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12326 for (const auto *Clause : OldClauses) {
12327 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12328 TransformedClauses, DirKind, Clause))
12329 TransformedClauses.push_back(TransformedClause);
12330 }
12331 return TransformedClauses;
12332}
12333
12334template <typename Derived>
12335StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
12336 OpenACCComputeConstruct *C) {
12337 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12338
12339 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12340 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12341 C->clauses());
12342
12343 if (getSema().OpenACC().ActOnStartStmtDirective(
12344 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12345 return StmtError();
12346
12347 // Transform Structured Block.
12348 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12349 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12350 C->clauses(), TransformedClauses);
12351 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12352 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12353 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12354
12355 return getDerived().RebuildOpenACCComputeConstruct(
12356 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12357 C->getEndLoc(), TransformedClauses, StrBlock);
12358}
12359
12360template <typename Derived>
12362TreeTransform<Derived>::TransformOpenACCLoopConstruct(OpenACCLoopConstruct *C) {
12363
12364 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12365
12366 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12367 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12368 C->clauses());
12369
12370 if (getSema().OpenACC().ActOnStartStmtDirective(
12371 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12372 return StmtError();
12373
12374 // Transform Loop.
12375 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12376 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12377 C->clauses(), TransformedClauses);
12378 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12379 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12380 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12381
12382 return getDerived().RebuildOpenACCLoopConstruct(
12383 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12384 TransformedClauses, Loop);
12385}
12386
12387template <typename Derived>
12388StmtResult TreeTransform<Derived>::TransformOpenACCCombinedConstruct(
12389 OpenACCCombinedConstruct *C) {
12390 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12391
12392 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12393 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12394 C->clauses());
12395
12396 if (getSema().OpenACC().ActOnStartStmtDirective(
12397 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12398 return StmtError();
12399
12400 // Transform Loop.
12401 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12402 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12403 C->clauses(), TransformedClauses);
12404 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12405 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12406 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12407
12408 return getDerived().RebuildOpenACCCombinedConstruct(
12409 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12410 C->getEndLoc(), TransformedClauses, Loop);
12411}
12412
12413template <typename Derived>
12415TreeTransform<Derived>::TransformOpenACCDataConstruct(OpenACCDataConstruct *C) {
12416 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12417
12418 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12419 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12420 C->clauses());
12421 if (getSema().OpenACC().ActOnStartStmtDirective(
12422 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12423 return StmtError();
12424
12425 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12426 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12427 C->clauses(), TransformedClauses);
12428 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12429 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12430 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12431
12432 return getDerived().RebuildOpenACCDataConstruct(
12433 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12434 TransformedClauses, StrBlock);
12435}
12436
12437template <typename Derived>
12438StmtResult TreeTransform<Derived>::TransformOpenACCEnterDataConstruct(
12439 OpenACCEnterDataConstruct *C) {
12440 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12441
12442 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12443 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12444 C->clauses());
12445 if (getSema().OpenACC().ActOnStartStmtDirective(
12446 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12447 return StmtError();
12448
12449 return getDerived().RebuildOpenACCEnterDataConstruct(
12450 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12451 TransformedClauses);
12452}
12453
12454template <typename Derived>
12455StmtResult TreeTransform<Derived>::TransformOpenACCExitDataConstruct(
12456 OpenACCExitDataConstruct *C) {
12457 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12458
12459 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12460 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12461 C->clauses());
12462 if (getSema().OpenACC().ActOnStartStmtDirective(
12463 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12464 return StmtError();
12465
12466 return getDerived().RebuildOpenACCExitDataConstruct(
12467 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12468 TransformedClauses);
12469}
12470
12471template <typename Derived>
12472StmtResult TreeTransform<Derived>::TransformOpenACCHostDataConstruct(
12473 OpenACCHostDataConstruct *C) {
12474 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12475
12476 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12477 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12478 C->clauses());
12479 if (getSema().OpenACC().ActOnStartStmtDirective(
12480 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12481 return StmtError();
12482
12483 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12484 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12485 C->clauses(), TransformedClauses);
12486 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12487 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12488 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12489
12490 return getDerived().RebuildOpenACCHostDataConstruct(
12491 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12492 TransformedClauses, StrBlock);
12493}
12494
12495template <typename Derived>
12497TreeTransform<Derived>::TransformOpenACCInitConstruct(OpenACCInitConstruct *C) {
12498 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12499
12500 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12501 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12502 C->clauses());
12503 if (getSema().OpenACC().ActOnStartStmtDirective(
12504 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12505 return StmtError();
12506
12507 return getDerived().RebuildOpenACCInitConstruct(
12508 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12509 TransformedClauses);
12510}
12511
12512template <typename Derived>
12513StmtResult TreeTransform<Derived>::TransformOpenACCShutdownConstruct(
12514 OpenACCShutdownConstruct *C) {
12515 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12516
12517 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12518 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12519 C->clauses());
12520 if (getSema().OpenACC().ActOnStartStmtDirective(
12521 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12522 return StmtError();
12523
12524 return getDerived().RebuildOpenACCShutdownConstruct(
12525 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12526 TransformedClauses);
12527}
12528template <typename Derived>
12530TreeTransform<Derived>::TransformOpenACCSetConstruct(OpenACCSetConstruct *C) {
12531 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12532
12533 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12534 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12535 C->clauses());
12536 if (getSema().OpenACC().ActOnStartStmtDirective(
12537 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12538 return StmtError();
12539
12540 return getDerived().RebuildOpenACCSetConstruct(
12541 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12542 TransformedClauses);
12543}
12544
12545template <typename Derived>
12546StmtResult TreeTransform<Derived>::TransformOpenACCUpdateConstruct(
12547 OpenACCUpdateConstruct *C) {
12548 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12549
12550 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12551 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12552 C->clauses());
12553 if (getSema().OpenACC().ActOnStartStmtDirective(
12554 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12555 return StmtError();
12556
12557 return getDerived().RebuildOpenACCUpdateConstruct(
12558 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12559 TransformedClauses);
12560}
12561
12562template <typename Derived>
12564TreeTransform<Derived>::TransformOpenACCWaitConstruct(OpenACCWaitConstruct *C) {
12565 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12566
12567 ExprResult DevNumExpr;
12568 if (C->hasDevNumExpr()) {
12569 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
12570
12571 if (DevNumExpr.isUsable())
12572 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
12574 C->getBeginLoc(), DevNumExpr.get());
12575 }
12576
12577 llvm::SmallVector<Expr *> QueueIdExprs;
12578
12579 for (Expr *QE : C->getQueueIdExprs()) {
12580 assert(QE && "Null queue id expr?");
12581 ExprResult NewEQ = getDerived().TransformExpr(QE);
12582
12583 if (!NewEQ.isUsable())
12584 break;
12585 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
12587 C->getBeginLoc(), NewEQ.get());
12588 if (NewEQ.isUsable())
12589 QueueIdExprs.push_back(NewEQ.get());
12590 }
12591
12592 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12593 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12594 C->clauses());
12595
12596 if (getSema().OpenACC().ActOnStartStmtDirective(
12597 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12598 return StmtError();
12599
12600 return getDerived().RebuildOpenACCWaitConstruct(
12601 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12602 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
12603 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
12604}
12605
12606template <typename Derived>
12607ExprResult TreeTransform<Derived>::TransformOpenACCAsteriskSizeExpr(
12608 OpenACCAsteriskSizeExpr *E) {
12609 if (getDerived().AlwaysRebuild())
12610 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
12611 // Nothing can ever change, so there is never anything to transform.
12612 return E;
12613}
12614
12615//===----------------------------------------------------------------------===//
12616// Expression transformation
12617//===----------------------------------------------------------------------===//
12618template<typename Derived>
12620TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
12621 return TransformExpr(E->getSubExpr());
12622}
12623
12624template <typename Derived>
12625ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
12626 SYCLUniqueStableNameExpr *E) {
12627 if (!E->isTypeDependent())
12628 return E;
12629
12630 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
12631
12632 if (!NewT)
12633 return ExprError();
12634
12635 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
12636 return E;
12637
12638 return getDerived().RebuildSYCLUniqueStableNameExpr(
12639 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
12640}
12641
12642template<typename Derived>
12644TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
12645 if (!E->isTypeDependent())
12646 return E;
12647
12648 return getDerived().RebuildPredefinedExpr(E->getLocation(),
12649 E->getIdentKind());
12650}
12651
12652template<typename Derived>
12654TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
12655 NestedNameSpecifierLoc QualifierLoc;
12656 if (E->getQualifierLoc()) {
12657 QualifierLoc
12658 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12659 if (!QualifierLoc)
12660 return ExprError();
12661 }
12662
12663 ValueDecl *ND
12664 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
12665 E->getDecl()));
12666 if (!ND)
12667 return ExprError();
12668
12669 NamedDecl *Found = ND;
12670 if (E->getFoundDecl() != E->getDecl()) {
12671 Found = cast_or_null<NamedDecl>(
12672 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
12673 if (!Found)
12674 return ExprError();
12675 }
12676
12677 DeclarationNameInfo NameInfo = E->getNameInfo();
12678 if (NameInfo.getName()) {
12679 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
12680 if (!NameInfo.getName())
12681 return ExprError();
12682 }
12683
12684 if (!getDerived().AlwaysRebuild() &&
12685 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
12686 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
12687 Found == E->getFoundDecl() &&
12688 NameInfo.getName() == E->getDecl()->getDeclName() &&
12689 !E->hasExplicitTemplateArgs()) {
12690
12691 // Mark it referenced in the new context regardless.
12692 // FIXME: this is a bit instantiation-specific.
12693 SemaRef.MarkDeclRefReferenced(E);
12694
12695 return E;
12696 }
12697
12698 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
12699 if (E->hasExplicitTemplateArgs()) {
12700 TemplateArgs = &TransArgs;
12701 TransArgs.setLAngleLoc(E->getLAngleLoc());
12702 TransArgs.setRAngleLoc(E->getRAngleLoc());
12703 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
12704 E->getNumTemplateArgs(),
12705 TransArgs))
12706 return ExprError();
12707 }
12708
12709 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
12710 Found, TemplateArgs);
12711}
12712
12713template<typename Derived>
12715TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
12716 return E;
12717}
12718
12719template <typename Derived>
12720ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
12721 FixedPointLiteral *E) {
12722 return E;
12723}
12724
12725template<typename Derived>
12727TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
12728 return E;
12729}
12730
12731template<typename Derived>
12733TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
12734 return E;
12735}
12736
12737template<typename Derived>
12739TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
12740 return E;
12741}
12742
12743template<typename Derived>
12745TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
12746 return E;
12747}
12748
12749template<typename Derived>
12751TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
12752 return getDerived().TransformCallExpr(E);
12753}
12754
12755template<typename Derived>
12757TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
12758 ExprResult ControllingExpr;
12759 TypeSourceInfo *ControllingType = nullptr;
12760 if (E->isExprPredicate())
12761 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
12762 else
12763 ControllingType = getDerived().TransformType(E->getControllingType());
12764
12765 if (ControllingExpr.isInvalid() && !ControllingType)
12766 return ExprError();
12767
12768 SmallVector<Expr *, 4> AssocExprs;
12770 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
12771 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
12772 if (TSI) {
12773 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
12774 if (!AssocType)
12775 return ExprError();
12776 AssocTypes.push_back(AssocType);
12777 } else {
12778 AssocTypes.push_back(nullptr);
12779 }
12780
12781 ExprResult AssocExpr =
12782 getDerived().TransformExpr(Assoc.getAssociationExpr());
12783 if (AssocExpr.isInvalid())
12784 return ExprError();
12785 AssocExprs.push_back(AssocExpr.get());
12786 }
12787
12788 if (!ControllingType)
12789 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
12790 E->getDefaultLoc(),
12791 E->getRParenLoc(),
12792 ControllingExpr.get(),
12793 AssocTypes,
12794 AssocExprs);
12795 return getDerived().RebuildGenericSelectionExpr(
12796 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
12797 ControllingType, AssocTypes, AssocExprs);
12798}
12799
12800template<typename Derived>
12802TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
12803 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12804 if (SubExpr.isInvalid())
12805 return ExprError();
12806
12807 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
12808 return E;
12809
12810 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
12811 E->getRParen());
12812}
12813
12814/// The operand of a unary address-of operator has special rules: it's
12815/// allowed to refer to a non-static member of a class even if there's no 'this'
12816/// object available.
12817template<typename Derived>
12820 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
12821 return getDerived().TransformDependentScopeDeclRefExpr(
12822 DRE, /*IsAddressOfOperand=*/true, nullptr);
12823 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
12824 return getDerived().TransformUnresolvedLookupExpr(
12825 ULE, /*IsAddressOfOperand=*/true);
12826 else
12827 return getDerived().TransformExpr(E);
12828}
12829
12830template<typename Derived>
12833 ExprResult SubExpr;
12834 if (E->getOpcode() == UO_AddrOf)
12835 SubExpr = TransformAddressOfOperand(E->getSubExpr());
12836 else
12837 SubExpr = TransformExpr(E->getSubExpr());
12838 if (SubExpr.isInvalid())
12839 return ExprError();
12840
12841 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
12842 return E;
12843
12844 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
12845 E->getOpcode(),
12846 SubExpr.get());
12847}
12848
12849template<typename Derived>
12851TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
12852 // Transform the type.
12853 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12854 if (!Type)
12855 return ExprError();
12856
12857 // Transform all of the components into components similar to what the
12858 // parser uses.
12859 // FIXME: It would be slightly more efficient in the non-dependent case to
12860 // just map FieldDecls, rather than requiring the rebuilder to look for
12861 // the fields again. However, __builtin_offsetof is rare enough in
12862 // template code that we don't care.
12863 bool ExprChanged = false;
12864 typedef Sema::OffsetOfComponent Component;
12865 SmallVector<Component, 4> Components;
12866 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
12867 const OffsetOfNode &ON = E->getComponent(I);
12868 Component Comp;
12869 Comp.isBrackets = true;
12870 Comp.LocStart = ON.getSourceRange().getBegin();
12871 Comp.LocEnd = ON.getSourceRange().getEnd();
12872 switch (ON.getKind()) {
12873 case OffsetOfNode::Array: {
12874 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
12875 ExprResult Index = getDerived().TransformExpr(FromIndex);
12876 if (Index.isInvalid())
12877 return ExprError();
12878
12879 ExprChanged = ExprChanged || Index.get() != FromIndex;
12880 Comp.isBrackets = true;
12881 Comp.U.E = Index.get();
12882 break;
12883 }
12884
12887 Comp.isBrackets = false;
12888 Comp.U.IdentInfo = ON.getFieldName();
12889 if (!Comp.U.IdentInfo)
12890 continue;
12891
12892 break;
12893
12894 case OffsetOfNode::Base:
12895 // Will be recomputed during the rebuild.
12896 continue;
12897 }
12898
12899 Components.push_back(Comp);
12900 }
12901
12902 // If nothing changed, retain the existing expression.
12903 if (!getDerived().AlwaysRebuild() &&
12904 Type == E->getTypeSourceInfo() &&
12905 !ExprChanged)
12906 return E;
12907
12908 // Build a new offsetof expression.
12909 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
12910 Components, E->getRParenLoc());
12911}
12912
12913template<typename Derived>
12915TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
12916 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
12917 "opaque value expression requires transformation");
12918 return E;
12919}
12920
12921template<typename Derived>
12923TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
12924 return E;
12925}
12926
12927template <typename Derived>
12928ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) {
12930 bool Changed = false;
12931 for (Expr *C : E->subExpressions()) {
12932 ExprResult NewC = getDerived().TransformExpr(C);
12933 if (NewC.isInvalid())
12934 return ExprError();
12935 Children.push_back(NewC.get());
12936
12937 Changed |= NewC.get() != C;
12938 }
12939 if (!getDerived().AlwaysRebuild() && !Changed)
12940 return E;
12941 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
12942 Children, E->getType());
12943}
12944
12945template<typename Derived>
12947TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
12948 // Rebuild the syntactic form. The original syntactic form has
12949 // opaque-value expressions in it, so strip those away and rebuild
12950 // the result. This is a really awful way of doing this, but the
12951 // better solution (rebuilding the semantic expressions and
12952 // rebinding OVEs as necessary) doesn't work; we'd need
12953 // TreeTransform to not strip away implicit conversions.
12954 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
12955 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
12956 if (result.isInvalid()) return ExprError();
12957
12958 // If that gives us a pseudo-object result back, the pseudo-object
12959 // expression must have been an lvalue-to-rvalue conversion which we
12960 // should reapply.
12961 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
12962 result = SemaRef.PseudoObject().checkRValue(result.get());
12963
12964 return result;
12965}
12966
12967template<typename Derived>
12969TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
12970 UnaryExprOrTypeTraitExpr *E) {
12971 if (E->isArgumentType()) {
12972 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
12973
12974 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
12975 if (!NewT)
12976 return ExprError();
12977
12978 if (!getDerived().AlwaysRebuild() && OldT == NewT)
12979 return E;
12980
12981 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
12982 E->getKind(),
12983 E->getSourceRange());
12984 }
12985
12986 // C++0x [expr.sizeof]p1:
12987 // The operand is either an expression, which is an unevaluated operand
12988 // [...]
12989 EnterExpressionEvaluationContext Unevaluated(
12992
12993 // Try to recover if we have something like sizeof(T::X) where X is a type.
12994 // Notably, there must be *exactly* one set of parens if X is a type.
12995 TypeSourceInfo *RecoveryTSI = nullptr;
12996 ExprResult SubExpr;
12997 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
12998 if (auto *DRE =
12999 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
13000 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
13001 PE, DRE, false, &RecoveryTSI);
13002 else
13003 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
13004
13005 if (RecoveryTSI) {
13006 return getDerived().RebuildUnaryExprOrTypeTrait(
13007 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
13008 } else if (SubExpr.isInvalid())
13009 return ExprError();
13010
13011 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13012 return E;
13013
13014 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13015 E->getOperatorLoc(),
13016 E->getKind(),
13017 E->getSourceRange());
13018}
13019
13020template<typename Derived>
13022TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
13023 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13024 if (LHS.isInvalid())
13025 return ExprError();
13026
13027 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13028 if (RHS.isInvalid())
13029 return ExprError();
13030
13031
13032 if (!getDerived().AlwaysRebuild() &&
13033 LHS.get() == E->getLHS() &&
13034 RHS.get() == E->getRHS())
13035 return E;
13036
13037 return getDerived().RebuildArraySubscriptExpr(
13038 LHS.get(),
13039 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13040}
13041
13042template <typename Derived>
13044TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
13045 ExprResult Base = getDerived().TransformExpr(E->getBase());
13046 if (Base.isInvalid())
13047 return ExprError();
13048
13049 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13050 if (RowIdx.isInvalid())
13051 return ExprError();
13052
13053 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13054 if (ColumnIdx.isInvalid())
13055 return ExprError();
13056
13057 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13058 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13059 return E;
13060
13061 return getDerived().RebuildMatrixSubscriptExpr(
13062 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13063}
13064
13065template <typename Derived>
13067TreeTransform<Derived>::TransformArraySectionExpr(ArraySectionExpr *E) {
13068 ExprResult Base = getDerived().TransformExpr(E->getBase());
13069 if (Base.isInvalid())
13070 return ExprError();
13071
13072 ExprResult LowerBound;
13073 if (E->getLowerBound()) {
13074 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13075 if (LowerBound.isInvalid())
13076 return ExprError();
13077 }
13078
13079 ExprResult Length;
13080 if (E->getLength()) {
13081 Length = getDerived().TransformExpr(E->getLength());
13082 if (Length.isInvalid())
13083 return ExprError();
13084 }
13085
13086 ExprResult Stride;
13087 if (E->isOMPArraySection()) {
13088 if (Expr *Str = E->getStride()) {
13089 Stride = getDerived().TransformExpr(Str);
13090 if (Stride.isInvalid())
13091 return ExprError();
13092 }
13093 }
13094
13095 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13096 LowerBound.get() == E->getLowerBound() &&
13097 Length.get() == E->getLength() &&
13098 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13099 return E;
13100
13101 return getDerived().RebuildArraySectionExpr(
13102 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13103 LowerBound.get(), E->getColonLocFirst(),
13104 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13105 Length.get(), Stride.get(), E->getRBracketLoc());
13106}
13107
13108template <typename Derived>
13110TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
13111 ExprResult Base = getDerived().TransformExpr(E->getBase());
13112 if (Base.isInvalid())
13113 return ExprError();
13114
13116 bool ErrorFound = false;
13117 for (Expr *Dim : E->getDimensions()) {
13118 ExprResult DimRes = getDerived().TransformExpr(Dim);
13119 if (DimRes.isInvalid()) {
13120 ErrorFound = true;
13121 continue;
13122 }
13123 Dims.push_back(DimRes.get());
13124 }
13125
13126 if (ErrorFound)
13127 return ExprError();
13128 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13129 E->getRParenLoc(), Dims,
13130 E->getBracketsRanges());
13131}
13132
13133template <typename Derived>
13135TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) {
13136 unsigned NumIterators = E->numOfIterators();
13138
13139 bool ErrorFound = false;
13140 bool NeedToRebuild = getDerived().AlwaysRebuild();
13141 for (unsigned I = 0; I < NumIterators; ++I) {
13142 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13143 Data[I].DeclIdent = D->getIdentifier();
13144 Data[I].DeclIdentLoc = D->getLocation();
13145 if (D->getLocation() == D->getBeginLoc()) {
13146 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13147 "Implicit type must be int.");
13148 } else {
13149 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13150 QualType DeclTy = getDerived().TransformType(D->getType());
13151 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13152 }
13153 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13154 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13155 ExprResult End = getDerived().TransformExpr(Range.End);
13156 ExprResult Step = getDerived().TransformExpr(Range.Step);
13157 ErrorFound = ErrorFound ||
13158 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13159 !Data[I].Type.get().isNull())) ||
13160 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13161 if (ErrorFound)
13162 continue;
13163 Data[I].Range.Begin = Begin.get();
13164 Data[I].Range.End = End.get();
13165 Data[I].Range.Step = Step.get();
13166 Data[I].AssignLoc = E->getAssignLoc(I);
13167 Data[I].ColonLoc = E->getColonLoc(I);
13168 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13169 NeedToRebuild =
13170 NeedToRebuild ||
13171 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13172 D->getType().getTypePtrOrNull()) ||
13173 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13174 Range.Step != Data[I].Range.Step;
13175 }
13176 if (ErrorFound)
13177 return ExprError();
13178 if (!NeedToRebuild)
13179 return E;
13180
13181 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13182 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13183 if (!Res.isUsable())
13184 return Res;
13185 auto *IE = cast<OMPIteratorExpr>(Res.get());
13186 for (unsigned I = 0; I < NumIterators; ++I)
13187 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13188 IE->getIteratorDecl(I));
13189 return Res;
13190}
13191
13192template<typename Derived>
13194TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
13195 // Transform the callee.
13196 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13197 if (Callee.isInvalid())
13198 return ExprError();
13199
13200 // Transform arguments.
13201 bool ArgChanged = false;
13203 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13204 &ArgChanged))
13205 return ExprError();
13206
13207 if (!getDerived().AlwaysRebuild() &&
13208 Callee.get() == E->getCallee() &&
13209 !ArgChanged)
13210 return SemaRef.MaybeBindToTemporary(E);
13211
13212 // FIXME: Wrong source location information for the '('.
13213 SourceLocation FakeLParenLoc
13214 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13215
13216 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13217 if (E->hasStoredFPFeatures()) {
13218 FPOptionsOverride NewOverrides = E->getFPFeatures();
13219 getSema().CurFPFeatures =
13220 NewOverrides.applyOverrides(getSema().getLangOpts());
13221 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13222 }
13223
13224 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13225 Args,
13226 E->getRParenLoc());
13227}
13228
13229template<typename Derived>
13231TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
13232 ExprResult Base = getDerived().TransformExpr(E->getBase());
13233 if (Base.isInvalid())
13234 return ExprError();
13235
13236 NestedNameSpecifierLoc QualifierLoc;
13237 if (E->hasQualifier()) {
13238 QualifierLoc
13239 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13240
13241 if (!QualifierLoc)
13242 return ExprError();
13243 }
13244 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13245
13246 ValueDecl *Member
13247 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
13248 E->getMemberDecl()));
13249 if (!Member)
13250 return ExprError();
13251
13252 NamedDecl *FoundDecl = E->getFoundDecl();
13253 if (FoundDecl == E->getMemberDecl()) {
13254 FoundDecl = Member;
13255 } else {
13256 FoundDecl = cast_or_null<NamedDecl>(
13257 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
13258 if (!FoundDecl)
13259 return ExprError();
13260 }
13261
13262 if (!getDerived().AlwaysRebuild() &&
13263 Base.get() == E->getBase() &&
13264 QualifierLoc == E->getQualifierLoc() &&
13265 Member == E->getMemberDecl() &&
13266 FoundDecl == E->getFoundDecl() &&
13267 !E->hasExplicitTemplateArgs()) {
13268
13269 // Skip for member expression of (this->f), rebuilt thisi->f is needed
13270 // for Openmp where the field need to be privatizized in the case.
13271 if (!(isa<CXXThisExpr>(E->getBase()) &&
13272 getSema().OpenMP().isOpenMPRebuildMemberExpr(
13273 cast<ValueDecl>(Member)))) {
13274 // Mark it referenced in the new context regardless.
13275 // FIXME: this is a bit instantiation-specific.
13276 SemaRef.MarkMemberReferenced(E);
13277 return E;
13278 }
13279 }
13280
13281 TemplateArgumentListInfo TransArgs;
13282 if (E->hasExplicitTemplateArgs()) {
13283 TransArgs.setLAngleLoc(E->getLAngleLoc());
13284 TransArgs.setRAngleLoc(E->getRAngleLoc());
13285 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13286 E->getNumTemplateArgs(),
13287 TransArgs))
13288 return ExprError();
13289 }
13290
13291 // FIXME: Bogus source location for the operator
13292 SourceLocation FakeOperatorLoc =
13293 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
13294
13295 // FIXME: to do this check properly, we will need to preserve the
13296 // first-qualifier-in-scope here, just in case we had a dependent
13297 // base (and therefore couldn't do the check) and a
13298 // nested-name-qualifier (and therefore could do the lookup).
13299 NamedDecl *FirstQualifierInScope = nullptr;
13300 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
13301 if (MemberNameInfo.getName()) {
13302 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
13303 if (!MemberNameInfo.getName())
13304 return ExprError();
13305 }
13306
13307 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
13308 E->isArrow(),
13309 QualifierLoc,
13310 TemplateKWLoc,
13311 MemberNameInfo,
13312 Member,
13313 FoundDecl,
13314 (E->hasExplicitTemplateArgs()
13315 ? &TransArgs : nullptr),
13316 FirstQualifierInScope);
13317}
13318
13319template<typename Derived>
13321TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
13322 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13323 if (LHS.isInvalid())
13324 return ExprError();
13325
13326 ExprResult RHS =
13327 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
13328 if (RHS.isInvalid())
13329 return ExprError();
13330
13331 if (!getDerived().AlwaysRebuild() &&
13332 LHS.get() == E->getLHS() &&
13333 RHS.get() == E->getRHS())
13334 return E;
13335
13336 if (E->isCompoundAssignmentOp())
13337 // FPFeatures has already been established from trailing storage
13338 return getDerived().RebuildBinaryOperator(
13339 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
13340 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13341 FPOptionsOverride NewOverrides(E->getFPFeatures());
13342 getSema().CurFPFeatures =
13343 NewOverrides.applyOverrides(getSema().getLangOpts());
13344 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13345 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
13346 LHS.get(), RHS.get());
13347}
13348
13349template <typename Derived>
13350ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
13351 CXXRewrittenBinaryOperator *E) {
13352 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
13353
13354 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
13355 if (LHS.isInvalid())
13356 return ExprError();
13357
13358 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
13359 if (RHS.isInvalid())
13360 return ExprError();
13361
13362 // Extract the already-resolved callee declarations so that we can restrict
13363 // ourselves to using them as the unqualified lookup results when rebuilding.
13364 UnresolvedSet<2> UnqualLookups;
13365 bool ChangedAnyLookups = false;
13366 Expr *PossibleBinOps[] = {E->getSemanticForm(),
13367 const_cast<Expr *>(Decomp.InnerBinOp)};
13368 for (Expr *PossibleBinOp : PossibleBinOps) {
13369 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
13370 if (!Op)
13371 continue;
13372 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
13373 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
13374 continue;
13375
13376 // Transform the callee in case we built a call to a local extern
13377 // declaration.
13378 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
13379 E->getOperatorLoc(), Callee->getFoundDecl()));
13380 if (!Found)
13381 return ExprError();
13382 if (Found != Callee->getFoundDecl())
13383 ChangedAnyLookups = true;
13384 UnqualLookups.addDecl(Found);
13385 }
13386
13387 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
13388 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
13389 // Mark all functions used in the rewrite as referenced. Note that when
13390 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
13391 // function calls, and/or there might be a user-defined conversion sequence
13392 // applied to the operands of the <.
13393 // FIXME: this is a bit instantiation-specific.
13394 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
13395 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
13396 return E;
13397 }
13398
13399 return getDerived().RebuildCXXRewrittenBinaryOperator(
13400 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
13401}
13402
13403template<typename Derived>
13405TreeTransform<Derived>::TransformCompoundAssignOperator(
13406 CompoundAssignOperator *E) {
13407 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13408 FPOptionsOverride NewOverrides(E->getFPFeatures());
13409 getSema().CurFPFeatures =
13410 NewOverrides.applyOverrides(getSema().getLangOpts());
13411 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13412 return getDerived().TransformBinaryOperator(E);
13413}
13414
13415template<typename Derived>
13416ExprResult TreeTransform<Derived>::
13417TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
13418 // Just rebuild the common and RHS expressions and see whether we
13419 // get any changes.
13420
13421 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
13422 if (commonExpr.isInvalid())
13423 return ExprError();
13424
13425 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
13426 if (rhs.isInvalid())
13427 return ExprError();
13428
13429 if (!getDerived().AlwaysRebuild() &&
13430 commonExpr.get() == e->getCommon() &&
13431 rhs.get() == e->getFalseExpr())
13432 return e;
13433
13434 return getDerived().RebuildConditionalOperator(commonExpr.get(),
13435 e->getQuestionLoc(),
13436 nullptr,
13437 e->getColonLoc(),
13438 rhs.get());
13439}
13440
13441template<typename Derived>
13443TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
13444 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13445 if (Cond.isInvalid())
13446 return ExprError();
13447
13448 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13449 if (LHS.isInvalid())
13450 return ExprError();
13451
13452 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13453 if (RHS.isInvalid())
13454 return ExprError();
13455
13456 if (!getDerived().AlwaysRebuild() &&
13457 Cond.get() == E->getCond() &&
13458 LHS.get() == E->getLHS() &&
13459 RHS.get() == E->getRHS())
13460 return E;
13461
13462 return getDerived().RebuildConditionalOperator(Cond.get(),
13463 E->getQuestionLoc(),
13464 LHS.get(),
13465 E->getColonLoc(),
13466 RHS.get());
13467}
13468
13469template<typename Derived>
13471TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
13472 // Implicit casts are eliminated during transformation, since they
13473 // will be recomputed by semantic analysis after transformation.
13474 return getDerived().TransformExpr(E->getSubExprAsWritten());
13475}
13476
13477template<typename Derived>
13479TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
13480 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13481 if (!Type)
13482 return ExprError();
13483
13484 ExprResult SubExpr
13485 = getDerived().TransformExpr(E->getSubExprAsWritten());
13486 if (SubExpr.isInvalid())
13487 return ExprError();
13488
13489 if (!getDerived().AlwaysRebuild() &&
13490 Type == E->getTypeInfoAsWritten() &&
13491 SubExpr.get() == E->getSubExpr())
13492 return E;
13493
13494 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
13495 Type,
13496 E->getRParenLoc(),
13497 SubExpr.get());
13498}
13499
13500template<typename Derived>
13502TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
13503 TypeSourceInfo *OldT = E->getTypeSourceInfo();
13504 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13505 if (!NewT)
13506 return ExprError();
13507
13508 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
13509 if (Init.isInvalid())
13510 return ExprError();
13511
13512 if (!getDerived().AlwaysRebuild() &&
13513 OldT == NewT &&
13514 Init.get() == E->getInitializer())
13515 return SemaRef.MaybeBindToTemporary(E);
13516
13517 // Note: the expression type doesn't necessarily match the
13518 // type-as-written, but that's okay, because it should always be
13519 // derivable from the initializer.
13520
13521 return getDerived().RebuildCompoundLiteralExpr(
13522 E->getLParenLoc(), NewT,
13523 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
13524}
13525
13526template<typename Derived>
13528TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
13529 ExprResult Base = getDerived().TransformExpr(E->getBase());
13530 if (Base.isInvalid())
13531 return ExprError();
13532
13533 if (!getDerived().AlwaysRebuild() &&
13534 Base.get() == E->getBase())
13535 return E;
13536
13537 // FIXME: Bad source location
13538 SourceLocation FakeOperatorLoc =
13539 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
13540 return getDerived().RebuildExtVectorElementExpr(
13541 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
13542 E->getAccessor());
13543}
13544
13545template<typename Derived>
13547TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
13548 if (InitListExpr *Syntactic = E->getSyntacticForm())
13549 E = Syntactic;
13550
13551 bool InitChanged = false;
13552
13553 EnterExpressionEvaluationContext Context(
13555
13557 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
13558 Inits, &InitChanged))
13559 return ExprError();
13560
13561 if (!getDerived().AlwaysRebuild() && !InitChanged) {
13562 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
13563 // in some cases. We can't reuse it in general, because the syntactic and
13564 // semantic forms are linked, and we can't know that semantic form will
13565 // match even if the syntactic form does.
13566 }
13567
13568 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
13569 E->getRBraceLoc());
13570}
13571
13572template<typename Derived>
13574TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
13575 Designation Desig;
13576
13577 // transform the initializer value
13578 ExprResult Init = getDerived().TransformExpr(E->getInit());
13579 if (Init.isInvalid())
13580 return ExprError();
13581
13582 // transform the designators.
13583 SmallVector<Expr*, 4> ArrayExprs;
13584 bool ExprChanged = false;
13585 for (const DesignatedInitExpr::Designator &D : E->designators()) {
13586 if (D.isFieldDesignator()) {
13587 if (D.getFieldDecl()) {
13588 FieldDecl *Field = cast_or_null<FieldDecl>(
13589 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
13590 if (Field != D.getFieldDecl())
13591 // Rebuild the expression when the transformed FieldDecl is
13592 // different to the already assigned FieldDecl.
13593 ExprChanged = true;
13594 if (Field->isAnonymousStructOrUnion())
13595 continue;
13596 } else {
13597 // Ensure that the designator expression is rebuilt when there isn't
13598 // a resolved FieldDecl in the designator as we don't want to assign
13599 // a FieldDecl to a pattern designator that will be instantiated again.
13600 ExprChanged = true;
13601 }
13602 Desig.AddDesignator(Designator::CreateFieldDesignator(
13603 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
13604 continue;
13605 }
13606
13607 if (D.isArrayDesignator()) {
13608 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
13609 if (Index.isInvalid())
13610 return ExprError();
13611
13612 Desig.AddDesignator(
13613 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
13614
13615 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
13616 ArrayExprs.push_back(Index.get());
13617 continue;
13618 }
13619
13620 assert(D.isArrayRangeDesignator() && "New kind of designator?");
13621 ExprResult Start
13622 = getDerived().TransformExpr(E->getArrayRangeStart(D));
13623 if (Start.isInvalid())
13624 return ExprError();
13625
13626 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
13627 if (End.isInvalid())
13628 return ExprError();
13629
13630 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
13631 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
13632
13633 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
13634 End.get() != E->getArrayRangeEnd(D);
13635
13636 ArrayExprs.push_back(Start.get());
13637 ArrayExprs.push_back(End.get());
13638 }
13639
13640 if (!getDerived().AlwaysRebuild() &&
13641 Init.get() == E->getInit() &&
13642 !ExprChanged)
13643 return E;
13644
13645 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
13646 E->getEqualOrColonLoc(),
13647 E->usesGNUSyntax(), Init.get());
13648}
13649
13650// Seems that if TransformInitListExpr() only works on the syntactic form of an
13651// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
13652template<typename Derived>
13654TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
13655 DesignatedInitUpdateExpr *E) {
13656 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
13657 "initializer");
13658 return ExprError();
13659}
13660
13661template<typename Derived>
13663TreeTransform<Derived>::TransformNoInitExpr(
13664 NoInitExpr *E) {
13665 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
13666 return ExprError();
13667}
13668
13669template<typename Derived>
13671TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
13672 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
13673 return ExprError();
13674}
13675
13676template<typename Derived>
13678TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
13679 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
13680 return ExprError();
13681}
13682
13683template<typename Derived>
13685TreeTransform<Derived>::TransformImplicitValueInitExpr(
13686 ImplicitValueInitExpr *E) {
13687 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
13688
13689 // FIXME: Will we ever have proper type location here? Will we actually
13690 // need to transform the type?
13691 QualType T = getDerived().TransformType(E->getType());
13692 if (T.isNull())
13693 return ExprError();
13694
13695 if (!getDerived().AlwaysRebuild() &&
13696 T == E->getType())
13697 return E;
13698
13699 return getDerived().RebuildImplicitValueInitExpr(T);
13700}
13701
13702template<typename Derived>
13704TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
13705 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
13706 if (!TInfo)
13707 return ExprError();
13708
13709 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13710 if (SubExpr.isInvalid())
13711 return ExprError();
13712
13713 if (!getDerived().AlwaysRebuild() &&
13714 TInfo == E->getWrittenTypeInfo() &&
13715 SubExpr.get() == E->getSubExpr())
13716 return E;
13717
13718 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
13719 TInfo, E->getRParenLoc());
13720}
13721
13722template<typename Derived>
13724TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
13725 bool ArgumentChanged = false;
13727 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
13728 &ArgumentChanged))
13729 return ExprError();
13730
13731 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
13732 Inits,
13733 E->getRParenLoc());
13734}
13735
13736/// Transform an address-of-label expression.
13737///
13738/// By default, the transformation of an address-of-label expression always
13739/// rebuilds the expression, so that the label identifier can be resolved to
13740/// the corresponding label statement by semantic analysis.
13741template<typename Derived>
13743TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
13744 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
13745 E->getLabel());
13746 if (!LD)
13747 return ExprError();
13748
13749 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
13750 cast<LabelDecl>(LD));
13751}
13752
13753template<typename Derived>
13755TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
13756 SemaRef.ActOnStartStmtExpr();
13757 StmtResult SubStmt
13758 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
13759 if (SubStmt.isInvalid()) {
13760 SemaRef.ActOnStmtExprError();
13761 return ExprError();
13762 }
13763
13764 unsigned OldDepth = E->getTemplateDepth();
13765 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
13766
13767 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
13768 SubStmt.get() == E->getSubStmt()) {
13769 // Calling this an 'error' is unintuitive, but it does the right thing.
13770 SemaRef.ActOnStmtExprError();
13771 return SemaRef.MaybeBindToTemporary(E);
13772 }
13773
13774 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
13775 E->getRParenLoc(), NewDepth);
13776}
13777
13778template<typename Derived>
13780TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
13781 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13782 if (Cond.isInvalid())
13783 return ExprError();
13784
13785 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13786 if (LHS.isInvalid())
13787 return ExprError();
13788
13789 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13790 if (RHS.isInvalid())
13791 return ExprError();
13792
13793 if (!getDerived().AlwaysRebuild() &&
13794 Cond.get() == E->getCond() &&
13795 LHS.get() == E->getLHS() &&
13796 RHS.get() == E->getRHS())
13797 return E;
13798
13799 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
13800 Cond.get(), LHS.get(), RHS.get(),
13801 E->getRParenLoc());
13802}
13803
13804template<typename Derived>
13806TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
13807 return E;
13808}
13809
13810template<typename Derived>
13812TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
13813 switch (E->getOperator()) {
13814 case OO_New:
13815 case OO_Delete:
13816 case OO_Array_New:
13817 case OO_Array_Delete:
13818 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
13819
13820 case OO_Subscript:
13821 case OO_Call: {
13822 // This is a call to an object's operator().
13823 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
13824
13825 // Transform the object itself.
13826 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
13827 if (Object.isInvalid())
13828 return ExprError();
13829
13830 // FIXME: Poor location information
13831 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
13832 static_cast<Expr *>(Object.get())->getEndLoc());
13833
13834 // Transform the call arguments.
13836 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
13837 Args))
13838 return ExprError();
13839
13840 if (E->getOperator() == OO_Subscript)
13841 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
13842 Args, E->getEndLoc());
13843
13844 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
13845 E->getEndLoc());
13846 }
13847
13848#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
13849 case OO_##Name: \
13850 break;
13851
13852#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
13853#include "clang/Basic/OperatorKinds.def"
13854
13855 case OO_Conditional:
13856 llvm_unreachable("conditional operator is not actually overloadable");
13857
13858 case OO_None:
13860 llvm_unreachable("not an overloaded operator?");
13861 }
13862
13864 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
13865 First = getDerived().TransformAddressOfOperand(E->getArg(0));
13866 else
13867 First = getDerived().TransformExpr(E->getArg(0));
13868 if (First.isInvalid())
13869 return ExprError();
13870
13871 ExprResult Second;
13872 if (E->getNumArgs() == 2) {
13873 Second =
13874 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
13875 if (Second.isInvalid())
13876 return ExprError();
13877 }
13878
13879 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13880 FPOptionsOverride NewOverrides(E->getFPFeatures());
13881 getSema().CurFPFeatures =
13882 NewOverrides.applyOverrides(getSema().getLangOpts());
13883 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13884
13885 Expr *Callee = E->getCallee();
13886 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
13887 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
13889 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
13890 return ExprError();
13891
13892 return getDerived().RebuildCXXOperatorCallExpr(
13893 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
13894 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
13895 }
13896
13897 UnresolvedSet<1> Functions;
13898 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
13899 Callee = ICE->getSubExprAsWritten();
13900 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
13901 ValueDecl *VD = cast_or_null<ValueDecl>(
13902 getDerived().TransformDecl(DR->getLocation(), DR));
13903 if (!VD)
13904 return ExprError();
13905
13906 if (!isa<CXXMethodDecl>(VD))
13907 Functions.addDecl(VD);
13908
13909 return getDerived().RebuildCXXOperatorCallExpr(
13910 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
13911 /*RequiresADL=*/false, Functions, First.get(), Second.get());
13912}
13913
13914template<typename Derived>
13916TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
13917 return getDerived().TransformCallExpr(E);
13918}
13919
13920template <typename Derived>
13921ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
13922 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
13923 getSema().CurContext != E->getParentContext();
13924
13925 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
13926 return E;
13927
13928 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
13929 E->getBeginLoc(), E->getEndLoc(),
13930 getSema().CurContext);
13931}
13932
13933template <typename Derived>
13934ExprResult TreeTransform<Derived>::TransformEmbedExpr(EmbedExpr *E) {
13935 return E;
13936}
13937
13938template<typename Derived>
13940TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
13941 // Transform the callee.
13942 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13943 if (Callee.isInvalid())
13944 return ExprError();
13945
13946 // Transform exec config.
13947 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
13948 if (EC.isInvalid())
13949 return ExprError();
13950
13951 // Transform arguments.
13952 bool ArgChanged = false;
13954 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13955 &ArgChanged))
13956 return ExprError();
13957
13958 if (!getDerived().AlwaysRebuild() &&
13959 Callee.get() == E->getCallee() &&
13960 !ArgChanged)
13961 return SemaRef.MaybeBindToTemporary(E);
13962
13963 // FIXME: Wrong source location information for the '('.
13964 SourceLocation FakeLParenLoc
13965 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13966 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13967 Args,
13968 E->getRParenLoc(), EC.get());
13969}
13970
13971template<typename Derived>
13974 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13975 if (!Type)
13976 return ExprError();
13977
13978 ExprResult SubExpr
13979 = getDerived().TransformExpr(E->getSubExprAsWritten());
13980 if (SubExpr.isInvalid())
13981 return ExprError();
13982
13983 if (!getDerived().AlwaysRebuild() &&
13984 Type == E->getTypeInfoAsWritten() &&
13985 SubExpr.get() == E->getSubExpr())
13986 return E;
13987 return getDerived().RebuildCXXNamedCastExpr(
13988 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
13989 Type, E->getAngleBrackets().getEnd(),
13990 // FIXME. this should be '(' location
13991 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
13992}
13993
13994template<typename Derived>
13997 TypeSourceInfo *TSI =
13998 getDerived().TransformType(BCE->getTypeInfoAsWritten());
13999 if (!TSI)
14000 return ExprError();
14001
14002 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
14003 if (Sub.isInvalid())
14004 return ExprError();
14005
14006 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
14007 Sub.get(), BCE->getEndLoc());
14008}
14009
14010template<typename Derived>
14012TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14013 return getDerived().TransformCXXNamedCastExpr(E);
14014}
14015
14016template<typename Derived>
14018TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
14019 return getDerived().TransformCXXNamedCastExpr(E);
14020}
14021
14022template<typename Derived>
14024TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
14025 CXXReinterpretCastExpr *E) {
14026 return getDerived().TransformCXXNamedCastExpr(E);
14027}
14028
14029template<typename Derived>
14031TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
14032 return getDerived().TransformCXXNamedCastExpr(E);
14033}
14034
14035template<typename Derived>
14037TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
14038 return getDerived().TransformCXXNamedCastExpr(E);
14039}
14040
14041template<typename Derived>
14043TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
14044 CXXFunctionalCastExpr *E) {
14045 TypeSourceInfo *Type =
14046 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14047 if (!Type)
14048 return ExprError();
14049
14050 ExprResult SubExpr
14051 = getDerived().TransformExpr(E->getSubExprAsWritten());
14052 if (SubExpr.isInvalid())
14053 return ExprError();
14054
14055 if (!getDerived().AlwaysRebuild() &&
14056 Type == E->getTypeInfoAsWritten() &&
14057 SubExpr.get() == E->getSubExpr())
14058 return E;
14059
14060 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14061 E->getLParenLoc(),
14062 SubExpr.get(),
14063 E->getRParenLoc(),
14064 E->isListInitialization());
14065}
14066
14067template<typename Derived>
14069TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
14070 if (E->isTypeOperand()) {
14071 TypeSourceInfo *TInfo
14072 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14073 if (!TInfo)
14074 return ExprError();
14075
14076 if (!getDerived().AlwaysRebuild() &&
14077 TInfo == E->getTypeOperandSourceInfo())
14078 return E;
14079
14080 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14081 TInfo, E->getEndLoc());
14082 }
14083
14084 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14085 // type. We must not unilaterally enter unevaluated context here, as then
14086 // semantic processing can re-transform an already transformed operand.
14087 Expr *Op = E->getExprOperand();
14089 if (E->isGLValue())
14090 if (auto *RecordT = Op->getType()->getAs<RecordType>())
14091 if (cast<CXXRecordDecl>(RecordT->getDecl())->isPolymorphic())
14092 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14093
14094 EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx,
14096
14097 ExprResult SubExpr = getDerived().TransformExpr(Op);
14098 if (SubExpr.isInvalid())
14099 return ExprError();
14100
14101 if (!getDerived().AlwaysRebuild() &&
14102 SubExpr.get() == E->getExprOperand())
14103 return E;
14104
14105 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14106 SubExpr.get(), E->getEndLoc());
14107}
14108
14109template<typename Derived>
14111TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
14112 if (E->isTypeOperand()) {
14113 TypeSourceInfo *TInfo
14114 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14115 if (!TInfo)
14116 return ExprError();
14117
14118 if (!getDerived().AlwaysRebuild() &&
14119 TInfo == E->getTypeOperandSourceInfo())
14120 return E;
14121
14122 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14123 TInfo, E->getEndLoc());
14124 }
14125
14126 EnterExpressionEvaluationContext Unevaluated(
14128
14129 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14130 if (SubExpr.isInvalid())
14131 return ExprError();
14132
14133 if (!getDerived().AlwaysRebuild() &&
14134 SubExpr.get() == E->getExprOperand())
14135 return E;
14136
14137 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14138 SubExpr.get(), E->getEndLoc());
14139}
14140
14141template<typename Derived>
14143TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
14144 return E;
14145}
14146
14147template<typename Derived>
14149TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
14150 CXXNullPtrLiteralExpr *E) {
14151 return E;
14152}
14153
14154template<typename Derived>
14156TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
14157
14158 // In lambdas, the qualifiers of the type depends of where in
14159 // the call operator `this` appear, and we do not have a good way to
14160 // rebuild this information, so we transform the type.
14161 //
14162 // In other contexts, the type of `this` may be overrided
14163 // for type deduction, so we need to recompute it.
14164 //
14165 // Always recompute the type if we're in the body of a lambda, and
14166 // 'this' is dependent on a lambda's explicit object parameter.
14167 QualType T = [&]() {
14168 auto &S = getSema();
14169 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14170 return S.getCurrentThisType();
14171 if (S.getCurLambda())
14172 return getDerived().TransformType(E->getType());
14173 return S.getCurrentThisType();
14174 }();
14175
14176 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
14177 // Mark it referenced in the new context regardless.
14178 // FIXME: this is a bit instantiation-specific.
14179 getSema().MarkThisReferenced(E);
14180 return E;
14181 }
14182
14183 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14184}
14185
14186template<typename Derived>
14188TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
14189 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14190 if (SubExpr.isInvalid())
14191 return ExprError();
14192
14193 if (!getDerived().AlwaysRebuild() &&
14194 SubExpr.get() == E->getSubExpr())
14195 return E;
14196
14197 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
14198 E->isThrownVariableInScope());
14199}
14200
14201template<typename Derived>
14203TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
14204 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
14205 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
14206 if (!Param)
14207 return ExprError();
14208
14209 ExprResult InitRes;
14210 if (E->hasRewrittenInit()) {
14211 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
14212 if (InitRes.isInvalid())
14213 return ExprError();
14214 }
14215
14216 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
14217 E->getUsedContext() == SemaRef.CurContext &&
14218 InitRes.get() == E->getRewrittenExpr())
14219 return E;
14220
14221 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
14222 InitRes.get());
14223}
14224
14225template<typename Derived>
14227TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
14228 FieldDecl *Field = cast_or_null<FieldDecl>(
14229 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
14230 if (!Field)
14231 return ExprError();
14232
14233 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
14234 E->getUsedContext() == SemaRef.CurContext)
14235 return E;
14236
14237 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
14238}
14239
14240template<typename Derived>
14242TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
14243 CXXScalarValueInitExpr *E) {
14244 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
14245 if (!T)
14246 return ExprError();
14247
14248 if (!getDerived().AlwaysRebuild() &&
14249 T == E->getTypeSourceInfo())
14250 return E;
14251
14252 return getDerived().RebuildCXXScalarValueInitExpr(T,
14253 /*FIXME:*/T->getTypeLoc().getEndLoc(),
14254 E->getRParenLoc());
14255}
14256
14257template<typename Derived>
14259TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
14260 // Transform the type that we're allocating
14261 TypeSourceInfo *AllocTypeInfo =
14262 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
14263 if (!AllocTypeInfo)
14264 return ExprError();
14265
14266 // Transform the size of the array we're allocating (if any).
14267 std::optional<Expr *> ArraySize;
14268 if (E->isArray()) {
14269 ExprResult NewArraySize;
14270 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
14271 NewArraySize = getDerived().TransformExpr(*OldArraySize);
14272 if (NewArraySize.isInvalid())
14273 return ExprError();
14274 }
14275 ArraySize = NewArraySize.get();
14276 }
14277
14278 // Transform the placement arguments (if any).
14279 bool ArgumentChanged = false;
14280 SmallVector<Expr*, 8> PlacementArgs;
14281 if (getDerived().TransformExprs(E->getPlacementArgs(),
14282 E->getNumPlacementArgs(), true,
14283 PlacementArgs, &ArgumentChanged))
14284 return ExprError();
14285
14286 // Transform the initializer (if any).
14287 Expr *OldInit = E->getInitializer();
14288 ExprResult NewInit;
14289 if (OldInit)
14290 NewInit = getDerived().TransformInitializer(OldInit, true);
14291 if (NewInit.isInvalid())
14292 return ExprError();
14293
14294 // Transform new operator and delete operator.
14295 FunctionDecl *OperatorNew = nullptr;
14296 if (E->getOperatorNew()) {
14297 OperatorNew = cast_or_null<FunctionDecl>(
14298 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
14299 if (!OperatorNew)
14300 return ExprError();
14301 }
14302
14303 FunctionDecl *OperatorDelete = nullptr;
14304 if (E->getOperatorDelete()) {
14305 OperatorDelete = cast_or_null<FunctionDecl>(
14306 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14307 if (!OperatorDelete)
14308 return ExprError();
14309 }
14310
14311 if (!getDerived().AlwaysRebuild() &&
14312 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
14313 ArraySize == E->getArraySize() &&
14314 NewInit.get() == OldInit &&
14315 OperatorNew == E->getOperatorNew() &&
14316 OperatorDelete == E->getOperatorDelete() &&
14317 !ArgumentChanged) {
14318 // Mark any declarations we need as referenced.
14319 // FIXME: instantiation-specific.
14320 if (OperatorNew)
14321 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
14322 if (OperatorDelete)
14323 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14324
14325 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
14326 QualType ElementType
14327 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
14328 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
14329 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
14330 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
14332 }
14333 }
14334 }
14335
14336 return E;
14337 }
14338
14339 QualType AllocType = AllocTypeInfo->getType();
14340 if (!ArraySize) {
14341 // If no array size was specified, but the new expression was
14342 // instantiated with an array type (e.g., "new T" where T is
14343 // instantiated with "int[4]"), extract the outer bound from the
14344 // array type as our array size. We do this with constant and
14345 // dependently-sized array types.
14346 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
14347 if (!ArrayT) {
14348 // Do nothing
14349 } else if (const ConstantArrayType *ConsArrayT
14350 = dyn_cast<ConstantArrayType>(ArrayT)) {
14351 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
14352 SemaRef.Context.getSizeType(),
14353 /*FIXME:*/ E->getBeginLoc());
14354 AllocType = ConsArrayT->getElementType();
14355 } else if (const DependentSizedArrayType *DepArrayT
14356 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
14357 if (DepArrayT->getSizeExpr()) {
14358 ArraySize = DepArrayT->getSizeExpr();
14359 AllocType = DepArrayT->getElementType();
14360 }
14361 }
14362 }
14363
14364 return getDerived().RebuildCXXNewExpr(
14365 E->getBeginLoc(), E->isGlobalNew(),
14366 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
14367 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
14368 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
14369}
14370
14371template<typename Derived>
14373TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
14374 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
14375 if (Operand.isInvalid())
14376 return ExprError();
14377
14378 // Transform the delete operator, if known.
14379 FunctionDecl *OperatorDelete = nullptr;
14380 if (E->getOperatorDelete()) {
14381 OperatorDelete = cast_or_null<FunctionDecl>(
14382 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14383 if (!OperatorDelete)
14384 return ExprError();
14385 }
14386
14387 if (!getDerived().AlwaysRebuild() &&
14388 Operand.get() == E->getArgument() &&
14389 OperatorDelete == E->getOperatorDelete()) {
14390 // Mark any declarations we need as referenced.
14391 // FIXME: instantiation-specific.
14392 if (OperatorDelete)
14393 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14394
14395 if (!E->getArgument()->isTypeDependent()) {
14396 QualType Destroyed = SemaRef.Context.getBaseElementType(
14397 E->getDestroyedType());
14398 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
14399 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
14401 SemaRef.LookupDestructor(Record));
14402 }
14403 }
14404
14405 return E;
14406 }
14407
14408 return getDerived().RebuildCXXDeleteExpr(
14409 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
14410}
14411
14412template<typename Derived>
14414TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
14415 CXXPseudoDestructorExpr *E) {
14416 ExprResult Base = getDerived().TransformExpr(E->getBase());
14417 if (Base.isInvalid())
14418 return ExprError();
14419
14420 ParsedType ObjectTypePtr;
14421 bool MayBePseudoDestructor = false;
14422 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14423 E->getOperatorLoc(),
14424 E->isArrow()? tok::arrow : tok::period,
14425 ObjectTypePtr,
14426 MayBePseudoDestructor);
14427 if (Base.isInvalid())
14428 return ExprError();
14429
14430 QualType ObjectType = ObjectTypePtr.get();
14431 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
14432 if (QualifierLoc) {
14433 QualifierLoc
14434 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
14435 if (!QualifierLoc)
14436 return ExprError();
14437 }
14438 CXXScopeSpec SS;
14439 SS.Adopt(QualifierLoc);
14440
14441 PseudoDestructorTypeStorage Destroyed;
14442 if (E->getDestroyedTypeInfo()) {
14443 TypeSourceInfo *DestroyedTypeInfo
14444 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
14445 ObjectType, nullptr, SS);
14446 if (!DestroyedTypeInfo)
14447 return ExprError();
14448 Destroyed = DestroyedTypeInfo;
14449 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
14450 // We aren't likely to be able to resolve the identifier down to a type
14451 // now anyway, so just retain the identifier.
14452 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
14453 E->getDestroyedTypeLoc());
14454 } else {
14455 // Look for a destructor known with the given name.
14456 ParsedType T = SemaRef.getDestructorName(
14457 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
14458 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
14459 if (!T)
14460 return ExprError();
14461
14462 Destroyed
14464 E->getDestroyedTypeLoc());
14465 }
14466
14467 TypeSourceInfo *ScopeTypeInfo = nullptr;
14468 if (E->getScopeTypeInfo()) {
14469 CXXScopeSpec EmptySS;
14470 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
14471 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
14472 if (!ScopeTypeInfo)
14473 return ExprError();
14474 }
14475
14476 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
14477 E->getOperatorLoc(),
14478 E->isArrow(),
14479 SS,
14480 ScopeTypeInfo,
14481 E->getColonColonLoc(),
14482 E->getTildeLoc(),
14483 Destroyed);
14484}
14485
14486template <typename Derived>
14488 bool RequiresADL,
14489 LookupResult &R) {
14490 // Transform all the decls.
14491 bool AllEmptyPacks = true;
14492 for (auto *OldD : Old->decls()) {
14493 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
14494 if (!InstD) {
14495 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
14496 // This can happen because of dependent hiding.
14497 if (isa<UsingShadowDecl>(OldD))
14498 continue;
14499 else {
14500 R.clear();
14501 return true;
14502 }
14503 }
14504
14505 // Expand using pack declarations.
14506 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
14507 ArrayRef<NamedDecl*> Decls = SingleDecl;
14508 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
14509 Decls = UPD->expansions();
14510
14511 // Expand using declarations.
14512 for (auto *D : Decls) {
14513 if (auto *UD = dyn_cast<UsingDecl>(D)) {
14514 for (auto *SD : UD->shadows())
14515 R.addDecl(SD);
14516 } else {
14517 R.addDecl(D);
14518 }
14519 }
14520
14521 AllEmptyPacks &= Decls.empty();
14522 }
14523
14524 // C++ [temp.res]/8.4.2:
14525 // The program is ill-formed, no diagnostic required, if [...] lookup for
14526 // a name in the template definition found a using-declaration, but the
14527 // lookup in the corresponding scope in the instantiation odoes not find
14528 // any declarations because the using-declaration was a pack expansion and
14529 // the corresponding pack is empty
14530 if (AllEmptyPacks && !RequiresADL) {
14531 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
14532 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
14533 return true;
14534 }
14535
14536 // Resolve a kind, but don't do any further analysis. If it's
14537 // ambiguous, the callee needs to deal with it.
14538 R.resolveKind();
14539
14540 if (Old->hasTemplateKeyword() && !R.empty()) {
14542 getSema().FilterAcceptableTemplateNames(R,
14543 /*AllowFunctionTemplates=*/true,
14544 /*AllowDependent=*/true);
14545 if (R.empty()) {
14546 // If a 'template' keyword was used, a lookup that finds only non-template
14547 // names is an error.
14548 getSema().Diag(R.getNameLoc(),
14549 diag::err_template_kw_refers_to_non_template)
14551 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
14552 getSema().Diag(FoundDecl->getLocation(),
14553 diag::note_template_kw_refers_to_non_template)
14554 << R.getLookupName();
14555 return true;
14556 }
14557 }
14558
14559 return false;
14560}
14561
14562template <typename Derived>
14564 UnresolvedLookupExpr *Old) {
14565 return TransformUnresolvedLookupExpr(Old, /*IsAddressOfOperand=*/false);
14566}
14567
14568template <typename Derived>
14571 bool IsAddressOfOperand) {
14572 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
14574
14575 // Transform the declaration set.
14576 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
14577 return ExprError();
14578
14579 // Rebuild the nested-name qualifier, if present.
14580 CXXScopeSpec SS;
14581 if (Old->getQualifierLoc()) {
14582 NestedNameSpecifierLoc QualifierLoc
14583 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14584 if (!QualifierLoc)
14585 return ExprError();
14586
14587 SS.Adopt(QualifierLoc);
14588 }
14589
14590 if (Old->getNamingClass()) {
14591 CXXRecordDecl *NamingClass
14592 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
14593 Old->getNameLoc(),
14594 Old->getNamingClass()));
14595 if (!NamingClass) {
14596 R.clear();
14597 return ExprError();
14598 }
14599
14600 R.setNamingClass(NamingClass);
14601 }
14602
14603 // Rebuild the template arguments, if any.
14604 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14605 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
14606 if (Old->hasExplicitTemplateArgs() &&
14607 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14608 Old->getNumTemplateArgs(),
14609 TransArgs)) {
14610 R.clear();
14611 return ExprError();
14612 }
14613
14614 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
14615 // a non-static data member is named in an unevaluated operand, or when
14616 // a member is named in a dependent class scope function template explicit
14617 // specialization that is neither declared static nor with an explicit object
14618 // parameter.
14619 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
14620 return SemaRef.BuildPossibleImplicitMemberExpr(
14621 SS, TemplateKWLoc, R,
14622 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
14623 /*S=*/nullptr);
14624
14625 // If we have neither explicit template arguments, nor the template keyword,
14626 // it's a normal declaration name or member reference.
14627 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
14628 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
14629
14630 // If we have template arguments, then rebuild the template-id expression.
14631 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
14632 Old->requiresADL(), &TransArgs);
14633}
14634
14635template<typename Derived>
14637TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
14638 bool ArgChanged = false;
14640 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
14641 TypeSourceInfo *From = E->getArg(I);
14642 TypeLoc FromTL = From->getTypeLoc();
14643 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
14644 TypeLocBuilder TLB;
14645 TLB.reserve(FromTL.getFullDataSize());
14646 QualType To = getDerived().TransformType(TLB, FromTL);
14647 if (To.isNull())
14648 return ExprError();
14649
14650 if (To == From->getType())
14651 Args.push_back(From);
14652 else {
14653 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14654 ArgChanged = true;
14655 }
14656 continue;
14657 }
14658
14659 ArgChanged = true;
14660
14661 // We have a pack expansion. Instantiate it.
14662 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
14663 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
14665 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
14666
14667 // Determine whether the set of unexpanded parameter packs can and should
14668 // be expanded.
14669 bool Expand = true;
14670 bool RetainExpansion = false;
14671 std::optional<unsigned> OrigNumExpansions =
14672 ExpansionTL.getTypePtr()->getNumExpansions();
14673 std::optional<unsigned> NumExpansions = OrigNumExpansions;
14674 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
14675 PatternTL.getSourceRange(),
14676 Unexpanded,
14677 Expand, RetainExpansion,
14678 NumExpansions))
14679 return ExprError();
14680
14681 if (!Expand) {
14682 // The transform has determined that we should perform a simple
14683 // transformation on the pack expansion, producing another pack
14684 // expansion.
14685 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
14686
14687 TypeLocBuilder TLB;
14688 TLB.reserve(From->getTypeLoc().getFullDataSize());
14689
14690 QualType To = getDerived().TransformType(TLB, PatternTL);
14691 if (To.isNull())
14692 return ExprError();
14693
14694 To = getDerived().RebuildPackExpansionType(To,
14695 PatternTL.getSourceRange(),
14696 ExpansionTL.getEllipsisLoc(),
14697 NumExpansions);
14698 if (To.isNull())
14699 return ExprError();
14700
14701 PackExpansionTypeLoc ToExpansionTL
14702 = TLB.push<PackExpansionTypeLoc>(To);
14703 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14704 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14705 continue;
14706 }
14707
14708 // Expand the pack expansion by substituting for each argument in the
14709 // pack(s).
14710 for (unsigned I = 0; I != *NumExpansions; ++I) {
14711 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
14712 TypeLocBuilder TLB;
14713 TLB.reserve(PatternTL.getFullDataSize());
14714 QualType To = getDerived().TransformType(TLB, PatternTL);
14715 if (To.isNull())
14716 return ExprError();
14717
14718 if (To->containsUnexpandedParameterPack()) {
14719 To = getDerived().RebuildPackExpansionType(To,
14720 PatternTL.getSourceRange(),
14721 ExpansionTL.getEllipsisLoc(),
14722 NumExpansions);
14723 if (To.isNull())
14724 return ExprError();
14725
14726 PackExpansionTypeLoc ToExpansionTL
14727 = TLB.push<PackExpansionTypeLoc>(To);
14728 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14729 }
14730
14731 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14732 }
14733
14734 if (!RetainExpansion)
14735 continue;
14736
14737 // If we're supposed to retain a pack expansion, do so by temporarily
14738 // forgetting the partially-substituted parameter pack.
14739 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14740
14741 TypeLocBuilder TLB;
14742 TLB.reserve(From->getTypeLoc().getFullDataSize());
14743
14744 QualType To = getDerived().TransformType(TLB, PatternTL);
14745 if (To.isNull())
14746 return ExprError();
14747
14748 To = getDerived().RebuildPackExpansionType(To,
14749 PatternTL.getSourceRange(),
14750 ExpansionTL.getEllipsisLoc(),
14751 NumExpansions);
14752 if (To.isNull())
14753 return ExprError();
14754
14755 PackExpansionTypeLoc ToExpansionTL
14756 = TLB.push<PackExpansionTypeLoc>(To);
14757 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14758 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14759 }
14760
14761 if (!getDerived().AlwaysRebuild() && !ArgChanged)
14762 return E;
14763
14764 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
14765 E->getEndLoc());
14766}
14767
14768template<typename Derived>
14770TreeTransform<Derived>::TransformConceptSpecializationExpr(
14771 ConceptSpecializationExpr *E) {
14772 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
14773 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
14774 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14775 Old->NumTemplateArgs, TransArgs))
14776 return ExprError();
14777
14778 return getDerived().RebuildConceptSpecializationExpr(
14779 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
14780 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
14781 &TransArgs);
14782}
14783
14784template<typename Derived>
14786TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) {
14787 SmallVector<ParmVarDecl*, 4> TransParams;
14788 SmallVector<QualType, 4> TransParamTypes;
14789 Sema::ExtParameterInfoBuilder ExtParamInfos;
14790
14791 // C++2a [expr.prim.req]p2
14792 // Expressions appearing within a requirement-body are unevaluated operands.
14793 EnterExpressionEvaluationContext Ctx(
14796
14797 RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
14798 getSema().Context, getSema().CurContext,
14799 E->getBody()->getBeginLoc());
14800
14801 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
14802
14803 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
14804 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
14805 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
14806
14807 for (ParmVarDecl *Param : TransParams)
14808 if (Param)
14809 Param->setDeclContext(Body);
14810
14811 // On failure to transform, TransformRequiresTypeParams returns an expression
14812 // in the event that the transformation of the type params failed in some way.
14813 // It is expected that this will result in a 'not satisfied' Requires clause
14814 // when instantiating.
14815 if (!TypeParamResult.isUnset())
14816 return TypeParamResult;
14817
14819 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
14820 TransReqs))
14821 return ExprError();
14822
14823 for (concepts::Requirement *Req : TransReqs) {
14824 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
14825 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
14826 ER->getReturnTypeRequirement()
14827 .getTypeConstraintTemplateParameterList()->getParam(0)
14828 ->setDeclContext(Body);
14829 }
14830 }
14831 }
14832
14833 return getDerived().RebuildRequiresExpr(
14834 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
14835 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
14836}
14837
14838template<typename Derived>
14842 for (concepts::Requirement *Req : Reqs) {
14843 concepts::Requirement *TransReq = nullptr;
14844 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
14845 TransReq = getDerived().TransformTypeRequirement(TypeReq);
14846 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
14847 TransReq = getDerived().TransformExprRequirement(ExprReq);
14848 else
14849 TransReq = getDerived().TransformNestedRequirement(
14850 cast<concepts::NestedRequirement>(Req));
14851 if (!TransReq)
14852 return true;
14853 Transformed.push_back(TransReq);
14854 }
14855 return false;
14856}
14857
14858template<typename Derived>
14862 if (Req->isSubstitutionFailure()) {
14863 if (getDerived().AlwaysRebuild())
14864 return getDerived().RebuildTypeRequirement(
14866 return Req;
14867 }
14868 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
14869 if (!TransType)
14870 return nullptr;
14871 return getDerived().RebuildTypeRequirement(TransType);
14872}
14873
14874template<typename Derived>
14877 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
14878 if (Req->isExprSubstitutionFailure())
14879 TransExpr = Req->getExprSubstitutionDiagnostic();
14880 else {
14881 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
14882 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
14883 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
14884 if (TransExprRes.isInvalid())
14885 return nullptr;
14886 TransExpr = TransExprRes.get();
14887 }
14888
14889 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
14890 const auto &RetReq = Req->getReturnTypeRequirement();
14891 if (RetReq.isEmpty())
14892 TransRetReq.emplace();
14893 else if (RetReq.isSubstitutionFailure())
14894 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
14895 else if (RetReq.isTypeConstraint()) {
14896 TemplateParameterList *OrigTPL =
14897 RetReq.getTypeConstraintTemplateParameterList();
14899 getDerived().TransformTemplateParameterList(OrigTPL);
14900 if (!TPL)
14901 return nullptr;
14902 TransRetReq.emplace(TPL);
14903 }
14904 assert(TransRetReq && "All code paths leading here must set TransRetReq");
14905 if (Expr *E = TransExpr.dyn_cast<Expr *>())
14906 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
14907 Req->getNoexceptLoc(),
14908 std::move(*TransRetReq));
14909 return getDerived().RebuildExprRequirement(
14910 cast<concepts::Requirement::SubstitutionDiagnostic *>(TransExpr),
14911 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
14912}
14913
14914template<typename Derived>
14918 if (Req->hasInvalidConstraint()) {
14919 if (getDerived().AlwaysRebuild())
14920 return getDerived().RebuildNestedRequirement(
14922 return Req;
14923 }
14924 ExprResult TransConstraint =
14925 getDerived().TransformExpr(Req->getConstraintExpr());
14926 if (TransConstraint.isInvalid())
14927 return nullptr;
14928 return getDerived().RebuildNestedRequirement(TransConstraint.get());
14929}
14930
14931template<typename Derived>
14934 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
14935 if (!T)
14936 return ExprError();
14937
14938 if (!getDerived().AlwaysRebuild() &&
14939 T == E->getQueriedTypeSourceInfo())
14940 return E;
14941
14942 ExprResult SubExpr;
14943 {
14946 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
14947 if (SubExpr.isInvalid())
14948 return ExprError();
14949
14950 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
14951 return E;
14952 }
14953
14954 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
14955 SubExpr.get(), E->getEndLoc());
14956}
14957
14958template<typename Derived>
14960TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
14961 ExprResult SubExpr;
14962 {
14963 EnterExpressionEvaluationContext Unevaluated(
14965 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
14966 if (SubExpr.isInvalid())
14967 return ExprError();
14968
14969 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
14970 return E;
14971 }
14972
14973 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
14974 SubExpr.get(), E->getEndLoc());
14975}
14976
14977template <typename Derived>
14979 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
14980 TypeSourceInfo **RecoveryTSI) {
14981 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
14982 DRE, AddrTaken, RecoveryTSI);
14983
14984 // Propagate both errors and recovered types, which return ExprEmpty.
14985 if (!NewDRE.isUsable())
14986 return NewDRE;
14987
14988 // We got an expr, wrap it up in parens.
14989 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
14990 return PE;
14991 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
14992 PE->getRParen());
14993}
14994
14995template <typename Derived>
14998 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
14999 nullptr);
15000}
15001
15002template <typename Derived>
15004 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
15005 TypeSourceInfo **RecoveryTSI) {
15006 assert(E->getQualifierLoc());
15007 NestedNameSpecifierLoc QualifierLoc =
15008 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
15009 if (!QualifierLoc)
15010 return ExprError();
15011 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15012
15013 // TODO: If this is a conversion-function-id, verify that the
15014 // destination type name (if present) resolves the same way after
15015 // instantiation as it did in the local scope.
15016
15017 DeclarationNameInfo NameInfo =
15018 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15019 if (!NameInfo.getName())
15020 return ExprError();
15021
15022 if (!E->hasExplicitTemplateArgs()) {
15023 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15024 // Note: it is sufficient to compare the Name component of NameInfo:
15025 // if name has not changed, DNLoc has not changed either.
15026 NameInfo.getName() == E->getDeclName())
15027 return E;
15028
15029 return getDerived().RebuildDependentScopeDeclRefExpr(
15030 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15031 IsAddressOfOperand, RecoveryTSI);
15032 }
15033
15034 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15035 if (getDerived().TransformTemplateArguments(
15036 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15037 return ExprError();
15038
15039 return getDerived().RebuildDependentScopeDeclRefExpr(
15040 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15041 RecoveryTSI);
15042}
15043
15044template<typename Derived>
15046TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
15047 // CXXConstructExprs other than for list-initialization and
15048 // CXXTemporaryObjectExpr are always implicit, so when we have
15049 // a 1-argument construction we just transform that argument.
15050 if (getDerived().AllowSkippingCXXConstructExpr() &&
15051 ((E->getNumArgs() == 1 ||
15052 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15053 (!getDerived().DropCallArgument(E->getArg(0))) &&
15054 !E->isListInitialization()))
15055 return getDerived().TransformInitializer(E->getArg(0),
15056 /*DirectInit*/ false);
15057
15058 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15059
15060 QualType T = getDerived().TransformType(E->getType());
15061 if (T.isNull())
15062 return ExprError();
15063
15064 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15065 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15066 if (!Constructor)
15067 return ExprError();
15068
15069 bool ArgumentChanged = false;
15071 {
15072 EnterExpressionEvaluationContext Context(
15074 E->isListInitialization());
15075 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15076 &ArgumentChanged))
15077 return ExprError();
15078 }
15079
15080 if (!getDerived().AlwaysRebuild() &&
15081 T == E->getType() &&
15082 Constructor == E->getConstructor() &&
15083 !ArgumentChanged) {
15084 // Mark the constructor as referenced.
15085 // FIXME: Instantiation-specific
15086 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15087 return E;
15088 }
15089
15090 return getDerived().RebuildCXXConstructExpr(
15091 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15092 E->hadMultipleCandidates(), E->isListInitialization(),
15093 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15094 E->getConstructionKind(), E->getParenOrBraceRange());
15095}
15096
15097template<typename Derived>
15098ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
15099 CXXInheritedCtorInitExpr *E) {
15100 QualType T = getDerived().TransformType(E->getType());
15101 if (T.isNull())
15102 return ExprError();
15103
15104 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15105 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15106 if (!Constructor)
15107 return ExprError();
15108
15109 if (!getDerived().AlwaysRebuild() &&
15110 T == E->getType() &&
15111 Constructor == E->getConstructor()) {
15112 // Mark the constructor as referenced.
15113 // FIXME: Instantiation-specific
15114 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15115 return E;
15116 }
15117
15118 return getDerived().RebuildCXXInheritedCtorInitExpr(
15119 T, E->getLocation(), Constructor,
15120 E->constructsVBase(), E->inheritedFromVBase());
15121}
15122
15123/// Transform a C++ temporary-binding expression.
15124///
15125/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15126/// transform the subexpression and return that.
15127template<typename Derived>
15129TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
15130 if (auto *Dtor = E->getTemporary()->getDestructor())
15132 const_cast<CXXDestructorDecl *>(Dtor));
15133 return getDerived().TransformExpr(E->getSubExpr());
15134}
15135
15136/// Transform a C++ expression that contains cleanups that should
15137/// be run after the expression is evaluated.
15138///
15139/// Since ExprWithCleanups nodes are implicitly generated, we
15140/// just transform the subexpression and return that.
15141template<typename Derived>
15143TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
15144 return getDerived().TransformExpr(E->getSubExpr());
15145}
15146
15147template<typename Derived>
15149TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
15150 CXXTemporaryObjectExpr *E) {
15151 TypeSourceInfo *T =
15152 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15153 if (!T)
15154 return ExprError();
15155
15156 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15157 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15158 if (!Constructor)
15159 return ExprError();
15160
15161 bool ArgumentChanged = false;
15163 Args.reserve(E->getNumArgs());
15164 {
15165 EnterExpressionEvaluationContext Context(
15167 E->isListInitialization());
15168 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15169 &ArgumentChanged))
15170 return ExprError();
15171
15172 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15173 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc());
15174 if (Res.isInvalid())
15175 return ExprError();
15176 Args = {Res.get()};
15177 }
15178 }
15179
15180 if (!getDerived().AlwaysRebuild() &&
15181 T == E->getTypeSourceInfo() &&
15182 Constructor == E->getConstructor() &&
15183 !ArgumentChanged) {
15184 // FIXME: Instantiation-specific
15185 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15186 return SemaRef.MaybeBindToTemporary(E);
15187 }
15188
15189 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15190 return getDerived().RebuildCXXTemporaryObjectExpr(
15191 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15192}
15193
15194template<typename Derived>
15196TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
15197 // Transform any init-capture expressions before entering the scope of the
15198 // lambda body, because they are not semantically within that scope.
15199 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15200 struct TransformedInitCapture {
15201 // The location of the ... if the result is retaining a pack expansion.
15202 SourceLocation EllipsisLoc;
15203 // Zero or more expansions of the init-capture.
15205 };
15207 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
15208 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15209 CEnd = E->capture_end();
15210 C != CEnd; ++C) {
15211 if (!E->isInitCapture(C))
15212 continue;
15213
15214 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
15215 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15216
15217 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
15218 std::optional<unsigned> NumExpansions) {
15219 ExprResult NewExprInitResult = getDerived().TransformInitializer(
15220 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
15221
15222 if (NewExprInitResult.isInvalid()) {
15223 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
15224 return;
15225 }
15226 Expr *NewExprInit = NewExprInitResult.get();
15227
15228 QualType NewInitCaptureType =
15229 getSema().buildLambdaInitCaptureInitialization(
15230 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
15231 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
15232 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
15234 NewExprInit);
15235 Result.Expansions.push_back(
15236 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
15237 };
15238
15239 // If this is an init-capture pack, consider expanding the pack now.
15240 if (OldVD->isParameterPack()) {
15241 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
15242 ->getTypeLoc()
15243 .castAs<PackExpansionTypeLoc>();
15245 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
15246
15247 // Determine whether the set of unexpanded parameter packs can and should
15248 // be expanded.
15249 bool Expand = true;
15250 bool RetainExpansion = false;
15251 std::optional<unsigned> OrigNumExpansions =
15252 ExpansionTL.getTypePtr()->getNumExpansions();
15253 std::optional<unsigned> NumExpansions = OrigNumExpansions;
15254 if (getDerived().TryExpandParameterPacks(
15255 ExpansionTL.getEllipsisLoc(),
15256 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
15257 RetainExpansion, NumExpansions))
15258 return ExprError();
15259 assert(!RetainExpansion && "Should not need to retain expansion after a "
15260 "capture since it cannot be extended");
15261 if (Expand) {
15262 for (unsigned I = 0; I != *NumExpansions; ++I) {
15263 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15264 SubstInitCapture(SourceLocation(), std::nullopt);
15265 }
15266 } else {
15267 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
15268 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
15269 }
15270 } else {
15271 SubstInitCapture(SourceLocation(), std::nullopt);
15272 }
15273 }
15274
15275 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
15276 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
15277
15278 // Create the local class that will describe the lambda.
15279
15280 // FIXME: DependencyKind below is wrong when substituting inside a templated
15281 // context that isn't a DeclContext (such as a variable template), or when
15282 // substituting an unevaluated lambda inside of a function's parameter's type
15283 // - as parameter types are not instantiated from within a function's DC. We
15284 // use evaluation contexts to distinguish the function parameter case.
15287 DeclContext *DC = getSema().CurContext;
15288 // A RequiresExprBodyDecl is not interesting for dependencies.
15289 // For the following case,
15290 //
15291 // template <typename>
15292 // concept C = requires { [] {}; };
15293 //
15294 // template <class F>
15295 // struct Widget;
15296 //
15297 // template <C F>
15298 // struct Widget<F> {};
15299 //
15300 // While we are substituting Widget<F>, the parent of DC would be
15301 // the template specialization itself. Thus, the lambda expression
15302 // will be deemed as dependent even if there are no dependent template
15303 // arguments.
15304 // (A ClassTemplateSpecializationDecl is always a dependent context.)
15305 while (DC->isRequiresExprBody())
15306 DC = DC->getParent();
15307 if ((getSema().isUnevaluatedContext() ||
15308 getSema().isConstantEvaluatedContext()) &&
15309 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
15310 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
15311
15312 CXXRecordDecl *OldClass = E->getLambdaClass();
15313 CXXRecordDecl *Class = getSema().createLambdaClosureType(
15314 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
15315 E->getCaptureDefault());
15316 getDerived().transformedLocalDecl(OldClass, {Class});
15317
15318 CXXMethodDecl *NewCallOperator =
15319 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
15320
15321 // Enter the scope of the lambda.
15322 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
15323 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
15324 E->hasExplicitParameters(), E->isMutable());
15325
15326 // Introduce the context of the call operator.
15327 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
15328 /*NewThisContext*/false);
15329
15330 bool Invalid = false;
15331
15332 // Transform captures.
15333 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15334 CEnd = E->capture_end();
15335 C != CEnd; ++C) {
15336 // When we hit the first implicit capture, tell Sema that we've finished
15337 // the list of explicit captures.
15338 if (C->isImplicit())
15339 break;
15340
15341 // Capturing 'this' is trivial.
15342 if (C->capturesThis()) {
15343 // If this is a lambda that is part of a default member initialiser
15344 // and which we're instantiating outside the class that 'this' is
15345 // supposed to refer to, adjust the type of 'this' accordingly.
15346 //
15347 // Otherwise, leave the type of 'this' as-is.
15348 Sema::CXXThisScopeRAII ThisScope(
15349 getSema(),
15350 dyn_cast_if_present<CXXRecordDecl>(
15351 getSema().getFunctionLevelDeclContext()),
15352 Qualifiers());
15353 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15354 /*BuildAndDiagnose*/ true, nullptr,
15355 C->getCaptureKind() == LCK_StarThis);
15356 continue;
15357 }
15358 // Captured expression will be recaptured during captured variables
15359 // rebuilding.
15360 if (C->capturesVLAType())
15361 continue;
15362
15363 // Rebuild init-captures, including the implied field declaration.
15364 if (E->isInitCapture(C)) {
15365 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
15366
15367 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15369
15370 for (InitCaptureInfoTy &Info : NewC.Expansions) {
15371 ExprResult Init = Info.first;
15372 QualType InitQualType = Info.second;
15373 if (Init.isInvalid() || InitQualType.isNull()) {
15374 Invalid = true;
15375 break;
15376 }
15377 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
15378 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
15379 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
15380 getSema().CurContext);
15381 if (!NewVD) {
15382 Invalid = true;
15383 break;
15384 }
15385 NewVDs.push_back(NewVD);
15386 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
15387 // Cases we want to tackle:
15388 // ([C(Pack)] {}, ...)
15389 // But rule out cases e.g.
15390 // [...C = Pack()] {}
15391 if (NewC.EllipsisLoc.isInvalid())
15392 LSI->ContainsUnexpandedParameterPack |=
15393 Init.get()->containsUnexpandedParameterPack();
15394 }
15395
15396 if (Invalid)
15397 break;
15398
15399 getDerived().transformedLocalDecl(OldVD, NewVDs);
15400 continue;
15401 }
15402
15403 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15404
15405 // Determine the capture kind for Sema.
15407 = C->isImplicit()? Sema::TryCapture_Implicit
15408 : C->getCaptureKind() == LCK_ByCopy
15411 SourceLocation EllipsisLoc;
15412 if (C->isPackExpansion()) {
15413 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
15414 bool ShouldExpand = false;
15415 bool RetainExpansion = false;
15416 std::optional<unsigned> NumExpansions;
15417 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
15418 C->getLocation(),
15419 Unexpanded,
15420 ShouldExpand, RetainExpansion,
15421 NumExpansions)) {
15422 Invalid = true;
15423 continue;
15424 }
15425
15426 if (ShouldExpand) {
15427 // The transform has determined that we should perform an expansion;
15428 // transform and capture each of the arguments.
15429 // expansion of the pattern. Do so.
15430 auto *Pack = cast<VarDecl>(C->getCapturedVar());
15431 for (unsigned I = 0; I != *NumExpansions; ++I) {
15432 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15433 VarDecl *CapturedVar
15434 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
15435 Pack));
15436 if (!CapturedVar) {
15437 Invalid = true;
15438 continue;
15439 }
15440
15441 // Capture the transformed variable.
15442 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
15443 }
15444
15445 // FIXME: Retain a pack expansion if RetainExpansion is true.
15446
15447 continue;
15448 }
15449
15450 EllipsisLoc = C->getEllipsisLoc();
15451 }
15452
15453 // Transform the captured variable.
15454 auto *CapturedVar = cast_or_null<ValueDecl>(
15455 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15456 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
15457 Invalid = true;
15458 continue;
15459 }
15460
15461 // This is not an init-capture; however it contains an unexpanded pack e.g.
15462 // ([Pack] {}(), ...)
15463 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
15464 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
15465
15466 // Capture the transformed variable.
15467 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
15468 EllipsisLoc);
15469 }
15470 getSema().finishLambdaExplicitCaptures(LSI);
15471
15472 // Transform the template parameters, and add them to the current
15473 // instantiation scope. The null case is handled correctly.
15474 auto TPL = getDerived().TransformTemplateParameterList(
15475 E->getTemplateParameterList());
15476 LSI->GLTemplateParameterList = TPL;
15477 if (TPL) {
15478 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
15479 TPL);
15480 LSI->ContainsUnexpandedParameterPack |=
15481 TPL->containsUnexpandedParameterPack();
15482 }
15483
15484 TypeLocBuilder NewCallOpTLBuilder;
15485 TypeLoc OldCallOpTypeLoc =
15486 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
15487 QualType NewCallOpType =
15488 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
15489 if (NewCallOpType.isNull())
15490 return ExprError();
15491 LSI->ContainsUnexpandedParameterPack |=
15492 NewCallOpType->containsUnexpandedParameterPack();
15493 TypeSourceInfo *NewCallOpTSI =
15494 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
15495
15496 // The type may be an AttributedType or some other kind of sugar;
15497 // get the actual underlying FunctionProtoType.
15498 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
15499 assert(FPTL && "Not a FunctionProtoType?");
15500
15501 getSema().CompleteLambdaCallOperator(
15502 NewCallOperator, E->getCallOperator()->getLocation(),
15503 E->getCallOperator()->getInnerLocStart(),
15504 E->getCallOperator()->getTrailingRequiresClause(), NewCallOpTSI,
15505 E->getCallOperator()->getConstexprKind(),
15506 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
15507 E->hasExplicitResultType());
15508
15509 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
15510 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
15511
15512 {
15513 // Number the lambda for linkage purposes if necessary.
15514 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
15515
15516 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
15517 if (getDerived().ReplacingOriginal()) {
15518 Numbering = OldClass->getLambdaNumbering();
15519 }
15520
15521 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
15522 }
15523
15524 // FIXME: Sema's lambda-building mechanism expects us to push an expression
15525 // evaluation context even if we're not transforming the function body.
15526 getSema().PushExpressionEvaluationContext(
15527 E->getCallOperator()->isConsteval() ?
15530 getSema().currentEvaluationContext().InImmediateEscalatingFunctionContext =
15531 getSema().getLangOpts().CPlusPlus20 &&
15532 E->getCallOperator()->isImmediateEscalating();
15533
15534 Sema::CodeSynthesisContext C;
15536 C.PointOfInstantiation = E->getBody()->getBeginLoc();
15537 getSema().pushCodeSynthesisContext(C);
15538
15539 // Instantiate the body of the lambda expression.
15540 StmtResult Body =
15541 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
15542
15543 getSema().popCodeSynthesisContext();
15544
15545 // ActOnLambda* will pop the function scope for us.
15546 FuncScopeCleanup.disable();
15547
15548 if (Body.isInvalid()) {
15549 SavedContext.pop();
15550 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
15551 /*IsInstantiation=*/true);
15552 return ExprError();
15553 }
15554
15555 // Copy the LSI before ActOnFinishFunctionBody removes it.
15556 // FIXME: This is dumb. Store the lambda information somewhere that outlives
15557 // the call operator.
15558 auto LSICopy = *LSI;
15559 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15560 /*IsInstantiation*/ true);
15561 SavedContext.pop();
15562
15563 // Recompute the dependency of the lambda so that we can defer the lambda call
15564 // construction until after we have all the necessary template arguments. For
15565 // example, given
15566 //
15567 // template <class> struct S {
15568 // template <class U>
15569 // using Type = decltype([](U){}(42.0));
15570 // };
15571 // void foo() {
15572 // using T = S<int>::Type<float>;
15573 // ^~~~~~
15574 // }
15575 //
15576 // We would end up here from instantiating S<int> when ensuring its
15577 // completeness. That would transform the lambda call expression regardless of
15578 // the absence of the corresponding argument for U.
15579 //
15580 // Going ahead with unsubstituted type U makes things worse: we would soon
15581 // compare the argument type (which is float) against the parameter U
15582 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
15583 // error suggesting unmatched types 'U' and 'float'!
15584 //
15585 // That said, everything will be fine if we defer that semantic checking.
15586 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
15587 // dependent. Since the CallExpr's dependency boils down to the lambda's
15588 // dependency in this case, we can harness that by recomputing the dependency
15589 // from the instantiation arguments.
15590 //
15591 // FIXME: Creating the type of a lambda requires us to have a dependency
15592 // value, which happens before its substitution. We update its dependency
15593 // *after* the substitution in case we can't decide the dependency
15594 // so early, e.g. because we want to see if any of the *substituted*
15595 // parameters are dependent.
15596 DependencyKind = getDerived().ComputeLambdaDependency(&LSICopy);
15597 Class->setLambdaDependencyKind(DependencyKind);
15598 // Clean up the type cache created previously. Then, we re-create a type for
15599 // such Decl with the new DependencyKind.
15600 Class->setTypeForDecl(nullptr);
15601 getSema().Context.getTypeDeclType(Class);
15602
15603 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15604 Body.get()->getEndLoc(), &LSICopy);
15605}
15606
15607template<typename Derived>
15610 return TransformStmt(S);
15611}
15612
15613template<typename Derived>
15616 // Transform captures.
15617 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15618 CEnd = E->capture_end();
15619 C != CEnd; ++C) {
15620 // When we hit the first implicit capture, tell Sema that we've finished
15621 // the list of explicit captures.
15622 if (!C->isImplicit())
15623 continue;
15624
15625 // Capturing 'this' is trivial.
15626 if (C->capturesThis()) {
15627 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15628 /*BuildAndDiagnose*/ true, nullptr,
15629 C->getCaptureKind() == LCK_StarThis);
15630 continue;
15631 }
15632 // Captured expression will be recaptured during captured variables
15633 // rebuilding.
15634 if (C->capturesVLAType())
15635 continue;
15636
15637 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15638 assert(!E->isInitCapture(C) && "implicit init-capture?");
15639
15640 // Transform the captured variable.
15641 VarDecl *CapturedVar = cast_or_null<VarDecl>(
15642 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15643 if (!CapturedVar || CapturedVar->isInvalidDecl())
15644 return StmtError();
15645
15646 // Capture the transformed variable.
15647 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
15648 }
15649
15650 return S;
15651}
15652
15653template<typename Derived>
15657 TypeSourceInfo *T =
15658 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15659 if (!T)
15660 return ExprError();
15661
15662 bool ArgumentChanged = false;
15664 Args.reserve(E->getNumArgs());
15665 {
15668 E->isListInitialization());
15669 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
15670 &ArgumentChanged))
15671 return ExprError();
15672 }
15673
15674 if (!getDerived().AlwaysRebuild() &&
15675 T == E->getTypeSourceInfo() &&
15676 !ArgumentChanged)
15677 return E;
15678
15679 // FIXME: we're faking the locations of the commas
15680 return getDerived().RebuildCXXUnresolvedConstructExpr(
15681 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
15682}
15683
15684template<typename Derived>
15686TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
15687 CXXDependentScopeMemberExpr *E) {
15688 // Transform the base of the expression.
15689 ExprResult Base((Expr*) nullptr);
15690 Expr *OldBase;
15691 QualType BaseType;
15692 QualType ObjectType;
15693 if (!E->isImplicitAccess()) {
15694 OldBase = E->getBase();
15695 Base = getDerived().TransformExpr(OldBase);
15696 if (Base.isInvalid())
15697 return ExprError();
15698
15699 // Start the member reference and compute the object's type.
15700 ParsedType ObjectTy;
15701 bool MayBePseudoDestructor = false;
15702 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15703 E->getOperatorLoc(),
15704 E->isArrow()? tok::arrow : tok::period,
15705 ObjectTy,
15706 MayBePseudoDestructor);
15707 if (Base.isInvalid())
15708 return ExprError();
15709
15710 ObjectType = ObjectTy.get();
15711 BaseType = ((Expr*) Base.get())->getType();
15712 } else {
15713 OldBase = nullptr;
15714 BaseType = getDerived().TransformType(E->getBaseType());
15715 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
15716 }
15717
15718 // Transform the first part of the nested-name-specifier that qualifies
15719 // the member name.
15720 NamedDecl *FirstQualifierInScope
15721 = getDerived().TransformFirstQualifierInScope(
15722 E->getFirstQualifierFoundInScope(),
15723 E->getQualifierLoc().getBeginLoc());
15724
15725 NestedNameSpecifierLoc QualifierLoc;
15726 if (E->getQualifier()) {
15727 QualifierLoc
15728 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
15729 ObjectType,
15730 FirstQualifierInScope);
15731 if (!QualifierLoc)
15732 return ExprError();
15733 }
15734
15735 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15736
15737 // TODO: If this is a conversion-function-id, verify that the
15738 // destination type name (if present) resolves the same way after
15739 // instantiation as it did in the local scope.
15740
15741 DeclarationNameInfo NameInfo
15742 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
15743 if (!NameInfo.getName())
15744 return ExprError();
15745
15746 if (!E->hasExplicitTemplateArgs()) {
15747 // This is a reference to a member without an explicitly-specified
15748 // template argument list. Optimize for this common case.
15749 if (!getDerived().AlwaysRebuild() &&
15750 Base.get() == OldBase &&
15751 BaseType == E->getBaseType() &&
15752 QualifierLoc == E->getQualifierLoc() &&
15753 NameInfo.getName() == E->getMember() &&
15754 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
15755 return E;
15756
15757 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15758 BaseType,
15759 E->isArrow(),
15760 E->getOperatorLoc(),
15761 QualifierLoc,
15762 TemplateKWLoc,
15763 FirstQualifierInScope,
15764 NameInfo,
15765 /*TemplateArgs*/nullptr);
15766 }
15767
15768 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15769 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
15770 E->getNumTemplateArgs(),
15771 TransArgs))
15772 return ExprError();
15773
15774 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15775 BaseType,
15776 E->isArrow(),
15777 E->getOperatorLoc(),
15778 QualifierLoc,
15779 TemplateKWLoc,
15780 FirstQualifierInScope,
15781 NameInfo,
15782 &TransArgs);
15783}
15784
15785template <typename Derived>
15786ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
15787 UnresolvedMemberExpr *Old) {
15788 // Transform the base of the expression.
15789 ExprResult Base((Expr *)nullptr);
15790 QualType BaseType;
15791 if (!Old->isImplicitAccess()) {
15792 Base = getDerived().TransformExpr(Old->getBase());
15793 if (Base.isInvalid())
15794 return ExprError();
15795 Base =
15796 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
15797 if (Base.isInvalid())
15798 return ExprError();
15799 BaseType = Base.get()->getType();
15800 } else {
15801 BaseType = getDerived().TransformType(Old->getBaseType());
15802 }
15803
15804 NestedNameSpecifierLoc QualifierLoc;
15805 if (Old->getQualifierLoc()) {
15806 QualifierLoc =
15807 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15808 if (!QualifierLoc)
15809 return ExprError();
15810 }
15811
15812 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15813
15814 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
15815
15816 // Transform the declaration set.
15817 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
15818 return ExprError();
15819
15820 // Determine the naming class.
15821 if (Old->getNamingClass()) {
15822 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
15823 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
15824 if (!NamingClass)
15825 return ExprError();
15826
15827 R.setNamingClass(NamingClass);
15828 }
15829
15830 TemplateArgumentListInfo TransArgs;
15831 if (Old->hasExplicitTemplateArgs()) {
15832 TransArgs.setLAngleLoc(Old->getLAngleLoc());
15833 TransArgs.setRAngleLoc(Old->getRAngleLoc());
15834 if (getDerived().TransformTemplateArguments(
15835 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
15836 return ExprError();
15837 }
15838
15839 // FIXME: to do this check properly, we will need to preserve the
15840 // first-qualifier-in-scope here, just in case we had a dependent
15841 // base (and therefore couldn't do the check) and a
15842 // nested-name-qualifier (and therefore could do the lookup).
15843 NamedDecl *FirstQualifierInScope = nullptr;
15844
15845 return getDerived().RebuildUnresolvedMemberExpr(
15846 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
15847 TemplateKWLoc, FirstQualifierInScope, R,
15848 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
15849}
15850
15851template<typename Derived>
15853TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
15854 EnterExpressionEvaluationContext Unevaluated(
15856 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
15857 if (SubExpr.isInvalid())
15858 return ExprError();
15859
15860 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
15861 return E;
15862
15863 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
15864}
15865
15866template<typename Derived>
15868TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
15869 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
15870 if (Pattern.isInvalid())
15871 return ExprError();
15872
15873 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
15874 return E;
15875
15876 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
15877 E->getNumExpansions());
15878}
15879
15880template<typename Derived>
15882TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
15883 // If E is not value-dependent, then nothing will change when we transform it.
15884 // Note: This is an instantiation-centric view.
15885 if (!E->isValueDependent())
15886 return E;
15887
15888 EnterExpressionEvaluationContext Unevaluated(
15890
15892 TemplateArgument ArgStorage;
15893
15894 // Find the argument list to transform.
15895 if (E->isPartiallySubstituted()) {
15896 PackArgs = E->getPartialArguments();
15897 } else if (E->isValueDependent()) {
15898 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
15899 bool ShouldExpand = false;
15900 bool RetainExpansion = false;
15901 std::optional<unsigned> NumExpansions;
15902 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
15903 Unexpanded,
15904 ShouldExpand, RetainExpansion,
15905 NumExpansions))
15906 return ExprError();
15907
15908 // If we need to expand the pack, build a template argument from it and
15909 // expand that.
15910 if (ShouldExpand) {
15911 auto *Pack = E->getPack();
15912 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
15913 ArgStorage = getSema().Context.getPackExpansionType(
15914 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
15915 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
15916 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
15917 } else {
15918 auto *VD = cast<ValueDecl>(Pack);
15919 ExprResult DRE = getSema().BuildDeclRefExpr(
15920 VD, VD->getType().getNonLValueExprType(getSema().Context),
15921 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
15922 E->getPackLoc());
15923 if (DRE.isInvalid())
15924 return ExprError();
15925 ArgStorage = new (getSema().Context)
15926 PackExpansionExpr(getSema().Context.DependentTy, DRE.get(),
15927 E->getPackLoc(), std::nullopt);
15928 }
15929 PackArgs = ArgStorage;
15930 }
15931 }
15932
15933 // If we're not expanding the pack, just transform the decl.
15934 if (!PackArgs.size()) {
15935 auto *Pack = cast_or_null<NamedDecl>(
15936 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
15937 if (!Pack)
15938 return ExprError();
15939 return getDerived().RebuildSizeOfPackExpr(
15940 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
15941 std::nullopt, {});
15942 }
15943
15944 // Try to compute the result without performing a partial substitution.
15945 std::optional<unsigned> Result = 0;
15946 for (const TemplateArgument &Arg : PackArgs) {
15947 if (!Arg.isPackExpansion()) {
15948 Result = *Result + 1;
15949 continue;
15950 }
15951
15952 TemplateArgumentLoc ArgLoc;
15953 InventTemplateArgumentLoc(Arg, ArgLoc);
15954
15955 // Find the pattern of the pack expansion.
15956 SourceLocation Ellipsis;
15957 std::optional<unsigned> OrigNumExpansions;
15958 TemplateArgumentLoc Pattern =
15959 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
15960 OrigNumExpansions);
15961
15962 // Substitute under the pack expansion. Do not expand the pack (yet).
15963 TemplateArgumentLoc OutPattern;
15964 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15965 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
15966 /*Uneval*/ true))
15967 return true;
15968
15969 // See if we can determine the number of arguments from the result.
15970 std::optional<unsigned> NumExpansions =
15971 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
15972 if (!NumExpansions) {
15973 // No: we must be in an alias template expansion, and we're going to need
15974 // to actually expand the packs.
15975 Result = std::nullopt;
15976 break;
15977 }
15978
15979 Result = *Result + *NumExpansions;
15980 }
15981
15982 // Common case: we could determine the number of expansions without
15983 // substituting.
15984 if (Result)
15985 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
15986 E->getPackLoc(),
15987 E->getRParenLoc(), *Result, {});
15988
15989 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
15990 E->getPackLoc());
15991 {
15992 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
15993 typedef TemplateArgumentLocInventIterator<
15994 Derived, const TemplateArgument*> PackLocIterator;
15995 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
15996 PackLocIterator(*this, PackArgs.end()),
15997 TransformedPackArgs, /*Uneval*/true))
15998 return ExprError();
15999 }
16000
16001 // Check whether we managed to fully-expand the pack.
16002 // FIXME: Is it possible for us to do so and not hit the early exit path?
16004 bool PartialSubstitution = false;
16005 for (auto &Loc : TransformedPackArgs.arguments()) {
16006 Args.push_back(Loc.getArgument());
16007 if (Loc.getArgument().isPackExpansion())
16008 PartialSubstitution = true;
16009 }
16010
16011 if (PartialSubstitution)
16012 return getDerived().RebuildSizeOfPackExpr(
16013 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16014 std::nullopt, Args);
16015
16016 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16017 E->getPackLoc(), E->getRParenLoc(),
16018 Args.size(), {});
16019}
16020
16021template <typename Derived>
16023TreeTransform<Derived>::TransformPackIndexingExpr(PackIndexingExpr *E) {
16024 if (!E->isValueDependent())
16025 return E;
16026
16027 // Transform the index
16028 ExprResult IndexExpr;
16029 {
16030 EnterExpressionEvaluationContext ConstantContext(
16032 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16033 if (IndexExpr.isInvalid())
16034 return ExprError();
16035 }
16036
16037 SmallVector<Expr *, 5> ExpandedExprs;
16038 bool FullySubstituted = true;
16039 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16040 Expr *Pattern = E->getPackIdExpression();
16042 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16043 Unexpanded);
16044 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16045
16046 // Determine whether the set of unexpanded parameter packs can and should
16047 // be expanded.
16048 bool ShouldExpand = true;
16049 bool RetainExpansion = false;
16050 std::optional<unsigned> OrigNumExpansions;
16051 std::optional<unsigned> NumExpansions = OrigNumExpansions;
16052 if (getDerived().TryExpandParameterPacks(
16053 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16054 ShouldExpand, RetainExpansion, NumExpansions))
16055 return true;
16056 if (!ShouldExpand) {
16057 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16058 ExprResult Pack = getDerived().TransformExpr(Pattern);
16059 if (Pack.isInvalid())
16060 return ExprError();
16061 return getDerived().RebuildPackIndexingExpr(
16062 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16063 {}, /*FullySubstituted=*/false);
16064 }
16065 for (unsigned I = 0; I != *NumExpansions; ++I) {
16066 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
16067 ExprResult Out = getDerived().TransformExpr(Pattern);
16068 if (Out.isInvalid())
16069 return true;
16070 if (Out.get()->containsUnexpandedParameterPack()) {
16071 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16072 OrigNumExpansions);
16073 if (Out.isInvalid())
16074 return true;
16075 FullySubstituted = false;
16076 }
16077 ExpandedExprs.push_back(Out.get());
16078 }
16079 // If we're supposed to retain a pack expansion, do so by temporarily
16080 // forgetting the partially-substituted parameter pack.
16081 if (RetainExpansion) {
16082 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16083
16084 ExprResult Out = getDerived().TransformExpr(Pattern);
16085 if (Out.isInvalid())
16086 return true;
16087
16088 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16089 OrigNumExpansions);
16090 if (Out.isInvalid())
16091 return true;
16092 FullySubstituted = false;
16093 ExpandedExprs.push_back(Out.get());
16094 }
16095 } else if (!E->expandsToEmptyPack()) {
16096 if (getDerived().TransformExprs(E->getExpressions().data(),
16097 E->getExpressions().size(), false,
16098 ExpandedExprs))
16099 return ExprError();
16100 }
16101
16102 return getDerived().RebuildPackIndexingExpr(
16103 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16104 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16105}
16106
16107template<typename Derived>
16109TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
16110 SubstNonTypeTemplateParmPackExpr *E) {
16111 // Default behavior is to do nothing with this transformation.
16112 return E;
16113}
16114
16115template<typename Derived>
16117TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
16118 SubstNonTypeTemplateParmExpr *E) {
16119 // Default behavior is to do nothing with this transformation.
16120 return E;
16121}
16122
16123template<typename Derived>
16125TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
16126 // Default behavior is to do nothing with this transformation.
16127 return E;
16128}
16129
16130template<typename Derived>
16132TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
16133 MaterializeTemporaryExpr *E) {
16134 return getDerived().TransformExpr(E->getSubExpr());
16135}
16136
16137template<typename Derived>
16139TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
16140 UnresolvedLookupExpr *Callee = nullptr;
16141 if (Expr *OldCallee = E->getCallee()) {
16142 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
16143 if (CalleeResult.isInvalid())
16144 return ExprError();
16145 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
16146 }
16147
16148 Expr *Pattern = E->getPattern();
16149
16151 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
16152 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16153
16154 // Determine whether the set of unexpanded parameter packs can and should
16155 // be expanded.
16156 bool Expand = true;
16157 bool RetainExpansion = false;
16158 std::optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
16159 NumExpansions = OrigNumExpansions;
16160 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
16161 Pattern->getSourceRange(),
16162 Unexpanded,
16163 Expand, RetainExpansion,
16164 NumExpansions))
16165 return true;
16166
16167 if (!Expand) {
16168 // Do not expand any packs here, just transform and rebuild a fold
16169 // expression.
16170 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16171
16172 ExprResult LHS =
16173 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
16174 if (LHS.isInvalid())
16175 return true;
16176
16177 ExprResult RHS =
16178 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
16179 if (RHS.isInvalid())
16180 return true;
16181
16182 if (!getDerived().AlwaysRebuild() &&
16183 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
16184 return E;
16185
16186 return getDerived().RebuildCXXFoldExpr(
16187 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
16188 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
16189 }
16190
16191 // Formally a fold expression expands to nested parenthesized expressions.
16192 // Enforce this limit to avoid creating trees so deep we can't safely traverse
16193 // them.
16194 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) {
16195 SemaRef.Diag(E->getEllipsisLoc(),
16196 clang::diag::err_fold_expression_limit_exceeded)
16197 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
16198 << E->getSourceRange();
16199 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
16200 return ExprError();
16201 }
16202
16203 // The transform has determined that we should perform an elementwise
16204 // expansion of the pattern. Do so.
16205 ExprResult Result = getDerived().TransformExpr(E->getInit());
16206 if (Result.isInvalid())
16207 return true;
16208 bool LeftFold = E->isLeftFold();
16209
16210 // If we're retaining an expansion for a right fold, it is the innermost
16211 // component and takes the init (if any).
16212 if (!LeftFold && RetainExpansion) {
16213 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16214
16215 ExprResult Out = getDerived().TransformExpr(Pattern);
16216 if (Out.isInvalid())
16217 return true;
16218
16219 Result = getDerived().RebuildCXXFoldExpr(
16220 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
16221 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
16222 if (Result.isInvalid())
16223 return true;
16224 }
16225
16226 for (unsigned I = 0; I != *NumExpansions; ++I) {
16227 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
16228 getSema(), LeftFold ? I : *NumExpansions - I - 1);
16229 ExprResult Out = getDerived().TransformExpr(Pattern);
16230 if (Out.isInvalid())
16231 return true;
16232
16233 if (Out.get()->containsUnexpandedParameterPack()) {
16234 // We still have a pack; retain a pack expansion for this slice.
16235 Result = getDerived().RebuildCXXFoldExpr(
16236 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
16237 E->getOperator(), E->getEllipsisLoc(),
16238 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
16239 OrigNumExpansions);
16240 } else if (Result.isUsable()) {
16241 // We've got down to a single element; build a binary operator.
16242 Expr *LHS = LeftFold ? Result.get() : Out.get();
16243 Expr *RHS = LeftFold ? Out.get() : Result.get();
16244 if (Callee) {
16245 UnresolvedSet<16> Functions;
16246 Functions.append(Callee->decls_begin(), Callee->decls_end());
16247 Result = getDerived().RebuildCXXOperatorCallExpr(
16249 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
16250 Functions, LHS, RHS);
16251 } else {
16252 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
16253 E->getOperator(), LHS, RHS);
16254 }
16255 } else
16256 Result = Out;
16257
16258 if (Result.isInvalid())
16259 return true;
16260 }
16261
16262 // If we're retaining an expansion for a left fold, it is the outermost
16263 // component and takes the complete expansion so far as its init (if any).
16264 if (LeftFold && RetainExpansion) {
16265 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16266
16267 ExprResult Out = getDerived().TransformExpr(Pattern);
16268 if (Out.isInvalid())
16269 return true;
16270
16271 Result = getDerived().RebuildCXXFoldExpr(
16272 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
16273 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
16274 if (Result.isInvalid())
16275 return true;
16276 }
16277
16278 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
16279 PE->setIsProducedByFoldExpansion();
16280
16281 // If we had no init and an empty pack, and we're not retaining an expansion,
16282 // then produce a fallback value or error.
16283 if (Result.isUnset())
16284 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
16285 E->getOperator());
16286 return Result;
16287}
16288
16289template <typename Derived>
16291TreeTransform<Derived>::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) {
16292 SmallVector<Expr *, 4> TransformedInits;
16293 ArrayRef<Expr *> InitExprs = E->getInitExprs();
16294 if (TransformExprs(InitExprs.data(), InitExprs.size(), true,
16295 TransformedInits))
16296 return ExprError();
16297
16298 return getDerived().RebuildParenListExpr(E->getBeginLoc(), TransformedInits,
16299 E->getEndLoc());
16300}
16301
16302template<typename Derived>
16304TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
16305 CXXStdInitializerListExpr *E) {
16306 return getDerived().TransformExpr(E->getSubExpr());
16307}
16308
16309template<typename Derived>
16311TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
16312 return SemaRef.MaybeBindToTemporary(E);
16313}
16314
16315template<typename Derived>
16317TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
16318 return E;
16319}
16320
16321template<typename Derived>
16323TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
16324 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
16325 if (SubExpr.isInvalid())
16326 return ExprError();
16327
16328 if (!getDerived().AlwaysRebuild() &&
16329 SubExpr.get() == E->getSubExpr())
16330 return E;
16331
16332 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
16333}
16334
16335template<typename Derived>
16337TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
16338 // Transform each of the elements.
16339 SmallVector<Expr *, 8> Elements;
16340 bool ArgChanged = false;
16341 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
16342 /*IsCall=*/false, Elements, &ArgChanged))
16343 return ExprError();
16344
16345 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16346 return SemaRef.MaybeBindToTemporary(E);
16347
16348 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
16349 Elements.data(),
16350 Elements.size());
16351}
16352
16353template<typename Derived>
16355TreeTransform<Derived>::TransformObjCDictionaryLiteral(
16356 ObjCDictionaryLiteral *E) {
16357 // Transform each of the elements.
16359 bool ArgChanged = false;
16360 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
16361 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
16362
16363 if (OrigElement.isPackExpansion()) {
16364 // This key/value element is a pack expansion.
16366 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
16367 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
16368 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16369
16370 // Determine whether the set of unexpanded parameter packs can
16371 // and should be expanded.
16372 bool Expand = true;
16373 bool RetainExpansion = false;
16374 std::optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
16375 std::optional<unsigned> NumExpansions = OrigNumExpansions;
16376 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
16377 OrigElement.Value->getEndLoc());
16378 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
16379 PatternRange, Unexpanded, Expand,
16380 RetainExpansion, NumExpansions))
16381 return ExprError();
16382
16383 if (!Expand) {
16384 // The transform has determined that we should perform a simple
16385 // transformation on the pack expansion, producing another pack
16386 // expansion.
16387 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16388 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16389 if (Key.isInvalid())
16390 return ExprError();
16391
16392 if (Key.get() != OrigElement.Key)
16393 ArgChanged = true;
16394
16395 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16396 if (Value.isInvalid())
16397 return ExprError();
16398
16399 if (Value.get() != OrigElement.Value)
16400 ArgChanged = true;
16401
16402 ObjCDictionaryElement Expansion = {
16403 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
16404 };
16405 Elements.push_back(Expansion);
16406 continue;
16407 }
16408
16409 // Record right away that the argument was changed. This needs
16410 // to happen even if the array expands to nothing.
16411 ArgChanged = true;
16412
16413 // The transform has determined that we should perform an elementwise
16414 // expansion of the pattern. Do so.
16415 for (unsigned I = 0; I != *NumExpansions; ++I) {
16416 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
16417 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16418 if (Key.isInvalid())
16419 return ExprError();
16420
16421 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16422 if (Value.isInvalid())
16423 return ExprError();
16424
16425 ObjCDictionaryElement Element = {
16426 Key.get(), Value.get(), SourceLocation(), NumExpansions
16427 };
16428
16429 // If any unexpanded parameter packs remain, we still have a
16430 // pack expansion.
16431 // FIXME: Can this really happen?
16432 if (Key.get()->containsUnexpandedParameterPack() ||
16433 Value.get()->containsUnexpandedParameterPack())
16434 Element.EllipsisLoc = OrigElement.EllipsisLoc;
16435
16436 Elements.push_back(Element);
16437 }
16438
16439 // FIXME: Retain a pack expansion if RetainExpansion is true.
16440
16441 // We've finished with this pack expansion.
16442 continue;
16443 }
16444
16445 // Transform and check key.
16446 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16447 if (Key.isInvalid())
16448 return ExprError();
16449
16450 if (Key.get() != OrigElement.Key)
16451 ArgChanged = true;
16452
16453 // Transform and check value.
16455 = getDerived().TransformExpr(OrigElement.Value);
16456 if (Value.isInvalid())
16457 return ExprError();
16458
16459 if (Value.get() != OrigElement.Value)
16460 ArgChanged = true;
16461
16462 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
16463 std::nullopt};
16464 Elements.push_back(Element);
16465 }
16466
16467 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16468 return SemaRef.MaybeBindToTemporary(E);
16469
16470 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
16471 Elements);
16472}
16473
16474template<typename Derived>
16476TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
16477 TypeSourceInfo *EncodedTypeInfo
16478 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
16479 if (!EncodedTypeInfo)
16480 return ExprError();
16481
16482 if (!getDerived().AlwaysRebuild() &&
16483 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
16484 return E;
16485
16486 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
16487 EncodedTypeInfo,
16488 E->getRParenLoc());
16489}
16490
16491template<typename Derived>
16492ExprResult TreeTransform<Derived>::
16493TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
16494 // This is a kind of implicit conversion, and it needs to get dropped
16495 // and recomputed for the same general reasons that ImplicitCastExprs
16496 // do, as well a more specific one: this expression is only valid when
16497 // it appears *immediately* as an argument expression.
16498 return getDerived().TransformExpr(E->getSubExpr());
16499}
16500
16501template<typename Derived>
16502ExprResult TreeTransform<Derived>::
16503TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
16504 TypeSourceInfo *TSInfo
16505 = getDerived().TransformType(E->getTypeInfoAsWritten());
16506 if (!TSInfo)
16507 return ExprError();
16508
16509 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
16510 if (Result.isInvalid())
16511 return ExprError();
16512
16513 if (!getDerived().AlwaysRebuild() &&
16514 TSInfo == E->getTypeInfoAsWritten() &&
16515 Result.get() == E->getSubExpr())
16516 return E;
16517
16518 return SemaRef.ObjC().BuildObjCBridgedCast(
16519 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
16520 Result.get());
16521}
16522
16523template <typename Derived>
16524ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
16525 ObjCAvailabilityCheckExpr *E) {
16526 return E;
16527}
16528
16529template<typename Derived>
16531TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
16532 // Transform arguments.
16533 bool ArgChanged = false;
16535 Args.reserve(E->getNumArgs());
16536 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
16537 &ArgChanged))
16538 return ExprError();
16539
16540 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
16541 // Class message: transform the receiver type.
16542 TypeSourceInfo *ReceiverTypeInfo
16543 = getDerived().TransformType(E->getClassReceiverTypeInfo());
16544 if (!ReceiverTypeInfo)
16545 return ExprError();
16546
16547 // If nothing changed, just retain the existing message send.
16548 if (!getDerived().AlwaysRebuild() &&
16549 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
16550 return SemaRef.MaybeBindToTemporary(E);
16551
16552 // Build a new class message send.
16554 E->getSelectorLocs(SelLocs);
16555 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
16556 E->getSelector(),
16557 SelLocs,
16558 E->getMethodDecl(),
16559 E->getLeftLoc(),
16560 Args,
16561 E->getRightLoc());
16562 }
16563 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
16564 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16565 if (!E->getMethodDecl())
16566 return ExprError();
16567
16568 // Build a new class message send to 'super'.
16570 E->getSelectorLocs(SelLocs);
16571 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
16572 E->getSelector(),
16573 SelLocs,
16574 E->getReceiverType(),
16575 E->getMethodDecl(),
16576 E->getLeftLoc(),
16577 Args,
16578 E->getRightLoc());
16579 }
16580
16581 // Instance message: transform the receiver
16582 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
16583 "Only class and instance messages may be instantiated");
16584 ExprResult Receiver
16585 = getDerived().TransformExpr(E->getInstanceReceiver());
16586 if (Receiver.isInvalid())
16587 return ExprError();
16588
16589 // If nothing changed, just retain the existing message send.
16590 if (!getDerived().AlwaysRebuild() &&
16591 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
16592 return SemaRef.MaybeBindToTemporary(E);
16593
16594 // Build a new instance message send.
16596 E->getSelectorLocs(SelLocs);
16597 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
16598 E->getSelector(),
16599 SelLocs,
16600 E->getMethodDecl(),
16601 E->getLeftLoc(),
16602 Args,
16603 E->getRightLoc());
16604}
16605
16606template<typename Derived>
16608TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
16609 return E;
16610}
16611
16612template<typename Derived>
16614TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
16615 return E;
16616}
16617
16618template<typename Derived>
16620TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
16621 // Transform the base expression.
16622 ExprResult Base = getDerived().TransformExpr(E->getBase());
16623 if (Base.isInvalid())
16624 return ExprError();
16625
16626 // We don't need to transform the ivar; it will never change.
16627
16628 // If nothing changed, just retain the existing expression.
16629 if (!getDerived().AlwaysRebuild() &&
16630 Base.get() == E->getBase())
16631 return E;
16632
16633 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
16634 E->getLocation(),
16635 E->isArrow(), E->isFreeIvar());
16636}
16637
16638template<typename Derived>
16640TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
16641 // 'super' and types never change. Property never changes. Just
16642 // retain the existing expression.
16643 if (!E->isObjectReceiver())
16644 return E;
16645
16646 // Transform the base expression.
16647 ExprResult Base = getDerived().TransformExpr(E->getBase());
16648 if (Base.isInvalid())
16649 return ExprError();
16650
16651 // We don't need to transform the property; it will never change.
16652
16653 // If nothing changed, just retain the existing expression.
16654 if (!getDerived().AlwaysRebuild() &&
16655 Base.get() == E->getBase())
16656 return E;
16657
16658 if (E->isExplicitProperty())
16659 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16660 E->getExplicitProperty(),
16661 E->getLocation());
16662
16663 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16664 SemaRef.Context.PseudoObjectTy,
16665 E->getImplicitPropertyGetter(),
16666 E->getImplicitPropertySetter(),
16667 E->getLocation());
16668}
16669
16670template<typename Derived>
16672TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
16673 // Transform the base expression.
16674 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
16675 if (Base.isInvalid())
16676 return ExprError();
16677
16678 // Transform the key expression.
16679 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
16680 if (Key.isInvalid())
16681 return ExprError();
16682
16683 // If nothing changed, just retain the existing expression.
16684 if (!getDerived().AlwaysRebuild() &&
16685 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
16686 return E;
16687
16688 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
16689 Base.get(), Key.get(),
16690 E->getAtIndexMethodDecl(),
16691 E->setAtIndexMethodDecl());
16692}
16693
16694template<typename Derived>
16696TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
16697 // Transform the base expression.
16698 ExprResult Base = getDerived().TransformExpr(E->getBase());
16699 if (Base.isInvalid())
16700 return ExprError();
16701
16702 // If nothing changed, just retain the existing expression.
16703 if (!getDerived().AlwaysRebuild() &&
16704 Base.get() == E->getBase())
16705 return E;
16706
16707 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
16708 E->getOpLoc(),
16709 E->isArrow());
16710}
16711
16712template<typename Derived>
16714TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
16715 bool ArgumentChanged = false;
16716 SmallVector<Expr*, 8> SubExprs;
16717 SubExprs.reserve(E->getNumSubExprs());
16718 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
16719 SubExprs, &ArgumentChanged))
16720 return ExprError();
16721
16722 if (!getDerived().AlwaysRebuild() &&
16723 !ArgumentChanged)
16724 return E;
16725
16726 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
16727 SubExprs,
16728 E->getRParenLoc());
16729}
16730
16731template<typename Derived>
16733TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
16734 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
16735 if (SrcExpr.isInvalid())
16736 return ExprError();
16737
16738 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
16739 if (!Type)
16740 return ExprError();
16741
16742 if (!getDerived().AlwaysRebuild() &&
16743 Type == E->getTypeSourceInfo() &&
16744 SrcExpr.get() == E->getSrcExpr())
16745 return E;
16746
16747 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
16748 SrcExpr.get(), Type,
16749 E->getRParenLoc());
16750}
16751
16752template<typename Derived>
16754TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
16755 BlockDecl *oldBlock = E->getBlockDecl();
16756
16757 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
16758 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
16759
16760 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
16761 blockScope->TheDecl->setBlockMissingReturnType(
16762 oldBlock->blockMissingReturnType());
16763
16765 SmallVector<QualType, 4> paramTypes;
16766
16767 const FunctionProtoType *exprFunctionType = E->getFunctionType();
16768
16769 // Parameter substitution.
16770 Sema::ExtParameterInfoBuilder extParamInfos;
16771 if (getDerived().TransformFunctionTypeParams(
16772 E->getCaretLocation(), oldBlock->parameters(), nullptr,
16773 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
16774 extParamInfos)) {
16775 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
16776 return ExprError();
16777 }
16778
16779 QualType exprResultType =
16780 getDerived().TransformType(exprFunctionType->getReturnType());
16781
16782 auto epi = exprFunctionType->getExtProtoInfo();
16783 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
16784
16785 QualType functionType =
16786 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
16787 blockScope->FunctionType = functionType;
16788
16789 // Set the parameters on the block decl.
16790 if (!params.empty())
16791 blockScope->TheDecl->setParams(params);
16792
16793 if (!oldBlock->blockMissingReturnType()) {
16794 blockScope->HasImplicitReturnType = false;
16795 blockScope->ReturnType = exprResultType;
16796 }
16797
16798 // Transform the body
16799 StmtResult body = getDerived().TransformStmt(E->getBody());
16800 if (body.isInvalid()) {
16801 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
16802 return ExprError();
16803 }
16804
16805#ifndef NDEBUG
16806 // In builds with assertions, make sure that we captured everything we
16807 // captured before.
16808 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
16809 for (const auto &I : oldBlock->captures()) {
16810 VarDecl *oldCapture = I.getVariable();
16811
16812 // Ignore parameter packs.
16813 if (oldCapture->isParameterPack())
16814 continue;
16815
16816 VarDecl *newCapture =
16817 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
16818 oldCapture));
16819 assert(blockScope->CaptureMap.count(newCapture));
16820 }
16821
16822 // The this pointer may not be captured by the instantiated block, even when
16823 // it's captured by the original block, if the expression causing the
16824 // capture is in the discarded branch of a constexpr if statement.
16825 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
16826 "this pointer isn't captured in the old block");
16827 }
16828#endif
16829
16830 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
16831 /*Scope=*/nullptr);
16832}
16833
16834template<typename Derived>
16836TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
16837 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
16838 if (SrcExpr.isInvalid())
16839 return ExprError();
16840
16841 QualType Type = getDerived().TransformType(E->getType());
16842
16843 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
16844 E->getRParenLoc());
16845}
16846
16847template<typename Derived>
16849TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
16850 bool ArgumentChanged = false;
16851 SmallVector<Expr*, 8> SubExprs;
16852 SubExprs.reserve(E->getNumSubExprs());
16853 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
16854 SubExprs, &ArgumentChanged))
16855 return ExprError();
16856
16857 if (!getDerived().AlwaysRebuild() &&
16858 !ArgumentChanged)
16859 return E;
16860
16861 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
16862 E->getOp(), E->getRParenLoc());
16863}
16864
16865//===----------------------------------------------------------------------===//
16866// Type reconstruction
16867//===----------------------------------------------------------------------===//
16868
16869template<typename Derived>
16872 return SemaRef.BuildPointerType(PointeeType, Star,
16873 getDerived().getBaseEntity());
16874}
16875
16876template<typename Derived>
16879 return SemaRef.BuildBlockPointerType(PointeeType, Star,
16880 getDerived().getBaseEntity());
16881}
16882
16883template<typename Derived>
16886 bool WrittenAsLValue,
16887 SourceLocation Sigil) {
16888 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
16889 Sigil, getDerived().getBaseEntity());
16890}
16891
16892template<typename Derived>
16895 QualType ClassType,
16896 SourceLocation Sigil) {
16897 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
16898 getDerived().getBaseEntity());
16899}
16900
16901template<typename Derived>
16903 const ObjCTypeParamDecl *Decl,
16904 SourceLocation ProtocolLAngleLoc,
16906 ArrayRef<SourceLocation> ProtocolLocs,
16907 SourceLocation ProtocolRAngleLoc) {
16908 return SemaRef.ObjC().BuildObjCTypeParamType(
16909 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16910 /*FailOnError=*/true);
16911}
16912
16913template<typename Derived>
16915 QualType BaseType,
16917 SourceLocation TypeArgsLAngleLoc,
16919 SourceLocation TypeArgsRAngleLoc,
16920 SourceLocation ProtocolLAngleLoc,
16922 ArrayRef<SourceLocation> ProtocolLocs,
16923 SourceLocation ProtocolRAngleLoc) {
16924 return SemaRef.ObjC().BuildObjCObjectType(
16925 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
16926 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16927 /*FailOnError=*/true,
16928 /*Rebuilding=*/true);
16929}
16930
16931template<typename Derived>
16933 QualType PointeeType,
16935 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
16936}
16937
16938template <typename Derived>
16940 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
16941 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16942 if (SizeExpr || !Size)
16943 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
16944 IndexTypeQuals, BracketsRange,
16945 getDerived().getBaseEntity());
16946
16947 QualType Types[] = {
16951 };
16952 QualType SizeType;
16953 for (const auto &T : Types)
16954 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
16955 SizeType = T;
16956 break;
16957 }
16958
16959 // Note that we can return a VariableArrayType here in the case where
16960 // the element type was a dependent VariableArrayType.
16961 IntegerLiteral *ArraySize
16962 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
16963 /*FIXME*/BracketsRange.getBegin());
16964 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
16965 IndexTypeQuals, BracketsRange,
16966 getDerived().getBaseEntity());
16967}
16968
16969template <typename Derived>
16971 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
16972 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16973 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
16974 IndexTypeQuals, BracketsRange);
16975}
16976
16977template <typename Derived>
16979 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
16980 SourceRange BracketsRange) {
16981 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
16982 IndexTypeQuals, BracketsRange);
16983}
16984
16985template <typename Derived>
16987 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16988 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16989 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16990 SizeExpr,
16991 IndexTypeQuals, BracketsRange);
16992}
16993
16994template <typename Derived>
16996 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16997 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16998 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16999 SizeExpr,
17000 IndexTypeQuals, BracketsRange);
17001}
17002
17003template <typename Derived>
17005 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
17006 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
17007 AttributeLoc);
17008}
17009
17010template <typename Derived>
17012 unsigned NumElements,
17013 VectorKind VecKind) {
17014 // FIXME: semantic checking!
17015 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17016}
17017
17018template <typename Derived>
17020 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17021 VectorKind VecKind) {
17022 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17023}
17024
17025template<typename Derived>
17027 unsigned NumElements,
17028 SourceLocation AttributeLoc) {
17029 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17030 NumElements, true);
17031 IntegerLiteral *VectorSize
17032 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17033 AttributeLoc);
17034 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17035}
17036
17037template<typename Derived>
17040 Expr *SizeExpr,
17041 SourceLocation AttributeLoc) {
17042 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17043}
17044
17045template <typename Derived>
17047 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17048 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17049 NumColumns);
17050}
17051
17052template <typename Derived>
17054 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17055 SourceLocation AttributeLoc) {
17056 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17057 AttributeLoc);
17058}
17059
17060template<typename Derived>
17062 QualType T,
17063 MutableArrayRef<QualType> ParamTypes,
17065 return SemaRef.BuildFunctionType(T, ParamTypes,
17066 getDerived().getBaseLocation(),
17067 getDerived().getBaseEntity(),
17068 EPI);
17069}
17070
17071template<typename Derived>
17073 return SemaRef.Context.getFunctionNoProtoType(T);
17074}
17075
17076template<typename Derived>
17078 Decl *D) {
17079 assert(D && "no decl found");
17080 if (D->isInvalidDecl()) return QualType();
17081
17082 // FIXME: Doesn't account for ObjCInterfaceDecl!
17083 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
17084 // A valid resolved using typename pack expansion decl can have multiple
17085 // UsingDecls, but they must each have exactly one type, and it must be
17086 // the same type in every case. But we must have at least one expansion!
17087 if (UPD->expansions().empty()) {
17088 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
17089 << UPD->isCXXClassMember() << UPD;
17090 return QualType();
17091 }
17092
17093 // We might still have some unresolved types. Try to pick a resolved type
17094 // if we can. The final instantiation will check that the remaining
17095 // unresolved types instantiate to the type we pick.
17096 QualType FallbackT;
17097 QualType T;
17098 for (auto *E : UPD->expansions()) {
17099 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
17100 if (ThisT.isNull())
17101 continue;
17102 else if (ThisT->getAs<UnresolvedUsingType>())
17103 FallbackT = ThisT;
17104 else if (T.isNull())
17105 T = ThisT;
17106 else
17107 assert(getSema().Context.hasSameType(ThisT, T) &&
17108 "mismatched resolved types in using pack expansion");
17109 }
17110 return T.isNull() ? FallbackT : T;
17111 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
17112 assert(Using->hasTypename() &&
17113 "UnresolvedUsingTypenameDecl transformed to non-typename using");
17114
17115 // A valid resolved using typename decl points to exactly one type decl.
17116 assert(++Using->shadow_begin() == Using->shadow_end());
17117
17118 UsingShadowDecl *Shadow = *Using->shadow_begin();
17119 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), Loc))
17120 return QualType();
17121 return SemaRef.Context.getUsingType(
17122 Shadow, SemaRef.Context.getTypeDeclType(
17123 cast<TypeDecl>(Shadow->getTargetDecl())));
17124 } else {
17125 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
17126 "UnresolvedUsingTypenameDecl transformed to non-using decl");
17127 return SemaRef.Context.getTypeDeclType(
17128 cast<UnresolvedUsingTypenameDecl>(D));
17129 }
17130}
17131
17132template <typename Derived>
17134 TypeOfKind Kind) {
17135 return SemaRef.BuildTypeofExprType(E, Kind);
17136}
17137
17138template<typename Derived>
17140 TypeOfKind Kind) {
17141 return SemaRef.Context.getTypeOfType(Underlying, Kind);
17142}
17143
17144template <typename Derived>
17146 return SemaRef.BuildDecltypeType(E);
17147}
17148
17149template <typename Derived>
17151 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
17152 SourceLocation EllipsisLoc, bool FullySubstituted,
17153 ArrayRef<QualType> Expansions) {
17154 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
17155 FullySubstituted, Expansions);
17156}
17157
17158template<typename Derived>
17162 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
17163}
17164
17165template<typename Derived>
17167 TemplateName Template,
17168 SourceLocation TemplateNameLoc,
17169 TemplateArgumentListInfo &TemplateArgs) {
17170 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
17171}
17172
17173template<typename Derived>
17175 SourceLocation KWLoc) {
17176 return SemaRef.BuildAtomicType(ValueType, KWLoc);
17177}
17178
17179template<typename Derived>
17181 SourceLocation KWLoc,
17182 bool isReadPipe) {
17183 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
17184 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
17185}
17186
17187template <typename Derived>
17189 unsigned NumBits,
17191 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17192 NumBits, true);
17193 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
17194 SemaRef.Context.IntTy, Loc);
17195 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
17196}
17197
17198template <typename Derived>
17200 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
17201 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
17202}
17203
17204template<typename Derived>
17207 bool TemplateKW,
17208 TemplateDecl *Template) {
17209 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
17210 TemplateName(Template));
17211}
17212
17213template<typename Derived>
17216 SourceLocation TemplateKWLoc,
17217 const IdentifierInfo &Name,
17218 SourceLocation NameLoc,
17219 QualType ObjectType,
17220 NamedDecl *FirstQualifierInScope,
17221 bool AllowInjectedClassName) {
17223 TemplateName.setIdentifier(&Name, NameLoc);
17224 Sema::TemplateTy Template;
17225 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
17226 TemplateName, ParsedType::make(ObjectType),
17227 /*EnteringContext=*/false, Template,
17228 AllowInjectedClassName);
17229 return Template.get();
17230}
17231
17232template<typename Derived>
17235 SourceLocation TemplateKWLoc,
17236 OverloadedOperatorKind Operator,
17237 SourceLocation NameLoc,
17238 QualType ObjectType,
17239 bool AllowInjectedClassName) {
17240 UnqualifiedId Name;
17241 // FIXME: Bogus location information.
17242 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
17243 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
17244 Sema::TemplateTy Template;
17245 getSema().ActOnTemplateName(
17246 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
17247 /*EnteringContext=*/false, Template, AllowInjectedClassName);
17248 return Template.get();
17249}
17250
17251template <typename Derived>
17254 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
17255 Expr *Second) {
17256 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
17257
17258 if (First->getObjectKind() == OK_ObjCProperty) {
17261 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
17262 Opc, First, Second);
17264 if (Result.isInvalid())
17265 return ExprError();
17266 First = Result.get();
17267 }
17268
17269 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
17270 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
17271 if (Result.isInvalid())
17272 return ExprError();
17273 Second = Result.get();
17274 }
17275
17276 // Determine whether this should be a builtin operation.
17277 if (Op == OO_Subscript) {
17278 if (!First->getType()->isOverloadableType() &&
17279 !Second->getType()->isOverloadableType())
17280 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
17281 OpLoc);
17282 } else if (Op == OO_Arrow) {
17283 // It is possible that the type refers to a RecoveryExpr created earlier
17284 // in the tree transformation.
17285 if (First->getType()->isDependentType())
17286 return ExprError();
17287 // -> is never a builtin operation.
17288 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
17289 } else if (Second == nullptr || isPostIncDec) {
17290 if (!First->getType()->isOverloadableType() ||
17291 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
17292 // The argument is not of overloadable type, or this is an expression
17293 // of the form &Class::member, so try to create a built-in unary
17294 // operation.
17296 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17297
17298 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
17299 }
17300 } else {
17301 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
17302 !First->getType()->isOverloadableType() &&
17303 !Second->getType()->isOverloadableType()) {
17304 // Neither of the arguments is type-dependent or has an overloadable
17305 // type, so try to create a built-in binary operation.
17308 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
17309 if (Result.isInvalid())
17310 return ExprError();
17311
17312 return Result;
17313 }
17314 }
17315
17316 // Create the overloaded operator invocation for unary operators.
17317 if (!Second || isPostIncDec) {
17319 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17320 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
17321 RequiresADL);
17322 }
17323
17324 // Create the overloaded operator invocation for binary operators.
17326 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
17327 First, Second, RequiresADL);
17328 if (Result.isInvalid())
17329 return ExprError();
17330
17331 return Result;
17332}
17333
17334template<typename Derived>
17337 SourceLocation OperatorLoc,
17338 bool isArrow,
17339 CXXScopeSpec &SS,
17340 TypeSourceInfo *ScopeType,
17341 SourceLocation CCLoc,
17342 SourceLocation TildeLoc,
17343 PseudoDestructorTypeStorage Destroyed) {
17344 QualType BaseType = Base->getType();
17345 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
17346 (!isArrow && !BaseType->getAs<RecordType>()) ||
17347 (isArrow && BaseType->getAs<PointerType>() &&
17348 !BaseType->castAs<PointerType>()->getPointeeType()
17349 ->template getAs<RecordType>())){
17350 // This pseudo-destructor expression is still a pseudo-destructor.
17351 return SemaRef.BuildPseudoDestructorExpr(
17352 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
17353 CCLoc, TildeLoc, Destroyed);
17354 }
17355
17356 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
17358 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
17359 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
17360 NameInfo.setNamedTypeInfo(DestroyedType);
17361
17362 // The scope type is now known to be a valid nested name specifier
17363 // component. Tack it on to the end of the nested name specifier.
17364 if (ScopeType) {
17365 if (!ScopeType->getType()->getAs<TagType>()) {
17366 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
17367 diag::err_expected_class_or_namespace)
17368 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
17369 return ExprError();
17370 }
17371 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
17372 CCLoc);
17373 }
17374
17375 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
17376 return getSema().BuildMemberReferenceExpr(Base, BaseType,
17377 OperatorLoc, isArrow,
17378 SS, TemplateKWLoc,
17379 /*FIXME: FirstQualifier*/ nullptr,
17380 NameInfo,
17381 /*TemplateArgs*/ nullptr,
17382 /*S*/nullptr);
17383}
17384
17385template<typename Derived>
17388 SourceLocation Loc = S->getBeginLoc();
17389 CapturedDecl *CD = S->getCapturedDecl();
17390 unsigned NumParams = CD->getNumParams();
17391 unsigned ContextParamPos = CD->getContextParamPosition();
17393 for (unsigned I = 0; I < NumParams; ++I) {
17394 if (I != ContextParamPos) {
17395 Params.push_back(
17396 std::make_pair(
17397 CD->getParam(I)->getName(),
17398 getDerived().TransformType(CD->getParam(I)->getType())));
17399 } else {
17400 Params.push_back(std::make_pair(StringRef(), QualType()));
17401 }
17402 }
17403 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
17404 S->getCapturedRegionKind(), Params);
17405 StmtResult Body;
17406 {
17407 Sema::CompoundScopeRAII CompoundScope(getSema());
17408 Body = getDerived().TransformStmt(S->getCapturedStmt());
17409 }
17410
17411 if (Body.isInvalid()) {
17412 getSema().ActOnCapturedRegionError();
17413 return StmtError();
17414 }
17415
17416 return getSema().ActOnCapturedRegionEnd(Body.get());
17417}
17418
17419template <typename Derived>
17420ExprResult TreeTransform<Derived>::TransformHLSLOutArgExpr(HLSLOutArgExpr *E) {
17421 // We can transform the base expression and allow argument resolution to fill
17422 // in the rest.
17423 return getDerived().TransformExpr(E->getArgLValue());
17424}
17425
17426} // end namespace clang
17427
17428#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:3055
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:2107
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:6561
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:6571
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:6576
AutoTypeKeyword getKeyword() const
Definition: Type.h:6592
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2196
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:2158
void setIsVariadic(bool value)
Definition: Decl.h:4564
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:1499
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4687
unsigned getNumParams() const
Definition: Decl.h:4729
unsigned getContextParamPosition() const
Definition: Decl.h:4758
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4731
This captures a statement into a function.
Definition: Stmt.h:3784
Expr * getSubExpr()
Definition: Expr.h:3597
SourceLocation getBegin() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1628
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:1519
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:6548
bool isDeduced() const
Definition: Type.h:6549
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:7081
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:4828
Expr * getCondition() const
Definition: Type.h:4835
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:6948
RAII object that enters a new expression evaluation context.
Represents an enum.
Definition: Decl.h:3861
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:276
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:4721
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:4942
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4686
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5107
QualType desugar() const
Definition: Type.h:5651
param_type_iterator param_type_begin() const
Definition: Type.h:5520
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:5558
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:5500
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5371
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:5367
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:4648
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:980
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:3143
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 OpenACCDefaultAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, 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 OpenACCDeviceClause * 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 OpenACCHostClause * 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:7146
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:7171
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:7936
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:7976
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:8030
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7968
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:4162
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6077
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:1282
Represents a __leave statement.
Definition: Stmt.h:3745
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:338
OpenACCDirectiveKind getDirectiveKind() const
Definition: SemaOpenACC.h:260
void setLParenLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:467
void setConditionDetails(Expr *ConditionExpr)
Definition: SemaOpenACC.h:476
void setCollapseDetails(bool IsForce, Expr *LoopCount)
Definition: SemaOpenACC.h:642
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:470
SourceLocation getQueuesLoc() const
Definition: SemaOpenACC.h:318
void setVarListDetails(ArrayRef< Expr * > VarList, bool IsReadOnly, bool IsZero)
Definition: SemaOpenACC.h:536
void setWaitDetails(Expr *DevNum, SourceLocation QueuesLoc, llvm::SmallVector< Expr * > &&IntExprs)
Definition: SemaOpenACC.h:628
void setEndLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:468
void setIntExprDetails(ArrayRef< Expr * > IntExprs)
Definition: SemaOpenACC.h:490
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 * 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 * ActOnOpenMPAllocateClause(Expr *Allocator, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' 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:141
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:13200
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:8048
A RAII object to enter scope of a compound statement.
Definition: Sema.h:916
A helper class for building up ExtParameterInfos.
Definition: Sema.h:12614
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:12633
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition: Sema.h:12621
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition: Sema.h:13569
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:464
QualType BuildParenType(QualType T)
Build a paren type including T.
Definition: SemaType.cpp:1675
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:6395
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:4479
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:8990
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:8998
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:8993
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:6498
ExprResult ActOnConstantExpression(ExprResult Res)
Definition: SemaExpr.cpp:19654
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:4412
QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc)
Definition: SemaType.cpp:2327
StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: SemaStmt.cpp:651
SemaOpenMP & OpenMP()
Definition: Sema.h:1126
@ IER_DoesNotExist
The symbol does not exist.
Definition: Sema.h:8465
@ IER_Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition: Sema.h:8469
@ IER_Error
An error occurred.
Definition: Sema.h:8472
@ IER_Exists
The symbol exists.
Definition: Sema.h:8462
void ActOnStartStmtExpr()
Definition: SemaExpr.cpp:15840
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:15846
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:20171
std::optional< FunctionEffectMode > ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName)
Try to parse the conditional expression attached to an effect attribute (e.g.
Definition: SemaType.cpp:7625
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:20387
ConditionKind
Definition: Sema.h:7351
@ 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:3217
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:2393
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
Definition: SemaInit.cpp:3488
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth)
Definition: SemaExpr.cpp:15859
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:1151
ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16502
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:909
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:2633
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:529
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:1111
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:532
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:15777
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:4403
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:692
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Definition: SemaExpr.cpp:3486
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
Definition: SemaExpr.cpp:7054
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Definition: SemaExpr.cpp:15827
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
Definition: SemaExpr.cpp:7909
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
Definition: SemaType.cpp:9614
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:16932
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:1940
ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16115
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:1581
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Definition: SemaStmt.cpp:1308
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:82
const LangOptions & getLangOpts() const
Definition: Sema.h:525
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:1792
SemaOpenACC & OpenACC()
Definition: Sema.h:1116
@ ReuseLambdaContextDecl
Definition: Sema.h:6531
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:16783
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:15929
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Definition: Sema.cpp:2406
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
Definition: SemaInit.cpp:7542
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:736
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:16907
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:940
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
Definition: SemaDecl.cpp:14871
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:1857
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:13194
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:2361
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:1044
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:20015
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:2255
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
Definition: SemaStmt.cpp:3232
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
Definition: SemaExpr.cpp:4109
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Definition: SemaExpr.cpp:20971
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:3842
@ NTK_TypeAliasTemplate
Definition: Sema.h:3850
TryCaptureKind
Definition: Sema.h:6593
@ TryCapture_Implicit
Definition: Sema.h:6594
@ TryCapture_ExplicitByVal
Definition: Sema.h:6595
@ TryCapture_ExplicitByRef
Definition: Sema.h:6596
ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Create a new AsTypeExpr node (bitcast) from the arguments.
Definition: SemaExpr.cpp:6710
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:8776
QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted=false, ArrayRef< QualType > Expansions={})
Definition: SemaType.cpp:9736
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:10019
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:13865
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:3883
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:1805
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:2683
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
Definition: SemaStmt.cpp:1822
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
Definition: SemaStmt.cpp:1184
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:9704
QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, SourceLocation Loc)
Definition: SemaType.cpp:9963
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
Definition: SemaStmt.cpp:4441
ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a sizeof or alignof expression given a type operand.
Definition: SemaExpr.cpp:4617
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:7917
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:2048
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Definition: SemaExpr.cpp:5581
QualType BuildReadPipeType(QualType T, SourceLocation Loc)
Build a Read-only Pipe type.
Definition: SemaType.cpp:1932
concepts::NestedRequirement * BuildNestedRequirement(Expr *E)
QualType BuildWritePipeType(QualType T, SourceLocation Loc)
Build a Write-only Pipe type.
Definition: SemaType.cpp:1936
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h:10757
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:16301
QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind)
Definition: SemaType.cpp:9591
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:20037
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:18085
QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, SourceLocation AttrLoc)
Definition: SemaType.cpp:2447
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:21168
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
Definition: SemaExpr.cpp:15345
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:962
ExprResult BuildInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, SourceLocation RBraceLoc)
Definition: SemaExpr.cpp:7254
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
Definition: SemaExpr.cpp:16153
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
Definition: SemaExpr.cpp:4829
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:14768
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:6437
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:2751
static ConditionResult ConditionError()
Definition: Sema.h:7338
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition: SemaStmt.cpp:451
SemaPseudoObject & PseudoObject()
Definition: Sema.h:1136
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:4290
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition: SemaStmt.cpp:588
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
Definition: SemaExpr.cpp:17912
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:2682
QualType BuildBlockPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a block pointer type.
Definition: SemaType.cpp:2734
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
Definition: SemaStmt.cpp:3199
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition: Sema.h:8268
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
Definition: SemaExpr.cpp:5006
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:357
StmtClass
Definition: Stmt.h:86
@ NoStmtClass
Definition: Stmt.h:87
StmtClass getStmtClass() const
Definition: Stmt.h:1380
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:333
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:345
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:3578
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:6666
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.
StmtResult RebuildOpenACCSetConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
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)
OMPClause * RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocate' clause.
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 RebuildOpenACCUpdateConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
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.
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:7907
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:7918
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:3213
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:6906
The base class of the type hierarchy.
Definition: Type.h:1828
bool isPointerType() const
Definition: Type.h:8191
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8805
bool isReferenceType() const
Definition: Type.h:8209
bool isEnumeralType() const
Definition: Type.h:8295
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:8656
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:8187
bool isObjCObjectPointerType() const
Definition: Type.h:8333
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8736
bool isRecordType() const
Definition: Type.h:8291
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3427
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:1417
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:5672
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3343
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3407
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:6876
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:236
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:6851
@ 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:4845
EffectConditionExpr Cond
Definition: Type.h:4847
Holds information about the various types of exception specification.
Definition: Type.h:5164
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:5180
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5166
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5169
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:5172
Extra information about a function prototype.
Definition: Type.h:5192
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5199
FunctionEffectsRef FunctionEffects
Definition: Type.h:5202
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:5200
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:12691
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:2810
Location information for a TemplateArgument.
Definition: TemplateBase.h:472