clang 20.0.0git
TreeTransform.h
Go to the documentation of this file.
1//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//===----------------------------------------------------------------------===//
7//
8// This file implements a semantic tree transformation that takes a given
9// AST and rebuilds it, possibly transforming some nodes in the process.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15
17#include "TypeLocBuilder.h"
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
22#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
27#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
36#include "clang/Sema/Lookup.h"
42#include "clang/Sema/SemaObjC.h"
46#include "clang/Sema/SemaSYCL.h"
47#include "llvm/ADT/ArrayRef.h"
48#include "llvm/Support/ErrorHandling.h"
49#include <algorithm>
50#include <optional>
51
52using namespace llvm::omp;
53
54namespace clang {
55using namespace sema;
56
57/// A semantic tree transformation that allows one to transform one
58/// abstract syntax tree into another.
59///
60/// A new tree transformation is defined by creating a new subclass \c X of
61/// \c TreeTransform<X> and then overriding certain operations to provide
62/// behavior specific to that transformation. For example, template
63/// instantiation is implemented as a tree transformation where the
64/// transformation of TemplateTypeParmType nodes involves substituting the
65/// template arguments for their corresponding template parameters; a similar
66/// transformation is performed for non-type template parameters and
67/// template template parameters.
68///
69/// This tree-transformation template uses static polymorphism to allow
70/// subclasses to customize any of its operations. Thus, a subclass can
71/// override any of the transformation or rebuild operators by providing an
72/// operation with the same signature as the default implementation. The
73/// overriding function should not be virtual.
74///
75/// Semantic tree transformations are split into two stages, either of which
76/// can be replaced by a subclass. The "transform" step transforms an AST node
77/// or the parts of an AST node using the various transformation functions,
78/// then passes the pieces on to the "rebuild" step, which constructs a new AST
79/// node of the appropriate kind from the pieces. The default transformation
80/// routines recursively transform the operands to composite AST nodes (e.g.,
81/// the pointee type of a PointerType node) and, if any of those operand nodes
82/// were changed by the transformation, invokes the rebuild operation to create
83/// a new AST node.
84///
85/// Subclasses can customize the transformation at various levels. The
86/// most coarse-grained transformations involve replacing TransformType(),
87/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
88/// TransformTemplateName(), or TransformTemplateArgument() with entirely
89/// new implementations.
90///
91/// For more fine-grained transformations, subclasses can replace any of the
92/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
93/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
94/// replacing TransformTemplateTypeParmType() allows template instantiation
95/// to substitute template arguments for their corresponding template
96/// parameters. Additionally, subclasses can override the \c RebuildXXX
97/// functions to control how AST nodes are rebuilt when their operands change.
98/// By default, \c TreeTransform will invoke semantic analysis to rebuild
99/// AST nodes. However, certain other tree transformations (e.g, cloning) may
100/// be able to use more efficient rebuild steps.
101///
102/// There are a handful of other functions that can be overridden, allowing one
103/// to avoid traversing nodes that don't need any transformation
104/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
105/// operands have not changed (\c AlwaysRebuild()), and customize the
106/// default locations and entity names used for type-checking
107/// (\c getBaseLocation(), \c getBaseEntity()).
108template<typename Derived>
110 /// Private RAII object that helps us forget and then re-remember
111 /// the template argument corresponding to a partially-substituted parameter
112 /// pack.
113 class ForgetPartiallySubstitutedPackRAII {
114 Derived &Self;
116 // Set the pack expansion index to -1 to avoid pack substitution and
117 // indicate that parameter packs should be instantiated as themselves.
118 Sema::ArgumentPackSubstitutionIndexRAII ResetPackSubstIndex;
119
120 public:
121 ForgetPartiallySubstitutedPackRAII(Derived &Self)
122 : Self(Self), ResetPackSubstIndex(Self.getSema(), -1) {
123 Old = Self.ForgetPartiallySubstitutedPack();
124 }
125
126 ~ForgetPartiallySubstitutedPackRAII() {
127 Self.RememberPartiallySubstitutedPack(Old);
128 }
129 };
130
131protected:
133
134 /// The set of local declarations that have been transformed, for
135 /// cases where we are forced to build new declarations within the transformer
136 /// rather than in the subclass (e.g., lambda closure types).
137 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
138
139public:
140 /// Initializes a new tree transformer.
142
143 /// Retrieves a reference to the derived class.
144 Derived &getDerived() { return static_cast<Derived&>(*this); }
145
146 /// Retrieves a reference to the derived class.
147 const Derived &getDerived() const {
148 return static_cast<const Derived&>(*this);
149 }
150
151 static inline ExprResult Owned(Expr *E) { return E; }
152 static inline StmtResult Owned(Stmt *S) { return S; }
153
154 /// Retrieves a reference to the semantic analysis object used for
155 /// this tree transform.
156 Sema &getSema() const { return SemaRef; }
157
158 /// Whether the transformation should always rebuild AST nodes, even
159 /// if none of the children have changed.
160 ///
161 /// Subclasses may override this function to specify when the transformation
162 /// should rebuild all AST nodes.
163 ///
164 /// We must always rebuild all AST nodes when performing variadic template
165 /// pack expansion, in order to avoid violating the AST invariant that each
166 /// statement node appears at most once in its containing declaration.
168
169 /// Whether the transformation is forming an expression or statement that
170 /// replaces the original. In this case, we'll reuse mangling numbers from
171 /// existing lambdas.
172 bool ReplacingOriginal() { return false; }
173
174 /// Wether CXXConstructExpr can be skipped when they are implicit.
175 /// They will be reconstructed when used if needed.
176 /// This is useful when the user that cause rebuilding of the
177 /// CXXConstructExpr is outside of the expression at which the TreeTransform
178 /// started.
179 bool AllowSkippingCXXConstructExpr() { return true; }
180
181 /// Returns the location of the entity being transformed, if that
182 /// information was not available elsewhere in the AST.
183 ///
184 /// By default, returns no source-location information. Subclasses can
185 /// provide an alternative implementation that provides better location
186 /// information.
188
189 /// Returns the name of the entity being transformed, if that
190 /// information was not available elsewhere in the AST.
191 ///
192 /// By default, returns an empty name. Subclasses can provide an alternative
193 /// implementation with a more precise name.
195
196 /// Sets the "base" location and entity when that
197 /// information is known based on another transformation.
198 ///
199 /// By default, the source location and entity are ignored. Subclasses can
200 /// override this function to provide a customized implementation.
202
203 /// RAII object that temporarily sets the base location and entity
204 /// used for reporting diagnostics in types.
206 TreeTransform &Self;
207 SourceLocation OldLocation;
208 DeclarationName OldEntity;
209
210 public:
212 DeclarationName Entity) : Self(Self) {
213 OldLocation = Self.getDerived().getBaseLocation();
214 OldEntity = Self.getDerived().getBaseEntity();
215
216 if (Location.isValid())
217 Self.getDerived().setBase(Location, Entity);
218 }
219
221 Self.getDerived().setBase(OldLocation, OldEntity);
222 }
223 };
224
225 /// Determine whether the given type \p T has already been
226 /// transformed.
227 ///
228 /// Subclasses can provide an alternative implementation of this routine
229 /// to short-circuit evaluation when it is known that a given type will
230 /// not change. For example, template instantiation need not traverse
231 /// non-dependent types.
233 return T.isNull();
234 }
235
236 /// Transform a template parameter depth level.
237 ///
238 /// During a transformation that transforms template parameters, this maps
239 /// an old template parameter depth to a new depth.
240 unsigned TransformTemplateDepth(unsigned Depth) {
241 return Depth;
242 }
243
244 /// Determine whether the given call argument should be dropped, e.g.,
245 /// because it is a default argument.
246 ///
247 /// Subclasses can provide an alternative implementation of this routine to
248 /// determine which kinds of call arguments get dropped. By default,
249 /// CXXDefaultArgument nodes are dropped (prior to transformation).
251 return E->isDefaultArgument();
252 }
253
254 /// Determine whether we should expand a pack expansion with the
255 /// given set of parameter packs into separate arguments by repeatedly
256 /// transforming the pattern.
257 ///
258 /// By default, the transformer never tries to expand pack expansions.
259 /// Subclasses can override this routine to provide different behavior.
260 ///
261 /// \param EllipsisLoc The location of the ellipsis that identifies the
262 /// pack expansion.
263 ///
264 /// \param PatternRange The source range that covers the entire pattern of
265 /// the pack expansion.
266 ///
267 /// \param Unexpanded The set of unexpanded parameter packs within the
268 /// pattern.
269 ///
270 /// \param ShouldExpand Will be set to \c true if the transformer should
271 /// expand the corresponding pack expansions into separate arguments. When
272 /// set, \c NumExpansions must also be set.
273 ///
274 /// \param RetainExpansion Whether the caller should add an unexpanded
275 /// pack expansion after all of the expanded arguments. This is used
276 /// when extending explicitly-specified template argument packs per
277 /// C++0x [temp.arg.explicit]p9.
278 ///
279 /// \param NumExpansions The number of separate arguments that will be in
280 /// the expanded form of the corresponding pack expansion. This is both an
281 /// input and an output parameter, which can be set by the caller if the
282 /// number of expansions is known a priori (e.g., due to a prior substitution)
283 /// and will be set by the callee when the number of expansions is known.
284 /// The callee must set this value when \c ShouldExpand is \c true; it may
285 /// set this value in other cases.
286 ///
287 /// \returns true if an error occurred (e.g., because the parameter packs
288 /// are to be instantiated with arguments of different lengths), false
289 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
290 /// must be set.
292 SourceRange PatternRange,
294 bool &ShouldExpand, bool &RetainExpansion,
295 std::optional<unsigned> &NumExpansions) {
296 ShouldExpand = false;
297 return false;
298 }
299
300 /// "Forget" about the partially-substituted pack template argument,
301 /// when performing an instantiation that must preserve the parameter pack
302 /// use.
303 ///
304 /// This routine is meant to be overridden by the template instantiator.
306 return TemplateArgument();
307 }
308
309 /// "Remember" the partially-substituted pack template argument
310 /// after performing an instantiation that must preserve the parameter pack
311 /// use.
312 ///
313 /// This routine is meant to be overridden by the template instantiator.
315
316 /// Note to the derived class when a function parameter pack is
317 /// being expanded.
319
320 /// Transforms the given type into another type.
321 ///
322 /// By default, this routine transforms a type by creating a
323 /// TypeSourceInfo for it and delegating to the appropriate
324 /// function. This is expensive, but we don't mind, because
325 /// this method is deprecated anyway; all users should be
326 /// switched to storing TypeSourceInfos.
327 ///
328 /// \returns the transformed type.
330
331 /// Transforms the given type-with-location into a new
332 /// type-with-location.
333 ///
334 /// By default, this routine transforms a type by delegating to the
335 /// appropriate TransformXXXType to build a new type. Subclasses
336 /// may override this function (to take over all type
337 /// transformations) or some set of the TransformXXXType functions
338 /// to alter the transformation.
340
341 /// Transform the given type-with-location into a new
342 /// type, collecting location information in the given builder
343 /// as necessary.
344 ///
346
347 /// Transform a type that is permitted to produce a
348 /// DeducedTemplateSpecializationType.
349 ///
350 /// This is used in the (relatively rare) contexts where it is acceptable
351 /// for transformation to produce a class template type with deduced
352 /// template arguments.
353 /// @{
356 /// @}
357
358 /// The reason why the value of a statement is not discarded, if any.
363 };
364
365 /// Transform the given statement.
366 ///
367 /// By default, this routine transforms a statement by delegating to the
368 /// appropriate TransformXXXStmt function to transform a specific kind of
369 /// statement or the TransformExpr() function to transform an expression.
370 /// Subclasses may override this function to transform statements using some
371 /// other mechanism.
372 ///
373 /// \returns the transformed statement.
375
376 /// Transform the given statement.
377 ///
378 /// By default, this routine transforms a statement by delegating to the
379 /// appropriate TransformOMPXXXClause function to transform a specific kind
380 /// of clause. Subclasses may override this function to transform statements
381 /// using some other mechanism.
382 ///
383 /// \returns the transformed OpenMP clause.
385
386 /// Transform the given attribute.
387 ///
388 /// By default, this routine transforms a statement by delegating to the
389 /// appropriate TransformXXXAttr function to transform a specific kind
390 /// of attribute. Subclasses may override this function to transform
391 /// attributed statements/types using some other mechanism.
392 ///
393 /// \returns the transformed attribute
394 const Attr *TransformAttr(const Attr *S);
395
396 // Transform the given statement attribute.
397 //
398 // Delegates to the appropriate TransformXXXAttr function to transform a
399 // specific kind of statement attribute. Unlike the non-statement taking
400 // version of this, this implements all attributes, not just pragmas.
401 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
402 const Attr *A);
403
404 // Transform the specified attribute.
405 //
406 // Subclasses should override the transformation of attributes with a pragma
407 // spelling to transform expressions stored within the attribute.
408 //
409 // \returns the transformed attribute.
410#define ATTR(X) \
411 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
412#include "clang/Basic/AttrList.inc"
413
414 // Transform the specified attribute.
415 //
416 // Subclasses should override the transformation of attributes to do
417 // transformation and checking of statement attributes. By default, this
418 // delegates to the non-statement taking version.
419 //
420 // \returns the transformed attribute.
421#define ATTR(X) \
422 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
423 const X##Attr *A) { \
424 return getDerived().Transform##X##Attr(A); \
425 }
426#include "clang/Basic/AttrList.inc"
427
428 /// Transform the given expression.
429 ///
430 /// By default, this routine transforms an expression by delegating to the
431 /// appropriate TransformXXXExpr function to build a new expression.
432 /// Subclasses may override this function to transform expressions using some
433 /// other mechanism.
434 ///
435 /// \returns the transformed expression.
437
438 /// Transform the given initializer.
439 ///
440 /// By default, this routine transforms an initializer by stripping off the
441 /// semantic nodes added by initialization, then passing the result to
442 /// TransformExpr or TransformExprs.
443 ///
444 /// \returns the transformed initializer.
446
447 /// Transform the given list of expressions.
448 ///
449 /// This routine transforms a list of expressions by invoking
450 /// \c TransformExpr() for each subexpression. However, it also provides
451 /// support for variadic templates by expanding any pack expansions (if the
452 /// derived class permits such expansion) along the way. When pack expansions
453 /// are present, the number of outputs may not equal the number of inputs.
454 ///
455 /// \param Inputs The set of expressions to be transformed.
456 ///
457 /// \param NumInputs The number of expressions in \c Inputs.
458 ///
459 /// \param IsCall If \c true, then this transform is being performed on
460 /// function-call arguments, and any arguments that should be dropped, will
461 /// be.
462 ///
463 /// \param Outputs The transformed input expressions will be added to this
464 /// vector.
465 ///
466 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
467 /// due to transformation.
468 ///
469 /// \returns true if an error occurred, false otherwise.
470 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
472 bool *ArgChanged = nullptr);
473
474 /// Transform the given declaration, which is referenced from a type
475 /// or expression.
476 ///
477 /// By default, acts as the identity function on declarations, unless the
478 /// transformer has had to transform the declaration itself. Subclasses
479 /// may override this function to provide alternate behavior.
481 llvm::DenseMap<Decl *, Decl *>::iterator Known
482 = TransformedLocalDecls.find(D);
483 if (Known != TransformedLocalDecls.end())
484 return Known->second;
485
486 return D;
487 }
488
489 /// Transform the specified condition.
490 ///
491 /// By default, this transforms the variable and expression and rebuilds
492 /// the condition.
494 Expr *Expr,
496
497 /// Transform the attributes associated with the given declaration and
498 /// place them on the new declaration.
499 ///
500 /// By default, this operation does nothing. Subclasses may override this
501 /// behavior to transform attributes.
502 void transformAttrs(Decl *Old, Decl *New) { }
503
504 /// Note that a local declaration has been transformed by this
505 /// transformer.
506 ///
507 /// Local declarations are typically transformed via a call to
508 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
509 /// the transformer itself has to transform the declarations. This routine
510 /// can be overridden by a subclass that keeps track of such mappings.
512 assert(New.size() == 1 &&
513 "must override transformedLocalDecl if performing pack expansion");
514 TransformedLocalDecls[Old] = New.front();
515 }
516
517 /// Transform the definition of the given declaration.
518 ///
519 /// By default, invokes TransformDecl() to transform the declaration.
520 /// Subclasses may override this function to provide alternate behavior.
522 return getDerived().TransformDecl(Loc, D);
523 }
524
525 /// Transform the given declaration, which was the first part of a
526 /// nested-name-specifier in a member access expression.
527 ///
528 /// This specific declaration transformation only applies to the first
529 /// identifier in a nested-name-specifier of a member access expression, e.g.,
530 /// the \c T in \c x->T::member
531 ///
532 /// By default, invokes TransformDecl() to transform the declaration.
533 /// Subclasses may override this function to provide alternate behavior.
535 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
536 }
537
538 /// Transform the set of declarations in an OverloadExpr.
539 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
540 LookupResult &R);
541
542 /// Transform the given nested-name-specifier with source-location
543 /// information.
544 ///
545 /// By default, transforms all of the types and declarations within the
546 /// nested-name-specifier. Subclasses may override this function to provide
547 /// alternate behavior.
550 QualType ObjectType = QualType(),
551 NamedDecl *FirstQualifierInScope = nullptr);
552
553 /// Transform the given declaration name.
554 ///
555 /// By default, transforms the types of conversion function, constructor,
556 /// and destructor names and then (if needed) rebuilds the declaration name.
557 /// Identifiers and selectors are returned unmodified. Subclasses may
558 /// override this function to provide alternate behavior.
561
571
572 /// Transform the given template name.
573 ///
574 /// \param SS The nested-name-specifier that qualifies the template
575 /// name. This nested-name-specifier must already have been transformed.
576 ///
577 /// \param Name The template name to transform.
578 ///
579 /// \param NameLoc The source location of the template name.
580 ///
581 /// \param ObjectType If we're translating a template name within a member
582 /// access expression, this is the type of the object whose member template
583 /// is being referenced.
584 ///
585 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
586 /// also refers to a name within the current (lexical) scope, this is the
587 /// declaration it refers to.
588 ///
589 /// By default, transforms the template name by transforming the declarations
590 /// and nested-name-specifiers that occur within the template name.
591 /// Subclasses may override this function to provide alternate behavior.
594 SourceLocation NameLoc,
595 QualType ObjectType = QualType(),
596 NamedDecl *FirstQualifierInScope = nullptr,
597 bool AllowInjectedClassName = false);
598
599 /// Transform the given template argument.
600 ///
601 /// By default, this operation transforms the type, expression, or
602 /// declaration stored within the template argument and constructs a
603 /// new template argument from the transformed result. Subclasses may
604 /// override this function to provide alternate behavior.
605 ///
606 /// Returns true if there was an error.
608 TemplateArgumentLoc &Output,
609 bool Uneval = false);
610
611 /// Transform the given set of template arguments.
612 ///
613 /// By default, this operation transforms all of the template arguments
614 /// in the input set using \c TransformTemplateArgument(), and appends
615 /// the transformed arguments to the output list.
616 ///
617 /// Note that this overload of \c TransformTemplateArguments() is merely
618 /// a convenience function. Subclasses that wish to override this behavior
619 /// should override the iterator-based member template version.
620 ///
621 /// \param Inputs The set of template arguments to be transformed.
622 ///
623 /// \param NumInputs The number of template arguments in \p Inputs.
624 ///
625 /// \param Outputs The set of transformed template arguments output by this
626 /// routine.
627 ///
628 /// Returns true if an error occurred.
630 unsigned NumInputs,
632 bool Uneval = false) {
633 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
634 Uneval);
635 }
636
637 /// Transform the given set of template arguments.
638 ///
639 /// By default, this operation transforms all of the template arguments
640 /// in the input set using \c TransformTemplateArgument(), and appends
641 /// the transformed arguments to the output list.
642 ///
643 /// \param First An iterator to the first template argument.
644 ///
645 /// \param Last An iterator one step past the last template argument.
646 ///
647 /// \param Outputs The set of transformed template arguments output by this
648 /// routine.
649 ///
650 /// Returns true if an error occurred.
651 template<typename InputIterator>
653 InputIterator Last,
655 bool Uneval = false);
656
657 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
659 TemplateArgumentLoc &ArgLoc);
660
661 /// Fakes up a TypeSourceInfo for a type.
665 }
666
667#define ABSTRACT_TYPELOC(CLASS, PARENT)
668#define TYPELOC(CLASS, PARENT) \
669 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
670#include "clang/AST/TypeLocNodes.def"
671
674 bool SuppressObjCLifetime);
678 bool SuppressObjCLifetime);
679
680 template<typename Fn>
683 CXXRecordDecl *ThisContext,
684 Qualifiers ThisTypeQuals,
686
689 SmallVectorImpl<QualType> &Exceptions,
690 bool &Changed);
691
693
697 TemplateName Template);
698
702 TemplateName Template,
703 CXXScopeSpec &SS);
704
707 NestedNameSpecifierLoc QualifierLoc);
708
709 /// Transforms the parameters of a function type into the
710 /// given vectors.
711 ///
712 /// The result vectors should be kept in sync; null entries in the
713 /// variables vector are acceptable.
714 ///
715 /// LastParamTransformed, if non-null, will be set to the index of the last
716 /// parameter on which transfromation was started. In the event of an error,
717 /// this will contain the parameter which failed to instantiate.
718 ///
719 /// Return true on error.
722 const QualType *ParamTypes,
723 const FunctionProtoType::ExtParameterInfo *ParamInfos,
725 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
726
729 const QualType *ParamTypes,
730 const FunctionProtoType::ExtParameterInfo *ParamInfos,
733 return getDerived().TransformFunctionTypeParams(
734 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
735 }
736
737 /// Transforms the parameters of a requires expresison into the given vectors.
738 ///
739 /// The result vectors should be kept in sync; null entries in the
740 /// variables vector are acceptable.
741 ///
742 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
743 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
744 /// which are cases where transformation shouldn't continue.
746 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
752 KWLoc, Params, /*ParamTypes=*/nullptr,
753 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
754 return ExprError();
755
756 return ExprResult{};
757 }
758
759 /// Transforms a single function-type parameter. Return null
760 /// on error.
761 ///
762 /// \param indexAdjustment - A number to add to the parameter's
763 /// scope index; can be negative
765 int indexAdjustment,
766 std::optional<unsigned> NumExpansions,
767 bool ExpectParameterPack);
768
769 /// Transform the body of a lambda-expression.
771 /// Alternative implementation of TransformLambdaBody that skips transforming
772 /// the body.
774
777 return static_cast<CXXRecordDecl::LambdaDependencyKind>(
779 }
780
782
785
788 return TPL;
789 }
790
792
794 bool IsAddressOfOperand,
795 TypeSourceInfo **RecoveryTSI);
796
798 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
799 TypeSourceInfo **RecoveryTSI);
800
802 bool IsAddressOfOperand);
803
805
807
808// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
809// amount of stack usage with clang.
810#define STMT(Node, Parent) \
811 LLVM_ATTRIBUTE_NOINLINE \
812 StmtResult Transform##Node(Node *S);
813#define VALUESTMT(Node, Parent) \
814 LLVM_ATTRIBUTE_NOINLINE \
815 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
816#define EXPR(Node, Parent) \
817 LLVM_ATTRIBUTE_NOINLINE \
818 ExprResult Transform##Node(Node *E);
819#define ABSTRACT_STMT(Stmt)
820#include "clang/AST/StmtNodes.inc"
821
822#define GEN_CLANG_CLAUSE_CLASS
823#define CLAUSE_CLASS(Enum, Str, Class) \
824 LLVM_ATTRIBUTE_NOINLINE \
825 OMPClause *Transform##Class(Class *S);
826#include "llvm/Frontend/OpenMP/OMP.inc"
827
828 /// Build a new qualified type given its unqualified type and type location.
829 ///
830 /// By default, this routine adds type qualifiers only to types that can
831 /// have qualifiers, and silently suppresses those qualifiers that are not
832 /// permitted. Subclasses may override this routine to provide different
833 /// behavior.
835
836 /// Build a new pointer type given its pointee type.
837 ///
838 /// By default, performs semantic analysis when building the pointer type.
839 /// Subclasses may override this routine to provide different behavior.
841
842 /// Build a new block pointer type given its pointee type.
843 ///
844 /// By default, performs semantic analysis when building the block pointer
845 /// type. Subclasses may override this routine to provide different behavior.
847
848 /// Build a new reference type given the type it references.
849 ///
850 /// By default, performs semantic analysis when building the
851 /// reference type. Subclasses may override this routine to provide
852 /// different behavior.
853 ///
854 /// \param LValue whether the type was written with an lvalue sigil
855 /// or an rvalue sigil.
857 bool LValue,
858 SourceLocation Sigil);
859
860 /// Build a new member pointer type given the pointee type and the
861 /// class type it refers into.
862 ///
863 /// By default, performs semantic analysis when building the member pointer
864 /// type. Subclasses may override this routine to provide different behavior.
866 SourceLocation Sigil);
867
869 SourceLocation ProtocolLAngleLoc,
871 ArrayRef<SourceLocation> ProtocolLocs,
872 SourceLocation ProtocolRAngleLoc);
873
874 /// Build an Objective-C object type.
875 ///
876 /// By default, performs semantic analysis when building the object type.
877 /// Subclasses may override this routine to provide different behavior.
880 SourceLocation TypeArgsLAngleLoc,
882 SourceLocation TypeArgsRAngleLoc,
883 SourceLocation ProtocolLAngleLoc,
885 ArrayRef<SourceLocation> ProtocolLocs,
886 SourceLocation ProtocolRAngleLoc);
887
888 /// Build a new Objective-C object pointer type given the pointee type.
889 ///
890 /// By default, directly builds the pointer type, with no additional semantic
891 /// analysis.
894
895 /// Build a new array type given the element type, size
896 /// modifier, size of the array (if known), size expression, and index type
897 /// qualifiers.
898 ///
899 /// By default, performs semantic analysis when building the array type.
900 /// Subclasses may override this routine to provide different behavior.
901 /// Also by default, all of the other Rebuild*Array
903 const llvm::APInt *Size, Expr *SizeExpr,
904 unsigned IndexTypeQuals, SourceRange BracketsRange);
905
906 /// Build a new constant array type given the element type, size
907 /// modifier, (known) size of the array, and index type qualifiers.
908 ///
909 /// By default, performs semantic analysis when building the array type.
910 /// Subclasses may override this routine to provide different behavior.
912 ArraySizeModifier SizeMod,
913 const llvm::APInt &Size, Expr *SizeExpr,
914 unsigned IndexTypeQuals,
915 SourceRange BracketsRange);
916
917 /// Build a new incomplete array type given the element type, size
918 /// modifier, and index type qualifiers.
919 ///
920 /// By default, performs semantic analysis when building the array type.
921 /// Subclasses may override this routine to provide different behavior.
923 ArraySizeModifier SizeMod,
924 unsigned IndexTypeQuals,
925 SourceRange BracketsRange);
926
927 /// Build a new variable-length array type given the element type,
928 /// size modifier, size expression, and index type qualifiers.
929 ///
930 /// By default, performs semantic analysis when building the array type.
931 /// Subclasses may override this routine to provide different behavior.
933 ArraySizeModifier SizeMod, Expr *SizeExpr,
934 unsigned IndexTypeQuals,
935 SourceRange BracketsRange);
936
937 /// Build a new dependent-sized array type given the element type,
938 /// size modifier, size expression, and index type qualifiers.
939 ///
940 /// By default, performs semantic analysis when building the array type.
941 /// Subclasses may override this routine to provide different behavior.
943 ArraySizeModifier SizeMod,
944 Expr *SizeExpr,
945 unsigned IndexTypeQuals,
946 SourceRange BracketsRange);
947
948 /// Build a new vector type given the element type and
949 /// number of elements.
950 ///
951 /// By default, performs semantic analysis when building the vector type.
952 /// Subclasses may override this routine to provide different behavior.
953 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
954 VectorKind VecKind);
955
956 /// Build a new potentially dependently-sized extended vector type
957 /// given the element type and number of elements.
958 ///
959 /// By default, performs semantic analysis when building the vector type.
960 /// Subclasses may override this routine to provide different behavior.
962 SourceLocation AttributeLoc, VectorKind);
963
964 /// Build a new extended vector type given the element type and
965 /// number of elements.
966 ///
967 /// By default, performs semantic analysis when building the vector type.
968 /// Subclasses may override this routine to provide different behavior.
969 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
970 SourceLocation AttributeLoc);
971
972 /// Build a new potentially dependently-sized extended vector type
973 /// given the element type and number of elements.
974 ///
975 /// By default, performs semantic analysis when building the vector type.
976 /// Subclasses may override this routine to provide different behavior.
978 Expr *SizeExpr,
979 SourceLocation AttributeLoc);
980
981 /// Build a new matrix type given the element type and dimensions.
982 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
983 unsigned NumColumns);
984
985 /// Build a new matrix type given the type and dependently-defined
986 /// dimensions.
988 Expr *ColumnExpr,
989 SourceLocation AttributeLoc);
990
991 /// Build a new DependentAddressSpaceType or return the pointee
992 /// type variable with the correct address space (retrieved from
993 /// AddrSpaceExpr) applied to it. The former will be returned in cases
994 /// where the address space remains dependent.
995 ///
996 /// By default, performs semantic analysis when building the type with address
997 /// space applied. Subclasses may override this routine to provide different
998 /// behavior.
1000 Expr *AddrSpaceExpr,
1001 SourceLocation AttributeLoc);
1002
1003 /// Build a new function type.
1004 ///
1005 /// By default, performs semantic analysis when building the function type.
1006 /// Subclasses may override this routine to provide different behavior.
1008 MutableArrayRef<QualType> ParamTypes,
1010
1011 /// Build a new unprototyped function type.
1013
1014 /// Rebuild an unresolved typename type, given the decl that
1015 /// the UnresolvedUsingTypenameDecl was transformed to.
1017
1018 /// Build a new type found via an alias.
1020 return SemaRef.Context.getUsingType(Found, Underlying);
1021 }
1022
1023 /// Build a new typedef type.
1025 return SemaRef.Context.getTypeDeclType(Typedef);
1026 }
1027
1028 /// Build a new MacroDefined type.
1030 const IdentifierInfo *MacroII) {
1031 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1032 }
1033
1034 /// Build a new class/struct/union type.
1037 }
1038
1039 /// Build a new Enum type.
1042 }
1043
1044 /// Build a new typeof(expr) type.
1045 ///
1046 /// By default, performs semantic analysis when building the typeof type.
1047 /// Subclasses may override this routine to provide different behavior.
1049 TypeOfKind Kind);
1050
1051 /// Build a new typeof(type) type.
1052 ///
1053 /// By default, builds a new TypeOfType with the given underlying type.
1055
1056 /// Build a new unary transform type.
1060
1061 /// Build a new C++11 decltype type.
1062 ///
1063 /// By default, performs semantic analysis when building the decltype type.
1064 /// Subclasses may override this routine to provide different behavior.
1066
1069 SourceLocation EllipsisLoc,
1070 bool FullySubstituted,
1071 ArrayRef<QualType> Expansions = {});
1072
1073 /// Build a new C++11 auto type.
1074 ///
1075 /// By default, builds a new AutoType with the given deduced type.
1077 ConceptDecl *TypeConstraintConcept,
1078 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1079 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1080 // which has been deduced to a dependent type into an undeduced 'auto', so
1081 // that we'll retry deduction after the transformation.
1082 return SemaRef.Context.getAutoType(Deduced, Keyword,
1083 /*IsDependent*/ false, /*IsPack=*/false,
1084 TypeConstraintConcept,
1085 TypeConstraintArgs);
1086 }
1087
1088 /// By default, builds a new DeducedTemplateSpecializationType with the given
1089 /// deduced type.
1091 QualType Deduced) {
1093 Template, Deduced, /*IsDependent*/ false);
1094 }
1095
1096 /// Build a new template specialization type.
1097 ///
1098 /// By default, performs semantic analysis when building the template
1099 /// specialization type. Subclasses may override this routine to provide
1100 /// different behavior.
1102 SourceLocation TemplateLoc,
1104
1105 /// Build a new parenthesized type.
1106 ///
1107 /// By default, builds a new ParenType type from the inner type.
1108 /// Subclasses may override this routine to provide different behavior.
1110 return SemaRef.BuildParenType(InnerType);
1111 }
1112
1113 /// Build a new qualified name type.
1114 ///
1115 /// By default, builds a new ElaboratedType type from the keyword,
1116 /// the nested-name-specifier and the named type.
1117 /// Subclasses may override this routine to provide different behavior.
1119 ElaboratedTypeKeyword Keyword,
1120 NestedNameSpecifierLoc QualifierLoc,
1121 QualType Named) {
1122 return SemaRef.Context.getElaboratedType(Keyword,
1123 QualifierLoc.getNestedNameSpecifier(),
1124 Named);
1125 }
1126
1127 /// Build a new typename type that refers to a template-id.
1128 ///
1129 /// By default, builds a new DependentNameType type from the
1130 /// nested-name-specifier and the given type. Subclasses may override
1131 /// this routine to provide different behavior.
1133 ElaboratedTypeKeyword Keyword,
1134 NestedNameSpecifierLoc QualifierLoc,
1135 SourceLocation TemplateKWLoc,
1136 const IdentifierInfo *Name,
1137 SourceLocation NameLoc,
1139 bool AllowInjectedClassName) {
1140 // Rebuild the template name.
1141 // TODO: avoid TemplateName abstraction
1142 CXXScopeSpec SS;
1143 SS.Adopt(QualifierLoc);
1144 TemplateName InstName = getDerived().RebuildTemplateName(
1145 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1146 AllowInjectedClassName);
1147
1148 if (InstName.isNull())
1149 return QualType();
1150
1151 // If it's still dependent, make a dependent specialization.
1152 if (InstName.getAsDependentTemplateName())
1154 Keyword, QualifierLoc.getNestedNameSpecifier(), Name,
1155 Args.arguments());
1156
1157 // Otherwise, make an elaborated type wrapping a non-dependent
1158 // specialization.
1159 QualType T =
1160 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1161 if (T.isNull())
1162 return QualType();
1164 Keyword, QualifierLoc.getNestedNameSpecifier(), T);
1165 }
1166
1167 /// Build a new typename type that refers to an identifier.
1168 ///
1169 /// By default, performs semantic analysis when building the typename type
1170 /// (or elaborated type). Subclasses may override this routine to provide
1171 /// different behavior.
1173 SourceLocation KeywordLoc,
1174 NestedNameSpecifierLoc QualifierLoc,
1175 const IdentifierInfo *Id,
1176 SourceLocation IdLoc,
1177 bool DeducedTSTContext) {
1178 CXXScopeSpec SS;
1179 SS.Adopt(QualifierLoc);
1180
1181 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1182 // If the name is still dependent, just build a new dependent name type.
1183 if (!SemaRef.computeDeclContext(SS))
1184 return SemaRef.Context.getDependentNameType(Keyword,
1185 QualifierLoc.getNestedNameSpecifier(),
1186 Id);
1187 }
1188
1189 if (Keyword == ElaboratedTypeKeyword::None ||
1191 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1192 *Id, IdLoc, DeducedTSTContext);
1193 }
1194
1196
1197 // We had a dependent elaborated-type-specifier that has been transformed
1198 // into a non-dependent elaborated-type-specifier. Find the tag we're
1199 // referring to.
1201 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1202 if (!DC)
1203 return QualType();
1204
1206 return QualType();
1207
1208 TagDecl *Tag = nullptr;
1210 switch (Result.getResultKind()) {
1213 break;
1214
1216 Tag = Result.getAsSingle<TagDecl>();
1217 break;
1218
1221 llvm_unreachable("Tag lookup cannot find non-tags");
1222
1224 // Let the LookupResult structure handle ambiguities.
1225 return QualType();
1226 }
1227
1228 if (!Tag) {
1229 // Check where the name exists but isn't a tag type and use that to emit
1230 // better diagnostics.
1233 switch (Result.getResultKind()) {
1237 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1238 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1239 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1240 << SomeDecl << NTK << llvm::to_underlying(Kind);
1241 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1242 break;
1243 }
1244 default:
1245 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1246 << llvm::to_underlying(Kind) << Id << DC
1247 << QualifierLoc.getSourceRange();
1248 break;
1249 }
1250 return QualType();
1251 }
1252
1253 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1254 IdLoc, Id)) {
1255 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1256 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1257 return QualType();
1258 }
1259
1260 // Build the elaborated-type-specifier type.
1262 return SemaRef.Context.getElaboratedType(Keyword,
1263 QualifierLoc.getNestedNameSpecifier(),
1264 T);
1265 }
1266
1267 /// Build a new pack expansion type.
1268 ///
1269 /// By default, builds a new PackExpansionType type from the given pattern.
1270 /// Subclasses may override this routine to provide different behavior.
1272 SourceLocation EllipsisLoc,
1273 std::optional<unsigned> NumExpansions) {
1274 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1275 NumExpansions);
1276 }
1277
1278 /// Build a new atomic type given its value type.
1279 ///
1280 /// By default, performs semantic analysis when building the atomic type.
1281 /// Subclasses may override this routine to provide different behavior.
1283
1284 /// Build a new pipe type given its value type.
1286 bool isReadPipe);
1287
1288 /// Build a bit-precise int given its value type.
1289 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1291
1292 /// Build a dependent bit-precise int given its value type.
1293 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1295
1296 /// Build a new template name given a nested name specifier, a flag
1297 /// indicating whether the "template" keyword was provided, and the template
1298 /// that the template name refers to.
1299 ///
1300 /// By default, builds the new template name directly. Subclasses may override
1301 /// this routine to provide different behavior.
1303 bool TemplateKW,
1304 TemplateDecl *Template);
1305
1306 /// Build a new template name given a nested name specifier and the
1307 /// name that is referred to as a template.
1308 ///
1309 /// By default, performs semantic analysis to determine whether the name can
1310 /// be resolved to a specific template, then builds the appropriate kind of
1311 /// template name. Subclasses may override this routine to provide different
1312 /// behavior.
1314 SourceLocation TemplateKWLoc,
1315 const IdentifierInfo &Name,
1316 SourceLocation NameLoc, QualType ObjectType,
1317 NamedDecl *FirstQualifierInScope,
1318 bool AllowInjectedClassName);
1319
1320 /// Build a new template name given a nested name specifier and the
1321 /// overloaded operator name that is referred to as a template.
1322 ///
1323 /// By default, performs semantic analysis to determine whether the name can
1324 /// be resolved to a specific template, then builds the appropriate kind of
1325 /// template name. Subclasses may override this routine to provide different
1326 /// behavior.
1328 SourceLocation TemplateKWLoc,
1329 OverloadedOperatorKind Operator,
1330 SourceLocation NameLoc, QualType ObjectType,
1331 bool AllowInjectedClassName);
1332
1333 /// Build a new template name given a template template parameter pack
1334 /// and the
1335 ///
1336 /// By default, performs semantic analysis to determine whether the name can
1337 /// be resolved to a specific template, then builds the appropriate kind of
1338 /// template name. Subclasses may override this routine to provide different
1339 /// behavior.
1341 Decl *AssociatedDecl, unsigned Index,
1342 bool Final) {
1344 ArgPack, AssociatedDecl, Index, Final);
1345 }
1346
1347 /// Build a new compound statement.
1348 ///
1349 /// By default, performs semantic analysis to build the new statement.
1350 /// Subclasses may override this routine to provide different behavior.
1352 MultiStmtArg Statements,
1353 SourceLocation RBraceLoc,
1354 bool IsStmtExpr) {
1355 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1356 IsStmtExpr);
1357 }
1358
1359 /// Build a new case statement.
1360 ///
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
1364 Expr *LHS,
1365 SourceLocation EllipsisLoc,
1366 Expr *RHS,
1367 SourceLocation ColonLoc) {
1368 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1369 ColonLoc);
1370 }
1371
1372 /// Attach the body to a new case statement.
1373 ///
1374 /// By default, performs semantic analysis to build the new statement.
1375 /// Subclasses may override this routine to provide different behavior.
1377 getSema().ActOnCaseStmtBody(S, Body);
1378 return S;
1379 }
1380
1381 /// Build a new default statement.
1382 ///
1383 /// By default, performs semantic analysis to build the new statement.
1384 /// Subclasses may override this routine to provide different behavior.
1386 SourceLocation ColonLoc,
1387 Stmt *SubStmt) {
1388 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1389 /*CurScope=*/nullptr);
1390 }
1391
1392 /// Build a new label statement.
1393 ///
1394 /// By default, performs semantic analysis to build the new statement.
1395 /// Subclasses may override this routine to provide different behavior.
1397 SourceLocation ColonLoc, Stmt *SubStmt) {
1398 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1399 }
1400
1401 /// Build a new attributed statement.
1402 ///
1403 /// By default, performs semantic analysis to build the new statement.
1404 /// Subclasses may override this routine to provide different behavior.
1407 Stmt *SubStmt) {
1409 return StmtError();
1410 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1411 }
1412
1413 /// Build a new "if" statement.
1414 ///
1415 /// By default, performs semantic analysis to build the new statement.
1416 /// Subclasses may override this routine to provide different behavior.
1418 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1419 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1420 SourceLocation ElseLoc, Stmt *Else) {
1421 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1422 Then, ElseLoc, Else);
1423 }
1424
1425 /// Start building a new switch statement.
1426 ///
1427 /// By default, performs semantic analysis to build the new statement.
1428 /// Subclasses may override this routine to provide different behavior.
1430 SourceLocation LParenLoc, Stmt *Init,
1432 SourceLocation RParenLoc) {
1433 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1434 RParenLoc);
1435 }
1436
1437 /// Attach the body to the switch statement.
1438 ///
1439 /// By default, performs semantic analysis to build the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
1442 Stmt *Switch, Stmt *Body) {
1443 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1444 }
1445
1446 /// Build a new while statement.
1447 ///
1448 /// By default, performs semantic analysis to build the new statement.
1449 /// Subclasses may override this routine to provide different behavior.
1452 SourceLocation RParenLoc, Stmt *Body) {
1453 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1454 }
1455
1456 /// Build a new do-while statement.
1457 ///
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
1461 SourceLocation WhileLoc, SourceLocation LParenLoc,
1462 Expr *Cond, SourceLocation RParenLoc) {
1463 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1464 Cond, RParenLoc);
1465 }
1466
1467 /// Build a new for statement.
1468 ///
1469 /// By default, performs semantic analysis to build the new statement.
1470 /// Subclasses may override this routine to provide different behavior.
1473 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1474 Stmt *Body) {
1475 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1476 Inc, RParenLoc, Body);
1477 }
1478
1479 /// Build a new goto statement.
1480 ///
1481 /// By default, performs semantic analysis to build the new statement.
1482 /// Subclasses may override this routine to provide different behavior.
1484 LabelDecl *Label) {
1485 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1486 }
1487
1488 /// Build a new indirect goto statement.
1489 ///
1490 /// By default, performs semantic analysis to build the new statement.
1491 /// Subclasses may override this routine to provide different behavior.
1493 SourceLocation StarLoc,
1494 Expr *Target) {
1495 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1496 }
1497
1498 /// Build a new return statement.
1499 ///
1500 /// By default, performs semantic analysis to build the new statement.
1501 /// Subclasses may override this routine to provide different behavior.
1503 return getSema().BuildReturnStmt(ReturnLoc, Result);
1504 }
1505
1506 /// Build a new declaration statement.
1507 ///
1508 /// By default, performs semantic analysis to build the new statement.
1509 /// Subclasses may override this routine to provide different behavior.
1511 SourceLocation StartLoc, SourceLocation EndLoc) {
1513 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1514 }
1515
1516 /// Build a new inline asm statement.
1517 ///
1518 /// By default, performs semantic analysis to build the new statement.
1519 /// Subclasses may override this routine to provide different behavior.
1521 bool IsVolatile, unsigned NumOutputs,
1522 unsigned NumInputs, IdentifierInfo **Names,
1523 MultiExprArg Constraints, MultiExprArg Exprs,
1524 Expr *AsmString, MultiExprArg Clobbers,
1525 unsigned NumLabels,
1526 SourceLocation RParenLoc) {
1527 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1528 NumInputs, Names, Constraints, Exprs,
1529 AsmString, Clobbers, NumLabels, RParenLoc);
1530 }
1531
1532 /// Build a new MS style inline asm statement.
1533 ///
1534 /// By default, performs semantic analysis to build the new statement.
1535 /// Subclasses may override this routine to provide different behavior.
1537 ArrayRef<Token> AsmToks,
1538 StringRef AsmString,
1539 unsigned NumOutputs, unsigned NumInputs,
1540 ArrayRef<StringRef> Constraints,
1541 ArrayRef<StringRef> Clobbers,
1542 ArrayRef<Expr*> Exprs,
1543 SourceLocation EndLoc) {
1544 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1545 NumOutputs, NumInputs,
1546 Constraints, Clobbers, Exprs, EndLoc);
1547 }
1548
1549 /// Build a new co_return statement.
1550 ///
1551 /// By default, performs semantic analysis to build the new statement.
1552 /// Subclasses may override this routine to provide different behavior.
1554 bool IsImplicit) {
1555 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1556 }
1557
1558 /// Build a new co_await expression.
1559 ///
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
1563 UnresolvedLookupExpr *OpCoawaitLookup,
1564 bool IsImplicit) {
1565 // This function rebuilds a coawait-expr given its operator.
1566 // For an explicit coawait-expr, the rebuild involves the full set
1567 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1568 // including calling await_transform().
1569 // For an implicit coawait-expr, we need to rebuild the "operator
1570 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1571 // This mirrors how the implicit CoawaitExpr is originally created
1572 // in Sema::ActOnCoroutineBodyStart().
1573 if (IsImplicit) {
1575 CoawaitLoc, Operand, OpCoawaitLookup);
1576 if (Suspend.isInvalid())
1577 return ExprError();
1578 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1579 Suspend.get(), true);
1580 }
1581
1582 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1583 OpCoawaitLookup);
1584 }
1585
1586 /// Build a new co_await expression.
1587 ///
1588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
1591 Expr *Result,
1592 UnresolvedLookupExpr *Lookup) {
1593 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1594 }
1595
1596 /// Build a new co_yield expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
1601 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1602 }
1603
1605 return getSema().BuildCoroutineBodyStmt(Args);
1606 }
1607
1608 /// Build a new Objective-C \@try statement.
1609 ///
1610 /// By default, performs semantic analysis to build the new statement.
1611 /// Subclasses may override this routine to provide different behavior.
1613 Stmt *TryBody,
1614 MultiStmtArg CatchStmts,
1615 Stmt *Finally) {
1616 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1617 Finally);
1618 }
1619
1620 /// Rebuild an Objective-C exception declaration.
1621 ///
1622 /// By default, performs semantic analysis to build the new declaration.
1623 /// Subclasses may override this routine to provide different behavior.
1625 TypeSourceInfo *TInfo, QualType T) {
1627 TInfo, T, ExceptionDecl->getInnerLocStart(),
1628 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1629 }
1630
1631 /// Build a new Objective-C \@catch statement.
1632 ///
1633 /// By default, performs semantic analysis to build the new statement.
1634 /// Subclasses may override this routine to provide different behavior.
1636 SourceLocation RParenLoc,
1637 VarDecl *Var,
1638 Stmt *Body) {
1639 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1640 }
1641
1642 /// Build a new Objective-C \@finally statement.
1643 ///
1644 /// By default, performs semantic analysis to build the new statement.
1645 /// Subclasses may override this routine to provide different behavior.
1647 Stmt *Body) {
1648 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1649 }
1650
1651 /// Build a new Objective-C \@throw statement.
1652 ///
1653 /// By default, performs semantic analysis to build the new statement.
1654 /// Subclasses may override this routine to provide different behavior.
1656 Expr *Operand) {
1657 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1658 }
1659
1660 /// Build a new OpenMP Canonical loop.
1661 ///
1662 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1663 /// OMPCanonicalLoop.
1665 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1666 }
1667
1668 /// Build a new OpenMP executable directive.
1669 ///
1670 /// By default, performs semantic analysis to build the new statement.
1671 /// Subclasses may override this routine to provide different behavior.
1673 DeclarationNameInfo DirName,
1674 OpenMPDirectiveKind CancelRegion,
1675 ArrayRef<OMPClause *> Clauses,
1676 Stmt *AStmt, SourceLocation StartLoc,
1677 SourceLocation EndLoc) {
1678
1680 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1681 }
1682
1683 /// Build a new OpenMP informational directive.
1685 DeclarationNameInfo DirName,
1686 ArrayRef<OMPClause *> Clauses,
1687 Stmt *AStmt,
1688 SourceLocation StartLoc,
1689 SourceLocation EndLoc) {
1690
1692 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1693 }
1694
1695 /// Build a new OpenMP 'if' clause.
1696 ///
1697 /// By default, performs semantic analysis to build the new OpenMP clause.
1698 /// Subclasses may override this routine to provide different behavior.
1700 Expr *Condition, SourceLocation StartLoc,
1701 SourceLocation LParenLoc,
1702 SourceLocation NameModifierLoc,
1703 SourceLocation ColonLoc,
1704 SourceLocation EndLoc) {
1706 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1707 EndLoc);
1708 }
1709
1710 /// Build a new OpenMP 'final' clause.
1711 ///
1712 /// By default, performs semantic analysis to build the new OpenMP clause.
1713 /// Subclasses may override this routine to provide different behavior.
1715 SourceLocation LParenLoc,
1716 SourceLocation EndLoc) {
1717 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1718 LParenLoc, EndLoc);
1719 }
1720
1721 /// Build a new OpenMP 'num_threads' clause.
1722 ///
1723 /// By default, performs semantic analysis to build the new OpenMP clause.
1724 /// Subclasses may override this routine to provide different behavior.
1726 SourceLocation StartLoc,
1727 SourceLocation LParenLoc,
1728 SourceLocation EndLoc) {
1729 return getSema().OpenMP().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1730 LParenLoc, EndLoc);
1731 }
1732
1733 /// Build a new OpenMP 'safelen' clause.
1734 ///
1735 /// By default, performs semantic analysis to build the new OpenMP clause.
1736 /// Subclasses may override this routine to provide different behavior.
1738 SourceLocation LParenLoc,
1739 SourceLocation EndLoc) {
1740 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1741 EndLoc);
1742 }
1743
1744 /// Build a new OpenMP 'simdlen' clause.
1745 ///
1746 /// By default, performs semantic analysis to build the new OpenMP clause.
1747 /// Subclasses may override this routine to provide different behavior.
1749 SourceLocation LParenLoc,
1750 SourceLocation EndLoc) {
1751 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1752 EndLoc);
1753 }
1754
1756 SourceLocation StartLoc,
1757 SourceLocation LParenLoc,
1758 SourceLocation EndLoc) {
1759 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1760 EndLoc);
1761 }
1762
1763 /// Build a new OpenMP 'permutation' clause.
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation EndLoc) {
1768 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1769 LParenLoc, EndLoc);
1770 }
1771
1772 /// Build a new OpenMP 'full' clause.
1774 SourceLocation EndLoc) {
1775 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1776 }
1777
1778 /// Build a new OpenMP 'partial' clause.
1780 SourceLocation LParenLoc,
1781 SourceLocation EndLoc) {
1782 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1783 LParenLoc, EndLoc);
1784 }
1785
1786 /// Build a new OpenMP 'allocator' clause.
1787 ///
1788 /// By default, performs semantic analysis to build the new OpenMP clause.
1789 /// Subclasses may override this routine to provide different behavior.
1791 SourceLocation LParenLoc,
1792 SourceLocation EndLoc) {
1793 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1794 EndLoc);
1795 }
1796
1797 /// Build a new OpenMP 'collapse' clause.
1798 ///
1799 /// By default, performs semantic analysis to build the new OpenMP clause.
1800 /// Subclasses may override this routine to provide different behavior.
1802 SourceLocation LParenLoc,
1803 SourceLocation EndLoc) {
1804 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1805 LParenLoc, EndLoc);
1806 }
1807
1808 /// Build a new OpenMP 'default' clause.
1809 ///
1810 /// By default, performs semantic analysis to build the new OpenMP clause.
1811 /// Subclasses may override this routine to provide different behavior.
1813 SourceLocation StartLoc,
1814 SourceLocation LParenLoc,
1815 SourceLocation EndLoc) {
1817 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1818 }
1819
1820 /// Build a new OpenMP 'proc_bind' clause.
1821 ///
1822 /// By default, performs semantic analysis to build the new OpenMP clause.
1823 /// Subclasses may override this routine to provide different behavior.
1825 SourceLocation KindKwLoc,
1826 SourceLocation StartLoc,
1827 SourceLocation LParenLoc,
1828 SourceLocation EndLoc) {
1830 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1831 }
1832
1833 /// Build a new OpenMP 'schedule' clause.
1834 ///
1835 /// By default, performs semantic analysis to build the new OpenMP clause.
1836 /// Subclasses may override this routine to provide different behavior.
1839 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1840 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1841 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1843 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1844 CommaLoc, EndLoc);
1845 }
1846
1847 /// Build a new OpenMP 'ordered' clause.
1848 ///
1849 /// By default, performs semantic analysis to build the new OpenMP clause.
1850 /// Subclasses may override this routine to provide different behavior.
1852 SourceLocation EndLoc,
1853 SourceLocation LParenLoc, Expr *Num) {
1854 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1855 LParenLoc, Num);
1856 }
1857
1858 /// Build a new OpenMP 'private' clause.
1859 ///
1860 /// By default, performs semantic analysis to build the new OpenMP clause.
1861 /// Subclasses may override this routine to provide different behavior.
1863 SourceLocation StartLoc,
1864 SourceLocation LParenLoc,
1865 SourceLocation EndLoc) {
1866 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1867 LParenLoc, EndLoc);
1868 }
1869
1870 /// Build a new OpenMP 'firstprivate' clause.
1871 ///
1872 /// By default, performs semantic analysis to build the new OpenMP clause.
1873 /// Subclasses may override this routine to provide different behavior.
1875 SourceLocation StartLoc,
1876 SourceLocation LParenLoc,
1877 SourceLocation EndLoc) {
1878 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1879 LParenLoc, EndLoc);
1880 }
1881
1882 /// Build a new OpenMP 'lastprivate' clause.
1883 ///
1884 /// By default, performs semantic analysis to build the new OpenMP clause.
1885 /// Subclasses may override this routine to provide different behavior.
1888 SourceLocation LPKindLoc,
1889 SourceLocation ColonLoc,
1890 SourceLocation StartLoc,
1891 SourceLocation LParenLoc,
1892 SourceLocation EndLoc) {
1894 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1895 }
1896
1897 /// Build a new OpenMP 'shared' clause.
1898 ///
1899 /// By default, performs semantic analysis to build the new OpenMP clause.
1900 /// Subclasses may override this routine to provide different behavior.
1902 SourceLocation StartLoc,
1903 SourceLocation LParenLoc,
1904 SourceLocation EndLoc) {
1905 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1906 LParenLoc, EndLoc);
1907 }
1908
1909 /// Build a new OpenMP 'reduction' clause.
1910 ///
1911 /// By default, performs semantic analysis to build the new statement.
1912 /// Subclasses may override this routine to provide different behavior.
1915 SourceLocation StartLoc, SourceLocation LParenLoc,
1916 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1917 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1918 const DeclarationNameInfo &ReductionId,
1919 ArrayRef<Expr *> UnresolvedReductions) {
1921 VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1922 ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1923 }
1924
1925 /// Build a new OpenMP 'task_reduction' clause.
1926 ///
1927 /// By default, performs semantic analysis to build the new statement.
1928 /// Subclasses may override this routine to provide different behavior.
1930 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1931 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1932 CXXScopeSpec &ReductionIdScopeSpec,
1933 const DeclarationNameInfo &ReductionId,
1934 ArrayRef<Expr *> UnresolvedReductions) {
1936 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1937 ReductionId, UnresolvedReductions);
1938 }
1939
1940 /// Build a new OpenMP 'in_reduction' clause.
1941 ///
1942 /// By default, performs semantic analysis to build the new statement.
1943 /// Subclasses may override this routine to provide different behavior.
1944 OMPClause *
1946 SourceLocation LParenLoc, SourceLocation ColonLoc,
1947 SourceLocation EndLoc,
1948 CXXScopeSpec &ReductionIdScopeSpec,
1949 const DeclarationNameInfo &ReductionId,
1950 ArrayRef<Expr *> UnresolvedReductions) {
1952 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1953 ReductionId, UnresolvedReductions);
1954 }
1955
1956 /// Build a new OpenMP 'linear' clause.
1957 ///
1958 /// By default, performs semantic analysis to build the new OpenMP clause.
1959 /// Subclasses may override this routine to provide different behavior.
1961 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1962 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1963 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1964 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1966 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1967 StepModifierLoc, EndLoc);
1968 }
1969
1970 /// Build a new OpenMP 'aligned' clause.
1971 ///
1972 /// By default, performs semantic analysis to build the new OpenMP clause.
1973 /// Subclasses may override this routine to provide different behavior.
1975 SourceLocation StartLoc,
1976 SourceLocation LParenLoc,
1977 SourceLocation ColonLoc,
1978 SourceLocation EndLoc) {
1980 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
1981 }
1982
1983 /// Build a new OpenMP 'copyin' clause.
1984 ///
1985 /// By default, performs semantic analysis to build the new OpenMP clause.
1986 /// Subclasses may override this routine to provide different behavior.
1988 SourceLocation StartLoc,
1989 SourceLocation LParenLoc,
1990 SourceLocation EndLoc) {
1991 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
1992 LParenLoc, EndLoc);
1993 }
1994
1995 /// Build a new OpenMP 'copyprivate' clause.
1996 ///
1997 /// By default, performs semantic analysis to build the new OpenMP clause.
1998 /// Subclasses may override this routine to provide different behavior.
2000 SourceLocation StartLoc,
2001 SourceLocation LParenLoc,
2002 SourceLocation EndLoc) {
2003 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2004 LParenLoc, EndLoc);
2005 }
2006
2007 /// Build a new OpenMP 'flush' pseudo clause.
2008 ///
2009 /// By default, performs semantic analysis to build the new OpenMP clause.
2010 /// Subclasses may override this routine to provide different behavior.
2012 SourceLocation StartLoc,
2013 SourceLocation LParenLoc,
2014 SourceLocation EndLoc) {
2015 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2016 LParenLoc, EndLoc);
2017 }
2018
2019 /// Build a new OpenMP 'depobj' pseudo clause.
2020 ///
2021 /// By default, performs semantic analysis to build the new OpenMP clause.
2022 /// Subclasses may override this routine to provide different behavior.
2024 SourceLocation LParenLoc,
2025 SourceLocation EndLoc) {
2026 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2027 LParenLoc, EndLoc);
2028 }
2029
2030 /// Build a new OpenMP 'depend' pseudo clause.
2031 ///
2032 /// By default, performs semantic analysis to build the new OpenMP clause.
2033 /// Subclasses may override this routine to provide different behavior.
2035 Expr *DepModifier, ArrayRef<Expr *> VarList,
2036 SourceLocation StartLoc,
2037 SourceLocation LParenLoc,
2038 SourceLocation EndLoc) {
2040 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2041 }
2042
2043 /// Build a new OpenMP 'device' clause.
2044 ///
2045 /// By default, performs semantic analysis to build the new statement.
2046 /// Subclasses may override this routine to provide different behavior.
2048 Expr *Device, SourceLocation StartLoc,
2049 SourceLocation LParenLoc,
2050 SourceLocation ModifierLoc,
2051 SourceLocation EndLoc) {
2053 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2054 }
2055
2056 /// Build a new OpenMP 'map' clause.
2057 ///
2058 /// By default, performs semantic analysis to build the new OpenMP clause.
2059 /// Subclasses may override this routine to provide different behavior.
2061 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2062 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2063 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2064 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2065 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2066 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2068 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2069 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2070 ColonLoc, VarList, Locs,
2071 /*NoDiagnose=*/false, UnresolvedMappers);
2072 }
2073
2074 /// Build a new OpenMP 'allocate' clause.
2075 ///
2076 /// By default, performs semantic analysis to build the new OpenMP clause.
2077 /// Subclasses may override this routine to provide different behavior.
2080 ArrayRef<Expr *> VarList,
2081 SourceLocation StartLoc,
2082 SourceLocation LParenLoc,
2083 SourceLocation ColonLoc,
2084 SourceLocation EndLoc) {
2086 Allocate, ACModifier, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2087 }
2088
2089 /// Build a new OpenMP 'num_teams' clause.
2090 ///
2091 /// By default, performs semantic analysis to build the new statement.
2092 /// Subclasses may override this routine to provide different behavior.
2094 SourceLocation StartLoc,
2095 SourceLocation LParenLoc,
2096 SourceLocation EndLoc) {
2097 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc,
2098 LParenLoc, EndLoc);
2099 }
2100
2101 /// Build a new OpenMP 'thread_limit' clause.
2102 ///
2103 /// By default, performs semantic analysis to build the new statement.
2104 /// Subclasses may override this routine to provide different behavior.
2106 SourceLocation StartLoc,
2107 SourceLocation LParenLoc,
2108 SourceLocation EndLoc) {
2109 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2110 LParenLoc, EndLoc);
2111 }
2112
2113 /// Build a new OpenMP 'priority' clause.
2114 ///
2115 /// By default, performs semantic analysis to build the new statement.
2116 /// Subclasses may override this routine to provide different behavior.
2118 SourceLocation LParenLoc,
2119 SourceLocation EndLoc) {
2120 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2121 LParenLoc, EndLoc);
2122 }
2123
2124 /// Build a new OpenMP 'grainsize' clause.
2125 ///
2126 /// By default, performs semantic analysis to build the new statement.
2127 /// Subclasses may override this routine to provide different behavior.
2129 Expr *Device, SourceLocation StartLoc,
2130 SourceLocation LParenLoc,
2131 SourceLocation ModifierLoc,
2132 SourceLocation EndLoc) {
2134 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2135 }
2136
2137 /// Build a new OpenMP 'num_tasks' clause.
2138 ///
2139 /// By default, performs semantic analysis to build the new statement.
2140 /// Subclasses may override this routine to provide different behavior.
2142 Expr *NumTasks, SourceLocation StartLoc,
2143 SourceLocation LParenLoc,
2144 SourceLocation ModifierLoc,
2145 SourceLocation EndLoc) {
2147 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2148 }
2149
2150 /// Build a new OpenMP 'hint' clause.
2151 ///
2152 /// By default, performs semantic analysis to build the new statement.
2153 /// Subclasses may override this routine to provide different behavior.
2155 SourceLocation LParenLoc,
2156 SourceLocation EndLoc) {
2157 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2158 EndLoc);
2159 }
2160
2161 /// Build a new OpenMP 'detach' clause.
2162 ///
2163 /// By default, performs semantic analysis to build the new statement.
2164 /// Subclasses may override this routine to provide different behavior.
2166 SourceLocation LParenLoc,
2167 SourceLocation EndLoc) {
2168 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2169 EndLoc);
2170 }
2171
2172 /// Build a new OpenMP 'dist_schedule' clause.
2173 ///
2174 /// By default, performs semantic analysis to build the new OpenMP clause.
2175 /// Subclasses may override this routine to provide different behavior.
2176 OMPClause *
2178 Expr *ChunkSize, SourceLocation StartLoc,
2179 SourceLocation LParenLoc, SourceLocation KindLoc,
2180 SourceLocation CommaLoc, SourceLocation EndLoc) {
2182 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2183 }
2184
2185 /// Build a new OpenMP 'to' clause.
2186 ///
2187 /// By default, performs semantic analysis to build the new statement.
2188 /// Subclasses may override this routine to provide different behavior.
2189 OMPClause *
2191 ArrayRef<SourceLocation> MotionModifiersLoc,
2192 CXXScopeSpec &MapperIdScopeSpec,
2193 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2194 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2195 ArrayRef<Expr *> UnresolvedMappers) {
2197 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2198 ColonLoc, VarList, Locs, UnresolvedMappers);
2199 }
2200
2201 /// Build a new OpenMP 'from' clause.
2202 ///
2203 /// By default, performs semantic analysis to build the new statement.
2204 /// Subclasses may override this routine to provide different behavior.
2205 OMPClause *
2207 ArrayRef<SourceLocation> MotionModifiersLoc,
2208 CXXScopeSpec &MapperIdScopeSpec,
2209 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2210 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2211 ArrayRef<Expr *> UnresolvedMappers) {
2213 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2214 ColonLoc, VarList, Locs, UnresolvedMappers);
2215 }
2216
2217 /// Build a new OpenMP 'use_device_ptr' clause.
2218 ///
2219 /// By default, performs semantic analysis to build the new OpenMP clause.
2220 /// Subclasses may override this routine to provide different behavior.
2222 const OMPVarListLocTy &Locs) {
2223 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2224 }
2225
2226 /// Build a new OpenMP 'use_device_addr' clause.
2227 ///
2228 /// By default, performs semantic analysis to build the new OpenMP clause.
2229 /// Subclasses may override this routine to provide different behavior.
2231 const OMPVarListLocTy &Locs) {
2232 return getSema().OpenMP().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2233 }
2234
2235 /// Build a new OpenMP 'is_device_ptr' clause.
2236 ///
2237 /// By default, performs semantic analysis to build the new OpenMP clause.
2238 /// Subclasses may override this routine to provide different behavior.
2240 const OMPVarListLocTy &Locs) {
2241 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2242 }
2243
2244 /// Build a new OpenMP 'has_device_addr' clause.
2245 ///
2246 /// By default, performs semantic analysis to build the new OpenMP clause.
2247 /// Subclasses may override this routine to provide different behavior.
2249 const OMPVarListLocTy &Locs) {
2250 return getSema().OpenMP().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2251 }
2252
2253 /// Build a new OpenMP 'defaultmap' clause.
2254 ///
2255 /// By default, performs semantic analysis to build the new OpenMP clause.
2256 /// Subclasses may override this routine to provide different behavior.
2259 SourceLocation StartLoc,
2260 SourceLocation LParenLoc,
2261 SourceLocation MLoc,
2262 SourceLocation KindLoc,
2263 SourceLocation EndLoc) {
2265 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2266 }
2267
2268 /// Build a new OpenMP 'nontemporal' clause.
2269 ///
2270 /// By default, performs semantic analysis to build the new OpenMP clause.
2271 /// Subclasses may override this routine to provide different behavior.
2273 SourceLocation StartLoc,
2274 SourceLocation LParenLoc,
2275 SourceLocation EndLoc) {
2276 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2277 LParenLoc, EndLoc);
2278 }
2279
2280 /// Build a new OpenMP 'inclusive' clause.
2281 ///
2282 /// By default, performs semantic analysis to build the new OpenMP clause.
2283 /// Subclasses may override this routine to provide different behavior.
2285 SourceLocation StartLoc,
2286 SourceLocation LParenLoc,
2287 SourceLocation EndLoc) {
2288 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2289 LParenLoc, EndLoc);
2290 }
2291
2292 /// Build a new OpenMP 'exclusive' clause.
2293 ///
2294 /// By default, performs semantic analysis to build the new OpenMP clause.
2295 /// Subclasses may override this routine to provide different behavior.
2297 SourceLocation StartLoc,
2298 SourceLocation LParenLoc,
2299 SourceLocation EndLoc) {
2300 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2301 LParenLoc, EndLoc);
2302 }
2303
2304 /// Build a new OpenMP 'uses_allocators' clause.
2305 ///
2306 /// By default, performs semantic analysis to build the new OpenMP clause.
2307 /// Subclasses may override this routine to provide different behavior.
2310 SourceLocation LParenLoc, SourceLocation EndLoc) {
2312 StartLoc, LParenLoc, EndLoc, Data);
2313 }
2314
2315 /// Build a new OpenMP 'affinity' clause.
2316 ///
2317 /// By default, performs semantic analysis to build the new OpenMP clause.
2318 /// Subclasses may override this routine to provide different behavior.
2320 SourceLocation LParenLoc,
2321 SourceLocation ColonLoc,
2322 SourceLocation EndLoc, Expr *Modifier,
2323 ArrayRef<Expr *> Locators) {
2325 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2326 }
2327
2328 /// Build a new OpenMP 'order' clause.
2329 ///
2330 /// By default, performs semantic analysis to build the new OpenMP clause.
2331 /// Subclasses may override this routine to provide different behavior.
2333 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2334 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2335 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2337 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2338 }
2339
2340 /// Build a new OpenMP 'init' clause.
2341 ///
2342 /// By default, performs semantic analysis to build the new OpenMP clause.
2343 /// Subclasses may override this routine to provide different behavior.
2345 SourceLocation StartLoc,
2346 SourceLocation LParenLoc,
2347 SourceLocation VarLoc,
2348 SourceLocation EndLoc) {
2350 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2351 }
2352
2353 /// Build a new OpenMP 'use' clause.
2354 ///
2355 /// By default, performs semantic analysis to build the new OpenMP clause.
2356 /// Subclasses may override this routine to provide different behavior.
2358 SourceLocation LParenLoc,
2359 SourceLocation VarLoc, SourceLocation EndLoc) {
2360 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2361 LParenLoc, VarLoc, EndLoc);
2362 }
2363
2364 /// Build a new OpenMP 'destroy' clause.
2365 ///
2366 /// By default, performs semantic analysis to build the new OpenMP clause.
2367 /// Subclasses may override this routine to provide different behavior.
2369 SourceLocation LParenLoc,
2370 SourceLocation VarLoc,
2371 SourceLocation EndLoc) {
2373 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2374 }
2375
2376 /// Build a new OpenMP 'novariants' clause.
2377 ///
2378 /// By default, performs semantic analysis to build the new OpenMP clause.
2379 /// Subclasses may override this routine to provide different behavior.
2381 SourceLocation StartLoc,
2382 SourceLocation LParenLoc,
2383 SourceLocation EndLoc) {
2385 LParenLoc, EndLoc);
2386 }
2387
2388 /// Build a new OpenMP 'nocontext' clause.
2389 ///
2390 /// By default, performs semantic analysis to build the new OpenMP clause.
2391 /// Subclasses may override this routine to provide different behavior.
2393 SourceLocation LParenLoc,
2394 SourceLocation EndLoc) {
2396 LParenLoc, EndLoc);
2397 }
2398
2399 /// Build a new OpenMP 'filter' clause.
2400 ///
2401 /// By default, performs semantic analysis to build the new OpenMP clause.
2402 /// Subclasses may override this routine to provide different behavior.
2404 SourceLocation LParenLoc,
2405 SourceLocation EndLoc) {
2406 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2407 LParenLoc, EndLoc);
2408 }
2409
2410 /// Build a new OpenMP 'bind' clause.
2411 ///
2412 /// By default, performs semantic analysis to build the new OpenMP clause.
2413 /// Subclasses may override this routine to provide different behavior.
2415 SourceLocation KindLoc,
2416 SourceLocation StartLoc,
2417 SourceLocation LParenLoc,
2418 SourceLocation EndLoc) {
2419 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2420 LParenLoc, EndLoc);
2421 }
2422
2423 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2424 ///
2425 /// By default, performs semantic analysis to build the new OpenMP clause.
2426 /// Subclasses may override this routine to provide different behavior.
2428 SourceLocation LParenLoc,
2429 SourceLocation EndLoc) {
2430 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2431 LParenLoc, EndLoc);
2432 }
2433
2434 /// Build a new OpenMP 'ompx_attribute' clause.
2435 ///
2436 /// By default, performs semantic analysis to build the new OpenMP clause.
2437 /// Subclasses may override this routine to provide different behavior.
2439 SourceLocation StartLoc,
2440 SourceLocation LParenLoc,
2441 SourceLocation EndLoc) {
2442 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2443 LParenLoc, EndLoc);
2444 }
2445
2446 /// Build a new OpenMP 'ompx_bare' clause.
2447 ///
2448 /// By default, performs semantic analysis to build the new OpenMP clause.
2449 /// Subclasses may override this routine to provide different behavior.
2451 SourceLocation EndLoc) {
2452 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2453 }
2454
2455 /// Build a new OpenMP 'align' clause.
2456 ///
2457 /// By default, performs semantic analysis to build the new OpenMP clause.
2458 /// Subclasses may override this routine to provide different behavior.
2460 SourceLocation LParenLoc,
2461 SourceLocation EndLoc) {
2462 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2463 EndLoc);
2464 }
2465
2466 /// Build a new OpenMP 'at' clause.
2467 ///
2468 /// By default, performs semantic analysis to build the new OpenMP clause.
2469 /// Subclasses may override this routine to provide different behavior.
2471 SourceLocation StartLoc,
2472 SourceLocation LParenLoc,
2473 SourceLocation EndLoc) {
2474 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2475 LParenLoc, EndLoc);
2476 }
2477
2478 /// Build a new OpenMP 'severity' clause.
2479 ///
2480 /// By default, performs semantic analysis to build the new OpenMP clause.
2481 /// Subclasses may override this routine to provide different behavior.
2483 SourceLocation KwLoc,
2484 SourceLocation StartLoc,
2485 SourceLocation LParenLoc,
2486 SourceLocation EndLoc) {
2487 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2488 LParenLoc, EndLoc);
2489 }
2490
2491 /// Build a new OpenMP 'message' clause.
2492 ///
2493 /// By default, performs semantic analysis to build the new OpenMP clause.
2494 /// Subclasses may override this routine to provide different behavior.
2496 SourceLocation LParenLoc,
2497 SourceLocation EndLoc) {
2498 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2499 EndLoc);
2500 }
2501
2502 /// Build a new OpenMP 'doacross' clause.
2503 ///
2504 /// By default, performs semantic analysis to build the new OpenMP clause.
2505 /// Subclasses may override this routine to provide different behavior.
2506 OMPClause *
2508 SourceLocation DepLoc, SourceLocation ColonLoc,
2509 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2510 SourceLocation LParenLoc, SourceLocation EndLoc) {
2512 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2513 }
2514
2515 /// Build a new OpenMP 'holds' clause.
2517 SourceLocation LParenLoc,
2518 SourceLocation EndLoc) {
2519 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2520 EndLoc);
2521 }
2522
2523 /// Rebuild the operand to an Objective-C \@synchronized statement.
2524 ///
2525 /// By default, performs semantic analysis to build the new statement.
2526 /// Subclasses may override this routine to provide different behavior.
2528 Expr *object) {
2529 return getSema().ObjC().ActOnObjCAtSynchronizedOperand(atLoc, object);
2530 }
2531
2532 /// Build a new Objective-C \@synchronized statement.
2533 ///
2534 /// By default, performs semantic analysis to build the new statement.
2535 /// Subclasses may override this routine to provide different behavior.
2537 Expr *Object, Stmt *Body) {
2538 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2539 }
2540
2541 /// Build a new Objective-C \@autoreleasepool statement.
2542 ///
2543 /// By default, performs semantic analysis to build the new statement.
2544 /// Subclasses may override this routine to provide different behavior.
2546 Stmt *Body) {
2547 return getSema().ObjC().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2548 }
2549
2550 /// Build a new Objective-C fast enumeration statement.
2551 ///
2552 /// By default, performs semantic analysis to build the new statement.
2553 /// Subclasses may override this routine to provide different behavior.
2555 Stmt *Element,
2556 Expr *Collection,
2557 SourceLocation RParenLoc,
2558 Stmt *Body) {
2560 ForLoc, Element, Collection, RParenLoc);
2561 if (ForEachStmt.isInvalid())
2562 return StmtError();
2563
2564 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2565 Body);
2566 }
2567
2568 /// Build a new C++ exception declaration.
2569 ///
2570 /// By default, performs semantic analysis to build the new decaration.
2571 /// Subclasses may override this routine to provide different behavior.
2574 SourceLocation StartLoc,
2575 SourceLocation IdLoc,
2576 IdentifierInfo *Id) {
2578 StartLoc, IdLoc, Id);
2579 if (Var)
2580 getSema().CurContext->addDecl(Var);
2581 return Var;
2582 }
2583
2584 /// Build a new C++ catch statement.
2585 ///
2586 /// By default, performs semantic analysis to build the new statement.
2587 /// Subclasses may override this routine to provide different behavior.
2589 VarDecl *ExceptionDecl,
2590 Stmt *Handler) {
2591 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2592 Handler));
2593 }
2594
2595 /// Build a new C++ try statement.
2596 ///
2597 /// By default, performs semantic analysis to build the new statement.
2598 /// Subclasses may override this routine to provide different behavior.
2600 ArrayRef<Stmt *> Handlers) {
2601 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2602 }
2603
2604 /// Build a new C++0x range-based for statement.
2605 ///
2606 /// By default, performs semantic analysis to build the new statement.
2607 /// Subclasses may override this routine to provide different behavior.
2609 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2610 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2611 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2612 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2613 // If we've just learned that the range is actually an Objective-C
2614 // collection, treat this as an Objective-C fast enumeration loop.
2615 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2616 if (RangeStmt->isSingleDecl()) {
2617 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2618 if (RangeVar->isInvalidDecl())
2619 return StmtError();
2620
2621 Expr *RangeExpr = RangeVar->getInit();
2622 if (!RangeExpr->isTypeDependent() &&
2623 RangeExpr->getType()->isObjCObjectPointerType()) {
2624 // FIXME: Support init-statements in Objective-C++20 ranged for
2625 // statement.
2626 if (Init) {
2627 return SemaRef.Diag(Init->getBeginLoc(),
2628 diag::err_objc_for_range_init_stmt)
2629 << Init->getSourceRange();
2630 }
2632 ForLoc, LoopVar, RangeExpr, RParenLoc);
2633 }
2634 }
2635 }
2636 }
2637
2639 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2640 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2641 }
2642
2643 /// Build a new C++0x range-based for statement.
2644 ///
2645 /// By default, performs semantic analysis to build the new statement.
2646 /// Subclasses may override this routine to provide different behavior.
2648 bool IsIfExists,
2649 NestedNameSpecifierLoc QualifierLoc,
2650 DeclarationNameInfo NameInfo,
2651 Stmt *Nested) {
2652 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2653 QualifierLoc, NameInfo, Nested);
2654 }
2655
2656 /// Attach body to a C++0x range-based for statement.
2657 ///
2658 /// By default, performs semantic analysis to finish the new statement.
2659 /// Subclasses may override this routine to provide different behavior.
2661 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2662 }
2663
2665 Stmt *TryBlock, Stmt *Handler) {
2666 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2667 }
2668
2670 Stmt *Block) {
2671 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2672 }
2673
2675 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2676 }
2677
2679 SourceLocation LParen,
2680 SourceLocation RParen,
2681 TypeSourceInfo *TSI) {
2682 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2683 TSI);
2684 }
2685
2686 /// Build a new predefined expression.
2687 ///
2688 /// By default, performs semantic analysis to build the new expression.
2689 /// Subclasses may override this routine to provide different behavior.
2691 return getSema().BuildPredefinedExpr(Loc, IK);
2692 }
2693
2694 /// Build a new expression that references a declaration.
2695 ///
2696 /// By default, performs semantic analysis to build the new expression.
2697 /// Subclasses may override this routine to provide different behavior.
2699 LookupResult &R,
2700 bool RequiresADL) {
2701 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2702 }
2703
2704
2705 /// Build a new expression that references a declaration.
2706 ///
2707 /// By default, performs semantic analysis to build the new expression.
2708 /// Subclasses may override this routine to provide different behavior.
2710 ValueDecl *VD,
2711 const DeclarationNameInfo &NameInfo,
2713 TemplateArgumentListInfo *TemplateArgs) {
2714 CXXScopeSpec SS;
2715 SS.Adopt(QualifierLoc);
2716 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2717 TemplateArgs);
2718 }
2719
2720 /// Build a new expression in parentheses.
2721 ///
2722 /// By default, performs semantic analysis to build the new expression.
2723 /// Subclasses may override this routine to provide different behavior.
2725 SourceLocation RParen) {
2726 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2727 }
2728
2729 /// Build a new pseudo-destructor expression.
2730 ///
2731 /// By default, performs semantic analysis to build the new expression.
2732 /// Subclasses may override this routine to provide different behavior.
2734 SourceLocation OperatorLoc,
2735 bool isArrow,
2736 CXXScopeSpec &SS,
2737 TypeSourceInfo *ScopeType,
2738 SourceLocation CCLoc,
2739 SourceLocation TildeLoc,
2740 PseudoDestructorTypeStorage Destroyed);
2741
2742 /// Build a new unary operator expression.
2743 ///
2744 /// By default, performs semantic analysis to build the new expression.
2745 /// Subclasses may override this routine to provide different behavior.
2748 Expr *SubExpr) {
2749 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2750 }
2751
2752 /// Build a new builtin offsetof expression.
2753 ///
2754 /// By default, performs semantic analysis to build the new expression.
2755 /// Subclasses may override this routine to provide different behavior.
2759 SourceLocation RParenLoc) {
2760 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2761 RParenLoc);
2762 }
2763
2764 /// Build a new sizeof, alignof or vec_step expression with a
2765 /// type argument.
2766 ///
2767 /// By default, performs semantic analysis to build the new expression.
2768 /// Subclasses may override this routine to provide different behavior.
2770 SourceLocation OpLoc,
2771 UnaryExprOrTypeTrait ExprKind,
2772 SourceRange R) {
2773 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2774 }
2775
2776 /// Build a new sizeof, alignof or vec step expression with an
2777 /// expression argument.
2778 ///
2779 /// By default, performs semantic analysis to build the new expression.
2780 /// Subclasses may override this routine to provide different behavior.
2782 UnaryExprOrTypeTrait ExprKind,
2783 SourceRange R) {
2785 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2786 if (Result.isInvalid())
2787 return ExprError();
2788
2789 return Result;
2790 }
2791
2792 /// Build a new array subscript expression.
2793 ///
2794 /// By default, performs semantic analysis to build the new expression.
2795 /// Subclasses may override this routine to provide different behavior.
2797 SourceLocation LBracketLoc,
2798 Expr *RHS,
2799 SourceLocation RBracketLoc) {
2800 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2801 LBracketLoc, RHS,
2802 RBracketLoc);
2803 }
2804
2805 /// Build a new matrix subscript expression.
2806 ///
2807 /// By default, performs semantic analysis to build the new expression.
2808 /// Subclasses may override this routine to provide different behavior.
2810 Expr *ColumnIdx,
2811 SourceLocation RBracketLoc) {
2812 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2813 RBracketLoc);
2814 }
2815
2816 /// Build a new array section expression.
2817 ///
2818 /// By default, performs semantic analysis to build the new expression.
2819 /// Subclasses may override this routine to provide different behavior.
2821 SourceLocation LBracketLoc,
2822 Expr *LowerBound,
2823 SourceLocation ColonLocFirst,
2824 SourceLocation ColonLocSecond,
2825 Expr *Length, Expr *Stride,
2826 SourceLocation RBracketLoc) {
2827 if (IsOMPArraySection)
2829 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2830 Stride, RBracketLoc);
2831
2832 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2833 "Stride/second colon not allowed for OpenACC");
2834
2836 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2837 }
2838
2839 /// Build a new array shaping expression.
2840 ///
2841 /// By default, performs semantic analysis to build the new expression.
2842 /// Subclasses may override this routine to provide different behavior.
2844 SourceLocation RParenLoc,
2845 ArrayRef<Expr *> Dims,
2846 ArrayRef<SourceRange> BracketsRanges) {
2848 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2849 }
2850
2851 /// Build a new iterator expression.
2852 ///
2853 /// By default, performs semantic analysis to build the new expression.
2854 /// Subclasses may override this routine to provide different behavior.
2857 SourceLocation RLoc,
2860 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2861 }
2862
2863 /// Build a new call expression.
2864 ///
2865 /// By default, performs semantic analysis to build the new expression.
2866 /// Subclasses may override this routine to provide different behavior.
2868 MultiExprArg Args,
2869 SourceLocation RParenLoc,
2870 Expr *ExecConfig = nullptr) {
2871 return getSema().ActOnCallExpr(
2872 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2873 }
2874
2876 MultiExprArg Args,
2877 SourceLocation RParenLoc) {
2879 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2880 }
2881
2882 /// Build a new member access expression.
2883 ///
2884 /// By default, performs semantic analysis to build the new expression.
2885 /// Subclasses may override this routine to provide different behavior.
2887 bool isArrow,
2888 NestedNameSpecifierLoc QualifierLoc,
2889 SourceLocation TemplateKWLoc,
2890 const DeclarationNameInfo &MemberNameInfo,
2892 NamedDecl *FoundDecl,
2893 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2894 NamedDecl *FirstQualifierInScope) {
2896 isArrow);
2897 if (!Member->getDeclName()) {
2898 // We have a reference to an unnamed field. This is always the
2899 // base of an anonymous struct/union member access, i.e. the
2900 // field is always of record type.
2901 assert(Member->getType()->isRecordType() &&
2902 "unnamed member not of record type?");
2903
2904 BaseResult =
2906 QualifierLoc.getNestedNameSpecifier(),
2907 FoundDecl, Member);
2908 if (BaseResult.isInvalid())
2909 return ExprError();
2910 Base = BaseResult.get();
2911
2912 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2913 // from the AST, so we need to re-insert them if needed (since
2914 // `BuildFieldRefereneExpr()` doesn't do this).
2915 if (!isArrow && Base->isPRValue()) {
2917 if (BaseResult.isInvalid())
2918 return ExprError();
2919 Base = BaseResult.get();
2920 }
2921
2922 CXXScopeSpec EmptySS;
2924 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2925 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2926 MemberNameInfo);
2927 }
2928
2929 CXXScopeSpec SS;
2930 SS.Adopt(QualifierLoc);
2931
2932 Base = BaseResult.get();
2933 if (Base->containsErrors())
2934 return ExprError();
2935
2936 QualType BaseType = Base->getType();
2937
2938 if (isArrow && !BaseType->isPointerType())
2939 return ExprError();
2940
2941 // FIXME: this involves duplicating earlier analysis in a lot of
2942 // cases; we should avoid this when possible.
2943 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2944 R.addDecl(FoundDecl);
2945 R.resolveKind();
2946
2947 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2948 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2949 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2950 ->getType()
2951 ->getPointeeType()
2952 ->getAsCXXRecordDecl()) {
2953 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2954 // In unevaluated contexts, an expression supposed to be a member access
2955 // might reference a member in an unrelated class.
2956 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2957 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2958 VK_LValue, Member->getLocation());
2959 }
2960 }
2961
2962 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2963 SS, TemplateKWLoc,
2964 FirstQualifierInScope,
2965 R, ExplicitTemplateArgs,
2966 /*S*/nullptr);
2967 }
2968
2969 /// Build a new binary operator expression.
2970 ///
2971 /// By default, performs semantic analysis to build the new expression.
2972 /// Subclasses may override this routine to provide different behavior.
2975 Expr *LHS, Expr *RHS) {
2976 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2977 }
2978
2979 /// Build a new rewritten operator expression.
2980 ///
2981 /// By default, performs semantic analysis to build the new expression.
2982 /// Subclasses may override this routine to provide different behavior.
2984 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2985 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2986 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2987 RHS, /*RequiresADL*/false);
2988 }
2989
2990 /// Build a new conditional operator expression.
2991 ///
2992 /// By default, performs semantic analysis to build the new expression.
2993 /// Subclasses may override this routine to provide different behavior.
2995 SourceLocation QuestionLoc,
2996 Expr *LHS,
2997 SourceLocation ColonLoc,
2998 Expr *RHS) {
2999 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3000 LHS, RHS);
3001 }
3002
3003 /// Build a new C-style cast expression.
3004 ///
3005 /// By default, performs semantic analysis to build the new expression.
3006 /// Subclasses may override this routine to provide different behavior.
3008 TypeSourceInfo *TInfo,
3009 SourceLocation RParenLoc,
3010 Expr *SubExpr) {
3011 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3012 SubExpr);
3013 }
3014
3015 /// Build a new compound literal expression.
3016 ///
3017 /// By default, performs semantic analysis to build the new expression.
3018 /// Subclasses may override this routine to provide different behavior.
3020 TypeSourceInfo *TInfo,
3021 SourceLocation RParenLoc,
3022 Expr *Init) {
3023 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3024 Init);
3025 }
3026
3027 /// Build a new extended vector element access expression.
3028 ///
3029 /// By default, performs semantic analysis to build the new expression.
3030 /// Subclasses may override this routine to provide different behavior.
3032 bool IsArrow,
3033 SourceLocation AccessorLoc,
3034 IdentifierInfo &Accessor) {
3035
3036 CXXScopeSpec SS;
3037 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3039 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3040 /*FirstQualifierInScope*/ nullptr, NameInfo,
3041 /* TemplateArgs */ nullptr,
3042 /*S*/ nullptr);
3043 }
3044
3045 /// Build a new initializer list expression.
3046 ///
3047 /// By default, performs semantic analysis to build the new expression.
3048 /// Subclasses may override this routine to provide different behavior.
3050 MultiExprArg Inits,
3051 SourceLocation RBraceLoc) {
3052 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3053 }
3054
3055 /// Build a new designated initializer expression.
3056 ///
3057 /// By default, performs semantic analysis to build the new expression.
3058 /// Subclasses may override this routine to provide different behavior.
3060 MultiExprArg ArrayExprs,
3061 SourceLocation EqualOrColonLoc,
3062 bool GNUSyntax,
3063 Expr *Init) {
3065 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3066 Init);
3067 if (Result.isInvalid())
3068 return ExprError();
3069
3070 return Result;
3071 }
3072
3073 /// Build a new value-initialized expression.
3074 ///
3075 /// By default, builds the implicit value initialization without performing
3076 /// any semantic analysis. Subclasses may override this routine to provide
3077 /// different behavior.
3079 return new (SemaRef.Context) ImplicitValueInitExpr(T);
3080 }
3081
3082 /// Build a new \c va_arg expression.
3083 ///
3084 /// By default, performs semantic analysis to build the new expression.
3085 /// Subclasses may override this routine to provide different behavior.
3087 Expr *SubExpr, TypeSourceInfo *TInfo,
3088 SourceLocation RParenLoc) {
3089 return getSema().BuildVAArgExpr(BuiltinLoc,
3090 SubExpr, TInfo,
3091 RParenLoc);
3092 }
3093
3094 /// Build a new expression list in parentheses.
3095 ///
3096 /// By default, performs semantic analysis to build the new expression.
3097 /// Subclasses may override this routine to provide different behavior.
3099 MultiExprArg SubExprs,
3100 SourceLocation RParenLoc) {
3101 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3102 }
3103
3104 /// Build a new address-of-label expression.
3105 ///
3106 /// By default, performs semantic analysis, using the name of the label
3107 /// rather than attempting to map the label statement itself.
3108 /// Subclasses may override this routine to provide different behavior.
3110 SourceLocation LabelLoc, LabelDecl *Label) {
3111 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3112 }
3113
3114 /// Build a new GNU statement expression.
3115 ///
3116 /// By default, performs semantic analysis to build the new expression.
3117 /// Subclasses may override this routine to provide different behavior.
3119 SourceLocation RParenLoc, unsigned TemplateDepth) {
3120 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3121 TemplateDepth);
3122 }
3123
3124 /// Build a new __builtin_choose_expr expression.
3125 ///
3126 /// By default, performs semantic analysis to build the new expression.
3127 /// Subclasses may override this routine to provide different behavior.
3129 Expr *Cond, Expr *LHS, Expr *RHS,
3130 SourceLocation RParenLoc) {
3131 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3132 Cond, LHS, RHS,
3133 RParenLoc);
3134 }
3135
3136 /// Build a new generic selection expression with an expression predicate.
3137 ///
3138 /// By default, performs semantic analysis to build the new expression.
3139 /// Subclasses may override this routine to provide different behavior.
3141 SourceLocation DefaultLoc,
3142 SourceLocation RParenLoc,
3143 Expr *ControllingExpr,
3145 ArrayRef<Expr *> Exprs) {
3146 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3147 /*PredicateIsExpr=*/true,
3148 ControllingExpr, Types, Exprs);
3149 }
3150
3151 /// Build a new generic selection expression with a type predicate.
3152 ///
3153 /// By default, performs semantic analysis to build the new expression.
3154 /// Subclasses may override this routine to provide different behavior.
3156 SourceLocation DefaultLoc,
3157 SourceLocation RParenLoc,
3158 TypeSourceInfo *ControllingType,
3160 ArrayRef<Expr *> Exprs) {
3161 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3162 /*PredicateIsExpr=*/false,
3163 ControllingType, Types, Exprs);
3164 }
3165
3166 /// Build a new overloaded operator call expression.
3167 ///
3168 /// By default, performs semantic analysis to build the new expression.
3169 /// The semantic analysis provides the behavior of template instantiation,
3170 /// copying with transformations that turn what looks like an overloaded
3171 /// operator call into a use of a builtin operator, performing
3172 /// argument-dependent lookup, etc. Subclasses may override this routine to
3173 /// provide different behavior.
3175 SourceLocation OpLoc,
3176 SourceLocation CalleeLoc,
3177 bool RequiresADL,
3178 const UnresolvedSetImpl &Functions,
3179 Expr *First, Expr *Second);
3180
3181 /// Build a new C++ "named" cast expression, such as static_cast or
3182 /// reinterpret_cast.
3183 ///
3184 /// By default, this routine dispatches to one of the more-specific routines
3185 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3186 /// Subclasses may override this routine to provide different behavior.
3189 SourceLocation LAngleLoc,
3190 TypeSourceInfo *TInfo,
3191 SourceLocation RAngleLoc,
3192 SourceLocation LParenLoc,
3193 Expr *SubExpr,
3194 SourceLocation RParenLoc) {
3195 switch (Class) {
3196 case Stmt::CXXStaticCastExprClass:
3197 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3198 RAngleLoc, LParenLoc,
3199 SubExpr, RParenLoc);
3200
3201 case Stmt::CXXDynamicCastExprClass:
3202 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3203 RAngleLoc, LParenLoc,
3204 SubExpr, RParenLoc);
3205
3206 case Stmt::CXXReinterpretCastExprClass:
3207 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3208 RAngleLoc, LParenLoc,
3209 SubExpr,
3210 RParenLoc);
3211
3212 case Stmt::CXXConstCastExprClass:
3213 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3214 RAngleLoc, LParenLoc,
3215 SubExpr, RParenLoc);
3216
3217 case Stmt::CXXAddrspaceCastExprClass:
3218 return getDerived().RebuildCXXAddrspaceCastExpr(
3219 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3220
3221 default:
3222 llvm_unreachable("Invalid C++ named cast");
3223 }
3224 }
3225
3226 /// Build a new C++ static_cast expression.
3227 ///
3228 /// By default, performs semantic analysis to build the new expression.
3229 /// Subclasses may override this routine to provide different behavior.
3231 SourceLocation LAngleLoc,
3232 TypeSourceInfo *TInfo,
3233 SourceLocation RAngleLoc,
3234 SourceLocation LParenLoc,
3235 Expr *SubExpr,
3236 SourceLocation RParenLoc) {
3237 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3238 TInfo, SubExpr,
3239 SourceRange(LAngleLoc, RAngleLoc),
3240 SourceRange(LParenLoc, RParenLoc));
3241 }
3242
3243 /// Build a new C++ dynamic_cast expression.
3244 ///
3245 /// By default, performs semantic analysis to build the new expression.
3246 /// Subclasses may override this routine to provide different behavior.
3248 SourceLocation LAngleLoc,
3249 TypeSourceInfo *TInfo,
3250 SourceLocation RAngleLoc,
3251 SourceLocation LParenLoc,
3252 Expr *SubExpr,
3253 SourceLocation RParenLoc) {
3254 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3255 TInfo, SubExpr,
3256 SourceRange(LAngleLoc, RAngleLoc),
3257 SourceRange(LParenLoc, RParenLoc));
3258 }
3259
3260 /// Build a new C++ reinterpret_cast expression.
3261 ///
3262 /// By default, performs semantic analysis to build the new expression.
3263 /// Subclasses may override this routine to provide different behavior.
3265 SourceLocation LAngleLoc,
3266 TypeSourceInfo *TInfo,
3267 SourceLocation RAngleLoc,
3268 SourceLocation LParenLoc,
3269 Expr *SubExpr,
3270 SourceLocation RParenLoc) {
3271 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3272 TInfo, SubExpr,
3273 SourceRange(LAngleLoc, RAngleLoc),
3274 SourceRange(LParenLoc, RParenLoc));
3275 }
3276
3277 /// Build a new C++ const_cast expression.
3278 ///
3279 /// By default, performs semantic analysis to build the new expression.
3280 /// Subclasses may override this routine to provide different behavior.
3282 SourceLocation LAngleLoc,
3283 TypeSourceInfo *TInfo,
3284 SourceLocation RAngleLoc,
3285 SourceLocation LParenLoc,
3286 Expr *SubExpr,
3287 SourceLocation RParenLoc) {
3288 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3289 TInfo, SubExpr,
3290 SourceRange(LAngleLoc, RAngleLoc),
3291 SourceRange(LParenLoc, RParenLoc));
3292 }
3293
3296 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3297 SourceLocation LParenLoc, Expr *SubExpr,
3298 SourceLocation RParenLoc) {
3299 return getSema().BuildCXXNamedCast(
3300 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3301 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3302 }
3303
3304 /// Build a new C++ functional-style cast expression.
3305 ///
3306 /// By default, performs semantic analysis to build the new expression.
3307 /// Subclasses may override this routine to provide different behavior.
3309 SourceLocation LParenLoc,
3310 Expr *Sub,
3311 SourceLocation RParenLoc,
3312 bool ListInitialization) {
3313 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3314 // CXXParenListInitExpr. Pass its expanded arguments so that the
3315 // CXXParenListInitExpr can be rebuilt.
3316 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3318 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3319 RParenLoc, ListInitialization);
3320 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3321 MultiExprArg(&Sub, 1), RParenLoc,
3322 ListInitialization);
3323 }
3324
3325 /// Build a new C++ __builtin_bit_cast expression.
3326 ///
3327 /// By default, performs semantic analysis to build the new expression.
3328 /// Subclasses may override this routine to provide different behavior.
3330 TypeSourceInfo *TSI, Expr *Sub,
3331 SourceLocation RParenLoc) {
3332 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3333 }
3334
3335 /// Build a new C++ typeid(type) expression.
3336 ///
3337 /// By default, performs semantic analysis to build the new expression.
3338 /// Subclasses may override this routine to provide different behavior.
3340 SourceLocation TypeidLoc,
3341 TypeSourceInfo *Operand,
3342 SourceLocation RParenLoc) {
3343 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3344 RParenLoc);
3345 }
3346
3347
3348 /// Build a new C++ typeid(expr) expression.
3349 ///
3350 /// By default, performs semantic analysis to build the new expression.
3351 /// Subclasses may override this routine to provide different behavior.
3353 SourceLocation TypeidLoc,
3354 Expr *Operand,
3355 SourceLocation RParenLoc) {
3356 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3357 RParenLoc);
3358 }
3359
3360 /// Build a new C++ __uuidof(type) expression.
3361 ///
3362 /// By default, performs semantic analysis to build the new expression.
3363 /// Subclasses may override this routine to provide different behavior.
3365 TypeSourceInfo *Operand,
3366 SourceLocation RParenLoc) {
3367 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3368 }
3369
3370 /// Build a new C++ __uuidof(expr) expression.
3371 ///
3372 /// By default, performs semantic analysis to build the new expression.
3373 /// Subclasses may override this routine to provide different behavior.
3375 Expr *Operand, SourceLocation RParenLoc) {
3376 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3377 }
3378
3379 /// Build a new C++ "this" expression.
3380 ///
3381 /// By default, performs semantic analysis to build a new "this" expression.
3382 /// Subclasses may override this routine to provide different behavior.
3384 QualType ThisType,
3385 bool isImplicit) {
3386 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3387 return ExprError();
3388 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3389 }
3390
3391 /// Build a new C++ throw expression.
3392 ///
3393 /// By default, performs semantic analysis to build the new expression.
3394 /// Subclasses may override this routine to provide different behavior.
3396 bool IsThrownVariableInScope) {
3397 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3398 }
3399
3400 /// Build a new C++ default-argument expression.
3401 ///
3402 /// By default, builds a new default-argument expression, which does not
3403 /// require any semantic analysis. Subclasses may override this routine to
3404 /// provide different behavior.
3406 Expr *RewrittenExpr) {
3407 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3408 RewrittenExpr, getSema().CurContext);
3409 }
3410
3411 /// Build a new C++11 default-initialization expression.
3412 ///
3413 /// By default, builds a new default field initialization expression, which
3414 /// does not require any semantic analysis. Subclasses may override this
3415 /// routine to provide different behavior.
3417 FieldDecl *Field) {
3418 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3419 }
3420
3421 /// Build a new C++ zero-initialization expression.
3422 ///
3423 /// By default, performs semantic analysis to build the new expression.
3424 /// Subclasses may override this routine to provide different behavior.
3426 SourceLocation LParenLoc,
3427 SourceLocation RParenLoc) {
3428 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3429 /*ListInitialization=*/false);
3430 }
3431
3432 /// Build a new C++ "new" expression.
3433 ///
3434 /// By default, performs semantic analysis to build the new expression.
3435 /// Subclasses may override this routine to provide different behavior.
3437 SourceLocation PlacementLParen,
3438 MultiExprArg PlacementArgs,
3439 SourceLocation PlacementRParen,
3440 SourceRange TypeIdParens, QualType AllocatedType,
3441 TypeSourceInfo *AllocatedTypeInfo,
3442 std::optional<Expr *> ArraySize,
3443 SourceRange DirectInitRange, Expr *Initializer) {
3444 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3445 PlacementLParen,
3446 PlacementArgs,
3447 PlacementRParen,
3448 TypeIdParens,
3449 AllocatedType,
3450 AllocatedTypeInfo,
3451 ArraySize,
3452 DirectInitRange,
3453 Initializer);
3454 }
3455
3456 /// Build a new C++ "delete" expression.
3457 ///
3458 /// By default, performs semantic analysis to build the new expression.
3459 /// Subclasses may override this routine to provide different behavior.
3461 bool IsGlobalDelete,
3462 bool IsArrayForm,
3463 Expr *Operand) {
3464 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3465 Operand);
3466 }
3467
3468 /// Build a new type trait expression.
3469 ///
3470 /// By default, performs semantic analysis to build the new expression.
3471 /// Subclasses may override this routine to provide different behavior.
3473 SourceLocation StartLoc,
3475 SourceLocation RParenLoc) {
3476 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3477 }
3478
3479 /// Build a new array type trait expression.
3480 ///
3481 /// By default, performs semantic analysis to build the new expression.
3482 /// Subclasses may override this routine to provide different behavior.
3484 SourceLocation StartLoc,
3485 TypeSourceInfo *TSInfo,
3486 Expr *DimExpr,
3487 SourceLocation RParenLoc) {
3488 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3489 }
3490
3491 /// Build a new expression trait expression.
3492 ///
3493 /// By default, performs semantic analysis to build the new expression.
3494 /// Subclasses may override this routine to provide different behavior.
3496 SourceLocation StartLoc,
3497 Expr *Queried,
3498 SourceLocation RParenLoc) {
3499 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3500 }
3501
3502 /// Build a new (previously unresolved) declaration reference
3503 /// expression.
3504 ///
3505 /// By default, performs semantic analysis to build the new expression.
3506 /// Subclasses may override this routine to provide different behavior.
3508 NestedNameSpecifierLoc QualifierLoc,
3509 SourceLocation TemplateKWLoc,
3510 const DeclarationNameInfo &NameInfo,
3511 const TemplateArgumentListInfo *TemplateArgs,
3512 bool IsAddressOfOperand,
3513 TypeSourceInfo **RecoveryTSI) {
3514 CXXScopeSpec SS;
3515 SS.Adopt(QualifierLoc);
3516
3517 if (TemplateArgs || TemplateKWLoc.isValid())
3519 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3520
3522 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3523 }
3524
3525 /// Build a new template-id expression.
3526 ///
3527 /// By default, performs semantic analysis to build the new expression.
3528 /// Subclasses may override this routine to provide different behavior.
3530 SourceLocation TemplateKWLoc,
3531 LookupResult &R,
3532 bool RequiresADL,
3533 const TemplateArgumentListInfo *TemplateArgs) {
3534 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3535 TemplateArgs);
3536 }
3537
3538 /// Build a new object-construction expression.
3539 ///
3540 /// By default, performs semantic analysis to build the new expression.
3541 /// Subclasses may override this routine to provide different behavior.
3544 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3545 bool ListInitialization, bool StdInitListInitialization,
3546 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3547 SourceRange ParenRange) {
3548 // Reconstruct the constructor we originally found, which might be
3549 // different if this is a call to an inherited constructor.
3550 CXXConstructorDecl *FoundCtor = Constructor;
3551 if (Constructor->isInheritingConstructor())
3552 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3553
3554 SmallVector<Expr *, 8> ConvertedArgs;
3555 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3556 ConvertedArgs))
3557 return ExprError();
3558
3559 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3560 IsElidable,
3561 ConvertedArgs,
3562 HadMultipleCandidates,
3563 ListInitialization,
3564 StdInitListInitialization,
3565 RequiresZeroInit, ConstructKind,
3566 ParenRange);
3567 }
3568
3569 /// Build a new implicit construction via inherited constructor
3570 /// expression.
3572 CXXConstructorDecl *Constructor,
3573 bool ConstructsVBase,
3574 bool InheritedFromVBase) {
3576 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3577 }
3578
3579 /// Build a new object-construction expression.
3580 ///
3581 /// By default, performs semantic analysis to build the new expression.
3582 /// Subclasses may override this routine to provide different behavior.
3584 SourceLocation LParenOrBraceLoc,
3585 MultiExprArg Args,
3586 SourceLocation RParenOrBraceLoc,
3587 bool ListInitialization) {
3589 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3590 }
3591
3592 /// Build a new object-construction expression.
3593 ///
3594 /// By default, performs semantic analysis to build the new expression.
3595 /// Subclasses may override this routine to provide different behavior.
3597 SourceLocation LParenLoc,
3598 MultiExprArg Args,
3599 SourceLocation RParenLoc,
3600 bool ListInitialization) {
3601 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3602 RParenLoc, ListInitialization);
3603 }
3604
3605 /// Build a new member reference expression.
3606 ///
3607 /// By default, performs semantic analysis to build the new expression.
3608 /// Subclasses may override this routine to provide different behavior.
3610 QualType BaseType,
3611 bool IsArrow,
3612 SourceLocation OperatorLoc,
3613 NestedNameSpecifierLoc QualifierLoc,
3614 SourceLocation TemplateKWLoc,
3615 NamedDecl *FirstQualifierInScope,
3616 const DeclarationNameInfo &MemberNameInfo,
3617 const TemplateArgumentListInfo *TemplateArgs) {
3618 CXXScopeSpec SS;
3619 SS.Adopt(QualifierLoc);
3620
3621 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3622 OperatorLoc, IsArrow,
3623 SS, TemplateKWLoc,
3624 FirstQualifierInScope,
3625 MemberNameInfo,
3626 TemplateArgs, /*S*/nullptr);
3627 }
3628
3629 /// Build a new member reference expression.
3630 ///
3631 /// By default, performs semantic analysis to build the new expression.
3632 /// Subclasses may override this routine to provide different behavior.
3634 SourceLocation OperatorLoc,
3635 bool IsArrow,
3636 NestedNameSpecifierLoc QualifierLoc,
3637 SourceLocation TemplateKWLoc,
3638 NamedDecl *FirstQualifierInScope,
3639 LookupResult &R,
3640 const TemplateArgumentListInfo *TemplateArgs) {
3641 CXXScopeSpec SS;
3642 SS.Adopt(QualifierLoc);
3643
3644 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3645 OperatorLoc, IsArrow,
3646 SS, TemplateKWLoc,
3647 FirstQualifierInScope,
3648 R, TemplateArgs, /*S*/nullptr);
3649 }
3650
3651 /// Build a new noexcept expression.
3652 ///
3653 /// By default, performs semantic analysis to build the new expression.
3654 /// Subclasses may override this routine to provide different behavior.
3656 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3657 }
3658
3659 /// Build a new expression to compute the length of a parameter pack.
3661 SourceLocation PackLoc,
3662 SourceLocation RParenLoc,
3663 std::optional<unsigned> Length,
3664 ArrayRef<TemplateArgument> PartialArgs) {
3665 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3666 RParenLoc, Length, PartialArgs);
3667 }
3668
3670 SourceLocation RSquareLoc,
3671 Expr *PackIdExpression, Expr *IndexExpr,
3672 ArrayRef<Expr *> ExpandedExprs,
3673 bool FullySubstituted = false) {
3674 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3675 IndexExpr, RSquareLoc, ExpandedExprs,
3676 FullySubstituted);
3677 }
3678
3679 /// Build a new expression representing a call to a source location
3680 /// builtin.
3681 ///
3682 /// By default, performs semantic analysis to build the new expression.
3683 /// Subclasses may override this routine to provide different behavior.
3685 SourceLocation BuiltinLoc,
3686 SourceLocation RPLoc,
3687 DeclContext *ParentContext) {
3688 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3689 ParentContext);
3690 }
3691
3692 /// Build a new Objective-C boxed expression.
3693 ///
3694 /// By default, performs semantic analysis to build the new expression.
3695 /// Subclasses may override this routine to provide different behavior.
3697 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3698 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3700 CXXScopeSpec SS;
3701 SS.Adopt(NNS);
3702 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3703 ConceptNameInfo,
3704 FoundDecl,
3705 NamedConcept, TALI);
3706 if (Result.isInvalid())
3707 return ExprError();
3708 return Result;
3709 }
3710
3711 /// \brief Build a new requires expression.
3712 ///
3713 /// By default, performs semantic analysis to build the new expression.
3714 /// Subclasses may override this routine to provide different behavior.
3717 SourceLocation LParenLoc,
3718 ArrayRef<ParmVarDecl *> LocalParameters,
3719 SourceLocation RParenLoc,
3721 SourceLocation ClosingBraceLoc) {
3722 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3723 LocalParameters, RParenLoc, Requirements,
3724 ClosingBraceLoc);
3725 }
3726
3730 return SemaRef.BuildTypeRequirement(SubstDiag);
3731 }
3732
3735 }
3736
3739 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3740 SourceLocation NoexceptLoc,
3742 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3743 std::move(Ret));
3744 }
3745
3747 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3749 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3750 std::move(Ret));
3751 }
3752
3754 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3755 const ASTConstraintSatisfaction &Satisfaction) {
3756 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3757 Satisfaction);
3758 }
3759
3761 return SemaRef.BuildNestedRequirement(Constraint);
3762 }
3763
3764 /// \brief Build a new Objective-C boxed expression.
3765 ///
3766 /// By default, performs semantic analysis to build the new expression.
3767 /// Subclasses may override this routine to provide different behavior.
3769 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3770 }
3771
3772 /// Build a new Objective-C array literal.
3773 ///
3774 /// By default, performs semantic analysis to build the new expression.
3775 /// Subclasses may override this routine to provide different behavior.
3777 Expr **Elements, unsigned NumElements) {
3779 Range, MultiExprArg(Elements, NumElements));
3780 }
3781
3783 Expr *Base, Expr *Key,
3784 ObjCMethodDecl *getterMethod,
3785 ObjCMethodDecl *setterMethod) {
3787 RB, Base, Key, getterMethod, setterMethod);
3788 }
3789
3790 /// Build a new Objective-C dictionary literal.
3791 ///
3792 /// By default, performs semantic analysis to build the new expression.
3793 /// Subclasses may override this routine to provide different behavior.
3796 return getSema().ObjC().BuildObjCDictionaryLiteral(Range, Elements);
3797 }
3798
3799 /// Build a new Objective-C \@encode expression.
3800 ///
3801 /// By default, performs semantic analysis to build the new expression.
3802 /// Subclasses may override this routine to provide different behavior.
3804 TypeSourceInfo *EncodeTypeInfo,
3805 SourceLocation RParenLoc) {
3806 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3807 RParenLoc);
3808 }
3809
3810 /// Build a new Objective-C class message.
3812 Selector Sel,
3813 ArrayRef<SourceLocation> SelectorLocs,
3814 ObjCMethodDecl *Method,
3815 SourceLocation LBracLoc,
3816 MultiExprArg Args,
3817 SourceLocation RBracLoc) {
3819 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3820 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3821 RBracLoc, Args);
3822 }
3823
3824 /// Build a new Objective-C instance message.
3826 Selector Sel,
3827 ArrayRef<SourceLocation> SelectorLocs,
3828 ObjCMethodDecl *Method,
3829 SourceLocation LBracLoc,
3830 MultiExprArg Args,
3831 SourceLocation RBracLoc) {
3832 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3833 /*SuperLoc=*/SourceLocation(),
3834 Sel, Method, LBracLoc,
3835 SelectorLocs, RBracLoc, Args);
3836 }
3837
3838 /// Build a new Objective-C instance/class message to 'super'.
3840 Selector Sel,
3841 ArrayRef<SourceLocation> SelectorLocs,
3842 QualType SuperType,
3843 ObjCMethodDecl *Method,
3844 SourceLocation LBracLoc,
3845 MultiExprArg Args,
3846 SourceLocation RBracLoc) {
3847 return Method->isInstanceMethod()
3849 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3850 SelectorLocs, RBracLoc, Args)
3851 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3852 Sel, Method, LBracLoc,
3853 SelectorLocs, RBracLoc, Args);
3854 }
3855
3856 /// Build a new Objective-C ivar reference expression.
3857 ///
3858 /// By default, performs semantic analysis to build the new expression.
3859 /// Subclasses may override this routine to provide different behavior.
3861 SourceLocation IvarLoc,
3862 bool IsArrow, bool IsFreeIvar) {
3863 CXXScopeSpec SS;
3864 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3866 BaseArg, BaseArg->getType(),
3867 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3868 /*FirstQualifierInScope=*/nullptr, NameInfo,
3869 /*TemplateArgs=*/nullptr,
3870 /*S=*/nullptr);
3871 if (IsFreeIvar && Result.isUsable())
3872 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3873 return Result;
3874 }
3875
3876 /// Build a new Objective-C property reference expression.
3877 ///
3878 /// By default, performs semantic analysis to build the new expression.
3879 /// Subclasses may override this routine to provide different behavior.
3882 SourceLocation PropertyLoc) {
3883 CXXScopeSpec SS;
3884 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3885 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3886 /*FIXME:*/PropertyLoc,
3887 /*IsArrow=*/false,
3888 SS, SourceLocation(),
3889 /*FirstQualifierInScope=*/nullptr,
3890 NameInfo,
3891 /*TemplateArgs=*/nullptr,
3892 /*S=*/nullptr);
3893 }
3894
3895 /// Build a new Objective-C property reference expression.
3896 ///
3897 /// By default, performs semantic analysis to build the new expression.
3898 /// Subclasses may override this routine to provide different behavior.
3900 ObjCMethodDecl *Getter,
3901 ObjCMethodDecl *Setter,
3902 SourceLocation PropertyLoc) {
3903 // Since these expressions can only be value-dependent, we do not
3904 // need to perform semantic analysis again.
3905 return Owned(
3906 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3908 PropertyLoc, Base));
3909 }
3910
3911 /// Build a new Objective-C "isa" expression.
3912 ///
3913 /// By default, performs semantic analysis to build the new expression.
3914 /// Subclasses may override this routine to provide different behavior.
3916 SourceLocation OpLoc, bool IsArrow) {
3917 CXXScopeSpec SS;
3918 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3919 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3920 OpLoc, IsArrow,
3921 SS, SourceLocation(),
3922 /*FirstQualifierInScope=*/nullptr,
3923 NameInfo,
3924 /*TemplateArgs=*/nullptr,
3925 /*S=*/nullptr);
3926 }
3927
3928 /// Build a new shuffle vector expression.
3929 ///
3930 /// By default, performs semantic analysis to build the new expression.
3931 /// Subclasses may override this routine to provide different behavior.
3933 MultiExprArg SubExprs,
3934 SourceLocation RParenLoc) {
3935 // Find the declaration for __builtin_shufflevector
3936 const IdentifierInfo &Name
3937 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3939 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3940 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3941
3942 // Build a reference to the __builtin_shufflevector builtin
3943 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3944 Expr *Callee = new (SemaRef.Context)
3945 DeclRefExpr(SemaRef.Context, Builtin, false,
3946 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3947 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3948 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3949 CK_BuiltinFnToFnPtr).get();
3950
3951 // Build the CallExpr
3952 ExprResult TheCall = CallExpr::Create(
3953 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3954 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3956
3957 // Type-check the __builtin_shufflevector expression.
3958 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3959 }
3960
3961 /// Build a new convert vector expression.
3963 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3964 SourceLocation RParenLoc) {
3965 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3966 }
3967
3968 /// Build a new template argument pack expansion.
3969 ///
3970 /// By default, performs semantic analysis to build a new pack expansion
3971 /// for a template argument. Subclasses may override this routine to provide
3972 /// different behavior.
3975 std::optional<unsigned> NumExpansions) {
3976 switch (Pattern.getArgument().getKind()) {
3980 EllipsisLoc, NumExpansions);
3981 if (Result.isInvalid())
3982 return TemplateArgumentLoc();
3983
3984 return TemplateArgumentLoc(Result.get(), Result.get());
3985 }
3986
3988 return TemplateArgumentLoc(
3991 NumExpansions),
3992 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3993 EllipsisLoc);
3994
4002 llvm_unreachable("Pack expansion pattern has no parameter packs");
4003
4005 if (TypeSourceInfo *Expansion
4006 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4007 EllipsisLoc,
4008 NumExpansions))
4009 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4010 Expansion);
4011 break;
4012 }
4013
4014 return TemplateArgumentLoc();
4015 }
4016
4017 /// Build a new expression pack expansion.
4018 ///
4019 /// By default, performs semantic analysis to build a new pack expansion
4020 /// for an expression. Subclasses may override this routine to provide
4021 /// different behavior.
4023 std::optional<unsigned> NumExpansions) {
4024 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4025 }
4026
4027 /// Build a new C++1z fold-expression.
4028 ///
4029 /// By default, performs semantic analysis in order to build a new fold
4030 /// expression.
4032 SourceLocation LParenLoc, Expr *LHS,
4033 BinaryOperatorKind Operator,
4034 SourceLocation EllipsisLoc, Expr *RHS,
4035 SourceLocation RParenLoc,
4036 std::optional<unsigned> NumExpansions) {
4037 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4038 EllipsisLoc, RHS, RParenLoc,
4039 NumExpansions);
4040 }
4041
4043 LambdaScopeInfo *LSI) {
4044 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4045 if (Expr *Init = PVD->getInit())
4047 Init->containsUnexpandedParameterPack();
4048 else if (PVD->hasUninstantiatedDefaultArg())
4050 PVD->getUninstantiatedDefaultArg()
4051 ->containsUnexpandedParameterPack();
4052 }
4053 return getSema().BuildLambdaExpr(StartLoc, EndLoc, LSI);
4054 }
4055
4056 /// Build an empty C++1z fold-expression with the given operator.
4057 ///
4058 /// By default, produces the fallback value for the fold-expression, or
4059 /// produce an error if there is no fallback value.
4061 BinaryOperatorKind Operator) {
4062 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4063 }
4064
4065 /// Build a new atomic operation expression.
4066 ///
4067 /// By default, performs semantic analysis to build the new expression.
4068 /// Subclasses may override this routine to provide different behavior.
4071 SourceLocation RParenLoc) {
4072 // Use this for all of the locations, since we don't know the difference
4073 // between the call and the expr at this point.
4074 SourceRange Range{BuiltinLoc, RParenLoc};
4075 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4077 }
4078
4080 ArrayRef<Expr *> SubExprs, QualType Type) {
4081 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4082 }
4083
4085 SourceLocation BeginLoc,
4086 SourceLocation DirLoc,
4087 SourceLocation EndLoc,
4089 StmtResult StrBlock) {
4091 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4092 SourceLocation{}, EndLoc, Clauses, StrBlock);
4093 }
4094
4096 SourceLocation DirLoc,
4097 SourceLocation EndLoc,
4099 StmtResult Loop) {
4101 OpenACCDirectiveKind::Loop, BeginLoc, DirLoc, SourceLocation{},
4102 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, Loop);
4103 }
4104
4106 SourceLocation BeginLoc,
4107 SourceLocation DirLoc,
4108 SourceLocation EndLoc,
4110 StmtResult Loop) {
4112 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4113 SourceLocation{}, EndLoc, Clauses, Loop);
4114 }
4115
4117 SourceLocation DirLoc,
4118 SourceLocation EndLoc,
4120 StmtResult StrBlock) {
4122 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4123 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4124 }
4125
4128 SourceLocation DirLoc, SourceLocation EndLoc,
4129 ArrayRef<OpenACCClause *> Clauses) {
4132 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4133 }
4134
4137 SourceLocation DirLoc, SourceLocation EndLoc,
4138 ArrayRef<OpenACCClause *> Clauses) {
4141 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4142 }
4143
4145 SourceLocation DirLoc,
4146 SourceLocation EndLoc,
4148 StmtResult StrBlock) {
4151 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4152 }
4153
4155 SourceLocation DirLoc,
4156 SourceLocation EndLoc,
4157 ArrayRef<OpenACCClause *> Clauses) {
4159 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4160 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4161 }
4162
4165 SourceLocation DirLoc, SourceLocation EndLoc,
4166 ArrayRef<OpenACCClause *> Clauses) {
4169 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4170 }
4171
4173 SourceLocation DirLoc,
4174 SourceLocation EndLoc,
4175 ArrayRef<OpenACCClause *> Clauses) {
4177 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4178 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4179 }
4180
4182 SourceLocation DirLoc,
4183 SourceLocation EndLoc,
4184 ArrayRef<OpenACCClause *> Clauses) {
4186 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4187 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4188 }
4189
4191 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4192 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4193 SourceLocation RParenLoc, SourceLocation EndLoc,
4194 ArrayRef<OpenACCClause *> Clauses) {
4196 Exprs.push_back(DevNumExpr);
4197 Exprs.insert(Exprs.end(), QueueIdExprs.begin(), QueueIdExprs.end());
4199 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4200 Exprs, RParenLoc, EndLoc, Clauses, {});
4201 }
4202
4204 return getSema().OpenACC().ActOnOpenACCAsteriskSizeExpr(AsteriskLoc);
4205 }
4206
4207private:
4208 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
4209 QualType ObjectType,
4210 NamedDecl *FirstQualifierInScope,
4211 CXXScopeSpec &SS);
4212
4213 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4214 QualType ObjectType,
4215 NamedDecl *FirstQualifierInScope,
4216 CXXScopeSpec &SS);
4217
4218 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
4219 NamedDecl *FirstQualifierInScope,
4220 CXXScopeSpec &SS);
4221
4222 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4224 bool DeducibleTSTContext);
4225
4227 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4229
4231 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4232 OpenACCDirectiveKind DirKind,
4233 const OpenACCClause *OldClause);
4234};
4235
4236template <typename Derived>
4238 if (!S)
4239 return S;
4240
4241 switch (S->getStmtClass()) {
4242 case Stmt::NoStmtClass: break;
4243
4244 // Transform individual statement nodes
4245 // Pass SDK into statements that can produce a value
4246#define STMT(Node, Parent) \
4247 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4248#define VALUESTMT(Node, Parent) \
4249 case Stmt::Node##Class: \
4250 return getDerived().Transform##Node(cast<Node>(S), SDK);
4251#define ABSTRACT_STMT(Node)
4252#define EXPR(Node, Parent)
4253#include "clang/AST/StmtNodes.inc"
4254
4255 // Transform expressions by calling TransformExpr.
4256#define STMT(Node, Parent)
4257#define ABSTRACT_STMT(Stmt)
4258#define EXPR(Node, Parent) case Stmt::Node##Class:
4259#include "clang/AST/StmtNodes.inc"
4260 {
4261 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4262
4263 if (SDK == SDK_StmtExprResult)
4264 E = getSema().ActOnStmtExprResult(E);
4265 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
4266 }
4267 }
4268
4269 return S;
4270}
4271
4272template<typename Derived>
4274 if (!S)
4275 return S;
4276
4277 switch (S->getClauseKind()) {
4278 default: break;
4279 // Transform individual clause nodes
4280#define GEN_CLANG_CLAUSE_CLASS
4281#define CLAUSE_CLASS(Enum, Str, Class) \
4282 case Enum: \
4283 return getDerived().Transform##Class(cast<Class>(S));
4284#include "llvm/Frontend/OpenMP/OMP.inc"
4285 }
4286
4287 return S;
4288}
4289
4290
4291template<typename Derived>
4293 if (!E)
4294 return E;
4295
4296 switch (E->getStmtClass()) {
4297 case Stmt::NoStmtClass: break;
4298#define STMT(Node, Parent) case Stmt::Node##Class: break;
4299#define ABSTRACT_STMT(Stmt)
4300#define EXPR(Node, Parent) \
4301 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4302#include "clang/AST/StmtNodes.inc"
4303 }
4304
4305 return E;
4306}
4307
4308template<typename Derived>
4310 bool NotCopyInit) {
4311 // Initializers are instantiated like expressions, except that various outer
4312 // layers are stripped.
4313 if (!Init)
4314 return Init;
4315
4316 if (auto *FE = dyn_cast<FullExpr>(Init))
4317 Init = FE->getSubExpr();
4318
4319 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4320 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4321 Init = OVE->getSourceExpr();
4322 }
4323
4324 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4325 Init = MTE->getSubExpr();
4326
4327 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4328 Init = Binder->getSubExpr();
4329
4330 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4331 Init = ICE->getSubExprAsWritten();
4332
4333 if (CXXStdInitializerListExpr *ILE =
4334 dyn_cast<CXXStdInitializerListExpr>(Init))
4335 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4336
4337 // If this is copy-initialization, we only need to reconstruct
4338 // InitListExprs. Other forms of copy-initialization will be a no-op if
4339 // the initializer is already the right type.
4340 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4341 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4342 return getDerived().TransformExpr(Init);
4343
4344 // Revert value-initialization back to empty parens.
4345 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4346 SourceRange Parens = VIE->getSourceRange();
4347 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4348 Parens.getEnd());
4349 }
4350
4351 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4352 if (isa<ImplicitValueInitExpr>(Init))
4353 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4354 SourceLocation());
4355
4356 // Revert initialization by constructor back to a parenthesized or braced list
4357 // of expressions. Any other form of initializer can just be reused directly.
4358 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4359 return getDerived().TransformExpr(Init);
4360
4361 // If the initialization implicitly converted an initializer list to a
4362 // std::initializer_list object, unwrap the std::initializer_list too.
4363 if (Construct && Construct->isStdInitListInitialization())
4364 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4365
4366 // Enter a list-init context if this was list initialization.
4369 Construct->isListInitialization());
4370
4371 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4372 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4373 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4374 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4375 SmallVector<Expr*, 8> NewArgs;
4376 bool ArgChanged = false;
4377 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4378 /*IsCall*/true, NewArgs, &ArgChanged))
4379 return ExprError();
4380
4381 // If this was list initialization, revert to syntactic list form.
4382 if (Construct->isListInitialization())
4383 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4384 Construct->getEndLoc());
4385
4386 // Build a ParenListExpr to represent anything else.
4388 if (Parens.isInvalid()) {
4389 // This was a variable declaration's initialization for which no initializer
4390 // was specified.
4391 assert(NewArgs.empty() &&
4392 "no parens or braces but have direct init with arguments?");
4393 return ExprEmpty();
4394 }
4395 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4396 Parens.getEnd());
4397}
4398
4399template<typename Derived>
4401 unsigned NumInputs,
4402 bool IsCall,
4403 SmallVectorImpl<Expr *> &Outputs,
4404 bool *ArgChanged) {
4405 for (unsigned I = 0; I != NumInputs; ++I) {
4406 // If requested, drop call arguments that need to be dropped.
4407 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4408 if (ArgChanged)
4409 *ArgChanged = true;
4410
4411 break;
4412 }
4413
4414 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4415 Expr *Pattern = Expansion->getPattern();
4416
4418 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4419 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4420
4421 // Determine whether the set of unexpanded parameter packs can and should
4422 // be expanded.
4423 bool Expand = true;
4424 bool RetainExpansion = false;
4425 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4426 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4427 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4428 Pattern->getSourceRange(),
4429 Unexpanded,
4430 Expand, RetainExpansion,
4431 NumExpansions))
4432 return true;
4433
4434 if (!Expand) {
4435 // The transform has determined that we should perform a simple
4436 // transformation on the pack expansion, producing another pack
4437 // expansion.
4438 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4439 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4440 if (OutPattern.isInvalid())
4441 return true;
4442
4443 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4444 Expansion->getEllipsisLoc(),
4445 NumExpansions);
4446 if (Out.isInvalid())
4447 return true;
4448
4449 if (ArgChanged)
4450 *ArgChanged = true;
4451 Outputs.push_back(Out.get());
4452 continue;
4453 }
4454
4455 // Record right away that the argument was changed. This needs
4456 // to happen even if the array expands to nothing.
4457 if (ArgChanged) *ArgChanged = true;
4458
4459 // The transform has determined that we should perform an elementwise
4460 // expansion of the pattern. Do so.
4461 for (unsigned I = 0; I != *NumExpansions; ++I) {
4462 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4463 ExprResult Out = getDerived().TransformExpr(Pattern);
4464 if (Out.isInvalid())
4465 return true;
4466
4467 if (Out.get()->containsUnexpandedParameterPack()) {
4468 Out = getDerived().RebuildPackExpansion(
4469 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4470 if (Out.isInvalid())
4471 return true;
4472 }
4473
4474 Outputs.push_back(Out.get());
4475 }
4476
4477 // If we're supposed to retain a pack expansion, do so by temporarily
4478 // forgetting the partially-substituted parameter pack.
4479 if (RetainExpansion) {
4480 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4481
4482 ExprResult Out = getDerived().TransformExpr(Pattern);
4483 if (Out.isInvalid())
4484 return true;
4485
4486 Out = getDerived().RebuildPackExpansion(
4487 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4488 if (Out.isInvalid())
4489 return true;
4490
4491 Outputs.push_back(Out.get());
4492 }
4493
4494 continue;
4495 }
4496
4498 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4499 : getDerived().TransformExpr(Inputs[I]);
4500 if (Result.isInvalid())
4501 return true;
4502
4503 if (Result.get() != Inputs[I] && ArgChanged)
4504 *ArgChanged = true;
4505
4506 Outputs.push_back(Result.get());
4507 }
4508
4509 return false;
4510}
4511
4512template <typename Derived>
4515 if (Var) {
4516 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4517 getDerived().TransformDefinition(Var->getLocation(), Var));
4518
4519 if (!ConditionVar)
4520 return Sema::ConditionError();
4521
4522 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4523 }
4524
4525 if (Expr) {
4526 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4527
4528 if (CondExpr.isInvalid())
4529 return Sema::ConditionError();
4530
4531 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4532 /*MissingOK=*/true);
4533 }
4534
4535 return Sema::ConditionResult();
4536}
4537
4538template <typename Derived>
4540 NestedNameSpecifierLoc NNS, QualType ObjectType,
4541 NamedDecl *FirstQualifierInScope) {
4543
4544 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4545 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4546 Qualifier = Qualifier.getPrefix())
4547 Qualifiers.push_back(Qualifier);
4548 };
4549 insertNNS(NNS);
4550
4551 CXXScopeSpec SS;
4552 while (!Qualifiers.empty()) {
4553 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4555
4556 switch (QNNS->getKind()) {
4560 ObjectType);
4561 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4562 SS, FirstQualifierInScope, false))
4563 return NestedNameSpecifierLoc();
4564 break;
4565 }
4566
4568 NamespaceDecl *NS =
4569 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4570 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4571 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4572 break;
4573 }
4574
4576 NamespaceAliasDecl *Alias =
4577 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4579 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4580 Q.getLocalEndLoc());
4581 break;
4582 }
4583
4585 // There is no meaningful transformation that one could perform on the
4586 // global scope.
4587 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4588 break;
4589
4591 CXXRecordDecl *RD =
4592 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4593 SourceLocation(), QNNS->getAsRecordDecl()));
4594 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4595 break;
4596 }
4597
4600 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4601 FirstQualifierInScope, SS);
4602
4603 if (!TL)
4604 return NestedNameSpecifierLoc();
4605
4606 QualType T = TL.getType();
4607 if (T->isDependentType() || T->isRecordType() ||
4608 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4609 if (T->isEnumeralType())
4610 SemaRef.Diag(TL.getBeginLoc(),
4611 diag::warn_cxx98_compat_enum_nested_name_spec);
4612
4613 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) {
4614 SS.Adopt(ETL.getQualifierLoc());
4615 TL = ETL.getNamedTypeLoc();
4616 }
4617
4618 SS.Extend(SemaRef.Context, TL.getTemplateKeywordLoc(), TL,
4619 Q.getLocalEndLoc());
4620 break;
4621 }
4622 // If the nested-name-specifier is an invalid type def, don't emit an
4623 // error because a previous error should have already been emitted.
4625 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4626 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4627 << T << SS.getRange();
4628 }
4629 return NestedNameSpecifierLoc();
4630 }
4631 }
4632
4633 // The qualifier-in-scope and object type only apply to the leftmost entity.
4634 FirstQualifierInScope = nullptr;
4635 ObjectType = QualType();
4636 }
4637
4638 // Don't rebuild the nested-name-specifier if we don't have to.
4639 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4640 !getDerived().AlwaysRebuild())
4641 return NNS;
4642
4643 // If we can re-use the source-location data from the original
4644 // nested-name-specifier, do so.
4645 if (SS.location_size() == NNS.getDataLength() &&
4646 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4648
4649 // Allocate new nested-name-specifier location information.
4650 return SS.getWithLocInContext(SemaRef.Context);
4651}
4652
4653template<typename Derived>
4657 DeclarationName Name = NameInfo.getName();
4658 if (!Name)
4659 return DeclarationNameInfo();
4660
4661 switch (Name.getNameKind()) {
4669 return NameInfo;
4670
4672 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4673 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4674 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4675 if (!NewTemplate)
4676 return DeclarationNameInfo();
4677
4678 DeclarationNameInfo NewNameInfo(NameInfo);
4679 NewNameInfo.setName(
4681 return NewNameInfo;
4682 }
4683
4687 TypeSourceInfo *NewTInfo;
4688 CanQualType NewCanTy;
4689 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4690 NewTInfo = getDerived().TransformType(OldTInfo);
4691 if (!NewTInfo)
4692 return DeclarationNameInfo();
4693 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4694 }
4695 else {
4696 NewTInfo = nullptr;
4697 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4698 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4699 if (NewT.isNull())
4700 return DeclarationNameInfo();
4701 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4702 }
4703
4704 DeclarationName NewName
4705 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4706 NewCanTy);
4707 DeclarationNameInfo NewNameInfo(NameInfo);
4708 NewNameInfo.setName(NewName);
4709 NewNameInfo.setNamedTypeInfo(NewTInfo);
4710 return NewNameInfo;
4711 }
4712 }
4713
4714 llvm_unreachable("Unknown name kind.");
4715}
4716
4717template<typename Derived>
4720 TemplateName Name,
4721 SourceLocation NameLoc,
4722 QualType ObjectType,
4723 NamedDecl *FirstQualifierInScope,
4724 bool AllowInjectedClassName) {
4725 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4726 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
4727 assert(Template && "qualified template name must refer to a template");
4728
4729 TemplateDecl *TransTemplate
4730 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4731 Template));
4732 if (!TransTemplate)
4733 return TemplateName();
4734
4735 if (!getDerived().AlwaysRebuild() &&
4736 SS.getScopeRep() == QTN->getQualifier() &&
4737 TransTemplate == Template)
4738 return Name;
4739
4740 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4741 TransTemplate);
4742 }
4743
4744 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4745 if (SS.getScopeRep()) {
4746 // These apply to the scope specifier, not the template.
4747 ObjectType = QualType();
4748 FirstQualifierInScope = nullptr;
4749 }
4750
4751 if (!getDerived().AlwaysRebuild() &&
4752 SS.getScopeRep() == DTN->getQualifier() &&
4753 ObjectType.isNull())
4754 return Name;
4755
4756 // FIXME: Preserve the location of the "template" keyword.
4757 SourceLocation TemplateKWLoc = NameLoc;
4758
4759 if (DTN->isIdentifier()) {
4760 return getDerived().RebuildTemplateName(SS,
4761 TemplateKWLoc,
4762 *DTN->getIdentifier(),
4763 NameLoc,
4764 ObjectType,
4765 FirstQualifierInScope,
4766 AllowInjectedClassName);
4767 }
4768
4769 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4770 DTN->getOperator(), NameLoc,
4771 ObjectType, AllowInjectedClassName);
4772 }
4773
4774 // FIXME: Try to preserve more of the TemplateName.
4775 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4776 TemplateDecl *TransTemplate
4777 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4778 Template));
4779 if (!TransTemplate)
4780 return TemplateName();
4781
4782 return getDerived().RebuildTemplateName(SS, /*TemplateKeyword=*/false,
4783 TransTemplate);
4784 }
4785
4787 = Name.getAsSubstTemplateTemplateParmPack()) {
4788 return getDerived().RebuildTemplateName(
4789 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4790 SubstPack->getIndex(), SubstPack->getFinal());
4791 }
4792
4793 // These should be getting filtered out before they reach the AST.
4794 llvm_unreachable("overloaded function decl survived to here");
4795}
4796
4797template<typename Derived>
4799 const TemplateArgument &Arg,
4800 TemplateArgumentLoc &Output) {
4801 Output = getSema().getTrivialTemplateArgumentLoc(
4802 Arg, QualType(), getDerived().getBaseLocation());
4803}
4804
4805template <typename Derived>
4807 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4808 bool Uneval) {
4809 const TemplateArgument &Arg = Input.getArgument();
4810 switch (Arg.getKind()) {
4813 llvm_unreachable("Unexpected TemplateArgument");
4814
4819 // Transform a resolved template argument straight to a resolved template
4820 // argument. We get here when substituting into an already-substituted
4821 // template type argument during concept satisfaction checking.
4823 QualType NewT = getDerived().TransformType(T);
4824 if (NewT.isNull())
4825 return true;
4826
4828 ? Arg.getAsDecl()
4829 : nullptr;
4830 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4831 getDerived().getBaseLocation(), D))
4832 : nullptr;
4833 if (D && !NewD)
4834 return true;
4835
4836 if (NewT == T && D == NewD)
4837 Output = Input;
4838 else if (Arg.getKind() == TemplateArgument::Integral)
4839 Output = TemplateArgumentLoc(
4840 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4842 else if (Arg.getKind() == TemplateArgument::NullPtr)
4843 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4845 else if (Arg.getKind() == TemplateArgument::Declaration)
4846 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4849 Output = TemplateArgumentLoc(
4850 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4852 else
4853 llvm_unreachable("unexpected template argument kind");
4854
4855 return false;
4856 }
4857
4859 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4860 if (!DI)
4861 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4862
4863 DI = getDerived().TransformType(DI);
4864 if (!DI)
4865 return true;
4866
4867 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4868 return false;
4869 }
4870
4872 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4873 if (QualifierLoc) {
4874 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4875 if (!QualifierLoc)
4876 return true;
4877 }
4878
4879 CXXScopeSpec SS;
4880 SS.Adopt(QualifierLoc);
4881 TemplateName Template = getDerived().TransformTemplateName(
4882 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4883 if (Template.isNull())
4884 return true;
4885
4886 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4887 QualifierLoc, Input.getTemplateNameLoc());
4888 return false;
4889 }
4890
4892 llvm_unreachable("Caller should expand pack expansions");
4893
4895 // Template argument expressions are constant expressions.
4897 getSema(),
4900 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
4902
4903 Expr *InputExpr = Input.getSourceExpression();
4904 if (!InputExpr)
4905 InputExpr = Input.getArgument().getAsExpr();
4906
4907 ExprResult E = getDerived().TransformExpr(InputExpr);
4908 E = SemaRef.ActOnConstantExpression(E);
4909 if (E.isInvalid())
4910 return true;
4911 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4912 return false;
4913 }
4914 }
4915
4916 // Work around bogus GCC warning
4917 return true;
4918}
4919
4920/// Iterator adaptor that invents template argument location information
4921/// for each of the template arguments in its underlying iterator.
4922template<typename Derived, typename InputIterator>
4925 InputIterator Iter;
4926
4927public:
4930 typedef typename std::iterator_traits<InputIterator>::difference_type
4932 typedef std::input_iterator_tag iterator_category;
4933
4934 class pointer {
4936
4937 public:
4938 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4939
4940 const TemplateArgumentLoc *operator->() const { return &Arg; }
4941 };
4942
4944 InputIterator Iter)
4945 : Self(Self), Iter(Iter) { }
4946
4948 ++Iter;
4949 return *this;
4950 }
4951
4954 ++(*this);
4955 return Old;
4956 }
4957
4960 Self.InventTemplateArgumentLoc(*Iter, Result);
4961 return Result;
4962 }
4963
4964 pointer operator->() const { return pointer(**this); }
4965
4968 return X.Iter == Y.Iter;
4969 }
4970
4973 return X.Iter != Y.Iter;
4974 }
4975};
4976
4977template<typename Derived>
4978template<typename InputIterator>
4980 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4981 bool Uneval) {
4982 for (; First != Last; ++First) {
4985
4986 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4987 // Unpack argument packs, which we translate them into separate
4988 // arguments.
4989 // FIXME: We could do much better if we could guarantee that the
4990 // TemplateArgumentLocInfo for the pack expansion would be usable for
4991 // all of the template arguments in the argument pack.
4992 typedef TemplateArgumentLocInventIterator<Derived,
4994 PackLocIterator;
4995 if (TransformTemplateArguments(PackLocIterator(*this,
4996 In.getArgument().pack_begin()),
4997 PackLocIterator(*this,
4998 In.getArgument().pack_end()),
4999 Outputs, Uneval))
5000 return true;
5001
5002 continue;
5003 }
5004
5005 if (In.getArgument().isPackExpansion()) {
5006 // We have a pack expansion, for which we will be substituting into
5007 // the pattern.
5008 SourceLocation Ellipsis;
5009 std::optional<unsigned> OrigNumExpansions;
5010 TemplateArgumentLoc Pattern
5011 = getSema().getTemplateArgumentPackExpansionPattern(
5012 In, Ellipsis, OrigNumExpansions);
5013
5015 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5016 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5017
5018 // Determine whether the set of unexpanded parameter packs can and should
5019 // be expanded.
5020 bool Expand = true;
5021 bool RetainExpansion = false;
5022 std::optional<unsigned> NumExpansions = OrigNumExpansions;
5023 if (getDerived().TryExpandParameterPacks(Ellipsis,
5024 Pattern.getSourceRange(),
5025 Unexpanded,
5026 Expand,
5027 RetainExpansion,
5028 NumExpansions))
5029 return true;
5030
5031 if (!Expand) {
5032 // The transform has determined that we should perform a simple
5033 // transformation on the pack expansion, producing another pack
5034 // expansion.
5035 TemplateArgumentLoc OutPattern;
5036 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5037 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5038 return true;
5039
5040 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
5041 NumExpansions);
5042 if (Out.getArgument().isNull())
5043 return true;
5044
5045 Outputs.addArgument(Out);
5046 continue;
5047 }
5048
5049 // The transform has determined that we should perform an elementwise
5050 // expansion of the pattern. Do so.
5051 for (unsigned I = 0; I != *NumExpansions; ++I) {
5052 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5053
5054 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5055 return true;
5056
5057 if (Out.getArgument().containsUnexpandedParameterPack()) {
5058 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5059 OrigNumExpansions);
5060 if (Out.getArgument().isNull())
5061 return true;
5062 }
5063
5064 Outputs.addArgument(Out);
5065 }
5066
5067 // If we're supposed to retain a pack expansion, do so by temporarily
5068 // forgetting the partially-substituted parameter pack.
5069 if (RetainExpansion) {
5070 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5071
5072 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5073 return true;
5074
5075 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5076 OrigNumExpansions);
5077 if (Out.getArgument().isNull())
5078 return true;
5079
5080 Outputs.addArgument(Out);
5081 }
5082
5083 continue;
5084 }
5085
5086 // The simple case:
5087 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5088 return true;
5089
5090 Outputs.addArgument(Out);
5091 }
5092
5093 return false;
5094
5095}
5096
5097//===----------------------------------------------------------------------===//
5098// Type transformation
5099//===----------------------------------------------------------------------===//
5100
5101template<typename Derived>
5103 if (getDerived().AlreadyTransformed(T))
5104 return T;
5105
5106 // Temporary workaround. All of these transformations should
5107 // eventually turn into transformations on TypeLocs.
5108 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5109 getDerived().getBaseLocation());
5110
5111 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
5112
5113 if (!NewDI)
5114 return QualType();
5115
5116 return NewDI->getType();
5117}
5118
5119template<typename Derived>
5121 // Refine the base location to the type's location.
5122 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5123 getDerived().getBaseEntity());
5124 if (getDerived().AlreadyTransformed(DI->getType()))
5125 return DI;
5126
5127 TypeLocBuilder TLB;
5128
5129 TypeLoc TL = DI->getTypeLoc();
5130 TLB.reserve(TL.getFullDataSize());
5131
5132 QualType Result = getDerived().TransformType(TLB, TL);
5133 if (Result.isNull())
5134 return nullptr;
5135
5136 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5137}
5138
5139template<typename Derived>
5142 switch (T.getTypeLocClass()) {
5143#define ABSTRACT_TYPELOC(CLASS, PARENT)
5144#define TYPELOC(CLASS, PARENT) \
5145 case TypeLoc::CLASS: \
5146 return getDerived().Transform##CLASS##Type(TLB, \
5147 T.castAs<CLASS##TypeLoc>());
5148#include "clang/AST/TypeLocNodes.def"
5149 }
5150
5151 llvm_unreachable("unhandled type loc!");
5152}
5153
5154template<typename Derived>
5156 if (!isa<DependentNameType>(T))
5157 return TransformType(T);
5158
5159 if (getDerived().AlreadyTransformed(T))
5160 return T;
5161 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5162 getDerived().getBaseLocation());
5163 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5164 return NewDI ? NewDI->getType() : QualType();
5165}
5166
5167template<typename Derived>
5170 if (!isa<DependentNameType>(DI->getType()))
5171 return TransformType(DI);
5172
5173 // Refine the base location to the type's location.
5174 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5175 getDerived().getBaseEntity());
5176 if (getDerived().AlreadyTransformed(DI->getType()))
5177 return DI;
5178
5179 TypeLocBuilder TLB;
5180
5181 TypeLoc TL = DI->getTypeLoc();
5182 TLB.reserve(TL.getFullDataSize());
5183
5184 auto QTL = TL.getAs<QualifiedTypeLoc>();
5185 if (QTL)
5186 TL = QTL.getUnqualifiedLoc();
5187
5188 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5189
5190 QualType Result = getDerived().TransformDependentNameType(
5191 TLB, DNTL, /*DeducedTSTContext*/true);
5192 if (Result.isNull())
5193 return nullptr;
5194
5195 if (QTL) {
5196 Result = getDerived().RebuildQualifiedType(Result, QTL);
5197 if (Result.isNull())
5198 return nullptr;
5200 }
5201
5202 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5203}
5204
5205template<typename Derived>
5210 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5211 auto SuppressObjCLifetime =
5212 T.getType().getLocalQualifiers().hasObjCLifetime();
5213 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5214 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5215 SuppressObjCLifetime);
5216 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5217 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5218 TLB, STTP, SuppressObjCLifetime);
5219 } else {
5220 Result = getDerived().TransformType(TLB, UnqualTL);
5221 }
5222
5223 if (Result.isNull())
5224 return QualType();
5225
5226 Result = getDerived().RebuildQualifiedType(Result, T);
5227
5228 if (Result.isNull())
5229 return QualType();
5230
5231 // RebuildQualifiedType might have updated the type, but not in a way
5232 // that invalidates the TypeLoc. (There's no location information for
5233 // qualifiers.)
5235
5236 return Result;
5237}
5238
5239template <typename Derived>
5241 QualifiedTypeLoc TL) {
5242
5244 Qualifiers Quals = TL.getType().getLocalQualifiers();
5245
5246 if ((T.getAddressSpace() != LangAS::Default &&
5247 Quals.getAddressSpace() != LangAS::Default) &&
5248 T.getAddressSpace() != Quals.getAddressSpace()) {
5249 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5250 << TL.getType() << T;
5251 return QualType();
5252 }
5253
5254 // C++ [dcl.fct]p7:
5255 // [When] adding cv-qualifications on top of the function type [...] the
5256 // cv-qualifiers are ignored.
5257 if (T->isFunctionType()) {
5259 Quals.getAddressSpace());
5260 return T;
5261 }
5262
5263 // C++ [dcl.ref]p1:
5264 // when the cv-qualifiers are introduced through the use of a typedef-name
5265 // or decltype-specifier [...] the cv-qualifiers are ignored.
5266 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5267 // applied to a reference type.
5268 if (T->isReferenceType()) {
5269 // The only qualifier that applies to a reference type is restrict.
5270 if (!Quals.hasRestrict())
5271 return T;
5273 }
5274
5275 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5276 // resulting type.
5277 if (Quals.hasObjCLifetime()) {
5278 if (!T->isObjCLifetimeType() && !T->isDependentType())
5279 Quals.removeObjCLifetime();
5280 else if (T.getObjCLifetime()) {
5281 // Objective-C ARC:
5282 // A lifetime qualifier applied to a substituted template parameter
5283 // overrides the lifetime qualifier from the template argument.
5284 const AutoType *AutoTy;
5285 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5286 // 'auto' types behave the same way as template parameters.
5287 QualType Deduced = AutoTy->getDeducedType();
5288 Qualifiers Qs = Deduced.getQualifiers();
5289 Qs.removeObjCLifetime();
5290 Deduced =
5291 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5292 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5293 AutoTy->isDependentType(),
5294 /*isPack=*/false,
5295 AutoTy->getTypeConstraintConcept(),
5296 AutoTy->getTypeConstraintArguments());
5297 } else {
5298 // Otherwise, complain about the addition of a qualifier to an
5299 // already-qualified type.
5300 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5301 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5302 Quals.removeObjCLifetime();
5303 }
5304 }
5305 }
5306
5307 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5308}
5309
5310template<typename Derived>
5311TypeLoc
5313 QualType ObjectType,
5314 NamedDecl *UnqualLookup,
5315 CXXScopeSpec &SS) {
5316 if (getDerived().AlreadyTransformed(TL.getType()))
5317 return TL;
5318
5319 TypeSourceInfo *TSI =
5320 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
5321 if (TSI)
5322 return TSI->getTypeLoc();
5323 return TypeLoc();
5324}
5325
5326template<typename Derived>
5327TypeSourceInfo *
5328TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
5329 QualType ObjectType,
5330 NamedDecl *UnqualLookup,
5331 CXXScopeSpec &SS) {
5332 if (getDerived().AlreadyTransformed(TSInfo->getType()))
5333 return TSInfo;
5334
5335 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
5336 UnqualLookup, SS);
5337}
5338
5339template <typename Derived>
5340TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
5341 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
5342 CXXScopeSpec &SS) {
5343 QualType T = TL.getType();
5344 assert(!getDerived().AlreadyTransformed(T));
5345
5346 TypeLocBuilder TLB;
5347 QualType Result;
5348
5349 if (isa<TemplateSpecializationType>(T)) {
5350 TemplateSpecializationTypeLoc SpecTL =
5351 TL.castAs<TemplateSpecializationTypeLoc>();
5352
5353 TemplateName Template = getDerived().TransformTemplateName(
5354 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
5355 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
5356 if (Template.isNull())
5357 return nullptr;
5358
5359 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
5360 Template);
5361 } else if (isa<DependentTemplateSpecializationType>(T)) {
5362 DependentTemplateSpecializationTypeLoc SpecTL =
5363 TL.castAs<DependentTemplateSpecializationTypeLoc>();
5364
5365 TemplateName Template
5366 = getDerived().RebuildTemplateName(SS,
5367 SpecTL.getTemplateKeywordLoc(),
5368 *SpecTL.getTypePtr()->getIdentifier(),
5369 SpecTL.getTemplateNameLoc(),
5370 ObjectType, UnqualLookup,
5371 /*AllowInjectedClassName*/true);
5372 if (Template.isNull())
5373 return nullptr;
5374
5375 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
5376 SpecTL,
5377 Template,
5378 SS);
5379 } else {
5380 // Nothing special needs to be done for these.
5381 Result = getDerived().TransformType(TLB, TL);
5382 }
5383
5384 if (Result.isNull())
5385 return nullptr;
5386
5387 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5388}
5389
5390template <class TyLoc> static inline
5392 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5393 NewT.setNameLoc(T.getNameLoc());
5394 return T.getType();
5395}
5396
5397template<typename Derived>
5398QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5399 BuiltinTypeLoc T) {
5400 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5401 NewT.setBuiltinLoc(T.getBuiltinLoc());
5402 if (T.needsExtraLocalData())
5403 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5404 return T.getType();
5405}
5406
5407template<typename Derived>
5408QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
5409 ComplexTypeLoc T) {
5410 // FIXME: recurse?
5411 return TransformTypeSpecType(TLB, T);
5412}
5413
5414template <typename Derived>
5415QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
5416 AdjustedTypeLoc TL) {
5417 // Adjustments applied during transformation are handled elsewhere.
5418 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5419}
5420
5421template<typename Derived>
5422QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
5423 DecayedTypeLoc TL) {
5424 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5425 if (OriginalType.isNull())
5426 return QualType();
5427
5428 QualType Result = TL.getType();
5429 if (getDerived().AlwaysRebuild() ||
5430 OriginalType != TL.getOriginalLoc().getType())
5431 Result = SemaRef.Context.getDecayedType(OriginalType);
5432 TLB.push<DecayedTypeLoc>(Result);
5433 // Nothing to set for DecayedTypeLoc.
5434 return Result;
5435}
5436
5437template <typename Derived>
5438QualType
5439TreeTransform<Derived>::TransformArrayParameterType(TypeLocBuilder &TLB,
5440 ArrayParameterTypeLoc TL) {
5441 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5442 if (OriginalType.isNull())
5443 return QualType();
5444
5445 QualType Result = TL.getType();
5446 if (getDerived().AlwaysRebuild() ||
5447 OriginalType != TL.getElementLoc().getType())
5448 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5449 TLB.push<ArrayParameterTypeLoc>(Result);
5450 // Nothing to set for ArrayParameterTypeLoc.
5451 return Result;
5452}
5453
5454template<typename Derived>
5455QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
5456 PointerTypeLoc TL) {
5457 QualType PointeeType
5458 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5459 if (PointeeType.isNull())
5460 return QualType();
5461
5462 QualType Result = TL.getType();
5463 if (PointeeType->getAs<ObjCObjectType>()) {
5464 // A dependent pointer type 'T *' has is being transformed such
5465 // that an Objective-C class type is being replaced for 'T'. The
5466 // resulting pointer type is an ObjCObjectPointerType, not a
5467 // PointerType.
5468 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5469
5470 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5471 NewT.setStarLoc(TL.getStarLoc());
5472 return Result;
5473 }
5474
5475 if (getDerived().AlwaysRebuild() ||
5476 PointeeType != TL.getPointeeLoc().getType()) {
5477 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5478 if (Result.isNull())
5479 return QualType();
5480 }
5481
5482 // Objective-C ARC can add lifetime qualifiers to the type that we're
5483 // pointing to.
5484 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5485
5486 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5487 NewT.setSigilLoc(TL.getSigilLoc());
5488 return Result;
5489}
5490
5491template<typename Derived>
5492QualType
5493TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
5494 BlockPointerTypeLoc TL) {
5495 QualType PointeeType
5496 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5497 if (PointeeType.isNull())
5498 return QualType();
5499
5500 QualType Result = TL.getType();
5501 if (getDerived().AlwaysRebuild() ||
5502 PointeeType != TL.getPointeeLoc().getType()) {
5503 Result = getDerived().RebuildBlockPointerType(PointeeType,
5504 TL.getSigilLoc());
5505 if (Result.isNull())
5506 return QualType();
5507 }
5508
5509 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5510 NewT.setSigilLoc(TL.getSigilLoc());
5511 return Result;
5512}
5513
5514/// Transforms a reference type. Note that somewhat paradoxically we
5515/// don't care whether the type itself is an l-value type or an r-value
5516/// type; we only care if the type was *written* as an l-value type
5517/// or an r-value type.
5518template<typename Derived>
5519QualType
5521 ReferenceTypeLoc TL) {
5522 const ReferenceType *T = TL.getTypePtr();
5523
5524 // Note that this works with the pointee-as-written.
5525 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5526 if (PointeeType.isNull())
5527 return QualType();
5528
5529 QualType Result = TL.getType();
5530 if (getDerived().AlwaysRebuild() ||
5531 PointeeType != T->getPointeeTypeAsWritten()) {
5532 Result = getDerived().RebuildReferenceType(PointeeType,
5533 T->isSpelledAsLValue(),
5534 TL.getSigilLoc());
5535 if (Result.isNull())
5536 return QualType();
5537 }
5538
5539 // Objective-C ARC can add lifetime qualifiers to the type that we're
5540 // referring to.
5543
5544 // r-value references can be rebuilt as l-value references.
5545 ReferenceTypeLoc NewTL;
5546 if (isa<LValueReferenceType>(Result))
5547 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5548 else
5549 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5550 NewTL.setSigilLoc(TL.getSigilLoc());
5551
5552 return Result;
5553}
5554
5555template<typename Derived>
5559 return TransformReferenceType(TLB, TL);
5560}
5561
5562template<typename Derived>
5563QualType
5564TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5565 RValueReferenceTypeLoc TL) {
5566 return TransformReferenceType(TLB, TL);
5567}
5568
5569template<typename Derived>
5570QualType
5571TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5572 MemberPointerTypeLoc TL) {
5573 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5574 if (PointeeType.isNull())
5575 return QualType();
5576
5577 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
5578 TypeSourceInfo *NewClsTInfo = nullptr;
5579 if (OldClsTInfo) {
5580 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
5581 if (!NewClsTInfo)
5582 return QualType();
5583 }
5584
5585 const MemberPointerType *T = TL.getTypePtr();
5586 QualType OldClsType = QualType(T->getClass(), 0);
5587 QualType NewClsType;
5588 if (NewClsTInfo)
5589 NewClsType = NewClsTInfo->getType();
5590 else {
5591 NewClsType = getDerived().TransformType(OldClsType);
5592 if (NewClsType.isNull())
5593 return QualType();
5594 }
5595
5596 QualType Result = TL.getType();
5597 if (getDerived().AlwaysRebuild() ||
5598 PointeeType != T->getPointeeType() ||
5599 NewClsType != OldClsType) {
5600 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
5601 TL.getStarLoc());
5602 if (Result.isNull())
5603 return QualType();
5604 }
5605
5606 // If we had to adjust the pointee type when building a member pointer, make
5607 // sure to push TypeLoc info for it.
5608 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5609 if (MPT && PointeeType != MPT->getPointeeType()) {
5610 assert(isa<AdjustedType>(MPT->getPointeeType()));
5611 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5612 }
5613
5614 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
5615 NewTL.setSigilLoc(TL.getSigilLoc());
5616 NewTL.setClassTInfo(NewClsTInfo);
5617
5618 return Result;
5619}
5620
5621template<typename Derived>
5622QualType
5623TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
5624 ConstantArrayTypeLoc TL) {
5625 const ConstantArrayType *T = TL.getTypePtr();
5626 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5627 if (ElementType.isNull())
5628 return QualType();
5629
5630 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5631 Expr *OldSize = TL.getSizeExpr();
5632 if (!OldSize)
5633 OldSize = const_cast<Expr*>(T->getSizeExpr());
5634 Expr *NewSize = nullptr;
5635 if (OldSize) {
5636 EnterExpressionEvaluationContext Unevaluated(
5638 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5639 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5640 }
5641
5642 QualType Result = TL.getType();
5643 if (getDerived().AlwaysRebuild() ||
5644 ElementType != T->getElementType() ||
5645 (T->getSizeExpr() && NewSize != OldSize)) {
5646 Result = getDerived().RebuildConstantArrayType(ElementType,
5647 T->getSizeModifier(),
5648 T->getSize(), NewSize,
5649 T->getIndexTypeCVRQualifiers(),
5650 TL.getBracketsRange());
5651 if (Result.isNull())
5652 return QualType();
5653 }
5654
5655 // We might have either a ConstantArrayType or a VariableArrayType now:
5656 // a ConstantArrayType is allowed to have an element type which is a
5657 // VariableArrayType if the type is dependent. Fortunately, all array
5658 // types have the same location layout.
5659 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5660 NewTL.setLBracketLoc(TL.getLBracketLoc());
5661 NewTL.setRBracketLoc(TL.getRBracketLoc());
5662 NewTL.setSizeExpr(NewSize);
5663
5664 return Result;
5665}
5666
5667template<typename Derived>
5668QualType TreeTransform<Derived>::TransformIncompleteArrayType(
5669 TypeLocBuilder &TLB,
5670 IncompleteArrayTypeLoc TL) {
5671 const IncompleteArrayType *T = TL.getTypePtr();
5672 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5673 if (ElementType.isNull())
5674 return QualType();
5675
5676 QualType Result = TL.getType();
5677 if (getDerived().AlwaysRebuild() ||
5678 ElementType != T->getElementType()) {
5679 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5680 T->getSizeModifier(),
5681 T->getIndexTypeCVRQualifiers(),
5682 TL.getBracketsRange());
5683 if (Result.isNull())
5684 return QualType();
5685 }
5686
5687 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5688 NewTL.setLBracketLoc(TL.getLBracketLoc());
5689 NewTL.setRBracketLoc(TL.getRBracketLoc());
5690 NewTL.setSizeExpr(nullptr);
5691
5692 return Result;
5693}
5694
5695template<typename Derived>
5696QualType
5697TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
5698 VariableArrayTypeLoc TL) {
5699 const VariableArrayType *T = TL.getTypePtr();
5700 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5701 if (ElementType.isNull())
5702 return QualType();
5703
5704 ExprResult SizeResult;
5705 {
5706 EnterExpressionEvaluationContext Context(
5708 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5709 }
5710 if (SizeResult.isInvalid())
5711 return QualType();
5712 SizeResult =
5713 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5714 if (SizeResult.isInvalid())
5715 return QualType();
5716
5717 Expr *Size = SizeResult.get();
5718
5719 QualType Result = TL.getType();
5720 if (getDerived().AlwaysRebuild() ||
5721 ElementType != T->getElementType() ||
5722 Size != T->getSizeExpr()) {
5723 Result = getDerived().RebuildVariableArrayType(ElementType,
5724 T->getSizeModifier(),
5725 Size,
5726 T->getIndexTypeCVRQualifiers(),
5727 TL.getBracketsRange());
5728 if (Result.isNull())
5729 return QualType();
5730 }
5731
5732 // We might have constant size array now, but fortunately it has the same
5733 // location layout.
5734 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5735 NewTL.setLBracketLoc(TL.getLBracketLoc());
5736 NewTL.setRBracketLoc(TL.getRBracketLoc());
5737 NewTL.setSizeExpr(Size);
5738
5739 return Result;
5740}
5741
5742template<typename Derived>
5743QualType
5744TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
5745 DependentSizedArrayTypeLoc TL) {
5746 const DependentSizedArrayType *T = TL.getTypePtr();
5747 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5748 if (ElementType.isNull())
5749 return QualType();
5750
5751 // Array bounds are constant expressions.
5752 EnterExpressionEvaluationContext Unevaluated(
5754
5755 // If we have a VLA then it won't be a constant.
5756 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5757
5758 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5759 Expr *origSize = TL.getSizeExpr();
5760 if (!origSize) origSize = T->getSizeExpr();
5761
5762 ExprResult sizeResult
5763 = getDerived().TransformExpr(origSize);
5764 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5765 if (sizeResult.isInvalid())
5766 return QualType();
5767
5768 Expr *size = sizeResult.get();
5769
5770 QualType Result = TL.getType();
5771 if (getDerived().AlwaysRebuild() ||
5772 ElementType != T->getElementType() ||
5773 size != origSize) {
5774 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5775 T->getSizeModifier(),
5776 size,
5777 T->getIndexTypeCVRQualifiers(),
5778 TL.getBracketsRange());
5779 if (Result.isNull())
5780 return QualType();
5781 }
5782
5783 // We might have any sort of array type now, but fortunately they
5784 // all have the same location layout.
5785 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5786 NewTL.setLBracketLoc(TL.getLBracketLoc());
5787 NewTL.setRBracketLoc(TL.getRBracketLoc());
5788 NewTL.setSizeExpr(size);
5789
5790 return Result;
5791}
5792
5793template <typename Derived>
5794QualType TreeTransform<Derived>::TransformDependentVectorType(
5795 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
5796 const DependentVectorType *T = TL.getTypePtr();
5797 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5798 if (ElementType.isNull())
5799 return QualType();
5800
5801 EnterExpressionEvaluationContext Unevaluated(
5803
5804 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5805 Size = SemaRef.ActOnConstantExpression(Size);
5806 if (Size.isInvalid())
5807 return QualType();
5808
5809 QualType Result = TL.getType();
5810 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5811 Size.get() != T->getSizeExpr()) {
5812 Result = getDerived().RebuildDependentVectorType(
5813 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5814 if (Result.isNull())
5815 return QualType();
5816 }
5817
5818 // Result might be dependent or not.
5819 if (isa<DependentVectorType>(Result)) {
5820 DependentVectorTypeLoc NewTL =
5821 TLB.push<DependentVectorTypeLoc>(Result);
5822 NewTL.setNameLoc(TL.getNameLoc());
5823 } else {
5824 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5825 NewTL.setNameLoc(TL.getNameLoc());
5826 }
5827
5828 return Result;
5829}
5830
5831template<typename Derived>
5832QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
5833 TypeLocBuilder &TLB,
5834 DependentSizedExtVectorTypeLoc TL) {
5835 const DependentSizedExtVectorType *T = TL.getTypePtr();
5836
5837 // FIXME: ext vector locs should be nested
5838 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5839 if (ElementType.isNull())
5840 return QualType();
5841
5842 // Vector sizes are constant expressions.
5843 EnterExpressionEvaluationContext Unevaluated(
5845
5846 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5847 Size = SemaRef.ActOnConstantExpression(Size);
5848 if (Size.isInvalid())
5849 return QualType();
5850
5851 QualType Result = TL.getType();
5852 if (getDerived().AlwaysRebuild() ||
5853 ElementType != T->getElementType() ||
5854 Size.get() != T->getSizeExpr()) {
5855 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5856 Size.get(),
5857 T->getAttributeLoc());
5858 if (Result.isNull())
5859 return QualType();
5860 }
5861
5862 // Result might be dependent or not.
5863 if (isa<DependentSizedExtVectorType>(Result)) {
5864 DependentSizedExtVectorTypeLoc NewTL
5865 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
5866 NewTL.setNameLoc(TL.getNameLoc());
5867 } else {
5868 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5869 NewTL.setNameLoc(TL.getNameLoc());
5870 }
5871
5872 return Result;
5873}
5874
5875template <typename Derived>
5876QualType
5877TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
5878 ConstantMatrixTypeLoc TL) {
5879 const ConstantMatrixType *T = TL.getTypePtr();
5880 QualType ElementType = getDerived().TransformType(T->getElementType());
5881 if (ElementType.isNull())
5882 return QualType();
5883
5884 QualType Result = TL.getType();
5885 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
5886 Result = getDerived().RebuildConstantMatrixType(
5887 ElementType, T->getNumRows(), T->getNumColumns());
5888 if (Result.isNull())
5889 return QualType();
5890 }
5891
5892 ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
5893 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5894 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5895 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
5896 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
5897
5898 return Result;
5899}
5900
5901template <typename Derived>
5902QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
5903 TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
5904 const DependentSizedMatrixType *T = TL.getTypePtr();
5905
5906 QualType ElementType = getDerived().TransformType(T->getElementType());
5907 if (ElementType.isNull()) {
5908 return QualType();
5909 }
5910
5911 // Matrix dimensions are constant expressions.
5912 EnterExpressionEvaluationContext Unevaluated(
5914
5915 Expr *origRows = TL.getAttrRowOperand();
5916 if (!origRows)
5917 origRows = T->getRowExpr();
5918 Expr *origColumns = TL.getAttrColumnOperand();
5919 if (!origColumns)
5920 origColumns = T->getColumnExpr();
5921
5922 ExprResult rowResult = getDerived().TransformExpr(origRows);
5923 rowResult = SemaRef.ActOnConstantExpression(rowResult);
5924 if (rowResult.isInvalid())
5925 return QualType();
5926
5927 ExprResult columnResult = getDerived().TransformExpr(origColumns);
5928 columnResult = SemaRef.ActOnConstantExpression(columnResult);
5929 if (columnResult.isInvalid())
5930 return QualType();
5931
5932 Expr *rows = rowResult.get();
5933 Expr *columns = columnResult.get();
5934
5935 QualType Result = TL.getType();
5936 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5937 rows != origRows || columns != origColumns) {
5938 Result = getDerived().RebuildDependentSizedMatrixType(
5939 ElementType, rows, columns, T->getAttributeLoc());
5940
5941 if (Result.isNull())
5942 return QualType();
5943 }
5944
5945 // We might have any sort of matrix type now, but fortunately they
5946 // all have the same location layout.
5947 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
5948 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5949 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5950 NewTL.setAttrRowOperand(rows);
5951 NewTL.setAttrColumnOperand(columns);
5952 return Result;
5953}
5954
5955template <typename Derived>
5956QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
5957 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
5958 const DependentAddressSpaceType *T = TL.getTypePtr();
5959
5960 QualType pointeeType =
5961 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
5962
5963 if (pointeeType.isNull())
5964 return QualType();
5965
5966 // Address spaces are constant expressions.
5967 EnterExpressionEvaluationContext Unevaluated(
5969
5970 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
5971 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
5972 if (AddrSpace.isInvalid())
5973 return QualType();
5974
5975 QualType Result = TL.getType();
5976 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
5977 AddrSpace.get() != T->getAddrSpaceExpr()) {
5978 Result = getDerived().RebuildDependentAddressSpaceType(
5979 pointeeType, AddrSpace.get(), T->getAttributeLoc());
5980 if (Result.isNull())
5981 return QualType();
5982 }
5983
5984 // Result might be dependent or not.
5985 if (isa<DependentAddressSpaceType>(Result)) {
5986 DependentAddressSpaceTypeLoc NewTL =
5987 TLB.push<DependentAddressSpaceTypeLoc>(Result);
5988
5989 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5990 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5991 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5992
5993 } else {
5994 TLB.TypeWasModifiedSafely(Result);
5995 }
5996
5997 return Result;
5998}
5999
6000template <typename Derived>
6001QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
6002 VectorTypeLoc TL) {
6003 const VectorType *T = TL.getTypePtr();
6004 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6005 if (ElementType.isNull())
6006 return QualType();
6007
6008 QualType Result = TL.getType();
6009 if (getDerived().AlwaysRebuild() ||
6010 ElementType != T->getElementType()) {
6011 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6012 T->getVectorKind());
6013 if (Result.isNull())
6014 return QualType();
6015 }
6016
6017 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6018 NewTL.setNameLoc(TL.getNameLoc());
6019
6020 return Result;
6021}
6022
6023template<typename Derived>
6024QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
6025 ExtVectorTypeLoc TL) {
6026 const VectorType *T = TL.getTypePtr();
6027 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6028 if (ElementType.isNull())
6029 return QualType();
6030
6031 QualType Result = TL.getType();
6032 if (getDerived().AlwaysRebuild() ||
6033 ElementType != T->getElementType()) {
6034 Result = getDerived().RebuildExtVectorType(ElementType,
6035 T->getNumElements(),
6036 /*FIXME*/ SourceLocation());
6037 if (Result.isNull())
6038 return QualType();
6039 }
6040
6041 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6042 NewTL.setNameLoc(TL.getNameLoc());
6043
6044 return Result;
6045}
6046
6047template <typename Derived>
6049 ParmVarDecl *OldParm, int indexAdjustment,
6050 std::optional<unsigned> NumExpansions, bool ExpectParameterPack) {
6051 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
6052 TypeSourceInfo *NewDI = nullptr;
6053
6054 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
6055 // If we're substituting into a pack expansion type and we know the
6056 // length we want to expand to, just substitute for the pattern.
6057 TypeLoc OldTL = OldDI->getTypeLoc();
6058 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6059
6060 TypeLocBuilder TLB;
6061 TypeLoc NewTL = OldDI->getTypeLoc();
6062 TLB.reserve(NewTL.getFullDataSize());
6063
6064 QualType Result = getDerived().TransformType(TLB,
6065 OldExpansionTL.getPatternLoc());
6066 if (Result.isNull())
6067 return nullptr;
6068
6069 Result = RebuildPackExpansionType(Result,
6070 OldExpansionTL.getPatternLoc().getSourceRange(),
6071 OldExpansionTL.getEllipsisLoc(),
6072 NumExpansions);
6073 if (Result.isNull())
6074 return nullptr;
6075
6076 PackExpansionTypeLoc NewExpansionTL
6077 = TLB.push<PackExpansionTypeLoc>(Result);
6078 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6079 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6080 } else
6081 NewDI = getDerived().TransformType(OldDI);
6082 if (!NewDI)
6083 return nullptr;
6084
6085 if (NewDI == OldDI && indexAdjustment == 0)
6086 return OldParm;
6087
6088 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
6089 OldParm->getDeclContext(),
6090 OldParm->getInnerLocStart(),
6091 OldParm->getLocation(),
6092 OldParm->getIdentifier(),
6093 NewDI->getType(),
6094 NewDI,
6095 OldParm->getStorageClass(),
6096 /* DefArg */ nullptr);
6097 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6098 OldParm->getFunctionScopeIndex() + indexAdjustment);
6099 transformedLocalDecl(OldParm, {newParm});
6100 return newParm;
6101}
6102
6103template <typename Derived>
6106 const QualType *ParamTypes,
6107 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6108 SmallVectorImpl<QualType> &OutParamTypes,
6111 unsigned *LastParamTransformed) {
6112 int indexAdjustment = 0;
6113
6114 unsigned NumParams = Params.size();
6115 for (unsigned i = 0; i != NumParams; ++i) {
6116 if (LastParamTransformed)
6117 *LastParamTransformed = i;
6118 if (ParmVarDecl *OldParm = Params[i]) {
6119 assert(OldParm->getFunctionScopeIndex() == i);
6120
6121 std::optional<unsigned> NumExpansions;
6122 ParmVarDecl *NewParm = nullptr;
6123 if (OldParm->isParameterPack()) {
6124 // We have a function parameter pack that may need to be expanded.
6126
6127 // Find the parameter packs that could be expanded.
6128 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6130 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6131 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6132
6133 // Determine whether we should expand the parameter packs.
6134 bool ShouldExpand = false;
6135 bool RetainExpansion = false;
6136 std::optional<unsigned> OrigNumExpansions;
6137 if (Unexpanded.size() > 0) {
6138 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6139 NumExpansions = OrigNumExpansions;
6140 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
6141 Pattern.getSourceRange(),
6142 Unexpanded,
6143 ShouldExpand,
6144 RetainExpansion,
6145 NumExpansions)) {
6146 return true;
6147 }
6148 } else {
6149#ifndef NDEBUG
6150 const AutoType *AT =
6151 Pattern.getType().getTypePtr()->getContainedAutoType();
6152 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6153 "Could not find parameter packs or undeduced auto type!");
6154#endif
6155 }
6156
6157 if (ShouldExpand) {
6158 // Expand the function parameter pack into multiple, separate
6159 // parameters.
6160 getDerived().ExpandingFunctionParameterPack(OldParm);
6161 for (unsigned I = 0; I != *NumExpansions; ++I) {
6162 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6163 ParmVarDecl *NewParm
6164 = getDerived().TransformFunctionTypeParam(OldParm,
6165 indexAdjustment++,
6166 OrigNumExpansions,
6167 /*ExpectParameterPack=*/false);
6168 if (!NewParm)
6169 return true;
6170
6171 if (ParamInfos)
6172 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6173 OutParamTypes.push_back(NewParm->getType());
6174 if (PVars)
6175 PVars->push_back(NewParm);
6176 }
6177
6178 // If we're supposed to retain a pack expansion, do so by temporarily
6179 // forgetting the partially-substituted parameter pack.
6180 if (RetainExpansion) {
6181 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6182 ParmVarDecl *NewParm
6183 = getDerived().TransformFunctionTypeParam(OldParm,
6184 indexAdjustment++,
6185 OrigNumExpansions,
6186 /*ExpectParameterPack=*/false);
6187 if (!NewParm)
6188 return true;
6189
6190 if (ParamInfos)
6191 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6192 OutParamTypes.push_back(NewParm->getType());
6193 if (PVars)
6194 PVars->push_back(NewParm);
6195 }
6196
6197 // The next parameter should have the same adjustment as the
6198 // last thing we pushed, but we post-incremented indexAdjustment
6199 // on every push. Also, if we push nothing, the adjustment should
6200 // go down by one.
6201 indexAdjustment--;
6202
6203 // We're done with the pack expansion.
6204 continue;
6205 }
6206
6207 // We'll substitute the parameter now without expanding the pack
6208 // expansion.
6209 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6210 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6211 indexAdjustment,
6212 NumExpansions,
6213 /*ExpectParameterPack=*/true);
6214 assert(NewParm->isParameterPack() &&
6215 "Parameter pack no longer a parameter pack after "
6216 "transformation.");
6217 } else {
6218 NewParm = getDerived().TransformFunctionTypeParam(
6219 OldParm, indexAdjustment, std::nullopt,
6220 /*ExpectParameterPack=*/false);
6221 }
6222
6223 if (!NewParm)
6224 return true;
6225
6226 if (ParamInfos)
6227 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6228 OutParamTypes.push_back(NewParm->getType());
6229 if (PVars)
6230 PVars->push_back(NewParm);
6231 continue;
6232 }
6233
6234 // Deal with the possibility that we don't have a parameter
6235 // declaration for this parameter.
6236 assert(ParamTypes);
6237 QualType OldType = ParamTypes[i];
6238 bool IsPackExpansion = false;
6239 std::optional<unsigned> NumExpansions;
6240 QualType NewType;
6241 if (const PackExpansionType *Expansion
6242 = dyn_cast<PackExpansionType>(OldType)) {
6243 // We have a function parameter pack that may need to be expanded.
6244 QualType Pattern = Expansion->getPattern();
6246 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6247
6248 // Determine whether we should expand the parameter packs.
6249 bool ShouldExpand = false;
6250 bool RetainExpansion = false;
6251 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
6252 Unexpanded,
6253 ShouldExpand,
6254 RetainExpansion,
6255 NumExpansions)) {
6256 return true;
6257 }
6258
6259 if (ShouldExpand) {
6260 // Expand the function parameter pack into multiple, separate
6261 // parameters.
6262 for (unsigned I = 0; I != *NumExpansions; ++I) {
6263 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6264 QualType NewType = getDerived().TransformType(Pattern);
6265 if (NewType.isNull())
6266 return true;
6267
6268 if (NewType->containsUnexpandedParameterPack()) {
6269 NewType = getSema().getASTContext().getPackExpansionType(
6270 NewType, std::nullopt);
6271
6272 if (NewType.isNull())
6273 return true;
6274 }
6275
6276 if (ParamInfos)
6277 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6278 OutParamTypes.push_back(NewType);
6279 if (PVars)
6280 PVars->push_back(nullptr);
6281 }
6282
6283 // We're done with the pack expansion.
6284 continue;
6285 }
6286
6287 // If we're supposed to retain a pack expansion, do so by temporarily
6288 // forgetting the partially-substituted parameter pack.
6289 if (RetainExpansion) {
6290 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6291 QualType NewType = getDerived().TransformType(Pattern);
6292 if (NewType.isNull())
6293 return true;
6294
6295 if (ParamInfos)
6296 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6297 OutParamTypes.push_back(NewType);
6298 if (PVars)
6299 PVars->push_back(nullptr);
6300 }
6301
6302 // We'll substitute the parameter now without expanding the pack
6303 // expansion.
6304 OldType = Expansion->getPattern();
6305 IsPackExpansion = true;
6306 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6307 NewType = getDerived().TransformType(OldType);
6308 } else {
6309 NewType = getDerived().TransformType(OldType);
6310 }
6311
6312 if (NewType.isNull())
6313 return true;
6314
6315 if (IsPackExpansion)
6316 NewType = getSema().Context.getPackExpansionType(NewType,
6317 NumExpansions);
6318
6319 if (ParamInfos)
6320 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6321 OutParamTypes.push_back(NewType);
6322 if (PVars)
6323 PVars->push_back(nullptr);
6324 }
6325
6326#ifndef NDEBUG
6327 if (PVars) {
6328 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6329 if (ParmVarDecl *parm = (*PVars)[i])
6330 assert(parm->getFunctionScopeIndex() == i);
6331 }
6332#endif
6333
6334 return false;
6335}
6336
6337template<typename Derived>
6341 SmallVector<QualType, 4> ExceptionStorage;
6342 return getDerived().TransformFunctionProtoType(
6343 TLB, TL, nullptr, Qualifiers(),
6344 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6345 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6346 ExceptionStorage, Changed);
6347 });
6348}
6349
6350template<typename Derived> template<typename Fn>
6352 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6353 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6354
6355 // Transform the parameters and return type.
6356 //
6357 // We are required to instantiate the params and return type in source order.
6358 // When the function has a trailing return type, we instantiate the
6359 // parameters before the return type, since the return type can then refer
6360 // to the parameters themselves (via decltype, sizeof, etc.).
6361 //
6362 SmallVector<QualType, 4> ParamTypes;
6364 Sema::ExtParameterInfoBuilder ExtParamInfos;
6365 const FunctionProtoType *T = TL.getTypePtr();
6366
6367 QualType ResultType;
6368
6369 if (T->hasTrailingReturn()) {
6370 if (getDerived().TransformFunctionTypeParams(
6371 TL.getBeginLoc(), TL.getParams(),
6374 ParamTypes, &ParamDecls, ExtParamInfos))
6375 return QualType();
6376
6377 {
6378 // C++11 [expr.prim.general]p3:
6379 // If a declaration declares a member function or member function
6380 // template of a class X, the expression this is a prvalue of type
6381 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6382 // and the end of the function-definition, member-declarator, or
6383 // declarator.
6384 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6385 Sema::CXXThisScopeRAII ThisScope(
6386 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6387
6388 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6389 if (ResultType.isNull())
6390 return QualType();
6391 }
6392 }
6393 else {
6394 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6395 if (ResultType.isNull())
6396 return QualType();
6397
6398 if (getDerived().TransformFunctionTypeParams(
6399 TL.getBeginLoc(), TL.getParams(),
6402 ParamTypes, &ParamDecls, ExtParamInfos))
6403 return QualType();
6404 }
6405
6407
6408 bool EPIChanged = false;
6409 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6410 return QualType();
6411
6412 // Handle extended parameter information.
6413 if (auto NewExtParamInfos =
6414 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6415 if (!EPI.ExtParameterInfos ||
6417 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6418 EPIChanged = true;
6419 }
6420 EPI.ExtParameterInfos = NewExtParamInfos;
6421 } else if (EPI.ExtParameterInfos) {
6422 EPIChanged = true;
6423 EPI.ExtParameterInfos = nullptr;
6424 }
6425
6426 // Transform any function effects with unevaluated conditions.
6427 // Hold this set in a local for the rest of this function, since EPI
6428 // may need to hold a FunctionEffectsRef pointing into it.
6429 std::optional<FunctionEffectSet> NewFX;
6430 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6431 NewFX.emplace();
6434
6435 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6436 FunctionEffectWithCondition NewEC = PrevEC;
6437 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6438 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6439 if (NewExpr.isInvalid())
6440 return QualType();
6441 std::optional<FunctionEffectMode> Mode =
6442 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6443 if (!Mode)
6444 return QualType();
6445
6446 // The condition expression has been transformed, and re-evaluated.
6447 // It may or may not have become constant.
6448 switch (*Mode) {
6450 NewEC.Cond = {};
6451 break;
6453 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6454 NewEC.Cond = {};
6455 break;
6457 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6458 break;
6460 llvm_unreachable(
6461 "FunctionEffectMode::None shouldn't be possible here");
6462 }
6463 }
6464 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6465 TL.getBeginLoc())) {
6467 NewFX->insert(NewEC, Errs);
6468 assert(Errs.empty());
6469 }
6470 }
6471 EPI.FunctionEffects = *NewFX;
6472 EPIChanged = true;
6473 }
6474
6475 QualType Result = TL.getType();
6476 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6477 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6478 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6479 if (Result.isNull())
6480 return QualType();
6481 }
6482
6485 NewTL.setLParenLoc(TL.getLParenLoc());
6486 NewTL.setRParenLoc(TL.getRParenLoc());
6489 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6490 NewTL.setParam(i, ParamDecls[i]);
6491
6492 return Result;
6493}
6494
6495template<typename Derived>
6498 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6499 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6500
6501 // Instantiate a dynamic noexcept expression, if any.
6502 if (isComputedNoexcept(ESI.Type)) {
6503 // Update this scrope because ContextDecl in Sema will be used in
6504 // TransformExpr.
6505 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6506 Sema::CXXThisScopeRAII ThisScope(
6507 SemaRef, Method ? Method->getParent() : nullptr,
6508 Method ? Method->getMethodQualifiers() : Qualifiers{},
6509 Method != nullptr);
6512 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6513 if (NoexceptExpr.isInvalid())
6514 return true;
6515
6517 NoexceptExpr =
6518 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6519 if (NoexceptExpr.isInvalid())
6520 return true;
6521
6522 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6523 Changed = true;
6524 ESI.NoexceptExpr = NoexceptExpr.get();
6525 ESI.Type = EST;
6526 }
6527
6528 if (ESI.Type != EST_Dynamic)
6529 return false;
6530
6531 // Instantiate a dynamic exception specification's type.
6532 for (QualType T : ESI.Exceptions) {
6533 if (const PackExpansionType *PackExpansion =
6535 Changed = true;
6536
6537 // We have a pack expansion. Instantiate it.
6539 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6540 Unexpanded);
6541 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6542
6543 // Determine whether the set of unexpanded parameter packs can and
6544 // should
6545 // be expanded.
6546 bool Expand = false;
6547 bool RetainExpansion = false;
6548 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6549 // FIXME: Track the location of the ellipsis (and track source location
6550 // information for the types in the exception specification in general).
6551 if (getDerived().TryExpandParameterPacks(
6552 Loc, SourceRange(), Unexpanded, Expand,
6553 RetainExpansion, NumExpansions))
6554 return true;
6555
6556 if (!Expand) {
6557 // We can't expand this pack expansion into separate arguments yet;
6558 // just substitute into the pattern and create a new pack expansion
6559 // type.
6560 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6561 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6562 if (U.isNull())
6563 return true;
6564
6565 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6566 Exceptions.push_back(U);
6567 continue;
6568 }
6569
6570 // Substitute into the pack expansion pattern for each slice of the
6571 // pack.
6572 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6573 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6574
6575 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6576 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6577 return true;
6578
6579 Exceptions.push_back(U);
6580 }
6581 } else {
6582 QualType U = getDerived().TransformType(T);
6583 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6584 return true;
6585 if (T != U)
6586 Changed = true;
6587
6588 Exceptions.push_back(U);
6589 }
6590 }
6591
6592 ESI.Exceptions = Exceptions;
6593 if (ESI.Exceptions.empty())
6594 ESI.Type = EST_DynamicNone;
6595 return false;
6596}
6597
6598template<typename Derived>
6600 TypeLocBuilder &TLB,
6602 const FunctionNoProtoType *T = TL.getTypePtr();
6603 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6604 if (ResultType.isNull())
6605 return QualType();
6606
6607 QualType Result = TL.getType();
6608 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6609 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6610
6613 NewTL.setLParenLoc(TL.getLParenLoc());
6614 NewTL.setRParenLoc(TL.getRParenLoc());
6616
6617 return Result;
6618}
6619
6620template <typename Derived>
6621QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6622 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6623 const UnresolvedUsingType *T = TL.getTypePtr();
6624 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6625 if (!D)
6626 return QualType();
6627
6628 QualType Result = TL.getType();
6629 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
6630 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
6631 if (Result.isNull())
6632 return QualType();
6633 }
6634
6635 // We might get an arbitrary type spec type back. We should at
6636 // least always get a type spec type, though.
6637 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
6638 NewTL.setNameLoc(TL.getNameLoc());
6639
6640 return Result;
6641}
6642
6643template <typename Derived>
6644QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
6645 UsingTypeLoc TL) {
6646 const UsingType *T = TL.getTypePtr();
6647
6648 auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl(
6649 TL.getLocalSourceRange().getBegin(), T->getFoundDecl()));
6650 if (!Found)
6651 return QualType();
6652
6653 QualType Underlying = getDerived().TransformType(T->desugar());
6654 if (Underlying.isNull())
6655 return QualType();
6656
6657 QualType Result = TL.getType();
6658 if (getDerived().AlwaysRebuild() || Found != T->getFoundDecl() ||
6659 Underlying != T->getUnderlyingType()) {
6660 Result = getDerived().RebuildUsingType(Found, Underlying);
6661 if (Result.isNull())
6662 return QualType();
6663 }
6664
6665 TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc());
6666 return Result;
6667}
6668
6669template<typename Derived>
6670QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
6671 TypedefTypeLoc TL) {
6672 const TypedefType *T = TL.getTypePtr();
6673 TypedefNameDecl *Typedef
6674 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6675 T->getDecl()));
6676 if (!Typedef)
6677 return QualType();
6678
6679 QualType Result = TL.getType();
6680 if (getDerived().AlwaysRebuild() ||
6681 Typedef != T->getDecl()) {
6682 Result = getDerived().RebuildTypedefType(Typedef);
6683 if (Result.isNull())
6684 return QualType();
6685 }
6686
6687 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
6688 NewTL.setNameLoc(TL.getNameLoc());
6689
6690 return Result;
6691}
6692
6693template<typename Derived>
6694QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
6695 TypeOfExprTypeLoc TL) {
6696 // typeof expressions are not potentially evaluated contexts
6697 EnterExpressionEvaluationContext Unevaluated(
6700
6701 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6702 if (E.isInvalid())
6703 return QualType();
6704
6705 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6706 if (E.isInvalid())
6707 return QualType();
6708
6709 QualType Result = TL.getType();
6710 TypeOfKind Kind = Result->castAs<TypeOfExprType>()->getKind();
6711 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6712 Result =
6713 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6714 if (Result.isNull())
6715 return QualType();
6716 }
6717
6718 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6719 NewTL.setTypeofLoc(TL.getTypeofLoc());
6720 NewTL.setLParenLoc(TL.getLParenLoc());
6721 NewTL.setRParenLoc(TL.getRParenLoc());
6722
6723 return Result;
6724}
6725
6726template<typename Derived>
6727QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
6728 TypeOfTypeLoc TL) {
6729 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6730 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6731 if (!New_Under_TI)
6732 return QualType();
6733
6734 QualType Result = TL.getType();
6735 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6736 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6737 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6738 if (Result.isNull())
6739 return QualType();
6740 }
6741
6742 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6743 NewTL.setTypeofLoc(TL.getTypeofLoc());
6744 NewTL.setLParenLoc(TL.getLParenLoc());
6745 NewTL.setRParenLoc(TL.getRParenLoc());
6746 NewTL.setUnmodifiedTInfo(New_Under_TI);
6747
6748 return Result;
6749}
6750
6751template<typename Derived>
6752QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
6753 DecltypeTypeLoc TL) {
6754 const DecltypeType *T = TL.getTypePtr();
6755
6756 // decltype expressions are not potentially evaluated contexts
6757 EnterExpressionEvaluationContext Unevaluated(
6760
6761 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6762 if (E.isInvalid())
6763 return QualType();
6764
6765 E = getSema().ActOnDecltypeExpression(E.get());
6766 if (E.isInvalid())
6767 return QualType();
6768
6769 QualType Result = TL.getType();
6770 if (getDerived().AlwaysRebuild() ||
6771 E.get() != T->getUnderlyingExpr()) {
6772 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6773 if (Result.isNull())
6774 return QualType();
6775 }
6776 else E.get();
6777
6778 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6779 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6780 NewTL.setRParenLoc(TL.getRParenLoc());
6781 return Result;
6782}
6783
6784template <typename Derived>
6785QualType
6786TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
6787 PackIndexingTypeLoc TL) {
6788 // Transform the index
6789 ExprResult IndexExpr;
6790 {
6791 EnterExpressionEvaluationContext ConstantContext(
6793
6794 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6795 if (IndexExpr.isInvalid())
6796 return QualType();
6797 }
6798 QualType Pattern = TL.getPattern();
6799
6800 const PackIndexingType *PIT = TL.getTypePtr();
6801 SmallVector<QualType, 5> SubtitutedTypes;
6802 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6803
6804 bool NotYetExpanded = Types.empty();
6805 bool FullySubstituted = true;
6806
6807 if (Types.empty() && !PIT->expandsToEmptyPack())
6808 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
6809
6810 for (QualType T : Types) {
6812 QualType Transformed = getDerived().TransformType(T);
6813 if (Transformed.isNull())
6814 return QualType();
6815 SubtitutedTypes.push_back(Transformed);
6816 continue;
6817 }
6818
6820 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
6821 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6822 // Determine whether the set of unexpanded parameter packs can and should
6823 // be expanded.
6824 bool ShouldExpand = true;
6825 bool RetainExpansion = false;
6826 std::optional<unsigned> OrigNumExpansions;
6827 std::optional<unsigned> NumExpansions = OrigNumExpansions;
6828 if (getDerived().TryExpandParameterPacks(TL.getEllipsisLoc(), SourceRange(),
6829 Unexpanded, ShouldExpand,
6830 RetainExpansion, NumExpansions))
6831 return QualType();
6832 if (!ShouldExpand) {
6833 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6834 // FIXME: should we keep TypeLoc for individual expansions in
6835 // PackIndexingTypeLoc?
6836 TypeSourceInfo *TI =
6837 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
6838 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
6839 if (Pack.isNull())
6840 return QualType();
6841 if (NotYetExpanded) {
6842 FullySubstituted = false;
6843 QualType Out = getDerived().RebuildPackIndexingType(
6844 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6845 FullySubstituted);
6846 if (Out.isNull())
6847 return QualType();
6848
6849 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6850 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6851 return Out;
6852 }
6853 SubtitutedTypes.push_back(Pack);
6854 continue;
6855 }
6856 for (unsigned I = 0; I != *NumExpansions; ++I) {
6857 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6858 QualType Out = getDerived().TransformType(T);
6859 if (Out.isNull())
6860 return QualType();
6861 SubtitutedTypes.push_back(Out);
6862 FullySubstituted &= !Out->containsUnexpandedParameterPack();
6863 }
6864 // If we're supposed to retain a pack expansion, do so by temporarily
6865 // forgetting the partially-substituted parameter pack.
6866 if (RetainExpansion) {
6867 FullySubstituted = false;
6868 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6869 QualType Out = getDerived().TransformType(T);
6870 if (Out.isNull())
6871 return QualType();
6872 SubtitutedTypes.push_back(Out);
6873 }
6874 }
6875
6876 // A pack indexing type can appear in a larger pack expansion,
6877 // e.g. `Pack...[pack_of_indexes]...`
6878 // so we need to temporarily disable substitution of pack elements
6879 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6880 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
6881
6882 QualType Out = getDerived().RebuildPackIndexingType(
6883 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6884 FullySubstituted, SubtitutedTypes);
6885 if (Out.isNull())
6886 return Out;
6887
6888 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6889 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6890 return Out;
6891}
6892
6893template<typename Derived>
6894QualType TreeTransform<Derived>::TransformUnaryTransformType(
6895 TypeLocBuilder &TLB,
6896 UnaryTransformTypeLoc TL) {
6897 QualType Result = TL.getType();
6898 if (Result->isDependentType()) {
6899 const UnaryTransformType *T = TL.getTypePtr();
6900
6901 TypeSourceInfo *NewBaseTSI =
6902 getDerived().TransformType(TL.getUnderlyingTInfo());
6903 if (!NewBaseTSI)
6904 return QualType();
6905 QualType NewBase = NewBaseTSI->getType();
6906
6907 Result = getDerived().RebuildUnaryTransformType(NewBase,
6908 T->getUTTKind(),
6909 TL.getKWLoc());
6910 if (Result.isNull())
6911 return QualType();
6912 }
6913
6914 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
6915 NewTL.setKWLoc(TL.getKWLoc());
6916 NewTL.setParensRange(TL.getParensRange());
6917 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
6918 return Result;
6919}
6920
6921template<typename Derived>
6922QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
6923 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
6924 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
6925
6926 CXXScopeSpec SS;
6927 TemplateName TemplateName = getDerived().TransformTemplateName(
6928 SS, T->getTemplateName(), TL.getTemplateNameLoc());
6929 if (TemplateName.isNull())
6930 return QualType();
6931
6932 QualType OldDeduced = T->getDeducedType();
6933 QualType NewDeduced;
6934 if (!OldDeduced.isNull()) {
6935 NewDeduced = getDerived().TransformType(OldDeduced);
6936 if (NewDeduced.isNull())
6937 return QualType();
6938 }
6939
6940 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
6941 TemplateName, NewDeduced);
6942 if (Result.isNull())
6943 return QualType();
6944
6945 DeducedTemplateSpecializationTypeLoc NewTL =
6946 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
6947 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6948
6949 return Result;
6950}
6951
6952template<typename Derived>
6953QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
6954 RecordTypeLoc TL) {
6955 const RecordType *T = TL.getTypePtr();
6956 RecordDecl *Record
6957 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6958 T->getDecl()));
6959 if (!Record)
6960 return QualType();
6961
6962 QualType Result = TL.getType();
6963 if (getDerived().AlwaysRebuild() ||
6964 Record != T->getDecl()) {
6965 Result = getDerived().RebuildRecordType(Record);
6966 if (Result.isNull())
6967 return QualType();
6968 }
6969
6970 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
6971 NewTL.setNameLoc(TL.getNameLoc());
6972
6973 return Result;
6974}
6975
6976template<typename Derived>
6977QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
6978 EnumTypeLoc TL) {
6979 const EnumType *T = TL.getTypePtr();
6980 EnumDecl *Enum
6981 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6982 T->getDecl()));
6983 if (!Enum)
6984 return QualType();
6985
6986 QualType Result = TL.getType();
6987 if (getDerived().AlwaysRebuild() ||
6988 Enum != T->getDecl()) {
6989 Result = getDerived().RebuildEnumType(Enum);
6990 if (Result.isNull())
6991 return QualType();
6992 }
6993
6994 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
6995 NewTL.setNameLoc(TL.getNameLoc());
6996
6997 return Result;
6998}
6999
7000template<typename Derived>
7001QualType TreeTransform<Derived>::TransformInjectedClassNameType(
7002 TypeLocBuilder &TLB,
7003 InjectedClassNameTypeLoc TL) {
7004 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
7005 TL.getTypePtr()->getDecl());
7006 if (!D) return QualType();
7007
7008 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
7009 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
7010 return T;
7011}
7012
7013template<typename Derived>
7015 TypeLocBuilder &TLB,
7017 return getDerived().TransformTemplateTypeParmType(
7018 TLB, TL,
7019 /*SuppressObjCLifetime=*/false);
7020}
7021
7022template <typename Derived>
7024 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7025 return TransformTypeSpecType(TLB, TL);
7026}
7027
7028template<typename Derived>
7029QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7030 TypeLocBuilder &TLB,
7031 SubstTemplateTypeParmTypeLoc TL) {
7032 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7033
7034 Decl *NewReplaced =
7035 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7036
7037 // Substitute into the replacement type, which itself might involve something
7038 // that needs to be transformed. This only tends to occur with default
7039 // template arguments of template template parameters.
7040 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7041 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7042 if (Replacement.isNull())
7043 return QualType();
7044
7045 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7046 Replacement, NewReplaced, T->getIndex(), T->getPackIndex());
7047
7048 // Propagate type-source information.
7049 SubstTemplateTypeParmTypeLoc NewTL
7050 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7051 NewTL.setNameLoc(TL.getNameLoc());
7052 return Result;
7053
7054}
7055
7056template<typename Derived>
7058 TypeLocBuilder &TLB,
7060 return getDerived().TransformSubstTemplateTypeParmPackType(
7061 TLB, TL, /*SuppressObjCLifetime=*/false);
7062}
7063
7064template <typename Derived>
7067 return TransformTypeSpecType(TLB, TL);
7068}
7069
7070template<typename Derived>
7072 TypeLocBuilder &TLB,
7075
7076 // The nested-name-specifier never matters in a TemplateSpecializationType,
7077 // because we can't have a dependent nested-name-specifier anyway.
7078 CXXScopeSpec SS;
7079 TemplateName Template
7080 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
7081 TL.getTemplateNameLoc());
7082 if (Template.isNull())
7083 return QualType();
7084
7085 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
7086}
7087
7088template<typename Derived>
7090 AtomicTypeLoc TL) {
7091 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7092 if (ValueType.isNull())
7093 return QualType();
7094
7095 QualType Result = TL.getType();
7096 if (getDerived().AlwaysRebuild() ||
7097 ValueType != TL.getValueLoc().getType()) {
7098 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7099 if (Result.isNull())
7100 return QualType();
7101 }
7102
7103 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7104 NewTL.setKWLoc(TL.getKWLoc());
7105 NewTL.setLParenLoc(TL.getLParenLoc());
7106 NewTL.setRParenLoc(TL.getRParenLoc());
7107
7108 return Result;
7109}
7110
7111template <typename Derived>
7112QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
7113 PipeTypeLoc TL) {
7114 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7115 if (ValueType.isNull())
7116 return QualType();
7117
7118 QualType Result = TL.getType();
7119 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7120 const PipeType *PT = Result->castAs<PipeType>();
7121 bool isReadPipe = PT->isReadOnly();
7122 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7123 if (Result.isNull())
7124 return QualType();
7125 }
7126
7127 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7128 NewTL.setKWLoc(TL.getKWLoc());
7129
7130 return Result;
7131}
7132
7133template <typename Derived>
7134QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
7135 BitIntTypeLoc TL) {
7136 const BitIntType *EIT = TL.getTypePtr();
7137 QualType Result = TL.getType();
7138
7139 if (getDerived().AlwaysRebuild()) {
7140 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7141 EIT->getNumBits(), TL.getNameLoc());
7142 if (Result.isNull())
7143 return QualType();
7144 }
7145
7146 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7147 NewTL.setNameLoc(TL.getNameLoc());
7148 return Result;
7149}
7150
7151template <typename Derived>
7152QualType TreeTransform<Derived>::TransformDependentBitIntType(
7153 TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) {
7154 const DependentBitIntType *EIT = TL.getTypePtr();
7155
7156 EnterExpressionEvaluationContext Unevaluated(
7158 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7159 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7160
7161 if (BitsExpr.isInvalid())
7162 return QualType();
7163
7164 QualType Result = TL.getType();
7165
7166 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7167 Result = getDerived().RebuildDependentBitIntType(
7168 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7169
7170 if (Result.isNull())
7171 return QualType();
7172 }
7173
7174 if (isa<DependentBitIntType>(Result)) {
7175 DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
7176 NewTL.setNameLoc(TL.getNameLoc());
7177 } else {
7178 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7179 NewTL.setNameLoc(TL.getNameLoc());
7180 }
7181 return Result;
7182}
7183
7184 /// Simple iterator that traverses the template arguments in a
7185 /// container that provides a \c getArgLoc() member function.
7186 ///
7187 /// This iterator is intended to be used with the iterator form of
7188 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7189 template<typename ArgLocContainer>
7191 ArgLocContainer *Container;
7192 unsigned Index;
7193
7194 public:
7197 typedef int difference_type;
7198 typedef std::input_iterator_tag iterator_category;
7199
7200 class pointer {
7202
7203 public:
7204 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7205
7207 return &Arg;
7208 }
7209 };
7210
7211
7213
7214 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7215 unsigned Index)
7216 : Container(&Container), Index(Index) { }
7217
7219 ++Index;
7220 return *this;
7221 }
7222
7225 ++(*this);
7226 return Old;
7227 }
7228
7230 return Container->getArgLoc(Index);
7231 }
7232
7234 return pointer(Container->getArgLoc(Index));
7235 }
7236
7239 return X.Container == Y.Container && X.Index == Y.Index;
7240 }
7241
7244 return !(X == Y);
7245 }
7246 };
7247
7248template<typename Derived>
7249QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7250 AutoTypeLoc TL) {
7251 const AutoType *T = TL.getTypePtr();
7252 QualType OldDeduced = T->getDeducedType();
7253 QualType NewDeduced;
7254 if (!OldDeduced.isNull()) {
7255 NewDeduced = getDerived().TransformType(OldDeduced);
7256 if (NewDeduced.isNull())
7257 return QualType();
7258 }
7259
7260 ConceptDecl *NewCD = nullptr;
7261 TemplateArgumentListInfo NewTemplateArgs;
7262 NestedNameSpecifierLoc NewNestedNameSpec;
7263 if (T->isConstrained()) {
7264 assert(TL.getConceptReference());
7265 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7266 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7267
7268 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7269 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7270 typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator;
7271 if (getDerived().TransformTemplateArguments(
7272 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7273 NewTemplateArgs))
7274 return QualType();
7275
7276 if (TL.getNestedNameSpecifierLoc()) {
7277 NewNestedNameSpec
7278 = getDerived().TransformNestedNameSpecifierLoc(
7279 TL.getNestedNameSpecifierLoc());
7280 if (!NewNestedNameSpec)
7281 return QualType();
7282 }
7283 }
7284
7285 QualType Result = TL.getType();
7286 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7287 T->isDependentType() || T->isConstrained()) {
7288 // FIXME: Maybe don't rebuild if all template arguments are the same.
7290 NewArgList.reserve(NewTemplateArgs.size());
7291 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7292 NewArgList.push_back(ArgLoc.getArgument());
7293 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7294 NewArgList);
7295 if (Result.isNull())
7296 return QualType();
7297 }
7298
7299 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7300 NewTL.setNameLoc(TL.getNameLoc());
7301 NewTL.setRParenLoc(TL.getRParenLoc());
7302 NewTL.setConceptReference(nullptr);
7303
7304 if (T->isConstrained()) {
7305 DeclarationNameInfo DNI = DeclarationNameInfo(
7306 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7307 TL.getConceptNameLoc(),
7308 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7309 auto *CR = ConceptReference::Create(
7310 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7311 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7312 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7313 NewTL.setConceptReference(CR);
7314 }
7315
7316 return Result;
7317}
7318
7319template <typename Derived>
7321 TypeLocBuilder &TLB,
7322 TemplateSpecializationTypeLoc TL,
7323 TemplateName Template) {
7324 TemplateArgumentListInfo NewTemplateArgs;
7325 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7326 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7327 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
7328 ArgIterator;
7329 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7330 ArgIterator(TL, TL.getNumArgs()),
7331 NewTemplateArgs))
7332 return QualType();
7333
7334 // FIXME: maybe don't rebuild if all the template arguments are the same.
7335
7336 QualType Result =
7337 getDerived().RebuildTemplateSpecializationType(Template,
7338 TL.getTemplateNameLoc(),
7339 NewTemplateArgs);
7340
7341 if (!Result.isNull()) {
7342 // Specializations of template template parameters are represented as
7343 // TemplateSpecializationTypes, and substitution of type alias templates
7344 // within a dependent context can transform them into
7345 // DependentTemplateSpecializationTypes.
7346 if (isa<DependentTemplateSpecializationType>(Result)) {
7347 DependentTemplateSpecializationTypeLoc NewTL
7348 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
7349 NewTL.setElaboratedKeywordLoc(SourceLocation());
7350 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
7351 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7352 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7353 NewTL.setLAngleLoc(TL.getLAngleLoc());
7354 NewTL.setRAngleLoc(TL.getRAngleLoc());
7355 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7356 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7357 return Result;
7358 }
7359
7360 TemplateSpecializationTypeLoc NewTL
7361 = TLB.push<TemplateSpecializationTypeLoc>(Result);
7362 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7363 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7364 NewTL.setLAngleLoc(TL.getLAngleLoc());
7365 NewTL.setRAngleLoc(TL.getRAngleLoc());
7366 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7367 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7368 }
7369
7370 return Result;
7371}
7372
7373template <typename Derived>
7375 TypeLocBuilder &TLB,
7377 TemplateName Template,
7378 CXXScopeSpec &SS) {
7379 TemplateArgumentListInfo NewTemplateArgs;
7380 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7381 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7384 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7385 ArgIterator(TL, TL.getNumArgs()),
7386 NewTemplateArgs))
7387 return QualType();
7388
7389 // FIXME: maybe don't rebuild if all the template arguments are the same.
7390
7391 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
7392 QualType Result = getSema().Context.getDependentTemplateSpecializationType(
7393 TL.getTypePtr()->getKeyword(), DTN->getQualifier(),
7394 DTN->getIdentifier(), NewTemplateArgs.arguments());
7395
7399 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
7402 NewTL.setLAngleLoc(TL.getLAngleLoc());
7403 NewTL.setRAngleLoc(TL.getRAngleLoc());
7404 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7405 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7406 return Result;
7407 }
7408
7410 = getDerived().RebuildTemplateSpecializationType(Template,
7411 TL.getTemplateNameLoc(),
7412 NewTemplateArgs);
7413
7414 if (!Result.isNull()) {
7415 /// FIXME: Wrap this in an elaborated-type-specifier?
7420 NewTL.setLAngleLoc(TL.getLAngleLoc());
7421 NewTL.setRAngleLoc(TL.getRAngleLoc());
7422 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7423 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7424 }
7425
7426 return Result;
7427}
7428
7429template<typename Derived>
7432 ElaboratedTypeLoc TL) {
7433 const ElaboratedType *T = TL.getTypePtr();
7434
7435 NestedNameSpecifierLoc QualifierLoc;
7436 // NOTE: the qualifier in an ElaboratedType is optional.
7437 if (TL.getQualifierLoc()) {
7438 QualifierLoc
7439 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7440 if (!QualifierLoc)
7441 return QualType();
7442 }
7443
7444 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
7445 if (NamedT.isNull())
7446 return QualType();
7447
7448 // C++0x [dcl.type.elab]p2:
7449 // If the identifier resolves to a typedef-name or the simple-template-id
7450 // resolves to an alias template specialization, the
7451 // elaborated-type-specifier is ill-formed.
7452 if (T->getKeyword() != ElaboratedTypeKeyword::None &&
7453 T->getKeyword() != ElaboratedTypeKeyword::Typename) {
7454 if (const TemplateSpecializationType *TST =
7455 NamedT->getAs<TemplateSpecializationType>()) {
7456 TemplateName Template = TST->getTemplateName();
7457 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
7458 Template.getAsTemplateDecl())) {
7459 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
7460 diag::err_tag_reference_non_tag)
7462 << llvm::to_underlying(
7464 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
7465 }
7466 }
7467 }
7468
7469 QualType Result = TL.getType();
7470 if (getDerived().AlwaysRebuild() ||
7471 QualifierLoc != TL.getQualifierLoc() ||
7472 NamedT != T->getNamedType()) {
7473 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
7474 T->getKeyword(),
7475 QualifierLoc, NamedT);
7476 if (Result.isNull())
7477 return QualType();
7478 }
7479
7480 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7481 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7482 NewTL.setQualifierLoc(QualifierLoc);
7483 return Result;
7484}
7485
7486template <typename Derived>
7487QualType TreeTransform<Derived>::TransformAttributedType(TypeLocBuilder &TLB,
7488 AttributedTypeLoc TL) {
7489 const AttributedType *oldType = TL.getTypePtr();
7490 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7491 if (modifiedType.isNull())
7492 return QualType();
7493
7494 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7495 const Attr *oldAttr = TL.getAttr();
7496 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7497 if (oldAttr && !newAttr)
7498 return QualType();
7499
7500 QualType result = TL.getType();
7501
7502 // FIXME: dependent operand expressions?
7503 if (getDerived().AlwaysRebuild() ||
7504 modifiedType != oldType->getModifiedType()) {
7505 // If the equivalent type is equal to the modified type, we don't want to
7506 // transform it as well because:
7507 //
7508 // 1. The transformation would yield the same result and is therefore
7509 // superfluous, and
7510 //
7511 // 2. Transforming the same type twice can cause problems, e.g. if it
7512 // is a FunctionProtoType, we may end up instantiating the function
7513 // parameters twice, which causes an assertion since the parameters
7514 // are already bound to their counterparts in the template for this
7515 // instantiation.
7516 //
7517 QualType equivalentType = modifiedType;
7518 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7519 TypeLocBuilder AuxiliaryTLB;
7520 AuxiliaryTLB.reserve(TL.getFullDataSize());
7521 equivalentType =
7522 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7523 if (equivalentType.isNull())
7524 return QualType();
7525 }
7526
7527 // Check whether we can add nullability; it is only represented as
7528 // type sugar, and therefore cannot be diagnosed in any other way.
7529 if (auto nullability = oldType->getImmediateNullability()) {
7530 if (!modifiedType->canHaveNullability()) {
7531 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7532 : TL.getModifiedLoc().getBeginLoc()),
7533 diag::err_nullability_nonpointer)
7534 << DiagNullabilityKind(*nullability, false) << modifiedType;
7535 return QualType();
7536 }
7537 }
7538
7539 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7540 modifiedType,
7541 equivalentType,
7542 TL.getAttr());
7543 }
7544
7545 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7546 newTL.setAttr(newAttr);
7547 return result;
7548}
7549
7550template <typename Derived>
7551QualType TreeTransform<Derived>::TransformCountAttributedType(
7552 TypeLocBuilder &TLB, CountAttributedTypeLoc TL) {
7553 const CountAttributedType *OldTy = TL.getTypePtr();
7554 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7555 if (InnerTy.isNull())
7556 return QualType();
7557
7558 Expr *OldCount = TL.getCountExpr();
7559 Expr *NewCount = nullptr;
7560 if (OldCount) {
7561 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7562 if (CountResult.isInvalid())
7563 return QualType();
7564 NewCount = CountResult.get();
7565 }
7566
7567 QualType Result = TL.getType();
7568 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7569 OldCount != NewCount) {
7570 // Currently, CountAttributedType can only wrap incomplete array types.
7572 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7573 }
7574
7575 TLB.push<CountAttributedTypeLoc>(Result);
7576 return Result;
7577}
7578
7579template <typename Derived>
7580QualType TreeTransform<Derived>::TransformBTFTagAttributedType(
7581 TypeLocBuilder &TLB, BTFTagAttributedTypeLoc TL) {
7582 // The BTFTagAttributedType is available for C only.
7583 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7584}
7585
7586template <typename Derived>
7587QualType TreeTransform<Derived>::TransformHLSLAttributedResourceType(
7588 TypeLocBuilder &TLB, HLSLAttributedResourceTypeLoc TL) {
7589
7590 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7591
7592 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7593 if (WrappedTy.isNull())
7594 return QualType();
7595
7596 QualType ContainedTy = QualType();
7597 QualType OldContainedTy = oldType->getContainedType();
7598 if (!OldContainedTy.isNull()) {
7599 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7600 if (!oldContainedTSI)
7601 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7602 OldContainedTy, SourceLocation());
7603 TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI);
7604 if (!ContainedTSI)
7605 return QualType();
7606 ContainedTy = ContainedTSI->getType();
7607 }
7608
7609 QualType Result = TL.getType();
7610 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7611 ContainedTy != oldType->getContainedType()) {
7613 WrappedTy, ContainedTy, oldType->getAttrs());
7614 }
7615
7616 TLB.push<HLSLAttributedResourceTypeLoc>(Result);
7617 return Result;
7618}
7619
7620template<typename Derived>
7621QualType
7622TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
7623 ParenTypeLoc TL) {
7624 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7625 if (Inner.isNull())
7626 return QualType();
7627
7628 QualType Result = TL.getType();
7629 if (getDerived().AlwaysRebuild() ||
7630 Inner != TL.getInnerLoc().getType()) {
7631 Result = getDerived().RebuildParenType(Inner);
7632 if (Result.isNull())
7633 return QualType();
7634 }
7635
7636 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7637 NewTL.setLParenLoc(TL.getLParenLoc());
7638 NewTL.setRParenLoc(TL.getRParenLoc());
7639 return Result;
7640}
7641
7642template <typename Derived>
7643QualType
7644TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
7645 MacroQualifiedTypeLoc TL) {
7646 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7647 if (Inner.isNull())
7648 return QualType();
7649
7650 QualType Result = TL.getType();
7651 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7652 Result =
7653 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7654 if (Result.isNull())
7655 return QualType();
7656 }
7657
7658 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
7659 NewTL.setExpansionLoc(TL.getExpansionLoc());
7660 return Result;
7661}
7662
7663template<typename Derived>
7664QualType TreeTransform<Derived>::TransformDependentNameType(
7665 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
7666 return TransformDependentNameType(TLB, TL, false);
7667}
7668
7669template<typename Derived>
7670QualType TreeTransform<Derived>::TransformDependentNameType(
7671 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
7672 const DependentNameType *T = TL.getTypePtr();
7673
7674 NestedNameSpecifierLoc QualifierLoc
7675 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7676 if (!QualifierLoc)
7677 return QualType();
7678
7679 QualType Result
7680 = getDerived().RebuildDependentNameType(T->getKeyword(),
7681 TL.getElaboratedKeywordLoc(),
7682 QualifierLoc,
7683 T->getIdentifier(),
7684 TL.getNameLoc(),
7685 DeducedTSTContext);
7686 if (Result.isNull())
7687 return QualType();
7688
7689 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
7690 QualType NamedT = ElabT->getNamedType();
7691 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
7692
7693 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7694 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7695 NewTL.setQualifierLoc(QualifierLoc);
7696 } else {
7697 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
7698 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7699 NewTL.setQualifierLoc(QualifierLoc);
7700 NewTL.setNameLoc(TL.getNameLoc());
7701 }
7702 return Result;
7703}
7704
7705template<typename Derived>
7708 DependentTemplateSpecializationTypeLoc TL) {
7709 NestedNameSpecifierLoc QualifierLoc;
7710 if (TL.getQualifierLoc()) {
7711 QualifierLoc
7712 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7713 if (!QualifierLoc)
7714 return QualType();
7715 }
7716
7717 return getDerived()
7718 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
7719}
7720
7721template<typename Derived>
7725 NestedNameSpecifierLoc QualifierLoc) {
7727
7728 TemplateArgumentListInfo NewTemplateArgs;
7729 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7730 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7731
7734 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7735 ArgIterator(TL, TL.getNumArgs()),
7736 NewTemplateArgs))
7737 return QualType();
7738
7739 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
7740 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
7741 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
7742 /*AllowInjectedClassName*/ false);
7743 if (Result.isNull())
7744 return QualType();
7745
7746 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
7747 QualType NamedT = ElabT->getNamedType();
7748
7749 // Copy information relevant to the template specialization.
7751 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
7754 NamedTL.setLAngleLoc(TL.getLAngleLoc());
7755 NamedTL.setRAngleLoc(TL.getRAngleLoc());
7756 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7757 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7758
7759 // Copy information relevant to the elaborated type.
7762 NewTL.setQualifierLoc(QualifierLoc);
7763 } else if (isa<DependentTemplateSpecializationType>(Result)) {
7767 SpecTL.setQualifierLoc(QualifierLoc);
7770 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7771 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7772 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7773 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7774 } else {
7779 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7780 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7781 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7782 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7783 }
7784 return Result;
7785}
7786
7787template<typename Derived>
7790 QualType Pattern
7791 = getDerived().TransformType(TLB, TL.getPatternLoc());
7792 if (Pattern.isNull())
7793 return QualType();
7794
7795 QualType Result = TL.getType();
7796 if (getDerived().AlwaysRebuild() ||
7797 Pattern != TL.getPatternLoc().getType()) {
7798 Result = getDerived().RebuildPackExpansionType(Pattern,
7800 TL.getEllipsisLoc(),
7802 if (Result.isNull())
7803 return QualType();
7804 }
7805
7806 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
7807 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7808 return Result;
7809}
7810
7811template<typename Derived>
7812QualType
7813TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
7814 ObjCInterfaceTypeLoc TL) {
7815 // ObjCInterfaceType is never dependent.
7816 TLB.pushFullCopy(TL);
7817 return TL.getType();
7818}
7819
7820template<typename Derived>
7821QualType
7822TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
7823 ObjCTypeParamTypeLoc TL) {
7824 const ObjCTypeParamType *T = TL.getTypePtr();
7825 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7826 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7827 if (!OTP)
7828 return QualType();
7829
7830 QualType Result = TL.getType();
7831 if (getDerived().AlwaysRebuild() ||
7832 OTP != T->getDecl()) {
7833 Result = getDerived().RebuildObjCTypeParamType(
7834 OTP, TL.getProtocolLAngleLoc(),
7835 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7836 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7837 if (Result.isNull())
7838 return QualType();
7839 }
7840
7841 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
7842 if (TL.getNumProtocols()) {
7843 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7844 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7845 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7846 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7847 }
7848 return Result;
7849}
7850
7851template<typename Derived>
7852QualType
7853TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
7854 ObjCObjectTypeLoc TL) {
7855 // Transform base type.
7856 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7857 if (BaseType.isNull())
7858 return QualType();
7859
7860 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7861
7862 // Transform type arguments.
7863 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7864 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7865 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7866 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7867 QualType TypeArg = TypeArgInfo->getType();
7868 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7869 AnyChanged = true;
7870
7871 // We have a pack expansion. Instantiate it.
7872 const auto *PackExpansion = PackExpansionLoc.getType()
7873 ->castAs<PackExpansionType>();
7875 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7876 Unexpanded);
7877 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7878
7879 // Determine whether the set of unexpanded parameter packs can
7880 // and should be expanded.
7881 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7882 bool Expand = false;
7883 bool RetainExpansion = false;
7884 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
7885 if (getDerived().TryExpandParameterPacks(
7886 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7887 Unexpanded, Expand, RetainExpansion, NumExpansions))
7888 return QualType();
7889
7890 if (!Expand) {
7891 // We can't expand this pack expansion into separate arguments yet;
7892 // just substitute into the pattern and create a new pack expansion
7893 // type.
7894 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7895
7896 TypeLocBuilder TypeArgBuilder;
7897 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7898 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7899 PatternLoc);
7900 if (NewPatternType.isNull())
7901 return QualType();
7902
7903 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7904 NewPatternType, NumExpansions);
7905 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7906 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7907 NewTypeArgInfos.push_back(
7908 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7909 continue;
7910 }
7911
7912 // Substitute into the pack expansion pattern for each slice of the
7913 // pack.
7914 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7915 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
7916
7917 TypeLocBuilder TypeArgBuilder;
7918 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7919
7920 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7921 PatternLoc);
7922 if (NewTypeArg.isNull())
7923 return QualType();
7924
7925 NewTypeArgInfos.push_back(
7926 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7927 }
7928
7929 continue;
7930 }
7931
7932 TypeLocBuilder TypeArgBuilder;
7933 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7934 QualType NewTypeArg =
7935 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7936 if (NewTypeArg.isNull())
7937 return QualType();
7938
7939 // If nothing changed, just keep the old TypeSourceInfo.
7940 if (NewTypeArg == TypeArg) {
7941 NewTypeArgInfos.push_back(TypeArgInfo);
7942 continue;
7943 }
7944
7945 NewTypeArgInfos.push_back(
7946 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7947 AnyChanged = true;
7948 }
7949
7950 QualType Result = TL.getType();
7951 if (getDerived().AlwaysRebuild() || AnyChanged) {
7952 // Rebuild the type.
7953 Result = getDerived().RebuildObjCObjectType(
7954 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
7955 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
7956 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7957 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7958
7959 if (Result.isNull())
7960 return QualType();
7961 }
7962
7963 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
7964 NewT.setHasBaseTypeAsWritten(true);
7965 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
7966 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
7967 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
7968 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
7969 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7970 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7971 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
7972 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7973 return Result;
7974}
7975
7976template<typename Derived>
7977QualType
7978TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
7979 ObjCObjectPointerTypeLoc TL) {
7980 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7981 if (PointeeType.isNull())
7982 return QualType();
7983
7984 QualType Result = TL.getType();
7985 if (getDerived().AlwaysRebuild() ||
7986 PointeeType != TL.getPointeeLoc().getType()) {
7987 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7988 TL.getStarLoc());
7989 if (Result.isNull())
7990 return QualType();
7991 }
7992
7993 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
7994 NewT.setStarLoc(TL.getStarLoc());
7995 return Result;
7996}
7997
7998//===----------------------------------------------------------------------===//
7999// Statement transformation
8000//===----------------------------------------------------------------------===//
8001template<typename Derived>
8003TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
8004 return S;
8005}
8006
8007template<typename Derived>
8010 return getDerived().TransformCompoundStmt(S, false);
8011}
8012
8013template<typename Derived>
8016 bool IsStmtExpr) {
8017 Sema::CompoundScopeRAII CompoundScope(getSema());
8018 Sema::FPFeaturesStateRAII FPSave(getSema());
8019 if (S->hasStoredFPFeatures())
8020 getSema().resetFPOptions(
8021 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8022
8023 const Stmt *ExprResult = S->getStmtExprResult();
8024 bool SubStmtInvalid = false;
8025 bool SubStmtChanged = false;
8026 SmallVector<Stmt*, 8> Statements;
8027 for (auto *B : S->body()) {
8028 StmtResult Result = getDerived().TransformStmt(
8029 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
8030
8031 if (Result.isInvalid()) {
8032 // Immediately fail if this was a DeclStmt, since it's very
8033 // likely that this will cause problems for future statements.
8034 if (isa<DeclStmt>(B))
8035 return StmtError();
8036
8037 // Otherwise, just keep processing substatements and fail later.
8038 SubStmtInvalid = true;
8039 continue;
8040 }
8041
8042 SubStmtChanged = SubStmtChanged || Result.get() != B;
8043 Statements.push_back(Result.getAs<Stmt>());
8044 }
8045
8046 if (SubStmtInvalid)
8047 return StmtError();
8048
8049 if (!getDerived().AlwaysRebuild() &&
8050 !SubStmtChanged)
8051 return S;
8052
8053 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8054 Statements,
8055 S->getRBracLoc(),
8056 IsStmtExpr);
8057}
8058
8059template<typename Derived>
8061TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
8062 ExprResult LHS, RHS;
8063 {
8064 EnterExpressionEvaluationContext Unevaluated(
8066
8067 // Transform the left-hand case value.
8068 LHS = getDerived().TransformExpr(S->getLHS());
8069 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8070 if (LHS.isInvalid())
8071 return StmtError();
8072
8073 // Transform the right-hand case value (for the GNU case-range extension).
8074 RHS = getDerived().TransformExpr(S->getRHS());
8075 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8076 if (RHS.isInvalid())
8077 return StmtError();
8078 }
8079
8080 // Build the case statement.
8081 // Case statements are always rebuilt so that they will attached to their
8082 // transformed switch statement.
8083 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8084 LHS.get(),
8085 S->getEllipsisLoc(),
8086 RHS.get(),
8087 S->getColonLoc());
8088 if (Case.isInvalid())
8089 return StmtError();
8090
8091 // Transform the statement following the case
8092 StmtResult SubStmt =
8093 getDerived().TransformStmt(S->getSubStmt());
8094 if (SubStmt.isInvalid())
8095 return StmtError();
8096
8097 // Attach the body to the case statement
8098 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8099}
8100
8101template <typename Derived>
8102StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
8103 // Transform the statement following the default case
8104 StmtResult SubStmt =
8105 getDerived().TransformStmt(S->getSubStmt());
8106 if (SubStmt.isInvalid())
8107 return StmtError();
8108
8109 // Default statements are always rebuilt
8110 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8111 SubStmt.get());
8112}
8113
8114template<typename Derived>
8116TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
8117 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8118 if (SubStmt.isInvalid())
8119 return StmtError();
8120
8121 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8122 S->getDecl());
8123 if (!LD)
8124 return StmtError();
8125
8126 // If we're transforming "in-place" (we're not creating new local
8127 // declarations), assume we're replacing the old label statement
8128 // and clear out the reference to it.
8129 if (LD == S->getDecl())
8130 S->getDecl()->setStmt(nullptr);
8131
8132 // FIXME: Pass the real colon location in.
8133 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8134 cast<LabelDecl>(LD), SourceLocation(),
8135 SubStmt.get());
8136}
8137
8138template <typename Derived>
8140 if (!R)
8141 return R;
8142
8143 switch (R->getKind()) {
8144// Transform attributes by calling TransformXXXAttr.
8145#define ATTR(X) \
8146 case attr::X: \
8147 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8148#include "clang/Basic/AttrList.inc"
8149 }
8150 return R;
8151}
8152
8153template <typename Derived>
8155 const Stmt *InstS,
8156 const Attr *R) {
8157 if (!R)
8158 return R;
8159
8160 switch (R->getKind()) {
8161// Transform attributes by calling TransformStmtXXXAttr.
8162#define ATTR(X) \
8163 case attr::X: \
8164 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8165#include "clang/Basic/AttrList.inc"
8166 }
8167 return TransformAttr(R);
8168}
8169
8170template <typename Derived>
8173 StmtDiscardKind SDK) {
8174 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8175 if (SubStmt.isInvalid())
8176 return StmtError();
8177
8178 bool AttrsChanged = false;
8180
8181 // Visit attributes and keep track if any are transformed.
8182 for (const auto *I : S->getAttrs()) {
8183 const Attr *R =
8184 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8185 AttrsChanged |= (I != R);
8186 if (R)
8187 Attrs.push_back(R);
8188 }
8189
8190 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8191 return S;
8192
8193 // If transforming the attributes failed for all of the attributes in the
8194 // statement, don't make an AttributedStmt without attributes.
8195 if (Attrs.empty())
8196 return SubStmt;
8197
8198 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8199 SubStmt.get());
8200}
8201
8202template<typename Derived>
8204TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
8205 // Transform the initialization statement
8206 StmtResult Init = getDerived().TransformStmt(S->getInit());
8207 if (Init.isInvalid())
8208 return StmtError();
8209
8210 Sema::ConditionResult Cond;
8211 if (!S->isConsteval()) {
8212 // Transform the condition
8213 Cond = getDerived().TransformCondition(
8214 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8215 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8217 if (Cond.isInvalid())
8218 return StmtError();
8219 }
8220
8221 // If this is a constexpr if, determine which arm we should instantiate.
8222 std::optional<bool> ConstexprConditionValue;
8223 if (S->isConstexpr())
8224 ConstexprConditionValue = Cond.getKnownValue();
8225
8226 // Transform the "then" branch.
8227 StmtResult Then;
8228 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8229 EnterExpressionEvaluationContext Ctx(
8232 S->isNonNegatedConsteval());
8233
8234 Then = getDerived().TransformStmt(S->getThen());
8235 if (Then.isInvalid())
8236 return StmtError();
8237 } else {
8238 // Discarded branch is replaced with empty CompoundStmt so we can keep
8239 // proper source location for start and end of original branch, so
8240 // subsequent transformations like CoverageMapping work properly
8241 Then = new (getSema().Context)
8242 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8243 }
8244
8245 // Transform the "else" branch.
8246 StmtResult Else;
8247 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8248 EnterExpressionEvaluationContext Ctx(
8251 S->isNegatedConsteval());
8252
8253 Else = getDerived().TransformStmt(S->getElse());
8254 if (Else.isInvalid())
8255 return StmtError();
8256 } else if (S->getElse() && ConstexprConditionValue &&
8257 *ConstexprConditionValue) {
8258 // Same thing here as with <then> branch, we are discarding it, we can't
8259 // replace it with NULL nor NullStmt as we need to keep for source location
8260 // range, for CoverageMapping
8261 Else = new (getSema().Context)
8262 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8263 }
8264
8265 if (!getDerived().AlwaysRebuild() &&
8266 Init.get() == S->getInit() &&
8267 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8268 Then.get() == S->getThen() &&
8269 Else.get() == S->getElse())
8270 return S;
8271
8272 return getDerived().RebuildIfStmt(
8273 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8274 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8275}
8276
8277template<typename Derived>
8279TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
8280 // Transform the initialization statement
8281 StmtResult Init = getDerived().TransformStmt(S->getInit());
8282 if (Init.isInvalid())
8283 return StmtError();
8284
8285 // Transform the condition.
8286 Sema::ConditionResult Cond = getDerived().TransformCondition(
8287 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8289 if (Cond.isInvalid())
8290 return StmtError();
8291
8292 // Rebuild the switch statement.
8294 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8295 Init.get(), Cond, S->getRParenLoc());
8296 if (Switch.isInvalid())
8297 return StmtError();
8298
8299 // Transform the body of the switch statement.
8300 StmtResult Body = getDerived().TransformStmt(S->getBody());
8301 if (Body.isInvalid())
8302 return StmtError();
8303
8304 // Complete the switch statement.
8305 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8306 Body.get());
8307}
8308
8309template<typename Derived>
8311TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
8312 // Transform the condition
8313 Sema::ConditionResult Cond = getDerived().TransformCondition(
8314 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8316 if (Cond.isInvalid())
8317 return StmtError();
8318
8319 // OpenACC Restricts a while-loop inside of certain construct/clause
8320 // combinations, so diagnose that here in OpenACC mode.
8321 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8322 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8323
8324 // Transform the body
8325 StmtResult Body = getDerived().TransformStmt(S->getBody());
8326 if (Body.isInvalid())
8327 return StmtError();
8328
8329 if (!getDerived().AlwaysRebuild() &&
8330 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8331 Body.get() == S->getBody())
8332 return Owned(S);
8333
8334 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8335 Cond, S->getRParenLoc(), Body.get());
8336}
8337
8338template<typename Derived>
8340TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
8341 // OpenACC Restricts a do-loop inside of certain construct/clause
8342 // combinations, so diagnose that here in OpenACC mode.
8343 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8344 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8345
8346 // Transform the body
8347 StmtResult Body = getDerived().TransformStmt(S->getBody());
8348 if (Body.isInvalid())
8349 return StmtError();
8350
8351 // Transform the condition
8352 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8353 if (Cond.isInvalid())
8354 return StmtError();
8355
8356 if (!getDerived().AlwaysRebuild() &&
8357 Cond.get() == S->getCond() &&
8358 Body.get() == S->getBody())
8359 return S;
8360
8361 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8362 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8363 S->getRParenLoc());
8364}
8365
8366template<typename Derived>
8368TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
8369 if (getSema().getLangOpts().OpenMP)
8370 getSema().OpenMP().startOpenMPLoop();
8371
8372 // Transform the initialization statement
8373 StmtResult Init = getDerived().TransformStmt(S->getInit());
8374 if (Init.isInvalid())
8375 return StmtError();
8376
8377 // In OpenMP loop region loop control variable must be captured and be
8378 // private. Perform analysis of first part (if any).
8379 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8380 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8381 Init.get());
8382
8383 // Transform the condition
8384 Sema::ConditionResult Cond = getDerived().TransformCondition(
8385 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8387 if (Cond.isInvalid())
8388 return StmtError();
8389
8390 // Transform the increment
8391 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8392 if (Inc.isInvalid())
8393 return StmtError();
8394
8395 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8396 if (S->getInc() && !FullInc.get())
8397 return StmtError();
8398
8399 // OpenACC Restricts a for-loop inside of certain construct/clause
8400 // combinations, so diagnose that here in OpenACC mode.
8401 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8402 SemaRef.OpenACC().ActOnForStmtBegin(
8403 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8404 Cond.get().second, S->getInc(), Inc.get());
8405
8406 // Transform the body
8407 StmtResult Body = getDerived().TransformStmt(S->getBody());
8408 if (Body.isInvalid())
8409 return StmtError();
8410
8411 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8412
8413 if (!getDerived().AlwaysRebuild() &&
8414 Init.get() == S->getInit() &&
8415 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8416 Inc.get() == S->getInc() &&
8417 Body.get() == S->getBody())
8418 return S;
8419
8420 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8421 Init.get(), Cond, FullInc,
8422 S->getRParenLoc(), Body.get());
8423}
8424
8425template<typename Derived>
8427TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
8428 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8429 S->getLabel());
8430 if (!LD)
8431 return StmtError();
8432
8433 // Goto statements must always be rebuilt, to resolve the label.
8434 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8435 cast<LabelDecl>(LD));
8436}
8437
8438template<typename Derived>
8440TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
8441 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8442 if (Target.isInvalid())
8443 return StmtError();
8444 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8445
8446 if (!getDerived().AlwaysRebuild() &&
8447 Target.get() == S->getTarget())
8448 return S;
8449
8450 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8451 Target.get());
8452}
8453
8454template<typename Derived>
8456TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
8457 return S;
8458}
8459
8460template<typename Derived>
8462TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
8463 return S;
8464}
8465
8466template<typename Derived>
8468TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
8469 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8470 /*NotCopyInit*/false);
8471 if (Result.isInvalid())
8472 return StmtError();
8473
8474 // FIXME: We always rebuild the return statement because there is no way
8475 // to tell whether the return type of the function has changed.
8476 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8477}
8478
8479template<typename Derived>
8481TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
8482 bool DeclChanged = false;
8484 LambdaScopeInfo *LSI = getSema().getCurLambda();
8485 for (auto *D : S->decls()) {
8486 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8487 if (!Transformed)
8488 return StmtError();
8489
8490 if (Transformed != D)
8491 DeclChanged = true;
8492
8493 if (LSI) {
8494 if (auto *TD = dyn_cast<TypeDecl>(Transformed))
8495 LSI->ContainsUnexpandedParameterPack |=
8496 getSema()
8497 .getASTContext()
8498 .getTypeDeclType(TD)
8499 .getCanonicalType()
8500 ->containsUnexpandedParameterPack();
8501
8502 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8503 LSI->ContainsUnexpandedParameterPack |=
8504 VD->getType()->containsUnexpandedParameterPack();
8505 }
8506
8507 Decls.push_back(Transformed);
8508 }
8509
8510 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8511 return S;
8512
8513 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8514}
8515
8516template<typename Derived>
8518TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
8519
8520 SmallVector<Expr*, 8> Constraints;
8523
8524 ExprResult AsmString;
8525 SmallVector<Expr*, 8> Clobbers;
8526
8527 bool ExprsChanged = false;
8528
8529 // Go through the outputs.
8530 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8531 Names.push_back(S->getOutputIdentifier(I));
8532
8533 // No need to transform the constraint literal.
8534 Constraints.push_back(S->getOutputConstraintLiteral(I));
8535
8536 // Transform the output expr.
8537 Expr *OutputExpr = S->getOutputExpr(I);
8538 ExprResult Result = getDerived().TransformExpr(OutputExpr);
8539 if (Result.isInvalid())
8540 return StmtError();
8541
8542 ExprsChanged |= Result.get() != OutputExpr;
8543
8544 Exprs.push_back(Result.get());
8545 }
8546
8547 // Go through the inputs.
8548 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8549 Names.push_back(S->getInputIdentifier(I));
8550
8551 // No need to transform the constraint literal.
8552 Constraints.push_back(S->getInputConstraintLiteral(I));
8553
8554 // Transform the input expr.
8555 Expr *InputExpr = S->getInputExpr(I);
8556 ExprResult Result = getDerived().TransformExpr(InputExpr);
8557 if (Result.isInvalid())
8558 return StmtError();
8559
8560 ExprsChanged |= Result.get() != InputExpr;
8561
8562 Exprs.push_back(Result.get());
8563 }
8564
8565 // Go through the Labels.
8566 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8567 Names.push_back(S->getLabelIdentifier(I));
8568
8569 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8570 if (Result.isInvalid())
8571 return StmtError();
8572 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8573 Exprs.push_back(Result.get());
8574 }
8575 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8576 return S;
8577
8578 // Go through the clobbers.
8579 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
8580 Clobbers.push_back(S->getClobberStringLiteral(I));
8581
8582 // No need to transform the asm string literal.
8583 AsmString = S->getAsmString();
8584 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8585 S->isVolatile(), S->getNumOutputs(),
8586 S->getNumInputs(), Names.data(),
8587 Constraints, Exprs, AsmString.get(),
8588 Clobbers, S->getNumLabels(),
8589 S->getRParenLoc());
8590}
8591
8592template<typename Derived>
8594TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
8595 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8596
8597 bool HadError = false, HadChange = false;
8598
8599 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8600 SmallVector<Expr*, 8> TransformedExprs;
8601 TransformedExprs.reserve(SrcExprs.size());
8602 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8603 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8604 if (!Result.isUsable()) {
8605 HadError = true;
8606 } else {
8607 HadChange |= (Result.get() != SrcExprs[i]);
8608 TransformedExprs.push_back(Result.get());
8609 }
8610 }
8611
8612 if (HadError) return StmtError();
8613 if (!HadChange && !getDerived().AlwaysRebuild())
8614 return Owned(S);
8615
8616 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8617 AsmToks, S->getAsmString(),
8618 S->getNumOutputs(), S->getNumInputs(),
8619 S->getAllConstraints(), S->getClobbers(),
8620 TransformedExprs, S->getEndLoc());
8621}
8622
8623// C++ Coroutines
8624template<typename Derived>
8626TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
8627 auto *ScopeInfo = SemaRef.getCurFunction();
8628 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8629 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8630 ScopeInfo->NeedsCoroutineSuspends &&
8631 ScopeInfo->CoroutineSuspends.first == nullptr &&
8632 ScopeInfo->CoroutineSuspends.second == nullptr &&
8633 "expected clean scope info");
8634
8635 // Set that we have (possibly-invalid) suspend points before we do anything
8636 // that may fail.
8637 ScopeInfo->setNeedsCoroutineSuspends(false);
8638
8639 // We re-build the coroutine promise object (and the coroutine parameters its
8640 // type and constructor depend on) based on the types used in our current
8641 // function. We must do so, and set it on the current FunctionScopeInfo,
8642 // before attempting to transform the other parts of the coroutine body
8643 // statement, such as the implicit suspend statements (because those
8644 // statements reference the FunctionScopeInfo::CoroutinePromise).
8645 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8646 return StmtError();
8647 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8648 if (!Promise)
8649 return StmtError();
8650 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8651 ScopeInfo->CoroutinePromise = Promise;
8652
8653 // Transform the implicit coroutine statements constructed using dependent
8654 // types during the previous parse: initial and final suspensions, the return
8655 // object, and others. We also transform the coroutine function's body.
8656 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8657 if (InitSuspend.isInvalid())
8658 return StmtError();
8659 StmtResult FinalSuspend =
8660 getDerived().TransformStmt(S->getFinalSuspendStmt());
8661 if (FinalSuspend.isInvalid() ||
8662 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8663 return StmtError();
8664 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8665 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8666
8667 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8668 if (BodyRes.isInvalid())
8669 return StmtError();
8670
8671 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8672 if (Builder.isInvalid())
8673 return StmtError();
8674
8675 Expr *ReturnObject = S->getReturnValueInit();
8676 assert(ReturnObject && "the return object is expected to be valid");
8677 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8678 /*NoCopyInit*/ false);
8679 if (Res.isInvalid())
8680 return StmtError();
8681 Builder.ReturnValue = Res.get();
8682
8683 // If during the previous parse the coroutine still had a dependent promise
8684 // statement, we may need to build some implicit coroutine statements
8685 // (such as exception and fallthrough handlers) for the first time.
8686 if (S->hasDependentPromiseType()) {
8687 // We can only build these statements, however, if the current promise type
8688 // is not dependent.
8689 if (!Promise->getType()->isDependentType()) {
8690 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8691 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8692 "these nodes should not have been built yet");
8693 if (!Builder.buildDependentStatements())
8694 return StmtError();
8695 }
8696 } else {
8697 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8698 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8699 if (Res.isInvalid())
8700 return StmtError();
8701 Builder.OnFallthrough = Res.get();
8702 }
8703
8704 if (auto *OnException = S->getExceptionHandler()) {
8705 StmtResult Res = getDerived().TransformStmt(OnException);
8706 if (Res.isInvalid())
8707 return StmtError();
8708 Builder.OnException = Res.get();
8709 }
8710
8711 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8712 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8713 if (Res.isInvalid())
8714 return StmtError();
8715 Builder.ReturnStmtOnAllocFailure = Res.get();
8716 }
8717
8718 // Transform any additional statements we may have already built
8719 assert(S->getAllocate() && S->getDeallocate() &&
8720 "allocation and deallocation calls must already be built");
8721 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8722 if (AllocRes.isInvalid())
8723 return StmtError();
8724 Builder.Allocate = AllocRes.get();
8725
8726 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8727 if (DeallocRes.isInvalid())
8728 return StmtError();
8729 Builder.Deallocate = DeallocRes.get();
8730
8731 if (auto *ResultDecl = S->getResultDecl()) {
8732 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8733 if (Res.isInvalid())
8734 return StmtError();
8735 Builder.ResultDecl = Res.get();
8736 }
8737
8738 if (auto *ReturnStmt = S->getReturnStmt()) {
8739 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8740 if (Res.isInvalid())
8741 return StmtError();
8742 Builder.ReturnStmt = Res.get();
8743 }
8744 }
8745
8746 return getDerived().RebuildCoroutineBodyStmt(Builder);
8747}
8748
8749template<typename Derived>
8751TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
8752 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8753 /*NotCopyInit*/false);
8754 if (Result.isInvalid())
8755 return StmtError();
8756
8757 // Always rebuild; we don't know if this needs to be injected into a new
8758 // context or if the promise type has changed.
8759 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8760 S->isImplicit());
8761}
8762
8763template <typename Derived>
8764ExprResult TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
8765 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8766 /*NotCopyInit*/ false);
8767 if (Operand.isInvalid())
8768 return ExprError();
8769
8770 // Rebuild the common-expr from the operand rather than transforming it
8771 // separately.
8772
8773 // FIXME: getCurScope() should not be used during template instantiation.
8774 // We should pick up the set of unqualified lookup results for operator
8775 // co_await during the initial parse.
8776 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8777 getSema().getCurScope(), E->getKeywordLoc());
8778
8779 // Always rebuild; we don't know if this needs to be injected into a new
8780 // context or if the promise type has changed.
8781 return getDerived().RebuildCoawaitExpr(
8782 E->getKeywordLoc(), Operand.get(),
8783 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8784}
8785
8786template <typename Derived>
8788TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
8789 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8790 /*NotCopyInit*/ false);
8791 if (OperandResult.isInvalid())
8792 return ExprError();
8793
8794 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8795 E->getOperatorCoawaitLookup());
8796
8797 if (LookupResult.isInvalid())
8798 return ExprError();
8799
8800 // Always rebuild; we don't know if this needs to be injected into a new
8801 // context or if the promise type has changed.
8802 return getDerived().RebuildDependentCoawaitExpr(
8803 E->getKeywordLoc(), OperandResult.get(),
8804 cast<UnresolvedLookupExpr>(LookupResult.get()));
8805}
8806
8807template<typename Derived>
8809TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
8810 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8811 /*NotCopyInit*/false);
8812 if (Result.isInvalid())
8813 return ExprError();
8814
8815 // Always rebuild; we don't know if this needs to be injected into a new
8816 // context or if the promise type has changed.
8817 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8818}
8819
8820// Objective-C Statements.
8821
8822template<typename Derived>
8824TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
8825 // Transform the body of the @try.
8826 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8827 if (TryBody.isInvalid())
8828 return StmtError();
8829
8830 // Transform the @catch statements (if present).
8831 bool AnyCatchChanged = false;
8832 SmallVector<Stmt*, 8> CatchStmts;
8833 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8834 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8835 if (Catch.isInvalid())
8836 return StmtError();
8837 if (Catch.get() != S->getCatchStmt(I))
8838 AnyCatchChanged = true;
8839 CatchStmts.push_back(Catch.get());
8840 }
8841
8842 // Transform the @finally statement (if present).
8843 StmtResult Finally;
8844 if (S->getFinallyStmt()) {
8845 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8846 if (Finally.isInvalid())
8847 return StmtError();
8848 }
8849
8850 // If nothing changed, just retain this statement.
8851 if (!getDerived().AlwaysRebuild() &&
8852 TryBody.get() == S->getTryBody() &&
8853 !AnyCatchChanged &&
8854 Finally.get() == S->getFinallyStmt())
8855 return S;
8856
8857 // Build a new statement.
8858 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8859 CatchStmts, Finally.get());
8860}
8861
8862template<typename Derived>
8864TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
8865 // Transform the @catch parameter, if there is one.
8866 VarDecl *Var = nullptr;
8867 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8868 TypeSourceInfo *TSInfo = nullptr;
8869 if (FromVar->getTypeSourceInfo()) {
8870 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8871 if (!TSInfo)
8872 return StmtError();
8873 }
8874
8875 QualType T;
8876 if (TSInfo)
8877 T = TSInfo->getType();
8878 else {
8879 T = getDerived().TransformType(FromVar->getType());
8880 if (T.isNull())
8881 return StmtError();
8882 }
8883
8884 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8885 if (!Var)
8886 return StmtError();
8887 }
8888
8889 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8890 if (Body.isInvalid())
8891 return StmtError();
8892
8893 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8894 S->getRParenLoc(),
8895 Var, Body.get());
8896}
8897
8898template<typename Derived>
8900TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
8901 // Transform the body.
8902 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8903 if (Body.isInvalid())
8904 return StmtError();
8905
8906 // If nothing changed, just retain this statement.
8907 if (!getDerived().AlwaysRebuild() &&
8908 Body.get() == S->getFinallyBody())
8909 return S;
8910
8911 // Build a new statement.
8912 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8913 Body.get());
8914}
8915
8916template<typename Derived>
8918TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
8920 if (S->getThrowExpr()) {
8921 Operand = getDerived().TransformExpr(S->getThrowExpr());
8922 if (Operand.isInvalid())
8923 return StmtError();
8924 }
8925
8926 if (!getDerived().AlwaysRebuild() &&
8927 Operand.get() == S->getThrowExpr())
8928 return S;
8929
8930 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8931}
8932
8933template<typename Derived>
8935TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
8936 ObjCAtSynchronizedStmt *S) {
8937 // Transform the object we are locking.
8938 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
8939 if (Object.isInvalid())
8940 return StmtError();
8941 Object =
8942 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8943 Object.get());
8944 if (Object.isInvalid())
8945 return StmtError();
8946
8947 // Transform the body.
8948 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8949 if (Body.isInvalid())
8950 return StmtError();
8951
8952 // If nothing change, just retain the current statement.
8953 if (!getDerived().AlwaysRebuild() &&
8954 Object.get() == S->getSynchExpr() &&
8955 Body.get() == S->getSynchBody())
8956 return S;
8957
8958 // Build a new statement.
8959 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
8960 Object.get(), Body.get());
8961}
8962
8963template<typename Derived>
8965TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
8966 ObjCAutoreleasePoolStmt *S) {
8967 // Transform the body.
8968 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
8969 if (Body.isInvalid())
8970 return StmtError();
8971
8972 // If nothing changed, just retain this statement.
8973 if (!getDerived().AlwaysRebuild() &&
8974 Body.get() == S->getSubStmt())
8975 return S;
8976
8977 // Build a new statement.
8978 return getDerived().RebuildObjCAutoreleasePoolStmt(
8979 S->getAtLoc(), Body.get());
8980}
8981
8982template<typename Derived>
8984TreeTransform<Derived>::TransformObjCForCollectionStmt(
8985 ObjCForCollectionStmt *S) {
8986 // Transform the element statement.
8987 StmtResult Element =
8988 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
8989 if (Element.isInvalid())
8990 return StmtError();
8991
8992 // Transform the collection expression.
8993 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
8994 if (Collection.isInvalid())
8995 return StmtError();
8996
8997 // Transform the body.
8998 StmtResult Body = getDerived().TransformStmt(S->getBody());
8999 if (Body.isInvalid())
9000 return StmtError();
9001
9002 // If nothing changed, just retain this statement.
9003 if (!getDerived().AlwaysRebuild() &&
9004 Element.get() == S->getElement() &&
9005 Collection.get() == S->getCollection() &&
9006 Body.get() == S->getBody())
9007 return S;
9008
9009 // Build a new statement.
9010 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9011 Element.get(),
9012 Collection.get(),
9013 S->getRParenLoc(),
9014 Body.get());
9015}
9016
9017template <typename Derived>
9018StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
9019 // Transform the exception declaration, if any.
9020 VarDecl *Var = nullptr;
9021 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9022 TypeSourceInfo *T =
9023 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9024 if (!T)
9025 return StmtError();
9026
9027 Var = getDerived().RebuildExceptionDecl(
9028 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9029 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9030 if (!Var || Var->isInvalidDecl())
9031 return StmtError();
9032 }
9033
9034 // Transform the actual exception handler.
9035 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9036 if (Handler.isInvalid())
9037 return StmtError();
9038
9039 if (!getDerived().AlwaysRebuild() && !Var &&
9040 Handler.get() == S->getHandlerBlock())
9041 return S;
9042
9043 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9044}
9045
9046template <typename Derived>
9047StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
9048 // Transform the try block itself.
9049 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9050 if (TryBlock.isInvalid())
9051 return StmtError();
9052
9053 // Transform the handlers.
9054 bool HandlerChanged = false;
9055 SmallVector<Stmt *, 8> Handlers;
9056 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9057 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9058 if (Handler.isInvalid())
9059 return StmtError();
9060
9061 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9062 Handlers.push_back(Handler.getAs<Stmt>());
9063 }
9064
9065 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9066 !HandlerChanged)
9067 return S;
9068
9069 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9070 Handlers);
9071}
9072
9073template<typename Derived>
9075TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
9076 EnterExpressionEvaluationContext ForRangeInitContext(
9078 /*LambdaContextDecl=*/nullptr,
9080 getSema().getLangOpts().CPlusPlus23);
9081
9082 // P2718R0 - Lifetime extension in range-based for loops.
9083 if (getSema().getLangOpts().CPlusPlus23) {
9084 auto &LastRecord = getSema().currentEvaluationContext();
9085 LastRecord.InLifetimeExtendingContext = true;
9086 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9087 }
9089 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9090 if (Init.isInvalid())
9091 return StmtError();
9092
9093 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9094 if (Range.isInvalid())
9095 return StmtError();
9096
9097 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9098 assert(getSema().getLangOpts().CPlusPlus23 ||
9099 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9100 auto ForRangeLifetimeExtendTemps =
9101 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9102
9103 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9104 if (Begin.isInvalid())
9105 return StmtError();
9106 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9107 if (End.isInvalid())
9108 return StmtError();
9109
9110 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9111 if (Cond.isInvalid())
9112 return StmtError();
9113 if (Cond.get())
9114 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9115 if (Cond.isInvalid())
9116 return StmtError();
9117 if (Cond.get())
9118 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9119
9120 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9121 if (Inc.isInvalid())
9122 return StmtError();
9123 if (Inc.get())
9124 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9125
9126 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9127 if (LoopVar.isInvalid())
9128 return StmtError();
9129
9130 StmtResult NewStmt = S;
9131 if (getDerived().AlwaysRebuild() ||
9132 Init.get() != S->getInit() ||
9133 Range.get() != S->getRangeStmt() ||
9134 Begin.get() != S->getBeginStmt() ||
9135 End.get() != S->getEndStmt() ||
9136 Cond.get() != S->getCond() ||
9137 Inc.get() != S->getInc() ||
9138 LoopVar.get() != S->getLoopVarStmt()) {
9139 NewStmt = getDerived().RebuildCXXForRangeStmt(
9140 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9141 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9142 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9143 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9144 // Might not have attached any initializer to the loop variable.
9145 getSema().ActOnInitializerError(
9146 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9147 return StmtError();
9148 }
9149 }
9150
9151 // OpenACC Restricts a while-loop inside of certain construct/clause
9152 // combinations, so diagnose that here in OpenACC mode.
9153 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
9154 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9155
9156 StmtResult Body = getDerived().TransformStmt(S->getBody());
9157 if (Body.isInvalid())
9158 return StmtError();
9159
9160 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9161
9162 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9163 // it now so we have a new statement to attach the body to.
9164 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9165 NewStmt = getDerived().RebuildCXXForRangeStmt(
9166 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9167 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9168 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9169 if (NewStmt.isInvalid())
9170 return StmtError();
9171 }
9172
9173 if (NewStmt.get() == S)
9174 return S;
9175
9176 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9177}
9178
9179template<typename Derived>
9181TreeTransform<Derived>::TransformMSDependentExistsStmt(
9182 MSDependentExistsStmt *S) {
9183 // Transform the nested-name-specifier, if any.
9184 NestedNameSpecifierLoc QualifierLoc;
9185 if (S->getQualifierLoc()) {
9186 QualifierLoc
9187 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9188 if (!QualifierLoc)
9189 return StmtError();
9190 }
9191
9192 // Transform the declaration name.
9193 DeclarationNameInfo NameInfo = S->getNameInfo();
9194 if (NameInfo.getName()) {
9195 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9196 if (!NameInfo.getName())
9197 return StmtError();
9198 }
9199
9200 // Check whether anything changed.
9201 if (!getDerived().AlwaysRebuild() &&
9202 QualifierLoc == S->getQualifierLoc() &&
9203 NameInfo.getName() == S->getNameInfo().getName())
9204 return S;
9205
9206 // Determine whether this name exists, if we can.
9207 CXXScopeSpec SS;
9208 SS.Adopt(QualifierLoc);
9209 bool Dependent = false;
9210 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9211 case Sema::IER_Exists:
9212 if (S->isIfExists())
9213 break;
9214
9215 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9216
9218 if (S->isIfNotExists())
9219 break;
9220
9221 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9222
9224 Dependent = true;
9225 break;
9226
9227 case Sema::IER_Error:
9228 return StmtError();
9229 }
9230
9231 // We need to continue with the instantiation, so do so now.
9232 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9233 if (SubStmt.isInvalid())
9234 return StmtError();
9235
9236 // If we have resolved the name, just transform to the substatement.
9237 if (!Dependent)
9238 return SubStmt;
9239
9240 // The name is still dependent, so build a dependent expression again.
9241 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9242 S->isIfExists(),
9243 QualifierLoc,
9244 NameInfo,
9245 SubStmt.get());
9246}
9247
9248template<typename Derived>
9250TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
9251 NestedNameSpecifierLoc QualifierLoc;
9252 if (E->getQualifierLoc()) {
9253 QualifierLoc
9254 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9255 if (!QualifierLoc)
9256 return ExprError();
9257 }
9258
9259 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9260 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9261 if (!PD)
9262 return ExprError();
9263
9264 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9265 if (Base.isInvalid())
9266 return ExprError();
9267
9268 return new (SemaRef.getASTContext())
9269 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9271 QualifierLoc, E->getMemberLoc());
9272}
9273
9274template <typename Derived>
9275ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
9276 MSPropertySubscriptExpr *E) {
9277 auto BaseRes = getDerived().TransformExpr(E->getBase());
9278 if (BaseRes.isInvalid())
9279 return ExprError();
9280 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9281 if (IdxRes.isInvalid())
9282 return ExprError();
9283
9284 if (!getDerived().AlwaysRebuild() &&
9285 BaseRes.get() == E->getBase() &&
9286 IdxRes.get() == E->getIdx())
9287 return E;
9288
9289 return getDerived().RebuildArraySubscriptExpr(
9290 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9291}
9292
9293template <typename Derived>
9294StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
9295 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9296 if (TryBlock.isInvalid())
9297 return StmtError();
9298
9299 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9300 if (Handler.isInvalid())
9301 return StmtError();
9302
9303 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9304 Handler.get() == S->getHandler())
9305 return S;
9306
9307 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9308 TryBlock.get(), Handler.get());
9309}
9310
9311template <typename Derived>
9312StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
9313 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9314 if (Block.isInvalid())
9315 return StmtError();
9316
9317 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9318}
9319
9320template <typename Derived>
9321StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
9322 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9323 if (FilterExpr.isInvalid())
9324 return StmtError();
9325
9326 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9327 if (Block.isInvalid())
9328 return StmtError();
9329
9330 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9331 Block.get());
9332}
9333
9334template <typename Derived>
9336 if (isa<SEHFinallyStmt>(Handler))
9337 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9338 else
9339 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9340}
9341
9342template<typename Derived>
9345 return S;
9346}
9347
9348//===----------------------------------------------------------------------===//
9349// OpenMP directive transformation
9350//===----------------------------------------------------------------------===//
9351
9352template <typename Derived>
9354TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9355 // OMPCanonicalLoops are eliminated during transformation, since they will be
9356 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9357 // after transformation.
9358 return getDerived().TransformStmt(L->getLoopStmt());
9359}
9360
9361template <typename Derived>
9364
9365 // Transform the clauses
9367 ArrayRef<OMPClause *> Clauses = D->clauses();
9368 TClauses.reserve(Clauses.size());
9369 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9370 I != E; ++I) {
9371 if (*I) {
9372 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9373 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9374 getDerived().getSema().OpenMP().EndOpenMPClause();
9375 if (Clause)
9376 TClauses.push_back(Clause);
9377 } else {
9378 TClauses.push_back(nullptr);
9379 }
9380 }
9381 StmtResult AssociatedStmt;
9382 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9383 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9384 D->getDirectiveKind(),
9385 /*CurScope=*/nullptr);
9386 StmtResult Body;
9387 {
9388 Sema::CompoundScopeRAII CompoundScope(getSema());
9389 Stmt *CS;
9390 if (D->getDirectiveKind() == OMPD_atomic ||
9391 D->getDirectiveKind() == OMPD_critical ||
9392 D->getDirectiveKind() == OMPD_section ||
9393 D->getDirectiveKind() == OMPD_master)
9394 CS = D->getAssociatedStmt();
9395 else
9396 CS = D->getRawStmt();
9397 Body = getDerived().TransformStmt(CS);
9398 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9399 getSema().getLangOpts().OpenMPIRBuilder)
9400 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9401 }
9402 AssociatedStmt =
9403 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9404 if (AssociatedStmt.isInvalid()) {
9405 return StmtError();
9406 }
9407 }
9408 if (TClauses.size() != Clauses.size()) {
9409 return StmtError();
9410 }
9411
9412 // Transform directive name for 'omp critical' directive.
9413 DeclarationNameInfo DirName;
9414 if (D->getDirectiveKind() == OMPD_critical) {
9415 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9416 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9417 }
9418 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9419 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9420 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9421 } else if (D->getDirectiveKind() == OMPD_cancel) {
9422 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9423 }
9424
9425 return getDerived().RebuildOMPExecutableDirective(
9426 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9427 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9428}
9429
9430/// This is mostly the same as above, but allows 'informational' class
9431/// directives when rebuilding the stmt. It still takes an
9432/// OMPExecutableDirective-type argument because we're reusing that as the
9433/// superclass for the 'assume' directive at present, instead of defining a
9434/// mostly-identical OMPInformationalDirective parent class.
9435template <typename Derived>
9438
9439 // Transform the clauses
9441 ArrayRef<OMPClause *> Clauses = D->clauses();
9442 TClauses.reserve(Clauses.size());
9443 for (OMPClause *C : Clauses) {
9444 if (C) {
9445 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9446 OMPClause *Clause = getDerived().TransformOMPClause(C);
9447 getDerived().getSema().OpenMP().EndOpenMPClause();
9448 if (Clause)
9449 TClauses.push_back(Clause);
9450 } else {
9451 TClauses.push_back(nullptr);
9452 }
9453 }
9454 StmtResult AssociatedStmt;
9455 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9456 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9457 D->getDirectiveKind(),
9458 /*CurScope=*/nullptr);
9459 StmtResult Body;
9460 {
9461 Sema::CompoundScopeRAII CompoundScope(getSema());
9462 assert(D->getDirectiveKind() == OMPD_assume &&
9463 "Unexpected informational directive");
9464 Stmt *CS = D->getAssociatedStmt();
9465 Body = getDerived().TransformStmt(CS);
9466 }
9467 AssociatedStmt =
9468 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9469 if (AssociatedStmt.isInvalid())
9470 return StmtError();
9471 }
9472 if (TClauses.size() != Clauses.size())
9473 return StmtError();
9474
9475 DeclarationNameInfo DirName;
9476
9477 return getDerived().RebuildOMPInformationalDirective(
9478 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9479 D->getBeginLoc(), D->getEndLoc());
9480}
9481
9482template <typename Derived>
9485 // TODO: Fix This
9486 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9487 << getOpenMPDirectiveName(D->getDirectiveKind());
9488 return StmtError();
9489}
9490
9491template <typename Derived>
9493TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9494 DeclarationNameInfo DirName;
9495 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9496 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9497 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9498 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9499 return Res;
9500}
9501
9502template <typename Derived>
9504TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
9505 DeclarationNameInfo DirName;
9506 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9507 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9508 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9509 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9510 return Res;
9511}
9512
9513template <typename Derived>
9515TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
9516 DeclarationNameInfo DirName;
9517 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9518 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9519 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9520 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9521 return Res;
9522}
9523
9524template <typename Derived>
9526TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {
9527 DeclarationNameInfo DirName;
9528 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9529 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9530 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9531 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9532 return Res;
9533}
9534
9535template <typename Derived>
9537TreeTransform<Derived>::TransformOMPReverseDirective(OMPReverseDirective *D) {
9538 DeclarationNameInfo DirName;
9539 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9540 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9541 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9542 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9543 return Res;
9544}
9545
9546template <typename Derived>
9547StmtResult TreeTransform<Derived>::TransformOMPInterchangeDirective(
9548 OMPInterchangeDirective *D) {
9549 DeclarationNameInfo DirName;
9550 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9551 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9552 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9553 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9554 return Res;
9555}
9556
9557template <typename Derived>
9559TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
9560 DeclarationNameInfo DirName;
9561 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9562 OMPD_for, DirName, nullptr, D->getBeginLoc());
9563 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9564 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9565 return Res;
9566}
9567
9568template <typename Derived>
9570TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
9571 DeclarationNameInfo DirName;
9572 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9573 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9574 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9575 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9576 return Res;
9577}
9578
9579template <typename Derived>
9581TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
9582 DeclarationNameInfo DirName;
9583 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9584 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9585 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9586 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9587 return Res;
9588}
9589
9590template <typename Derived>
9592TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
9593 DeclarationNameInfo DirName;
9594 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9595 OMPD_section, DirName, nullptr, D->getBeginLoc());
9596 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9597 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9598 return Res;
9599}
9600
9601template <typename Derived>
9603TreeTransform<Derived>::TransformOMPScopeDirective(OMPScopeDirective *D) {
9604 DeclarationNameInfo DirName;
9605 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9606 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9607 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9608 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9609 return Res;
9610}
9611
9612template <typename Derived>
9614TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
9615 DeclarationNameInfo DirName;
9616 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9617 OMPD_single, DirName, nullptr, D->getBeginLoc());
9618 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9619 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9620 return Res;
9621}
9622
9623template <typename Derived>
9625TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
9626 DeclarationNameInfo DirName;
9627 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9628 OMPD_master, DirName, nullptr, D->getBeginLoc());
9629 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9630 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9631 return Res;
9632}
9633
9634template <typename Derived>
9636TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
9637 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9638 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9639 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9640 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9641 return Res;
9642}
9643
9644template <typename Derived>
9645StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
9646 OMPParallelForDirective *D) {
9647 DeclarationNameInfo DirName;
9648 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9649 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9650 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9651 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9652 return Res;
9653}
9654
9655template <typename Derived>
9656StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
9657 OMPParallelForSimdDirective *D) {
9658 DeclarationNameInfo DirName;
9659 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9660 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9661 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9662 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9663 return Res;
9664}
9665
9666template <typename Derived>
9667StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
9668 OMPParallelMasterDirective *D) {
9669 DeclarationNameInfo DirName;
9670 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9671 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9672 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9673 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9674 return Res;
9675}
9676
9677template <typename Derived>
9678StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective(
9679 OMPParallelMaskedDirective *D) {
9680 DeclarationNameInfo DirName;
9681 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9682 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9683 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9684 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9685 return Res;
9686}
9687
9688template <typename Derived>
9689StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
9690 OMPParallelSectionsDirective *D) {
9691 DeclarationNameInfo DirName;
9692 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9693 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9694 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9695 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9696 return Res;
9697}
9698
9699template <typename Derived>
9701TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
9702 DeclarationNameInfo DirName;
9703 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9704 OMPD_task, DirName, nullptr, D->getBeginLoc());
9705 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9706 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9707 return Res;
9708}
9709
9710template <typename Derived>
9711StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
9712 OMPTaskyieldDirective *D) {
9713 DeclarationNameInfo DirName;
9714 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9715 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9716 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9717 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9718 return Res;
9719}
9720
9721template <typename Derived>
9723TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
9724 DeclarationNameInfo DirName;
9725 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9726 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9727 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9728 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9729 return Res;
9730}
9731
9732template <typename Derived>
9734TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
9735 DeclarationNameInfo DirName;
9736 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9737 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9738 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9739 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9740 return Res;
9741}
9742
9743template <typename Derived>
9745TreeTransform<Derived>::TransformOMPAssumeDirective(OMPAssumeDirective *D) {
9746 DeclarationNameInfo DirName;
9747 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9748 OMPD_assume, DirName, nullptr, D->getBeginLoc());
9749 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
9750 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9751 return Res;
9752}
9753
9754template <typename Derived>
9756TreeTransform<Derived>::TransformOMPErrorDirective(OMPErrorDirective *D) {
9757 DeclarationNameInfo DirName;
9758 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9759 OMPD_error, DirName, nullptr, D->getBeginLoc());
9760 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9761 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9762 return Res;
9763}
9764
9765template <typename Derived>
9766StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
9767 OMPTaskgroupDirective *D) {
9768 DeclarationNameInfo DirName;
9769 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9770 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9771 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9772 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9773 return Res;
9774}
9775
9776template <typename Derived>
9778TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
9779 DeclarationNameInfo DirName;
9780 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9781 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9782 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9783 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9784 return Res;
9785}
9786
9787template <typename Derived>
9789TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
9790 DeclarationNameInfo DirName;
9791 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9792 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9793 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9794 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9795 return Res;
9796}
9797
9798template <typename Derived>
9800TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
9801 DeclarationNameInfo DirName;
9802 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9803 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9804 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9805 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9806 return Res;
9807}
9808
9809template <typename Derived>
9811TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
9812 DeclarationNameInfo DirName;
9813 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9814 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9815 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9816 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9817 return Res;
9818}
9819
9820template <typename Derived>
9822TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
9823 DeclarationNameInfo DirName;
9824 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9825 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9826 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9827 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9828 return Res;
9829}
9830
9831template <typename Derived>
9833TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
9834 DeclarationNameInfo DirName;
9835 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9836 OMPD_target, DirName, nullptr, D->getBeginLoc());
9837 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9838 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9839 return Res;
9840}
9841
9842template <typename Derived>
9843StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
9844 OMPTargetDataDirective *D) {
9845 DeclarationNameInfo DirName;
9846 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9847 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
9848 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9849 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9850 return Res;
9851}
9852
9853template <typename Derived>
9854StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
9855 OMPTargetEnterDataDirective *D) {
9856 DeclarationNameInfo DirName;
9857 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9858 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
9859 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9860 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9861 return Res;
9862}
9863
9864template <typename Derived>
9865StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
9866 OMPTargetExitDataDirective *D) {
9867 DeclarationNameInfo DirName;
9868 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9869 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
9870 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9871 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9872 return Res;
9873}
9874
9875template <typename Derived>
9876StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
9877 OMPTargetParallelDirective *D) {
9878 DeclarationNameInfo DirName;
9879 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9880 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
9881 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9882 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9883 return Res;
9884}
9885
9886template <typename Derived>
9887StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
9888 OMPTargetParallelForDirective *D) {
9889 DeclarationNameInfo DirName;
9890 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9891 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
9892 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9893 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9894 return Res;
9895}
9896
9897template <typename Derived>
9898StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
9899 OMPTargetUpdateDirective *D) {
9900 DeclarationNameInfo DirName;
9901 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9902 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
9903 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9904 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9905 return Res;
9906}
9907
9908template <typename Derived>
9910TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
9911 DeclarationNameInfo DirName;
9912 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9913 OMPD_teams, DirName, nullptr, D->getBeginLoc());
9914 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9915 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9916 return Res;
9917}
9918
9919template <typename Derived>
9920StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
9921 OMPCancellationPointDirective *D) {
9922 DeclarationNameInfo DirName;
9923 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9924 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
9925 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9926 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9927 return Res;
9928}
9929
9930template <typename Derived>
9932TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
9933 DeclarationNameInfo DirName;
9934 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9935 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
9936 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9937 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9938 return Res;
9939}
9940
9941template <typename Derived>
9943TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
9944 DeclarationNameInfo DirName;
9945 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9946 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
9947 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9948 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9949 return Res;
9950}
9951
9952template <typename Derived>
9953StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
9954 OMPTaskLoopSimdDirective *D) {
9955 DeclarationNameInfo DirName;
9956 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9957 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9958 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9959 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9960 return Res;
9961}
9962
9963template <typename Derived>
9964StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
9965 OMPMasterTaskLoopDirective *D) {
9966 DeclarationNameInfo DirName;
9967 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9968 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
9969 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9970 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9971 return Res;
9972}
9973
9974template <typename Derived>
9975StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopDirective(
9976 OMPMaskedTaskLoopDirective *D) {
9977 DeclarationNameInfo DirName;
9978 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9979 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
9980 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9981 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9982 return Res;
9983}
9984
9985template <typename Derived>
9986StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
9987 OMPMasterTaskLoopSimdDirective *D) {
9988 DeclarationNameInfo DirName;
9989 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9990 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9991 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9992 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9993 return Res;
9994}
9995
9996template <typename Derived>
9997StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopSimdDirective(
9998 OMPMaskedTaskLoopSimdDirective *D) {
9999 DeclarationNameInfo DirName;
10000 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10001 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10002 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10003 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10004 return Res;
10005}
10006
10007template <typename Derived>
10008StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
10009 OMPParallelMasterTaskLoopDirective *D) {
10010 DeclarationNameInfo DirName;
10011 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10012 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10013 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10014 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10015 return Res;
10016}
10017
10018template <typename Derived>
10019StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopDirective(
10020 OMPParallelMaskedTaskLoopDirective *D) {
10021 DeclarationNameInfo DirName;
10022 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10023 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10024 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10025 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10026 return Res;
10027}
10028
10029template <typename Derived>
10031TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective(
10032 OMPParallelMasterTaskLoopSimdDirective *D) {
10033 DeclarationNameInfo DirName;
10034 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10035 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10036 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10037 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10038 return Res;
10039}
10040
10041template <typename Derived>
10043TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopSimdDirective(
10044 OMPParallelMaskedTaskLoopSimdDirective *D) {
10045 DeclarationNameInfo DirName;
10046 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10047 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10048 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10049 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10050 return Res;
10051}
10052
10053template <typename Derived>
10054StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
10055 OMPDistributeDirective *D) {
10056 DeclarationNameInfo DirName;
10057 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10058 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10059 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10060 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10061 return Res;
10062}
10063
10064template <typename Derived>
10065StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
10066 OMPDistributeParallelForDirective *D) {
10067 DeclarationNameInfo DirName;
10068 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10069 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10070 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10071 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10072 return Res;
10073}
10074
10075template <typename Derived>
10077TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
10078 OMPDistributeParallelForSimdDirective *D) {
10079 DeclarationNameInfo DirName;
10080 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10081 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10082 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10083 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10084 return Res;
10085}
10086
10087template <typename Derived>
10088StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
10089 OMPDistributeSimdDirective *D) {
10090 DeclarationNameInfo DirName;
10091 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10092 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10093 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10094 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10095 return Res;
10096}
10097
10098template <typename Derived>
10099StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
10100 OMPTargetParallelForSimdDirective *D) {
10101 DeclarationNameInfo DirName;
10102 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10103 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10104 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10105 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10106 return Res;
10107}
10108
10109template <typename Derived>
10110StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
10111 OMPTargetSimdDirective *D) {
10112 DeclarationNameInfo DirName;
10113 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10114 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10115 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10116 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10117 return Res;
10118}
10119
10120template <typename Derived>
10121StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
10122 OMPTeamsDistributeDirective *D) {
10123 DeclarationNameInfo DirName;
10124 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10125 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10126 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10127 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10128 return Res;
10129}
10130
10131template <typename Derived>
10132StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
10133 OMPTeamsDistributeSimdDirective *D) {
10134 DeclarationNameInfo DirName;
10135 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10136 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10137 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10138 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10139 return Res;
10140}
10141
10142template <typename Derived>
10143StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
10144 OMPTeamsDistributeParallelForSimdDirective *D) {
10145 DeclarationNameInfo DirName;
10146 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10147 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10148 D->getBeginLoc());
10149 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10150 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10151 return Res;
10152}
10153
10154template <typename Derived>
10155StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
10156 OMPTeamsDistributeParallelForDirective *D) {
10157 DeclarationNameInfo DirName;
10158 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10159 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10160 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10161 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10162 return Res;
10163}
10164
10165template <typename Derived>
10166StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
10167 OMPTargetTeamsDirective *D) {
10168 DeclarationNameInfo DirName;
10169 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10170 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10171 auto Res = getDerived().TransformOMPExecutableDirective(D);
10172 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10173 return Res;
10174}
10175
10176template <typename Derived>
10177StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
10178 OMPTargetTeamsDistributeDirective *D) {
10179 DeclarationNameInfo DirName;
10180 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10181 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10182 auto Res = getDerived().TransformOMPExecutableDirective(D);
10183 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10184 return Res;
10185}
10186
10187template <typename Derived>
10189TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
10190 OMPTargetTeamsDistributeParallelForDirective *D) {
10191 DeclarationNameInfo DirName;
10192 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10193 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10194 D->getBeginLoc());
10195 auto Res = getDerived().TransformOMPExecutableDirective(D);
10196 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10197 return Res;
10198}
10199
10200template <typename Derived>
10201StmtResult TreeTransform<Derived>::
10202 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
10203 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10204 DeclarationNameInfo DirName;
10205 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10206 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10207 D->getBeginLoc());
10208 auto Res = getDerived().TransformOMPExecutableDirective(D);
10209 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10210 return Res;
10211}
10212
10213template <typename Derived>
10215TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
10216 OMPTargetTeamsDistributeSimdDirective *D) {
10217 DeclarationNameInfo DirName;
10218 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10219 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10220 auto Res = getDerived().TransformOMPExecutableDirective(D);
10221 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10222 return Res;
10223}
10224
10225template <typename Derived>
10227TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
10228 DeclarationNameInfo DirName;
10229 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10230 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10231 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10232 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10233 return Res;
10234}
10235
10236template <typename Derived>
10238TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
10239 DeclarationNameInfo DirName;
10240 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10241 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10242 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10243 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10244 return Res;
10245}
10246
10247template <typename Derived>
10249TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
10250 DeclarationNameInfo DirName;
10251 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10252 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10253 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10254 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10255 return Res;
10256}
10257
10258template <typename Derived>
10259StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
10260 OMPGenericLoopDirective *D) {
10261 DeclarationNameInfo DirName;
10262 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10263 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10264 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10265 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10266 return Res;
10267}
10268
10269template <typename Derived>
10270StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective(
10271 OMPTeamsGenericLoopDirective *D) {
10272 DeclarationNameInfo DirName;
10273 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10274 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10275 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10276 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10277 return Res;
10278}
10279
10280template <typename Derived>
10281StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsGenericLoopDirective(
10282 OMPTargetTeamsGenericLoopDirective *D) {
10283 DeclarationNameInfo DirName;
10284 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10285 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10286 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10287 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10288 return Res;
10289}
10290
10291template <typename Derived>
10292StmtResult TreeTransform<Derived>::TransformOMPParallelGenericLoopDirective(
10293 OMPParallelGenericLoopDirective *D) {
10294 DeclarationNameInfo DirName;
10295 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10296 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10297 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10298 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10299 return Res;
10300}
10301
10302template <typename Derived>
10304TreeTransform<Derived>::TransformOMPTargetParallelGenericLoopDirective(
10305 OMPTargetParallelGenericLoopDirective *D) {
10306 DeclarationNameInfo DirName;
10307 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10308 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10309 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10310 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10311 return Res;
10312}
10313
10314//===----------------------------------------------------------------------===//
10315// OpenMP clause transformation
10316//===----------------------------------------------------------------------===//
10317template <typename Derived>
10318OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
10319 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10320 if (Cond.isInvalid())
10321 return nullptr;
10322 return getDerived().RebuildOMPIfClause(
10323 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10324 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10325}
10326
10327template <typename Derived>
10328OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
10329 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10330 if (Cond.isInvalid())
10331 return nullptr;
10332 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10333 C->getLParenLoc(), C->getEndLoc());
10334}
10335
10336template <typename Derived>
10337OMPClause *
10338TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
10339 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10340 if (NumThreads.isInvalid())
10341 return nullptr;
10342 return getDerived().RebuildOMPNumThreadsClause(
10343 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10344}
10345
10346template <typename Derived>
10347OMPClause *
10348TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
10349 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10350 if (E.isInvalid())
10351 return nullptr;
10352 return getDerived().RebuildOMPSafelenClause(
10353 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10354}
10355
10356template <typename Derived>
10357OMPClause *
10358TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
10359 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10360 if (E.isInvalid())
10361 return nullptr;
10362 return getDerived().RebuildOMPAllocatorClause(
10363 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10364}
10365
10366template <typename Derived>
10367OMPClause *
10368TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
10369 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10370 if (E.isInvalid())
10371 return nullptr;
10372 return getDerived().RebuildOMPSimdlenClause(
10373 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10374}
10375
10376template <typename Derived>
10377OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) {
10378 SmallVector<Expr *, 4> TransformedSizes;
10379 TransformedSizes.reserve(C->getNumSizes());
10380 bool Changed = false;
10381 for (Expr *E : C->getSizesRefs()) {
10382 if (!E) {
10383 TransformedSizes.push_back(nullptr);
10384 continue;
10385 }
10386
10387 ExprResult T = getDerived().TransformExpr(E);
10388 if (T.isInvalid())
10389 return nullptr;
10390 if (E != T.get())
10391 Changed = true;
10392 TransformedSizes.push_back(T.get());
10393 }
10394
10395 if (!Changed && !getDerived().AlwaysRebuild())
10396 return C;
10397 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10398 C->getLParenLoc(), C->getEndLoc());
10399}
10400
10401template <typename Derived>
10402OMPClause *
10403TreeTransform<Derived>::TransformOMPPermutationClause(OMPPermutationClause *C) {
10404 SmallVector<Expr *> TransformedArgs;
10405 TransformedArgs.reserve(C->getNumLoops());
10406 bool Changed = false;
10407 for (Expr *E : C->getArgsRefs()) {
10408 if (!E) {
10409 TransformedArgs.push_back(nullptr);
10410 continue;
10411 }
10412
10413 ExprResult T = getDerived().TransformExpr(E);
10414 if (T.isInvalid())
10415 return nullptr;
10416 if (E != T.get())
10417 Changed = true;
10418 TransformedArgs.push_back(T.get());
10419 }
10420
10421 if (!Changed && !getDerived().AlwaysRebuild())
10422 return C;
10423 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10424 C->getLParenLoc(), C->getEndLoc());
10425}
10426
10427template <typename Derived>
10428OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) {
10429 if (!getDerived().AlwaysRebuild())
10430 return C;
10431 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10432}
10433
10434template <typename Derived>
10435OMPClause *
10436TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
10437 ExprResult T = getDerived().TransformExpr(C->getFactor());
10438 if (T.isInvalid())
10439 return nullptr;
10440 Expr *Factor = T.get();
10441 bool Changed = Factor != C->getFactor();
10442
10443 if (!Changed && !getDerived().AlwaysRebuild())
10444 return C;
10445 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10446 C->getEndLoc());
10447}
10448
10449template <typename Derived>
10450OMPClause *
10451TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
10452 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10453 if (E.isInvalid())
10454 return nullptr;
10455 return getDerived().RebuildOMPCollapseClause(
10456 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10457}
10458
10459template <typename Derived>
10460OMPClause *
10461TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
10462 return getDerived().RebuildOMPDefaultClause(
10463 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
10464 C->getLParenLoc(), C->getEndLoc());
10465}
10466
10467template <typename Derived>
10468OMPClause *
10469TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
10470 return getDerived().RebuildOMPProcBindClause(
10471 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10472 C->getLParenLoc(), C->getEndLoc());
10473}
10474
10475template <typename Derived>
10476OMPClause *
10477TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
10478 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10479 if (E.isInvalid())
10480 return nullptr;
10481 return getDerived().RebuildOMPScheduleClause(
10482 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10483 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10484 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10485 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10486}
10487
10488template <typename Derived>
10489OMPClause *
10490TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
10491 ExprResult E;
10492 if (auto *Num = C->getNumForLoops()) {
10493 E = getDerived().TransformExpr(Num);
10494 if (E.isInvalid())
10495 return nullptr;
10496 }
10497 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10498 C->getLParenLoc(), E.get());
10499}
10500
10501template <typename Derived>
10502OMPClause *
10503TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
10504 ExprResult E;
10505 if (Expr *Evt = C->getEventHandler()) {
10506 E = getDerived().TransformExpr(Evt);
10507 if (E.isInvalid())
10508 return nullptr;
10509 }
10510 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10511 C->getLParenLoc(), C->getEndLoc());
10512}
10513
10514template <typename Derived>
10515OMPClause *
10516TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
10517 // No need to rebuild this clause, no template-dependent parameters.
10518 return C;
10519}
10520
10521template <typename Derived>
10522OMPClause *
10523TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
10524 // No need to rebuild this clause, no template-dependent parameters.
10525 return C;
10526}
10527
10528template <typename Derived>
10529OMPClause *
10530TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
10531 // No need to rebuild this clause, no template-dependent parameters.
10532 return C;
10533}
10534
10535template <typename Derived>
10536OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
10537 // No need to rebuild this clause, no template-dependent parameters.
10538 return C;
10539}
10540
10541template <typename Derived>
10542OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
10543 // No need to rebuild this clause, no template-dependent parameters.
10544 return C;
10545}
10546
10547template <typename Derived>
10548OMPClause *
10549TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
10550 // No need to rebuild this clause, no template-dependent parameters.
10551 return C;
10552}
10553
10554template <typename Derived>
10555OMPClause *
10556TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
10557 // No need to rebuild this clause, no template-dependent parameters.
10558 return C;
10559}
10560
10561template <typename Derived>
10562OMPClause *
10563TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
10564 // No need to rebuild this clause, no template-dependent parameters.
10565 return C;
10566}
10567
10568template <typename Derived>
10569OMPClause *TreeTransform<Derived>::TransformOMPFailClause(OMPFailClause *C) {
10570 // No need to rebuild this clause, no template-dependent parameters.
10571 return C;
10572}
10573
10574template <typename Derived>
10575OMPClause *
10576TreeTransform<Derived>::TransformOMPAbsentClause(OMPAbsentClause *C) {
10577 return C;
10578}
10579
10580template <typename Derived>
10581OMPClause *TreeTransform<Derived>::TransformOMPHoldsClause(OMPHoldsClause *C) {
10582 ExprResult E = getDerived().TransformExpr(C->getExpr());
10583 if (E.isInvalid())
10584 return nullptr;
10585 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
10586 C->getLParenLoc(), C->getEndLoc());
10587}
10588
10589template <typename Derived>
10590OMPClause *
10591TreeTransform<Derived>::TransformOMPContainsClause(OMPContainsClause *C) {
10592 return C;
10593}
10594
10595template <typename Derived>
10596OMPClause *
10597TreeTransform<Derived>::TransformOMPNoOpenMPClause(OMPNoOpenMPClause *C) {
10598 return C;
10599}
10600template <typename Derived>
10601OMPClause *TreeTransform<Derived>::TransformOMPNoOpenMPRoutinesClause(
10602 OMPNoOpenMPRoutinesClause *C) {
10603 return C;
10604}
10605template <typename Derived>
10606OMPClause *TreeTransform<Derived>::TransformOMPNoParallelismClause(
10607 OMPNoParallelismClause *C) {
10608 return C;
10609}
10610
10611template <typename Derived>
10612OMPClause *
10613TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
10614 // No need to rebuild this clause, no template-dependent parameters.
10615 return C;
10616}
10617
10618template <typename Derived>
10619OMPClause *
10620TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
10621 // No need to rebuild this clause, no template-dependent parameters.
10622 return C;
10623}
10624
10625template <typename Derived>
10626OMPClause *
10627TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
10628 // No need to rebuild this clause, no template-dependent parameters.
10629 return C;
10630}
10631
10632template <typename Derived>
10633OMPClause *
10634TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
10635 // No need to rebuild this clause, no template-dependent parameters.
10636 return C;
10637}
10638
10639template <typename Derived>
10640OMPClause *
10641TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
10642 // No need to rebuild this clause, no template-dependent parameters.
10643 return C;
10644}
10645
10646template <typename Derived>
10647OMPClause *TreeTransform<Derived>::TransformOMPWeakClause(OMPWeakClause *C) {
10648 // No need to rebuild this clause, no template-dependent parameters.
10649 return C;
10650}
10651
10652template <typename Derived>
10653OMPClause *
10654TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
10655 // No need to rebuild this clause, no template-dependent parameters.
10656 return C;
10657}
10658
10659template <typename Derived>
10660OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
10661 // No need to rebuild this clause, no template-dependent parameters.
10662 return C;
10663}
10664
10665template <typename Derived>
10666OMPClause *
10667TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
10668 // No need to rebuild this clause, no template-dependent parameters.
10669 return C;
10670}
10671
10672template <typename Derived>
10673OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
10674 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10675 if (IVR.isInvalid())
10676 return nullptr;
10677
10678 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10679 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10680 for (Expr *E : llvm::drop_begin(C->varlist())) {
10681 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10682 if (ER.isInvalid())
10683 return nullptr;
10684 InteropInfo.PreferTypes.push_back(ER.get());
10685 }
10686 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10687 C->getBeginLoc(), C->getLParenLoc(),
10688 C->getVarLoc(), C->getEndLoc());
10689}
10690
10691template <typename Derived>
10692OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) {
10693 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10694 if (ER.isInvalid())
10695 return nullptr;
10696 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10697 C->getLParenLoc(), C->getVarLoc(),
10698 C->getEndLoc());
10699}
10700
10701template <typename Derived>
10702OMPClause *
10703TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
10704 ExprResult ER;
10705 if (Expr *IV = C->getInteropVar()) {
10706 ER = getDerived().TransformExpr(IV);
10707 if (ER.isInvalid())
10708 return nullptr;
10709 }
10710 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10711 C->getLParenLoc(), C->getVarLoc(),
10712 C->getEndLoc());
10713}
10714
10715template <typename Derived>
10716OMPClause *
10717TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
10718 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10719 if (Cond.isInvalid())
10720 return nullptr;
10721 return getDerived().RebuildOMPNovariantsClause(
10722 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10723}
10724
10725template <typename Derived>
10726OMPClause *
10727TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
10728 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10729 if (Cond.isInvalid())
10730 return nullptr;
10731 return getDerived().RebuildOMPNocontextClause(
10732 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10733}
10734
10735template <typename Derived>
10736OMPClause *
10737TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
10738 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10739 if (ThreadID.isInvalid())
10740 return nullptr;
10741 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10742 C->getLParenLoc(), C->getEndLoc());
10743}
10744
10745template <typename Derived>
10746OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) {
10747 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10748 if (E.isInvalid())
10749 return nullptr;
10750 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10751 C->getLParenLoc(), C->getEndLoc());
10752}
10753
10754template <typename Derived>
10755OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
10756 OMPUnifiedAddressClause *C) {
10757 llvm_unreachable("unified_address clause cannot appear in dependent context");
10758}
10759
10760template <typename Derived>
10761OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
10762 OMPUnifiedSharedMemoryClause *C) {
10763 llvm_unreachable(
10764 "unified_shared_memory clause cannot appear in dependent context");
10765}
10766
10767template <typename Derived>
10768OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
10769 OMPReverseOffloadClause *C) {
10770 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10771}
10772
10773template <typename Derived>
10774OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
10775 OMPDynamicAllocatorsClause *C) {
10776 llvm_unreachable(
10777 "dynamic_allocators clause cannot appear in dependent context");
10778}
10779
10780template <typename Derived>
10781OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
10782 OMPAtomicDefaultMemOrderClause *C) {
10783 llvm_unreachable(
10784 "atomic_default_mem_order clause cannot appear in dependent context");
10785}
10786
10787template <typename Derived>
10788OMPClause *TreeTransform<Derived>::TransformOMPAtClause(OMPAtClause *C) {
10789 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10790 C->getBeginLoc(), C->getLParenLoc(),
10791 C->getEndLoc());
10792}
10793
10794template <typename Derived>
10795OMPClause *
10796TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) {
10797 return getDerived().RebuildOMPSeverityClause(
10798 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10799 C->getLParenLoc(), C->getEndLoc());
10800}
10801
10802template <typename Derived>
10803OMPClause *
10804TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) {
10805 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10806 if (E.isInvalid())
10807 return nullptr;
10808 return getDerived().RebuildOMPMessageClause(
10809 C->getMessageString(), C->getBeginLoc(), C->getLParenLoc(),
10810 C->getEndLoc());
10811}
10812
10813template <typename Derived>
10814OMPClause *
10815TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
10817 Vars.reserve(C->varlist_size());
10818 for (auto *VE : C->varlist()) {
10819 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10820 if (EVar.isInvalid())
10821 return nullptr;
10822 Vars.push_back(EVar.get());
10823 }
10824 return getDerived().RebuildOMPPrivateClause(
10825 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10826}
10827
10828template <typename Derived>
10829OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
10830 OMPFirstprivateClause *C) {
10832 Vars.reserve(C->varlist_size());
10833 for (auto *VE : C->varlist()) {
10834 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10835 if (EVar.isInvalid())
10836 return nullptr;
10837 Vars.push_back(EVar.get());
10838 }
10839 return getDerived().RebuildOMPFirstprivateClause(
10840 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10841}
10842
10843template <typename Derived>
10844OMPClause *
10845TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
10847 Vars.reserve(C->varlist_size());
10848 for (auto *VE : C->varlist()) {
10849 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10850 if (EVar.isInvalid())
10851 return nullptr;
10852 Vars.push_back(EVar.get());
10853 }
10854 return getDerived().RebuildOMPLastprivateClause(
10855 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
10856 C->getLParenLoc(), C->getEndLoc());
10857}
10858
10859template <typename Derived>
10860OMPClause *
10861TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
10863 Vars.reserve(C->varlist_size());
10864 for (auto *VE : C->varlist()) {
10865 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10866 if (EVar.isInvalid())
10867 return nullptr;
10868 Vars.push_back(EVar.get());
10869 }
10870 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
10871 C->getLParenLoc(), C->getEndLoc());
10872}
10873
10874template <typename Derived>
10875OMPClause *
10876TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
10878 Vars.reserve(C->varlist_size());
10879 for (auto *VE : C->varlist()) {
10880 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10881 if (EVar.isInvalid())
10882 return nullptr;
10883 Vars.push_back(EVar.get());
10884 }
10885 CXXScopeSpec ReductionIdScopeSpec;
10886 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10887
10888 DeclarationNameInfo NameInfo = C->getNameInfo();
10889 if (NameInfo.getName()) {
10890 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10891 if (!NameInfo.getName())
10892 return nullptr;
10893 }
10894 // Build a list of all UDR decls with the same names ranged by the Scopes.
10895 // The Scope boundary is a duplication of the previous decl.
10896 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10897 for (auto *E : C->reduction_ops()) {
10898 // Transform all the decls.
10899 if (E) {
10900 auto *ULE = cast<UnresolvedLookupExpr>(E);
10901 UnresolvedSet<8> Decls;
10902 for (auto *D : ULE->decls()) {
10903 NamedDecl *InstD =
10904 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10905 Decls.addDecl(InstD, InstD->getAccess());
10906 }
10907 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10908 SemaRef.Context, /*NamingClass=*/nullptr,
10909 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10910 /*ADL=*/true, Decls.begin(), Decls.end(),
10911 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10912 } else
10913 UnresolvedReductions.push_back(nullptr);
10914 }
10915 return getDerived().RebuildOMPReductionClause(
10916 Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(),
10917 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
10918 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10919}
10920
10921template <typename Derived>
10922OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
10923 OMPTaskReductionClause *C) {
10925 Vars.reserve(C->varlist_size());
10926 for (auto *VE : C->varlist()) {
10927 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10928 if (EVar.isInvalid())
10929 return nullptr;
10930 Vars.push_back(EVar.get());
10931 }
10932 CXXScopeSpec ReductionIdScopeSpec;
10933 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10934
10935 DeclarationNameInfo NameInfo = C->getNameInfo();
10936 if (NameInfo.getName()) {
10937 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10938 if (!NameInfo.getName())
10939 return nullptr;
10940 }
10941 // Build a list of all UDR decls with the same names ranged by the Scopes.
10942 // The Scope boundary is a duplication of the previous decl.
10943 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10944 for (auto *E : C->reduction_ops()) {
10945 // Transform all the decls.
10946 if (E) {
10947 auto *ULE = cast<UnresolvedLookupExpr>(E);
10948 UnresolvedSet<8> Decls;
10949 for (auto *D : ULE->decls()) {
10950 NamedDecl *InstD =
10951 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10952 Decls.addDecl(InstD, InstD->getAccess());
10953 }
10954 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10955 SemaRef.Context, /*NamingClass=*/nullptr,
10956 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10957 /*ADL=*/true, Decls.begin(), Decls.end(),
10958 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10959 } else
10960 UnresolvedReductions.push_back(nullptr);
10961 }
10962 return getDerived().RebuildOMPTaskReductionClause(
10963 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10964 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10965}
10966
10967template <typename Derived>
10968OMPClause *
10969TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
10971 Vars.reserve(C->varlist_size());
10972 for (auto *VE : C->varlist()) {
10973 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10974 if (EVar.isInvalid())
10975 return nullptr;
10976 Vars.push_back(EVar.get());
10977 }
10978 CXXScopeSpec ReductionIdScopeSpec;
10979 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10980
10981 DeclarationNameInfo NameInfo = C->getNameInfo();
10982 if (NameInfo.getName()) {
10983 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10984 if (!NameInfo.getName())
10985 return nullptr;
10986 }
10987 // Build a list of all UDR decls with the same names ranged by the Scopes.
10988 // The Scope boundary is a duplication of the previous decl.
10989 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10990 for (auto *E : C->reduction_ops()) {
10991 // Transform all the decls.
10992 if (E) {
10993 auto *ULE = cast<UnresolvedLookupExpr>(E);
10994 UnresolvedSet<8> Decls;
10995 for (auto *D : ULE->decls()) {
10996 NamedDecl *InstD =
10997 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10998 Decls.addDecl(InstD, InstD->getAccess());
10999 }
11000 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11001 SemaRef.Context, /*NamingClass=*/nullptr,
11002 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11003 /*ADL=*/true, Decls.begin(), Decls.end(),
11004 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11005 } else
11006 UnresolvedReductions.push_back(nullptr);
11007 }
11008 return getDerived().RebuildOMPInReductionClause(
11009 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11010 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11011}
11012
11013template <typename Derived>
11014OMPClause *
11015TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
11017 Vars.reserve(C->varlist_size());
11018 for (auto *VE : C->varlist()) {
11019 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11020 if (EVar.isInvalid())
11021 return nullptr;
11022 Vars.push_back(EVar.get());
11023 }
11024 ExprResult Step = getDerived().TransformExpr(C->getStep());
11025 if (Step.isInvalid())
11026 return nullptr;
11027 return getDerived().RebuildOMPLinearClause(
11028 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11029 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11030 C->getEndLoc());
11031}
11032
11033template <typename Derived>
11034OMPClause *
11035TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
11037 Vars.reserve(C->varlist_size());
11038 for (auto *VE : C->varlist()) {
11039 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11040 if (EVar.isInvalid())
11041 return nullptr;
11042 Vars.push_back(EVar.get());
11043 }
11044 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11045 if (Alignment.isInvalid())
11046 return nullptr;
11047 return getDerived().RebuildOMPAlignedClause(
11048 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11049 C->getColonLoc(), C->getEndLoc());
11050}
11051
11052template <typename Derived>
11053OMPClause *
11054TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
11056 Vars.reserve(C->varlist_size());
11057 for (auto *VE : C->varlist()) {
11058 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11059 if (EVar.isInvalid())
11060 return nullptr;
11061 Vars.push_back(EVar.get());
11062 }
11063 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11064 C->getLParenLoc(), C->getEndLoc());
11065}
11066
11067template <typename Derived>
11068OMPClause *
11069TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
11071 Vars.reserve(C->varlist_size());
11072 for (auto *VE : C->varlist()) {
11073 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11074 if (EVar.isInvalid())
11075 return nullptr;
11076 Vars.push_back(EVar.get());
11077 }
11078 return getDerived().RebuildOMPCopyprivateClause(
11079 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11080}
11081
11082template <typename Derived>
11083OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
11085 Vars.reserve(C->varlist_size());
11086 for (auto *VE : C->varlist()) {
11087 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11088 if (EVar.isInvalid())
11089 return nullptr;
11090 Vars.push_back(EVar.get());
11091 }
11092 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11093 C->getLParenLoc(), C->getEndLoc());
11094}
11095
11096template <typename Derived>
11097OMPClause *
11098TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
11099 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11100 if (E.isInvalid())
11101 return nullptr;
11102 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11103 C->getLParenLoc(), C->getEndLoc());
11104}
11105
11106template <typename Derived>
11107OMPClause *
11108TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
11110 Expr *DepModifier = C->getModifier();
11111 if (DepModifier) {
11112 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11113 if (DepModRes.isInvalid())
11114 return nullptr;
11115 DepModifier = DepModRes.get();
11116 }
11117 Vars.reserve(C->varlist_size());
11118 for (auto *VE : C->varlist()) {
11119 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11120 if (EVar.isInvalid())
11121 return nullptr;
11122 Vars.push_back(EVar.get());
11123 }
11124 return getDerived().RebuildOMPDependClause(
11125 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11126 C->getOmpAllMemoryLoc()},
11127 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11128}
11129
11130template <typename Derived>
11131OMPClause *
11132TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
11133 ExprResult E = getDerived().TransformExpr(C->getDevice());
11134 if (E.isInvalid())
11135 return nullptr;
11136 return getDerived().RebuildOMPDeviceClause(
11137 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11138 C->getModifierLoc(), C->getEndLoc());
11139}
11140
11141template <typename Derived, class T>
11144 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11145 DeclarationNameInfo &MapperIdInfo,
11146 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11147 // Transform expressions in the list.
11148 Vars.reserve(C->varlist_size());
11149 for (auto *VE : C->varlist()) {
11150 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11151 if (EVar.isInvalid())
11152 return true;
11153 Vars.push_back(EVar.get());
11154 }
11155 // Transform mapper scope specifier and identifier.
11156 NestedNameSpecifierLoc QualifierLoc;
11157 if (C->getMapperQualifierLoc()) {
11158 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11159 C->getMapperQualifierLoc());
11160 if (!QualifierLoc)
11161 return true;
11162 }
11163 MapperIdScopeSpec.Adopt(QualifierLoc);
11164 MapperIdInfo = C->getMapperIdInfo();
11165 if (MapperIdInfo.getName()) {
11166 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11167 if (!MapperIdInfo.getName())
11168 return true;
11169 }
11170 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11171 // the previous user-defined mapper lookup in dependent environment.
11172 for (auto *E : C->mapperlists()) {
11173 // Transform all the decls.
11174 if (E) {
11175 auto *ULE = cast<UnresolvedLookupExpr>(E);
11176 UnresolvedSet<8> Decls;
11177 for (auto *D : ULE->decls()) {
11178 NamedDecl *InstD =
11179 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11180 Decls.addDecl(InstD, InstD->getAccess());
11181 }
11182 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11183 TT.getSema().Context, /*NamingClass=*/nullptr,
11184 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11185 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11186 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11187 } else {
11188 UnresolvedMappers.push_back(nullptr);
11189 }
11190 }
11191 return false;
11192}
11193
11194template <typename Derived>
11195OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11196 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11198 Expr *IteratorModifier = C->getIteratorModifier();
11199 if (IteratorModifier) {
11200 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11201 if (MapModRes.isInvalid())
11202 return nullptr;
11203 IteratorModifier = MapModRes.get();
11204 }
11205 CXXScopeSpec MapperIdScopeSpec;
11206 DeclarationNameInfo MapperIdInfo;
11207 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11208 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
11209 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11210 return nullptr;
11211 return getDerived().RebuildOMPMapClause(
11212 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11213 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11214 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11215}
11216
11217template <typename Derived>
11218OMPClause *
11219TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
11220 Expr *Allocator = C->getAllocator();
11221 if (Allocator) {
11222 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11223 if (AllocatorRes.isInvalid())
11224 return nullptr;
11225 Allocator = AllocatorRes.get();
11226 }
11228 Vars.reserve(C->varlist_size());
11229 for (auto *VE : C->varlist()) {
11230 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11231 if (EVar.isInvalid())
11232 return nullptr;
11233 Vars.push_back(EVar.get());
11234 }
11235 return getDerived().RebuildOMPAllocateClause(
11236 Allocator, C->getAllocatorModifier(), Vars, C->getBeginLoc(),
11237 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11238}
11239
11240template <typename Derived>
11241OMPClause *
11242TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
11244 Vars.reserve(C->varlist_size());
11245 for (auto *VE : C->varlist()) {
11246 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11247 if (EVar.isInvalid())
11248 return nullptr;
11249 Vars.push_back(EVar.get());
11250 }
11251 return getDerived().RebuildOMPNumTeamsClause(
11252 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11253}
11254
11255template <typename Derived>
11256OMPClause *
11257TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
11259 Vars.reserve(C->varlist_size());
11260 for (auto *VE : C->varlist()) {
11261 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11262 if (EVar.isInvalid())
11263 return nullptr;
11264 Vars.push_back(EVar.get());
11265 }
11266 return getDerived().RebuildOMPThreadLimitClause(
11267 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11268}
11269
11270template <typename Derived>
11271OMPClause *
11272TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
11273 ExprResult E = getDerived().TransformExpr(C->getPriority());
11274 if (E.isInvalid())
11275 return nullptr;
11276 return getDerived().RebuildOMPPriorityClause(
11277 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11278}
11279
11280template <typename Derived>
11281OMPClause *
11282TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
11283 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11284 if (E.isInvalid())
11285 return nullptr;
11286 return getDerived().RebuildOMPGrainsizeClause(
11287 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11288 C->getModifierLoc(), C->getEndLoc());
11289}
11290
11291template <typename Derived>
11292OMPClause *
11293TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
11294 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11295 if (E.isInvalid())
11296 return nullptr;
11297 return getDerived().RebuildOMPNumTasksClause(
11298 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11299 C->getModifierLoc(), C->getEndLoc());
11300}
11301
11302template <typename Derived>
11303OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
11304 ExprResult E = getDerived().TransformExpr(C->getHint());
11305 if (E.isInvalid())
11306 return nullptr;
11307 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11308 C->getLParenLoc(), C->getEndLoc());
11309}
11310
11311template <typename Derived>
11312OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
11313 OMPDistScheduleClause *C) {
11314 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11315 if (E.isInvalid())
11316 return nullptr;
11317 return getDerived().RebuildOMPDistScheduleClause(
11318 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11319 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11320}
11321
11322template <typename Derived>
11323OMPClause *
11324TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
11325 // Rebuild Defaultmap Clause since we need to invoke the checking of
11326 // defaultmap(none:variable-category) after template initialization.
11327 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11328 C->getDefaultmapKind(),
11329 C->getBeginLoc(),
11330 C->getLParenLoc(),
11331 C->getDefaultmapModifierLoc(),
11332 C->getDefaultmapKindLoc(),
11333 C->getEndLoc());
11334}
11335
11336template <typename Derived>
11337OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
11338 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11340 CXXScopeSpec MapperIdScopeSpec;
11341 DeclarationNameInfo MapperIdInfo;
11342 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11343 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
11344 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11345 return nullptr;
11346 return getDerived().RebuildOMPToClause(
11347 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11348 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11349}
11350
11351template <typename Derived>
11352OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
11353 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11355 CXXScopeSpec MapperIdScopeSpec;
11356 DeclarationNameInfo MapperIdInfo;
11357 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11358 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
11359 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11360 return nullptr;
11361 return getDerived().RebuildOMPFromClause(
11362 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11363 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11364}
11365
11366template <typename Derived>
11367OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
11368 OMPUseDevicePtrClause *C) {
11370 Vars.reserve(C->varlist_size());
11371 for (auto *VE : C->varlist()) {
11372 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11373 if (EVar.isInvalid())
11374 return nullptr;
11375 Vars.push_back(EVar.get());
11376 }
11377 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11378 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
11379}
11380
11381template <typename Derived>
11382OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause(
11383 OMPUseDeviceAddrClause *C) {
11385 Vars.reserve(C->varlist_size());
11386 for (auto *VE : C->varlist()) {
11387 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11388 if (EVar.isInvalid())
11389 return nullptr;
11390 Vars.push_back(EVar.get());
11391 }
11392 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11393 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11394}
11395
11396template <typename Derived>
11397OMPClause *
11398TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
11400 Vars.reserve(C->varlist_size());
11401 for (auto *VE : C->varlist()) {
11402 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11403 if (EVar.isInvalid())
11404 return nullptr;
11405 Vars.push_back(EVar.get());
11406 }
11407 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11408 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11409}
11410
11411template <typename Derived>
11412OMPClause *TreeTransform<Derived>::TransformOMPHasDeviceAddrClause(
11413 OMPHasDeviceAddrClause *C) {
11415 Vars.reserve(C->varlist_size());
11416 for (auto *VE : C->varlist()) {
11417 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11418 if (EVar.isInvalid())
11419 return nullptr;
11420 Vars.push_back(EVar.get());
11421 }
11422 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11423 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11424}
11425
11426template <typename Derived>
11427OMPClause *
11428TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) {
11430 Vars.reserve(C->varlist_size());
11431 for (auto *VE : C->varlist()) {
11432 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11433 if (EVar.isInvalid())
11434 return nullptr;
11435 Vars.push_back(EVar.get());
11436 }
11437 return getDerived().RebuildOMPNontemporalClause(
11438 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11439}
11440
11441template <typename Derived>
11442OMPClause *
11443TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) {
11445 Vars.reserve(C->varlist_size());
11446 for (auto *VE : C->varlist()) {
11447 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11448 if (EVar.isInvalid())
11449 return nullptr;
11450 Vars.push_back(EVar.get());
11451 }
11452 return getDerived().RebuildOMPInclusiveClause(
11453 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11454}
11455
11456template <typename Derived>
11457OMPClause *
11458TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) {
11460 Vars.reserve(C->varlist_size());
11461 for (auto *VE : C->varlist()) {
11462 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11463 if (EVar.isInvalid())
11464 return nullptr;
11465 Vars.push_back(EVar.get());
11466 }
11467 return getDerived().RebuildOMPExclusiveClause(
11468 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11469}
11470
11471template <typename Derived>
11472OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause(
11473 OMPUsesAllocatorsClause *C) {
11475 Data.reserve(C->getNumberOfAllocators());
11476 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11477 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11478 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11479 if (Allocator.isInvalid())
11480 continue;
11481 ExprResult AllocatorTraits;
11482 if (Expr *AT = D.AllocatorTraits) {
11483 AllocatorTraits = getDerived().TransformExpr(AT);
11484 if (AllocatorTraits.isInvalid())
11485 continue;
11486 }
11487 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11488 NewD.Allocator = Allocator.get();
11489 NewD.AllocatorTraits = AllocatorTraits.get();
11490 NewD.LParenLoc = D.LParenLoc;
11491 NewD.RParenLoc = D.RParenLoc;
11492 }
11493 return getDerived().RebuildOMPUsesAllocatorsClause(
11494 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11495}
11496
11497template <typename Derived>
11498OMPClause *
11499TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) {
11500 SmallVector<Expr *, 4> Locators;
11501 Locators.reserve(C->varlist_size());
11502 ExprResult ModifierRes;
11503 if (Expr *Modifier = C->getModifier()) {
11504 ModifierRes = getDerived().TransformExpr(Modifier);
11505 if (ModifierRes.isInvalid())
11506 return nullptr;
11507 }
11508 for (Expr *E : C->varlist()) {
11509 ExprResult Locator = getDerived().TransformExpr(E);
11510 if (Locator.isInvalid())
11511 continue;
11512 Locators.push_back(Locator.get());
11513 }
11514 return getDerived().RebuildOMPAffinityClause(
11515 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11516 ModifierRes.get(), Locators);
11517}
11518
11519template <typename Derived>
11520OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) {
11521 return getDerived().RebuildOMPOrderClause(
11522 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11523 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11524}
11525
11526template <typename Derived>
11527OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) {
11528 return getDerived().RebuildOMPBindClause(
11529 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11530 C->getLParenLoc(), C->getEndLoc());
11531}
11532
11533template <typename Derived>
11534OMPClause *TreeTransform<Derived>::TransformOMPXDynCGroupMemClause(
11535 OMPXDynCGroupMemClause *C) {
11536 ExprResult Size = getDerived().TransformExpr(C->getSize());
11537 if (Size.isInvalid())
11538 return nullptr;
11539 return getDerived().RebuildOMPXDynCGroupMemClause(
11540 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11541}
11542
11543template <typename Derived>
11544OMPClause *
11545TreeTransform<Derived>::TransformOMPDoacrossClause(OMPDoacrossClause *C) {
11547 Vars.reserve(C->varlist_size());
11548 for (auto *VE : C->varlist()) {
11549 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11550 if (EVar.isInvalid())
11551 return nullptr;
11552 Vars.push_back(EVar.get());
11553 }
11554 return getDerived().RebuildOMPDoacrossClause(
11555 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11556 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11557}
11558
11559template <typename Derived>
11560OMPClause *
11561TreeTransform<Derived>::TransformOMPXAttributeClause(OMPXAttributeClause *C) {
11563 for (auto *A : C->getAttrs())
11564 NewAttrs.push_back(getDerived().TransformAttr(A));
11565 return getDerived().RebuildOMPXAttributeClause(
11566 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11567}
11568
11569template <typename Derived>
11570OMPClause *TreeTransform<Derived>::TransformOMPXBareClause(OMPXBareClause *C) {
11571 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11572}
11573
11574//===----------------------------------------------------------------------===//
11575// OpenACC transformation
11576//===----------------------------------------------------------------------===//
11577namespace {
11578template <typename Derived>
11579class OpenACCClauseTransform final
11580 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11581 TreeTransform<Derived> &Self;
11582 ArrayRef<const OpenACCClause *> ExistingClauses;
11583 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11584 OpenACCClause *NewClause = nullptr;
11585
11586 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11587 llvm::SmallVector<Expr *> InstantiatedVarList;
11588 for (Expr *CurVar : VarList) {
11589 ExprResult Res = Self.TransformExpr(CurVar);
11590
11591 if (!Res.isUsable())
11592 continue;
11593
11594 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getClauseKind(),
11595 Res.get());
11596
11597 if (Res.isUsable())
11598 InstantiatedVarList.push_back(Res.get());
11599 }
11600
11601 return InstantiatedVarList;
11602 }
11603
11604public:
11605 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11606 ArrayRef<const OpenACCClause *> ExistingClauses,
11607 SemaOpenACC::OpenACCParsedClause &PC)
11608 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11609
11610 OpenACCClause *CreatedClause() const { return NewClause; }
11611
11612#define VISIT_CLAUSE(CLAUSE_NAME) \
11613 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11614#include "clang/Basic/OpenACCClauses.def"
11615};
11616
11617template <typename Derived>
11618void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11619 const OpenACCDefaultClause &C) {
11620 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11621
11622 NewClause = OpenACCDefaultClause::Create(
11623 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11624 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11625 ParsedClause.getEndLoc());
11626}
11627
11628template <typename Derived>
11629void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11630 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11631 assert(Cond && "If constructed with invalid Condition");
11632 Sema::ConditionResult Res = Self.TransformCondition(
11633 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11634
11635 if (Res.isInvalid() || !Res.get().second)
11636 return;
11637
11638 ParsedClause.setConditionDetails(Res.get().second);
11639
11640 NewClause = OpenACCIfClause::Create(
11641 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11642 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11643 ParsedClause.getEndLoc());
11644}
11645
11646template <typename Derived>
11647void OpenACCClauseTransform<Derived>::VisitSelfClause(
11648 const OpenACCSelfClause &C) {
11649
11650 // If this is an 'update' 'self' clause, this is actually a var list instead.
11651 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
11652 llvm::SmallVector<Expr *> InstantiatedVarList;
11653 for (Expr *CurVar : C.getVarList()) {
11654 ExprResult Res = Self.TransformExpr(CurVar);
11655
11656 if (!Res.isUsable())
11657 continue;
11658
11659 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getClauseKind(),
11660 Res.get());
11661
11662 if (Res.isUsable())
11663 InstantiatedVarList.push_back(Res.get());
11664 }
11665
11666 ParsedClause.setVarListDetails(InstantiatedVarList,
11667 /*IsReadOnly=*/false, /*IsZero=*/false);
11668
11669 NewClause = OpenACCSelfClause::Create(
11670 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11671 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11672 ParsedClause.getEndLoc());
11673 } else {
11674
11675 if (C.hasConditionExpr()) {
11676 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11677 Sema::ConditionResult Res =
11678 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11680
11681 if (Res.isInvalid() || !Res.get().second)
11682 return;
11683
11684 ParsedClause.setConditionDetails(Res.get().second);
11685 }
11686
11687 NewClause = OpenACCSelfClause::Create(
11688 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11689 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11690 ParsedClause.getEndLoc());
11691 }
11692}
11693
11694template <typename Derived>
11695void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11696 const OpenACCNumGangsClause &C) {
11697 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11698
11699 for (Expr *CurIntExpr : C.getIntExprs()) {
11700 ExprResult Res = Self.TransformExpr(CurIntExpr);
11701
11702 if (!Res.isUsable())
11703 return;
11704
11705 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11706 C.getClauseKind(),
11707 C.getBeginLoc(), Res.get());
11708 if (!Res.isUsable())
11709 return;
11710
11711 InstantiatedIntExprs.push_back(Res.get());
11712 }
11713
11714 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11716 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11717 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11718 ParsedClause.getEndLoc());
11719}
11720
11721template <typename Derived>
11722void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11723 const OpenACCPrivateClause &C) {
11724 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11725 /*IsReadOnly=*/false, /*IsZero=*/false);
11726
11727 NewClause = OpenACCPrivateClause::Create(
11728 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11729 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11730 ParsedClause.getEndLoc());
11731}
11732
11733template <typename Derived>
11734void OpenACCClauseTransform<Derived>::VisitHostClause(
11735 const OpenACCHostClause &C) {
11736 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11737 /*IsReadOnly=*/false, /*IsZero=*/false);
11738
11739 NewClause = OpenACCHostClause::Create(
11740 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11741 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11742 ParsedClause.getEndLoc());
11743}
11744
11745template <typename Derived>
11746void OpenACCClauseTransform<Derived>::VisitDeviceClause(
11747 const OpenACCDeviceClause &C) {
11748 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11749 /*IsReadOnly=*/false, /*IsZero=*/false);
11750
11751 NewClause = OpenACCDeviceClause::Create(
11752 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11753 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11754 ParsedClause.getEndLoc());
11755}
11756
11757template <typename Derived>
11758void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11759 const OpenACCFirstPrivateClause &C) {
11760 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11761 /*IsReadOnly=*/false, /*IsZero=*/false);
11762
11764 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11765 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11766 ParsedClause.getEndLoc());
11767}
11768
11769template <typename Derived>
11770void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
11771 const OpenACCNoCreateClause &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>::VisitPresentClause(
11783 const OpenACCPresentClause &C) {
11784 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11785 /*IsReadOnly=*/false, /*IsZero=*/false);
11786
11787 NewClause = OpenACCPresentClause::Create(
11788 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11789 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11790 ParsedClause.getEndLoc());
11791}
11792
11793template <typename Derived>
11794void OpenACCClauseTransform<Derived>::VisitCopyClause(
11795 const OpenACCCopyClause &C) {
11796 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11797 /*IsReadOnly=*/false, /*IsZero=*/false);
11798
11799 NewClause = OpenACCCopyClause::Create(
11800 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11801 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11802 ParsedClause.getVarList(), ParsedClause.getEndLoc());
11803}
11804
11805template <typename Derived>
11806void OpenACCClauseTransform<Derived>::VisitCopyInClause(
11807 const OpenACCCopyInClause &C) {
11808 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), C.isReadOnly(),
11809 /*IsZero=*/false);
11810
11811 NewClause = OpenACCCopyInClause::Create(
11812 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11813 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11814 ParsedClause.isReadOnly(), ParsedClause.getVarList(),
11815 ParsedClause.getEndLoc());
11816}
11817
11818template <typename Derived>
11819void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
11820 const OpenACCCopyOutClause &C) {
11821 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11822 /*IsReadOnly=*/false, C.isZero());
11823
11824 NewClause = OpenACCCopyOutClause::Create(
11825 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11826 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11827 ParsedClause.isZero(), ParsedClause.getVarList(),
11828 ParsedClause.getEndLoc());
11829}
11830
11831template <typename Derived>
11832void OpenACCClauseTransform<Derived>::VisitCreateClause(
11833 const OpenACCCreateClause &C) {
11834 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11835 /*IsReadOnly=*/false, C.isZero());
11836
11837 NewClause = OpenACCCreateClause::Create(
11838 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11839 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11840 ParsedClause.isZero(), ParsedClause.getVarList(),
11841 ParsedClause.getEndLoc());
11842}
11843template <typename Derived>
11844void OpenACCClauseTransform<Derived>::VisitAttachClause(
11845 const OpenACCAttachClause &C) {
11846 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11847
11848 // Ensure each var is a pointer type.
11849 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11850 return Self.getSema().OpenACC().CheckVarIsPointerType(
11851 OpenACCClauseKind::Attach, E);
11852 }), VarList.end());
11853
11854 ParsedClause.setVarListDetails(VarList,
11855 /*IsReadOnly=*/false, /*IsZero=*/false);
11856 NewClause = OpenACCAttachClause::Create(
11857 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11858 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11859 ParsedClause.getEndLoc());
11860}
11861
11862template <typename Derived>
11863void OpenACCClauseTransform<Derived>::VisitDetachClause(
11864 const OpenACCDetachClause &C) {
11865 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11866
11867 // Ensure each var is a pointer type.
11868 VarList.erase(
11869 std::remove_if(VarList.begin(), VarList.end(),
11870 [&](Expr *E) {
11871 return Self.getSema().OpenACC().CheckVarIsPointerType(
11872 OpenACCClauseKind::Detach, E);
11873 }),
11874 VarList.end());
11875
11876 ParsedClause.setVarListDetails(VarList,
11877 /*IsReadOnly=*/false, /*IsZero=*/false);
11878 NewClause = OpenACCDetachClause::Create(
11879 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11880 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11881 ParsedClause.getEndLoc());
11882}
11883
11884template <typename Derived>
11885void OpenACCClauseTransform<Derived>::VisitDeleteClause(
11886 const OpenACCDeleteClause &C) {
11887 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11888 /*IsReadOnly=*/false, /*IsZero=*/false);
11889 NewClause = OpenACCDeleteClause::Create(
11890 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11891 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11892 ParsedClause.getEndLoc());
11893}
11894
11895template <typename Derived>
11896void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
11897 const OpenACCUseDeviceClause &C) {
11898 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11899 /*IsReadOnly=*/false, /*IsZero=*/false);
11901 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11902 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11903 ParsedClause.getEndLoc());
11904}
11905
11906template <typename Derived>
11907void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
11908 const OpenACCDevicePtrClause &C) {
11909 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11910
11911 // Ensure each var is a pointer type.
11912 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11913 return Self.getSema().OpenACC().CheckVarIsPointerType(
11914 OpenACCClauseKind::DevicePtr, E);
11915 }), VarList.end());
11916
11917 ParsedClause.setVarListDetails(VarList,
11918 /*IsReadOnly=*/false, /*IsZero=*/false);
11920 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11921 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11922 ParsedClause.getEndLoc());
11923}
11924
11925template <typename Derived>
11926void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
11927 const OpenACCNumWorkersClause &C) {
11928 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11929 assert(IntExpr && "num_workers clause constructed with invalid int expr");
11930
11931 ExprResult Res = Self.TransformExpr(IntExpr);
11932 if (!Res.isUsable())
11933 return;
11934
11935 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11936 C.getClauseKind(),
11937 C.getBeginLoc(), Res.get());
11938 if (!Res.isUsable())
11939 return;
11940
11941 ParsedClause.setIntExprDetails(Res.get());
11943 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11944 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11945 ParsedClause.getEndLoc());
11946}
11947
11948template <typename Derived>
11949void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
11950 const OpenACCDeviceNumClause &C) {
11951 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11952 assert(IntExpr && "device_num clause constructed with invalid int expr");
11953
11954 ExprResult Res = Self.TransformExpr(IntExpr);
11955 if (!Res.isUsable())
11956 return;
11957
11958 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11959 C.getClauseKind(),
11960 C.getBeginLoc(), Res.get());
11961 if (!Res.isUsable())
11962 return;
11963
11964 ParsedClause.setIntExprDetails(Res.get());
11966 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11967 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11968 ParsedClause.getEndLoc());
11969}
11970
11971template <typename Derived>
11972void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
11973 const OpenACCDefaultAsyncClause &C) {
11974 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11975 assert(IntExpr && "default_async clause constructed with invalid int expr");
11976
11977 ExprResult Res = Self.TransformExpr(IntExpr);
11978 if (!Res.isUsable())
11979 return;
11980
11981 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11982 C.getClauseKind(),
11983 C.getBeginLoc(), Res.get());
11984 if (!Res.isUsable())
11985 return;
11986
11987 ParsedClause.setIntExprDetails(Res.get());
11989 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11990 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11991 ParsedClause.getEndLoc());
11992}
11993
11994template <typename Derived>
11995void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
11996 const OpenACCVectorLengthClause &C) {
11997 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11998 assert(IntExpr && "vector_length clause constructed with invalid int expr");
11999
12000 ExprResult Res = Self.TransformExpr(IntExpr);
12001 if (!Res.isUsable())
12002 return;
12003
12004 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12005 C.getClauseKind(),
12006 C.getBeginLoc(), Res.get());
12007 if (!Res.isUsable())
12008 return;
12009
12010 ParsedClause.setIntExprDetails(Res.get());
12012 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12013 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12014 ParsedClause.getEndLoc());
12015}
12016
12017template <typename Derived>
12018void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12019 const OpenACCAsyncClause &C) {
12020 if (C.hasIntExpr()) {
12021 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12022 if (!Res.isUsable())
12023 return;
12024
12025 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12026 C.getClauseKind(),
12027 C.getBeginLoc(), Res.get());
12028 if (!Res.isUsable())
12029 return;
12030 ParsedClause.setIntExprDetails(Res.get());
12031 }
12032
12033 NewClause = OpenACCAsyncClause::Create(
12034 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12035 ParsedClause.getLParenLoc(),
12036 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12037 : nullptr,
12038 ParsedClause.getEndLoc());
12039}
12040
12041template <typename Derived>
12042void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12043 const OpenACCWorkerClause &C) {
12044 if (C.hasIntExpr()) {
12045 // restrictions on this expression are all "does it exist in certain
12046 // situations" that are not possible to be dependent, so the only check we
12047 // have is that it transforms, and is an int expression.
12048 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12049 if (!Res.isUsable())
12050 return;
12051
12052 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12053 C.getClauseKind(),
12054 C.getBeginLoc(), Res.get());
12055 if (!Res.isUsable())
12056 return;
12057 ParsedClause.setIntExprDetails(Res.get());
12058 }
12059
12060 NewClause = OpenACCWorkerClause::Create(
12061 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12062 ParsedClause.getLParenLoc(),
12063 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12064 : nullptr,
12065 ParsedClause.getEndLoc());
12066}
12067
12068template <typename Derived>
12069void OpenACCClauseTransform<Derived>::VisitVectorClause(
12070 const OpenACCVectorClause &C) {
12071 if (C.hasIntExpr()) {
12072 // restrictions on this expression are all "does it exist in certain
12073 // situations" that are not possible to be dependent, so the only check we
12074 // have is that it transforms, and is an int expression.
12075 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12076 if (!Res.isUsable())
12077 return;
12078
12079 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12080 C.getClauseKind(),
12081 C.getBeginLoc(), Res.get());
12082 if (!Res.isUsable())
12083 return;
12084 ParsedClause.setIntExprDetails(Res.get());
12085 }
12086
12087 NewClause = OpenACCVectorClause::Create(
12088 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12089 ParsedClause.getLParenLoc(),
12090 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12091 : nullptr,
12092 ParsedClause.getEndLoc());
12093}
12094
12095template <typename Derived>
12096void OpenACCClauseTransform<Derived>::VisitWaitClause(
12097 const OpenACCWaitClause &C) {
12098 if (!C.getLParenLoc().isInvalid()) {
12099 Expr *DevNumExpr = nullptr;
12100 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12101
12102 // Instantiate devnum expr if it exists.
12103 if (C.getDevNumExpr()) {
12104 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12105 if (!Res.isUsable())
12106 return;
12107 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12108 C.getClauseKind(),
12109 C.getBeginLoc(), Res.get());
12110 if (!Res.isUsable())
12111 return;
12112
12113 DevNumExpr = Res.get();
12114 }
12115
12116 // Instantiate queue ids.
12117 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12118 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12119 if (!Res.isUsable())
12120 return;
12121 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12122 C.getClauseKind(),
12123 C.getBeginLoc(), Res.get());
12124 if (!Res.isUsable())
12125 return;
12126
12127 InstantiatedQueueIdExprs.push_back(Res.get());
12128 }
12129
12130 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12131 std::move(InstantiatedQueueIdExprs));
12132 }
12133
12134 NewClause = OpenACCWaitClause::Create(
12135 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12136 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12137 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12138 ParsedClause.getEndLoc());
12139}
12140
12141template <typename Derived>
12142void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12143 const OpenACCDeviceTypeClause &C) {
12144 // Nothing to transform here, just create a new version of 'C'.
12146 Self.getSema().getASTContext(), C.getClauseKind(),
12147 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12148 C.getArchitectures(), ParsedClause.getEndLoc());
12149}
12150
12151template <typename Derived>
12152void OpenACCClauseTransform<Derived>::VisitAutoClause(
12153 const OpenACCAutoClause &C) {
12154 // Nothing to do, so just create a new node.
12155 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12156 ParsedClause.getBeginLoc(),
12157 ParsedClause.getEndLoc());
12158}
12159
12160template <typename Derived>
12161void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12162 const OpenACCIndependentClause &C) {
12163 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12164 ParsedClause.getBeginLoc(),
12165 ParsedClause.getEndLoc());
12166}
12167
12168template <typename Derived>
12169void OpenACCClauseTransform<Derived>::VisitSeqClause(
12170 const OpenACCSeqClause &C) {
12171 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12172 ParsedClause.getBeginLoc(),
12173 ParsedClause.getEndLoc());
12174}
12175template <typename Derived>
12176void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12177 const OpenACCFinalizeClause &C) {
12178 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12179 ParsedClause.getBeginLoc(),
12180 ParsedClause.getEndLoc());
12181}
12182
12183template <typename Derived>
12184void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12185 const OpenACCIfPresentClause &C) {
12186 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12187 ParsedClause.getBeginLoc(),
12188 ParsedClause.getEndLoc());
12189}
12190
12191template <typename Derived>
12192void OpenACCClauseTransform<Derived>::VisitReductionClause(
12193 const OpenACCReductionClause &C) {
12194 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12195 SmallVector<Expr *> ValidVars;
12196
12197 for (Expr *Var : TransformedVars) {
12198 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12199 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12200 if (Res.isUsable())
12201 ValidVars.push_back(Res.get());
12202 }
12203
12204 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12205 ExistingClauses, ParsedClause.getDirectiveKind(),
12206 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12207 C.getReductionOp(), ValidVars, ParsedClause.getEndLoc());
12208}
12209
12210template <typename Derived>
12211void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12212 const OpenACCCollapseClause &C) {
12213 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12214 assert(LoopCount && "collapse clause constructed with invalid loop count");
12215
12216 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12217
12218 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12220 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12221
12222 NewLoopCount =
12223 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12224
12225 if (!NewLoopCount.isUsable())
12226 return;
12227
12228 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12230 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12231 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12232 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12233}
12234
12235template <typename Derived>
12236void OpenACCClauseTransform<Derived>::VisitTileClause(
12237 const OpenACCTileClause &C) {
12238
12239 llvm::SmallVector<Expr *> TransformedExprs;
12240
12241 for (Expr *E : C.getSizeExprs()) {
12242 ExprResult NewSizeExpr = Self.TransformExpr(E);
12243
12244 if (!NewSizeExpr.isUsable())
12245 return;
12246
12247 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12249 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12250
12251 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12252
12253 if (!NewSizeExpr.isUsable())
12254 return;
12255 TransformedExprs.push_back(NewSizeExpr.get());
12256 }
12257
12258 ParsedClause.setIntExprDetails(TransformedExprs);
12259 NewClause = OpenACCTileClause::Create(
12260 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12261 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12262 ParsedClause.getEndLoc());
12263}
12264template <typename Derived>
12265void OpenACCClauseTransform<Derived>::VisitGangClause(
12266 const OpenACCGangClause &C) {
12267 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12268 llvm::SmallVector<Expr *> TransformedIntExprs;
12269
12270 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12271 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12272 if (!ER.isUsable())
12273 continue;
12274
12275 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12276 ParsedClause.getDirectiveKind(),
12277 C.getExpr(I).first, ER.get());
12278 if (!ER.isUsable())
12279 continue;
12280 TransformedGangKinds.push_back(C.getExpr(I).first);
12281 TransformedIntExprs.push_back(ER.get());
12282 }
12283
12284 NewClause = Self.getSema().OpenACC().CheckGangClause(
12285 ParsedClause.getDirectiveKind(), ExistingClauses,
12286 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12287 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12288}
12289} // namespace
12290template <typename Derived>
12291OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12292 ArrayRef<const OpenACCClause *> ExistingClauses,
12293 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12294
12295 SemaOpenACC::OpenACCParsedClause ParsedClause(
12296 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12297 ParsedClause.setEndLoc(OldClause->getEndLoc());
12298
12299 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12300 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12301
12302 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12303 ParsedClause};
12304 Transform.Visit(OldClause);
12305
12306 return Transform.CreatedClause();
12307}
12308
12309template <typename Derived>
12311TreeTransform<Derived>::TransformOpenACCClauseList(
12313 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12314 for (const auto *Clause : OldClauses) {
12315 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12316 TransformedClauses, DirKind, Clause))
12317 TransformedClauses.push_back(TransformedClause);
12318 }
12319 return TransformedClauses;
12320}
12321
12322template <typename Derived>
12323StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
12324 OpenACCComputeConstruct *C) {
12325 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12326
12327 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12328 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12329 C->clauses());
12330
12331 if (getSema().OpenACC().ActOnStartStmtDirective(
12332 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12333 return StmtError();
12334
12335 // Transform Structured Block.
12336 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12337 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12338 C->clauses(), TransformedClauses);
12339 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12340 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12341 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12342
12343 return getDerived().RebuildOpenACCComputeConstruct(
12344 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12345 C->getEndLoc(), TransformedClauses, StrBlock);
12346}
12347
12348template <typename Derived>
12350TreeTransform<Derived>::TransformOpenACCLoopConstruct(OpenACCLoopConstruct *C) {
12351
12352 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12353
12354 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12355 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12356 C->clauses());
12357
12358 if (getSema().OpenACC().ActOnStartStmtDirective(
12359 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12360 return StmtError();
12361
12362 // Transform Loop.
12363 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12364 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12365 C->clauses(), TransformedClauses);
12366 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12367 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12368 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12369
12370 return getDerived().RebuildOpenACCLoopConstruct(
12371 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12372 TransformedClauses, Loop);
12373}
12374
12375template <typename Derived>
12376StmtResult TreeTransform<Derived>::TransformOpenACCCombinedConstruct(
12377 OpenACCCombinedConstruct *C) {
12378 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12379
12380 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12381 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12382 C->clauses());
12383
12384 if (getSema().OpenACC().ActOnStartStmtDirective(
12385 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12386 return StmtError();
12387
12388 // Transform Loop.
12389 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12390 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12391 C->clauses(), TransformedClauses);
12392 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12393 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12394 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12395
12396 return getDerived().RebuildOpenACCCombinedConstruct(
12397 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12398 C->getEndLoc(), TransformedClauses, Loop);
12399}
12400
12401template <typename Derived>
12403TreeTransform<Derived>::TransformOpenACCDataConstruct(OpenACCDataConstruct *C) {
12404 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12405
12406 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12407 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12408 C->clauses());
12409 if (getSema().OpenACC().ActOnStartStmtDirective(
12410 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12411 return StmtError();
12412
12413 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12414 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12415 C->clauses(), TransformedClauses);
12416 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12417 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12418 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12419
12420 return getDerived().RebuildOpenACCDataConstruct(
12421 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12422 TransformedClauses, StrBlock);
12423}
12424
12425template <typename Derived>
12426StmtResult TreeTransform<Derived>::TransformOpenACCEnterDataConstruct(
12427 OpenACCEnterDataConstruct *C) {
12428 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12429
12430 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12431 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12432 C->clauses());
12433 if (getSema().OpenACC().ActOnStartStmtDirective(
12434 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12435 return StmtError();
12436
12437 return getDerived().RebuildOpenACCEnterDataConstruct(
12438 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12439 TransformedClauses);
12440}
12441
12442template <typename Derived>
12443StmtResult TreeTransform<Derived>::TransformOpenACCExitDataConstruct(
12444 OpenACCExitDataConstruct *C) {
12445 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12446
12447 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12448 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12449 C->clauses());
12450 if (getSema().OpenACC().ActOnStartStmtDirective(
12451 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12452 return StmtError();
12453
12454 return getDerived().RebuildOpenACCExitDataConstruct(
12455 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12456 TransformedClauses);
12457}
12458
12459template <typename Derived>
12460StmtResult TreeTransform<Derived>::TransformOpenACCHostDataConstruct(
12461 OpenACCHostDataConstruct *C) {
12462 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12463
12464 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12465 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12466 C->clauses());
12467 if (getSema().OpenACC().ActOnStartStmtDirective(
12468 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12469 return StmtError();
12470
12471 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12472 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12473 C->clauses(), TransformedClauses);
12474 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12475 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12476 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12477
12478 return getDerived().RebuildOpenACCHostDataConstruct(
12479 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12480 TransformedClauses, StrBlock);
12481}
12482
12483template <typename Derived>
12485TreeTransform<Derived>::TransformOpenACCInitConstruct(OpenACCInitConstruct *C) {
12486 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12487
12488 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12489 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12490 C->clauses());
12491 if (getSema().OpenACC().ActOnStartStmtDirective(
12492 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12493 return StmtError();
12494
12495 return getDerived().RebuildOpenACCInitConstruct(
12496 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12497 TransformedClauses);
12498}
12499
12500template <typename Derived>
12501StmtResult TreeTransform<Derived>::TransformOpenACCShutdownConstruct(
12502 OpenACCShutdownConstruct *C) {
12503 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12504
12505 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12506 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12507 C->clauses());
12508 if (getSema().OpenACC().ActOnStartStmtDirective(
12509 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12510 return StmtError();
12511
12512 return getDerived().RebuildOpenACCShutdownConstruct(
12513 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12514 TransformedClauses);
12515}
12516template <typename Derived>
12518TreeTransform<Derived>::TransformOpenACCSetConstruct(OpenACCSetConstruct *C) {
12519 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12520
12521 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12522 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12523 C->clauses());
12524 if (getSema().OpenACC().ActOnStartStmtDirective(
12525 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12526 return StmtError();
12527
12528 return getDerived().RebuildOpenACCSetConstruct(
12529 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12530 TransformedClauses);
12531}
12532
12533template <typename Derived>
12534StmtResult TreeTransform<Derived>::TransformOpenACCUpdateConstruct(
12535 OpenACCUpdateConstruct *C) {
12536 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12537
12538 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12539 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12540 C->clauses());
12541 if (getSema().OpenACC().ActOnStartStmtDirective(
12542 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12543 return StmtError();
12544
12545 return getDerived().RebuildOpenACCUpdateConstruct(
12546 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12547 TransformedClauses);
12548}
12549
12550template <typename Derived>
12552TreeTransform<Derived>::TransformOpenACCWaitConstruct(OpenACCWaitConstruct *C) {
12553 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12554
12555 ExprResult DevNumExpr;
12556 if (C->hasDevNumExpr()) {
12557 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
12558
12559 if (DevNumExpr.isUsable())
12560 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
12562 C->getBeginLoc(), DevNumExpr.get());
12563 }
12564
12565 llvm::SmallVector<Expr *> QueueIdExprs;
12566
12567 for (Expr *QE : C->getQueueIdExprs()) {
12568 assert(QE && "Null queue id expr?");
12569 ExprResult NewEQ = getDerived().TransformExpr(QE);
12570
12571 if (!NewEQ.isUsable())
12572 break;
12573 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
12575 C->getBeginLoc(), NewEQ.get());
12576 if (NewEQ.isUsable())
12577 QueueIdExprs.push_back(NewEQ.get());
12578 }
12579
12580 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12581 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12582 C->clauses());
12583
12584 if (getSema().OpenACC().ActOnStartStmtDirective(
12585 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12586 return StmtError();
12587
12588 return getDerived().RebuildOpenACCWaitConstruct(
12589 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12590 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
12591 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
12592}
12593
12594template <typename Derived>
12595ExprResult TreeTransform<Derived>::TransformOpenACCAsteriskSizeExpr(
12596 OpenACCAsteriskSizeExpr *E) {
12597 if (getDerived().AlwaysRebuild())
12598 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
12599 // Nothing can ever change, so there is never anything to transform.
12600 return E;
12601}
12602
12603//===----------------------------------------------------------------------===//
12604// Expression transformation
12605//===----------------------------------------------------------------------===//
12606template<typename Derived>
12608TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
12609 return TransformExpr(E->getSubExpr());
12610}
12611
12612template <typename Derived>
12613ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
12614 SYCLUniqueStableNameExpr *E) {
12615 if (!E->isTypeDependent())
12616 return E;
12617
12618 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
12619
12620 if (!NewT)
12621 return ExprError();
12622
12623 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
12624 return E;
12625
12626 return getDerived().RebuildSYCLUniqueStableNameExpr(
12627 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
12628}
12629
12630template<typename Derived>
12632TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
12633 if (!E->isTypeDependent())
12634 return E;
12635
12636 return getDerived().RebuildPredefinedExpr(E->getLocation(),
12637 E->getIdentKind());
12638}
12639
12640template<typename Derived>
12642TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
12643 NestedNameSpecifierLoc QualifierLoc;
12644 if (E->getQualifierLoc()) {
12645 QualifierLoc
12646 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12647 if (!QualifierLoc)
12648 return ExprError();
12649 }
12650
12651 ValueDecl *ND
12652 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
12653 E->getDecl()));
12654 if (!ND)
12655 return ExprError();
12656
12657 NamedDecl *Found = ND;
12658 if (E->getFoundDecl() != E->getDecl()) {
12659 Found = cast_or_null<NamedDecl>(
12660 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
12661 if (!Found)
12662 return ExprError();
12663 }
12664
12665 DeclarationNameInfo NameInfo = E->getNameInfo();
12666 if (NameInfo.getName()) {
12667 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
12668 if (!NameInfo.getName())
12669 return ExprError();
12670 }
12671
12672 if (!getDerived().AlwaysRebuild() &&
12673 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
12674 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
12675 Found == E->getFoundDecl() &&
12676 NameInfo.getName() == E->getDecl()->getDeclName() &&
12677 !E->hasExplicitTemplateArgs()) {
12678
12679 // Mark it referenced in the new context regardless.
12680 // FIXME: this is a bit instantiation-specific.
12681 SemaRef.MarkDeclRefReferenced(E);
12682
12683 return E;
12684 }
12685
12686 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
12687 if (E->hasExplicitTemplateArgs()) {
12688 TemplateArgs = &TransArgs;
12689 TransArgs.setLAngleLoc(E->getLAngleLoc());
12690 TransArgs.setRAngleLoc(E->getRAngleLoc());
12691 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
12692 E->getNumTemplateArgs(),
12693 TransArgs))
12694 return ExprError();
12695 }
12696
12697 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
12698 Found, TemplateArgs);
12699}
12700
12701template<typename Derived>
12703TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
12704 return E;
12705}
12706
12707template <typename Derived>
12708ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
12709 FixedPointLiteral *E) {
12710 return E;
12711}
12712
12713template<typename Derived>
12715TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
12716 return E;
12717}
12718
12719template<typename Derived>
12721TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
12722 return E;
12723}
12724
12725template<typename Derived>
12727TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
12728 return E;
12729}
12730
12731template<typename Derived>
12733TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
12734 return E;
12735}
12736
12737template<typename Derived>
12739TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
12740 return getDerived().TransformCallExpr(E);
12741}
12742
12743template<typename Derived>
12745TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
12746 ExprResult ControllingExpr;
12747 TypeSourceInfo *ControllingType = nullptr;
12748 if (E->isExprPredicate())
12749 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
12750 else
12751 ControllingType = getDerived().TransformType(E->getControllingType());
12752
12753 if (ControllingExpr.isInvalid() && !ControllingType)
12754 return ExprError();
12755
12756 SmallVector<Expr *, 4> AssocExprs;
12758 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
12759 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
12760 if (TSI) {
12761 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
12762 if (!AssocType)
12763 return ExprError();
12764 AssocTypes.push_back(AssocType);
12765 } else {
12766 AssocTypes.push_back(nullptr);
12767 }
12768
12769 ExprResult AssocExpr =
12770 getDerived().TransformExpr(Assoc.getAssociationExpr());
12771 if (AssocExpr.isInvalid())
12772 return ExprError();
12773 AssocExprs.push_back(AssocExpr.get());
12774 }
12775
12776 if (!ControllingType)
12777 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
12778 E->getDefaultLoc(),
12779 E->getRParenLoc(),
12780 ControllingExpr.get(),
12781 AssocTypes,
12782 AssocExprs);
12783 return getDerived().RebuildGenericSelectionExpr(
12784 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
12785 ControllingType, AssocTypes, AssocExprs);
12786}
12787
12788template<typename Derived>
12790TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
12791 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12792 if (SubExpr.isInvalid())
12793 return ExprError();
12794
12795 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
12796 return E;
12797
12798 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
12799 E->getRParen());
12800}
12801
12802/// The operand of a unary address-of operator has special rules: it's
12803/// allowed to refer to a non-static member of a class even if there's no 'this'
12804/// object available.
12805template<typename Derived>
12808 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
12809 return getDerived().TransformDependentScopeDeclRefExpr(
12810 DRE, /*IsAddressOfOperand=*/true, nullptr);
12811 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
12812 return getDerived().TransformUnresolvedLookupExpr(
12813 ULE, /*IsAddressOfOperand=*/true);
12814 else
12815 return getDerived().TransformExpr(E);
12816}
12817
12818template<typename Derived>
12821 ExprResult SubExpr;
12822 if (E->getOpcode() == UO_AddrOf)
12823 SubExpr = TransformAddressOfOperand(E->getSubExpr());
12824 else
12825 SubExpr = TransformExpr(E->getSubExpr());
12826 if (SubExpr.isInvalid())
12827 return ExprError();
12828
12829 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
12830 return E;
12831
12832 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
12833 E->getOpcode(),
12834 SubExpr.get());
12835}
12836
12837template<typename Derived>
12839TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
12840 // Transform the type.
12841 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12842 if (!Type)
12843 return ExprError();
12844
12845 // Transform all of the components into components similar to what the
12846 // parser uses.
12847 // FIXME: It would be slightly more efficient in the non-dependent case to
12848 // just map FieldDecls, rather than requiring the rebuilder to look for
12849 // the fields again. However, __builtin_offsetof is rare enough in
12850 // template code that we don't care.
12851 bool ExprChanged = false;
12852 typedef Sema::OffsetOfComponent Component;
12853 SmallVector<Component, 4> Components;
12854 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
12855 const OffsetOfNode &ON = E->getComponent(I);
12856 Component Comp;
12857 Comp.isBrackets = true;
12858 Comp.LocStart = ON.getSourceRange().getBegin();
12859 Comp.LocEnd = ON.getSourceRange().getEnd();
12860 switch (ON.getKind()) {
12861 case OffsetOfNode::Array: {
12862 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
12863 ExprResult Index = getDerived().TransformExpr(FromIndex);
12864 if (Index.isInvalid())
12865 return ExprError();
12866
12867 ExprChanged = ExprChanged || Index.get() != FromIndex;
12868 Comp.isBrackets = true;
12869 Comp.U.E = Index.get();
12870 break;
12871 }
12872
12875 Comp.isBrackets = false;
12876 Comp.U.IdentInfo = ON.getFieldName();
12877 if (!Comp.U.IdentInfo)
12878 continue;
12879
12880 break;
12881
12882 case OffsetOfNode::Base:
12883 // Will be recomputed during the rebuild.
12884 continue;
12885 }
12886
12887 Components.push_back(Comp);
12888 }
12889
12890 // If nothing changed, retain the existing expression.
12891 if (!getDerived().AlwaysRebuild() &&
12892 Type == E->getTypeSourceInfo() &&
12893 !ExprChanged)
12894 return E;
12895
12896 // Build a new offsetof expression.
12897 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
12898 Components, E->getRParenLoc());
12899}
12900
12901template<typename Derived>
12903TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
12904 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
12905 "opaque value expression requires transformation");
12906 return E;
12907}
12908
12909template<typename Derived>
12911TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
12912 return E;
12913}
12914
12915template <typename Derived>
12916ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) {
12918 bool Changed = false;
12919 for (Expr *C : E->subExpressions()) {
12920 ExprResult NewC = getDerived().TransformExpr(C);
12921 if (NewC.isInvalid())
12922 return ExprError();
12923 Children.push_back(NewC.get());
12924
12925 Changed |= NewC.get() != C;
12926 }
12927 if (!getDerived().AlwaysRebuild() && !Changed)
12928 return E;
12929 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
12930 Children, E->getType());
12931}
12932
12933template<typename Derived>
12935TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
12936 // Rebuild the syntactic form. The original syntactic form has
12937 // opaque-value expressions in it, so strip those away and rebuild
12938 // the result. This is a really awful way of doing this, but the
12939 // better solution (rebuilding the semantic expressions and
12940 // rebinding OVEs as necessary) doesn't work; we'd need
12941 // TreeTransform to not strip away implicit conversions.
12942 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
12943 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
12944 if (result.isInvalid()) return ExprError();
12945
12946 // If that gives us a pseudo-object result back, the pseudo-object
12947 // expression must have been an lvalue-to-rvalue conversion which we
12948 // should reapply.
12949 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
12950 result = SemaRef.PseudoObject().checkRValue(result.get());
12951
12952 return result;
12953}
12954
12955template<typename Derived>
12957TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
12958 UnaryExprOrTypeTraitExpr *E) {
12959 if (E->isArgumentType()) {
12960 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
12961
12962 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
12963 if (!NewT)
12964 return ExprError();
12965
12966 if (!getDerived().AlwaysRebuild() && OldT == NewT)
12967 return E;
12968
12969 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
12970 E->getKind(),
12971 E->getSourceRange());
12972 }
12973
12974 // C++0x [expr.sizeof]p1:
12975 // The operand is either an expression, which is an unevaluated operand
12976 // [...]
12977 EnterExpressionEvaluationContext Unevaluated(
12980
12981 // Try to recover if we have something like sizeof(T::X) where X is a type.
12982 // Notably, there must be *exactly* one set of parens if X is a type.
12983 TypeSourceInfo *RecoveryTSI = nullptr;
12984 ExprResult SubExpr;
12985 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
12986 if (auto *DRE =
12987 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
12988 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
12989 PE, DRE, false, &RecoveryTSI);
12990 else
12991 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
12992
12993 if (RecoveryTSI) {
12994 return getDerived().RebuildUnaryExprOrTypeTrait(
12995 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
12996 } else if (SubExpr.isInvalid())
12997 return ExprError();
12998
12999 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13000 return E;
13001
13002 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13003 E->getOperatorLoc(),
13004 E->getKind(),
13005 E->getSourceRange());
13006}
13007
13008template<typename Derived>
13010TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
13011 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13012 if (LHS.isInvalid())
13013 return ExprError();
13014
13015 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13016 if (RHS.isInvalid())
13017 return ExprError();
13018
13019
13020 if (!getDerived().AlwaysRebuild() &&
13021 LHS.get() == E->getLHS() &&
13022 RHS.get() == E->getRHS())
13023 return E;
13024
13025 return getDerived().RebuildArraySubscriptExpr(
13026 LHS.get(),
13027 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13028}
13029
13030template <typename Derived>
13032TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
13033 ExprResult Base = getDerived().TransformExpr(E->getBase());
13034 if (Base.isInvalid())
13035 return ExprError();
13036
13037 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13038 if (RowIdx.isInvalid())
13039 return ExprError();
13040
13041 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13042 if (ColumnIdx.isInvalid())
13043 return ExprError();
13044
13045 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13046 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13047 return E;
13048
13049 return getDerived().RebuildMatrixSubscriptExpr(
13050 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13051}
13052
13053template <typename Derived>
13055TreeTransform<Derived>::TransformArraySectionExpr(ArraySectionExpr *E) {
13056 ExprResult Base = getDerived().TransformExpr(E->getBase());
13057 if (Base.isInvalid())
13058 return ExprError();
13059
13060 ExprResult LowerBound;
13061 if (E->getLowerBound()) {
13062 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13063 if (LowerBound.isInvalid())
13064 return ExprError();
13065 }
13066
13067 ExprResult Length;
13068 if (E->getLength()) {
13069 Length = getDerived().TransformExpr(E->getLength());
13070 if (Length.isInvalid())
13071 return ExprError();
13072 }
13073
13074 ExprResult Stride;
13075 if (E->isOMPArraySection()) {
13076 if (Expr *Str = E->getStride()) {
13077 Stride = getDerived().TransformExpr(Str);
13078 if (Stride.isInvalid())
13079 return ExprError();
13080 }
13081 }
13082
13083 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13084 LowerBound.get() == E->getLowerBound() &&
13085 Length.get() == E->getLength() &&
13086 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13087 return E;
13088
13089 return getDerived().RebuildArraySectionExpr(
13090 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13091 LowerBound.get(), E->getColonLocFirst(),
13092 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13093 Length.get(), Stride.get(), E->getRBracketLoc());
13094}
13095
13096template <typename Derived>
13098TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
13099 ExprResult Base = getDerived().TransformExpr(E->getBase());
13100 if (Base.isInvalid())
13101 return ExprError();
13102
13104 bool ErrorFound = false;
13105 for (Expr *Dim : E->getDimensions()) {
13106 ExprResult DimRes = getDerived().TransformExpr(Dim);
13107 if (DimRes.isInvalid()) {
13108 ErrorFound = true;
13109 continue;
13110 }
13111 Dims.push_back(DimRes.get());
13112 }
13113
13114 if (ErrorFound)
13115 return ExprError();
13116 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13117 E->getRParenLoc(), Dims,
13118 E->getBracketsRanges());
13119}
13120
13121template <typename Derived>
13123TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) {
13124 unsigned NumIterators = E->numOfIterators();
13126
13127 bool ErrorFound = false;
13128 bool NeedToRebuild = getDerived().AlwaysRebuild();
13129 for (unsigned I = 0; I < NumIterators; ++I) {
13130 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13131 Data[I].DeclIdent = D->getIdentifier();
13132 Data[I].DeclIdentLoc = D->getLocation();
13133 if (D->getLocation() == D->getBeginLoc()) {
13134 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13135 "Implicit type must be int.");
13136 } else {
13137 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13138 QualType DeclTy = getDerived().TransformType(D->getType());
13139 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13140 }
13141 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13142 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13143 ExprResult End = getDerived().TransformExpr(Range.End);
13144 ExprResult Step = getDerived().TransformExpr(Range.Step);
13145 ErrorFound = ErrorFound ||
13146 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13147 !Data[I].Type.get().isNull())) ||
13148 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13149 if (ErrorFound)
13150 continue;
13151 Data[I].Range.Begin = Begin.get();
13152 Data[I].Range.End = End.get();
13153 Data[I].Range.Step = Step.get();
13154 Data[I].AssignLoc = E->getAssignLoc(I);
13155 Data[I].ColonLoc = E->getColonLoc(I);
13156 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13157 NeedToRebuild =
13158 NeedToRebuild ||
13159 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13160 D->getType().getTypePtrOrNull()) ||
13161 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13162 Range.Step != Data[I].Range.Step;
13163 }
13164 if (ErrorFound)
13165 return ExprError();
13166 if (!NeedToRebuild)
13167 return E;
13168
13169 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13170 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13171 if (!Res.isUsable())
13172 return Res;
13173 auto *IE = cast<OMPIteratorExpr>(Res.get());
13174 for (unsigned I = 0; I < NumIterators; ++I)
13175 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13176 IE->getIteratorDecl(I));
13177 return Res;
13178}
13179
13180template<typename Derived>
13182TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
13183 // Transform the callee.
13184 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13185 if (Callee.isInvalid())
13186 return ExprError();
13187
13188 // Transform arguments.
13189 bool ArgChanged = false;
13191 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13192 &ArgChanged))
13193 return ExprError();
13194
13195 if (!getDerived().AlwaysRebuild() &&
13196 Callee.get() == E->getCallee() &&
13197 !ArgChanged)
13198 return SemaRef.MaybeBindToTemporary(E);
13199
13200 // FIXME: Wrong source location information for the '('.
13201 SourceLocation FakeLParenLoc
13202 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13203
13204 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13205 if (E->hasStoredFPFeatures()) {
13206 FPOptionsOverride NewOverrides = E->getFPFeatures();
13207 getSema().CurFPFeatures =
13208 NewOverrides.applyOverrides(getSema().getLangOpts());
13209 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13210 }
13211
13212 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13213 Args,
13214 E->getRParenLoc());
13215}
13216
13217template<typename Derived>
13219TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
13220 ExprResult Base = getDerived().TransformExpr(E->getBase());
13221 if (Base.isInvalid())
13222 return ExprError();
13223
13224 NestedNameSpecifierLoc QualifierLoc;
13225 if (E->hasQualifier()) {
13226 QualifierLoc
13227 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13228
13229 if (!QualifierLoc)
13230 return ExprError();
13231 }
13232 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13233
13234 ValueDecl *Member
13235 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
13236 E->getMemberDecl()));
13237 if (!Member)
13238 return ExprError();
13239
13240 NamedDecl *FoundDecl = E->getFoundDecl();
13241 if (FoundDecl == E->getMemberDecl()) {
13242 FoundDecl = Member;
13243 } else {
13244 FoundDecl = cast_or_null<NamedDecl>(
13245 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
13246 if (!FoundDecl)
13247 return ExprError();
13248 }
13249
13250 if (!getDerived().AlwaysRebuild() &&
13251 Base.get() == E->getBase() &&
13252 QualifierLoc == E->getQualifierLoc() &&
13253 Member == E->getMemberDecl() &&
13254 FoundDecl == E->getFoundDecl() &&
13255 !E->hasExplicitTemplateArgs()) {
13256
13257 // Skip for member expression of (this->f), rebuilt thisi->f is needed
13258 // for Openmp where the field need to be privatizized in the case.
13259 if (!(isa<CXXThisExpr>(E->getBase()) &&
13260 getSema().OpenMP().isOpenMPRebuildMemberExpr(
13261 cast<ValueDecl>(Member)))) {
13262 // Mark it referenced in the new context regardless.
13263 // FIXME: this is a bit instantiation-specific.
13264 SemaRef.MarkMemberReferenced(E);
13265 return E;
13266 }
13267 }
13268
13269 TemplateArgumentListInfo TransArgs;
13270 if (E->hasExplicitTemplateArgs()) {
13271 TransArgs.setLAngleLoc(E->getLAngleLoc());
13272 TransArgs.setRAngleLoc(E->getRAngleLoc());
13273 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13274 E->getNumTemplateArgs(),
13275 TransArgs))
13276 return ExprError();
13277 }
13278
13279 // FIXME: Bogus source location for the operator
13280 SourceLocation FakeOperatorLoc =
13281 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
13282
13283 // FIXME: to do this check properly, we will need to preserve the
13284 // first-qualifier-in-scope here, just in case we had a dependent
13285 // base (and therefore couldn't do the check) and a
13286 // nested-name-qualifier (and therefore could do the lookup).
13287 NamedDecl *FirstQualifierInScope = nullptr;
13288 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
13289 if (MemberNameInfo.getName()) {
13290 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
13291 if (!MemberNameInfo.getName())
13292 return ExprError();
13293 }
13294
13295 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
13296 E->isArrow(),
13297 QualifierLoc,
13298 TemplateKWLoc,
13299 MemberNameInfo,
13300 Member,
13301 FoundDecl,
13302 (E->hasExplicitTemplateArgs()
13303 ? &TransArgs : nullptr),
13304 FirstQualifierInScope);
13305}
13306
13307template<typename Derived>
13309TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
13310 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13311 if (LHS.isInvalid())
13312 return ExprError();
13313
13314 ExprResult RHS =
13315 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
13316 if (RHS.isInvalid())
13317 return ExprError();
13318
13319 if (!getDerived().AlwaysRebuild() &&
13320 LHS.get() == E->getLHS() &&
13321 RHS.get() == E->getRHS())
13322 return E;
13323
13324 if (E->isCompoundAssignmentOp())
13325 // FPFeatures has already been established from trailing storage
13326 return getDerived().RebuildBinaryOperator(
13327 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
13328 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13329 FPOptionsOverride NewOverrides(E->getFPFeatures());
13330 getSema().CurFPFeatures =
13331 NewOverrides.applyOverrides(getSema().getLangOpts());
13332 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13333 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
13334 LHS.get(), RHS.get());
13335}
13336
13337template <typename Derived>
13338ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
13339 CXXRewrittenBinaryOperator *E) {
13340 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
13341
13342 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
13343 if (LHS.isInvalid())
13344 return ExprError();
13345
13346 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
13347 if (RHS.isInvalid())
13348 return ExprError();
13349
13350 // Extract the already-resolved callee declarations so that we can restrict
13351 // ourselves to using them as the unqualified lookup results when rebuilding.
13352 UnresolvedSet<2> UnqualLookups;
13353 bool ChangedAnyLookups = false;
13354 Expr *PossibleBinOps[] = {E->getSemanticForm(),
13355 const_cast<Expr *>(Decomp.InnerBinOp)};
13356 for (Expr *PossibleBinOp : PossibleBinOps) {
13357 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
13358 if (!Op)
13359 continue;
13360 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
13361 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
13362 continue;
13363
13364 // Transform the callee in case we built a call to a local extern
13365 // declaration.
13366 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
13367 E->getOperatorLoc(), Callee->getFoundDecl()));
13368 if (!Found)
13369 return ExprError();
13370 if (Found != Callee->getFoundDecl())
13371 ChangedAnyLookups = true;
13372 UnqualLookups.addDecl(Found);
13373 }
13374
13375 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
13376 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
13377 // Mark all functions used in the rewrite as referenced. Note that when
13378 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
13379 // function calls, and/or there might be a user-defined conversion sequence
13380 // applied to the operands of the <.
13381 // FIXME: this is a bit instantiation-specific.
13382 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
13383 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
13384 return E;
13385 }
13386
13387 return getDerived().RebuildCXXRewrittenBinaryOperator(
13388 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
13389}
13390
13391template<typename Derived>
13393TreeTransform<Derived>::TransformCompoundAssignOperator(
13394 CompoundAssignOperator *E) {
13395 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13396 FPOptionsOverride NewOverrides(E->getFPFeatures());
13397 getSema().CurFPFeatures =
13398 NewOverrides.applyOverrides(getSema().getLangOpts());
13399 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13400 return getDerived().TransformBinaryOperator(E);
13401}
13402
13403template<typename Derived>
13404ExprResult TreeTransform<Derived>::
13405TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
13406 // Just rebuild the common and RHS expressions and see whether we
13407 // get any changes.
13408
13409 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
13410 if (commonExpr.isInvalid())
13411 return ExprError();
13412
13413 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
13414 if (rhs.isInvalid())
13415 return ExprError();
13416
13417 if (!getDerived().AlwaysRebuild() &&
13418 commonExpr.get() == e->getCommon() &&
13419 rhs.get() == e->getFalseExpr())
13420 return e;
13421
13422 return getDerived().RebuildConditionalOperator(commonExpr.get(),
13423 e->getQuestionLoc(),
13424 nullptr,
13425 e->getColonLoc(),
13426 rhs.get());
13427}
13428
13429template<typename Derived>
13431TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
13432 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13433 if (Cond.isInvalid())
13434 return ExprError();
13435
13436 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13437 if (LHS.isInvalid())
13438 return ExprError();
13439
13440 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13441 if (RHS.isInvalid())
13442 return ExprError();
13443
13444 if (!getDerived().AlwaysRebuild() &&
13445 Cond.get() == E->getCond() &&
13446 LHS.get() == E->getLHS() &&
13447 RHS.get() == E->getRHS())
13448 return E;
13449
13450 return getDerived().RebuildConditionalOperator(Cond.get(),
13451 E->getQuestionLoc(),
13452 LHS.get(),
13453 E->getColonLoc(),
13454 RHS.get());
13455}
13456
13457template<typename Derived>
13459TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
13460 // Implicit casts are eliminated during transformation, since they
13461 // will be recomputed by semantic analysis after transformation.
13462 return getDerived().TransformExpr(E->getSubExprAsWritten());
13463}
13464
13465template<typename Derived>
13467TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
13468 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13469 if (!Type)
13470 return ExprError();
13471
13472 ExprResult SubExpr
13473 = getDerived().TransformExpr(E->getSubExprAsWritten());
13474 if (SubExpr.isInvalid())
13475 return ExprError();
13476
13477 if (!getDerived().AlwaysRebuild() &&
13478 Type == E->getTypeInfoAsWritten() &&
13479 SubExpr.get() == E->getSubExpr())
13480 return E;
13481
13482 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
13483 Type,
13484 E->getRParenLoc(),
13485 SubExpr.get());
13486}
13487
13488template<typename Derived>
13490TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
13491 TypeSourceInfo *OldT = E->getTypeSourceInfo();
13492 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13493 if (!NewT)
13494 return ExprError();
13495
13496 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
13497 if (Init.isInvalid())
13498 return ExprError();
13499
13500 if (!getDerived().AlwaysRebuild() &&
13501 OldT == NewT &&
13502 Init.get() == E->getInitializer())
13503 return SemaRef.MaybeBindToTemporary(E);
13504
13505 // Note: the expression type doesn't necessarily match the
13506 // type-as-written, but that's okay, because it should always be
13507 // derivable from the initializer.
13508
13509 return getDerived().RebuildCompoundLiteralExpr(
13510 E->getLParenLoc(), NewT,
13511 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
13512}
13513
13514template<typename Derived>
13516TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
13517 ExprResult Base = getDerived().TransformExpr(E->getBase());
13518 if (Base.isInvalid())
13519 return ExprError();
13520
13521 if (!getDerived().AlwaysRebuild() &&
13522 Base.get() == E->getBase())
13523 return E;
13524
13525 // FIXME: Bad source location
13526 SourceLocation FakeOperatorLoc =
13527 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
13528 return getDerived().RebuildExtVectorElementExpr(
13529 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
13530 E->getAccessor());
13531}
13532
13533template<typename Derived>
13535TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
13536 if (InitListExpr *Syntactic = E->getSyntacticForm())
13537 E = Syntactic;
13538
13539 bool InitChanged = false;
13540
13541 EnterExpressionEvaluationContext Context(
13543
13545 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
13546 Inits, &InitChanged))
13547 return ExprError();
13548
13549 if (!getDerived().AlwaysRebuild() && !InitChanged) {
13550 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
13551 // in some cases. We can't reuse it in general, because the syntactic and
13552 // semantic forms are linked, and we can't know that semantic form will
13553 // match even if the syntactic form does.
13554 }
13555
13556 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
13557 E->getRBraceLoc());
13558}
13559
13560template<typename Derived>
13562TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
13563 Designation Desig;
13564
13565 // transform the initializer value
13566 ExprResult Init = getDerived().TransformExpr(E->getInit());
13567 if (Init.isInvalid())
13568 return ExprError();
13569
13570 // transform the designators.
13571 SmallVector<Expr*, 4> ArrayExprs;
13572 bool ExprChanged = false;
13573 for (const DesignatedInitExpr::Designator &D : E->designators()) {
13574 if (D.isFieldDesignator()) {
13575 if (D.getFieldDecl()) {
13576 FieldDecl *Field = cast_or_null<FieldDecl>(
13577 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
13578 if (Field != D.getFieldDecl())
13579 // Rebuild the expression when the transformed FieldDecl is
13580 // different to the already assigned FieldDecl.
13581 ExprChanged = true;
13582 if (Field->isAnonymousStructOrUnion())
13583 continue;
13584 } else {
13585 // Ensure that the designator expression is rebuilt when there isn't
13586 // a resolved FieldDecl in the designator as we don't want to assign
13587 // a FieldDecl to a pattern designator that will be instantiated again.
13588 ExprChanged = true;
13589 }
13590 Desig.AddDesignator(Designator::CreateFieldDesignator(
13591 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
13592 continue;
13593 }
13594
13595 if (D.isArrayDesignator()) {
13596 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
13597 if (Index.isInvalid())
13598 return ExprError();
13599
13600 Desig.AddDesignator(
13601 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
13602
13603 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
13604 ArrayExprs.push_back(Index.get());
13605 continue;
13606 }
13607
13608 assert(D.isArrayRangeDesignator() && "New kind of designator?");
13609 ExprResult Start
13610 = getDerived().TransformExpr(E->getArrayRangeStart(D));
13611 if (Start.isInvalid())
13612 return ExprError();
13613
13614 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
13615 if (End.isInvalid())
13616 return ExprError();
13617
13618 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
13619 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
13620
13621 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
13622 End.get() != E->getArrayRangeEnd(D);
13623
13624 ArrayExprs.push_back(Start.get());
13625 ArrayExprs.push_back(End.get());
13626 }
13627
13628 if (!getDerived().AlwaysRebuild() &&
13629 Init.get() == E->getInit() &&
13630 !ExprChanged)
13631 return E;
13632
13633 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
13634 E->getEqualOrColonLoc(),
13635 E->usesGNUSyntax(), Init.get());
13636}
13637
13638// Seems that if TransformInitListExpr() only works on the syntactic form of an
13639// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
13640template<typename Derived>
13642TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
13643 DesignatedInitUpdateExpr *E) {
13644 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
13645 "initializer");
13646 return ExprError();
13647}
13648
13649template<typename Derived>
13651TreeTransform<Derived>::TransformNoInitExpr(
13652 NoInitExpr *E) {
13653 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
13654 return ExprError();
13655}
13656
13657template<typename Derived>
13659TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
13660 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
13661 return ExprError();
13662}
13663
13664template<typename Derived>
13666TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
13667 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
13668 return ExprError();
13669}
13670
13671template<typename Derived>
13673TreeTransform<Derived>::TransformImplicitValueInitExpr(
13674 ImplicitValueInitExpr *E) {
13675 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
13676
13677 // FIXME: Will we ever have proper type location here? Will we actually
13678 // need to transform the type?
13679 QualType T = getDerived().TransformType(E->getType());
13680 if (T.isNull())
13681 return ExprError();
13682
13683 if (!getDerived().AlwaysRebuild() &&
13684 T == E->getType())
13685 return E;
13686
13687 return getDerived().RebuildImplicitValueInitExpr(T);
13688}
13689
13690template<typename Derived>
13692TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
13693 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
13694 if (!TInfo)
13695 return ExprError();
13696
13697 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13698 if (SubExpr.isInvalid())
13699 return ExprError();
13700
13701 if (!getDerived().AlwaysRebuild() &&
13702 TInfo == E->getWrittenTypeInfo() &&
13703 SubExpr.get() == E->getSubExpr())
13704 return E;
13705
13706 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
13707 TInfo, E->getRParenLoc());
13708}
13709
13710template<typename Derived>
13712TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
13713 bool ArgumentChanged = false;
13715 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
13716 &ArgumentChanged))
13717 return ExprError();
13718
13719 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
13720 Inits,
13721 E->getRParenLoc());
13722}
13723
13724/// Transform an address-of-label expression.
13725///
13726/// By default, the transformation of an address-of-label expression always
13727/// rebuilds the expression, so that the label identifier can be resolved to
13728/// the corresponding label statement by semantic analysis.
13729template<typename Derived>
13731TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
13732 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
13733 E->getLabel());
13734 if (!LD)
13735 return ExprError();
13736
13737 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
13738 cast<LabelDecl>(LD));
13739}
13740
13741template<typename Derived>
13743TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
13744 SemaRef.ActOnStartStmtExpr();
13745 StmtResult SubStmt
13746 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
13747 if (SubStmt.isInvalid()) {
13748 SemaRef.ActOnStmtExprError();
13749 return ExprError();
13750 }
13751
13752 unsigned OldDepth = E->getTemplateDepth();
13753 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
13754
13755 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
13756 SubStmt.get() == E->getSubStmt()) {
13757 // Calling this an 'error' is unintuitive, but it does the right thing.
13758 SemaRef.ActOnStmtExprError();
13759 return SemaRef.MaybeBindToTemporary(E);
13760 }
13761
13762 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
13763 E->getRParenLoc(), NewDepth);
13764}
13765
13766template<typename Derived>
13768TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
13769 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13770 if (Cond.isInvalid())
13771 return ExprError();
13772
13773 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13774 if (LHS.isInvalid())
13775 return ExprError();
13776
13777 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13778 if (RHS.isInvalid())
13779 return ExprError();
13780
13781 if (!getDerived().AlwaysRebuild() &&
13782 Cond.get() == E->getCond() &&
13783 LHS.get() == E->getLHS() &&
13784 RHS.get() == E->getRHS())
13785 return E;
13786
13787 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
13788 Cond.get(), LHS.get(), RHS.get(),
13789 E->getRParenLoc());
13790}
13791
13792template<typename Derived>
13794TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
13795 return E;
13796}
13797
13798template<typename Derived>
13800TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
13801 switch (E->getOperator()) {
13802 case OO_New:
13803 case OO_Delete:
13804 case OO_Array_New:
13805 case OO_Array_Delete:
13806 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
13807
13808 case OO_Subscript:
13809 case OO_Call: {
13810 // This is a call to an object's operator().
13811 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
13812
13813 // Transform the object itself.
13814 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
13815 if (Object.isInvalid())
13816 return ExprError();
13817
13818 // FIXME: Poor location information
13819 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
13820 static_cast<Expr *>(Object.get())->getEndLoc());
13821
13822 // Transform the call arguments.
13824 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
13825 Args))
13826 return ExprError();
13827
13828 if (E->getOperator() == OO_Subscript)
13829 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
13830 Args, E->getEndLoc());
13831
13832 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
13833 E->getEndLoc());
13834 }
13835
13836#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
13837 case OO_##Name: \
13838 break;
13839
13840#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
13841#include "clang/Basic/OperatorKinds.def"
13842
13843 case OO_Conditional:
13844 llvm_unreachable("conditional operator is not actually overloadable");
13845
13846 case OO_None:
13848 llvm_unreachable("not an overloaded operator?");
13849 }
13850
13852 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
13853 First = getDerived().TransformAddressOfOperand(E->getArg(0));
13854 else
13855 First = getDerived().TransformExpr(E->getArg(0));
13856 if (First.isInvalid())
13857 return ExprError();
13858
13859 ExprResult Second;
13860 if (E->getNumArgs() == 2) {
13861 Second =
13862 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
13863 if (Second.isInvalid())
13864 return ExprError();
13865 }
13866
13867 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13868 FPOptionsOverride NewOverrides(E->getFPFeatures());
13869 getSema().CurFPFeatures =
13870 NewOverrides.applyOverrides(getSema().getLangOpts());
13871 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13872
13873 Expr *Callee = E->getCallee();
13874 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
13875 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
13877 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
13878 return ExprError();
13879
13880 return getDerived().RebuildCXXOperatorCallExpr(
13881 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
13882 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
13883 }
13884
13885 UnresolvedSet<1> Functions;
13886 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
13887 Callee = ICE->getSubExprAsWritten();
13888 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
13889 ValueDecl *VD = cast_or_null<ValueDecl>(
13890 getDerived().TransformDecl(DR->getLocation(), DR));
13891 if (!VD)
13892 return ExprError();
13893
13894 if (!isa<CXXMethodDecl>(VD))
13895 Functions.addDecl(VD);
13896
13897 return getDerived().RebuildCXXOperatorCallExpr(
13898 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
13899 /*RequiresADL=*/false, Functions, First.get(), Second.get());
13900}
13901
13902template<typename Derived>
13904TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
13905 return getDerived().TransformCallExpr(E);
13906}
13907
13908template <typename Derived>
13909ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
13910 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
13911 getSema().CurContext != E->getParentContext();
13912
13913 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
13914 return E;
13915
13916 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
13917 E->getBeginLoc(), E->getEndLoc(),
13918 getSema().CurContext);
13919}
13920
13921template <typename Derived>
13922ExprResult TreeTransform<Derived>::TransformEmbedExpr(EmbedExpr *E) {
13923 return E;
13924}
13925
13926template<typename Derived>
13928TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
13929 // Transform the callee.
13930 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13931 if (Callee.isInvalid())
13932 return ExprError();
13933
13934 // Transform exec config.
13935 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
13936 if (EC.isInvalid())
13937 return ExprError();
13938
13939 // Transform arguments.
13940 bool ArgChanged = false;
13942 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13943 &ArgChanged))
13944 return ExprError();
13945
13946 if (!getDerived().AlwaysRebuild() &&
13947 Callee.get() == E->getCallee() &&
13948 !ArgChanged)
13949 return SemaRef.MaybeBindToTemporary(E);
13950
13951 // FIXME: Wrong source location information for the '('.
13952 SourceLocation FakeLParenLoc
13953 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13954 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13955 Args,
13956 E->getRParenLoc(), EC.get());
13957}
13958
13959template<typename Derived>
13962 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13963 if (!Type)
13964 return ExprError();
13965
13966 ExprResult SubExpr
13967 = getDerived().TransformExpr(E->getSubExprAsWritten());
13968 if (SubExpr.isInvalid())
13969 return ExprError();
13970
13971 if (!getDerived().AlwaysRebuild() &&
13972 Type == E->getTypeInfoAsWritten() &&
13973 SubExpr.get() == E->getSubExpr())
13974 return E;
13975 return getDerived().RebuildCXXNamedCastExpr(
13976 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
13977 Type, E->getAngleBrackets().getEnd(),
13978 // FIXME. this should be '(' location
13979 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
13980}
13981
13982template<typename Derived>
13985 TypeSourceInfo *TSI =
13986 getDerived().TransformType(BCE->getTypeInfoAsWritten());
13987 if (!TSI)
13988 return ExprError();
13989
13990 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
13991 if (Sub.isInvalid())
13992 return ExprError();
13993
13994 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
13995 Sub.get(), BCE->getEndLoc());
13996}
13997
13998template<typename Derived>
14000TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14001 return getDerived().TransformCXXNamedCastExpr(E);
14002}
14003
14004template<typename Derived>
14006TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
14007 return getDerived().TransformCXXNamedCastExpr(E);
14008}
14009
14010template<typename Derived>
14012TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
14013 CXXReinterpretCastExpr *E) {
14014 return getDerived().TransformCXXNamedCastExpr(E);
14015}
14016
14017template<typename Derived>
14019TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
14020 return getDerived().TransformCXXNamedCastExpr(E);
14021}
14022
14023template<typename Derived>
14025TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
14026 return getDerived().TransformCXXNamedCastExpr(E);
14027}
14028
14029template<typename Derived>
14031TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
14032 CXXFunctionalCastExpr *E) {
14033 TypeSourceInfo *Type =
14034 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14035 if (!Type)
14036 return ExprError();
14037
14038 ExprResult SubExpr
14039 = getDerived().TransformExpr(E->getSubExprAsWritten());
14040 if (SubExpr.isInvalid())
14041 return ExprError();
14042
14043 if (!getDerived().AlwaysRebuild() &&
14044 Type == E->getTypeInfoAsWritten() &&
14045 SubExpr.get() == E->getSubExpr())
14046 return E;
14047
14048 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14049 E->getLParenLoc(),
14050 SubExpr.get(),
14051 E->getRParenLoc(),
14052 E->isListInitialization());
14053}
14054
14055template<typename Derived>
14057TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
14058 if (E->isTypeOperand()) {
14059 TypeSourceInfo *TInfo
14060 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14061 if (!TInfo)
14062 return ExprError();
14063
14064 if (!getDerived().AlwaysRebuild() &&
14065 TInfo == E->getTypeOperandSourceInfo())
14066 return E;
14067
14068 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14069 TInfo, E->getEndLoc());
14070 }
14071
14072 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14073 // type. We must not unilaterally enter unevaluated context here, as then
14074 // semantic processing can re-transform an already transformed operand.
14075 Expr *Op = E->getExprOperand();
14077 if (E->isGLValue())
14078 if (auto *RecordT = Op->getType()->getAs<RecordType>())
14079 if (cast<CXXRecordDecl>(RecordT->getDecl())->isPolymorphic())
14080 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14081
14082 EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx,
14084
14085 ExprResult SubExpr = getDerived().TransformExpr(Op);
14086 if (SubExpr.isInvalid())
14087 return ExprError();
14088
14089 if (!getDerived().AlwaysRebuild() &&
14090 SubExpr.get() == E->getExprOperand())
14091 return E;
14092
14093 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14094 SubExpr.get(), E->getEndLoc());
14095}
14096
14097template<typename Derived>
14099TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
14100 if (E->isTypeOperand()) {
14101 TypeSourceInfo *TInfo
14102 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14103 if (!TInfo)
14104 return ExprError();
14105
14106 if (!getDerived().AlwaysRebuild() &&
14107 TInfo == E->getTypeOperandSourceInfo())
14108 return E;
14109
14110 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14111 TInfo, E->getEndLoc());
14112 }
14113
14114 EnterExpressionEvaluationContext Unevaluated(
14116
14117 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14118 if (SubExpr.isInvalid())
14119 return ExprError();
14120
14121 if (!getDerived().AlwaysRebuild() &&
14122 SubExpr.get() == E->getExprOperand())
14123 return E;
14124
14125 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14126 SubExpr.get(), E->getEndLoc());
14127}
14128
14129template<typename Derived>
14131TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
14132 return E;
14133}
14134
14135template<typename Derived>
14137TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
14138 CXXNullPtrLiteralExpr *E) {
14139 return E;
14140}
14141
14142template<typename Derived>
14144TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
14145
14146 // In lambdas, the qualifiers of the type depends of where in
14147 // the call operator `this` appear, and we do not have a good way to
14148 // rebuild this information, so we transform the type.
14149 //
14150 // In other contexts, the type of `this` may be overrided
14151 // for type deduction, so we need to recompute it.
14152 //
14153 // Always recompute the type if we're in the body of a lambda, and
14154 // 'this' is dependent on a lambda's explicit object parameter.
14155 QualType T = [&]() {
14156 auto &S = getSema();
14157 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14158 return S.getCurrentThisType();
14159 if (S.getCurLambda())
14160 return getDerived().TransformType(E->getType());
14161 return S.getCurrentThisType();
14162 }();
14163
14164 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
14165 // Mark it referenced in the new context regardless.
14166 // FIXME: this is a bit instantiation-specific.
14167 getSema().MarkThisReferenced(E);
14168 return E;
14169 }
14170
14171 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14172}
14173
14174template<typename Derived>
14176TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
14177 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14178 if (SubExpr.isInvalid())
14179 return ExprError();
14180
14181 if (!getDerived().AlwaysRebuild() &&
14182 SubExpr.get() == E->getSubExpr())
14183 return E;
14184
14185 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
14186 E->isThrownVariableInScope());
14187}
14188
14189template<typename Derived>
14191TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
14192 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
14193 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
14194 if (!Param)
14195 return ExprError();
14196
14197 ExprResult InitRes;
14198 if (E->hasRewrittenInit()) {
14199 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
14200 if (InitRes.isInvalid())
14201 return ExprError();
14202 }
14203
14204 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
14205 E->getUsedContext() == SemaRef.CurContext &&
14206 InitRes.get() == E->getRewrittenExpr())
14207 return E;
14208
14209 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
14210 InitRes.get());
14211}
14212
14213template<typename Derived>
14215TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
14216 FieldDecl *Field = cast_or_null<FieldDecl>(
14217 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
14218 if (!Field)
14219 return ExprError();
14220
14221 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
14222 E->getUsedContext() == SemaRef.CurContext)
14223 return E;
14224
14225 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
14226}
14227
14228template<typename Derived>
14230TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
14231 CXXScalarValueInitExpr *E) {
14232 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
14233 if (!T)
14234 return ExprError();
14235
14236 if (!getDerived().AlwaysRebuild() &&
14237 T == E->getTypeSourceInfo())
14238 return E;
14239
14240 return getDerived().RebuildCXXScalarValueInitExpr(T,
14241 /*FIXME:*/T->getTypeLoc().getEndLoc(),
14242 E->getRParenLoc());
14243}
14244
14245template<typename Derived>
14247TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
14248 // Transform the type that we're allocating
14249 TypeSourceInfo *AllocTypeInfo =
14250 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
14251 if (!AllocTypeInfo)
14252 return ExprError();
14253
14254 // Transform the size of the array we're allocating (if any).
14255 std::optional<Expr *> ArraySize;
14256 if (E->isArray()) {
14257 ExprResult NewArraySize;
14258 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
14259 NewArraySize = getDerived().TransformExpr(*OldArraySize);
14260 if (NewArraySize.isInvalid())
14261 return ExprError();
14262 }
14263 ArraySize = NewArraySize.get();
14264 }
14265
14266 // Transform the placement arguments (if any).
14267 bool ArgumentChanged = false;
14268 SmallVector<Expr*, 8> PlacementArgs;
14269 if (getDerived().TransformExprs(E->getPlacementArgs(),
14270 E->getNumPlacementArgs(), true,
14271 PlacementArgs, &ArgumentChanged))
14272 return ExprError();
14273
14274 // Transform the initializer (if any).
14275 Expr *OldInit = E->getInitializer();
14276 ExprResult NewInit;
14277 if (OldInit)
14278 NewInit = getDerived().TransformInitializer(OldInit, true);
14279 if (NewInit.isInvalid())
14280 return ExprError();
14281
14282 // Transform new operator and delete operator.
14283 FunctionDecl *OperatorNew = nullptr;
14284 if (E->getOperatorNew()) {
14285 OperatorNew = cast_or_null<FunctionDecl>(
14286 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
14287 if (!OperatorNew)
14288 return ExprError();
14289 }
14290
14291 FunctionDecl *OperatorDelete = nullptr;
14292 if (E->getOperatorDelete()) {
14293 OperatorDelete = cast_or_null<FunctionDecl>(
14294 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14295 if (!OperatorDelete)
14296 return ExprError();
14297 }
14298
14299 if (!getDerived().AlwaysRebuild() &&
14300 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
14301 ArraySize == E->getArraySize() &&
14302 NewInit.get() == OldInit &&
14303 OperatorNew == E->getOperatorNew() &&
14304 OperatorDelete == E->getOperatorDelete() &&
14305 !ArgumentChanged) {
14306 // Mark any declarations we need as referenced.
14307 // FIXME: instantiation-specific.
14308 if (OperatorNew)
14309 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
14310 if (OperatorDelete)
14311 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14312
14313 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
14314 QualType ElementType
14315 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
14316 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
14317 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
14318 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
14320 }
14321 }
14322 }
14323
14324 return E;
14325 }
14326
14327 QualType AllocType = AllocTypeInfo->getType();
14328 if (!ArraySize) {
14329 // If no array size was specified, but the new expression was
14330 // instantiated with an array type (e.g., "new T" where T is
14331 // instantiated with "int[4]"), extract the outer bound from the
14332 // array type as our array size. We do this with constant and
14333 // dependently-sized array types.
14334 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
14335 if (!ArrayT) {
14336 // Do nothing
14337 } else if (const ConstantArrayType *ConsArrayT
14338 = dyn_cast<ConstantArrayType>(ArrayT)) {
14339 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
14340 SemaRef.Context.getSizeType(),
14341 /*FIXME:*/ E->getBeginLoc());
14342 AllocType = ConsArrayT->getElementType();
14343 } else if (const DependentSizedArrayType *DepArrayT
14344 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
14345 if (DepArrayT->getSizeExpr()) {
14346 ArraySize = DepArrayT->getSizeExpr();
14347 AllocType = DepArrayT->getElementType();
14348 }
14349 }
14350 }
14351
14352 return getDerived().RebuildCXXNewExpr(
14353 E->getBeginLoc(), E->isGlobalNew(),
14354 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
14355 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
14356 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
14357}
14358
14359template<typename Derived>
14361TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
14362 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
14363 if (Operand.isInvalid())
14364 return ExprError();
14365
14366 // Transform the delete operator, if known.
14367 FunctionDecl *OperatorDelete = nullptr;
14368 if (E->getOperatorDelete()) {
14369 OperatorDelete = cast_or_null<FunctionDecl>(
14370 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14371 if (!OperatorDelete)
14372 return ExprError();
14373 }
14374
14375 if (!getDerived().AlwaysRebuild() &&
14376 Operand.get() == E->getArgument() &&
14377 OperatorDelete == E->getOperatorDelete()) {
14378 // Mark any declarations we need as referenced.
14379 // FIXME: instantiation-specific.
14380 if (OperatorDelete)
14381 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14382
14383 if (!E->getArgument()->isTypeDependent()) {
14384 QualType Destroyed = SemaRef.Context.getBaseElementType(
14385 E->getDestroyedType());
14386 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
14387 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
14389 SemaRef.LookupDestructor(Record));
14390 }
14391 }
14392
14393 return E;
14394 }
14395
14396 return getDerived().RebuildCXXDeleteExpr(
14397 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
14398}
14399
14400template<typename Derived>
14402TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
14403 CXXPseudoDestructorExpr *E) {
14404 ExprResult Base = getDerived().TransformExpr(E->getBase());
14405 if (Base.isInvalid())
14406 return ExprError();
14407
14408 ParsedType ObjectTypePtr;
14409 bool MayBePseudoDestructor = false;
14410 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14411 E->getOperatorLoc(),
14412 E->isArrow()? tok::arrow : tok::period,
14413 ObjectTypePtr,
14414 MayBePseudoDestructor);
14415 if (Base.isInvalid())
14416 return ExprError();
14417
14418 QualType ObjectType = ObjectTypePtr.get();
14419 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
14420 if (QualifierLoc) {
14421 QualifierLoc
14422 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
14423 if (!QualifierLoc)
14424 return ExprError();
14425 }
14426 CXXScopeSpec SS;
14427 SS.Adopt(QualifierLoc);
14428
14429 PseudoDestructorTypeStorage Destroyed;
14430 if (E->getDestroyedTypeInfo()) {
14431 TypeSourceInfo *DestroyedTypeInfo
14432 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
14433 ObjectType, nullptr, SS);
14434 if (!DestroyedTypeInfo)
14435 return ExprError();
14436 Destroyed = DestroyedTypeInfo;
14437 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
14438 // We aren't likely to be able to resolve the identifier down to a type
14439 // now anyway, so just retain the identifier.
14440 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
14441 E->getDestroyedTypeLoc());
14442 } else {
14443 // Look for a destructor known with the given name.
14444 ParsedType T = SemaRef.getDestructorName(
14445 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
14446 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
14447 if (!T)
14448 return ExprError();
14449
14450 Destroyed
14452 E->getDestroyedTypeLoc());
14453 }
14454
14455 TypeSourceInfo *ScopeTypeInfo = nullptr;
14456 if (E->getScopeTypeInfo()) {
14457 CXXScopeSpec EmptySS;
14458 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
14459 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
14460 if (!ScopeTypeInfo)
14461 return ExprError();
14462 }
14463
14464 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
14465 E->getOperatorLoc(),
14466 E->isArrow(),
14467 SS,
14468 ScopeTypeInfo,
14469 E->getColonColonLoc(),
14470 E->getTildeLoc(),
14471 Destroyed);
14472}
14473
14474template <typename Derived>
14476 bool RequiresADL,
14477 LookupResult &R) {
14478 // Transform all the decls.
14479 bool AllEmptyPacks = true;
14480 for (auto *OldD : Old->decls()) {
14481 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
14482 if (!InstD) {
14483 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
14484 // This can happen because of dependent hiding.
14485 if (isa<UsingShadowDecl>(OldD))
14486 continue;
14487 else {
14488 R.clear();
14489 return true;
14490 }
14491 }
14492
14493 // Expand using pack declarations.
14494 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
14495 ArrayRef<NamedDecl*> Decls = SingleDecl;
14496 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
14497 Decls = UPD->expansions();
14498
14499 // Expand using declarations.
14500 for (auto *D : Decls) {
14501 if (auto *UD = dyn_cast<UsingDecl>(D)) {
14502 for (auto *SD : UD->shadows())
14503 R.addDecl(SD);
14504 } else {
14505 R.addDecl(D);
14506 }
14507 }
14508
14509 AllEmptyPacks &= Decls.empty();
14510 }
14511
14512 // C++ [temp.res]/8.4.2:
14513 // The program is ill-formed, no diagnostic required, if [...] lookup for
14514 // a name in the template definition found a using-declaration, but the
14515 // lookup in the corresponding scope in the instantiation odoes not find
14516 // any declarations because the using-declaration was a pack expansion and
14517 // the corresponding pack is empty
14518 if (AllEmptyPacks && !RequiresADL) {
14519 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
14520 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
14521 return true;
14522 }
14523
14524 // Resolve a kind, but don't do any further analysis. If it's
14525 // ambiguous, the callee needs to deal with it.
14526 R.resolveKind();
14527
14528 if (Old->hasTemplateKeyword() && !R.empty()) {
14530 getSema().FilterAcceptableTemplateNames(R,
14531 /*AllowFunctionTemplates=*/true,
14532 /*AllowDependent=*/true);
14533 if (R.empty()) {
14534 // If a 'template' keyword was used, a lookup that finds only non-template
14535 // names is an error.
14536 getSema().Diag(R.getNameLoc(),
14537 diag::err_template_kw_refers_to_non_template)
14539 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
14540 getSema().Diag(FoundDecl->getLocation(),
14541 diag::note_template_kw_refers_to_non_template)
14542 << R.getLookupName();
14543 return true;
14544 }
14545 }
14546
14547 return false;
14548}
14549
14550template <typename Derived>
14552 UnresolvedLookupExpr *Old) {
14553 return TransformUnresolvedLookupExpr(Old, /*IsAddressOfOperand=*/false);
14554}
14555
14556template <typename Derived>
14559 bool IsAddressOfOperand) {
14560 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
14562
14563 // Transform the declaration set.
14564 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
14565 return ExprError();
14566
14567 // Rebuild the nested-name qualifier, if present.
14568 CXXScopeSpec SS;
14569 if (Old->getQualifierLoc()) {
14570 NestedNameSpecifierLoc QualifierLoc
14571 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14572 if (!QualifierLoc)
14573 return ExprError();
14574
14575 SS.Adopt(QualifierLoc);
14576 }
14577
14578 if (Old->getNamingClass()) {
14579 CXXRecordDecl *NamingClass
14580 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
14581 Old->getNameLoc(),
14582 Old->getNamingClass()));
14583 if (!NamingClass) {
14584 R.clear();
14585 return ExprError();
14586 }
14587
14588 R.setNamingClass(NamingClass);
14589 }
14590
14591 // Rebuild the template arguments, if any.
14592 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14593 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
14594 if (Old->hasExplicitTemplateArgs() &&
14595 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14596 Old->getNumTemplateArgs(),
14597 TransArgs)) {
14598 R.clear();
14599 return ExprError();
14600 }
14601
14602 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
14603 // a non-static data member is named in an unevaluated operand, or when
14604 // a member is named in a dependent class scope function template explicit
14605 // specialization that is neither declared static nor with an explicit object
14606 // parameter.
14607 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
14608 return SemaRef.BuildPossibleImplicitMemberExpr(
14609 SS, TemplateKWLoc, R,
14610 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
14611 /*S=*/nullptr);
14612
14613 // If we have neither explicit template arguments, nor the template keyword,
14614 // it's a normal declaration name or member reference.
14615 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
14616 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
14617
14618 // If we have template arguments, then rebuild the template-id expression.
14619 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
14620 Old->requiresADL(), &TransArgs);
14621}
14622
14623template<typename Derived>
14625TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
14626 bool ArgChanged = false;
14628 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
14629 TypeSourceInfo *From = E->getArg(I);
14630 TypeLoc FromTL = From->getTypeLoc();
14631 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
14632 TypeLocBuilder TLB;
14633 TLB.reserve(FromTL.getFullDataSize());
14634 QualType To = getDerived().TransformType(TLB, FromTL);
14635 if (To.isNull())
14636 return ExprError();
14637
14638 if (To == From->getType())
14639 Args.push_back(From);
14640 else {
14641 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14642 ArgChanged = true;
14643 }
14644 continue;
14645 }
14646
14647 ArgChanged = true;
14648
14649 // We have a pack expansion. Instantiate it.
14650 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
14651 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
14653 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
14654
14655 // Determine whether the set of unexpanded parameter packs can and should
14656 // be expanded.
14657 bool Expand = true;
14658 bool RetainExpansion = false;
14659 std::optional<unsigned> OrigNumExpansions =
14660 ExpansionTL.getTypePtr()->getNumExpansions();
14661 std::optional<unsigned> NumExpansions = OrigNumExpansions;
14662 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
14663 PatternTL.getSourceRange(),
14664 Unexpanded,
14665 Expand, RetainExpansion,
14666 NumExpansions))
14667 return ExprError();
14668
14669 if (!Expand) {
14670 // The transform has determined that we should perform a simple
14671 // transformation on the pack expansion, producing another pack
14672 // expansion.
14673 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
14674
14675 TypeLocBuilder TLB;
14676 TLB.reserve(From->getTypeLoc().getFullDataSize());
14677
14678 QualType To = getDerived().TransformType(TLB, PatternTL);
14679 if (To.isNull())
14680 return ExprError();
14681
14682 To = getDerived().RebuildPackExpansionType(To,
14683 PatternTL.getSourceRange(),
14684 ExpansionTL.getEllipsisLoc(),
14685 NumExpansions);
14686 if (To.isNull())
14687 return ExprError();
14688
14689 PackExpansionTypeLoc ToExpansionTL
14690 = TLB.push<PackExpansionTypeLoc>(To);
14691 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14692 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14693 continue;
14694 }
14695
14696 // Expand the pack expansion by substituting for each argument in the
14697 // pack(s).
14698 for (unsigned I = 0; I != *NumExpansions; ++I) {
14699 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
14700 TypeLocBuilder TLB;
14701 TLB.reserve(PatternTL.getFullDataSize());
14702 QualType To = getDerived().TransformType(TLB, PatternTL);
14703 if (To.isNull())
14704 return ExprError();
14705
14706 if (To->containsUnexpandedParameterPack()) {
14707 To = getDerived().RebuildPackExpansionType(To,
14708 PatternTL.getSourceRange(),
14709 ExpansionTL.getEllipsisLoc(),
14710 NumExpansions);
14711 if (To.isNull())
14712 return ExprError();
14713
14714 PackExpansionTypeLoc ToExpansionTL
14715 = TLB.push<PackExpansionTypeLoc>(To);
14716 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14717 }
14718
14719 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14720 }
14721
14722 if (!RetainExpansion)
14723 continue;
14724
14725 // If we're supposed to retain a pack expansion, do so by temporarily
14726 // forgetting the partially-substituted parameter pack.
14727 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14728
14729 TypeLocBuilder TLB;
14730 TLB.reserve(From->getTypeLoc().getFullDataSize());
14731
14732 QualType To = getDerived().TransformType(TLB, PatternTL);
14733 if (To.isNull())
14734 return ExprError();
14735
14736 To = getDerived().RebuildPackExpansionType(To,
14737 PatternTL.getSourceRange(),
14738 ExpansionTL.getEllipsisLoc(),
14739 NumExpansions);
14740 if (To.isNull())
14741 return ExprError();
14742
14743 PackExpansionTypeLoc ToExpansionTL
14744 = TLB.push<PackExpansionTypeLoc>(To);
14745 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14746 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14747 }
14748
14749 if (!getDerived().AlwaysRebuild() && !ArgChanged)
14750 return E;
14751
14752 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
14753 E->getEndLoc());
14754}
14755
14756template<typename Derived>
14758TreeTransform<Derived>::TransformConceptSpecializationExpr(
14759 ConceptSpecializationExpr *E) {
14760 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
14761 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
14762 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14763 Old->NumTemplateArgs, TransArgs))
14764 return ExprError();
14765
14766 return getDerived().RebuildConceptSpecializationExpr(
14767 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
14768 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
14769 &TransArgs);
14770}
14771
14772template<typename Derived>
14774TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) {
14775 SmallVector<ParmVarDecl*, 4> TransParams;
14776 SmallVector<QualType, 4> TransParamTypes;
14777 Sema::ExtParameterInfoBuilder ExtParamInfos;
14778
14779 // C++2a [expr.prim.req]p2
14780 // Expressions appearing within a requirement-body are unevaluated operands.
14781 EnterExpressionEvaluationContext Ctx(
14784
14785 RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
14786 getSema().Context, getSema().CurContext,
14787 E->getBody()->getBeginLoc());
14788
14789 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
14790
14791 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
14792 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
14793 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
14794
14795 for (ParmVarDecl *Param : TransParams)
14796 if (Param)
14797 Param->setDeclContext(Body);
14798
14799 // On failure to transform, TransformRequiresTypeParams returns an expression
14800 // in the event that the transformation of the type params failed in some way.
14801 // It is expected that this will result in a 'not satisfied' Requires clause
14802 // when instantiating.
14803 if (!TypeParamResult.isUnset())
14804 return TypeParamResult;
14805
14807 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
14808 TransReqs))
14809 return ExprError();
14810
14811 for (concepts::Requirement *Req : TransReqs) {
14812 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
14813 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
14814 ER->getReturnTypeRequirement()
14815 .getTypeConstraintTemplateParameterList()->getParam(0)
14816 ->setDeclContext(Body);
14817 }
14818 }
14819 }
14820
14821 return getDerived().RebuildRequiresExpr(
14822 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
14823 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
14824}
14825
14826template<typename Derived>
14830 for (concepts::Requirement *Req : Reqs) {
14831 concepts::Requirement *TransReq = nullptr;
14832 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
14833 TransReq = getDerived().TransformTypeRequirement(TypeReq);
14834 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
14835 TransReq = getDerived().TransformExprRequirement(ExprReq);
14836 else
14837 TransReq = getDerived().TransformNestedRequirement(
14838 cast<concepts::NestedRequirement>(Req));
14839 if (!TransReq)
14840 return true;
14841 Transformed.push_back(TransReq);
14842 }
14843 return false;
14844}
14845
14846template<typename Derived>
14850 if (Req->isSubstitutionFailure()) {
14851 if (getDerived().AlwaysRebuild())
14852 return getDerived().RebuildTypeRequirement(
14854 return Req;
14855 }
14856 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
14857 if (!TransType)
14858 return nullptr;
14859 return getDerived().RebuildTypeRequirement(TransType);
14860}
14861
14862template<typename Derived>
14865 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
14866 if (Req->isExprSubstitutionFailure())
14867 TransExpr = Req->getExprSubstitutionDiagnostic();
14868 else {
14869 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
14870 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
14871 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
14872 if (TransExprRes.isInvalid())
14873 return nullptr;
14874 TransExpr = TransExprRes.get();
14875 }
14876
14877 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
14878 const auto &RetReq = Req->getReturnTypeRequirement();
14879 if (RetReq.isEmpty())
14880 TransRetReq.emplace();
14881 else if (RetReq.isSubstitutionFailure())
14882 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
14883 else if (RetReq.isTypeConstraint()) {
14884 TemplateParameterList *OrigTPL =
14885 RetReq.getTypeConstraintTemplateParameterList();
14887 getDerived().TransformTemplateParameterList(OrigTPL);
14888 if (!TPL)
14889 return nullptr;
14890 TransRetReq.emplace(TPL);
14891 }
14892 assert(TransRetReq && "All code paths leading here must set TransRetReq");
14893 if (Expr *E = TransExpr.dyn_cast<Expr *>())
14894 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
14895 Req->getNoexceptLoc(),
14896 std::move(*TransRetReq));
14897 return getDerived().RebuildExprRequirement(
14898 cast<concepts::Requirement::SubstitutionDiagnostic *>(TransExpr),
14899 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
14900}
14901
14902template<typename Derived>
14906 if (Req->hasInvalidConstraint()) {
14907 if (getDerived().AlwaysRebuild())
14908 return getDerived().RebuildNestedRequirement(
14910 return Req;
14911 }
14912 ExprResult TransConstraint =
14913 getDerived().TransformExpr(Req->getConstraintExpr());
14914 if (TransConstraint.isInvalid())
14915 return nullptr;
14916 return getDerived().RebuildNestedRequirement(TransConstraint.get());
14917}
14918
14919template<typename Derived>
14922 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
14923 if (!T)
14924 return ExprError();
14925
14926 if (!getDerived().AlwaysRebuild() &&
14927 T == E->getQueriedTypeSourceInfo())
14928 return E;
14929
14930 ExprResult SubExpr;
14931 {
14934 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
14935 if (SubExpr.isInvalid())
14936 return ExprError();
14937
14938 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
14939 return E;
14940 }
14941
14942 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
14943 SubExpr.get(), E->getEndLoc());
14944}
14945
14946template<typename Derived>
14948TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
14949 ExprResult SubExpr;
14950 {
14951 EnterExpressionEvaluationContext Unevaluated(
14953 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
14954 if (SubExpr.isInvalid())
14955 return ExprError();
14956
14957 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
14958 return E;
14959 }
14960
14961 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
14962 SubExpr.get(), E->getEndLoc());
14963}
14964
14965template <typename Derived>
14967 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
14968 TypeSourceInfo **RecoveryTSI) {
14969 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
14970 DRE, AddrTaken, RecoveryTSI);
14971
14972 // Propagate both errors and recovered types, which return ExprEmpty.
14973 if (!NewDRE.isUsable())
14974 return NewDRE;
14975
14976 // We got an expr, wrap it up in parens.
14977 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
14978 return PE;
14979 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
14980 PE->getRParen());
14981}
14982
14983template <typename Derived>
14986 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
14987 nullptr);
14988}
14989
14990template <typename Derived>
14992 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
14993 TypeSourceInfo **RecoveryTSI) {
14994 assert(E->getQualifierLoc());
14995 NestedNameSpecifierLoc QualifierLoc =
14996 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
14997 if (!QualifierLoc)
14998 return ExprError();
14999 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15000
15001 // TODO: If this is a conversion-function-id, verify that the
15002 // destination type name (if present) resolves the same way after
15003 // instantiation as it did in the local scope.
15004
15005 DeclarationNameInfo NameInfo =
15006 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15007 if (!NameInfo.getName())
15008 return ExprError();
15009
15010 if (!E->hasExplicitTemplateArgs()) {
15011 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15012 // Note: it is sufficient to compare the Name component of NameInfo:
15013 // if name has not changed, DNLoc has not changed either.
15014 NameInfo.getName() == E->getDeclName())
15015 return E;
15016
15017 return getDerived().RebuildDependentScopeDeclRefExpr(
15018 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15019 IsAddressOfOperand, RecoveryTSI);
15020 }
15021
15022 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15023 if (getDerived().TransformTemplateArguments(
15024 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15025 return ExprError();
15026
15027 return getDerived().RebuildDependentScopeDeclRefExpr(
15028 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15029 RecoveryTSI);
15030}
15031
15032template<typename Derived>
15034TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
15035 // CXXConstructExprs other than for list-initialization and
15036 // CXXTemporaryObjectExpr are always implicit, so when we have
15037 // a 1-argument construction we just transform that argument.
15038 if (getDerived().AllowSkippingCXXConstructExpr() &&
15039 ((E->getNumArgs() == 1 ||
15040 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15041 (!getDerived().DropCallArgument(E->getArg(0))) &&
15042 !E->isListInitialization()))
15043 return getDerived().TransformInitializer(E->getArg(0),
15044 /*DirectInit*/ false);
15045
15046 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15047
15048 QualType T = getDerived().TransformType(E->getType());
15049 if (T.isNull())
15050 return ExprError();
15051
15052 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15053 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15054 if (!Constructor)
15055 return ExprError();
15056
15057 bool ArgumentChanged = false;
15059 {
15060 EnterExpressionEvaluationContext Context(
15062 E->isListInitialization());
15063 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15064 &ArgumentChanged))
15065 return ExprError();
15066 }
15067
15068 if (!getDerived().AlwaysRebuild() &&
15069 T == E->getType() &&
15070 Constructor == E->getConstructor() &&
15071 !ArgumentChanged) {
15072 // Mark the constructor as referenced.
15073 // FIXME: Instantiation-specific
15074 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15075 return E;
15076 }
15077
15078 return getDerived().RebuildCXXConstructExpr(
15079 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15080 E->hadMultipleCandidates(), E->isListInitialization(),
15081 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15082 E->getConstructionKind(), E->getParenOrBraceRange());
15083}
15084
15085template<typename Derived>
15086ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
15087 CXXInheritedCtorInitExpr *E) {
15088 QualType T = getDerived().TransformType(E->getType());
15089 if (T.isNull())
15090 return ExprError();
15091
15092 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15093 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15094 if (!Constructor)
15095 return ExprError();
15096
15097 if (!getDerived().AlwaysRebuild() &&
15098 T == E->getType() &&
15099 Constructor == E->getConstructor()) {
15100 // Mark the constructor as referenced.
15101 // FIXME: Instantiation-specific
15102 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15103 return E;
15104 }
15105
15106 return getDerived().RebuildCXXInheritedCtorInitExpr(
15107 T, E->getLocation(), Constructor,
15108 E->constructsVBase(), E->inheritedFromVBase());
15109}
15110
15111/// Transform a C++ temporary-binding expression.
15112///
15113/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15114/// transform the subexpression and return that.
15115template<typename Derived>
15117TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
15118 if (auto *Dtor = E->getTemporary()->getDestructor())
15120 const_cast<CXXDestructorDecl *>(Dtor));
15121 return getDerived().TransformExpr(E->getSubExpr());
15122}
15123
15124/// Transform a C++ expression that contains cleanups that should
15125/// be run after the expression is evaluated.
15126///
15127/// Since ExprWithCleanups nodes are implicitly generated, we
15128/// just transform the subexpression and return that.
15129template<typename Derived>
15131TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
15132 return getDerived().TransformExpr(E->getSubExpr());
15133}
15134
15135template<typename Derived>
15137TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
15138 CXXTemporaryObjectExpr *E) {
15139 TypeSourceInfo *T =
15140 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15141 if (!T)
15142 return ExprError();
15143
15144 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15145 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15146 if (!Constructor)
15147 return ExprError();
15148
15149 bool ArgumentChanged = false;
15151 Args.reserve(E->getNumArgs());
15152 {
15153 EnterExpressionEvaluationContext Context(
15155 E->isListInitialization());
15156 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15157 &ArgumentChanged))
15158 return ExprError();
15159
15160 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15161 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc());
15162 if (Res.isInvalid())
15163 return ExprError();
15164 Args = {Res.get()};
15165 }
15166 }
15167
15168 if (!getDerived().AlwaysRebuild() &&
15169 T == E->getTypeSourceInfo() &&
15170 Constructor == E->getConstructor() &&
15171 !ArgumentChanged) {
15172 // FIXME: Instantiation-specific
15173 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15174 return SemaRef.MaybeBindToTemporary(E);
15175 }
15176
15177 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15178 return getDerived().RebuildCXXTemporaryObjectExpr(
15179 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15180}
15181
15182template<typename Derived>
15184TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
15185 // Transform any init-capture expressions before entering the scope of the
15186 // lambda body, because they are not semantically within that scope.
15187 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15188 struct TransformedInitCapture {
15189 // The location of the ... if the result is retaining a pack expansion.
15190 SourceLocation EllipsisLoc;
15191 // Zero or more expansions of the init-capture.
15193 };
15195 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
15196 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15197 CEnd = E->capture_end();
15198 C != CEnd; ++C) {
15199 if (!E->isInitCapture(C))
15200 continue;
15201
15202 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
15203 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15204
15205 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
15206 std::optional<unsigned> NumExpansions) {
15207 ExprResult NewExprInitResult = getDerived().TransformInitializer(
15208 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
15209
15210 if (NewExprInitResult.isInvalid()) {
15211 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
15212 return;
15213 }
15214 Expr *NewExprInit = NewExprInitResult.get();
15215
15216 QualType NewInitCaptureType =
15217 getSema().buildLambdaInitCaptureInitialization(
15218 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
15219 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
15220 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
15222 NewExprInit);
15223 Result.Expansions.push_back(
15224 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
15225 };
15226
15227 // If this is an init-capture pack, consider expanding the pack now.
15228 if (OldVD->isParameterPack()) {
15229 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
15230 ->getTypeLoc()
15231 .castAs<PackExpansionTypeLoc>();
15233 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
15234
15235 // Determine whether the set of unexpanded parameter packs can and should
15236 // be expanded.
15237 bool Expand = true;
15238 bool RetainExpansion = false;
15239 std::optional<unsigned> OrigNumExpansions =
15240 ExpansionTL.getTypePtr()->getNumExpansions();
15241 std::optional<unsigned> NumExpansions = OrigNumExpansions;
15242 if (getDerived().TryExpandParameterPacks(
15243 ExpansionTL.getEllipsisLoc(),
15244 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
15245 RetainExpansion, NumExpansions))
15246 return ExprError();
15247 assert(!RetainExpansion && "Should not need to retain expansion after a "
15248 "capture since it cannot be extended");
15249 if (Expand) {
15250 for (unsigned I = 0; I != *NumExpansions; ++I) {
15251 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15252 SubstInitCapture(SourceLocation(), std::nullopt);
15253 }
15254 } else {
15255 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
15256 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
15257 }
15258 } else {
15259 SubstInitCapture(SourceLocation(), std::nullopt);
15260 }
15261 }
15262
15263 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
15264 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
15265
15266 // Create the local class that will describe the lambda.
15267
15268 // FIXME: DependencyKind below is wrong when substituting inside a templated
15269 // context that isn't a DeclContext (such as a variable template), or when
15270 // substituting an unevaluated lambda inside of a function's parameter's type
15271 // - as parameter types are not instantiated from within a function's DC. We
15272 // use evaluation contexts to distinguish the function parameter case.
15275 DeclContext *DC = getSema().CurContext;
15276 // A RequiresExprBodyDecl is not interesting for dependencies.
15277 // For the following case,
15278 //
15279 // template <typename>
15280 // concept C = requires { [] {}; };
15281 //
15282 // template <class F>
15283 // struct Widget;
15284 //
15285 // template <C F>
15286 // struct Widget<F> {};
15287 //
15288 // While we are substituting Widget<F>, the parent of DC would be
15289 // the template specialization itself. Thus, the lambda expression
15290 // will be deemed as dependent even if there are no dependent template
15291 // arguments.
15292 // (A ClassTemplateSpecializationDecl is always a dependent context.)
15293 while (DC->isRequiresExprBody())
15294 DC = DC->getParent();
15295 if ((getSema().isUnevaluatedContext() ||
15296 getSema().isConstantEvaluatedContext()) &&
15297 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
15298 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
15299
15300 CXXRecordDecl *OldClass = E->getLambdaClass();
15301 CXXRecordDecl *Class = getSema().createLambdaClosureType(
15302 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
15303 E->getCaptureDefault());
15304 getDerived().transformedLocalDecl(OldClass, {Class});
15305
15306 CXXMethodDecl *NewCallOperator =
15307 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
15308
15309 // Enter the scope of the lambda.
15310 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
15311 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
15312 E->hasExplicitParameters(), E->isMutable());
15313
15314 // Introduce the context of the call operator.
15315 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
15316 /*NewThisContext*/false);
15317
15318 bool Invalid = false;
15319
15320 // Transform captures.
15321 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15322 CEnd = E->capture_end();
15323 C != CEnd; ++C) {
15324 // When we hit the first implicit capture, tell Sema that we've finished
15325 // the list of explicit captures.
15326 if (C->isImplicit())
15327 break;
15328
15329 // Capturing 'this' is trivial.
15330 if (C->capturesThis()) {
15331 // If this is a lambda that is part of a default member initialiser
15332 // and which we're instantiating outside the class that 'this' is
15333 // supposed to refer to, adjust the type of 'this' accordingly.
15334 //
15335 // Otherwise, leave the type of 'this' as-is.
15336 Sema::CXXThisScopeRAII ThisScope(
15337 getSema(),
15338 dyn_cast_if_present<CXXRecordDecl>(
15339 getSema().getFunctionLevelDeclContext()),
15340 Qualifiers());
15341 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15342 /*BuildAndDiagnose*/ true, nullptr,
15343 C->getCaptureKind() == LCK_StarThis);
15344 continue;
15345 }
15346 // Captured expression will be recaptured during captured variables
15347 // rebuilding.
15348 if (C->capturesVLAType())
15349 continue;
15350
15351 // Rebuild init-captures, including the implied field declaration.
15352 if (E->isInitCapture(C)) {
15353 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
15354
15355 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15357
15358 for (InitCaptureInfoTy &Info : NewC.Expansions) {
15359 ExprResult Init = Info.first;
15360 QualType InitQualType = Info.second;
15361 if (Init.isInvalid() || InitQualType.isNull()) {
15362 Invalid = true;
15363 break;
15364 }
15365 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
15366 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
15367 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
15368 getSema().CurContext);
15369 if (!NewVD) {
15370 Invalid = true;
15371 break;
15372 }
15373 NewVDs.push_back(NewVD);
15374 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
15375 // Cases we want to tackle:
15376 // ([C(Pack)] {}, ...)
15377 // But rule out cases e.g.
15378 // [...C = Pack()] {}
15379 if (NewC.EllipsisLoc.isInvalid())
15380 LSI->ContainsUnexpandedParameterPack |=
15381 Init.get()->containsUnexpandedParameterPack();
15382 }
15383
15384 if (Invalid)
15385 break;
15386
15387 getDerived().transformedLocalDecl(OldVD, NewVDs);
15388 continue;
15389 }
15390
15391 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15392
15393 // Determine the capture kind for Sema.
15395 = C->isImplicit()? Sema::TryCapture_Implicit
15396 : C->getCaptureKind() == LCK_ByCopy
15399 SourceLocation EllipsisLoc;
15400 if (C->isPackExpansion()) {
15401 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
15402 bool ShouldExpand = false;
15403 bool RetainExpansion = false;
15404 std::optional<unsigned> NumExpansions;
15405 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
15406 C->getLocation(),
15407 Unexpanded,
15408 ShouldExpand, RetainExpansion,
15409 NumExpansions)) {
15410 Invalid = true;
15411 continue;
15412 }
15413
15414 if (ShouldExpand) {
15415 // The transform has determined that we should perform an expansion;
15416 // transform and capture each of the arguments.
15417 // expansion of the pattern. Do so.
15418 auto *Pack = cast<VarDecl>(C->getCapturedVar());
15419 for (unsigned I = 0; I != *NumExpansions; ++I) {
15420 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15421 VarDecl *CapturedVar
15422 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
15423 Pack));
15424 if (!CapturedVar) {
15425 Invalid = true;
15426 continue;
15427 }
15428
15429 // Capture the transformed variable.
15430 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
15431 }
15432
15433 // FIXME: Retain a pack expansion if RetainExpansion is true.
15434
15435 continue;
15436 }
15437
15438 EllipsisLoc = C->getEllipsisLoc();
15439 }
15440
15441 // Transform the captured variable.
15442 auto *CapturedVar = cast_or_null<ValueDecl>(
15443 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15444 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
15445 Invalid = true;
15446 continue;
15447 }
15448
15449 // This is not an init-capture; however it contains an unexpanded pack e.g.
15450 // ([Pack] {}(), ...)
15451 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
15452 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
15453
15454 // Capture the transformed variable.
15455 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
15456 EllipsisLoc);
15457 }
15458 getSema().finishLambdaExplicitCaptures(LSI);
15459
15460 // Transform the template parameters, and add them to the current
15461 // instantiation scope. The null case is handled correctly.
15462 auto TPL = getDerived().TransformTemplateParameterList(
15463 E->getTemplateParameterList());
15464 LSI->GLTemplateParameterList = TPL;
15465 if (TPL) {
15466 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
15467 TPL);
15468 LSI->ContainsUnexpandedParameterPack |=
15469 TPL->containsUnexpandedParameterPack();
15470 }
15471
15472 TypeLocBuilder NewCallOpTLBuilder;
15473 TypeLoc OldCallOpTypeLoc =
15474 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
15475 QualType NewCallOpType =
15476 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
15477 if (NewCallOpType.isNull())
15478 return ExprError();
15479 LSI->ContainsUnexpandedParameterPack |=
15480 NewCallOpType->containsUnexpandedParameterPack();
15481 TypeSourceInfo *NewCallOpTSI =
15482 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
15483
15484 // The type may be an AttributedType or some other kind of sugar;
15485 // get the actual underlying FunctionProtoType.
15486 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
15487 assert(FPTL && "Not a FunctionProtoType?");
15488
15489 getSema().CompleteLambdaCallOperator(
15490 NewCallOperator, E->getCallOperator()->getLocation(),
15491 E->getCallOperator()->getInnerLocStart(),
15492 E->getCallOperator()->getTrailingRequiresClause(), NewCallOpTSI,
15493 E->getCallOperator()->getConstexprKind(),
15494 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
15495 E->hasExplicitResultType());
15496
15497 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
15498 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
15499
15500 {
15501 // Number the lambda for linkage purposes if necessary.
15502 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
15503
15504 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
15505 if (getDerived().ReplacingOriginal()) {
15506 Numbering = OldClass->getLambdaNumbering();
15507 }
15508
15509 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
15510 }
15511
15512 // FIXME: Sema's lambda-building mechanism expects us to push an expression
15513 // evaluation context even if we're not transforming the function body.
15514 getSema().PushExpressionEvaluationContext(
15515 E->getCallOperator()->isConsteval() ?
15518 getSema().currentEvaluationContext().InImmediateEscalatingFunctionContext =
15519 getSema().getLangOpts().CPlusPlus20 &&
15520 E->getCallOperator()->isImmediateEscalating();
15521
15522 Sema::CodeSynthesisContext C;
15524 C.PointOfInstantiation = E->getBody()->getBeginLoc();
15525 getSema().pushCodeSynthesisContext(C);
15526
15527 // Instantiate the body of the lambda expression.
15528 StmtResult Body =
15529 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
15530
15531 getSema().popCodeSynthesisContext();
15532
15533 // ActOnLambda* will pop the function scope for us.
15534 FuncScopeCleanup.disable();
15535
15536 if (Body.isInvalid()) {
15537 SavedContext.pop();
15538 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
15539 /*IsInstantiation=*/true);
15540 return ExprError();
15541 }
15542
15543 // Copy the LSI before ActOnFinishFunctionBody removes it.
15544 // FIXME: This is dumb. Store the lambda information somewhere that outlives
15545 // the call operator.
15546 auto LSICopy = *LSI;
15547 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15548 /*IsInstantiation*/ true);
15549 SavedContext.pop();
15550
15551 // Recompute the dependency of the lambda so that we can defer the lambda call
15552 // construction until after we have all the necessary template arguments. For
15553 // example, given
15554 //
15555 // template <class> struct S {
15556 // template <class U>
15557 // using Type = decltype([](U){}(42.0));
15558 // };
15559 // void foo() {
15560 // using T = S<int>::Type<float>;
15561 // ^~~~~~
15562 // }
15563 //
15564 // We would end up here from instantiating S<int> when ensuring its
15565 // completeness. That would transform the lambda call expression regardless of
15566 // the absence of the corresponding argument for U.
15567 //
15568 // Going ahead with unsubstituted type U makes things worse: we would soon
15569 // compare the argument type (which is float) against the parameter U
15570 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
15571 // error suggesting unmatched types 'U' and 'float'!
15572 //
15573 // That said, everything will be fine if we defer that semantic checking.
15574 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
15575 // dependent. Since the CallExpr's dependency boils down to the lambda's
15576 // dependency in this case, we can harness that by recomputing the dependency
15577 // from the instantiation arguments.
15578 //
15579 // FIXME: Creating the type of a lambda requires us to have a dependency
15580 // value, which happens before its substitution. We update its dependency
15581 // *after* the substitution in case we can't decide the dependency
15582 // so early, e.g. because we want to see if any of the *substituted*
15583 // parameters are dependent.
15584 DependencyKind = getDerived().ComputeLambdaDependency(&LSICopy);
15585 Class->setLambdaDependencyKind(DependencyKind);
15586 // Clean up the type cache created previously. Then, we re-create a type for
15587 // such Decl with the new DependencyKind.
15588 Class->setTypeForDecl(nullptr);
15589 getSema().Context.getTypeDeclType(Class);
15590
15591 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15592 Body.get()->getEndLoc(), &LSICopy);
15593}
15594
15595template<typename Derived>
15598 return TransformStmt(S);
15599}
15600
15601template<typename Derived>
15604 // Transform captures.
15605 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15606 CEnd = E->capture_end();
15607 C != CEnd; ++C) {
15608 // When we hit the first implicit capture, tell Sema that we've finished
15609 // the list of explicit captures.
15610 if (!C->isImplicit())
15611 continue;
15612
15613 // Capturing 'this' is trivial.
15614 if (C->capturesThis()) {
15615 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15616 /*BuildAndDiagnose*/ true, nullptr,
15617 C->getCaptureKind() == LCK_StarThis);
15618 continue;
15619 }
15620 // Captured expression will be recaptured during captured variables
15621 // rebuilding.
15622 if (C->capturesVLAType())
15623 continue;
15624
15625 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15626 assert(!E->isInitCapture(C) && "implicit init-capture?");
15627
15628 // Transform the captured variable.
15629 VarDecl *CapturedVar = cast_or_null<VarDecl>(
15630 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15631 if (!CapturedVar || CapturedVar->isInvalidDecl())
15632 return StmtError();
15633
15634 // Capture the transformed variable.
15635 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
15636 }
15637
15638 return S;
15639}
15640
15641template<typename Derived>
15645 TypeSourceInfo *T =
15646 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15647 if (!T)
15648 return ExprError();
15649
15650 bool ArgumentChanged = false;
15652 Args.reserve(E->getNumArgs());
15653 {
15656 E->isListInitialization());
15657 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
15658 &ArgumentChanged))
15659 return ExprError();
15660 }
15661
15662 if (!getDerived().AlwaysRebuild() &&
15663 T == E->getTypeSourceInfo() &&
15664 !ArgumentChanged)
15665 return E;
15666
15667 // FIXME: we're faking the locations of the commas
15668 return getDerived().RebuildCXXUnresolvedConstructExpr(
15669 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
15670}
15671
15672template<typename Derived>
15674TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
15675 CXXDependentScopeMemberExpr *E) {
15676 // Transform the base of the expression.
15677 ExprResult Base((Expr*) nullptr);
15678 Expr *OldBase;
15679 QualType BaseType;
15680 QualType ObjectType;
15681 if (!E->isImplicitAccess()) {
15682 OldBase = E->getBase();
15683 Base = getDerived().TransformExpr(OldBase);
15684 if (Base.isInvalid())
15685 return ExprError();
15686
15687 // Start the member reference and compute the object's type.
15688 ParsedType ObjectTy;
15689 bool MayBePseudoDestructor = false;
15690 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15691 E->getOperatorLoc(),
15692 E->isArrow()? tok::arrow : tok::period,
15693 ObjectTy,
15694 MayBePseudoDestructor);
15695 if (Base.isInvalid())
15696 return ExprError();
15697
15698 ObjectType = ObjectTy.get();
15699 BaseType = ((Expr*) Base.get())->getType();
15700 } else {
15701 OldBase = nullptr;
15702 BaseType = getDerived().TransformType(E->getBaseType());
15703 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
15704 }
15705
15706 // Transform the first part of the nested-name-specifier that qualifies
15707 // the member name.
15708 NamedDecl *FirstQualifierInScope
15709 = getDerived().TransformFirstQualifierInScope(
15710 E->getFirstQualifierFoundInScope(),
15711 E->getQualifierLoc().getBeginLoc());
15712
15713 NestedNameSpecifierLoc QualifierLoc;
15714 if (E->getQualifier()) {
15715 QualifierLoc
15716 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
15717 ObjectType,
15718 FirstQualifierInScope);
15719 if (!QualifierLoc)
15720 return ExprError();
15721 }
15722
15723 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15724
15725 // TODO: If this is a conversion-function-id, verify that the
15726 // destination type name (if present) resolves the same way after
15727 // instantiation as it did in the local scope.
15728
15729 DeclarationNameInfo NameInfo
15730 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
15731 if (!NameInfo.getName())
15732 return ExprError();
15733
15734 if (!E->hasExplicitTemplateArgs()) {
15735 // This is a reference to a member without an explicitly-specified
15736 // template argument list. Optimize for this common case.
15737 if (!getDerived().AlwaysRebuild() &&
15738 Base.get() == OldBase &&
15739 BaseType == E->getBaseType() &&
15740 QualifierLoc == E->getQualifierLoc() &&
15741 NameInfo.getName() == E->getMember() &&
15742 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
15743 return E;
15744
15745 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15746 BaseType,
15747 E->isArrow(),
15748 E->getOperatorLoc(),
15749 QualifierLoc,
15750 TemplateKWLoc,
15751 FirstQualifierInScope,
15752 NameInfo,
15753 /*TemplateArgs*/nullptr);
15754 }
15755
15756 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15757 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
15758 E->getNumTemplateArgs(),
15759 TransArgs))
15760 return ExprError();
15761
15762 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15763 BaseType,
15764 E->isArrow(),
15765 E->getOperatorLoc(),
15766 QualifierLoc,
15767 TemplateKWLoc,
15768 FirstQualifierInScope,
15769 NameInfo,
15770 &TransArgs);
15771}
15772
15773template <typename Derived>
15774ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
15775 UnresolvedMemberExpr *Old) {
15776 // Transform the base of the expression.
15777 ExprResult Base((Expr *)nullptr);
15778 QualType BaseType;
15779 if (!Old->isImplicitAccess()) {
15780 Base = getDerived().TransformExpr(Old->getBase());
15781 if (Base.isInvalid())
15782 return ExprError();
15783 Base =
15784 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
15785 if (Base.isInvalid())
15786 return ExprError();
15787 BaseType = Base.get()->getType();
15788 } else {
15789 BaseType = getDerived().TransformType(Old->getBaseType());
15790 }
15791
15792 NestedNameSpecifierLoc QualifierLoc;
15793 if (Old->getQualifierLoc()) {
15794 QualifierLoc =
15795 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15796 if (!QualifierLoc)
15797 return ExprError();
15798 }
15799
15800 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15801
15802 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
15803
15804 // Transform the declaration set.
15805 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
15806 return ExprError();
15807
15808 // Determine the naming class.
15809 if (Old->getNamingClass()) {
15810 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
15811 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
15812 if (!NamingClass)
15813 return ExprError();
15814
15815 R.setNamingClass(NamingClass);
15816 }
15817
15818 TemplateArgumentListInfo TransArgs;
15819 if (Old->hasExplicitTemplateArgs()) {
15820 TransArgs.setLAngleLoc(Old->getLAngleLoc());
15821 TransArgs.setRAngleLoc(Old->getRAngleLoc());
15822 if (getDerived().TransformTemplateArguments(
15823 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
15824 return ExprError();
15825 }
15826
15827 // FIXME: to do this check properly, we will need to preserve the
15828 // first-qualifier-in-scope here, just in case we had a dependent
15829 // base (and therefore couldn't do the check) and a
15830 // nested-name-qualifier (and therefore could do the lookup).
15831 NamedDecl *FirstQualifierInScope = nullptr;
15832
15833 return getDerived().RebuildUnresolvedMemberExpr(
15834 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
15835 TemplateKWLoc, FirstQualifierInScope, R,
15836 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
15837}
15838
15839template<typename Derived>
15841TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
15842 EnterExpressionEvaluationContext Unevaluated(
15844 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
15845 if (SubExpr.isInvalid())
15846 return ExprError();
15847
15848 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
15849 return E;
15850
15851 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
15852}
15853
15854template<typename Derived>
15856TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
15857 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
15858 if (Pattern.isInvalid())
15859 return ExprError();
15860
15861 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
15862 return E;
15863
15864 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
15865 E->getNumExpansions());
15866}
15867
15868template<typename Derived>
15870TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
15871 // If E is not value-dependent, then nothing will change when we transform it.
15872 // Note: This is an instantiation-centric view.
15873 if (!E->isValueDependent())
15874 return E;
15875
15876 EnterExpressionEvaluationContext Unevaluated(
15878
15880 TemplateArgument ArgStorage;
15881
15882 // Find the argument list to transform.
15883 if (E->isPartiallySubstituted()) {
15884 PackArgs = E->getPartialArguments();
15885 } else if (E->isValueDependent()) {
15886 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
15887 bool ShouldExpand = false;
15888 bool RetainExpansion = false;
15889 std::optional<unsigned> NumExpansions;
15890 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
15891 Unexpanded,
15892 ShouldExpand, RetainExpansion,
15893 NumExpansions))
15894 return ExprError();
15895
15896 // If we need to expand the pack, build a template argument from it and
15897 // expand that.
15898 if (ShouldExpand) {
15899 auto *Pack = E->getPack();
15900 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
15901 ArgStorage = getSema().Context.getPackExpansionType(
15902 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
15903 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
15904 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
15905 } else {
15906 auto *VD = cast<ValueDecl>(Pack);
15907 ExprResult DRE = getSema().BuildDeclRefExpr(
15908 VD, VD->getType().getNonLValueExprType(getSema().Context),
15909 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
15910 E->getPackLoc());
15911 if (DRE.isInvalid())
15912 return ExprError();
15913 ArgStorage = new (getSema().Context)
15914 PackExpansionExpr(getSema().Context.DependentTy, DRE.get(),
15915 E->getPackLoc(), std::nullopt);
15916 }
15917 PackArgs = ArgStorage;
15918 }
15919 }
15920
15921 // If we're not expanding the pack, just transform the decl.
15922 if (!PackArgs.size()) {
15923 auto *Pack = cast_or_null<NamedDecl>(
15924 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
15925 if (!Pack)
15926 return ExprError();
15927 return getDerived().RebuildSizeOfPackExpr(
15928 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
15929 std::nullopt, {});
15930 }
15931
15932 // Try to compute the result without performing a partial substitution.
15933 std::optional<unsigned> Result = 0;
15934 for (const TemplateArgument &Arg : PackArgs) {
15935 if (!Arg.isPackExpansion()) {
15936 Result = *Result + 1;
15937 continue;
15938 }
15939
15940 TemplateArgumentLoc ArgLoc;
15941 InventTemplateArgumentLoc(Arg, ArgLoc);
15942
15943 // Find the pattern of the pack expansion.
15944 SourceLocation Ellipsis;
15945 std::optional<unsigned> OrigNumExpansions;
15946 TemplateArgumentLoc Pattern =
15947 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
15948 OrigNumExpansions);
15949
15950 // Substitute under the pack expansion. Do not expand the pack (yet).
15951 TemplateArgumentLoc OutPattern;
15952 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15953 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
15954 /*Uneval*/ true))
15955 return true;
15956
15957 // See if we can determine the number of arguments from the result.
15958 std::optional<unsigned> NumExpansions =
15959 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
15960 if (!NumExpansions) {
15961 // No: we must be in an alias template expansion, and we're going to need
15962 // to actually expand the packs.
15963 Result = std::nullopt;
15964 break;
15965 }
15966
15967 Result = *Result + *NumExpansions;
15968 }
15969
15970 // Common case: we could determine the number of expansions without
15971 // substituting.
15972 if (Result)
15973 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
15974 E->getPackLoc(),
15975 E->getRParenLoc(), *Result, {});
15976
15977 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
15978 E->getPackLoc());
15979 {
15980 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
15981 typedef TemplateArgumentLocInventIterator<
15982 Derived, const TemplateArgument*> PackLocIterator;
15983 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
15984 PackLocIterator(*this, PackArgs.end()),
15985 TransformedPackArgs, /*Uneval*/true))
15986 return ExprError();
15987 }
15988
15989 // Check whether we managed to fully-expand the pack.
15990 // FIXME: Is it possible for us to do so and not hit the early exit path?
15992 bool PartialSubstitution = false;
15993 for (auto &Loc : TransformedPackArgs.arguments()) {
15994 Args.push_back(Loc.getArgument());
15995 if (Loc.getArgument().isPackExpansion())
15996 PartialSubstitution = true;
15997 }
15998
15999 if (PartialSubstitution)
16000 return getDerived().RebuildSizeOfPackExpr(
16001 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16002 std::nullopt, Args);
16003
16004 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16005 E->getPackLoc(), E->getRParenLoc(),
16006 Args.size(), {});
16007}
16008
16009template <typename Derived>
16011TreeTransform<Derived>::TransformPackIndexingExpr(PackIndexingExpr *E) {
16012 if (!E->isValueDependent())
16013 return E;
16014
16015 // Transform the index
16016 ExprResult IndexExpr;
16017 {
16018 EnterExpressionEvaluationContext ConstantContext(
16020 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16021 if (IndexExpr.isInvalid())
16022 return ExprError();
16023 }
16024
16025 SmallVector<Expr *, 5> ExpandedExprs;
16026 bool FullySubstituted = true;
16027 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16028 Expr *Pattern = E->getPackIdExpression();
16030 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16031 Unexpanded);
16032 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16033
16034 // Determine whether the set of unexpanded parameter packs can and should
16035 // be expanded.
16036 bool ShouldExpand = true;
16037 bool RetainExpansion = false;
16038 std::optional<unsigned> OrigNumExpansions;
16039 std::optional<unsigned> NumExpansions = OrigNumExpansions;
16040 if (getDerived().TryExpandParameterPacks(
16041 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16042 ShouldExpand, RetainExpansion, NumExpansions))
16043 return true;
16044 if (!ShouldExpand) {
16045 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16046 ExprResult Pack = getDerived().TransformExpr(Pattern);
16047 if (Pack.isInvalid())
16048 return ExprError();
16049 return getDerived().RebuildPackIndexingExpr(
16050 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16051 {}, /*FullySubstituted=*/false);
16052 }
16053 for (unsigned I = 0; I != *NumExpansions; ++I) {
16054 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
16055 ExprResult Out = getDerived().TransformExpr(Pattern);
16056 if (Out.isInvalid())
16057 return true;
16058 if (Out.get()->containsUnexpandedParameterPack()) {
16059 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16060 OrigNumExpansions);
16061 if (Out.isInvalid())
16062 return true;
16063 FullySubstituted = false;
16064 }
16065 ExpandedExprs.push_back(Out.get());
16066 }
16067 // If we're supposed to retain a pack expansion, do so by temporarily
16068 // forgetting the partially-substituted parameter pack.
16069 if (RetainExpansion) {
16070 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16071
16072 ExprResult Out = getDerived().TransformExpr(Pattern);
16073 if (Out.isInvalid())
16074 return true;
16075
16076 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16077 OrigNumExpansions);
16078 if (Out.isInvalid())
16079 return true;
16080 FullySubstituted = false;
16081 ExpandedExprs.push_back(Out.get());
16082 }
16083 } else if (!E->expandsToEmptyPack()) {
16084 if (getDerived().TransformExprs(E->getExpressions().data(),
16085 E->getExpressions().size(), false,
16086 ExpandedExprs))
16087 return ExprError();
16088 }
16089
16090 return getDerived().RebuildPackIndexingExpr(
16091 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16092 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16093}
16094
16095template<typename Derived>
16097TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
16098 SubstNonTypeTemplateParmPackExpr *E) {
16099 // Default behavior is to do nothing with this transformation.
16100 return E;
16101}
16102
16103template<typename Derived>
16105TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
16106 SubstNonTypeTemplateParmExpr *E) {
16107 // Default behavior is to do nothing with this transformation.
16108 return E;
16109}
16110
16111template<typename Derived>
16113TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
16114 // Default behavior is to do nothing with this transformation.
16115 return E;
16116}
16117
16118template<typename Derived>
16120TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
16121 MaterializeTemporaryExpr *E) {
16122 return getDerived().TransformExpr(E->getSubExpr());
16123}
16124
16125template<typename Derived>
16127TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
16128 UnresolvedLookupExpr *Callee = nullptr;
16129 if (Expr *OldCallee = E->getCallee()) {
16130 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
16131 if (CalleeResult.isInvalid())
16132 return ExprError();
16133 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
16134 }
16135
16136 Expr *Pattern = E->getPattern();
16137
16139 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
16140 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16141
16142 // Determine whether the set of unexpanded parameter packs can and should
16143 // be expanded.
16144 bool Expand = true;
16145 bool RetainExpansion = false;
16146 std::optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
16147 NumExpansions = OrigNumExpansions;
16148 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
16149 Pattern->getSourceRange(),
16150 Unexpanded,
16151 Expand, RetainExpansion,
16152 NumExpansions))
16153 return true;
16154
16155 if (!Expand) {
16156 // Do not expand any packs here, just transform and rebuild a fold
16157 // expression.
16158 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16159
16160 ExprResult LHS =
16161 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
16162 if (LHS.isInvalid())
16163 return true;
16164
16165 ExprResult RHS =
16166 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
16167 if (RHS.isInvalid())
16168 return true;
16169
16170 if (!getDerived().AlwaysRebuild() &&
16171 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
16172 return E;
16173
16174 return getDerived().RebuildCXXFoldExpr(
16175 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
16176 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
16177 }
16178
16179 // Formally a fold expression expands to nested parenthesized expressions.
16180 // Enforce this limit to avoid creating trees so deep we can't safely traverse
16181 // them.
16182 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) {
16183 SemaRef.Diag(E->getEllipsisLoc(),
16184 clang::diag::err_fold_expression_limit_exceeded)
16185 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
16186 << E->getSourceRange();
16187 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
16188 return ExprError();
16189 }
16190
16191 // The transform has determined that we should perform an elementwise
16192 // expansion of the pattern. Do so.
16193 ExprResult Result = getDerived().TransformExpr(E->getInit());
16194 if (Result.isInvalid())
16195 return true;
16196 bool LeftFold = E->isLeftFold();
16197
16198 // If we're retaining an expansion for a right fold, it is the innermost
16199 // component and takes the init (if any).
16200 if (!LeftFold && RetainExpansion) {
16201 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16202
16203 ExprResult Out = getDerived().TransformExpr(Pattern);
16204 if (Out.isInvalid())
16205 return true;
16206
16207 Result = getDerived().RebuildCXXFoldExpr(
16208 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
16209 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
16210 if (Result.isInvalid())
16211 return true;
16212 }
16213
16214 for (unsigned I = 0; I != *NumExpansions; ++I) {
16215 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
16216 getSema(), LeftFold ? I : *NumExpansions - I - 1);
16217 ExprResult Out = getDerived().TransformExpr(Pattern);
16218 if (Out.isInvalid())
16219 return true;
16220
16221 if (Out.get()->containsUnexpandedParameterPack()) {
16222 // We still have a pack; retain a pack expansion for this slice.
16223 Result = getDerived().RebuildCXXFoldExpr(
16224 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
16225 E->getOperator(), E->getEllipsisLoc(),
16226 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
16227 OrigNumExpansions);
16228 } else if (Result.isUsable()) {
16229 // We've got down to a single element; build a binary operator.
16230 Expr *LHS = LeftFold ? Result.get() : Out.get();
16231 Expr *RHS = LeftFold ? Out.get() : Result.get();
16232 if (Callee) {
16233 UnresolvedSet<16> Functions;
16234 Functions.append(Callee->decls_begin(), Callee->decls_end());
16235 Result = getDerived().RebuildCXXOperatorCallExpr(
16237 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
16238 Functions, LHS, RHS);
16239 } else {
16240 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
16241 E->getOperator(), LHS, RHS);
16242 }
16243 } else
16244 Result = Out;
16245
16246 if (Result.isInvalid())
16247 return true;
16248 }
16249
16250 // If we're retaining an expansion for a left fold, it is the outermost
16251 // component and takes the complete expansion so far as its init (if any).
16252 if (LeftFold && RetainExpansion) {
16253 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16254
16255 ExprResult Out = getDerived().TransformExpr(Pattern);
16256 if (Out.isInvalid())
16257 return true;
16258
16259 Result = getDerived().RebuildCXXFoldExpr(
16260 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
16261 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
16262 if (Result.isInvalid())
16263 return true;
16264 }
16265
16266 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
16267 PE->setIsProducedByFoldExpansion();
16268
16269 // If we had no init and an empty pack, and we're not retaining an expansion,
16270 // then produce a fallback value or error.
16271 if (Result.isUnset())
16272 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
16273 E->getOperator());
16274 return Result;
16275}
16276
16277template <typename Derived>
16279TreeTransform<Derived>::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) {
16280 SmallVector<Expr *, 4> TransformedInits;
16281 ArrayRef<Expr *> InitExprs = E->getInitExprs();
16282 if (TransformExprs(InitExprs.data(), InitExprs.size(), true,
16283 TransformedInits))
16284 return ExprError();
16285
16286 return getDerived().RebuildParenListExpr(E->getBeginLoc(), TransformedInits,
16287 E->getEndLoc());
16288}
16289
16290template<typename Derived>
16292TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
16293 CXXStdInitializerListExpr *E) {
16294 return getDerived().TransformExpr(E->getSubExpr());
16295}
16296
16297template<typename Derived>
16299TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
16300 return SemaRef.MaybeBindToTemporary(E);
16301}
16302
16303template<typename Derived>
16305TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
16306 return E;
16307}
16308
16309template<typename Derived>
16311TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
16312 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
16313 if (SubExpr.isInvalid())
16314 return ExprError();
16315
16316 if (!getDerived().AlwaysRebuild() &&
16317 SubExpr.get() == E->getSubExpr())
16318 return E;
16319
16320 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
16321}
16322
16323template<typename Derived>
16325TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
16326 // Transform each of the elements.
16327 SmallVector<Expr *, 8> Elements;
16328 bool ArgChanged = false;
16329 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
16330 /*IsCall=*/false, Elements, &ArgChanged))
16331 return ExprError();
16332
16333 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16334 return SemaRef.MaybeBindToTemporary(E);
16335
16336 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
16337 Elements.data(),
16338 Elements.size());
16339}
16340
16341template<typename Derived>
16343TreeTransform<Derived>::TransformObjCDictionaryLiteral(
16344 ObjCDictionaryLiteral *E) {
16345 // Transform each of the elements.
16347 bool ArgChanged = false;
16348 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
16349 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
16350
16351 if (OrigElement.isPackExpansion()) {
16352 // This key/value element is a pack expansion.
16354 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
16355 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
16356 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16357
16358 // Determine whether the set of unexpanded parameter packs can
16359 // and should be expanded.
16360 bool Expand = true;
16361 bool RetainExpansion = false;
16362 std::optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
16363 std::optional<unsigned> NumExpansions = OrigNumExpansions;
16364 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
16365 OrigElement.Value->getEndLoc());
16366 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
16367 PatternRange, Unexpanded, Expand,
16368 RetainExpansion, NumExpansions))
16369 return ExprError();
16370
16371 if (!Expand) {
16372 // The transform has determined that we should perform a simple
16373 // transformation on the pack expansion, producing another pack
16374 // expansion.
16375 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16376 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16377 if (Key.isInvalid())
16378 return ExprError();
16379
16380 if (Key.get() != OrigElement.Key)
16381 ArgChanged = true;
16382
16383 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16384 if (Value.isInvalid())
16385 return ExprError();
16386
16387 if (Value.get() != OrigElement.Value)
16388 ArgChanged = true;
16389
16390 ObjCDictionaryElement Expansion = {
16391 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
16392 };
16393 Elements.push_back(Expansion);
16394 continue;
16395 }
16396
16397 // Record right away that the argument was changed. This needs
16398 // to happen even if the array expands to nothing.
16399 ArgChanged = true;
16400
16401 // The transform has determined that we should perform an elementwise
16402 // expansion of the pattern. Do so.
16403 for (unsigned I = 0; I != *NumExpansions; ++I) {
16404 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
16405 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16406 if (Key.isInvalid())
16407 return ExprError();
16408
16409 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16410 if (Value.isInvalid())
16411 return ExprError();
16412
16413 ObjCDictionaryElement Element = {
16414 Key.get(), Value.get(), SourceLocation(), NumExpansions
16415 };
16416
16417 // If any unexpanded parameter packs remain, we still have a
16418 // pack expansion.
16419 // FIXME: Can this really happen?
16420 if (Key.get()->containsUnexpandedParameterPack() ||
16421 Value.get()->containsUnexpandedParameterPack())
16422 Element.EllipsisLoc = OrigElement.EllipsisLoc;
16423
16424 Elements.push_back(Element);
16425 }
16426
16427 // FIXME: Retain a pack expansion if RetainExpansion is true.
16428
16429 // We've finished with this pack expansion.
16430 continue;
16431 }
16432
16433 // Transform and check key.
16434 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16435 if (Key.isInvalid())
16436 return ExprError();
16437
16438 if (Key.get() != OrigElement.Key)
16439 ArgChanged = true;
16440
16441 // Transform and check value.
16443 = getDerived().TransformExpr(OrigElement.Value);
16444 if (Value.isInvalid())
16445 return ExprError();
16446
16447 if (Value.get() != OrigElement.Value)
16448 ArgChanged = true;
16449
16450 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
16451 std::nullopt};
16452 Elements.push_back(Element);
16453 }
16454
16455 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16456 return SemaRef.MaybeBindToTemporary(E);
16457
16458 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
16459 Elements);
16460}
16461
16462template<typename Derived>
16464TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
16465 TypeSourceInfo *EncodedTypeInfo
16466 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
16467 if (!EncodedTypeInfo)
16468 return ExprError();
16469
16470 if (!getDerived().AlwaysRebuild() &&
16471 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
16472 return E;
16473
16474 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
16475 EncodedTypeInfo,
16476 E->getRParenLoc());
16477}
16478
16479template<typename Derived>
16480ExprResult TreeTransform<Derived>::
16481TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
16482 // This is a kind of implicit conversion, and it needs to get dropped
16483 // and recomputed for the same general reasons that ImplicitCastExprs
16484 // do, as well a more specific one: this expression is only valid when
16485 // it appears *immediately* as an argument expression.
16486 return getDerived().TransformExpr(E->getSubExpr());
16487}
16488
16489template<typename Derived>
16490ExprResult TreeTransform<Derived>::
16491TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
16492 TypeSourceInfo *TSInfo
16493 = getDerived().TransformType(E->getTypeInfoAsWritten());
16494 if (!TSInfo)
16495 return ExprError();
16496
16497 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
16498 if (Result.isInvalid())
16499 return ExprError();
16500
16501 if (!getDerived().AlwaysRebuild() &&
16502 TSInfo == E->getTypeInfoAsWritten() &&
16503 Result.get() == E->getSubExpr())
16504 return E;
16505
16506 return SemaRef.ObjC().BuildObjCBridgedCast(
16507 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
16508 Result.get());
16509}
16510
16511template <typename Derived>
16512ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
16513 ObjCAvailabilityCheckExpr *E) {
16514 return E;
16515}
16516
16517template<typename Derived>
16519TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
16520 // Transform arguments.
16521 bool ArgChanged = false;
16523 Args.reserve(E->getNumArgs());
16524 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
16525 &ArgChanged))
16526 return ExprError();
16527
16528 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
16529 // Class message: transform the receiver type.
16530 TypeSourceInfo *ReceiverTypeInfo
16531 = getDerived().TransformType(E->getClassReceiverTypeInfo());
16532 if (!ReceiverTypeInfo)
16533 return ExprError();
16534
16535 // If nothing changed, just retain the existing message send.
16536 if (!getDerived().AlwaysRebuild() &&
16537 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
16538 return SemaRef.MaybeBindToTemporary(E);
16539
16540 // Build a new class message send.
16542 E->getSelectorLocs(SelLocs);
16543 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
16544 E->getSelector(),
16545 SelLocs,
16546 E->getMethodDecl(),
16547 E->getLeftLoc(),
16548 Args,
16549 E->getRightLoc());
16550 }
16551 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
16552 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16553 if (!E->getMethodDecl())
16554 return ExprError();
16555
16556 // Build a new class message send to 'super'.
16558 E->getSelectorLocs(SelLocs);
16559 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
16560 E->getSelector(),
16561 SelLocs,
16562 E->getReceiverType(),
16563 E->getMethodDecl(),
16564 E->getLeftLoc(),
16565 Args,
16566 E->getRightLoc());
16567 }
16568
16569 // Instance message: transform the receiver
16570 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
16571 "Only class and instance messages may be instantiated");
16572 ExprResult Receiver
16573 = getDerived().TransformExpr(E->getInstanceReceiver());
16574 if (Receiver.isInvalid())
16575 return ExprError();
16576
16577 // If nothing changed, just retain the existing message send.
16578 if (!getDerived().AlwaysRebuild() &&
16579 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
16580 return SemaRef.MaybeBindToTemporary(E);
16581
16582 // Build a new instance message send.
16584 E->getSelectorLocs(SelLocs);
16585 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
16586 E->getSelector(),
16587 SelLocs,
16588 E->getMethodDecl(),
16589 E->getLeftLoc(),
16590 Args,
16591 E->getRightLoc());
16592}
16593
16594template<typename Derived>
16596TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
16597 return E;
16598}
16599
16600template<typename Derived>
16602TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
16603 return E;
16604}
16605
16606template<typename Derived>
16608TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
16609 // Transform the base expression.
16610 ExprResult Base = getDerived().TransformExpr(E->getBase());
16611 if (Base.isInvalid())
16612 return ExprError();
16613
16614 // We don't need to transform the ivar; it will never change.
16615
16616 // If nothing changed, just retain the existing expression.
16617 if (!getDerived().AlwaysRebuild() &&
16618 Base.get() == E->getBase())
16619 return E;
16620
16621 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
16622 E->getLocation(),
16623 E->isArrow(), E->isFreeIvar());
16624}
16625
16626template<typename Derived>
16628TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
16629 // 'super' and types never change. Property never changes. Just
16630 // retain the existing expression.
16631 if (!E->isObjectReceiver())
16632 return E;
16633
16634 // Transform the base expression.
16635 ExprResult Base = getDerived().TransformExpr(E->getBase());
16636 if (Base.isInvalid())
16637 return ExprError();
16638
16639 // We don't need to transform the property; it will never change.
16640
16641 // If nothing changed, just retain the existing expression.
16642 if (!getDerived().AlwaysRebuild() &&
16643 Base.get() == E->getBase())
16644 return E;
16645
16646 if (E->isExplicitProperty())
16647 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16648 E->getExplicitProperty(),
16649 E->getLocation());
16650
16651 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16652 SemaRef.Context.PseudoObjectTy,
16653 E->getImplicitPropertyGetter(),
16654 E->getImplicitPropertySetter(),
16655 E->getLocation());
16656}
16657
16658template<typename Derived>
16660TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
16661 // Transform the base expression.
16662 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
16663 if (Base.isInvalid())
16664 return ExprError();
16665
16666 // Transform the key expression.
16667 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
16668 if (Key.isInvalid())
16669 return ExprError();
16670
16671 // If nothing changed, just retain the existing expression.
16672 if (!getDerived().AlwaysRebuild() &&
16673 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
16674 return E;
16675
16676 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
16677 Base.get(), Key.get(),
16678 E->getAtIndexMethodDecl(),
16679 E->setAtIndexMethodDecl());
16680}
16681
16682template<typename Derived>
16684TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
16685 // Transform the base expression.
16686 ExprResult Base = getDerived().TransformExpr(E->getBase());
16687 if (Base.isInvalid())
16688 return ExprError();
16689
16690 // If nothing changed, just retain the existing expression.
16691 if (!getDerived().AlwaysRebuild() &&
16692 Base.get() == E->getBase())
16693 return E;
16694
16695 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
16696 E->getOpLoc(),
16697 E->isArrow());
16698}
16699
16700template<typename Derived>
16702TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
16703 bool ArgumentChanged = false;
16704 SmallVector<Expr*, 8> SubExprs;
16705 SubExprs.reserve(E->getNumSubExprs());
16706 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
16707 SubExprs, &ArgumentChanged))
16708 return ExprError();
16709
16710 if (!getDerived().AlwaysRebuild() &&
16711 !ArgumentChanged)
16712 return E;
16713
16714 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
16715 SubExprs,
16716 E->getRParenLoc());
16717}
16718
16719template<typename Derived>
16721TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
16722 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
16723 if (SrcExpr.isInvalid())
16724 return ExprError();
16725
16726 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
16727 if (!Type)
16728 return ExprError();
16729
16730 if (!getDerived().AlwaysRebuild() &&
16731 Type == E->getTypeSourceInfo() &&
16732 SrcExpr.get() == E->getSrcExpr())
16733 return E;
16734
16735 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
16736 SrcExpr.get(), Type,
16737 E->getRParenLoc());
16738}
16739
16740template<typename Derived>
16742TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
16743 BlockDecl *oldBlock = E->getBlockDecl();
16744
16745 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
16746 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
16747
16748 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
16749 blockScope->TheDecl->setBlockMissingReturnType(
16750 oldBlock->blockMissingReturnType());
16751
16753 SmallVector<QualType, 4> paramTypes;
16754
16755 const FunctionProtoType *exprFunctionType = E->getFunctionType();
16756
16757 // Parameter substitution.
16758 Sema::ExtParameterInfoBuilder extParamInfos;
16759 if (getDerived().TransformFunctionTypeParams(
16760 E->getCaretLocation(), oldBlock->parameters(), nullptr,
16761 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
16762 extParamInfos)) {
16763 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
16764 return ExprError();
16765 }
16766
16767 QualType exprResultType =
16768 getDerived().TransformType(exprFunctionType->getReturnType());
16769
16770 auto epi = exprFunctionType->getExtProtoInfo();
16771 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
16772
16773 QualType functionType =
16774 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
16775 blockScope->FunctionType = functionType;
16776
16777 // Set the parameters on the block decl.
16778 if (!params.empty())
16779 blockScope->TheDecl->setParams(params);
16780
16781 if (!oldBlock->blockMissingReturnType()) {
16782 blockScope->HasImplicitReturnType = false;
16783 blockScope->ReturnType = exprResultType;
16784 }
16785
16786 // Transform the body
16787 StmtResult body = getDerived().TransformStmt(E->getBody());
16788 if (body.isInvalid()) {
16789 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
16790 return ExprError();
16791 }
16792
16793#ifndef NDEBUG
16794 // In builds with assertions, make sure that we captured everything we
16795 // captured before.
16796 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
16797 for (const auto &I : oldBlock->captures()) {
16798 VarDecl *oldCapture = I.getVariable();
16799
16800 // Ignore parameter packs.
16801 if (oldCapture->isParameterPack())
16802 continue;
16803
16804 VarDecl *newCapture =
16805 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
16806 oldCapture));
16807 assert(blockScope->CaptureMap.count(newCapture));
16808 }
16809
16810 // The this pointer may not be captured by the instantiated block, even when
16811 // it's captured by the original block, if the expression causing the
16812 // capture is in the discarded branch of a constexpr if statement.
16813 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
16814 "this pointer isn't captured in the old block");
16815 }
16816#endif
16817
16818 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
16819 /*Scope=*/nullptr);
16820}
16821
16822template<typename Derived>
16824TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
16825 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
16826 if (SrcExpr.isInvalid())
16827 return ExprError();
16828
16829 QualType Type = getDerived().TransformType(E->getType());
16830
16831 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
16832 E->getRParenLoc());
16833}
16834
16835template<typename Derived>
16837TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
16838 bool ArgumentChanged = false;
16839 SmallVector<Expr*, 8> SubExprs;
16840 SubExprs.reserve(E->getNumSubExprs());
16841 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
16842 SubExprs, &ArgumentChanged))
16843 return ExprError();
16844
16845 if (!getDerived().AlwaysRebuild() &&
16846 !ArgumentChanged)
16847 return E;
16848
16849 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
16850 E->getOp(), E->getRParenLoc());
16851}
16852
16853//===----------------------------------------------------------------------===//
16854// Type reconstruction
16855//===----------------------------------------------------------------------===//
16856
16857template<typename Derived>
16860 return SemaRef.BuildPointerType(PointeeType, Star,
16861 getDerived().getBaseEntity());
16862}
16863
16864template<typename Derived>
16867 return SemaRef.BuildBlockPointerType(PointeeType, Star,
16868 getDerived().getBaseEntity());
16869}
16870
16871template<typename Derived>
16874 bool WrittenAsLValue,
16875 SourceLocation Sigil) {
16876 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
16877 Sigil, getDerived().getBaseEntity());
16878}
16879
16880template<typename Derived>
16883 QualType ClassType,
16884 SourceLocation Sigil) {
16885 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
16886 getDerived().getBaseEntity());
16887}
16888
16889template<typename Derived>
16891 const ObjCTypeParamDecl *Decl,
16892 SourceLocation ProtocolLAngleLoc,
16894 ArrayRef<SourceLocation> ProtocolLocs,
16895 SourceLocation ProtocolRAngleLoc) {
16896 return SemaRef.ObjC().BuildObjCTypeParamType(
16897 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16898 /*FailOnError=*/true);
16899}
16900
16901template<typename Derived>
16903 QualType BaseType,
16905 SourceLocation TypeArgsLAngleLoc,
16907 SourceLocation TypeArgsRAngleLoc,
16908 SourceLocation ProtocolLAngleLoc,
16910 ArrayRef<SourceLocation> ProtocolLocs,
16911 SourceLocation ProtocolRAngleLoc) {
16912 return SemaRef.ObjC().BuildObjCObjectType(
16913 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
16914 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16915 /*FailOnError=*/true,
16916 /*Rebuilding=*/true);
16917}
16918
16919template<typename Derived>
16921 QualType PointeeType,
16923 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
16924}
16925
16926template <typename Derived>
16928 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
16929 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16930 if (SizeExpr || !Size)
16931 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
16932 IndexTypeQuals, BracketsRange,
16933 getDerived().getBaseEntity());
16934
16935 QualType Types[] = {
16939 };
16940 QualType SizeType;
16941 for (const auto &T : Types)
16942 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
16943 SizeType = T;
16944 break;
16945 }
16946
16947 // Note that we can return a VariableArrayType here in the case where
16948 // the element type was a dependent VariableArrayType.
16949 IntegerLiteral *ArraySize
16950 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
16951 /*FIXME*/BracketsRange.getBegin());
16952 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
16953 IndexTypeQuals, BracketsRange,
16954 getDerived().getBaseEntity());
16955}
16956
16957template <typename Derived>
16959 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
16960 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16961 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
16962 IndexTypeQuals, BracketsRange);
16963}
16964
16965template <typename Derived>
16967 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
16968 SourceRange BracketsRange) {
16969 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
16970 IndexTypeQuals, BracketsRange);
16971}
16972
16973template <typename Derived>
16975 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16976 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16977 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16978 SizeExpr,
16979 IndexTypeQuals, BracketsRange);
16980}
16981
16982template <typename Derived>
16984 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16985 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16986 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16987 SizeExpr,
16988 IndexTypeQuals, BracketsRange);
16989}
16990
16991template <typename Derived>
16993 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
16994 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
16995 AttributeLoc);
16996}
16997
16998template <typename Derived>
17000 unsigned NumElements,
17001 VectorKind VecKind) {
17002 // FIXME: semantic checking!
17003 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17004}
17005
17006template <typename Derived>
17008 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17009 VectorKind VecKind) {
17010 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17011}
17012
17013template<typename Derived>
17015 unsigned NumElements,
17016 SourceLocation AttributeLoc) {
17017 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17018 NumElements, true);
17019 IntegerLiteral *VectorSize
17020 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17021 AttributeLoc);
17022 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17023}
17024
17025template<typename Derived>
17028 Expr *SizeExpr,
17029 SourceLocation AttributeLoc) {
17030 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17031}
17032
17033template <typename Derived>
17035 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17036 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17037 NumColumns);
17038}
17039
17040template <typename Derived>
17042 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17043 SourceLocation AttributeLoc) {
17044 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17045 AttributeLoc);
17046}
17047
17048template<typename Derived>
17050 QualType T,
17051 MutableArrayRef<QualType> ParamTypes,
17053 return SemaRef.BuildFunctionType(T, ParamTypes,
17054 getDerived().getBaseLocation(),
17055 getDerived().getBaseEntity(),
17056 EPI);
17057}
17058
17059template<typename Derived>
17061 return SemaRef.Context.getFunctionNoProtoType(T);
17062}
17063
17064template<typename Derived>
17066 Decl *D) {
17067 assert(D && "no decl found");
17068 if (D->isInvalidDecl()) return QualType();
17069
17070 // FIXME: Doesn't account for ObjCInterfaceDecl!
17071 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
17072 // A valid resolved using typename pack expansion decl can have multiple
17073 // UsingDecls, but they must each have exactly one type, and it must be
17074 // the same type in every case. But we must have at least one expansion!
17075 if (UPD->expansions().empty()) {
17076 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
17077 << UPD->isCXXClassMember() << UPD;
17078 return QualType();
17079 }
17080
17081 // We might still have some unresolved types. Try to pick a resolved type
17082 // if we can. The final instantiation will check that the remaining
17083 // unresolved types instantiate to the type we pick.
17084 QualType FallbackT;
17085 QualType T;
17086 for (auto *E : UPD->expansions()) {
17087 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
17088 if (ThisT.isNull())
17089 continue;
17090 else if (ThisT->getAs<UnresolvedUsingType>())
17091 FallbackT = ThisT;
17092 else if (T.isNull())
17093 T = ThisT;
17094 else
17095 assert(getSema().Context.hasSameType(ThisT, T) &&
17096 "mismatched resolved types in using pack expansion");
17097 }
17098 return T.isNull() ? FallbackT : T;
17099 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
17100 assert(Using->hasTypename() &&
17101 "UnresolvedUsingTypenameDecl transformed to non-typename using");
17102
17103 // A valid resolved using typename decl points to exactly one type decl.
17104 assert(++Using->shadow_begin() == Using->shadow_end());
17105
17106 UsingShadowDecl *Shadow = *Using->shadow_begin();
17107 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), Loc))
17108 return QualType();
17109 return SemaRef.Context.getUsingType(
17110 Shadow, SemaRef.Context.getTypeDeclType(
17111 cast<TypeDecl>(Shadow->getTargetDecl())));
17112 } else {
17113 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
17114 "UnresolvedUsingTypenameDecl transformed to non-using decl");
17115 return SemaRef.Context.getTypeDeclType(
17116 cast<UnresolvedUsingTypenameDecl>(D));
17117 }
17118}
17119
17120template <typename Derived>
17122 TypeOfKind Kind) {
17123 return SemaRef.BuildTypeofExprType(E, Kind);
17124}
17125
17126template<typename Derived>
17128 TypeOfKind Kind) {
17129 return SemaRef.Context.getTypeOfType(Underlying, Kind);
17130}
17131
17132template <typename Derived>
17134 return SemaRef.BuildDecltypeType(E);
17135}
17136
17137template <typename Derived>
17139 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
17140 SourceLocation EllipsisLoc, bool FullySubstituted,
17141 ArrayRef<QualType> Expansions) {
17142 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
17143 FullySubstituted, Expansions);
17144}
17145
17146template<typename Derived>
17150 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
17151}
17152
17153template<typename Derived>
17155 TemplateName Template,
17156 SourceLocation TemplateNameLoc,
17157 TemplateArgumentListInfo &TemplateArgs) {
17158 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
17159}
17160
17161template<typename Derived>
17163 SourceLocation KWLoc) {
17164 return SemaRef.BuildAtomicType(ValueType, KWLoc);
17165}
17166
17167template<typename Derived>
17169 SourceLocation KWLoc,
17170 bool isReadPipe) {
17171 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
17172 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
17173}
17174
17175template <typename Derived>
17177 unsigned NumBits,
17179 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17180 NumBits, true);
17181 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
17182 SemaRef.Context.IntTy, Loc);
17183 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
17184}
17185
17186template <typename Derived>
17188 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
17189 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
17190}
17191
17192template<typename Derived>
17195 bool TemplateKW,
17196 TemplateDecl *Template) {
17197 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
17198 TemplateName(Template));
17199}
17200
17201template<typename Derived>
17204 SourceLocation TemplateKWLoc,
17205 const IdentifierInfo &Name,
17206 SourceLocation NameLoc,
17207 QualType ObjectType,
17208 NamedDecl *FirstQualifierInScope,
17209 bool AllowInjectedClassName) {
17211 TemplateName.setIdentifier(&Name, NameLoc);
17212 Sema::TemplateTy Template;
17213 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
17214 TemplateName, ParsedType::make(ObjectType),
17215 /*EnteringContext=*/false, Template,
17216 AllowInjectedClassName);
17217 return Template.get();
17218}
17219
17220template<typename Derived>
17223 SourceLocation TemplateKWLoc,
17224 OverloadedOperatorKind Operator,
17225 SourceLocation NameLoc,
17226 QualType ObjectType,
17227 bool AllowInjectedClassName) {
17228 UnqualifiedId Name;
17229 // FIXME: Bogus location information.
17230 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
17231 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
17232 Sema::TemplateTy Template;
17233 getSema().ActOnTemplateName(
17234 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
17235 /*EnteringContext=*/false, Template, AllowInjectedClassName);
17236 return Template.get();
17237}
17238
17239template <typename Derived>
17242 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
17243 Expr *Second) {
17244 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
17245
17246 if (First->getObjectKind() == OK_ObjCProperty) {
17249 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
17250 Opc, First, Second);
17252 if (Result.isInvalid())
17253 return ExprError();
17254 First = Result.get();
17255 }
17256
17257 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
17258 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
17259 if (Result.isInvalid())
17260 return ExprError();
17261 Second = Result.get();
17262 }
17263
17264 // Determine whether this should be a builtin operation.
17265 if (Op == OO_Subscript) {
17266 if (!First->getType()->isOverloadableType() &&
17267 !Second->getType()->isOverloadableType())
17268 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
17269 OpLoc);
17270 } else if (Op == OO_Arrow) {
17271 // It is possible that the type refers to a RecoveryExpr created earlier
17272 // in the tree transformation.
17273 if (First->getType()->isDependentType())
17274 return ExprError();
17275 // -> is never a builtin operation.
17276 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
17277 } else if (Second == nullptr || isPostIncDec) {
17278 if (!First->getType()->isOverloadableType() ||
17279 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
17280 // The argument is not of overloadable type, or this is an expression
17281 // of the form &Class::member, so try to create a built-in unary
17282 // operation.
17284 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17285
17286 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
17287 }
17288 } else {
17289 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
17290 !First->getType()->isOverloadableType() &&
17291 !Second->getType()->isOverloadableType()) {
17292 // Neither of the arguments is type-dependent or has an overloadable
17293 // type, so try to create a built-in binary operation.
17296 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
17297 if (Result.isInvalid())
17298 return ExprError();
17299
17300 return Result;
17301 }
17302 }
17303
17304 // Create the overloaded operator invocation for unary operators.
17305 if (!Second || isPostIncDec) {
17307 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17308 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
17309 RequiresADL);
17310 }
17311
17312 // Create the overloaded operator invocation for binary operators.
17314 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
17315 First, Second, RequiresADL);
17316 if (Result.isInvalid())
17317 return ExprError();
17318
17319 return Result;
17320}
17321
17322template<typename Derived>
17325 SourceLocation OperatorLoc,
17326 bool isArrow,
17327 CXXScopeSpec &SS,
17328 TypeSourceInfo *ScopeType,
17329 SourceLocation CCLoc,
17330 SourceLocation TildeLoc,
17331 PseudoDestructorTypeStorage Destroyed) {
17332 QualType BaseType = Base->getType();
17333 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
17334 (!isArrow && !BaseType->getAs<RecordType>()) ||
17335 (isArrow && BaseType->getAs<PointerType>() &&
17336 !BaseType->castAs<PointerType>()->getPointeeType()
17337 ->template getAs<RecordType>())){
17338 // This pseudo-destructor expression is still a pseudo-destructor.
17339 return SemaRef.BuildPseudoDestructorExpr(
17340 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
17341 CCLoc, TildeLoc, Destroyed);
17342 }
17343
17344 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
17346 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
17347 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
17348 NameInfo.setNamedTypeInfo(DestroyedType);
17349
17350 // The scope type is now known to be a valid nested name specifier
17351 // component. Tack it on to the end of the nested name specifier.
17352 if (ScopeType) {
17353 if (!ScopeType->getType()->getAs<TagType>()) {
17354 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
17355 diag::err_expected_class_or_namespace)
17356 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
17357 return ExprError();
17358 }
17359 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
17360 CCLoc);
17361 }
17362
17363 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
17364 return getSema().BuildMemberReferenceExpr(Base, BaseType,
17365 OperatorLoc, isArrow,
17366 SS, TemplateKWLoc,
17367 /*FIXME: FirstQualifier*/ nullptr,
17368 NameInfo,
17369 /*TemplateArgs*/ nullptr,
17370 /*S*/nullptr);
17371}
17372
17373template<typename Derived>
17376 SourceLocation Loc = S->getBeginLoc();
17377 CapturedDecl *CD = S->getCapturedDecl();
17378 unsigned NumParams = CD->getNumParams();
17379 unsigned ContextParamPos = CD->getContextParamPosition();
17381 for (unsigned I = 0; I < NumParams; ++I) {
17382 if (I != ContextParamPos) {
17383 Params.push_back(
17384 std::make_pair(
17385 CD->getParam(I)->getName(),
17386 getDerived().TransformType(CD->getParam(I)->getType())));
17387 } else {
17388 Params.push_back(std::make_pair(StringRef(), QualType()));
17389 }
17390 }
17391 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
17392 S->getCapturedRegionKind(), Params);
17393 StmtResult Body;
17394 {
17395 Sema::CompoundScopeRAII CompoundScope(getSema());
17396 Body = getDerived().TransformStmt(S->getCapturedStmt());
17397 }
17398
17399 if (Body.isInvalid()) {
17400 getSema().ActOnCapturedRegionError();
17401 return StmtError();
17402 }
17403
17404 return getSema().ActOnCapturedRegionEnd(Body.get());
17405}
17406
17407template <typename Derived>
17408ExprResult TreeTransform<Derived>::TransformHLSLOutArgExpr(HLSLOutArgExpr *E) {
17409 // We can transform the base expression and allow argument resolution to fill
17410 // in the rest.
17411 return getDerived().TransformExpr(E->getArgLValue());
17412}
17413
17414} // end namespace clang
17415
17416#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:6556
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:6566
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:6571
AutoTypeKeyword getKeyword() const
Definition: Type.h:6587
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2188
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:2150
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:1491
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:6543
bool isDeduced() const
Definition: Type.h:6544
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3323
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:548
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2503
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2527
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2523
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:2519
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2491
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2547
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2487
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2539
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2555
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2531
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:7076
Designation - Represent a full designation, which is a sequence of designators.
Definition: Designator.h:208
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
Definition: Designator.h:172
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
Definition: Designator.h:142
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Designator.h:115
bool hasErrorOccurred() const
Definition: Diagnostic.h:866
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition: Type.h:4823
Expr * getCondition() const
Definition: Type.h:4830
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2350
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2362
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2354
TypeLoc getNamedTypeLoc() const
Definition: TypeLoc.h:2392
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2368
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6943
RAII object that enters a new expression evaluation context.
Represents an enum.
Definition: Decl.h: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:4716
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition: Type.cpp:5223
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition: Type.cpp:5209
ArrayRef< EffectConditionExpr > conditions() const
Definition: Type.h:4937
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4681
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5102
QualType desugar() const
Definition: Type.h:5646
param_type_iterator param_type_begin() const
Definition: Type.h:5515
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:5553
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:5495
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5366
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:5362
unsigned getNumParams() const
Definition: TypeLoc.h:1531
SourceLocation getLocalRangeEnd() const
Definition: TypeLoc.h:1483
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1479
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1495
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1511
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1538
ArrayRef< ParmVarDecl * > getParams() const
Definition: TypeLoc.h:1522
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1503
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1487
void setExceptionSpecRange(SourceRange R)
Definition: TypeLoc.h:1517
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1540
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1475
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1491
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1499
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:4347
QualType getReturnType() const
Definition: Type.h:4643
AssociationTy< false > Association
Definition: Expr.h:6197
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3724
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5841
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:514
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:972
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:7141
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:7166
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2170
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2195
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2199
Represents a parameter to a function.
Definition: Decl.h:1725
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1785
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1758
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2922
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1775
void setSigilLoc(SourceLocation Loc)
Definition: TypeLoc.h:1309
TypeLoc getPointeeLoc() const
Definition: TypeLoc.h:1313
SourceLocation getSigilLoc() const
Definition: TypeLoc.h:1305
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3198
QualType getPointeeType() const
Definition: Type.h:3208
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2566
const IdentifierInfo * getIdentifier() const
Definition: ExprCXX.h:2586
SourceLocation getLocation() const
Definition: ExprCXX.h:2590
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2582
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7931
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:7971
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:8025
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7963
Represents a template name as written in source code.
Definition: TemplateName.h:491
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition: TypeLoc.h:289
The collection of all-type qualifiers we support.
Definition: Type.h:324
void removeObjCLifetime()
Definition: Type.h:544
bool hasRestrict() const
Definition: Type.h:470
static Qualifiers fromCVRMask(unsigned CVR)
Definition: Type.h:428
bool hasObjCLifetime() const
Definition: Type.h:537
bool empty() const
Definition: Type.h:640
LangAS getAddressSpace() const
Definition: Type.h:564
Represents a struct/union/class.
Definition: Decl.h:4162
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6072
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3439
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3455
Represents the body of a requires-expression.
Definition: DeclCXX.h:2047
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition: DeclCXX.cpp:2268
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:502
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition: Stmt.cpp: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 * ActOnOpenMPAllocateClause(Expr *Allocator, OpenMPAllocateClauseModifier ACModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' clause.
OMPClause * ActOnOpenMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'dist_schedule' clause.
OMPClause * ActOnOpenMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'permutation' clause after parsing its arguments.
OMPClause * ActOnOpenMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nontemporal' clause.
OMPClause * ActOnOpenMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'from' clause.
OMPClause * ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'bind' clause.
OMPClause * ActOnOpenMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'thread_limit' clause.
OMPClause * ActOnOpenMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'shared' clause.
OMPClause * ActOnOpenMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyin' clause.
OMPClause * ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'destroy' clause.
OMPClause * ActOnOpenMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Called on well-formed 'affinity' clause.
OMPClause * ActOnOpenMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' clause.
OMPClause * ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depend' clause.
OMPClause * ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'doacross' clause.
OMPClause * ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'grainsize' clause.
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< OMPIteratorData > Data)
OMPClause * ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< UsesAllocatorsData > Data)
Called on well-formed 'uses_allocators' clause.
OMPClause * ActOnOpenMPAllocatorClause(Expr *Allocator, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocator' clause.
OMPClause * ActOnOpenMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'inclusive' clause.
OMPClause * ActOnOpenMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'task_reduction' clause.
OMPClause * ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, OpenMPOrderClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'order' clause.
OMPClause * ActOnOpenMPReductionClause(ArrayRef< Expr * > VarList, OpenMPReductionClauseModifier Modifier, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'reduction' clause.
OMPClause * ActOnOpenMPSizesClause(ArrayRef< Expr * > SizeExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'sizes' clause.
OMPClause * ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'device' clause.
OMPClause * ActOnOpenMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_threads' clause.
OMPClause * ActOnOpenMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'in_reduction' clause.
OMPClause * ActOnOpenMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'flush' pseudo clause.
StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
OMPClause * ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'message' clause.
OMPClause * ActOnOpenMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'schedule' clause.
OMPClause * ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'simdlen' clause.
OMPClause * ActOnOpenMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_ptr' clause.
OMPClause * ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'proc_bind' clause.
OMPClause * ActOnOpenMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_bare' clause.
StmtResult ActOnOpenMPInformationalDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Process an OpenMP informational directive.
StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt)
Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to an OpenMP loop directive.
OMPClause * ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'hint' clause.
ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > Brackets)
OMPClause * ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'at' clause.
OMPClause * ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'init' clause.
OMPClause * ActOnOpenMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_addr' clause.
OMPClause * ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'final' clause.
OMPClause * ActOnOpenMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, bool NoDiagnose=false, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'map' clause.
OMPClause * ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_tasks' clause.
OMPClause * ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'severity' clause.
OMPClause * ActOnOpenMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc)
Called on well-formed 'linear' clause.
OMPClause * ActOnOpenMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'defaultmap' clause.
OMPClause * ActOnOpenMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'aligned' clause.
OMPClause * ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depobj' pseudo clause.
OMPClause * ActOnOpenMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'novariants' clause.
OMPClause * ActOnOpenMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyprivate' clause.
OMPClause * ActOnOpenMPCollapseClause(Expr *NumForLoops, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'collapse' clause.
OMPClause * ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'align' clause.
OMPClause * ActOnOpenMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_attribute' clause.
OMPClause * ActOnOpenMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'exclusive' clause.
OMPClause * ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'if' clause.
ExprResult checkAssignment(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opcode, Expr *LHS, Expr *RHS)
Expr * recreateSyntacticForm(PseudoObjectExpr *E)
Given a pseudo-object expression, recreate what it looks like syntactically without the attendant Opa...
ExprResult checkRValue(Expr *E)
ExprResult BuildUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition: SemaSYCL.cpp: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:1674
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:6394
QualType getCurrentThisType()
Try to retrieve the type of the 'this' pointer.
bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range)
CheckSpecifiedExceptionType - Check if the given type is valid in an exception specification.
ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, UnresolvedLookupExpr *Lookup)
Build a call to 'operator co_await' if there is a suitable operator for the given expression.
ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, const Scope *S, ActOnMemberAccessExtraArgs *ExtraArgs=nullptr)
StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Definition: SemaStmt.cpp: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:6497
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:2326
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:7624
VarDecl * buildCoroutinePromise(SourceLocation Loc)
ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr=false)
CheckBooleanCondition - Diagnose problems involving the use of the given expression as a boolean cond...
Definition: SemaExpr.cpp: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:2392
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:2632
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:9567
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:1939
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:1580
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:1856
ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *input, bool RequiresADL=true)
Create a unary operation that may resolve to an overloaded operator.
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition: Sema.h: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:9689
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:9972
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:1804
StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, BuildForRangeKind Kind, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
Definition: SemaStmt.cpp: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:9657
QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, SourceLocation Loc)
Definition: SemaType.cpp:9916
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:2047
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:1931
concepts::NestedRequirement * BuildNestedRequirement(Expr *E)
QualType BuildWritePipeType(QualType T, SourceLocation Loc)
Build a Write-only Pipe type.
Definition: SemaType.cpp:1935
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h: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:9544
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:2446
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
Definition: SemaExpr.cpp: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:2750
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:2681
QualType BuildBlockPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a block pointer type.
Definition: SemaType.cpp:2733
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
Definition: SemaStmt.cpp: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:6661
Wrapper for template type parameters.
Definition: TypeLoc.h:758
The top declaration context.
Definition: Decl.h:84
RAII object that temporarily sets the base location and entity used for reporting diagnostics in type...
TemporaryBase(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
A semantic tree transformation that allows one to transform one abstract syntax tree into another.
ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *object)
Rebuild the operand to an Objective-C @synchronized statement.
OMPClause * RebuildOMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nontemporal' clause.
StmtResult RebuildOpenACCDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit)
Transform the given initializer.
StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new label statement.
StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args)
StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @autoreleasepool statement.
OMPClause * RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'dist_schedule' clause.
ExprResult RebuildUnaryOperator(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *SubExpr)
Build a new unary operator expression.
OMPClause * RebuildOMPProcBindClause(ProcBindKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'proc_bind' clause.
StmtResult RebuildOMPInformationalDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP informational directive.
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Build a new C++11 default-initialization expression.
OMPClause * RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'priority' clause.
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)
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.
OMPClause * RebuildOMPAllocateClause(Expr *Allocate, OpenMPAllocateClauseModifier ACModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocate' clause.
ExprResult TransformExpr(Expr *E)
Transform the given expression.
bool AlreadyTransformed(QualType T)
Determine whether the given type T has already been transformed.
concepts::TypeRequirement * RebuildTypeRequirement(TypeSourceInfo *T)
ExprResult RebuildOMPIteratorExpr(SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< SemaOpenMP::OMPIteratorData > Data)
Build a new iterator expression.
ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
OMPClause * RebuildOMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'grainsize' clause.
OMPClause * RebuildOMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
bool TransformTemplateArguments(InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
static ExprResult Owned(Expr *E)
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(expr) expression.
OMPClause * RebuildOMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_tasks' clause.
OMPClause * RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depobj' pseudo clause.
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc)
Build a new __builtin_choose_expr expression.
OMPClause * RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'align' clause.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C class message.
bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, LookupResult &R)
Transform the set of declarations in an OverloadExpr.
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, SourceLocation LParenOrBraceLoc, MultiExprArg Args, SourceLocation RParenOrBraceLoc, bool ListInitialization)
Build a new object-construction expression.
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init, SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps)
Build a new C++0x range-based for statement.
OMPClause * RebuildOMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Num)
Build a new OpenMP 'ordered' clause.
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
QualType RebuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build an Objective-C object type.
llvm::DenseMap< Decl *, Decl * > TransformedLocalDecls
The set of local declarations that have been transformed, for cases where we are forced to build new ...
OMPClause * RebuildOMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'novariants' clause.
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E)
ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocatedType, TypeSourceInfo *AllocatedTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
Build a new C++ "new" expression.
StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, Stmt *Element, Expr *Collection, SourceLocation RParenLoc, Stmt *Body)
Build a new Objective-C fast enumeration statement.
ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
Build a new (previously unresolved) declaration reference expression.
StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, Stmt *TryBody, MultiStmtArg CatchStmts, Stmt *Finally)
Build a new Objective-C @try statement.
DeclarationName getBaseEntity()
Returns the name of the entity being transformed, if that information was not available elsewhere in ...
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, bool ListInitialization)
Build a new object-construction expression.
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length, ArrayRef< TemplateArgument > PartialArgs)
Build a new expression to compute the length of a parameter pack.
ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, SourceLocation CalleeLoc, bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First, Expr *Second)
Build a new overloaded operator call expression.
OMPClause * RebuildOMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_addr' clause.
QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc)
Build a dependent bit-precise int given its value type.
OMPClause * RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'hint' clause.
Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind)
Transform the specified condition.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name, SourceLocation NameLoc, QualType ObjectType, NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the name that is referred to as a templat...
OMPClause * RebuildOMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'severity' clause.
OMPClause * RebuildOMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'firstprivate' clause.
StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef< Token > AsmToks, StringRef AsmString, unsigned NumOutputs, unsigned NumInputs, ArrayRef< StringRef > Constraints, ArrayRef< StringRef > Clobbers, ArrayRef< Expr * > Exprs, SourceLocation EndLoc)
Build a new MS style inline asm statement.
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, TemplateName Template)
VarDecl * RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *TInfo, QualType T)
Rebuild an Objective-C exception declaration.
concepts::NestedRequirement * TransformNestedRequirement(concepts::NestedRequirement *Req)
QualType RebuildConstantArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new constant array type given the element type, size modifier, (known) size of the array,...
ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > BracketsRanges)
Build a new array shaping expression.
ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, bool IsGlobalDelete, bool IsArrayForm, Expr *Operand)
Build a new C++ "delete" expression.
bool TransformExceptionSpec(SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, SmallVectorImpl< QualType > &Exceptions, bool &Changed)
QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, SourceLocation StartLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParenLoc)
Build a new array type trait expression.
OMPClause * RebuildOMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'is_device_ptr' clause.
QualType RebuildMacroQualifiedType(QualType T, const IdentifierInfo *MacroII)
Build a new MacroDefined type.
concepts::NestedRequirement * RebuildNestedRequirement(Expr *Constraint)
ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBracketLoc)
Build a new matrix subscript expression.
ExprResult TransformParenDependentScopeDeclRefExpr(ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
TemplateParameterList * TransformTemplateParameterList(TemplateParameterList *TPL)
QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the class type it refers into.
void transformAttrs(Decl *Old, Decl *New)
Transform the attributes associated with the given declaration and place them on the new declaration.
Decl * TransformDecl(SourceLocation Loc, Decl *D)
Transform the given declaration, which is referenced from a type or expression.
bool AlwaysRebuild()
Whether the transformation should always rebuild AST nodes, even if none of the children have changed...
ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, QualType SuperType, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance/class message to 'super'.
OMPClause * RebuildOMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'lastprivate' clause.
QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, VectorKind)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
bool AllowSkippingCXXConstructExpr()
Wether CXXConstructExpr can be skipped when they are implicit.
OMPClause * RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'safelen' clause.
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, SourceLocation RParenLoc)
Start building a new switch statement.
StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new default statement.
StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParenLoc, VarDecl *Var, Stmt *Body)
Build a new Objective-C @catch statement.
OMPClause * RebuildOMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'filter' clause.
ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, SourceLocation OperatorLoc, bool isArrow, CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage Destroyed)
Build a new pseudo-destructor expression.
QualType RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Build a new pack expansion type.
QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits, SourceLocation Loc)
Build a bit-precise int given its value type.
ExprResult RebuildObjCArrayLiteral(SourceRange Range, Expr **Elements, unsigned NumElements)
Build a new Objective-C array literal.
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(type) expression.
ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, SourceLocation OperatorLoc, bool IsArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
OMPClause * RebuildOMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'bind' clause.
concepts::NestedRequirement * RebuildNestedRequirement(StringRef InvalidConstraintEntity, const ASTConstraintSatisfaction &Satisfaction)
OMPClause * RebuildOMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyprivate' clause.
QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, ConceptDecl *TypeConstraintConcept, ArrayRef< TemplateArgument > TypeConstraintArgs)
Build a new C++11 auto type.
QualType RebuildVariableArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new variable-length array type given the element type, size modifier, size expression,...
ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ dynamic_cast expression.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, TypeSourceInfo *ControllingType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with a type predicate.
QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new pointer type given its pointee type.
concepts::TypeRequirement * RebuildTypeRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag)
OMPClause * RebuildOMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'permutation' clause.
OMPClause * RebuildOMPUsesAllocatorsClause(ArrayRef< SemaOpenMP::UsesAllocatorsData > Data, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'uses_allocators' clause.
ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool ConstructsVBase, bool InheritedFromVBase)
Build a new implicit construction via inherited constructor expression.
ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ const_cast expression.
ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, AtomicExpr::AtomicOp Op, SourceLocation RParenLoc)
Build a new atomic operation expression.
DeclarationNameInfo TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Transform the given declaration name.
OMPClause * RebuildOMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_attribute' clause.
ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, std::optional< unsigned > NumExpansions)
Build a new C++1z fold-expression.
OMPClause * RebuildOMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'to' clause.
StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation LParenLoc, Expr *Cond, SourceLocation RParenLoc)
Build a new do-while statement.
OMPClause * RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'if' clause.
StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body)
Attach the body to a new case statement.
ExprResult RebuildTypeTrait(TypeTrait Trait, SourceLocation StartLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
Build a new type trait expression.
ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
Build an empty C++1z fold-expression with the given operator.
QualType TransformTypeWithDeducedTST(QualType T)
Transform a type that is permitted to produce a DeducedTemplateSpecializationType.
OMPClause * RebuildOMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'init' clause.
OMPClause * RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'detach' clause.
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, MultiStmtArg Statements, SourceLocation RBraceLoc, bool IsStmtExpr)
Build a new compound statement.
ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, ValueDecl *VD, const DeclarationNameInfo &NameInfo, NamedDecl *Found, TemplateArgumentListInfo *TemplateArgs)
Build a new expression that references a declaration.
QualType RebuildArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new array type given the element type, size modifier, size of the array (if known),...
StmtResult RebuildDeclStmt(MutableArrayRef< Decl * > Decls, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new declaration statement.
QualType RebuildUsingType(UsingShadowDecl *Found, QualType Underlying)
Build a new type found via an alias.
ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, Expr *SrcExpr, TypeSourceInfo *DstTInfo, SourceLocation RParenLoc)
Build a new convert vector expression.
QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL)
Build a new qualified type given its unqualified type and type location.
OMPClause * RebuildOMPDependClause(OMPDependClause::DependDataTy Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depend' pseudo clause.
OMPClause * RebuildOMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'aligned' clause.
unsigned TransformTemplateDepth(unsigned Depth)
Transform a template parameter depth level.
QualType RebuildFunctionNoProtoType(QualType ResultType)
Build a new unprototyped function type.
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals, Fn TransformExceptionSpec)
const Attr * TransformAttr(const Attr *S)
Transform the given attribute.
QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns)
Build a new matrix type given the element type and dimensions.
OMPClause * RebuildOMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'map' clause.
ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Sub, SourceLocation RParenLoc)
Build a new C++ __builtin_bit_cast expression.
QualType RebuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted, ArrayRef< QualType > Expansions={})
StmtResult RebuildOMPCanonicalLoop(Stmt *LoopStmt)
Build a new OpenMP Canonical loop.
StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP executable directive.
concepts::ExprRequirement * RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
OMPClause * RebuildOMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'full' clause.
StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
OMPClause * RebuildOMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Build a new OpenMP 'affinity' clause.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(type) expression.
TypeSourceInfo * TransformTypeWithDeducedTST(TypeSourceInfo *DI)
ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, Stmt::StmtClass Class, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ "named" cast expression, such as static_cast or reinterpret_cast.
StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Attach the body to the switch statement.
TypeSourceInfo * InventTypeSourceInfo(QualType T)
Fakes up a TypeSourceInfo for a type.
ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec_step expression with a type argument.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with an expression predicate.
QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool SuppressObjCLifetime)
Derived & getDerived()
Retrieves a reference to the derived class.
OMPClause * RebuildOMPHoldsClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'holds' clause.
ExprResult RebuildArraySectionExpr(bool IsOMPArraySection, Expr *Base, SourceLocation LBracketLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBracketLoc)
Build a new array section expression.
concepts::ExprRequirement * TransformExprRequirement(concepts::ExprRequirement *Req)
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc, TypeOfKind Kind)
Build a new typeof(expr) type.
ParmVarDecl * TransformFunctionTypeParam(ParmVarDecl *OldParm, int indexAdjustment, std::optional< unsigned > NumExpansions, bool ExpectParameterPack)
Transforms a single function-type parameter.
bool ReplacingOriginal()
Whether the transformation is forming an expression or statement that replaces the original.
OMPClause * RebuildOMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'flush' pseudo clause.
bool TransformTemplateArgument(const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, bool Uneval=false)
Transform the given template argument.
QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, QualType Deduced)
By default, builds a new DeducedTemplateSpecializationType with the given deduced type.
ExprResult RebuildArraySubscriptExpr(Expr *LHS, SourceLocation LBracketLoc, Expr *RHS, SourceLocation RBracketLoc)
Build a new array subscript expression.
QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, SourceLocation AttributeLoc)
Build a new extended vector type given the element type and number of elements.
void transformedLocalDecl(Decl *Old, ArrayRef< Decl * > New)
Note that a local declaration has been transformed by this transformer.
ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
Build a new Objective-C boxed expression.
ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, bool IsThrownVariableInScope)
Build a new C++ throw expression.
bool TransformRequiresExprRequirements(ArrayRef< concepts::Requirement * > Reqs, llvm::SmallVectorImpl< concepts::Requirement * > &Transformed)
bool DropCallArgument(Expr *E)
Determine whether the given call argument should be dropped, e.g., because it is a default argument.
StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new goto statement.
OMPClause * RebuildOMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'private' clause.
ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation ClosingBraceLoc)
Build a new requires expression.
ExprResult RebuildExpressionTrait(ExpressionTrait Trait, SourceLocation StartLoc, Expr *Queried, SourceLocation RParenLoc)
Build a new expression trait expression.
OMPClause * RebuildOMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'doacross' clause.
OMPClause * RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'final' clause.
StmtResult RebuildIfStmt(SourceLocation IfLoc, IfStatementKind Kind, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Init, Stmt *Then, SourceLocation ElseLoc, Stmt *Else)
Build a new "if" statement.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
void TypeWasModifiedSafely(QualType T)
Tell the TypeLocBuilder that the type it is storing has been modified in some safe way that doesn't a...
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
Definition: TypeLoc.h:338
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:133
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:89
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
Definition: TypeLoc.h:78
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:153
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition: TypeLoc.h:164
SourceLocation getTemplateKeywordLoc() const
Get the SourceLocation of the template keyword (if any).
Definition: TypeLoc.cpp:756
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:2715
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
A container of type source information.
Definition: Type.h:7902
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7913
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:3213
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:6901
The base class of the type hierarchy.
Definition: Type.h:1828
bool isPointerType() const
Definition: Type.h:8186
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8800
bool isReferenceType() const
Definition: Type.h:8204
bool isEnumeralType() const
Definition: Type.h:8290
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:738
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2811
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2706
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2361
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: Type.h:8651
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:5048
bool isFunctionType() const
Definition: Type.h:8182
bool isObjCObjectPointerType() const
Definition: Type.h:8328
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
bool isRecordType() const
Definition: Type.h:8286
Base class for declarations which introduce a typedef-name.
Definition: Decl.h: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:1409
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:1028
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3203
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:3277
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:3272
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition: ExprCXX.cpp:419
A set of unresolved declarations.
Definition: UnresolvedSet.h:62
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:92
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5667
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h: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:6871
bool transformOMPMappableExprListClause(TreeTransform< Derived > &TT, OMPMappableExprListClause< T > *C, llvm::SmallVectorImpl< Expr * > &Vars, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperIdInfo, llvm::SmallVectorImpl< Expr * > &UnresolvedMappers)
ExprResult ExprError()
Definition: Ownership.h:264
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
Definition: Diagnostic.h:1488
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
Definition: OpenMPKinds.h:143
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:249
OpenMPDefaultmapClauseKind
OpenMP attributes for 'defaultmap' clause.
Definition: OpenMPKinds.h:111
OpenMPAllocateClauseModifier
OpenMP modifiers for 'allocate' clause.
Definition: OpenMPKinds.h:227
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition: OpenMPKinds.h:63
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:135
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:139
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition: Ownership.h:229
const FunctionProtoType * T
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
Definition: Sema.h: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:6846
@ None
No keyword precedes the qualified type name.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
OpenMPOrderClauseKind
OpenMP attributes for 'order' clause.
Definition: OpenMPKinds.h:165
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
@ Parens
New-expression has a C++98 paren-delimited initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DynamicNone
throw()
@ EST_Uninstantiated
not instantiated yet
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_Dynamic
throw(T1, T2)
PredefinedIdentKind
Definition: Expr.h:1975
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition: OpenMPKinds.h:31
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:258
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition: OpenMPKinds.h:71
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:89
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition: Type.h:4840
EffectConditionExpr Cond
Definition: Type.h:4842
Holds information about the various types of exception specification.
Definition: Type.h:5159
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:5175
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5161
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5164
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:5167
Extra information about a function prototype.
Definition: Type.h:5187
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5194
FunctionEffectsRef FunctionEffects
Definition: Type.h:5197
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:5195
This structure contains most locations needed for by an OMPVarListClause.
Definition: OpenMPClause.h:259
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition: Sema.h:12691
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:2810
Location information for a TemplateArgument.
Definition: TemplateBase.h:472