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
117 public:
118 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
119 Old = Self.ForgetPartiallySubstitutedPack();
120 }
121
122 ~ForgetPartiallySubstitutedPackRAII() {
123 Self.RememberPartiallySubstitutedPack(Old);
124 }
125 };
126
127protected:
129
130 /// The set of local declarations that have been transformed, for
131 /// cases where we are forced to build new declarations within the transformer
132 /// rather than in the subclass (e.g., lambda closure types).
133 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
134
135public:
136 /// Initializes a new tree transformer.
138
139 /// Retrieves a reference to the derived class.
140 Derived &getDerived() { return static_cast<Derived&>(*this); }
141
142 /// Retrieves a reference to the derived class.
143 const Derived &getDerived() const {
144 return static_cast<const Derived&>(*this);
145 }
146
147 static inline ExprResult Owned(Expr *E) { return E; }
148 static inline StmtResult Owned(Stmt *S) { return S; }
149
150 /// Retrieves a reference to the semantic analysis object used for
151 /// this tree transform.
152 Sema &getSema() const { return SemaRef; }
153
154 /// Whether the transformation should always rebuild AST nodes, even
155 /// if none of the children have changed.
156 ///
157 /// Subclasses may override this function to specify when the transformation
158 /// should rebuild all AST nodes.
159 ///
160 /// We must always rebuild all AST nodes when performing variadic template
161 /// pack expansion, in order to avoid violating the AST invariant that each
162 /// statement node appears at most once in its containing declaration.
164
165 /// Whether the transformation is forming an expression or statement that
166 /// replaces the original. In this case, we'll reuse mangling numbers from
167 /// existing lambdas.
168 bool ReplacingOriginal() { return false; }
169
170 /// Wether CXXConstructExpr can be skipped when they are implicit.
171 /// They will be reconstructed when used if needed.
172 /// This is useful when the user that cause rebuilding of the
173 /// CXXConstructExpr is outside of the expression at which the TreeTransform
174 /// started.
175 bool AllowSkippingCXXConstructExpr() { return true; }
176
177 /// Returns the location of the entity being transformed, if that
178 /// information was not available elsewhere in the AST.
179 ///
180 /// By default, returns no source-location information. Subclasses can
181 /// provide an alternative implementation that provides better location
182 /// information.
184
185 /// Returns the name of the entity being transformed, if that
186 /// information was not available elsewhere in the AST.
187 ///
188 /// By default, returns an empty name. Subclasses can provide an alternative
189 /// implementation with a more precise name.
191
192 /// Sets the "base" location and entity when that
193 /// information is known based on another transformation.
194 ///
195 /// By default, the source location and entity are ignored. Subclasses can
196 /// override this function to provide a customized implementation.
198
199 /// RAII object that temporarily sets the base location and entity
200 /// used for reporting diagnostics in types.
202 TreeTransform &Self;
203 SourceLocation OldLocation;
204 DeclarationName OldEntity;
205
206 public:
208 DeclarationName Entity) : Self(Self) {
209 OldLocation = Self.getDerived().getBaseLocation();
210 OldEntity = Self.getDerived().getBaseEntity();
211
212 if (Location.isValid())
213 Self.getDerived().setBase(Location, Entity);
214 }
215
217 Self.getDerived().setBase(OldLocation, OldEntity);
218 }
219 };
220
221 /// Determine whether the given type \p T has already been
222 /// transformed.
223 ///
224 /// Subclasses can provide an alternative implementation of this routine
225 /// to short-circuit evaluation when it is known that a given type will
226 /// not change. For example, template instantiation need not traverse
227 /// non-dependent types.
229 return T.isNull();
230 }
231
232 /// Transform a template parameter depth level.
233 ///
234 /// During a transformation that transforms template parameters, this maps
235 /// an old template parameter depth to a new depth.
236 unsigned TransformTemplateDepth(unsigned Depth) {
237 return Depth;
238 }
239
240 /// Determine whether the given call argument should be dropped, e.g.,
241 /// because it is a default argument.
242 ///
243 /// Subclasses can provide an alternative implementation of this routine to
244 /// determine which kinds of call arguments get dropped. By default,
245 /// CXXDefaultArgument nodes are dropped (prior to transformation).
247 return E->isDefaultArgument();
248 }
249
250 /// Determine whether we should expand a pack expansion with the
251 /// given set of parameter packs into separate arguments by repeatedly
252 /// transforming the pattern.
253 ///
254 /// By default, the transformer never tries to expand pack expansions.
255 /// Subclasses can override this routine to provide different behavior.
256 ///
257 /// \param EllipsisLoc The location of the ellipsis that identifies the
258 /// pack expansion.
259 ///
260 /// \param PatternRange The source range that covers the entire pattern of
261 /// the pack expansion.
262 ///
263 /// \param Unexpanded The set of unexpanded parameter packs within the
264 /// pattern.
265 ///
266 /// \param ShouldExpand Will be set to \c true if the transformer should
267 /// expand the corresponding pack expansions into separate arguments. When
268 /// set, \c NumExpansions must also be set.
269 ///
270 /// \param RetainExpansion Whether the caller should add an unexpanded
271 /// pack expansion after all of the expanded arguments. This is used
272 /// when extending explicitly-specified template argument packs per
273 /// C++0x [temp.arg.explicit]p9.
274 ///
275 /// \param NumExpansions The number of separate arguments that will be in
276 /// the expanded form of the corresponding pack expansion. This is both an
277 /// input and an output parameter, which can be set by the caller if the
278 /// number of expansions is known a priori (e.g., due to a prior substitution)
279 /// and will be set by the callee when the number of expansions is known.
280 /// The callee must set this value when \c ShouldExpand is \c true; it may
281 /// set this value in other cases.
282 ///
283 /// \returns true if an error occurred (e.g., because the parameter packs
284 /// are to be instantiated with arguments of different lengths), false
285 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
286 /// must be set.
288 SourceRange PatternRange,
290 bool &ShouldExpand, bool &RetainExpansion,
291 std::optional<unsigned> &NumExpansions) {
292 ShouldExpand = false;
293 return false;
294 }
295
296 /// "Forget" about the partially-substituted pack template argument,
297 /// when performing an instantiation that must preserve the parameter pack
298 /// use.
299 ///
300 /// This routine is meant to be overridden by the template instantiator.
302 return TemplateArgument();
303 }
304
305 /// "Remember" the partially-substituted pack template argument
306 /// after performing an instantiation that must preserve the parameter pack
307 /// use.
308 ///
309 /// This routine is meant to be overridden by the template instantiator.
311
312 /// Note to the derived class when a function parameter pack is
313 /// being expanded.
315
316 /// Transforms the given type into another type.
317 ///
318 /// By default, this routine transforms a type by creating a
319 /// TypeSourceInfo for it and delegating to the appropriate
320 /// function. This is expensive, but we don't mind, because
321 /// this method is deprecated anyway; all users should be
322 /// switched to storing TypeSourceInfos.
323 ///
324 /// \returns the transformed type.
326
327 /// Transforms the given type-with-location into a new
328 /// type-with-location.
329 ///
330 /// By default, this routine transforms a type by delegating to the
331 /// appropriate TransformXXXType to build a new type. Subclasses
332 /// may override this function (to take over all type
333 /// transformations) or some set of the TransformXXXType functions
334 /// to alter the transformation.
336
337 /// Transform the given type-with-location into a new
338 /// type, collecting location information in the given builder
339 /// as necessary.
340 ///
342
343 /// Transform a type that is permitted to produce a
344 /// DeducedTemplateSpecializationType.
345 ///
346 /// This is used in the (relatively rare) contexts where it is acceptable
347 /// for transformation to produce a class template type with deduced
348 /// template arguments.
349 /// @{
352 /// @}
353
354 /// The reason why the value of a statement is not discarded, if any.
359 };
360
361 /// Transform the given statement.
362 ///
363 /// By default, this routine transforms a statement by delegating to the
364 /// appropriate TransformXXXStmt function to transform a specific kind of
365 /// statement or the TransformExpr() function to transform an expression.
366 /// Subclasses may override this function to transform statements using some
367 /// other mechanism.
368 ///
369 /// \returns the transformed statement.
371
372 /// Transform the given statement.
373 ///
374 /// By default, this routine transforms a statement by delegating to the
375 /// appropriate TransformOMPXXXClause function to transform a specific kind
376 /// of clause. Subclasses may override this function to transform statements
377 /// using some other mechanism.
378 ///
379 /// \returns the transformed OpenMP clause.
381
382 /// Transform the given attribute.
383 ///
384 /// By default, this routine transforms a statement by delegating to the
385 /// appropriate TransformXXXAttr function to transform a specific kind
386 /// of attribute. Subclasses may override this function to transform
387 /// attributed statements/types using some other mechanism.
388 ///
389 /// \returns the transformed attribute
390 const Attr *TransformAttr(const Attr *S);
391
392 // Transform the given statement attribute.
393 //
394 // Delegates to the appropriate TransformXXXAttr function to transform a
395 // specific kind of statement attribute. Unlike the non-statement taking
396 // version of this, this implements all attributes, not just pragmas.
397 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
398 const Attr *A);
399
400 // Transform the specified attribute.
401 //
402 // Subclasses should override the transformation of attributes with a pragma
403 // spelling to transform expressions stored within the attribute.
404 //
405 // \returns the transformed attribute.
406#define ATTR(X) \
407 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
408#include "clang/Basic/AttrList.inc"
409
410 // Transform the specified attribute.
411 //
412 // Subclasses should override the transformation of attributes to do
413 // transformation and checking of statement attributes. By default, this
414 // delegates to the non-statement taking version.
415 //
416 // \returns the transformed attribute.
417#define ATTR(X) \
418 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
419 const X##Attr *A) { \
420 return getDerived().Transform##X##Attr(A); \
421 }
422#include "clang/Basic/AttrList.inc"
423
424 /// Transform the given expression.
425 ///
426 /// By default, this routine transforms an expression by delegating to the
427 /// appropriate TransformXXXExpr function to build a new expression.
428 /// Subclasses may override this function to transform expressions using some
429 /// other mechanism.
430 ///
431 /// \returns the transformed expression.
433
434 /// Transform the given initializer.
435 ///
436 /// By default, this routine transforms an initializer by stripping off the
437 /// semantic nodes added by initialization, then passing the result to
438 /// TransformExpr or TransformExprs.
439 ///
440 /// \returns the transformed initializer.
442
443 /// Transform the given list of expressions.
444 ///
445 /// This routine transforms a list of expressions by invoking
446 /// \c TransformExpr() for each subexpression. However, it also provides
447 /// support for variadic templates by expanding any pack expansions (if the
448 /// derived class permits such expansion) along the way. When pack expansions
449 /// are present, the number of outputs may not equal the number of inputs.
450 ///
451 /// \param Inputs The set of expressions to be transformed.
452 ///
453 /// \param NumInputs The number of expressions in \c Inputs.
454 ///
455 /// \param IsCall If \c true, then this transform is being performed on
456 /// function-call arguments, and any arguments that should be dropped, will
457 /// be.
458 ///
459 /// \param Outputs The transformed input expressions will be added to this
460 /// vector.
461 ///
462 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
463 /// due to transformation.
464 ///
465 /// \returns true if an error occurred, false otherwise.
466 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
468 bool *ArgChanged = nullptr);
469
470 /// Transform the given declaration, which is referenced from a type
471 /// or expression.
472 ///
473 /// By default, acts as the identity function on declarations, unless the
474 /// transformer has had to transform the declaration itself. Subclasses
475 /// may override this function to provide alternate behavior.
477 llvm::DenseMap<Decl *, Decl *>::iterator Known
478 = TransformedLocalDecls.find(D);
479 if (Known != TransformedLocalDecls.end())
480 return Known->second;
481
482 return D;
483 }
484
485 /// Transform the specified condition.
486 ///
487 /// By default, this transforms the variable and expression and rebuilds
488 /// the condition.
490 Expr *Expr,
492
493 /// Transform the attributes associated with the given declaration and
494 /// place them on the new declaration.
495 ///
496 /// By default, this operation does nothing. Subclasses may override this
497 /// behavior to transform attributes.
498 void transformAttrs(Decl *Old, Decl *New) { }
499
500 /// Note that a local declaration has been transformed by this
501 /// transformer.
502 ///
503 /// Local declarations are typically transformed via a call to
504 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
505 /// the transformer itself has to transform the declarations. This routine
506 /// can be overridden by a subclass that keeps track of such mappings.
508 assert(New.size() == 1 &&
509 "must override transformedLocalDecl if performing pack expansion");
510 TransformedLocalDecls[Old] = New.front();
511 }
512
513 /// Transform the definition of the given declaration.
514 ///
515 /// By default, invokes TransformDecl() to transform the declaration.
516 /// Subclasses may override this function to provide alternate behavior.
518 return getDerived().TransformDecl(Loc, D);
519 }
520
521 /// Transform the given declaration, which was the first part of a
522 /// nested-name-specifier in a member access expression.
523 ///
524 /// This specific declaration transformation only applies to the first
525 /// identifier in a nested-name-specifier of a member access expression, e.g.,
526 /// the \c T in \c x->T::member
527 ///
528 /// By default, invokes TransformDecl() to transform the declaration.
529 /// Subclasses may override this function to provide alternate behavior.
531 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
532 }
533
534 /// Transform the set of declarations in an OverloadExpr.
535 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
536 LookupResult &R);
537
538 /// Transform the given nested-name-specifier with source-location
539 /// information.
540 ///
541 /// By default, transforms all of the types and declarations within the
542 /// nested-name-specifier. Subclasses may override this function to provide
543 /// alternate behavior.
546 QualType ObjectType = QualType(),
547 NamedDecl *FirstQualifierInScope = nullptr);
548
549 /// Transform the given declaration name.
550 ///
551 /// By default, transforms the types of conversion function, constructor,
552 /// and destructor names and then (if needed) rebuilds the declaration name.
553 /// Identifiers and selectors are returned unmodified. Subclasses may
554 /// override this function to provide alternate behavior.
557
567
568 /// Transform the given template name.
569 ///
570 /// \param SS The nested-name-specifier that qualifies the template
571 /// name. This nested-name-specifier must already have been transformed.
572 ///
573 /// \param Name The template name to transform.
574 ///
575 /// \param NameLoc The source location of the template name.
576 ///
577 /// \param ObjectType If we're translating a template name within a member
578 /// access expression, this is the type of the object whose member template
579 /// is being referenced.
580 ///
581 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
582 /// also refers to a name within the current (lexical) scope, this is the
583 /// declaration it refers to.
584 ///
585 /// By default, transforms the template name by transforming the declarations
586 /// and nested-name-specifiers that occur within the template name.
587 /// Subclasses may override this function to provide alternate behavior.
590 SourceLocation NameLoc,
591 QualType ObjectType = QualType(),
592 NamedDecl *FirstQualifierInScope = nullptr,
593 bool AllowInjectedClassName = false);
594
595 /// Transform the given template argument.
596 ///
597 /// By default, this operation transforms the type, expression, or
598 /// declaration stored within the template argument and constructs a
599 /// new template argument from the transformed result. Subclasses may
600 /// override this function to provide alternate behavior.
601 ///
602 /// Returns true if there was an error.
604 TemplateArgumentLoc &Output,
605 bool Uneval = false);
606
607 /// Transform the given set of template arguments.
608 ///
609 /// By default, this operation transforms all of the template arguments
610 /// in the input set using \c TransformTemplateArgument(), and appends
611 /// the transformed arguments to the output list.
612 ///
613 /// Note that this overload of \c TransformTemplateArguments() is merely
614 /// a convenience function. Subclasses that wish to override this behavior
615 /// should override the iterator-based member template version.
616 ///
617 /// \param Inputs The set of template arguments to be transformed.
618 ///
619 /// \param NumInputs The number of template arguments in \p Inputs.
620 ///
621 /// \param Outputs The set of transformed template arguments output by this
622 /// routine.
623 ///
624 /// Returns true if an error occurred.
626 unsigned NumInputs,
628 bool Uneval = false) {
629 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
630 Uneval);
631 }
632
633 /// Transform the given set of template arguments.
634 ///
635 /// By default, this operation transforms all of the template arguments
636 /// in the input set using \c TransformTemplateArgument(), and appends
637 /// the transformed arguments to the output list.
638 ///
639 /// \param First An iterator to the first template argument.
640 ///
641 /// \param Last An iterator one step past the last template argument.
642 ///
643 /// \param Outputs The set of transformed template arguments output by this
644 /// routine.
645 ///
646 /// Returns true if an error occurred.
647 template<typename InputIterator>
649 InputIterator Last,
651 bool Uneval = false);
652
653 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
655 TemplateArgumentLoc &ArgLoc);
656
657 /// Fakes up a TypeSourceInfo for a type.
661 }
662
663#define ABSTRACT_TYPELOC(CLASS, PARENT)
664#define TYPELOC(CLASS, PARENT) \
665 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
666#include "clang/AST/TypeLocNodes.def"
667
670 bool SuppressObjCLifetime);
674 bool SuppressObjCLifetime);
675
676 template<typename Fn>
679 CXXRecordDecl *ThisContext,
680 Qualifiers ThisTypeQuals,
682
683 template <typename Fn>
685 Fn TransformModifiedType);
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
806// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
807// amount of stack usage with clang.
808#define STMT(Node, Parent) \
809 LLVM_ATTRIBUTE_NOINLINE \
810 StmtResult Transform##Node(Node *S);
811#define VALUESTMT(Node, Parent) \
812 LLVM_ATTRIBUTE_NOINLINE \
813 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
814#define EXPR(Node, Parent) \
815 LLVM_ATTRIBUTE_NOINLINE \
816 ExprResult Transform##Node(Node *E);
817#define ABSTRACT_STMT(Stmt)
818#include "clang/AST/StmtNodes.inc"
819
820#define GEN_CLANG_CLAUSE_CLASS
821#define CLAUSE_CLASS(Enum, Str, Class) \
822 LLVM_ATTRIBUTE_NOINLINE \
823 OMPClause *Transform##Class(Class *S);
824#include "llvm/Frontend/OpenMP/OMP.inc"
825
826 /// Build a new qualified type given its unqualified type and type location.
827 ///
828 /// By default, this routine adds type qualifiers only to types that can
829 /// have qualifiers, and silently suppresses those qualifiers that are not
830 /// permitted. Subclasses may override this routine to provide different
831 /// behavior.
833
834 /// Build a new pointer type given its pointee type.
835 ///
836 /// By default, performs semantic analysis when building the pointer type.
837 /// Subclasses may override this routine to provide different behavior.
839
840 /// Build a new block pointer type given its pointee type.
841 ///
842 /// By default, performs semantic analysis when building the block pointer
843 /// type. Subclasses may override this routine to provide different behavior.
845
846 /// Build a new reference type given the type it references.
847 ///
848 /// By default, performs semantic analysis when building the
849 /// reference type. Subclasses may override this routine to provide
850 /// different behavior.
851 ///
852 /// \param LValue whether the type was written with an lvalue sigil
853 /// or an rvalue sigil.
855 bool LValue,
856 SourceLocation Sigil);
857
858 /// Build a new member pointer type given the pointee type and the
859 /// class type it refers into.
860 ///
861 /// By default, performs semantic analysis when building the member pointer
862 /// type. Subclasses may override this routine to provide different behavior.
864 SourceLocation Sigil);
865
867 SourceLocation ProtocolLAngleLoc,
869 ArrayRef<SourceLocation> ProtocolLocs,
870 SourceLocation ProtocolRAngleLoc);
871
872 /// Build an Objective-C object type.
873 ///
874 /// By default, performs semantic analysis when building the object type.
875 /// Subclasses may override this routine to provide different behavior.
878 SourceLocation TypeArgsLAngleLoc,
880 SourceLocation TypeArgsRAngleLoc,
881 SourceLocation ProtocolLAngleLoc,
883 ArrayRef<SourceLocation> ProtocolLocs,
884 SourceLocation ProtocolRAngleLoc);
885
886 /// Build a new Objective-C object pointer type given the pointee type.
887 ///
888 /// By default, directly builds the pointer type, with no additional semantic
889 /// analysis.
892
893 /// Build a new array type given the element type, size
894 /// modifier, size of the array (if known), size expression, and index type
895 /// qualifiers.
896 ///
897 /// By default, performs semantic analysis when building the array type.
898 /// Subclasses may override this routine to provide different behavior.
899 /// Also by default, all of the other Rebuild*Array
901 const llvm::APInt *Size, Expr *SizeExpr,
902 unsigned IndexTypeQuals, SourceRange BracketsRange);
903
904 /// Build a new constant array type given the element type, size
905 /// modifier, (known) size of the array, and index type qualifiers.
906 ///
907 /// By default, performs semantic analysis when building the array type.
908 /// Subclasses may override this routine to provide different behavior.
910 ArraySizeModifier SizeMod,
911 const llvm::APInt &Size, Expr *SizeExpr,
912 unsigned IndexTypeQuals,
913 SourceRange BracketsRange);
914
915 /// Build a new incomplete array type given the element type, size
916 /// modifier, and index type qualifiers.
917 ///
918 /// By default, performs semantic analysis when building the array type.
919 /// Subclasses may override this routine to provide different behavior.
921 ArraySizeModifier SizeMod,
922 unsigned IndexTypeQuals,
923 SourceRange BracketsRange);
924
925 /// Build a new variable-length array type given the element type,
926 /// size modifier, size expression, and index type qualifiers.
927 ///
928 /// By default, performs semantic analysis when building the array type.
929 /// Subclasses may override this routine to provide different behavior.
931 ArraySizeModifier SizeMod, Expr *SizeExpr,
932 unsigned IndexTypeQuals,
933 SourceRange BracketsRange);
934
935 /// Build a new dependent-sized array type given the element type,
936 /// size modifier, size expression, and index type qualifiers.
937 ///
938 /// By default, performs semantic analysis when building the array type.
939 /// Subclasses may override this routine to provide different behavior.
941 ArraySizeModifier SizeMod,
942 Expr *SizeExpr,
943 unsigned IndexTypeQuals,
944 SourceRange BracketsRange);
945
946 /// Build a new vector type given the element type and
947 /// number of elements.
948 ///
949 /// By default, performs semantic analysis when building the vector type.
950 /// Subclasses may override this routine to provide different behavior.
951 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
952 VectorKind VecKind);
953
954 /// Build a new potentially dependently-sized extended vector type
955 /// given the element type and number of elements.
956 ///
957 /// By default, performs semantic analysis when building the vector type.
958 /// Subclasses may override this routine to provide different behavior.
960 SourceLocation AttributeLoc, VectorKind);
961
962 /// Build a new extended vector type given the element type and
963 /// number of elements.
964 ///
965 /// By default, performs semantic analysis when building the vector type.
966 /// Subclasses may override this routine to provide different behavior.
967 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
968 SourceLocation AttributeLoc);
969
970 /// Build a new potentially dependently-sized extended vector type
971 /// given the element type and number of elements.
972 ///
973 /// By default, performs semantic analysis when building the vector type.
974 /// Subclasses may override this routine to provide different behavior.
976 Expr *SizeExpr,
977 SourceLocation AttributeLoc);
978
979 /// Build a new matrix type given the element type and dimensions.
980 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
981 unsigned NumColumns);
982
983 /// Build a new matrix type given the type and dependently-defined
984 /// dimensions.
986 Expr *ColumnExpr,
987 SourceLocation AttributeLoc);
988
989 /// Build a new DependentAddressSpaceType or return the pointee
990 /// type variable with the correct address space (retrieved from
991 /// AddrSpaceExpr) applied to it. The former will be returned in cases
992 /// where the address space remains dependent.
993 ///
994 /// By default, performs semantic analysis when building the type with address
995 /// space applied. Subclasses may override this routine to provide different
996 /// behavior.
998 Expr *AddrSpaceExpr,
999 SourceLocation AttributeLoc);
1000
1001 /// Build a new function type.
1002 ///
1003 /// By default, performs semantic analysis when building the function type.
1004 /// Subclasses may override this routine to provide different behavior.
1006 MutableArrayRef<QualType> ParamTypes,
1008
1009 /// Build a new unprototyped function type.
1011
1012 /// Rebuild an unresolved typename type, given the decl that
1013 /// the UnresolvedUsingTypenameDecl was transformed to.
1015
1016 /// Build a new type found via an alias.
1018 return SemaRef.Context.getUsingType(Found, Underlying);
1019 }
1020
1021 /// Build a new typedef type.
1023 return SemaRef.Context.getTypeDeclType(Typedef);
1024 }
1025
1026 /// Build a new MacroDefined type.
1028 const IdentifierInfo *MacroII) {
1029 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1030 }
1031
1032 /// Build a new class/struct/union type.
1035 }
1036
1037 /// Build a new Enum type.
1040 }
1041
1042 /// Build a new typeof(expr) type.
1043 ///
1044 /// By default, performs semantic analysis when building the typeof type.
1045 /// Subclasses may override this routine to provide different behavior.
1047 TypeOfKind Kind);
1048
1049 /// Build a new typeof(type) type.
1050 ///
1051 /// By default, builds a new TypeOfType with the given underlying type.
1053
1054 /// Build a new unary transform type.
1058
1059 /// Build a new C++11 decltype type.
1060 ///
1061 /// By default, performs semantic analysis when building the decltype type.
1062 /// Subclasses may override this routine to provide different behavior.
1064
1067 SourceLocation EllipsisLoc,
1068 bool FullySubstituted,
1069 ArrayRef<QualType> Expansions = {});
1070
1071 /// Build a new C++11 auto type.
1072 ///
1073 /// By default, builds a new AutoType with the given deduced type.
1075 ConceptDecl *TypeConstraintConcept,
1076 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1077 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1078 // which has been deduced to a dependent type into an undeduced 'auto', so
1079 // that we'll retry deduction after the transformation.
1080 return SemaRef.Context.getAutoType(Deduced, Keyword,
1081 /*IsDependent*/ false, /*IsPack=*/false,
1082 TypeConstraintConcept,
1083 TypeConstraintArgs);
1084 }
1085
1086 /// By default, builds a new DeducedTemplateSpecializationType with the given
1087 /// deduced type.
1089 QualType Deduced) {
1091 Template, Deduced, /*IsDependent*/ false);
1092 }
1093
1094 /// Build a new template specialization type.
1095 ///
1096 /// By default, performs semantic analysis when building the template
1097 /// specialization type. Subclasses may override this routine to provide
1098 /// different behavior.
1100 SourceLocation TemplateLoc,
1102
1103 /// Build a new parenthesized type.
1104 ///
1105 /// By default, builds a new ParenType type from the inner type.
1106 /// Subclasses may override this routine to provide different behavior.
1108 return SemaRef.BuildParenType(InnerType);
1109 }
1110
1111 /// Build a new qualified name type.
1112 ///
1113 /// By default, builds a new ElaboratedType type from the keyword,
1114 /// the nested-name-specifier and the named type.
1115 /// Subclasses may override this routine to provide different behavior.
1117 ElaboratedTypeKeyword Keyword,
1118 NestedNameSpecifierLoc QualifierLoc,
1119 QualType Named) {
1120 return SemaRef.Context.getElaboratedType(Keyword,
1121 QualifierLoc.getNestedNameSpecifier(),
1122 Named);
1123 }
1124
1125 /// Build a new typename type that refers to a template-id.
1126 ///
1127 /// By default, builds a new DependentNameType type from the
1128 /// nested-name-specifier and the given type. Subclasses may override
1129 /// this routine to provide different behavior.
1131 ElaboratedTypeKeyword Keyword,
1132 NestedNameSpecifierLoc QualifierLoc,
1133 SourceLocation TemplateKWLoc,
1134 const IdentifierInfo *Name,
1135 SourceLocation NameLoc,
1137 bool AllowInjectedClassName) {
1138 // Rebuild the template name.
1139 // TODO: avoid TemplateName abstraction
1140 CXXScopeSpec SS;
1141 SS.Adopt(QualifierLoc);
1142 TemplateName InstName = getDerived().RebuildTemplateName(
1143 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1144 AllowInjectedClassName);
1145
1146 if (InstName.isNull())
1147 return QualType();
1148
1149 // If it's still dependent, make a dependent specialization.
1150 if (InstName.getAsDependentTemplateName())
1152 Keyword, QualifierLoc.getNestedNameSpecifier(), Name,
1153 Args.arguments());
1154
1155 // Otherwise, make an elaborated type wrapping a non-dependent
1156 // specialization.
1157 QualType T =
1158 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1159 if (T.isNull())
1160 return QualType();
1162 Keyword, QualifierLoc.getNestedNameSpecifier(), T);
1163 }
1164
1165 /// Build a new typename type that refers to an identifier.
1166 ///
1167 /// By default, performs semantic analysis when building the typename type
1168 /// (or elaborated type). Subclasses may override this routine to provide
1169 /// different behavior.
1171 SourceLocation KeywordLoc,
1172 NestedNameSpecifierLoc QualifierLoc,
1173 const IdentifierInfo *Id,
1174 SourceLocation IdLoc,
1175 bool DeducedTSTContext) {
1176 CXXScopeSpec SS;
1177 SS.Adopt(QualifierLoc);
1178
1179 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1180 // If the name is still dependent, just build a new dependent name type.
1181 if (!SemaRef.computeDeclContext(SS))
1182 return SemaRef.Context.getDependentNameType(Keyword,
1183 QualifierLoc.getNestedNameSpecifier(),
1184 Id);
1185 }
1186
1187 if (Keyword == ElaboratedTypeKeyword::None ||
1189 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1190 *Id, IdLoc, DeducedTSTContext);
1191 }
1192
1194
1195 // We had a dependent elaborated-type-specifier that has been transformed
1196 // into a non-dependent elaborated-type-specifier. Find the tag we're
1197 // referring to.
1199 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1200 if (!DC)
1201 return QualType();
1202
1204 return QualType();
1205
1206 TagDecl *Tag = nullptr;
1208 switch (Result.getResultKind()) {
1211 break;
1212
1214 Tag = Result.getAsSingle<TagDecl>();
1215 break;
1216
1219 llvm_unreachable("Tag lookup cannot find non-tags");
1220
1222 // Let the LookupResult structure handle ambiguities.
1223 return QualType();
1224 }
1225
1226 if (!Tag) {
1227 // Check where the name exists but isn't a tag type and use that to emit
1228 // better diagnostics.
1231 switch (Result.getResultKind()) {
1235 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1236 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1237 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1238 << SomeDecl << NTK << llvm::to_underlying(Kind);
1239 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1240 break;
1241 }
1242 default:
1243 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1244 << llvm::to_underlying(Kind) << Id << DC
1245 << QualifierLoc.getSourceRange();
1246 break;
1247 }
1248 return QualType();
1249 }
1250
1251 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1252 IdLoc, Id)) {
1253 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1254 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1255 return QualType();
1256 }
1257
1258 // Build the elaborated-type-specifier type.
1260 return SemaRef.Context.getElaboratedType(Keyword,
1261 QualifierLoc.getNestedNameSpecifier(),
1262 T);
1263 }
1264
1265 /// Build a new pack expansion type.
1266 ///
1267 /// By default, builds a new PackExpansionType type from the given pattern.
1268 /// Subclasses may override this routine to provide different behavior.
1270 SourceLocation EllipsisLoc,
1271 std::optional<unsigned> NumExpansions) {
1272 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1273 NumExpansions);
1274 }
1275
1276 /// Build a new atomic type given its value type.
1277 ///
1278 /// By default, performs semantic analysis when building the atomic type.
1279 /// Subclasses may override this routine to provide different behavior.
1281
1282 /// Build a new pipe type given its value type.
1284 bool isReadPipe);
1285
1286 /// Build a bit-precise int given its value type.
1287 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1289
1290 /// Build a dependent bit-precise int given its value type.
1291 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1293
1294 /// Build a new template name given a nested name specifier, a flag
1295 /// indicating whether the "template" keyword was provided, and the template
1296 /// that the template name refers to.
1297 ///
1298 /// By default, builds the new template name directly. Subclasses may override
1299 /// this routine to provide different behavior.
1301 bool TemplateKW,
1302 TemplateDecl *Template);
1303
1304 /// Build a new template name given a nested name specifier and the
1305 /// name that is referred to as a template.
1306 ///
1307 /// By default, performs semantic analysis to determine whether the name can
1308 /// be resolved to a specific template, then builds the appropriate kind of
1309 /// template name. Subclasses may override this routine to provide different
1310 /// behavior.
1312 SourceLocation TemplateKWLoc,
1313 const IdentifierInfo &Name,
1314 SourceLocation NameLoc, QualType ObjectType,
1315 NamedDecl *FirstQualifierInScope,
1316 bool AllowInjectedClassName);
1317
1318 /// Build a new template name given a nested name specifier and the
1319 /// overloaded operator name that is referred to as a template.
1320 ///
1321 /// By default, performs semantic analysis to determine whether the name can
1322 /// be resolved to a specific template, then builds the appropriate kind of
1323 /// template name. Subclasses may override this routine to provide different
1324 /// behavior.
1326 SourceLocation TemplateKWLoc,
1327 OverloadedOperatorKind Operator,
1328 SourceLocation NameLoc, QualType ObjectType,
1329 bool AllowInjectedClassName);
1330
1331 /// Build a new template name given a template template parameter pack
1332 /// and the
1333 ///
1334 /// By default, performs semantic analysis to determine whether the name can
1335 /// be resolved to a specific template, then builds the appropriate kind of
1336 /// template name. Subclasses may override this routine to provide different
1337 /// behavior.
1339 Decl *AssociatedDecl, unsigned Index,
1340 bool Final) {
1342 ArgPack, AssociatedDecl, Index, Final);
1343 }
1344
1345 /// Build a new compound statement.
1346 ///
1347 /// By default, performs semantic analysis to build the new statement.
1348 /// Subclasses may override this routine to provide different behavior.
1350 MultiStmtArg Statements,
1351 SourceLocation RBraceLoc,
1352 bool IsStmtExpr) {
1353 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1354 IsStmtExpr);
1355 }
1356
1357 /// Build a new case statement.
1358 ///
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
1362 Expr *LHS,
1363 SourceLocation EllipsisLoc,
1364 Expr *RHS,
1365 SourceLocation ColonLoc) {
1366 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1367 ColonLoc);
1368 }
1369
1370 /// Attach the body to a new case statement.
1371 ///
1372 /// By default, performs semantic analysis to build the new statement.
1373 /// Subclasses may override this routine to provide different behavior.
1375 getSema().ActOnCaseStmtBody(S, Body);
1376 return S;
1377 }
1378
1379 /// Build a new default statement.
1380 ///
1381 /// By default, performs semantic analysis to build the new statement.
1382 /// Subclasses may override this routine to provide different behavior.
1384 SourceLocation ColonLoc,
1385 Stmt *SubStmt) {
1386 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1387 /*CurScope=*/nullptr);
1388 }
1389
1390 /// Build a new label statement.
1391 ///
1392 /// By default, performs semantic analysis to build the new statement.
1393 /// Subclasses may override this routine to provide different behavior.
1395 SourceLocation ColonLoc, Stmt *SubStmt) {
1396 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1397 }
1398
1399 /// Build a new attributed statement.
1400 ///
1401 /// By default, performs semantic analysis to build the new statement.
1402 /// Subclasses may override this routine to provide different behavior.
1405 Stmt *SubStmt) {
1407 return StmtError();
1408 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1409 }
1410
1411 /// Build a new "if" statement.
1412 ///
1413 /// By default, performs semantic analysis to build the new statement.
1414 /// Subclasses may override this routine to provide different behavior.
1416 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1417 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1418 SourceLocation ElseLoc, Stmt *Else) {
1419 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1420 Then, ElseLoc, Else);
1421 }
1422
1423 /// Start building a new switch statement.
1424 ///
1425 /// By default, performs semantic analysis to build the new statement.
1426 /// Subclasses may override this routine to provide different behavior.
1428 SourceLocation LParenLoc, Stmt *Init,
1430 SourceLocation RParenLoc) {
1431 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1432 RParenLoc);
1433 }
1434
1435 /// Attach the body to the switch statement.
1436 ///
1437 /// By default, performs semantic analysis to build the new statement.
1438 /// Subclasses may override this routine to provide different behavior.
1440 Stmt *Switch, Stmt *Body) {
1441 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1442 }
1443
1444 /// Build a new while statement.
1445 ///
1446 /// By default, performs semantic analysis to build the new statement.
1447 /// Subclasses may override this routine to provide different behavior.
1450 SourceLocation RParenLoc, Stmt *Body) {
1451 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1452 }
1453
1454 /// Build a new do-while statement.
1455 ///
1456 /// By default, performs semantic analysis to build the new statement.
1457 /// Subclasses may override this routine to provide different behavior.
1459 SourceLocation WhileLoc, SourceLocation LParenLoc,
1460 Expr *Cond, SourceLocation RParenLoc) {
1461 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1462 Cond, RParenLoc);
1463 }
1464
1465 /// Build a new for statement.
1466 ///
1467 /// By default, performs semantic analysis to build the new statement.
1468 /// Subclasses may override this routine to provide different behavior.
1471 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1472 Stmt *Body) {
1473 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1474 Inc, RParenLoc, Body);
1475 }
1476
1477 /// Build a new goto statement.
1478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
1482 LabelDecl *Label) {
1483 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1484 }
1485
1486 /// Build a new indirect goto statement.
1487 ///
1488 /// By default, performs semantic analysis to build the new statement.
1489 /// Subclasses may override this routine to provide different behavior.
1491 SourceLocation StarLoc,
1492 Expr *Target) {
1493 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1494 }
1495
1496 /// Build a new return statement.
1497 ///
1498 /// By default, performs semantic analysis to build the new statement.
1499 /// Subclasses may override this routine to provide different behavior.
1501 return getSema().BuildReturnStmt(ReturnLoc, Result);
1502 }
1503
1504 /// Build a new declaration statement.
1505 ///
1506 /// By default, performs semantic analysis to build the new statement.
1507 /// Subclasses may override this routine to provide different behavior.
1509 SourceLocation StartLoc, SourceLocation EndLoc) {
1511 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1512 }
1513
1514 /// Build a new inline asm statement.
1515 ///
1516 /// By default, performs semantic analysis to build the new statement.
1517 /// Subclasses may override this routine to provide different behavior.
1519 bool IsVolatile, unsigned NumOutputs,
1520 unsigned NumInputs, IdentifierInfo **Names,
1521 MultiExprArg Constraints, MultiExprArg Exprs,
1522 Expr *AsmString, MultiExprArg Clobbers,
1523 unsigned NumLabels,
1524 SourceLocation RParenLoc) {
1525 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1526 NumInputs, Names, Constraints, Exprs,
1527 AsmString, Clobbers, NumLabels, RParenLoc);
1528 }
1529
1530 /// Build a new MS style inline asm statement.
1531 ///
1532 /// By default, performs semantic analysis to build the new statement.
1533 /// Subclasses may override this routine to provide different behavior.
1535 ArrayRef<Token> AsmToks,
1536 StringRef AsmString,
1537 unsigned NumOutputs, unsigned NumInputs,
1538 ArrayRef<StringRef> Constraints,
1539 ArrayRef<StringRef> Clobbers,
1540 ArrayRef<Expr*> Exprs,
1541 SourceLocation EndLoc) {
1542 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1543 NumOutputs, NumInputs,
1544 Constraints, Clobbers, Exprs, EndLoc);
1545 }
1546
1547 /// Build a new co_return statement.
1548 ///
1549 /// By default, performs semantic analysis to build the new statement.
1550 /// Subclasses may override this routine to provide different behavior.
1552 bool IsImplicit) {
1553 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1554 }
1555
1556 /// Build a new co_await expression.
1557 ///
1558 /// By default, performs semantic analysis to build the new expression.
1559 /// Subclasses may override this routine to provide different behavior.
1561 UnresolvedLookupExpr *OpCoawaitLookup,
1562 bool IsImplicit) {
1563 // This function rebuilds a coawait-expr given its operator.
1564 // For an explicit coawait-expr, the rebuild involves the full set
1565 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1566 // including calling await_transform().
1567 // For an implicit coawait-expr, we need to rebuild the "operator
1568 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1569 // This mirrors how the implicit CoawaitExpr is originally created
1570 // in Sema::ActOnCoroutineBodyStart().
1571 if (IsImplicit) {
1573 CoawaitLoc, Operand, OpCoawaitLookup);
1574 if (Suspend.isInvalid())
1575 return ExprError();
1576 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1577 Suspend.get(), true);
1578 }
1579
1580 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1581 OpCoawaitLookup);
1582 }
1583
1584 /// Build a new co_await expression.
1585 ///
1586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
1589 Expr *Result,
1590 UnresolvedLookupExpr *Lookup) {
1591 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1592 }
1593
1594 /// Build a new co_yield expression.
1595 ///
1596 /// By default, performs semantic analysis to build the new expression.
1597 /// Subclasses may override this routine to provide different behavior.
1599 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1600 }
1601
1603 return getSema().BuildCoroutineBodyStmt(Args);
1604 }
1605
1606 /// Build a new Objective-C \@try statement.
1607 ///
1608 /// By default, performs semantic analysis to build the new statement.
1609 /// Subclasses may override this routine to provide different behavior.
1611 Stmt *TryBody,
1612 MultiStmtArg CatchStmts,
1613 Stmt *Finally) {
1614 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1615 Finally);
1616 }
1617
1618 /// Rebuild an Objective-C exception declaration.
1619 ///
1620 /// By default, performs semantic analysis to build the new declaration.
1621 /// Subclasses may override this routine to provide different behavior.
1623 TypeSourceInfo *TInfo, QualType T) {
1625 TInfo, T, ExceptionDecl->getInnerLocStart(),
1626 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1627 }
1628
1629 /// Build a new Objective-C \@catch statement.
1630 ///
1631 /// By default, performs semantic analysis to build the new statement.
1632 /// Subclasses may override this routine to provide different behavior.
1634 SourceLocation RParenLoc,
1635 VarDecl *Var,
1636 Stmt *Body) {
1637 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1638 }
1639
1640 /// Build a new Objective-C \@finally statement.
1641 ///
1642 /// By default, performs semantic analysis to build the new statement.
1643 /// Subclasses may override this routine to provide different behavior.
1645 Stmt *Body) {
1646 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1647 }
1648
1649 /// Build a new Objective-C \@throw statement.
1650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1654 Expr *Operand) {
1655 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1656 }
1657
1658 /// Build a new OpenMP Canonical loop.
1659 ///
1660 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1661 /// OMPCanonicalLoop.
1663 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1664 }
1665
1666 /// Build a new OpenMP executable directive.
1667 ///
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
1671 DeclarationNameInfo DirName,
1672 OpenMPDirectiveKind CancelRegion,
1673 ArrayRef<OMPClause *> Clauses,
1674 Stmt *AStmt, SourceLocation StartLoc,
1675 SourceLocation EndLoc) {
1676
1678 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1679 }
1680
1681 /// Build a new OpenMP 'if' clause.
1682 ///
1683 /// By default, performs semantic analysis to build the new OpenMP clause.
1684 /// Subclasses may override this routine to provide different behavior.
1686 Expr *Condition, SourceLocation StartLoc,
1687 SourceLocation LParenLoc,
1688 SourceLocation NameModifierLoc,
1689 SourceLocation ColonLoc,
1690 SourceLocation EndLoc) {
1692 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1693 EndLoc);
1694 }
1695
1696 /// Build a new OpenMP 'final' clause.
1697 ///
1698 /// By default, performs semantic analysis to build the new OpenMP clause.
1699 /// Subclasses may override this routine to provide different behavior.
1701 SourceLocation LParenLoc,
1702 SourceLocation EndLoc) {
1703 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1704 LParenLoc, EndLoc);
1705 }
1706
1707 /// Build a new OpenMP 'num_threads' clause.
1708 ///
1709 /// By default, performs semantic analysis to build the new OpenMP clause.
1710 /// Subclasses may override this routine to provide different behavior.
1712 SourceLocation StartLoc,
1713 SourceLocation LParenLoc,
1714 SourceLocation EndLoc) {
1715 return getSema().OpenMP().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1716 LParenLoc, EndLoc);
1717 }
1718
1719 /// Build a new OpenMP 'safelen' clause.
1720 ///
1721 /// By default, performs semantic analysis to build the new OpenMP clause.
1722 /// Subclasses may override this routine to provide different behavior.
1724 SourceLocation LParenLoc,
1725 SourceLocation EndLoc) {
1726 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1727 EndLoc);
1728 }
1729
1730 /// Build a new OpenMP 'simdlen' clause.
1731 ///
1732 /// By default, performs semantic analysis to build the new OpenMP clause.
1733 /// Subclasses may override this routine to provide different behavior.
1735 SourceLocation LParenLoc,
1736 SourceLocation EndLoc) {
1737 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1738 EndLoc);
1739 }
1740
1742 SourceLocation StartLoc,
1743 SourceLocation LParenLoc,
1744 SourceLocation EndLoc) {
1745 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1746 EndLoc);
1747 }
1748
1749 /// Build a new OpenMP 'full' clause.
1751 SourceLocation EndLoc) {
1752 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1753 }
1754
1755 /// Build a new OpenMP 'partial' clause.
1757 SourceLocation LParenLoc,
1758 SourceLocation EndLoc) {
1759 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1760 LParenLoc, EndLoc);
1761 }
1762
1763 /// Build a new OpenMP 'allocator' clause.
1764 ///
1765 /// By default, performs semantic analysis to build the new OpenMP clause.
1766 /// Subclasses may override this routine to provide different behavior.
1768 SourceLocation LParenLoc,
1769 SourceLocation EndLoc) {
1770 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1771 EndLoc);
1772 }
1773
1774 /// Build a new OpenMP 'collapse' clause.
1775 ///
1776 /// By default, performs semantic analysis to build the new OpenMP clause.
1777 /// Subclasses may override this routine to provide different behavior.
1779 SourceLocation LParenLoc,
1780 SourceLocation EndLoc) {
1781 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1782 LParenLoc, EndLoc);
1783 }
1784
1785 /// Build a new OpenMP 'default' clause.
1786 ///
1787 /// By default, performs semantic analysis to build the new OpenMP clause.
1788 /// Subclasses may override this routine to provide different behavior.
1790 SourceLocation StartLoc,
1791 SourceLocation LParenLoc,
1792 SourceLocation EndLoc) {
1794 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1795 }
1796
1797 /// Build a new OpenMP 'proc_bind' 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 KindKwLoc,
1803 SourceLocation StartLoc,
1804 SourceLocation LParenLoc,
1805 SourceLocation EndLoc) {
1807 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1808 }
1809
1810 /// Build a new OpenMP 'schedule' clause.
1811 ///
1812 /// By default, performs semantic analysis to build the new OpenMP clause.
1813 /// Subclasses may override this routine to provide different behavior.
1816 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1817 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1818 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1820 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1821 CommaLoc, EndLoc);
1822 }
1823
1824 /// Build a new OpenMP 'ordered' clause.
1825 ///
1826 /// By default, performs semantic analysis to build the new OpenMP clause.
1827 /// Subclasses may override this routine to provide different behavior.
1829 SourceLocation EndLoc,
1830 SourceLocation LParenLoc, Expr *Num) {
1831 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1832 LParenLoc, Num);
1833 }
1834
1835 /// Build a new OpenMP 'private' clause.
1836 ///
1837 /// By default, performs semantic analysis to build the new OpenMP clause.
1838 /// Subclasses may override this routine to provide different behavior.
1840 SourceLocation StartLoc,
1841 SourceLocation LParenLoc,
1842 SourceLocation EndLoc) {
1843 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1844 LParenLoc, EndLoc);
1845 }
1846
1847 /// Build a new OpenMP 'firstprivate' 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 StartLoc,
1853 SourceLocation LParenLoc,
1854 SourceLocation EndLoc) {
1855 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1856 LParenLoc, EndLoc);
1857 }
1858
1859 /// Build a new OpenMP 'lastprivate' clause.
1860 ///
1861 /// By default, performs semantic analysis to build the new OpenMP clause.
1862 /// Subclasses may override this routine to provide different behavior.
1865 SourceLocation LPKindLoc,
1866 SourceLocation ColonLoc,
1867 SourceLocation StartLoc,
1868 SourceLocation LParenLoc,
1869 SourceLocation EndLoc) {
1871 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1872 }
1873
1874 /// Build a new OpenMP 'shared' clause.
1875 ///
1876 /// By default, performs semantic analysis to build the new OpenMP clause.
1877 /// Subclasses may override this routine to provide different behavior.
1879 SourceLocation StartLoc,
1880 SourceLocation LParenLoc,
1881 SourceLocation EndLoc) {
1882 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1883 LParenLoc, EndLoc);
1884 }
1885
1886 /// Build a new OpenMP 'reduction' clause.
1887 ///
1888 /// By default, performs semantic analysis to build the new statement.
1889 /// Subclasses may override this routine to provide different behavior.
1892 SourceLocation StartLoc, SourceLocation LParenLoc,
1893 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1894 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1895 const DeclarationNameInfo &ReductionId,
1896 ArrayRef<Expr *> UnresolvedReductions) {
1898 VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1899 ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1900 }
1901
1902 /// Build a new OpenMP 'task_reduction' clause.
1903 ///
1904 /// By default, performs semantic analysis to build the new statement.
1905 /// Subclasses may override this routine to provide different behavior.
1907 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1908 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1909 CXXScopeSpec &ReductionIdScopeSpec,
1910 const DeclarationNameInfo &ReductionId,
1911 ArrayRef<Expr *> UnresolvedReductions) {
1913 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1914 ReductionId, UnresolvedReductions);
1915 }
1916
1917 /// Build a new OpenMP 'in_reduction' clause.
1918 ///
1919 /// By default, performs semantic analysis to build the new statement.
1920 /// Subclasses may override this routine to provide different behavior.
1921 OMPClause *
1923 SourceLocation LParenLoc, SourceLocation ColonLoc,
1924 SourceLocation EndLoc,
1925 CXXScopeSpec &ReductionIdScopeSpec,
1926 const DeclarationNameInfo &ReductionId,
1927 ArrayRef<Expr *> UnresolvedReductions) {
1929 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1930 ReductionId, UnresolvedReductions);
1931 }
1932
1933 /// Build a new OpenMP 'linear' clause.
1934 ///
1935 /// By default, performs semantic analysis to build the new OpenMP clause.
1936 /// Subclasses may override this routine to provide different behavior.
1938 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1939 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1940 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1941 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1943 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1944 StepModifierLoc, EndLoc);
1945 }
1946
1947 /// Build a new OpenMP 'aligned' clause.
1948 ///
1949 /// By default, performs semantic analysis to build the new OpenMP clause.
1950 /// Subclasses may override this routine to provide different behavior.
1952 SourceLocation StartLoc,
1953 SourceLocation LParenLoc,
1954 SourceLocation ColonLoc,
1955 SourceLocation EndLoc) {
1957 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
1958 }
1959
1960 /// Build a new OpenMP 'copyin' clause.
1961 ///
1962 /// By default, performs semantic analysis to build the new OpenMP clause.
1963 /// Subclasses may override this routine to provide different behavior.
1965 SourceLocation StartLoc,
1966 SourceLocation LParenLoc,
1967 SourceLocation EndLoc) {
1968 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
1969 LParenLoc, EndLoc);
1970 }
1971
1972 /// Build a new OpenMP 'copyprivate' clause.
1973 ///
1974 /// By default, performs semantic analysis to build the new OpenMP clause.
1975 /// Subclasses may override this routine to provide different behavior.
1977 SourceLocation StartLoc,
1978 SourceLocation LParenLoc,
1979 SourceLocation EndLoc) {
1980 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
1981 LParenLoc, EndLoc);
1982 }
1983
1984 /// Build a new OpenMP 'flush' pseudo clause.
1985 ///
1986 /// By default, performs semantic analysis to build the new OpenMP clause.
1987 /// Subclasses may override this routine to provide different behavior.
1989 SourceLocation StartLoc,
1990 SourceLocation LParenLoc,
1991 SourceLocation EndLoc) {
1992 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
1993 LParenLoc, EndLoc);
1994 }
1995
1996 /// Build a new OpenMP 'depobj' pseudo clause.
1997 ///
1998 /// By default, performs semantic analysis to build the new OpenMP clause.
1999 /// Subclasses may override this routine to provide different behavior.
2001 SourceLocation LParenLoc,
2002 SourceLocation EndLoc) {
2003 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2004 LParenLoc, EndLoc);
2005 }
2006
2007 /// Build a new OpenMP 'depend' 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 Expr *DepModifier, ArrayRef<Expr *> VarList,
2013 SourceLocation StartLoc,
2014 SourceLocation LParenLoc,
2015 SourceLocation EndLoc) {
2017 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2018 }
2019
2020 /// Build a new OpenMP 'device' clause.
2021 ///
2022 /// By default, performs semantic analysis to build the new statement.
2023 /// Subclasses may override this routine to provide different behavior.
2025 Expr *Device, SourceLocation StartLoc,
2026 SourceLocation LParenLoc,
2027 SourceLocation ModifierLoc,
2028 SourceLocation EndLoc) {
2030 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2031 }
2032
2033 /// Build a new OpenMP 'map' clause.
2034 ///
2035 /// By default, performs semantic analysis to build the new OpenMP clause.
2036 /// Subclasses may override this routine to provide different behavior.
2038 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2039 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2040 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2041 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2042 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2043 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2045 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2046 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2047 ColonLoc, VarList, Locs,
2048 /*NoDiagnose=*/false, UnresolvedMappers);
2049 }
2050
2051 /// Build a new OpenMP 'allocate' clause.
2052 ///
2053 /// By default, performs semantic analysis to build the new OpenMP clause.
2054 /// Subclasses may override this routine to provide different behavior.
2056 SourceLocation StartLoc,
2057 SourceLocation LParenLoc,
2058 SourceLocation ColonLoc,
2059 SourceLocation EndLoc) {
2061 Allocate, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2062 }
2063
2064 /// Build a new OpenMP 'num_teams' clause.
2065 ///
2066 /// By default, performs semantic analysis to build the new statement.
2067 /// Subclasses may override this routine to provide different behavior.
2069 SourceLocation LParenLoc,
2070 SourceLocation EndLoc) {
2071 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc,
2072 LParenLoc, EndLoc);
2073 }
2074
2075 /// Build a new OpenMP 'thread_limit' clause.
2076 ///
2077 /// By default, performs semantic analysis to build the new statement.
2078 /// Subclasses may override this routine to provide different behavior.
2080 SourceLocation StartLoc,
2081 SourceLocation LParenLoc,
2082 SourceLocation EndLoc) {
2084 ThreadLimit, StartLoc, LParenLoc, EndLoc);
2085 }
2086
2087 /// Build a new OpenMP 'priority' clause.
2088 ///
2089 /// By default, performs semantic analysis to build the new statement.
2090 /// Subclasses may override this routine to provide different behavior.
2092 SourceLocation LParenLoc,
2093 SourceLocation EndLoc) {
2094 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2095 LParenLoc, EndLoc);
2096 }
2097
2098 /// Build a new OpenMP 'grainsize' clause.
2099 ///
2100 /// By default, performs semantic analysis to build the new statement.
2101 /// Subclasses may override this routine to provide different behavior.
2103 Expr *Device, SourceLocation StartLoc,
2104 SourceLocation LParenLoc,
2105 SourceLocation ModifierLoc,
2106 SourceLocation EndLoc) {
2108 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2109 }
2110
2111 /// Build a new OpenMP 'num_tasks' clause.
2112 ///
2113 /// By default, performs semantic analysis to build the new statement.
2114 /// Subclasses may override this routine to provide different behavior.
2116 Expr *NumTasks, SourceLocation StartLoc,
2117 SourceLocation LParenLoc,
2118 SourceLocation ModifierLoc,
2119 SourceLocation EndLoc) {
2121 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2122 }
2123
2124 /// Build a new OpenMP 'hint' clause.
2125 ///
2126 /// By default, performs semantic analysis to build the new statement.
2127 /// Subclasses may override this routine to provide different behavior.
2129 SourceLocation LParenLoc,
2130 SourceLocation EndLoc) {
2131 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2132 EndLoc);
2133 }
2134
2135 /// Build a new OpenMP 'detach' clause.
2136 ///
2137 /// By default, performs semantic analysis to build the new statement.
2138 /// Subclasses may override this routine to provide different behavior.
2140 SourceLocation LParenLoc,
2141 SourceLocation EndLoc) {
2142 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2143 EndLoc);
2144 }
2145
2146 /// Build a new OpenMP 'dist_schedule' clause.
2147 ///
2148 /// By default, performs semantic analysis to build the new OpenMP clause.
2149 /// Subclasses may override this routine to provide different behavior.
2150 OMPClause *
2152 Expr *ChunkSize, SourceLocation StartLoc,
2153 SourceLocation LParenLoc, SourceLocation KindLoc,
2154 SourceLocation CommaLoc, SourceLocation EndLoc) {
2156 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2157 }
2158
2159 /// Build a new OpenMP 'to' clause.
2160 ///
2161 /// By default, performs semantic analysis to build the new statement.
2162 /// Subclasses may override this routine to provide different behavior.
2163 OMPClause *
2165 ArrayRef<SourceLocation> MotionModifiersLoc,
2166 CXXScopeSpec &MapperIdScopeSpec,
2167 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2168 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2169 ArrayRef<Expr *> UnresolvedMappers) {
2171 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2172 ColonLoc, VarList, Locs, UnresolvedMappers);
2173 }
2174
2175 /// Build a new OpenMP 'from' clause.
2176 ///
2177 /// By default, performs semantic analysis to build the new statement.
2178 /// Subclasses may override this routine to provide different behavior.
2179 OMPClause *
2181 ArrayRef<SourceLocation> MotionModifiersLoc,
2182 CXXScopeSpec &MapperIdScopeSpec,
2183 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2184 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2185 ArrayRef<Expr *> UnresolvedMappers) {
2187 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2188 ColonLoc, VarList, Locs, UnresolvedMappers);
2189 }
2190
2191 /// Build a new OpenMP 'use_device_ptr' clause.
2192 ///
2193 /// By default, performs semantic analysis to build the new OpenMP clause.
2194 /// Subclasses may override this routine to provide different behavior.
2196 const OMPVarListLocTy &Locs) {
2197 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2198 }
2199
2200 /// Build a new OpenMP 'use_device_addr' clause.
2201 ///
2202 /// By default, performs semantic analysis to build the new OpenMP clause.
2203 /// Subclasses may override this routine to provide different behavior.
2205 const OMPVarListLocTy &Locs) {
2206 return getSema().OpenMP().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2207 }
2208
2209 /// Build a new OpenMP 'is_device_ptr' clause.
2210 ///
2211 /// By default, performs semantic analysis to build the new OpenMP clause.
2212 /// Subclasses may override this routine to provide different behavior.
2214 const OMPVarListLocTy &Locs) {
2215 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2216 }
2217
2218 /// Build a new OpenMP 'has_device_addr' clause.
2219 ///
2220 /// By default, performs semantic analysis to build the new OpenMP clause.
2221 /// Subclasses may override this routine to provide different behavior.
2223 const OMPVarListLocTy &Locs) {
2224 return getSema().OpenMP().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2225 }
2226
2227 /// Build a new OpenMP 'defaultmap' clause.
2228 ///
2229 /// By default, performs semantic analysis to build the new OpenMP clause.
2230 /// Subclasses may override this routine to provide different behavior.
2233 SourceLocation StartLoc,
2234 SourceLocation LParenLoc,
2235 SourceLocation MLoc,
2236 SourceLocation KindLoc,
2237 SourceLocation EndLoc) {
2239 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2240 }
2241
2242 /// Build a new OpenMP 'nontemporal' clause.
2243 ///
2244 /// By default, performs semantic analysis to build the new OpenMP clause.
2245 /// Subclasses may override this routine to provide different behavior.
2247 SourceLocation StartLoc,
2248 SourceLocation LParenLoc,
2249 SourceLocation EndLoc) {
2250 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2251 LParenLoc, EndLoc);
2252 }
2253
2254 /// Build a new OpenMP 'inclusive' clause.
2255 ///
2256 /// By default, performs semantic analysis to build the new OpenMP clause.
2257 /// Subclasses may override this routine to provide different behavior.
2259 SourceLocation StartLoc,
2260 SourceLocation LParenLoc,
2261 SourceLocation EndLoc) {
2262 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2263 LParenLoc, EndLoc);
2264 }
2265
2266 /// Build a new OpenMP 'exclusive' clause.
2267 ///
2268 /// By default, performs semantic analysis to build the new OpenMP clause.
2269 /// Subclasses may override this routine to provide different behavior.
2271 SourceLocation StartLoc,
2272 SourceLocation LParenLoc,
2273 SourceLocation EndLoc) {
2274 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2275 LParenLoc, EndLoc);
2276 }
2277
2278 /// Build a new OpenMP 'uses_allocators' clause.
2279 ///
2280 /// By default, performs semantic analysis to build the new OpenMP clause.
2281 /// Subclasses may override this routine to provide different behavior.
2284 SourceLocation LParenLoc, SourceLocation EndLoc) {
2286 StartLoc, LParenLoc, EndLoc, Data);
2287 }
2288
2289 /// Build a new OpenMP 'affinity' clause.
2290 ///
2291 /// By default, performs semantic analysis to build the new OpenMP clause.
2292 /// Subclasses may override this routine to provide different behavior.
2294 SourceLocation LParenLoc,
2295 SourceLocation ColonLoc,
2296 SourceLocation EndLoc, Expr *Modifier,
2297 ArrayRef<Expr *> Locators) {
2299 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2300 }
2301
2302 /// Build a new OpenMP 'order' clause.
2303 ///
2304 /// By default, performs semantic analysis to build the new OpenMP clause.
2305 /// Subclasses may override this routine to provide different behavior.
2307 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2308 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2309 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2311 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2312 }
2313
2314 /// Build a new OpenMP 'init' clause.
2315 ///
2316 /// By default, performs semantic analysis to build the new OpenMP clause.
2317 /// Subclasses may override this routine to provide different behavior.
2319 SourceLocation StartLoc,
2320 SourceLocation LParenLoc,
2321 SourceLocation VarLoc,
2322 SourceLocation EndLoc) {
2324 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2325 }
2326
2327 /// Build a new OpenMP 'use' clause.
2328 ///
2329 /// By default, performs semantic analysis to build the new OpenMP clause.
2330 /// Subclasses may override this routine to provide different behavior.
2332 SourceLocation LParenLoc,
2333 SourceLocation VarLoc, SourceLocation EndLoc) {
2334 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2335 LParenLoc, VarLoc, EndLoc);
2336 }
2337
2338 /// Build a new OpenMP 'destroy' clause.
2339 ///
2340 /// By default, performs semantic analysis to build the new OpenMP clause.
2341 /// Subclasses may override this routine to provide different behavior.
2343 SourceLocation LParenLoc,
2344 SourceLocation VarLoc,
2345 SourceLocation EndLoc) {
2347 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2348 }
2349
2350 /// Build a new OpenMP 'novariants' clause.
2351 ///
2352 /// By default, performs semantic analysis to build the new OpenMP clause.
2353 /// Subclasses may override this routine to provide different behavior.
2355 SourceLocation StartLoc,
2356 SourceLocation LParenLoc,
2357 SourceLocation EndLoc) {
2359 LParenLoc, EndLoc);
2360 }
2361
2362 /// Build a new OpenMP 'nocontext' clause.
2363 ///
2364 /// By default, performs semantic analysis to build the new OpenMP clause.
2365 /// Subclasses may override this routine to provide different behavior.
2367 SourceLocation LParenLoc,
2368 SourceLocation EndLoc) {
2370 LParenLoc, EndLoc);
2371 }
2372
2373 /// Build a new OpenMP 'filter' clause.
2374 ///
2375 /// By default, performs semantic analysis to build the new OpenMP clause.
2376 /// Subclasses may override this routine to provide different behavior.
2378 SourceLocation LParenLoc,
2379 SourceLocation EndLoc) {
2380 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2381 LParenLoc, EndLoc);
2382 }
2383
2384 /// Build a new OpenMP 'bind' clause.
2385 ///
2386 /// By default, performs semantic analysis to build the new OpenMP clause.
2387 /// Subclasses may override this routine to provide different behavior.
2389 SourceLocation KindLoc,
2390 SourceLocation StartLoc,
2391 SourceLocation LParenLoc,
2392 SourceLocation EndLoc) {
2393 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2394 LParenLoc, EndLoc);
2395 }
2396
2397 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2398 ///
2399 /// By default, performs semantic analysis to build the new OpenMP clause.
2400 /// Subclasses may override this routine to provide different behavior.
2402 SourceLocation LParenLoc,
2403 SourceLocation EndLoc) {
2404 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2405 LParenLoc, EndLoc);
2406 }
2407
2408 /// Build a new OpenMP 'ompx_attribute' clause.
2409 ///
2410 /// By default, performs semantic analysis to build the new OpenMP clause.
2411 /// Subclasses may override this routine to provide different behavior.
2413 SourceLocation StartLoc,
2414 SourceLocation LParenLoc,
2415 SourceLocation EndLoc) {
2416 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2417 LParenLoc, EndLoc);
2418 }
2419
2420 /// Build a new OpenMP 'ompx_bare' clause.
2421 ///
2422 /// By default, performs semantic analysis to build the new OpenMP clause.
2423 /// Subclasses may override this routine to provide different behavior.
2425 SourceLocation EndLoc) {
2426 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2427 }
2428
2429 /// Build a new OpenMP 'align' clause.
2430 ///
2431 /// By default, performs semantic analysis to build the new OpenMP clause.
2432 /// Subclasses may override this routine to provide different behavior.
2434 SourceLocation LParenLoc,
2435 SourceLocation EndLoc) {
2436 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2437 EndLoc);
2438 }
2439
2440 /// Build a new OpenMP 'at' clause.
2441 ///
2442 /// By default, performs semantic analysis to build the new OpenMP clause.
2443 /// Subclasses may override this routine to provide different behavior.
2445 SourceLocation StartLoc,
2446 SourceLocation LParenLoc,
2447 SourceLocation EndLoc) {
2448 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2449 LParenLoc, EndLoc);
2450 }
2451
2452 /// Build a new OpenMP 'severity' clause.
2453 ///
2454 /// By default, performs semantic analysis to build the new OpenMP clause.
2455 /// Subclasses may override this routine to provide different behavior.
2457 SourceLocation KwLoc,
2458 SourceLocation StartLoc,
2459 SourceLocation LParenLoc,
2460 SourceLocation EndLoc) {
2461 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2462 LParenLoc, EndLoc);
2463 }
2464
2465 /// Build a new OpenMP 'message' clause.
2466 ///
2467 /// By default, performs semantic analysis to build the new OpenMP clause.
2468 /// Subclasses may override this routine to provide different behavior.
2470 SourceLocation LParenLoc,
2471 SourceLocation EndLoc) {
2472 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2473 EndLoc);
2474 }
2475
2476 /// Build a new OpenMP 'doacross' clause.
2477 ///
2478 /// By default, performs semantic analysis to build the new OpenMP clause.
2479 /// Subclasses may override this routine to provide different behavior.
2480 OMPClause *
2482 SourceLocation DepLoc, SourceLocation ColonLoc,
2483 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2484 SourceLocation LParenLoc, SourceLocation EndLoc) {
2486 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2487 }
2488
2489 /// Rebuild the operand to an Objective-C \@synchronized statement.
2490 ///
2491 /// By default, performs semantic analysis to build the new statement.
2492 /// Subclasses may override this routine to provide different behavior.
2494 Expr *object) {
2495 return getSema().ObjC().ActOnObjCAtSynchronizedOperand(atLoc, object);
2496 }
2497
2498 /// Build a new Objective-C \@synchronized statement.
2499 ///
2500 /// By default, performs semantic analysis to build the new statement.
2501 /// Subclasses may override this routine to provide different behavior.
2503 Expr *Object, Stmt *Body) {
2504 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2505 }
2506
2507 /// Build a new Objective-C \@autoreleasepool statement.
2508 ///
2509 /// By default, performs semantic analysis to build the new statement.
2510 /// Subclasses may override this routine to provide different behavior.
2512 Stmt *Body) {
2513 return getSema().ObjC().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2514 }
2515
2516 /// Build a new Objective-C fast enumeration statement.
2517 ///
2518 /// By default, performs semantic analysis to build the new statement.
2519 /// Subclasses may override this routine to provide different behavior.
2521 Stmt *Element,
2522 Expr *Collection,
2523 SourceLocation RParenLoc,
2524 Stmt *Body) {
2526 ForLoc, Element, Collection, RParenLoc);
2527 if (ForEachStmt.isInvalid())
2528 return StmtError();
2529
2530 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2531 Body);
2532 }
2533
2534 /// Build a new C++ exception declaration.
2535 ///
2536 /// By default, performs semantic analysis to build the new decaration.
2537 /// Subclasses may override this routine to provide different behavior.
2540 SourceLocation StartLoc,
2541 SourceLocation IdLoc,
2542 IdentifierInfo *Id) {
2544 StartLoc, IdLoc, Id);
2545 if (Var)
2546 getSema().CurContext->addDecl(Var);
2547 return Var;
2548 }
2549
2550 /// Build a new C++ catch statement.
2551 ///
2552 /// By default, performs semantic analysis to build the new statement.
2553 /// Subclasses may override this routine to provide different behavior.
2555 VarDecl *ExceptionDecl,
2556 Stmt *Handler) {
2557 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2558 Handler));
2559 }
2560
2561 /// Build a new C++ try statement.
2562 ///
2563 /// By default, performs semantic analysis to build the new statement.
2564 /// Subclasses may override this routine to provide different behavior.
2566 ArrayRef<Stmt *> Handlers) {
2567 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2568 }
2569
2570 /// Build a new C++0x range-based for statement.
2571 ///
2572 /// By default, performs semantic analysis to build the new statement.
2573 /// Subclasses may override this routine to provide different behavior.
2575 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2576 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2577 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2578 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2579 // If we've just learned that the range is actually an Objective-C
2580 // collection, treat this as an Objective-C fast enumeration loop.
2581 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2582 if (RangeStmt->isSingleDecl()) {
2583 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2584 if (RangeVar->isInvalidDecl())
2585 return StmtError();
2586
2587 Expr *RangeExpr = RangeVar->getInit();
2588 if (!RangeExpr->isTypeDependent() &&
2589 RangeExpr->getType()->isObjCObjectPointerType()) {
2590 // FIXME: Support init-statements in Objective-C++20 ranged for
2591 // statement.
2592 if (Init) {
2593 return SemaRef.Diag(Init->getBeginLoc(),
2594 diag::err_objc_for_range_init_stmt)
2595 << Init->getSourceRange();
2596 }
2598 ForLoc, LoopVar, RangeExpr, RParenLoc);
2599 }
2600 }
2601 }
2602 }
2603
2605 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2606 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2607 }
2608
2609 /// Build a new C++0x range-based for statement.
2610 ///
2611 /// By default, performs semantic analysis to build the new statement.
2612 /// Subclasses may override this routine to provide different behavior.
2614 bool IsIfExists,
2615 NestedNameSpecifierLoc QualifierLoc,
2616 DeclarationNameInfo NameInfo,
2617 Stmt *Nested) {
2618 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2619 QualifierLoc, NameInfo, Nested);
2620 }
2621
2622 /// Attach body to a C++0x range-based for statement.
2623 ///
2624 /// By default, performs semantic analysis to finish the new statement.
2625 /// Subclasses may override this routine to provide different behavior.
2627 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2628 }
2629
2631 Stmt *TryBlock, Stmt *Handler) {
2632 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2633 }
2634
2636 Stmt *Block) {
2637 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2638 }
2639
2641 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2642 }
2643
2645 SourceLocation LParen,
2646 SourceLocation RParen,
2647 TypeSourceInfo *TSI) {
2648 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2649 TSI);
2650 }
2651
2652 /// Build a new predefined expression.
2653 ///
2654 /// By default, performs semantic analysis to build the new expression.
2655 /// Subclasses may override this routine to provide different behavior.
2657 return getSema().BuildPredefinedExpr(Loc, IK);
2658 }
2659
2660 /// Build a new expression that references a declaration.
2661 ///
2662 /// By default, performs semantic analysis to build the new expression.
2663 /// Subclasses may override this routine to provide different behavior.
2665 LookupResult &R,
2666 bool RequiresADL) {
2667 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2668 }
2669
2670
2671 /// Build a new expression that references a declaration.
2672 ///
2673 /// By default, performs semantic analysis to build the new expression.
2674 /// Subclasses may override this routine to provide different behavior.
2676 ValueDecl *VD,
2677 const DeclarationNameInfo &NameInfo,
2679 TemplateArgumentListInfo *TemplateArgs) {
2680 CXXScopeSpec SS;
2681 SS.Adopt(QualifierLoc);
2682 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2683 TemplateArgs);
2684 }
2685
2686 /// Build a new expression in parentheses.
2687 ///
2688 /// By default, performs semantic analysis to build the new expression.
2689 /// Subclasses may override this routine to provide different behavior.
2691 SourceLocation RParen) {
2692 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2693 }
2694
2695 /// Build a new pseudo-destructor expression.
2696 ///
2697 /// By default, performs semantic analysis to build the new expression.
2698 /// Subclasses may override this routine to provide different behavior.
2700 SourceLocation OperatorLoc,
2701 bool isArrow,
2702 CXXScopeSpec &SS,
2703 TypeSourceInfo *ScopeType,
2704 SourceLocation CCLoc,
2705 SourceLocation TildeLoc,
2706 PseudoDestructorTypeStorage Destroyed);
2707
2708 /// Build a new unary operator expression.
2709 ///
2710 /// By default, performs semantic analysis to build the new expression.
2711 /// Subclasses may override this routine to provide different behavior.
2714 Expr *SubExpr) {
2715 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2716 }
2717
2718 /// Build a new builtin offsetof expression.
2719 ///
2720 /// By default, performs semantic analysis to build the new expression.
2721 /// Subclasses may override this routine to provide different behavior.
2725 SourceLocation RParenLoc) {
2726 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2727 RParenLoc);
2728 }
2729
2730 /// Build a new sizeof, alignof or vec_step expression with a
2731 /// type argument.
2732 ///
2733 /// By default, performs semantic analysis to build the new expression.
2734 /// Subclasses may override this routine to provide different behavior.
2736 SourceLocation OpLoc,
2737 UnaryExprOrTypeTrait ExprKind,
2738 SourceRange R) {
2739 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2740 }
2741
2742 /// Build a new sizeof, alignof or vec step expression with an
2743 /// expression argument.
2744 ///
2745 /// By default, performs semantic analysis to build the new expression.
2746 /// Subclasses may override this routine to provide different behavior.
2748 UnaryExprOrTypeTrait ExprKind,
2749 SourceRange R) {
2751 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2752 if (Result.isInvalid())
2753 return ExprError();
2754
2755 return Result;
2756 }
2757
2758 /// Build a new array subscript expression.
2759 ///
2760 /// By default, performs semantic analysis to build the new expression.
2761 /// Subclasses may override this routine to provide different behavior.
2763 SourceLocation LBracketLoc,
2764 Expr *RHS,
2765 SourceLocation RBracketLoc) {
2766 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2767 LBracketLoc, RHS,
2768 RBracketLoc);
2769 }
2770
2771 /// Build a new matrix subscript expression.
2772 ///
2773 /// By default, performs semantic analysis to build the new expression.
2774 /// Subclasses may override this routine to provide different behavior.
2776 Expr *ColumnIdx,
2777 SourceLocation RBracketLoc) {
2778 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2779 RBracketLoc);
2780 }
2781
2782 /// Build a new array section expression.
2783 ///
2784 /// By default, performs semantic analysis to build the new expression.
2785 /// Subclasses may override this routine to provide different behavior.
2787 SourceLocation LBracketLoc,
2788 Expr *LowerBound,
2789 SourceLocation ColonLocFirst,
2790 SourceLocation ColonLocSecond,
2791 Expr *Length, Expr *Stride,
2792 SourceLocation RBracketLoc) {
2793 if (IsOMPArraySection)
2795 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2796 Stride, RBracketLoc);
2797
2798 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2799 "Stride/second colon not allowed for OpenACC");
2800
2802 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2803 }
2804
2805 /// Build a new array shaping expression.
2806 ///
2807 /// By default, performs semantic analysis to build the new expression.
2808 /// Subclasses may override this routine to provide different behavior.
2810 SourceLocation RParenLoc,
2811 ArrayRef<Expr *> Dims,
2812 ArrayRef<SourceRange> BracketsRanges) {
2814 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2815 }
2816
2817 /// Build a new iterator expression.
2818 ///
2819 /// By default, performs semantic analysis to build the new expression.
2820 /// Subclasses may override this routine to provide different behavior.
2823 SourceLocation RLoc,
2826 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2827 }
2828
2829 /// Build a new call expression.
2830 ///
2831 /// By default, performs semantic analysis to build the new expression.
2832 /// Subclasses may override this routine to provide different behavior.
2834 MultiExprArg Args,
2835 SourceLocation RParenLoc,
2836 Expr *ExecConfig = nullptr) {
2837 return getSema().ActOnCallExpr(
2838 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2839 }
2840
2842 MultiExprArg Args,
2843 SourceLocation RParenLoc) {
2845 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2846 }
2847
2848 /// Build a new member access expression.
2849 ///
2850 /// By default, performs semantic analysis to build the new expression.
2851 /// Subclasses may override this routine to provide different behavior.
2853 bool isArrow,
2854 NestedNameSpecifierLoc QualifierLoc,
2855 SourceLocation TemplateKWLoc,
2856 const DeclarationNameInfo &MemberNameInfo,
2858 NamedDecl *FoundDecl,
2859 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2860 NamedDecl *FirstQualifierInScope) {
2862 isArrow);
2863 if (!Member->getDeclName()) {
2864 // We have a reference to an unnamed field. This is always the
2865 // base of an anonymous struct/union member access, i.e. the
2866 // field is always of record type.
2867 assert(Member->getType()->isRecordType() &&
2868 "unnamed member not of record type?");
2869
2870 BaseResult =
2872 QualifierLoc.getNestedNameSpecifier(),
2873 FoundDecl, Member);
2874 if (BaseResult.isInvalid())
2875 return ExprError();
2876 Base = BaseResult.get();
2877
2878 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2879 // from the AST, so we need to re-insert them if needed (since
2880 // `BuildFieldRefereneExpr()` doesn't do this).
2881 if (!isArrow && Base->isPRValue()) {
2883 if (BaseResult.isInvalid())
2884 return ExprError();
2885 Base = BaseResult.get();
2886 }
2887
2888 CXXScopeSpec EmptySS;
2890 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2891 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2892 MemberNameInfo);
2893 }
2894
2895 CXXScopeSpec SS;
2896 SS.Adopt(QualifierLoc);
2897
2898 Base = BaseResult.get();
2899 if (Base->containsErrors())
2900 return ExprError();
2901
2902 QualType BaseType = Base->getType();
2903
2904 if (isArrow && !BaseType->isPointerType())
2905 return ExprError();
2906
2907 // FIXME: this involves duplicating earlier analysis in a lot of
2908 // cases; we should avoid this when possible.
2909 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2910 R.addDecl(FoundDecl);
2911 R.resolveKind();
2912
2913 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2914 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2915 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2916 ->getType()
2917 ->getPointeeType()
2918 ->getAsCXXRecordDecl()) {
2919 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2920 // In unevaluated contexts, an expression supposed to be a member access
2921 // might reference a member in an unrelated class.
2922 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2923 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2924 VK_LValue, Member->getLocation());
2925 }
2926 }
2927
2928 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2929 SS, TemplateKWLoc,
2930 FirstQualifierInScope,
2931 R, ExplicitTemplateArgs,
2932 /*S*/nullptr);
2933 }
2934
2935 /// Build a new binary operator expression.
2936 ///
2937 /// By default, performs semantic analysis to build the new expression.
2938 /// Subclasses may override this routine to provide different behavior.
2941 Expr *LHS, Expr *RHS) {
2942 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2943 }
2944
2945 /// Build a new rewritten operator expression.
2946 ///
2947 /// By default, performs semantic analysis to build the new expression.
2948 /// Subclasses may override this routine to provide different behavior.
2950 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2951 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2952 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2953 RHS, /*RequiresADL*/false);
2954 }
2955
2956 /// Build a new conditional operator expression.
2957 ///
2958 /// By default, performs semantic analysis to build the new expression.
2959 /// Subclasses may override this routine to provide different behavior.
2961 SourceLocation QuestionLoc,
2962 Expr *LHS,
2963 SourceLocation ColonLoc,
2964 Expr *RHS) {
2965 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2966 LHS, RHS);
2967 }
2968
2969 /// Build a new C-style cast expression.
2970 ///
2971 /// By default, performs semantic analysis to build the new expression.
2972 /// Subclasses may override this routine to provide different behavior.
2974 TypeSourceInfo *TInfo,
2975 SourceLocation RParenLoc,
2976 Expr *SubExpr) {
2977 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2978 SubExpr);
2979 }
2980
2981 /// Build a new compound literal expression.
2982 ///
2983 /// By default, performs semantic analysis to build the new expression.
2984 /// Subclasses may override this routine to provide different behavior.
2986 TypeSourceInfo *TInfo,
2987 SourceLocation RParenLoc,
2988 Expr *Init) {
2989 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2990 Init);
2991 }
2992
2993 /// Build a new extended vector element access expression.
2994 ///
2995 /// By default, performs semantic analysis to build the new expression.
2996 /// Subclasses may override this routine to provide different behavior.
2998 bool IsArrow,
2999 SourceLocation AccessorLoc,
3000 IdentifierInfo &Accessor) {
3001
3002 CXXScopeSpec SS;
3003 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3005 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3006 /*FirstQualifierInScope*/ nullptr, NameInfo,
3007 /* TemplateArgs */ nullptr,
3008 /*S*/ nullptr);
3009 }
3010
3011 /// Build a new initializer list expression.
3012 ///
3013 /// By default, performs semantic analysis to build the new expression.
3014 /// Subclasses may override this routine to provide different behavior.
3016 MultiExprArg Inits,
3017 SourceLocation RBraceLoc) {
3018 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3019 }
3020
3021 /// Build a new designated initializer expression.
3022 ///
3023 /// By default, performs semantic analysis to build the new expression.
3024 /// Subclasses may override this routine to provide different behavior.
3026 MultiExprArg ArrayExprs,
3027 SourceLocation EqualOrColonLoc,
3028 bool GNUSyntax,
3029 Expr *Init) {
3031 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3032 Init);
3033 if (Result.isInvalid())
3034 return ExprError();
3035
3036 return Result;
3037 }
3038
3039 /// Build a new value-initialized expression.
3040 ///
3041 /// By default, builds the implicit value initialization without performing
3042 /// any semantic analysis. Subclasses may override this routine to provide
3043 /// different behavior.
3045 return new (SemaRef.Context) ImplicitValueInitExpr(T);
3046 }
3047
3048 /// Build a new \c va_arg expression.
3049 ///
3050 /// By default, performs semantic analysis to build the new expression.
3051 /// Subclasses may override this routine to provide different behavior.
3053 Expr *SubExpr, TypeSourceInfo *TInfo,
3054 SourceLocation RParenLoc) {
3055 return getSema().BuildVAArgExpr(BuiltinLoc,
3056 SubExpr, TInfo,
3057 RParenLoc);
3058 }
3059
3060 /// Build a new expression list in parentheses.
3061 ///
3062 /// By default, performs semantic analysis to build the new expression.
3063 /// Subclasses may override this routine to provide different behavior.
3065 MultiExprArg SubExprs,
3066 SourceLocation RParenLoc) {
3067 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3068 }
3069
3070 /// Build a new address-of-label expression.
3071 ///
3072 /// By default, performs semantic analysis, using the name of the label
3073 /// rather than attempting to map the label statement itself.
3074 /// Subclasses may override this routine to provide different behavior.
3076 SourceLocation LabelLoc, LabelDecl *Label) {
3077 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3078 }
3079
3080 /// Build a new GNU statement expression.
3081 ///
3082 /// By default, performs semantic analysis to build the new expression.
3083 /// Subclasses may override this routine to provide different behavior.
3085 SourceLocation RParenLoc, unsigned TemplateDepth) {
3086 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3087 TemplateDepth);
3088 }
3089
3090 /// Build a new __builtin_choose_expr expression.
3091 ///
3092 /// By default, performs semantic analysis to build the new expression.
3093 /// Subclasses may override this routine to provide different behavior.
3095 Expr *Cond, Expr *LHS, Expr *RHS,
3096 SourceLocation RParenLoc) {
3097 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3098 Cond, LHS, RHS,
3099 RParenLoc);
3100 }
3101
3102 /// Build a new generic selection expression with an expression predicate.
3103 ///
3104 /// By default, performs semantic analysis to build the new expression.
3105 /// Subclasses may override this routine to provide different behavior.
3107 SourceLocation DefaultLoc,
3108 SourceLocation RParenLoc,
3109 Expr *ControllingExpr,
3111 ArrayRef<Expr *> Exprs) {
3112 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3113 /*PredicateIsExpr=*/true,
3114 ControllingExpr, Types, Exprs);
3115 }
3116
3117 /// Build a new generic selection expression with a type predicate.
3118 ///
3119 /// By default, performs semantic analysis to build the new expression.
3120 /// Subclasses may override this routine to provide different behavior.
3122 SourceLocation DefaultLoc,
3123 SourceLocation RParenLoc,
3124 TypeSourceInfo *ControllingType,
3126 ArrayRef<Expr *> Exprs) {
3127 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3128 /*PredicateIsExpr=*/false,
3129 ControllingType, Types, Exprs);
3130 }
3131
3132 /// Build a new overloaded operator call expression.
3133 ///
3134 /// By default, performs semantic analysis to build the new expression.
3135 /// The semantic analysis provides the behavior of template instantiation,
3136 /// copying with transformations that turn what looks like an overloaded
3137 /// operator call into a use of a builtin operator, performing
3138 /// argument-dependent lookup, etc. Subclasses may override this routine to
3139 /// provide different behavior.
3141 SourceLocation OpLoc,
3142 SourceLocation CalleeLoc,
3143 bool RequiresADL,
3144 const UnresolvedSetImpl &Functions,
3145 Expr *First, Expr *Second);
3146
3147 /// Build a new C++ "named" cast expression, such as static_cast or
3148 /// reinterpret_cast.
3149 ///
3150 /// By default, this routine dispatches to one of the more-specific routines
3151 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3152 /// Subclasses may override this routine to provide different behavior.
3155 SourceLocation LAngleLoc,
3156 TypeSourceInfo *TInfo,
3157 SourceLocation RAngleLoc,
3158 SourceLocation LParenLoc,
3159 Expr *SubExpr,
3160 SourceLocation RParenLoc) {
3161 switch (Class) {
3162 case Stmt::CXXStaticCastExprClass:
3163 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3164 RAngleLoc, LParenLoc,
3165 SubExpr, RParenLoc);
3166
3167 case Stmt::CXXDynamicCastExprClass:
3168 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3169 RAngleLoc, LParenLoc,
3170 SubExpr, RParenLoc);
3171
3172 case Stmt::CXXReinterpretCastExprClass:
3173 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3174 RAngleLoc, LParenLoc,
3175 SubExpr,
3176 RParenLoc);
3177
3178 case Stmt::CXXConstCastExprClass:
3179 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3180 RAngleLoc, LParenLoc,
3181 SubExpr, RParenLoc);
3182
3183 case Stmt::CXXAddrspaceCastExprClass:
3184 return getDerived().RebuildCXXAddrspaceCastExpr(
3185 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3186
3187 default:
3188 llvm_unreachable("Invalid C++ named cast");
3189 }
3190 }
3191
3192 /// Build a new C++ static_cast expression.
3193 ///
3194 /// By default, performs semantic analysis to build the new expression.
3195 /// Subclasses may override this routine to provide different behavior.
3197 SourceLocation LAngleLoc,
3198 TypeSourceInfo *TInfo,
3199 SourceLocation RAngleLoc,
3200 SourceLocation LParenLoc,
3201 Expr *SubExpr,
3202 SourceLocation RParenLoc) {
3203 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3204 TInfo, SubExpr,
3205 SourceRange(LAngleLoc, RAngleLoc),
3206 SourceRange(LParenLoc, RParenLoc));
3207 }
3208
3209 /// Build a new C++ dynamic_cast expression.
3210 ///
3211 /// By default, performs semantic analysis to build the new expression.
3212 /// Subclasses may override this routine to provide different behavior.
3214 SourceLocation LAngleLoc,
3215 TypeSourceInfo *TInfo,
3216 SourceLocation RAngleLoc,
3217 SourceLocation LParenLoc,
3218 Expr *SubExpr,
3219 SourceLocation RParenLoc) {
3220 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3221 TInfo, SubExpr,
3222 SourceRange(LAngleLoc, RAngleLoc),
3223 SourceRange(LParenLoc, RParenLoc));
3224 }
3225
3226 /// Build a new C++ reinterpret_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_reinterpret_cast,
3238 TInfo, SubExpr,
3239 SourceRange(LAngleLoc, RAngleLoc),
3240 SourceRange(LParenLoc, RParenLoc));
3241 }
3242
3243 /// Build a new C++ const_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_const_cast,
3255 TInfo, SubExpr,
3256 SourceRange(LAngleLoc, RAngleLoc),
3257 SourceRange(LParenLoc, RParenLoc));
3258 }
3259
3262 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3263 SourceLocation LParenLoc, Expr *SubExpr,
3264 SourceLocation RParenLoc) {
3265 return getSema().BuildCXXNamedCast(
3266 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3267 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3268 }
3269
3270 /// Build a new C++ functional-style cast expression.
3271 ///
3272 /// By default, performs semantic analysis to build the new expression.
3273 /// Subclasses may override this routine to provide different behavior.
3275 SourceLocation LParenLoc,
3276 Expr *Sub,
3277 SourceLocation RParenLoc,
3278 bool ListInitialization) {
3279 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3280 // CXXParenListInitExpr. Pass its expanded arguments so that the
3281 // CXXParenListInitExpr can be rebuilt.
3282 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3284 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3285 RParenLoc, ListInitialization);
3286 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3287 MultiExprArg(&Sub, 1), RParenLoc,
3288 ListInitialization);
3289 }
3290
3291 /// Build a new C++ __builtin_bit_cast expression.
3292 ///
3293 /// By default, performs semantic analysis to build the new expression.
3294 /// Subclasses may override this routine to provide different behavior.
3296 TypeSourceInfo *TSI, Expr *Sub,
3297 SourceLocation RParenLoc) {
3298 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3299 }
3300
3301 /// Build a new C++ typeid(type) expression.
3302 ///
3303 /// By default, performs semantic analysis to build the new expression.
3304 /// Subclasses may override this routine to provide different behavior.
3306 SourceLocation TypeidLoc,
3307 TypeSourceInfo *Operand,
3308 SourceLocation RParenLoc) {
3309 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3310 RParenLoc);
3311 }
3312
3313
3314 /// Build a new C++ typeid(expr) expression.
3315 ///
3316 /// By default, performs semantic analysis to build the new expression.
3317 /// Subclasses may override this routine to provide different behavior.
3319 SourceLocation TypeidLoc,
3320 Expr *Operand,
3321 SourceLocation RParenLoc) {
3322 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3323 RParenLoc);
3324 }
3325
3326 /// Build a new C++ __uuidof(type) expression.
3327 ///
3328 /// By default, performs semantic analysis to build the new expression.
3329 /// Subclasses may override this routine to provide different behavior.
3331 TypeSourceInfo *Operand,
3332 SourceLocation RParenLoc) {
3333 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3334 }
3335
3336 /// Build a new C++ __uuidof(expr) expression.
3337 ///
3338 /// By default, performs semantic analysis to build the new expression.
3339 /// Subclasses may override this routine to provide different behavior.
3341 Expr *Operand, SourceLocation RParenLoc) {
3342 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3343 }
3344
3345 /// Build a new C++ "this" expression.
3346 ///
3347 /// By default, performs semantic analysis to build a new "this" expression.
3348 /// Subclasses may override this routine to provide different behavior.
3350 QualType ThisType,
3351 bool isImplicit) {
3352 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3353 return ExprError();
3354 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3355 }
3356
3357 /// Build a new C++ throw expression.
3358 ///
3359 /// By default, performs semantic analysis to build the new expression.
3360 /// Subclasses may override this routine to provide different behavior.
3362 bool IsThrownVariableInScope) {
3363 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3364 }
3365
3366 /// Build a new C++ default-argument expression.
3367 ///
3368 /// By default, builds a new default-argument expression, which does not
3369 /// require any semantic analysis. Subclasses may override this routine to
3370 /// provide different behavior.
3372 Expr *RewrittenExpr) {
3373 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3374 RewrittenExpr, getSema().CurContext);
3375 }
3376
3377 /// Build a new C++11 default-initialization expression.
3378 ///
3379 /// By default, builds a new default field initialization expression, which
3380 /// does not require any semantic analysis. Subclasses may override this
3381 /// routine to provide different behavior.
3383 FieldDecl *Field) {
3384 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3385 }
3386
3387 /// Build a new C++ zero-initialization expression.
3388 ///
3389 /// By default, performs semantic analysis to build the new expression.
3390 /// Subclasses may override this routine to provide different behavior.
3392 SourceLocation LParenLoc,
3393 SourceLocation RParenLoc) {
3394 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, std::nullopt,
3395 RParenLoc,
3396 /*ListInitialization=*/false);
3397 }
3398
3399 /// Build a new C++ "new" expression.
3400 ///
3401 /// By default, performs semantic analysis to build the new expression.
3402 /// Subclasses may override this routine to provide different behavior.
3404 SourceLocation PlacementLParen,
3405 MultiExprArg PlacementArgs,
3406 SourceLocation PlacementRParen,
3407 SourceRange TypeIdParens, QualType AllocatedType,
3408 TypeSourceInfo *AllocatedTypeInfo,
3409 std::optional<Expr *> ArraySize,
3410 SourceRange DirectInitRange, Expr *Initializer) {
3411 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3412 PlacementLParen,
3413 PlacementArgs,
3414 PlacementRParen,
3415 TypeIdParens,
3416 AllocatedType,
3417 AllocatedTypeInfo,
3418 ArraySize,
3419 DirectInitRange,
3420 Initializer);
3421 }
3422
3423 /// Build a new C++ "delete" expression.
3424 ///
3425 /// By default, performs semantic analysis to build the new expression.
3426 /// Subclasses may override this routine to provide different behavior.
3428 bool IsGlobalDelete,
3429 bool IsArrayForm,
3430 Expr *Operand) {
3431 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3432 Operand);
3433 }
3434
3435 /// Build a new type trait expression.
3436 ///
3437 /// By default, performs semantic analysis to build the new expression.
3438 /// Subclasses may override this routine to provide different behavior.
3440 SourceLocation StartLoc,
3442 SourceLocation RParenLoc) {
3443 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3444 }
3445
3446 /// Build a new array type trait expression.
3447 ///
3448 /// By default, performs semantic analysis to build the new expression.
3449 /// Subclasses may override this routine to provide different behavior.
3451 SourceLocation StartLoc,
3452 TypeSourceInfo *TSInfo,
3453 Expr *DimExpr,
3454 SourceLocation RParenLoc) {
3455 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3456 }
3457
3458 /// Build a new expression trait expression.
3459 ///
3460 /// By default, performs semantic analysis to build the new expression.
3461 /// Subclasses may override this routine to provide different behavior.
3463 SourceLocation StartLoc,
3464 Expr *Queried,
3465 SourceLocation RParenLoc) {
3466 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3467 }
3468
3469 /// Build a new (previously unresolved) declaration reference
3470 /// expression.
3471 ///
3472 /// By default, performs semantic analysis to build the new expression.
3473 /// Subclasses may override this routine to provide different behavior.
3475 NestedNameSpecifierLoc QualifierLoc,
3476 SourceLocation TemplateKWLoc,
3477 const DeclarationNameInfo &NameInfo,
3478 const TemplateArgumentListInfo *TemplateArgs,
3479 bool IsAddressOfOperand,
3480 TypeSourceInfo **RecoveryTSI) {
3481 CXXScopeSpec SS;
3482 SS.Adopt(QualifierLoc);
3483
3484 if (TemplateArgs || TemplateKWLoc.isValid())
3486 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3487
3489 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3490 }
3491
3492 /// Build a new template-id expression.
3493 ///
3494 /// By default, performs semantic analysis to build the new expression.
3495 /// Subclasses may override this routine to provide different behavior.
3497 SourceLocation TemplateKWLoc,
3498 LookupResult &R,
3499 bool RequiresADL,
3500 const TemplateArgumentListInfo *TemplateArgs) {
3501 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3502 TemplateArgs);
3503 }
3504
3505 /// Build a new object-construction expression.
3506 ///
3507 /// By default, performs semantic analysis to build the new expression.
3508 /// Subclasses may override this routine to provide different behavior.
3511 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3512 bool ListInitialization, bool StdInitListInitialization,
3513 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3514 SourceRange ParenRange) {
3515 // Reconstruct the constructor we originally found, which might be
3516 // different if this is a call to an inherited constructor.
3517 CXXConstructorDecl *FoundCtor = Constructor;
3518 if (Constructor->isInheritingConstructor())
3519 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3520
3521 SmallVector<Expr *, 8> ConvertedArgs;
3522 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3523 ConvertedArgs))
3524 return ExprError();
3525
3526 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3527 IsElidable,
3528 ConvertedArgs,
3529 HadMultipleCandidates,
3530 ListInitialization,
3531 StdInitListInitialization,
3532 RequiresZeroInit, ConstructKind,
3533 ParenRange);
3534 }
3535
3536 /// Build a new implicit construction via inherited constructor
3537 /// expression.
3539 CXXConstructorDecl *Constructor,
3540 bool ConstructsVBase,
3541 bool InheritedFromVBase) {
3543 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3544 }
3545
3546 /// Build a new object-construction expression.
3547 ///
3548 /// By default, performs semantic analysis to build the new expression.
3549 /// Subclasses may override this routine to provide different behavior.
3551 SourceLocation LParenOrBraceLoc,
3552 MultiExprArg Args,
3553 SourceLocation RParenOrBraceLoc,
3554 bool ListInitialization) {
3556 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3557 }
3558
3559 /// Build a new object-construction expression.
3560 ///
3561 /// By default, performs semantic analysis to build the new expression.
3562 /// Subclasses may override this routine to provide different behavior.
3564 SourceLocation LParenLoc,
3565 MultiExprArg Args,
3566 SourceLocation RParenLoc,
3567 bool ListInitialization) {
3568 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3569 RParenLoc, ListInitialization);
3570 }
3571
3572 /// Build a new member reference expression.
3573 ///
3574 /// By default, performs semantic analysis to build the new expression.
3575 /// Subclasses may override this routine to provide different behavior.
3577 QualType BaseType,
3578 bool IsArrow,
3579 SourceLocation OperatorLoc,
3580 NestedNameSpecifierLoc QualifierLoc,
3581 SourceLocation TemplateKWLoc,
3582 NamedDecl *FirstQualifierInScope,
3583 const DeclarationNameInfo &MemberNameInfo,
3584 const TemplateArgumentListInfo *TemplateArgs) {
3585 CXXScopeSpec SS;
3586 SS.Adopt(QualifierLoc);
3587
3588 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3589 OperatorLoc, IsArrow,
3590 SS, TemplateKWLoc,
3591 FirstQualifierInScope,
3592 MemberNameInfo,
3593 TemplateArgs, /*S*/nullptr);
3594 }
3595
3596 /// Build a new member reference expression.
3597 ///
3598 /// By default, performs semantic analysis to build the new expression.
3599 /// Subclasses may override this routine to provide different behavior.
3601 SourceLocation OperatorLoc,
3602 bool IsArrow,
3603 NestedNameSpecifierLoc QualifierLoc,
3604 SourceLocation TemplateKWLoc,
3605 NamedDecl *FirstQualifierInScope,
3606 LookupResult &R,
3607 const TemplateArgumentListInfo *TemplateArgs) {
3608 CXXScopeSpec SS;
3609 SS.Adopt(QualifierLoc);
3610
3611 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3612 OperatorLoc, IsArrow,
3613 SS, TemplateKWLoc,
3614 FirstQualifierInScope,
3615 R, TemplateArgs, /*S*/nullptr);
3616 }
3617
3618 /// Build a new noexcept expression.
3619 ///
3620 /// By default, performs semantic analysis to build the new expression.
3621 /// Subclasses may override this routine to provide different behavior.
3623 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3624 }
3625
3626 /// Build a new expression to compute the length of a parameter pack.
3628 SourceLocation PackLoc,
3629 SourceLocation RParenLoc,
3630 std::optional<unsigned> Length,
3631 ArrayRef<TemplateArgument> PartialArgs) {
3632 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3633 RParenLoc, Length, PartialArgs);
3634 }
3635
3637 SourceLocation RSquareLoc,
3638 Expr *PackIdExpression, Expr *IndexExpr,
3639 ArrayRef<Expr *> ExpandedExprs,
3640 bool EmptyPack = false) {
3641 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3642 IndexExpr, RSquareLoc, ExpandedExprs,
3643 EmptyPack);
3644 }
3645
3646 /// Build a new expression representing a call to a source location
3647 /// builtin.
3648 ///
3649 /// By default, performs semantic analysis to build the new expression.
3650 /// Subclasses may override this routine to provide different behavior.
3652 SourceLocation BuiltinLoc,
3653 SourceLocation RPLoc,
3654 DeclContext *ParentContext) {
3655 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3656 ParentContext);
3657 }
3658
3659 /// Build a new Objective-C boxed expression.
3660 ///
3661 /// By default, performs semantic analysis to build the new expression.
3662 /// Subclasses may override this routine to provide different behavior.
3664 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3665 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3667 CXXScopeSpec SS;
3668 SS.Adopt(NNS);
3669 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3670 ConceptNameInfo,
3671 FoundDecl,
3672 NamedConcept, TALI);
3673 if (Result.isInvalid())
3674 return ExprError();
3675 return Result;
3676 }
3677
3678 /// \brief Build a new requires expression.
3679 ///
3680 /// By default, performs semantic analysis to build the new expression.
3681 /// Subclasses may override this routine to provide different behavior.
3684 SourceLocation LParenLoc,
3685 ArrayRef<ParmVarDecl *> LocalParameters,
3686 SourceLocation RParenLoc,
3688 SourceLocation ClosingBraceLoc) {
3689 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3690 LocalParameters, RParenLoc, Requirements,
3691 ClosingBraceLoc);
3692 }
3693
3697 return SemaRef.BuildTypeRequirement(SubstDiag);
3698 }
3699
3702 }
3703
3706 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3707 SourceLocation NoexceptLoc,
3709 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3710 std::move(Ret));
3711 }
3712
3714 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3716 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3717 std::move(Ret));
3718 }
3719
3721 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3722 const ASTConstraintSatisfaction &Satisfaction) {
3723 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3724 Satisfaction);
3725 }
3726
3728 return SemaRef.BuildNestedRequirement(Constraint);
3729 }
3730
3731 /// \brief Build a new Objective-C boxed expression.
3732 ///
3733 /// By default, performs semantic analysis to build the new expression.
3734 /// Subclasses may override this routine to provide different behavior.
3736 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3737 }
3738
3739 /// Build a new Objective-C array literal.
3740 ///
3741 /// By default, performs semantic analysis to build the new expression.
3742 /// Subclasses may override this routine to provide different behavior.
3744 Expr **Elements, unsigned NumElements) {
3746 Range, MultiExprArg(Elements, NumElements));
3747 }
3748
3750 Expr *Base, Expr *Key,
3751 ObjCMethodDecl *getterMethod,
3752 ObjCMethodDecl *setterMethod) {
3754 RB, Base, Key, getterMethod, setterMethod);
3755 }
3756
3757 /// Build a new Objective-C dictionary literal.
3758 ///
3759 /// By default, performs semantic analysis to build the new expression.
3760 /// Subclasses may override this routine to provide different behavior.
3763 return getSema().ObjC().BuildObjCDictionaryLiteral(Range, Elements);
3764 }
3765
3766 /// Build a new Objective-C \@encode expression.
3767 ///
3768 /// By default, performs semantic analysis to build the new expression.
3769 /// Subclasses may override this routine to provide different behavior.
3771 TypeSourceInfo *EncodeTypeInfo,
3772 SourceLocation RParenLoc) {
3773 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3774 RParenLoc);
3775 }
3776
3777 /// Build a new Objective-C class message.
3779 Selector Sel,
3780 ArrayRef<SourceLocation> SelectorLocs,
3781 ObjCMethodDecl *Method,
3782 SourceLocation LBracLoc,
3783 MultiExprArg Args,
3784 SourceLocation RBracLoc) {
3786 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3787 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3788 RBracLoc, Args);
3789 }
3790
3791 /// Build a new Objective-C instance message.
3793 Selector Sel,
3794 ArrayRef<SourceLocation> SelectorLocs,
3795 ObjCMethodDecl *Method,
3796 SourceLocation LBracLoc,
3797 MultiExprArg Args,
3798 SourceLocation RBracLoc) {
3799 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3800 /*SuperLoc=*/SourceLocation(),
3801 Sel, Method, LBracLoc,
3802 SelectorLocs, RBracLoc, Args);
3803 }
3804
3805 /// Build a new Objective-C instance/class message to 'super'.
3807 Selector Sel,
3808 ArrayRef<SourceLocation> SelectorLocs,
3809 QualType SuperType,
3810 ObjCMethodDecl *Method,
3811 SourceLocation LBracLoc,
3812 MultiExprArg Args,
3813 SourceLocation RBracLoc) {
3814 return Method->isInstanceMethod()
3816 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3817 SelectorLocs, RBracLoc, Args)
3818 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3819 Sel, Method, LBracLoc,
3820 SelectorLocs, RBracLoc, Args);
3821 }
3822
3823 /// Build a new Objective-C ivar reference expression.
3824 ///
3825 /// By default, performs semantic analysis to build the new expression.
3826 /// Subclasses may override this routine to provide different behavior.
3828 SourceLocation IvarLoc,
3829 bool IsArrow, bool IsFreeIvar) {
3830 CXXScopeSpec SS;
3831 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3833 BaseArg, BaseArg->getType(),
3834 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3835 /*FirstQualifierInScope=*/nullptr, NameInfo,
3836 /*TemplateArgs=*/nullptr,
3837 /*S=*/nullptr);
3838 if (IsFreeIvar && Result.isUsable())
3839 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3840 return Result;
3841 }
3842
3843 /// Build a new Objective-C property reference expression.
3844 ///
3845 /// By default, performs semantic analysis to build the new expression.
3846 /// Subclasses may override this routine to provide different behavior.
3849 SourceLocation PropertyLoc) {
3850 CXXScopeSpec SS;
3851 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3852 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3853 /*FIXME:*/PropertyLoc,
3854 /*IsArrow=*/false,
3855 SS, SourceLocation(),
3856 /*FirstQualifierInScope=*/nullptr,
3857 NameInfo,
3858 /*TemplateArgs=*/nullptr,
3859 /*S=*/nullptr);
3860 }
3861
3862 /// Build a new Objective-C property reference expression.
3863 ///
3864 /// By default, performs semantic analysis to build the new expression.
3865 /// Subclasses may override this routine to provide different behavior.
3867 ObjCMethodDecl *Getter,
3868 ObjCMethodDecl *Setter,
3869 SourceLocation PropertyLoc) {
3870 // Since these expressions can only be value-dependent, we do not
3871 // need to perform semantic analysis again.
3872 return Owned(
3873 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3875 PropertyLoc, Base));
3876 }
3877
3878 /// Build a new Objective-C "isa" expression.
3879 ///
3880 /// By default, performs semantic analysis to build the new expression.
3881 /// Subclasses may override this routine to provide different behavior.
3883 SourceLocation OpLoc, bool IsArrow) {
3884 CXXScopeSpec SS;
3885 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3886 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3887 OpLoc, IsArrow,
3888 SS, SourceLocation(),
3889 /*FirstQualifierInScope=*/nullptr,
3890 NameInfo,
3891 /*TemplateArgs=*/nullptr,
3892 /*S=*/nullptr);
3893 }
3894
3895 /// Build a new shuffle vector expression.
3896 ///
3897 /// By default, performs semantic analysis to build the new expression.
3898 /// Subclasses may override this routine to provide different behavior.
3900 MultiExprArg SubExprs,
3901 SourceLocation RParenLoc) {
3902 // Find the declaration for __builtin_shufflevector
3903 const IdentifierInfo &Name
3904 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3906 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3907 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3908
3909 // Build a reference to the __builtin_shufflevector builtin
3910 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3911 Expr *Callee = new (SemaRef.Context)
3912 DeclRefExpr(SemaRef.Context, Builtin, false,
3913 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3914 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3915 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3916 CK_BuiltinFnToFnPtr).get();
3917
3918 // Build the CallExpr
3919 ExprResult TheCall = CallExpr::Create(
3920 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3921 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3923
3924 // Type-check the __builtin_shufflevector expression.
3925 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3926 }
3927
3928 /// Build a new convert vector expression.
3930 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3931 SourceLocation RParenLoc) {
3932 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3933 }
3934
3935 /// Build a new template argument pack expansion.
3936 ///
3937 /// By default, performs semantic analysis to build a new pack expansion
3938 /// for a template argument. Subclasses may override this routine to provide
3939 /// different behavior.
3942 std::optional<unsigned> NumExpansions) {
3943 switch (Pattern.getArgument().getKind()) {
3947 EllipsisLoc, NumExpansions);
3948 if (Result.isInvalid())
3949 return TemplateArgumentLoc();
3950
3951 return TemplateArgumentLoc(Result.get(), Result.get());
3952 }
3953
3955 return TemplateArgumentLoc(
3958 NumExpansions),
3959 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3960 EllipsisLoc);
3961
3969 llvm_unreachable("Pack expansion pattern has no parameter packs");
3970
3972 if (TypeSourceInfo *Expansion
3973 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3974 EllipsisLoc,
3975 NumExpansions))
3976 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3977 Expansion);
3978 break;
3979 }
3980
3981 return TemplateArgumentLoc();
3982 }
3983
3984 /// Build a new expression pack expansion.
3985 ///
3986 /// By default, performs semantic analysis to build a new pack expansion
3987 /// for an expression. Subclasses may override this routine to provide
3988 /// different behavior.
3990 std::optional<unsigned> NumExpansions) {
3991 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3992 }
3993
3994 /// Build a new C++1z fold-expression.
3995 ///
3996 /// By default, performs semantic analysis in order to build a new fold
3997 /// expression.
3999 SourceLocation LParenLoc, Expr *LHS,
4000 BinaryOperatorKind Operator,
4001 SourceLocation EllipsisLoc, Expr *RHS,
4002 SourceLocation RParenLoc,
4003 std::optional<unsigned> NumExpansions) {
4004 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4005 EllipsisLoc, RHS, RParenLoc,
4006 NumExpansions);
4007 }
4008
4009 /// Build an empty C++1z fold-expression with the given operator.
4010 ///
4011 /// By default, produces the fallback value for the fold-expression, or
4012 /// produce an error if there is no fallback value.
4014 BinaryOperatorKind Operator) {
4015 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4016 }
4017
4018 /// Build a new atomic operation expression.
4019 ///
4020 /// By default, performs semantic analysis to build the new expression.
4021 /// Subclasses may override this routine to provide different behavior.
4024 SourceLocation RParenLoc) {
4025 // Use this for all of the locations, since we don't know the difference
4026 // between the call and the expr at this point.
4027 SourceRange Range{BuiltinLoc, RParenLoc};
4028 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4030 }
4031
4033 ArrayRef<Expr *> SubExprs, QualType Type) {
4034 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4035 }
4036
4038 SourceLocation BeginLoc,
4039 SourceLocation DirLoc,
4040 SourceLocation EndLoc,
4042 StmtResult StrBlock) {
4043 return getSema().OpenACC().ActOnEndStmtDirective(K, BeginLoc, DirLoc,
4044 EndLoc, Clauses, StrBlock);
4045 }
4046
4048 SourceLocation DirLoc,
4049 SourceLocation EndLoc,
4051 StmtResult Loop) {
4053 OpenACCDirectiveKind::Loop, BeginLoc, DirLoc, EndLoc, Clauses, Loop);
4054 }
4055
4056private:
4057 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
4058 QualType ObjectType,
4059 NamedDecl *FirstQualifierInScope,
4060 CXXScopeSpec &SS);
4061
4062 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4063 QualType ObjectType,
4064 NamedDecl *FirstQualifierInScope,
4065 CXXScopeSpec &SS);
4066
4067 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
4068 NamedDecl *FirstQualifierInScope,
4069 CXXScopeSpec &SS);
4070
4071 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4073 bool DeducibleTSTContext);
4074
4076 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4078
4080 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4081 OpenACCDirectiveKind DirKind,
4082 const OpenACCClause *OldClause);
4083};
4084
4085template <typename Derived>
4087 if (!S)
4088 return S;
4089
4090 switch (S->getStmtClass()) {
4091 case Stmt::NoStmtClass: break;
4092
4093 // Transform individual statement nodes
4094 // Pass SDK into statements that can produce a value
4095#define STMT(Node, Parent) \
4096 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4097#define VALUESTMT(Node, Parent) \
4098 case Stmt::Node##Class: \
4099 return getDerived().Transform##Node(cast<Node>(S), SDK);
4100#define ABSTRACT_STMT(Node)
4101#define EXPR(Node, Parent)
4102#include "clang/AST/StmtNodes.inc"
4103
4104 // Transform expressions by calling TransformExpr.
4105#define STMT(Node, Parent)
4106#define ABSTRACT_STMT(Stmt)
4107#define EXPR(Node, Parent) case Stmt::Node##Class:
4108#include "clang/AST/StmtNodes.inc"
4109 {
4110 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4111
4112 if (SDK == SDK_StmtExprResult)
4113 E = getSema().ActOnStmtExprResult(E);
4114 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
4115 }
4116 }
4117
4118 return S;
4119}
4120
4121template<typename Derived>
4123 if (!S)
4124 return S;
4125
4126 switch (S->getClauseKind()) {
4127 default: break;
4128 // Transform individual clause nodes
4129#define GEN_CLANG_CLAUSE_CLASS
4130#define CLAUSE_CLASS(Enum, Str, Class) \
4131 case Enum: \
4132 return getDerived().Transform##Class(cast<Class>(S));
4133#include "llvm/Frontend/OpenMP/OMP.inc"
4134 }
4135
4136 return S;
4137}
4138
4139
4140template<typename Derived>
4142 if (!E)
4143 return E;
4144
4145 switch (E->getStmtClass()) {
4146 case Stmt::NoStmtClass: break;
4147#define STMT(Node, Parent) case Stmt::Node##Class: break;
4148#define ABSTRACT_STMT(Stmt)
4149#define EXPR(Node, Parent) \
4150 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4151#include "clang/AST/StmtNodes.inc"
4152 }
4153
4154 return E;
4155}
4156
4157template<typename Derived>
4159 bool NotCopyInit) {
4160 // Initializers are instantiated like expressions, except that various outer
4161 // layers are stripped.
4162 if (!Init)
4163 return Init;
4164
4165 if (auto *FE = dyn_cast<FullExpr>(Init))
4166 Init = FE->getSubExpr();
4167
4168 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4169 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4170 Init = OVE->getSourceExpr();
4171 }
4172
4173 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4174 Init = MTE->getSubExpr();
4175
4176 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4177 Init = Binder->getSubExpr();
4178
4179 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4180 Init = ICE->getSubExprAsWritten();
4181
4182 if (CXXStdInitializerListExpr *ILE =
4183 dyn_cast<CXXStdInitializerListExpr>(Init))
4184 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4185
4186 // If this is copy-initialization, we only need to reconstruct
4187 // InitListExprs. Other forms of copy-initialization will be a no-op if
4188 // the initializer is already the right type.
4189 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4190 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4191 return getDerived().TransformExpr(Init);
4192
4193 // Revert value-initialization back to empty parens.
4194 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4195 SourceRange Parens = VIE->getSourceRange();
4196 return getDerived().RebuildParenListExpr(Parens.getBegin(), std::nullopt,
4197 Parens.getEnd());
4198 }
4199
4200 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4201 if (isa<ImplicitValueInitExpr>(Init))
4202 return getDerived().RebuildParenListExpr(SourceLocation(), std::nullopt,
4203 SourceLocation());
4204
4205 // Revert initialization by constructor back to a parenthesized or braced list
4206 // of expressions. Any other form of initializer can just be reused directly.
4207 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4208 return getDerived().TransformExpr(Init);
4209
4210 // If the initialization implicitly converted an initializer list to a
4211 // std::initializer_list object, unwrap the std::initializer_list too.
4212 if (Construct && Construct->isStdInitListInitialization())
4213 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4214
4215 // Enter a list-init context if this was list initialization.
4218 Construct->isListInitialization());
4219
4220 getSema().keepInLifetimeExtendingContext();
4221 SmallVector<Expr*, 8> NewArgs;
4222 bool ArgChanged = false;
4223 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4224 /*IsCall*/true, NewArgs, &ArgChanged))
4225 return ExprError();
4226
4227 // If this was list initialization, revert to syntactic list form.
4228 if (Construct->isListInitialization())
4229 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4230 Construct->getEndLoc());
4231
4232 // Build a ParenListExpr to represent anything else.
4234 if (Parens.isInvalid()) {
4235 // This was a variable declaration's initialization for which no initializer
4236 // was specified.
4237 assert(NewArgs.empty() &&
4238 "no parens or braces but have direct init with arguments?");
4239 return ExprEmpty();
4240 }
4241 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4242 Parens.getEnd());
4243}
4244
4245template<typename Derived>
4247 unsigned NumInputs,
4248 bool IsCall,
4249 SmallVectorImpl<Expr *> &Outputs,
4250 bool *ArgChanged) {
4251 for (unsigned I = 0; I != NumInputs; ++I) {
4252 // If requested, drop call arguments that need to be dropped.
4253 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4254 if (ArgChanged)
4255 *ArgChanged = true;
4256
4257 break;
4258 }
4259
4260 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4261 Expr *Pattern = Expansion->getPattern();
4262
4264 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4265 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4266
4267 // Determine whether the set of unexpanded parameter packs can and should
4268 // be expanded.
4269 bool Expand = true;
4270 bool RetainExpansion = false;
4271 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4272 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4273 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4274 Pattern->getSourceRange(),
4275 Unexpanded,
4276 Expand, RetainExpansion,
4277 NumExpansions))
4278 return true;
4279
4280 if (!Expand) {
4281 // The transform has determined that we should perform a simple
4282 // transformation on the pack expansion, producing another pack
4283 // expansion.
4284 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4285 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4286 if (OutPattern.isInvalid())
4287 return true;
4288
4289 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4290 Expansion->getEllipsisLoc(),
4291 NumExpansions);
4292 if (Out.isInvalid())
4293 return true;
4294
4295 if (ArgChanged)
4296 *ArgChanged = true;
4297 Outputs.push_back(Out.get());
4298 continue;
4299 }
4300
4301 // Record right away that the argument was changed. This needs
4302 // to happen even if the array expands to nothing.
4303 if (ArgChanged) *ArgChanged = true;
4304
4305 // The transform has determined that we should perform an elementwise
4306 // expansion of the pattern. Do so.
4307 for (unsigned I = 0; I != *NumExpansions; ++I) {
4308 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4309 ExprResult Out = getDerived().TransformExpr(Pattern);
4310 if (Out.isInvalid())
4311 return true;
4312
4313 if (Out.get()->containsUnexpandedParameterPack()) {
4314 Out = getDerived().RebuildPackExpansion(
4315 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4316 if (Out.isInvalid())
4317 return true;
4318 }
4319
4320 Outputs.push_back(Out.get());
4321 }
4322
4323 // If we're supposed to retain a pack expansion, do so by temporarily
4324 // forgetting the partially-substituted parameter pack.
4325 if (RetainExpansion) {
4326 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4327
4328 ExprResult Out = getDerived().TransformExpr(Pattern);
4329 if (Out.isInvalid())
4330 return true;
4331
4332 Out = getDerived().RebuildPackExpansion(
4333 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4334 if (Out.isInvalid())
4335 return true;
4336
4337 Outputs.push_back(Out.get());
4338 }
4339
4340 continue;
4341 }
4342
4344 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4345 : getDerived().TransformExpr(Inputs[I]);
4346 if (Result.isInvalid())
4347 return true;
4348
4349 if (Result.get() != Inputs[I] && ArgChanged)
4350 *ArgChanged = true;
4351
4352 Outputs.push_back(Result.get());
4353 }
4354
4355 return false;
4356}
4357
4358template <typename Derived>
4361 if (Var) {
4362 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4363 getDerived().TransformDefinition(Var->getLocation(), Var));
4364
4365 if (!ConditionVar)
4366 return Sema::ConditionError();
4367
4368 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4369 }
4370
4371 if (Expr) {
4372 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4373
4374 if (CondExpr.isInvalid())
4375 return Sema::ConditionError();
4376
4377 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4378 /*MissingOK=*/true);
4379 }
4380
4381 return Sema::ConditionResult();
4382}
4383
4384template <typename Derived>
4386 NestedNameSpecifierLoc NNS, QualType ObjectType,
4387 NamedDecl *FirstQualifierInScope) {
4389
4390 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4391 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4392 Qualifier = Qualifier.getPrefix())
4393 Qualifiers.push_back(Qualifier);
4394 };
4395 insertNNS(NNS);
4396
4397 CXXScopeSpec SS;
4398 while (!Qualifiers.empty()) {
4399 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4401
4402 switch (QNNS->getKind()) {
4406 ObjectType);
4407 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4408 SS, FirstQualifierInScope, false))
4409 return NestedNameSpecifierLoc();
4410 break;
4411 }
4412
4414 NamespaceDecl *NS =
4415 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4416 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4417 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4418 break;
4419 }
4420
4422 NamespaceAliasDecl *Alias =
4423 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4425 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4426 Q.getLocalEndLoc());
4427 break;
4428 }
4429
4431 // There is no meaningful transformation that one could perform on the
4432 // global scope.
4433 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4434 break;
4435
4437 CXXRecordDecl *RD =
4438 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4439 SourceLocation(), QNNS->getAsRecordDecl()));
4440 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4441 break;
4442 }
4443
4446 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4447 FirstQualifierInScope, SS);
4448
4449 if (!TL)
4450 return NestedNameSpecifierLoc();
4451
4452 QualType T = TL.getType();
4453 if (T->isDependentType() || T->isRecordType() ||
4454 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4455 if (T->isEnumeralType())
4456 SemaRef.Diag(TL.getBeginLoc(),
4457 diag::warn_cxx98_compat_enum_nested_name_spec);
4458
4459 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) {
4460 SS.Adopt(ETL.getQualifierLoc());
4461 TL = ETL.getNamedTypeLoc();
4462 }
4463
4464 SS.Extend(SemaRef.Context, TL.getTemplateKeywordLoc(), TL,
4465 Q.getLocalEndLoc());
4466 break;
4467 }
4468 // If the nested-name-specifier is an invalid type def, don't emit an
4469 // error because a previous error should have already been emitted.
4471 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4472 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4473 << T << SS.getRange();
4474 }
4475 return NestedNameSpecifierLoc();
4476 }
4477 }
4478
4479 // The qualifier-in-scope and object type only apply to the leftmost entity.
4480 FirstQualifierInScope = nullptr;
4481 ObjectType = QualType();
4482 }
4483
4484 // Don't rebuild the nested-name-specifier if we don't have to.
4485 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4486 !getDerived().AlwaysRebuild())
4487 return NNS;
4488
4489 // If we can re-use the source-location data from the original
4490 // nested-name-specifier, do so.
4491 if (SS.location_size() == NNS.getDataLength() &&
4492 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4494
4495 // Allocate new nested-name-specifier location information.
4496 return SS.getWithLocInContext(SemaRef.Context);
4497}
4498
4499template<typename Derived>
4503 DeclarationName Name = NameInfo.getName();
4504 if (!Name)
4505 return DeclarationNameInfo();
4506
4507 switch (Name.getNameKind()) {
4515 return NameInfo;
4516
4518 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4519 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4520 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4521 if (!NewTemplate)
4522 return DeclarationNameInfo();
4523
4524 DeclarationNameInfo NewNameInfo(NameInfo);
4525 NewNameInfo.setName(
4527 return NewNameInfo;
4528 }
4529
4533 TypeSourceInfo *NewTInfo;
4534 CanQualType NewCanTy;
4535 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4536 NewTInfo = getDerived().TransformType(OldTInfo);
4537 if (!NewTInfo)
4538 return DeclarationNameInfo();
4539 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4540 }
4541 else {
4542 NewTInfo = nullptr;
4543 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4544 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4545 if (NewT.isNull())
4546 return DeclarationNameInfo();
4547 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4548 }
4549
4550 DeclarationName NewName
4551 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4552 NewCanTy);
4553 DeclarationNameInfo NewNameInfo(NameInfo);
4554 NewNameInfo.setName(NewName);
4555 NewNameInfo.setNamedTypeInfo(NewTInfo);
4556 return NewNameInfo;
4557 }
4558 }
4559
4560 llvm_unreachable("Unknown name kind.");
4561}
4562
4563template<typename Derived>
4566 TemplateName Name,
4567 SourceLocation NameLoc,
4568 QualType ObjectType,
4569 NamedDecl *FirstQualifierInScope,
4570 bool AllowInjectedClassName) {
4571 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4572 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
4573 assert(Template && "qualified template name must refer to a template");
4574
4575 TemplateDecl *TransTemplate
4576 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4577 Template));
4578 if (!TransTemplate)
4579 return TemplateName();
4580
4581 if (!getDerived().AlwaysRebuild() &&
4582 SS.getScopeRep() == QTN->getQualifier() &&
4583 TransTemplate == Template)
4584 return Name;
4585
4586 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4587 TransTemplate);
4588 }
4589
4590 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4591 if (SS.getScopeRep()) {
4592 // These apply to the scope specifier, not the template.
4593 ObjectType = QualType();
4594 FirstQualifierInScope = nullptr;
4595 }
4596
4597 if (!getDerived().AlwaysRebuild() &&
4598 SS.getScopeRep() == DTN->getQualifier() &&
4599 ObjectType.isNull())
4600 return Name;
4601
4602 // FIXME: Preserve the location of the "template" keyword.
4603 SourceLocation TemplateKWLoc = NameLoc;
4604
4605 if (DTN->isIdentifier()) {
4606 return getDerived().RebuildTemplateName(SS,
4607 TemplateKWLoc,
4608 *DTN->getIdentifier(),
4609 NameLoc,
4610 ObjectType,
4611 FirstQualifierInScope,
4612 AllowInjectedClassName);
4613 }
4614
4615 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4616 DTN->getOperator(), NameLoc,
4617 ObjectType, AllowInjectedClassName);
4618 }
4619
4620 // FIXME: Try to preserve more of the TemplateName.
4621 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4622 TemplateDecl *TransTemplate
4623 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4624 Template));
4625 if (!TransTemplate)
4626 return TemplateName();
4627
4628 return getDerived().RebuildTemplateName(SS, /*TemplateKeyword=*/false,
4629 TransTemplate);
4630 }
4631
4633 = Name.getAsSubstTemplateTemplateParmPack()) {
4634 return getDerived().RebuildTemplateName(
4635 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4636 SubstPack->getIndex(), SubstPack->getFinal());
4637 }
4638
4639 // These should be getting filtered out before they reach the AST.
4640 llvm_unreachable("overloaded function decl survived to here");
4641}
4642
4643template<typename Derived>
4645 const TemplateArgument &Arg,
4646 TemplateArgumentLoc &Output) {
4647 Output = getSema().getTrivialTemplateArgumentLoc(
4648 Arg, QualType(), getDerived().getBaseLocation());
4649}
4650
4651template <typename Derived>
4653 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4654 bool Uneval) {
4655 const TemplateArgument &Arg = Input.getArgument();
4656 switch (Arg.getKind()) {
4659 llvm_unreachable("Unexpected TemplateArgument");
4660
4665 // Transform a resolved template argument straight to a resolved template
4666 // argument. We get here when substituting into an already-substituted
4667 // template type argument during concept satisfaction checking.
4669 QualType NewT = getDerived().TransformType(T);
4670 if (NewT.isNull())
4671 return true;
4672
4674 ? Arg.getAsDecl()
4675 : nullptr;
4676 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4677 getDerived().getBaseLocation(), D))
4678 : nullptr;
4679 if (D && !NewD)
4680 return true;
4681
4682 if (NewT == T && D == NewD)
4683 Output = Input;
4684 else if (Arg.getKind() == TemplateArgument::Integral)
4685 Output = TemplateArgumentLoc(
4686 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4688 else if (Arg.getKind() == TemplateArgument::NullPtr)
4689 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4691 else if (Arg.getKind() == TemplateArgument::Declaration)
4692 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4695 Output = TemplateArgumentLoc(
4696 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4698 else
4699 llvm_unreachable("unexpected template argument kind");
4700
4701 return false;
4702 }
4703
4705 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4706 if (!DI)
4707 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4708
4709 DI = getDerived().TransformType(DI);
4710 if (!DI)
4711 return true;
4712
4713 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4714 return false;
4715 }
4716
4718 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4719 if (QualifierLoc) {
4720 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4721 if (!QualifierLoc)
4722 return true;
4723 }
4724
4725 CXXScopeSpec SS;
4726 SS.Adopt(QualifierLoc);
4727 TemplateName Template = getDerived().TransformTemplateName(
4728 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4729 if (Template.isNull())
4730 return true;
4731
4732 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4733 QualifierLoc, Input.getTemplateNameLoc());
4734 return false;
4735 }
4736
4738 llvm_unreachable("Caller should expand pack expansions");
4739
4741 // Template argument expressions are constant expressions.
4743 getSema(),
4746 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
4748
4749 Expr *InputExpr = Input.getSourceExpression();
4750 if (!InputExpr)
4751 InputExpr = Input.getArgument().getAsExpr();
4752
4753 ExprResult E = getDerived().TransformExpr(InputExpr);
4754 E = SemaRef.ActOnConstantExpression(E);
4755 if (E.isInvalid())
4756 return true;
4757 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4758 return false;
4759 }
4760 }
4761
4762 // Work around bogus GCC warning
4763 return true;
4764}
4765
4766/// Iterator adaptor that invents template argument location information
4767/// for each of the template arguments in its underlying iterator.
4768template<typename Derived, typename InputIterator>
4771 InputIterator Iter;
4772
4773public:
4776 typedef typename std::iterator_traits<InputIterator>::difference_type
4778 typedef std::input_iterator_tag iterator_category;
4779
4780 class pointer {
4782
4783 public:
4784 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4785
4786 const TemplateArgumentLoc *operator->() const { return &Arg; }
4787 };
4788
4790 InputIterator Iter)
4791 : Self(Self), Iter(Iter) { }
4792
4794 ++Iter;
4795 return *this;
4796 }
4797
4800 ++(*this);
4801 return Old;
4802 }
4803
4806 Self.InventTemplateArgumentLoc(*Iter, Result);
4807 return Result;
4808 }
4809
4810 pointer operator->() const { return pointer(**this); }
4811
4814 return X.Iter == Y.Iter;
4815 }
4816
4819 return X.Iter != Y.Iter;
4820 }
4821};
4822
4823template<typename Derived>
4824template<typename InputIterator>
4826 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4827 bool Uneval) {
4828 for (; First != Last; ++First) {
4831
4832 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4833 // Unpack argument packs, which we translate them into separate
4834 // arguments.
4835 // FIXME: We could do much better if we could guarantee that the
4836 // TemplateArgumentLocInfo for the pack expansion would be usable for
4837 // all of the template arguments in the argument pack.
4838 typedef TemplateArgumentLocInventIterator<Derived,
4840 PackLocIterator;
4841 if (TransformTemplateArguments(PackLocIterator(*this,
4842 In.getArgument().pack_begin()),
4843 PackLocIterator(*this,
4844 In.getArgument().pack_end()),
4845 Outputs, Uneval))
4846 return true;
4847
4848 continue;
4849 }
4850
4851 if (In.getArgument().isPackExpansion()) {
4852 // We have a pack expansion, for which we will be substituting into
4853 // the pattern.
4854 SourceLocation Ellipsis;
4855 std::optional<unsigned> OrigNumExpansions;
4856 TemplateArgumentLoc Pattern
4857 = getSema().getTemplateArgumentPackExpansionPattern(
4858 In, Ellipsis, OrigNumExpansions);
4859
4861 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4862 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4863
4864 // Determine whether the set of unexpanded parameter packs can and should
4865 // be expanded.
4866 bool Expand = true;
4867 bool RetainExpansion = false;
4868 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4869 if (getDerived().TryExpandParameterPacks(Ellipsis,
4870 Pattern.getSourceRange(),
4871 Unexpanded,
4872 Expand,
4873 RetainExpansion,
4874 NumExpansions))
4875 return true;
4876
4877 if (!Expand) {
4878 // The transform has determined that we should perform a simple
4879 // transformation on the pack expansion, producing another pack
4880 // expansion.
4881 TemplateArgumentLoc OutPattern;
4882 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4883 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4884 return true;
4885
4886 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4887 NumExpansions);
4888 if (Out.getArgument().isNull())
4889 return true;
4890
4891 Outputs.addArgument(Out);
4892 continue;
4893 }
4894
4895 // The transform has determined that we should perform an elementwise
4896 // expansion of the pattern. Do so.
4897 for (unsigned I = 0; I != *NumExpansions; ++I) {
4898 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4899
4900 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4901 return true;
4902
4903 if (Out.getArgument().containsUnexpandedParameterPack()) {
4904 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4905 OrigNumExpansions);
4906 if (Out.getArgument().isNull())
4907 return true;
4908 }
4909
4910 Outputs.addArgument(Out);
4911 }
4912
4913 // If we're supposed to retain a pack expansion, do so by temporarily
4914 // forgetting the partially-substituted parameter pack.
4915 if (RetainExpansion) {
4916 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4917
4918 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4919 return true;
4920
4921 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4922 OrigNumExpansions);
4923 if (Out.getArgument().isNull())
4924 return true;
4925
4926 Outputs.addArgument(Out);
4927 }
4928
4929 continue;
4930 }
4931
4932 // The simple case:
4933 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4934 return true;
4935
4936 Outputs.addArgument(Out);
4937 }
4938
4939 return false;
4940
4941}
4942
4943//===----------------------------------------------------------------------===//
4944// Type transformation
4945//===----------------------------------------------------------------------===//
4946
4947template<typename Derived>
4949 if (getDerived().AlreadyTransformed(T))
4950 return T;
4951
4952 // Temporary workaround. All of these transformations should
4953 // eventually turn into transformations on TypeLocs.
4954 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4955 getDerived().getBaseLocation());
4956
4957 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
4958
4959 if (!NewDI)
4960 return QualType();
4961
4962 return NewDI->getType();
4963}
4964
4965template<typename Derived>
4967 // Refine the base location to the type's location.
4968 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4969 getDerived().getBaseEntity());
4970 if (getDerived().AlreadyTransformed(DI->getType()))
4971 return DI;
4972
4973 TypeLocBuilder TLB;
4974
4975 TypeLoc TL = DI->getTypeLoc();
4976 TLB.reserve(TL.getFullDataSize());
4977
4978 QualType Result = getDerived().TransformType(TLB, TL);
4979 if (Result.isNull())
4980 return nullptr;
4981
4982 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4983}
4984
4985template<typename Derived>
4988 switch (T.getTypeLocClass()) {
4989#define ABSTRACT_TYPELOC(CLASS, PARENT)
4990#define TYPELOC(CLASS, PARENT) \
4991 case TypeLoc::CLASS: \
4992 return getDerived().Transform##CLASS##Type(TLB, \
4993 T.castAs<CLASS##TypeLoc>());
4994#include "clang/AST/TypeLocNodes.def"
4995 }
4996
4997 llvm_unreachable("unhandled type loc!");
4998}
4999
5000template<typename Derived>
5002 if (!isa<DependentNameType>(T))
5003 return TransformType(T);
5004
5005 if (getDerived().AlreadyTransformed(T))
5006 return T;
5007 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5008 getDerived().getBaseLocation());
5009 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5010 return NewDI ? NewDI->getType() : QualType();
5011}
5012
5013template<typename Derived>
5016 if (!isa<DependentNameType>(DI->getType()))
5017 return TransformType(DI);
5018
5019 // Refine the base location to the type's location.
5020 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5021 getDerived().getBaseEntity());
5022 if (getDerived().AlreadyTransformed(DI->getType()))
5023 return DI;
5024
5025 TypeLocBuilder TLB;
5026
5027 TypeLoc TL = DI->getTypeLoc();
5028 TLB.reserve(TL.getFullDataSize());
5029
5030 auto QTL = TL.getAs<QualifiedTypeLoc>();
5031 if (QTL)
5032 TL = QTL.getUnqualifiedLoc();
5033
5034 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5035
5036 QualType Result = getDerived().TransformDependentNameType(
5037 TLB, DNTL, /*DeducedTSTContext*/true);
5038 if (Result.isNull())
5039 return nullptr;
5040
5041 if (QTL) {
5042 Result = getDerived().RebuildQualifiedType(Result, QTL);
5043 if (Result.isNull())
5044 return nullptr;
5046 }
5047
5048 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5049}
5050
5051template<typename Derived>
5056 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5057 auto SuppressObjCLifetime =
5058 T.getType().getLocalQualifiers().hasObjCLifetime();
5059 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5060 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5061 SuppressObjCLifetime);
5062 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5063 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5064 TLB, STTP, SuppressObjCLifetime);
5065 } else {
5066 Result = getDerived().TransformType(TLB, UnqualTL);
5067 }
5068
5069 if (Result.isNull())
5070 return QualType();
5071
5072 Result = getDerived().RebuildQualifiedType(Result, T);
5073
5074 if (Result.isNull())
5075 return QualType();
5076
5077 // RebuildQualifiedType might have updated the type, but not in a way
5078 // that invalidates the TypeLoc. (There's no location information for
5079 // qualifiers.)
5081
5082 return Result;
5083}
5084
5085template <typename Derived>
5087 QualifiedTypeLoc TL) {
5088
5090 Qualifiers Quals = TL.getType().getLocalQualifiers();
5091
5092 if ((T.getAddressSpace() != LangAS::Default &&
5093 Quals.getAddressSpace() != LangAS::Default) &&
5094 T.getAddressSpace() != Quals.getAddressSpace()) {
5095 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5096 << TL.getType() << T;
5097 return QualType();
5098 }
5099
5100 // C++ [dcl.fct]p7:
5101 // [When] adding cv-qualifications on top of the function type [...] the
5102 // cv-qualifiers are ignored.
5103 if (T->isFunctionType()) {
5105 Quals.getAddressSpace());
5106 return T;
5107 }
5108
5109 // C++ [dcl.ref]p1:
5110 // when the cv-qualifiers are introduced through the use of a typedef-name
5111 // or decltype-specifier [...] the cv-qualifiers are ignored.
5112 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5113 // applied to a reference type.
5114 if (T->isReferenceType()) {
5115 // The only qualifier that applies to a reference type is restrict.
5116 if (!Quals.hasRestrict())
5117 return T;
5119 }
5120
5121 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5122 // resulting type.
5123 if (Quals.hasObjCLifetime()) {
5124 if (!T->isObjCLifetimeType() && !T->isDependentType())
5125 Quals.removeObjCLifetime();
5126 else if (T.getObjCLifetime()) {
5127 // Objective-C ARC:
5128 // A lifetime qualifier applied to a substituted template parameter
5129 // overrides the lifetime qualifier from the template argument.
5130 const AutoType *AutoTy;
5131 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5132 // 'auto' types behave the same way as template parameters.
5133 QualType Deduced = AutoTy->getDeducedType();
5134 Qualifiers Qs = Deduced.getQualifiers();
5135 Qs.removeObjCLifetime();
5136 Deduced =
5137 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5138 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5139 AutoTy->isDependentType(),
5140 /*isPack=*/false,
5141 AutoTy->getTypeConstraintConcept(),
5142 AutoTy->getTypeConstraintArguments());
5143 } else {
5144 // Otherwise, complain about the addition of a qualifier to an
5145 // already-qualified type.
5146 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5147 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5148 Quals.removeObjCLifetime();
5149 }
5150 }
5151 }
5152
5153 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5154}
5155
5156template<typename Derived>
5157TypeLoc
5159 QualType ObjectType,
5160 NamedDecl *UnqualLookup,
5161 CXXScopeSpec &SS) {
5162 if (getDerived().AlreadyTransformed(TL.getType()))
5163 return TL;
5164
5165 TypeSourceInfo *TSI =
5166 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
5167 if (TSI)
5168 return TSI->getTypeLoc();
5169 return TypeLoc();
5170}
5171
5172template<typename Derived>
5173TypeSourceInfo *
5174TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
5175 QualType ObjectType,
5176 NamedDecl *UnqualLookup,
5177 CXXScopeSpec &SS) {
5178 if (getDerived().AlreadyTransformed(TSInfo->getType()))
5179 return TSInfo;
5180
5181 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
5182 UnqualLookup, SS);
5183}
5184
5185template <typename Derived>
5186TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
5187 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
5188 CXXScopeSpec &SS) {
5189 QualType T = TL.getType();
5190 assert(!getDerived().AlreadyTransformed(T));
5191
5192 TypeLocBuilder TLB;
5193 QualType Result;
5194
5195 if (isa<TemplateSpecializationType>(T)) {
5196 TemplateSpecializationTypeLoc SpecTL =
5197 TL.castAs<TemplateSpecializationTypeLoc>();
5198
5199 TemplateName Template = getDerived().TransformTemplateName(
5200 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
5201 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
5202 if (Template.isNull())
5203 return nullptr;
5204
5205 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
5206 Template);
5207 } else if (isa<DependentTemplateSpecializationType>(T)) {
5208 DependentTemplateSpecializationTypeLoc SpecTL =
5209 TL.castAs<DependentTemplateSpecializationTypeLoc>();
5210
5211 TemplateName Template
5212 = getDerived().RebuildTemplateName(SS,
5213 SpecTL.getTemplateKeywordLoc(),
5214 *SpecTL.getTypePtr()->getIdentifier(),
5215 SpecTL.getTemplateNameLoc(),
5216 ObjectType, UnqualLookup,
5217 /*AllowInjectedClassName*/true);
5218 if (Template.isNull())
5219 return nullptr;
5220
5221 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
5222 SpecTL,
5223 Template,
5224 SS);
5225 } else {
5226 // Nothing special needs to be done for these.
5227 Result = getDerived().TransformType(TLB, TL);
5228 }
5229
5230 if (Result.isNull())
5231 return nullptr;
5232
5233 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5234}
5235
5236template <class TyLoc> static inline
5238 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5239 NewT.setNameLoc(T.getNameLoc());
5240 return T.getType();
5241}
5242
5243template<typename Derived>
5244QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5245 BuiltinTypeLoc T) {
5246 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5247 NewT.setBuiltinLoc(T.getBuiltinLoc());
5248 if (T.needsExtraLocalData())
5249 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5250 return T.getType();
5251}
5252
5253template<typename Derived>
5254QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
5255 ComplexTypeLoc T) {
5256 // FIXME: recurse?
5257 return TransformTypeSpecType(TLB, T);
5258}
5259
5260template <typename Derived>
5261QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
5262 AdjustedTypeLoc TL) {
5263 // Adjustments applied during transformation are handled elsewhere.
5264 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5265}
5266
5267template<typename Derived>
5268QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
5269 DecayedTypeLoc TL) {
5270 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5271 if (OriginalType.isNull())
5272 return QualType();
5273
5274 QualType Result = TL.getType();
5275 if (getDerived().AlwaysRebuild() ||
5276 OriginalType != TL.getOriginalLoc().getType())
5277 Result = SemaRef.Context.getDecayedType(OriginalType);
5278 TLB.push<DecayedTypeLoc>(Result);
5279 // Nothing to set for DecayedTypeLoc.
5280 return Result;
5281}
5282
5283template <typename Derived>
5284QualType
5285TreeTransform<Derived>::TransformArrayParameterType(TypeLocBuilder &TLB,
5286 ArrayParameterTypeLoc TL) {
5287 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5288 if (OriginalType.isNull())
5289 return QualType();
5290
5291 QualType Result = TL.getType();
5292 if (getDerived().AlwaysRebuild() ||
5293 OriginalType != TL.getElementLoc().getType())
5294 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5295 TLB.push<ArrayParameterTypeLoc>(Result);
5296 // Nothing to set for ArrayParameterTypeLoc.
5297 return Result;
5298}
5299
5300template<typename Derived>
5301QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
5302 PointerTypeLoc TL) {
5303 QualType PointeeType
5304 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5305 if (PointeeType.isNull())
5306 return QualType();
5307
5308 QualType Result = TL.getType();
5309 if (PointeeType->getAs<ObjCObjectType>()) {
5310 // A dependent pointer type 'T *' has is being transformed such
5311 // that an Objective-C class type is being replaced for 'T'. The
5312 // resulting pointer type is an ObjCObjectPointerType, not a
5313 // PointerType.
5314 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5315
5316 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5317 NewT.setStarLoc(TL.getStarLoc());
5318 return Result;
5319 }
5320
5321 if (getDerived().AlwaysRebuild() ||
5322 PointeeType != TL.getPointeeLoc().getType()) {
5323 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5324 if (Result.isNull())
5325 return QualType();
5326 }
5327
5328 // Objective-C ARC can add lifetime qualifiers to the type that we're
5329 // pointing to.
5330 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5331
5332 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5333 NewT.setSigilLoc(TL.getSigilLoc());
5334 return Result;
5335}
5336
5337template<typename Derived>
5338QualType
5339TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
5340 BlockPointerTypeLoc TL) {
5341 QualType PointeeType
5342 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5343 if (PointeeType.isNull())
5344 return QualType();
5345
5346 QualType Result = TL.getType();
5347 if (getDerived().AlwaysRebuild() ||
5348 PointeeType != TL.getPointeeLoc().getType()) {
5349 Result = getDerived().RebuildBlockPointerType(PointeeType,
5350 TL.getSigilLoc());
5351 if (Result.isNull())
5352 return QualType();
5353 }
5354
5355 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5356 NewT.setSigilLoc(TL.getSigilLoc());
5357 return Result;
5358}
5359
5360/// Transforms a reference type. Note that somewhat paradoxically we
5361/// don't care whether the type itself is an l-value type or an r-value
5362/// type; we only care if the type was *written* as an l-value type
5363/// or an r-value type.
5364template<typename Derived>
5365QualType
5367 ReferenceTypeLoc TL) {
5368 const ReferenceType *T = TL.getTypePtr();
5369
5370 // Note that this works with the pointee-as-written.
5371 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5372 if (PointeeType.isNull())
5373 return QualType();
5374
5375 QualType Result = TL.getType();
5376 if (getDerived().AlwaysRebuild() ||
5377 PointeeType != T->getPointeeTypeAsWritten()) {
5378 Result = getDerived().RebuildReferenceType(PointeeType,
5379 T->isSpelledAsLValue(),
5380 TL.getSigilLoc());
5381 if (Result.isNull())
5382 return QualType();
5383 }
5384
5385 // Objective-C ARC can add lifetime qualifiers to the type that we're
5386 // referring to.
5389
5390 // r-value references can be rebuilt as l-value references.
5391 ReferenceTypeLoc NewTL;
5392 if (isa<LValueReferenceType>(Result))
5393 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5394 else
5395 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5396 NewTL.setSigilLoc(TL.getSigilLoc());
5397
5398 return Result;
5399}
5400
5401template<typename Derived>
5405 return TransformReferenceType(TLB, TL);
5406}
5407
5408template<typename Derived>
5409QualType
5410TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5411 RValueReferenceTypeLoc TL) {
5412 return TransformReferenceType(TLB, TL);
5413}
5414
5415template<typename Derived>
5416QualType
5417TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5418 MemberPointerTypeLoc TL) {
5419 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5420 if (PointeeType.isNull())
5421 return QualType();
5422
5423 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
5424 TypeSourceInfo *NewClsTInfo = nullptr;
5425 if (OldClsTInfo) {
5426 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
5427 if (!NewClsTInfo)
5428 return QualType();
5429 }
5430
5431 const MemberPointerType *T = TL.getTypePtr();
5432 QualType OldClsType = QualType(T->getClass(), 0);
5433 QualType NewClsType;
5434 if (NewClsTInfo)
5435 NewClsType = NewClsTInfo->getType();
5436 else {
5437 NewClsType = getDerived().TransformType(OldClsType);
5438 if (NewClsType.isNull())
5439 return QualType();
5440 }
5441
5442 QualType Result = TL.getType();
5443 if (getDerived().AlwaysRebuild() ||
5444 PointeeType != T->getPointeeType() ||
5445 NewClsType != OldClsType) {
5446 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
5447 TL.getStarLoc());
5448 if (Result.isNull())
5449 return QualType();
5450 }
5451
5452 // If we had to adjust the pointee type when building a member pointer, make
5453 // sure to push TypeLoc info for it.
5454 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5455 if (MPT && PointeeType != MPT->getPointeeType()) {
5456 assert(isa<AdjustedType>(MPT->getPointeeType()));
5457 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5458 }
5459
5460 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
5461 NewTL.setSigilLoc(TL.getSigilLoc());
5462 NewTL.setClassTInfo(NewClsTInfo);
5463
5464 return Result;
5465}
5466
5467template<typename Derived>
5468QualType
5469TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
5470 ConstantArrayTypeLoc TL) {
5471 const ConstantArrayType *T = TL.getTypePtr();
5472 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5473 if (ElementType.isNull())
5474 return QualType();
5475
5476 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5477 Expr *OldSize = TL.getSizeExpr();
5478 if (!OldSize)
5479 OldSize = const_cast<Expr*>(T->getSizeExpr());
5480 Expr *NewSize = nullptr;
5481 if (OldSize) {
5482 EnterExpressionEvaluationContext Unevaluated(
5484 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5485 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5486 }
5487
5488 QualType Result = TL.getType();
5489 if (getDerived().AlwaysRebuild() ||
5490 ElementType != T->getElementType() ||
5491 (T->getSizeExpr() && NewSize != OldSize)) {
5492 Result = getDerived().RebuildConstantArrayType(ElementType,
5493 T->getSizeModifier(),
5494 T->getSize(), NewSize,
5495 T->getIndexTypeCVRQualifiers(),
5496 TL.getBracketsRange());
5497 if (Result.isNull())
5498 return QualType();
5499 }
5500
5501 // We might have either a ConstantArrayType or a VariableArrayType now:
5502 // a ConstantArrayType is allowed to have an element type which is a
5503 // VariableArrayType if the type is dependent. Fortunately, all array
5504 // types have the same location layout.
5505 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5506 NewTL.setLBracketLoc(TL.getLBracketLoc());
5507 NewTL.setRBracketLoc(TL.getRBracketLoc());
5508 NewTL.setSizeExpr(NewSize);
5509
5510 return Result;
5511}
5512
5513template<typename Derived>
5514QualType TreeTransform<Derived>::TransformIncompleteArrayType(
5515 TypeLocBuilder &TLB,
5516 IncompleteArrayTypeLoc TL) {
5517 const IncompleteArrayType *T = TL.getTypePtr();
5518 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5519 if (ElementType.isNull())
5520 return QualType();
5521
5522 QualType Result = TL.getType();
5523 if (getDerived().AlwaysRebuild() ||
5524 ElementType != T->getElementType()) {
5525 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5526 T->getSizeModifier(),
5527 T->getIndexTypeCVRQualifiers(),
5528 TL.getBracketsRange());
5529 if (Result.isNull())
5530 return QualType();
5531 }
5532
5533 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5534 NewTL.setLBracketLoc(TL.getLBracketLoc());
5535 NewTL.setRBracketLoc(TL.getRBracketLoc());
5536 NewTL.setSizeExpr(nullptr);
5537
5538 return Result;
5539}
5540
5541template<typename Derived>
5542QualType
5543TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
5544 VariableArrayTypeLoc TL) {
5545 const VariableArrayType *T = TL.getTypePtr();
5546 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5547 if (ElementType.isNull())
5548 return QualType();
5549
5550 ExprResult SizeResult;
5551 {
5552 EnterExpressionEvaluationContext Context(
5554 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5555 }
5556 if (SizeResult.isInvalid())
5557 return QualType();
5558 SizeResult =
5559 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5560 if (SizeResult.isInvalid())
5561 return QualType();
5562
5563 Expr *Size = SizeResult.get();
5564
5565 QualType Result = TL.getType();
5566 if (getDerived().AlwaysRebuild() ||
5567 ElementType != T->getElementType() ||
5568 Size != T->getSizeExpr()) {
5569 Result = getDerived().RebuildVariableArrayType(ElementType,
5570 T->getSizeModifier(),
5571 Size,
5572 T->getIndexTypeCVRQualifiers(),
5573 TL.getBracketsRange());
5574 if (Result.isNull())
5575 return QualType();
5576 }
5577
5578 // We might have constant size array now, but fortunately it has the same
5579 // location layout.
5580 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5581 NewTL.setLBracketLoc(TL.getLBracketLoc());
5582 NewTL.setRBracketLoc(TL.getRBracketLoc());
5583 NewTL.setSizeExpr(Size);
5584
5585 return Result;
5586}
5587
5588template<typename Derived>
5589QualType
5590TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
5591 DependentSizedArrayTypeLoc TL) {
5592 const DependentSizedArrayType *T = TL.getTypePtr();
5593 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5594 if (ElementType.isNull())
5595 return QualType();
5596
5597 // Array bounds are constant expressions.
5598 EnterExpressionEvaluationContext Unevaluated(
5600
5601 // If we have a VLA then it won't be a constant.
5602 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5603
5604 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5605 Expr *origSize = TL.getSizeExpr();
5606 if (!origSize) origSize = T->getSizeExpr();
5607
5608 ExprResult sizeResult
5609 = getDerived().TransformExpr(origSize);
5610 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5611 if (sizeResult.isInvalid())
5612 return QualType();
5613
5614 Expr *size = sizeResult.get();
5615
5616 QualType Result = TL.getType();
5617 if (getDerived().AlwaysRebuild() ||
5618 ElementType != T->getElementType() ||
5619 size != origSize) {
5620 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5621 T->getSizeModifier(),
5622 size,
5623 T->getIndexTypeCVRQualifiers(),
5624 TL.getBracketsRange());
5625 if (Result.isNull())
5626 return QualType();
5627 }
5628
5629 // We might have any sort of array type now, but fortunately they
5630 // all have the same location layout.
5631 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5632 NewTL.setLBracketLoc(TL.getLBracketLoc());
5633 NewTL.setRBracketLoc(TL.getRBracketLoc());
5634 NewTL.setSizeExpr(size);
5635
5636 return Result;
5637}
5638
5639template <typename Derived>
5640QualType TreeTransform<Derived>::TransformDependentVectorType(
5641 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
5642 const DependentVectorType *T = TL.getTypePtr();
5643 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5644 if (ElementType.isNull())
5645 return QualType();
5646
5647 EnterExpressionEvaluationContext Unevaluated(
5649
5650 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5651 Size = SemaRef.ActOnConstantExpression(Size);
5652 if (Size.isInvalid())
5653 return QualType();
5654
5655 QualType Result = TL.getType();
5656 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5657 Size.get() != T->getSizeExpr()) {
5658 Result = getDerived().RebuildDependentVectorType(
5659 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5660 if (Result.isNull())
5661 return QualType();
5662 }
5663
5664 // Result might be dependent or not.
5665 if (isa<DependentVectorType>(Result)) {
5666 DependentVectorTypeLoc NewTL =
5667 TLB.push<DependentVectorTypeLoc>(Result);
5668 NewTL.setNameLoc(TL.getNameLoc());
5669 } else {
5670 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5671 NewTL.setNameLoc(TL.getNameLoc());
5672 }
5673
5674 return Result;
5675}
5676
5677template<typename Derived>
5678QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
5679 TypeLocBuilder &TLB,
5680 DependentSizedExtVectorTypeLoc TL) {
5681 const DependentSizedExtVectorType *T = TL.getTypePtr();
5682
5683 // FIXME: ext vector locs should be nested
5684 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5685 if (ElementType.isNull())
5686 return QualType();
5687
5688 // Vector sizes are constant expressions.
5689 EnterExpressionEvaluationContext Unevaluated(
5691
5692 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5693 Size = SemaRef.ActOnConstantExpression(Size);
5694 if (Size.isInvalid())
5695 return QualType();
5696
5697 QualType Result = TL.getType();
5698 if (getDerived().AlwaysRebuild() ||
5699 ElementType != T->getElementType() ||
5700 Size.get() != T->getSizeExpr()) {
5701 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5702 Size.get(),
5703 T->getAttributeLoc());
5704 if (Result.isNull())
5705 return QualType();
5706 }
5707
5708 // Result might be dependent or not.
5709 if (isa<DependentSizedExtVectorType>(Result)) {
5710 DependentSizedExtVectorTypeLoc NewTL
5711 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
5712 NewTL.setNameLoc(TL.getNameLoc());
5713 } else {
5714 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5715 NewTL.setNameLoc(TL.getNameLoc());
5716 }
5717
5718 return Result;
5719}
5720
5721template <typename Derived>
5722QualType
5723TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
5724 ConstantMatrixTypeLoc TL) {
5725 const ConstantMatrixType *T = TL.getTypePtr();
5726 QualType ElementType = getDerived().TransformType(T->getElementType());
5727 if (ElementType.isNull())
5728 return QualType();
5729
5730 QualType Result = TL.getType();
5731 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
5732 Result = getDerived().RebuildConstantMatrixType(
5733 ElementType, T->getNumRows(), T->getNumColumns());
5734 if (Result.isNull())
5735 return QualType();
5736 }
5737
5738 ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
5739 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5740 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5741 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
5742 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
5743
5744 return Result;
5745}
5746
5747template <typename Derived>
5748QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
5749 TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
5750 const DependentSizedMatrixType *T = TL.getTypePtr();
5751
5752 QualType ElementType = getDerived().TransformType(T->getElementType());
5753 if (ElementType.isNull()) {
5754 return QualType();
5755 }
5756
5757 // Matrix dimensions are constant expressions.
5758 EnterExpressionEvaluationContext Unevaluated(
5760
5761 Expr *origRows = TL.getAttrRowOperand();
5762 if (!origRows)
5763 origRows = T->getRowExpr();
5764 Expr *origColumns = TL.getAttrColumnOperand();
5765 if (!origColumns)
5766 origColumns = T->getColumnExpr();
5767
5768 ExprResult rowResult = getDerived().TransformExpr(origRows);
5769 rowResult = SemaRef.ActOnConstantExpression(rowResult);
5770 if (rowResult.isInvalid())
5771 return QualType();
5772
5773 ExprResult columnResult = getDerived().TransformExpr(origColumns);
5774 columnResult = SemaRef.ActOnConstantExpression(columnResult);
5775 if (columnResult.isInvalid())
5776 return QualType();
5777
5778 Expr *rows = rowResult.get();
5779 Expr *columns = columnResult.get();
5780
5781 QualType Result = TL.getType();
5782 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5783 rows != origRows || columns != origColumns) {
5784 Result = getDerived().RebuildDependentSizedMatrixType(
5785 ElementType, rows, columns, T->getAttributeLoc());
5786
5787 if (Result.isNull())
5788 return QualType();
5789 }
5790
5791 // We might have any sort of matrix type now, but fortunately they
5792 // all have the same location layout.
5793 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
5794 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5795 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5796 NewTL.setAttrRowOperand(rows);
5797 NewTL.setAttrColumnOperand(columns);
5798 return Result;
5799}
5800
5801template <typename Derived>
5802QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
5803 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
5804 const DependentAddressSpaceType *T = TL.getTypePtr();
5805
5806 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
5807
5808 if (pointeeType.isNull())
5809 return QualType();
5810
5811 // Address spaces are constant expressions.
5812 EnterExpressionEvaluationContext Unevaluated(
5814
5815 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
5816 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
5817 if (AddrSpace.isInvalid())
5818 return QualType();
5819
5820 QualType Result = TL.getType();
5821 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
5822 AddrSpace.get() != T->getAddrSpaceExpr()) {
5823 Result = getDerived().RebuildDependentAddressSpaceType(
5824 pointeeType, AddrSpace.get(), T->getAttributeLoc());
5825 if (Result.isNull())
5826 return QualType();
5827 }
5828
5829 // Result might be dependent or not.
5830 if (isa<DependentAddressSpaceType>(Result)) {
5831 DependentAddressSpaceTypeLoc NewTL =
5832 TLB.push<DependentAddressSpaceTypeLoc>(Result);
5833
5834 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5835 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5836 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5837
5838 } else {
5839 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
5840 Result, getDerived().getBaseLocation());
5841 TransformType(TLB, DI->getTypeLoc());
5842 }
5843
5844 return Result;
5845}
5846
5847template <typename Derived>
5848QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
5849 VectorTypeLoc TL) {
5850 const VectorType *T = TL.getTypePtr();
5851 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5852 if (ElementType.isNull())
5853 return QualType();
5854
5855 QualType Result = TL.getType();
5856 if (getDerived().AlwaysRebuild() ||
5857 ElementType != T->getElementType()) {
5858 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
5859 T->getVectorKind());
5860 if (Result.isNull())
5861 return QualType();
5862 }
5863
5864 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5865 NewTL.setNameLoc(TL.getNameLoc());
5866
5867 return Result;
5868}
5869
5870template<typename Derived>
5871QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
5872 ExtVectorTypeLoc TL) {
5873 const VectorType *T = TL.getTypePtr();
5874 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5875 if (ElementType.isNull())
5876 return QualType();
5877
5878 QualType Result = TL.getType();
5879 if (getDerived().AlwaysRebuild() ||
5880 ElementType != T->getElementType()) {
5881 Result = getDerived().RebuildExtVectorType(ElementType,
5882 T->getNumElements(),
5883 /*FIXME*/ SourceLocation());
5884 if (Result.isNull())
5885 return QualType();
5886 }
5887
5888 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5889 NewTL.setNameLoc(TL.getNameLoc());
5890
5891 return Result;
5892}
5893
5894template <typename Derived>
5896 ParmVarDecl *OldParm, int indexAdjustment,
5897 std::optional<unsigned> NumExpansions, bool ExpectParameterPack) {
5898 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
5899 TypeSourceInfo *NewDI = nullptr;
5900
5901 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
5902 // If we're substituting into a pack expansion type and we know the
5903 // length we want to expand to, just substitute for the pattern.
5904 TypeLoc OldTL = OldDI->getTypeLoc();
5905 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
5906
5907 TypeLocBuilder TLB;
5908 TypeLoc NewTL = OldDI->getTypeLoc();
5909 TLB.reserve(NewTL.getFullDataSize());
5910
5911 QualType Result = getDerived().TransformType(TLB,
5912 OldExpansionTL.getPatternLoc());
5913 if (Result.isNull())
5914 return nullptr;
5915
5916 Result = RebuildPackExpansionType(Result,
5917 OldExpansionTL.getPatternLoc().getSourceRange(),
5918 OldExpansionTL.getEllipsisLoc(),
5919 NumExpansions);
5920 if (Result.isNull())
5921 return nullptr;
5922
5923 PackExpansionTypeLoc NewExpansionTL
5924 = TLB.push<PackExpansionTypeLoc>(Result);
5925 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5926 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5927 } else
5928 NewDI = getDerived().TransformType(OldDI);
5929 if (!NewDI)
5930 return nullptr;
5931
5932 if (NewDI == OldDI && indexAdjustment == 0)
5933 return OldParm;
5934
5935 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5936 OldParm->getDeclContext(),
5937 OldParm->getInnerLocStart(),
5938 OldParm->getLocation(),
5939 OldParm->getIdentifier(),
5940 NewDI->getType(),
5941 NewDI,
5942 OldParm->getStorageClass(),
5943 /* DefArg */ nullptr);
5944 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5945 OldParm->getFunctionScopeIndex() + indexAdjustment);
5946 transformedLocalDecl(OldParm, {newParm});
5947 return newParm;
5948}
5949
5950template <typename Derived>
5953 const QualType *ParamTypes,
5954 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5955 SmallVectorImpl<QualType> &OutParamTypes,
5958 unsigned *LastParamTransformed) {
5959 int indexAdjustment = 0;
5960
5961 unsigned NumParams = Params.size();
5962 for (unsigned i = 0; i != NumParams; ++i) {
5963 if (LastParamTransformed)
5964 *LastParamTransformed = i;
5965 if (ParmVarDecl *OldParm = Params[i]) {
5966 assert(OldParm->getFunctionScopeIndex() == i);
5967
5968 std::optional<unsigned> NumExpansions;
5969 ParmVarDecl *NewParm = nullptr;
5970 if (OldParm->isParameterPack()) {
5971 // We have a function parameter pack that may need to be expanded.
5973
5974 // Find the parameter packs that could be expanded.
5975 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
5977 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5978 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
5979
5980 // Determine whether we should expand the parameter packs.
5981 bool ShouldExpand = false;
5982 bool RetainExpansion = false;
5983 std::optional<unsigned> OrigNumExpansions;
5984 if (Unexpanded.size() > 0) {
5985 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
5986 NumExpansions = OrigNumExpansions;
5987 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5988 Pattern.getSourceRange(),
5989 Unexpanded,
5990 ShouldExpand,
5991 RetainExpansion,
5992 NumExpansions)) {
5993 return true;
5994 }
5995 } else {
5996#ifndef NDEBUG
5997 const AutoType *AT =
5998 Pattern.getType().getTypePtr()->getContainedAutoType();
5999 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6000 "Could not find parameter packs or undeduced auto type!");
6001#endif
6002 }
6003
6004 if (ShouldExpand) {
6005 // Expand the function parameter pack into multiple, separate
6006 // parameters.
6007 getDerived().ExpandingFunctionParameterPack(OldParm);
6008 for (unsigned I = 0; I != *NumExpansions; ++I) {
6009 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6010 ParmVarDecl *NewParm
6011 = getDerived().TransformFunctionTypeParam(OldParm,
6012 indexAdjustment++,
6013 OrigNumExpansions,
6014 /*ExpectParameterPack=*/false);
6015 if (!NewParm)
6016 return true;
6017
6018 if (ParamInfos)
6019 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6020 OutParamTypes.push_back(NewParm->getType());
6021 if (PVars)
6022 PVars->push_back(NewParm);
6023 }
6024
6025 // If we're supposed to retain a pack expansion, do so by temporarily
6026 // forgetting the partially-substituted parameter pack.
6027 if (RetainExpansion) {
6028 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6029 ParmVarDecl *NewParm
6030 = getDerived().TransformFunctionTypeParam(OldParm,
6031 indexAdjustment++,
6032 OrigNumExpansions,
6033 /*ExpectParameterPack=*/false);
6034 if (!NewParm)
6035 return true;
6036
6037 if (ParamInfos)
6038 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6039 OutParamTypes.push_back(NewParm->getType());
6040 if (PVars)
6041 PVars->push_back(NewParm);
6042 }
6043
6044 // The next parameter should have the same adjustment as the
6045 // last thing we pushed, but we post-incremented indexAdjustment
6046 // on every push. Also, if we push nothing, the adjustment should
6047 // go down by one.
6048 indexAdjustment--;
6049
6050 // We're done with the pack expansion.
6051 continue;
6052 }
6053
6054 // We'll substitute the parameter now without expanding the pack
6055 // expansion.
6056 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6057 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6058 indexAdjustment,
6059 NumExpansions,
6060 /*ExpectParameterPack=*/true);
6061 assert(NewParm->isParameterPack() &&
6062 "Parameter pack no longer a parameter pack after "
6063 "transformation.");
6064 } else {
6065 NewParm = getDerived().TransformFunctionTypeParam(
6066 OldParm, indexAdjustment, std::nullopt,
6067 /*ExpectParameterPack=*/false);
6068 }
6069
6070 if (!NewParm)
6071 return true;
6072
6073 if (ParamInfos)
6074 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6075 OutParamTypes.push_back(NewParm->getType());
6076 if (PVars)
6077 PVars->push_back(NewParm);
6078 continue;
6079 }
6080
6081 // Deal with the possibility that we don't have a parameter
6082 // declaration for this parameter.
6083 assert(ParamTypes);
6084 QualType OldType = ParamTypes[i];
6085 bool IsPackExpansion = false;
6086 std::optional<unsigned> NumExpansions;
6087 QualType NewType;
6088 if (const PackExpansionType *Expansion
6089 = dyn_cast<PackExpansionType>(OldType)) {
6090 // We have a function parameter pack that may need to be expanded.
6091 QualType Pattern = Expansion->getPattern();
6093 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6094
6095 // Determine whether we should expand the parameter packs.
6096 bool ShouldExpand = false;
6097 bool RetainExpansion = false;
6098 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
6099 Unexpanded,
6100 ShouldExpand,
6101 RetainExpansion,
6102 NumExpansions)) {
6103 return true;
6104 }
6105
6106 if (ShouldExpand) {
6107 // Expand the function parameter pack into multiple, separate
6108 // parameters.
6109 for (unsigned I = 0; I != *NumExpansions; ++I) {
6110 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6111 QualType NewType = getDerived().TransformType(Pattern);
6112 if (NewType.isNull())
6113 return true;
6114
6115 if (NewType->containsUnexpandedParameterPack()) {
6116 NewType = getSema().getASTContext().getPackExpansionType(
6117 NewType, std::nullopt);
6118
6119 if (NewType.isNull())
6120 return true;
6121 }
6122
6123 if (ParamInfos)
6124 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6125 OutParamTypes.push_back(NewType);
6126 if (PVars)
6127 PVars->push_back(nullptr);
6128 }
6129
6130 // We're done with the pack expansion.
6131 continue;
6132 }
6133
6134 // If we're supposed to retain a pack expansion, do so by temporarily
6135 // forgetting the partially-substituted parameter pack.
6136 if (RetainExpansion) {
6137 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6138 QualType NewType = getDerived().TransformType(Pattern);
6139 if (NewType.isNull())
6140 return true;
6141
6142 if (ParamInfos)
6143 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6144 OutParamTypes.push_back(NewType);
6145 if (PVars)
6146 PVars->push_back(nullptr);
6147 }
6148
6149 // We'll substitute the parameter now without expanding the pack
6150 // expansion.
6151 OldType = Expansion->getPattern();
6152 IsPackExpansion = true;
6153 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6154 NewType = getDerived().TransformType(OldType);
6155 } else {
6156 NewType = getDerived().TransformType(OldType);
6157 }
6158
6159 if (NewType.isNull())
6160 return true;
6161
6162 if (IsPackExpansion)
6163 NewType = getSema().Context.getPackExpansionType(NewType,
6164 NumExpansions);
6165
6166 if (ParamInfos)
6167 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6168 OutParamTypes.push_back(NewType);
6169 if (PVars)
6170 PVars->push_back(nullptr);
6171 }
6172
6173#ifndef NDEBUG
6174 if (PVars) {
6175 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6176 if (ParmVarDecl *parm = (*PVars)[i])
6177 assert(parm->getFunctionScopeIndex() == i);
6178 }
6179#endif
6180
6181 return false;
6182}
6183
6184template<typename Derived>
6188 SmallVector<QualType, 4> ExceptionStorage;
6189 return getDerived().TransformFunctionProtoType(
6190 TLB, TL, nullptr, Qualifiers(),
6191 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6192 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6193 ExceptionStorage, Changed);
6194 });
6195}
6196
6197template<typename Derived> template<typename Fn>
6199 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6200 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6201
6202 // Transform the parameters and return type.
6203 //
6204 // We are required to instantiate the params and return type in source order.
6205 // When the function has a trailing return type, we instantiate the
6206 // parameters before the return type, since the return type can then refer
6207 // to the parameters themselves (via decltype, sizeof, etc.).
6208 //
6209 SmallVector<QualType, 4> ParamTypes;
6211 Sema::ExtParameterInfoBuilder ExtParamInfos;
6212 const FunctionProtoType *T = TL.getTypePtr();
6213
6214 QualType ResultType;
6215
6216 if (T->hasTrailingReturn()) {
6217 if (getDerived().TransformFunctionTypeParams(
6218 TL.getBeginLoc(), TL.getParams(),
6221 ParamTypes, &ParamDecls, ExtParamInfos))
6222 return QualType();
6223
6224 {
6225 // C++11 [expr.prim.general]p3:
6226 // If a declaration declares a member function or member function
6227 // template of a class X, the expression this is a prvalue of type
6228 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6229 // and the end of the function-definition, member-declarator, or
6230 // declarator.
6231 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6232 Sema::CXXThisScopeRAII ThisScope(
6233 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6234
6235 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6236 if (ResultType.isNull())
6237 return QualType();
6238 }
6239 }
6240 else {
6241 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6242 if (ResultType.isNull())
6243 return QualType();
6244
6245 if (getDerived().TransformFunctionTypeParams(
6246 TL.getBeginLoc(), TL.getParams(),
6249 ParamTypes, &ParamDecls, ExtParamInfos))
6250 return QualType();
6251 }
6252
6254
6255 bool EPIChanged = false;
6256 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6257 return QualType();
6258
6259 // Handle extended parameter information.
6260 if (auto NewExtParamInfos =
6261 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6262 if (!EPI.ExtParameterInfos ||
6264 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6265 EPIChanged = true;
6266 }
6267 EPI.ExtParameterInfos = NewExtParamInfos;
6268 } else if (EPI.ExtParameterInfos) {
6269 EPIChanged = true;
6270 EPI.ExtParameterInfos = nullptr;
6271 }
6272
6273 // Transform any function effects with unevaluated conditions.
6274 // Hold this set in a local for the rest of this function, since EPI
6275 // may need to hold a FunctionEffectsRef pointing into it.
6276 std::optional<FunctionEffectSet> NewFX;
6277 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6278 NewFX.emplace();
6281
6282 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6283 FunctionEffectWithCondition NewEC = PrevEC;
6284 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6285 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6286 if (NewExpr.isInvalid())
6287 return QualType();
6288 std::optional<FunctionEffectMode> Mode =
6289 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6290 if (!Mode)
6291 return QualType();
6292
6293 // The condition expression has been transformed, and re-evaluated.
6294 // It may or may not have become constant.
6295 switch (*Mode) {
6297 NewEC.Cond = {};
6298 break;
6300 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6301 NewEC.Cond = {};
6302 break;
6304 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6305 break;
6307 llvm_unreachable(
6308 "FunctionEffectMode::None shouldn't be possible here");
6309 }
6310 }
6311 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6312 TL.getBeginLoc())) {
6314 NewFX->insert(NewEC, Errs);
6315 assert(Errs.empty());
6316 }
6317 }
6318 EPI.FunctionEffects = *NewFX;
6319 EPIChanged = true;
6320 }
6321
6322 QualType Result = TL.getType();
6323 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6324 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6325 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6326 if (Result.isNull())
6327 return QualType();
6328 }
6329
6332 NewTL.setLParenLoc(TL.getLParenLoc());
6333 NewTL.setRParenLoc(TL.getRParenLoc());
6336 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6337 NewTL.setParam(i, ParamDecls[i]);
6338
6339 return Result;
6340}
6341
6342template<typename Derived>
6345 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6346 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6347
6348 // Instantiate a dynamic noexcept expression, if any.
6349 if (isComputedNoexcept(ESI.Type)) {
6350 // Update this scrope because ContextDecl in Sema will be used in
6351 // TransformExpr.
6352 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6353 Sema::CXXThisScopeRAII ThisScope(
6354 SemaRef, Method ? Method->getParent() : nullptr,
6355 Method ? Method->getMethodQualifiers() : Qualifiers{},
6356 Method != nullptr);
6359 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6360 if (NoexceptExpr.isInvalid())
6361 return true;
6362
6364 NoexceptExpr =
6365 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6366 if (NoexceptExpr.isInvalid())
6367 return true;
6368
6369 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6370 Changed = true;
6371 ESI.NoexceptExpr = NoexceptExpr.get();
6372 ESI.Type = EST;
6373 }
6374
6375 if (ESI.Type != EST_Dynamic)
6376 return false;
6377
6378 // Instantiate a dynamic exception specification's type.
6379 for (QualType T : ESI.Exceptions) {
6380 if (const PackExpansionType *PackExpansion =
6382 Changed = true;
6383
6384 // We have a pack expansion. Instantiate it.
6386 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6387 Unexpanded);
6388 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6389
6390 // Determine whether the set of unexpanded parameter packs can and
6391 // should
6392 // be expanded.
6393 bool Expand = false;
6394 bool RetainExpansion = false;
6395 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6396 // FIXME: Track the location of the ellipsis (and track source location
6397 // information for the types in the exception specification in general).
6398 if (getDerived().TryExpandParameterPacks(
6399 Loc, SourceRange(), Unexpanded, Expand,
6400 RetainExpansion, NumExpansions))
6401 return true;
6402
6403 if (!Expand) {
6404 // We can't expand this pack expansion into separate arguments yet;
6405 // just substitute into the pattern and create a new pack expansion
6406 // type.
6407 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6408 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6409 if (U.isNull())
6410 return true;
6411
6412 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6413 Exceptions.push_back(U);
6414 continue;
6415 }
6416
6417 // Substitute into the pack expansion pattern for each slice of the
6418 // pack.
6419 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6420 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6421
6422 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6423 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6424 return true;
6425
6426 Exceptions.push_back(U);
6427 }
6428 } else {
6429 QualType U = getDerived().TransformType(T);
6430 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6431 return true;
6432 if (T != U)
6433 Changed = true;
6434
6435 Exceptions.push_back(U);
6436 }
6437 }
6438
6439 ESI.Exceptions = Exceptions;
6440 if (ESI.Exceptions.empty())
6441 ESI.Type = EST_DynamicNone;
6442 return false;
6443}
6444
6445template<typename Derived>
6447 TypeLocBuilder &TLB,
6449 const FunctionNoProtoType *T = TL.getTypePtr();
6450 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6451 if (ResultType.isNull())
6452 return QualType();
6453
6454 QualType Result = TL.getType();
6455 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6456 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6457
6460 NewTL.setLParenLoc(TL.getLParenLoc());
6461 NewTL.setRParenLoc(TL.getRParenLoc());
6463
6464 return Result;
6465}
6466
6467template <typename Derived>
6468QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6469 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6470 const UnresolvedUsingType *T = TL.getTypePtr();
6471 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6472 if (!D)
6473 return QualType();
6474
6475 QualType Result = TL.getType();
6476 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
6477 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
6478 if (Result.isNull())
6479 return QualType();
6480 }
6481
6482 // We might get an arbitrary type spec type back. We should at
6483 // least always get a type spec type, though.
6484 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
6485 NewTL.setNameLoc(TL.getNameLoc());
6486
6487 return Result;
6488}
6489
6490template <typename Derived>
6491QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
6492 UsingTypeLoc TL) {
6493 const UsingType *T = TL.getTypePtr();
6494
6495 auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl(
6496 TL.getLocalSourceRange().getBegin(), T->getFoundDecl()));
6497 if (!Found)
6498 return QualType();
6499
6500 QualType Underlying = getDerived().TransformType(T->desugar());
6501 if (Underlying.isNull())
6502 return QualType();
6503
6504 QualType Result = TL.getType();
6505 if (getDerived().AlwaysRebuild() || Found != T->getFoundDecl() ||
6506 Underlying != T->getUnderlyingType()) {
6507 Result = getDerived().RebuildUsingType(Found, Underlying);
6508 if (Result.isNull())
6509 return QualType();
6510 }
6511
6512 TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc());
6513 return Result;
6514}
6515
6516template<typename Derived>
6517QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
6518 TypedefTypeLoc TL) {
6519 const TypedefType *T = TL.getTypePtr();
6520 TypedefNameDecl *Typedef
6521 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6522 T->getDecl()));
6523 if (!Typedef)
6524 return QualType();
6525
6526 QualType Result = TL.getType();
6527 if (getDerived().AlwaysRebuild() ||
6528 Typedef != T->getDecl()) {
6529 Result = getDerived().RebuildTypedefType(Typedef);
6530 if (Result.isNull())
6531 return QualType();
6532 }
6533
6534 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
6535 NewTL.setNameLoc(TL.getNameLoc());
6536
6537 return Result;
6538}
6539
6540template<typename Derived>
6541QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
6542 TypeOfExprTypeLoc TL) {
6543 // typeof expressions are not potentially evaluated contexts
6544 EnterExpressionEvaluationContext Unevaluated(
6547
6548 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6549 if (E.isInvalid())
6550 return QualType();
6551
6552 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6553 if (E.isInvalid())
6554 return QualType();
6555
6556 QualType Result = TL.getType();
6557 TypeOfKind Kind = Result->castAs<TypeOfExprType>()->getKind();
6558 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6559 Result =
6560 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6561 if (Result.isNull())
6562 return QualType();
6563 }
6564
6565 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6566 NewTL.setTypeofLoc(TL.getTypeofLoc());
6567 NewTL.setLParenLoc(TL.getLParenLoc());
6568 NewTL.setRParenLoc(TL.getRParenLoc());
6569
6570 return Result;
6571}
6572
6573template<typename Derived>
6574QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
6575 TypeOfTypeLoc TL) {
6576 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6577 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6578 if (!New_Under_TI)
6579 return QualType();
6580
6581 QualType Result = TL.getType();
6582 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6583 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6584 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6585 if (Result.isNull())
6586 return QualType();
6587 }
6588
6589 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6590 NewTL.setTypeofLoc(TL.getTypeofLoc());
6591 NewTL.setLParenLoc(TL.getLParenLoc());
6592 NewTL.setRParenLoc(TL.getRParenLoc());
6593 NewTL.setUnmodifiedTInfo(New_Under_TI);
6594
6595 return Result;
6596}
6597
6598template<typename Derived>
6599QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
6600 DecltypeTypeLoc TL) {
6601 const DecltypeType *T = TL.getTypePtr();
6602
6603 // decltype expressions are not potentially evaluated contexts
6604 EnterExpressionEvaluationContext Unevaluated(
6607
6608 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6609 if (E.isInvalid())
6610 return QualType();
6611
6612 E = getSema().ActOnDecltypeExpression(E.get());
6613 if (E.isInvalid())
6614 return QualType();
6615
6616 QualType Result = TL.getType();
6617 if (getDerived().AlwaysRebuild() ||
6618 E.get() != T->getUnderlyingExpr()) {
6619 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6620 if (Result.isNull())
6621 return QualType();
6622 }
6623 else E.get();
6624
6625 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6626 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6627 NewTL.setRParenLoc(TL.getRParenLoc());
6628 return Result;
6629}
6630
6631template <typename Derived>
6632QualType
6633TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
6634 PackIndexingTypeLoc TL) {
6635 // Transform the index
6636 ExprResult IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6637 if (IndexExpr.isInvalid())
6638 return QualType();
6639 QualType Pattern = TL.getPattern();
6640
6641 const PackIndexingType *PIT = TL.getTypePtr();
6642 SmallVector<QualType, 5> SubtitutedTypes;
6643 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6644
6645 bool NotYetExpanded = Types.empty();
6646 bool FullySubstituted = true;
6647
6648 if (Types.empty())
6649 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
6650
6651 for (const QualType &T : Types) {
6653 QualType Transformed = getDerived().TransformType(T);
6654 if (Transformed.isNull())
6655 return QualType();
6656 SubtitutedTypes.push_back(Transformed);
6657 continue;
6658 }
6659
6661 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
6662 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6663 // Determine whether the set of unexpanded parameter packs can and should
6664 // be expanded.
6665 bool ShouldExpand = true;
6666 bool RetainExpansion = false;
6667 std::optional<unsigned> OrigNumExpansions;
6668 std::optional<unsigned> NumExpansions = OrigNumExpansions;
6669 if (getDerived().TryExpandParameterPacks(TL.getEllipsisLoc(), SourceRange(),
6670 Unexpanded, ShouldExpand,
6671 RetainExpansion, NumExpansions))
6672 return QualType();
6673 if (!ShouldExpand) {
6674 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6675 // FIXME: should we keep TypeLoc for individual expansions in
6676 // PackIndexingTypeLoc?
6677 TypeSourceInfo *TI =
6678 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
6679 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
6680 if (Pack.isNull())
6681 return QualType();
6682 if (NotYetExpanded) {
6683 FullySubstituted = false;
6684 QualType Out = getDerived().RebuildPackIndexingType(
6685 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6686 FullySubstituted);
6687 if (Out.isNull())
6688 return QualType();
6689
6690 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6691 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6692 return Out;
6693 }
6694 SubtitutedTypes.push_back(Pack);
6695 continue;
6696 }
6697 for (unsigned I = 0; I != *NumExpansions; ++I) {
6698 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6699 QualType Out = getDerived().TransformType(T);
6700 if (Out.isNull())
6701 return QualType();
6702 SubtitutedTypes.push_back(Out);
6703 }
6704 // If we're supposed to retain a pack expansion, do so by temporarily
6705 // forgetting the partially-substituted parameter pack.
6706 if (RetainExpansion) {
6707 FullySubstituted = false;
6708 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6709 QualType Out = getDerived().TransformType(T);
6710 if (Out.isNull())
6711 return QualType();
6712 SubtitutedTypes.push_back(Out);
6713 }
6714 }
6715
6716 // A pack indexing type can appear in a larger pack expansion,
6717 // e.g. `Pack...[pack_of_indexes]...`
6718 // so we need to temporarily disable substitution of pack elements
6719 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6720 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
6721
6722 QualType Out = getDerived().RebuildPackIndexingType(
6723 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6724 FullySubstituted, SubtitutedTypes);
6725 if (Out.isNull())
6726 return Out;
6727
6728 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6729 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6730 return Out;
6731}
6732
6733template<typename Derived>
6734QualType TreeTransform<Derived>::TransformUnaryTransformType(
6735 TypeLocBuilder &TLB,
6736 UnaryTransformTypeLoc TL) {
6737 QualType Result = TL.getType();
6738 if (Result->isDependentType()) {
6739 const UnaryTransformType *T = TL.getTypePtr();
6740
6741 TypeSourceInfo *NewBaseTSI =
6742 getDerived().TransformType(TL.getUnderlyingTInfo());
6743 if (!NewBaseTSI)
6744 return QualType();
6745 QualType NewBase = NewBaseTSI->getType();
6746
6747 Result = getDerived().RebuildUnaryTransformType(NewBase,
6748 T->getUTTKind(),
6749 TL.getKWLoc());
6750 if (Result.isNull())
6751 return QualType();
6752 }
6753
6754 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
6755 NewTL.setKWLoc(TL.getKWLoc());
6756 NewTL.setParensRange(TL.getParensRange());
6757 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
6758 return Result;
6759}
6760
6761template<typename Derived>
6762QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
6763 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
6764 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
6765
6766 CXXScopeSpec SS;
6767 TemplateName TemplateName = getDerived().TransformTemplateName(
6768 SS, T->getTemplateName(), TL.getTemplateNameLoc());
6769 if (TemplateName.isNull())
6770 return QualType();
6771
6772 QualType OldDeduced = T->getDeducedType();
6773 QualType NewDeduced;
6774 if (!OldDeduced.isNull()) {
6775 NewDeduced = getDerived().TransformType(OldDeduced);
6776 if (NewDeduced.isNull())
6777 return QualType();
6778 }
6779
6780 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
6781 TemplateName, NewDeduced);
6782 if (Result.isNull())
6783 return QualType();
6784
6785 DeducedTemplateSpecializationTypeLoc NewTL =
6786 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
6787 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6788
6789 return Result;
6790}
6791
6792template<typename Derived>
6793QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
6794 RecordTypeLoc TL) {
6795 const RecordType *T = TL.getTypePtr();
6796 RecordDecl *Record
6797 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6798 T->getDecl()));
6799 if (!Record)
6800 return QualType();
6801
6802 QualType Result = TL.getType();
6803 if (getDerived().AlwaysRebuild() ||
6804 Record != T->getDecl()) {
6805 Result = getDerived().RebuildRecordType(Record);
6806 if (Result.isNull())
6807 return QualType();
6808 }
6809
6810 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
6811 NewTL.setNameLoc(TL.getNameLoc());
6812
6813 return Result;
6814}
6815
6816template<typename Derived>
6817QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
6818 EnumTypeLoc TL) {
6819 const EnumType *T = TL.getTypePtr();
6820 EnumDecl *Enum
6821 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6822 T->getDecl()));
6823 if (!Enum)
6824 return QualType();
6825
6826 QualType Result = TL.getType();
6827 if (getDerived().AlwaysRebuild() ||
6828 Enum != T->getDecl()) {
6829 Result = getDerived().RebuildEnumType(Enum);
6830 if (Result.isNull())
6831 return QualType();
6832 }
6833
6834 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
6835 NewTL.setNameLoc(TL.getNameLoc());
6836
6837 return Result;
6838}
6839
6840template<typename Derived>
6841QualType TreeTransform<Derived>::TransformInjectedClassNameType(
6842 TypeLocBuilder &TLB,
6843 InjectedClassNameTypeLoc TL) {
6844 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
6845 TL.getTypePtr()->getDecl());
6846 if (!D) return QualType();
6847
6848 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
6849 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
6850 return T;
6851}
6852
6853template<typename Derived>
6855 TypeLocBuilder &TLB,
6857 return getDerived().TransformTemplateTypeParmType(
6858 TLB, TL,
6859 /*SuppressObjCLifetime=*/false);
6860}
6861
6862template <typename Derived>
6864 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
6865 return TransformTypeSpecType(TLB, TL);
6866}
6867
6868template<typename Derived>
6869QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
6870 TypeLocBuilder &TLB,
6871 SubstTemplateTypeParmTypeLoc TL) {
6872 const SubstTemplateTypeParmType *T = TL.getTypePtr();
6873
6874 Decl *NewReplaced =
6875 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
6876
6877 // Substitute into the replacement type, which itself might involve something
6878 // that needs to be transformed. This only tends to occur with default
6879 // template arguments of template template parameters.
6880 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
6881 QualType Replacement = getDerived().TransformType(T->getReplacementType());
6882 if (Replacement.isNull())
6883 return QualType();
6884
6885 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
6886 Replacement, NewReplaced, T->getIndex(), T->getPackIndex());
6887
6888 // Propagate type-source information.
6889 SubstTemplateTypeParmTypeLoc NewTL
6890 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
6891 NewTL.setNameLoc(TL.getNameLoc());
6892 return Result;
6893
6894}
6895
6896template<typename Derived>
6898 TypeLocBuilder &TLB,
6900 return getDerived().TransformSubstTemplateTypeParmPackType(
6901 TLB, TL, /*SuppressObjCLifetime=*/false);
6902}
6903
6904template <typename Derived>
6907 return TransformTypeSpecType(TLB, TL);
6908}
6909
6910template<typename Derived>
6912 TypeLocBuilder &TLB,
6915
6916 // The nested-name-specifier never matters in a TemplateSpecializationType,
6917 // because we can't have a dependent nested-name-specifier anyway.
6918 CXXScopeSpec SS;
6919 TemplateName Template
6920 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
6921 TL.getTemplateNameLoc());
6922 if (Template.isNull())
6923 return QualType();
6924
6925 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
6926}
6927
6928template<typename Derived>
6930 AtomicTypeLoc TL) {
6931 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
6932 if (ValueType.isNull())
6933 return QualType();
6934
6935 QualType Result = TL.getType();
6936 if (getDerived().AlwaysRebuild() ||
6937 ValueType != TL.getValueLoc().getType()) {
6938 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
6939 if (Result.isNull())
6940 return QualType();
6941 }
6942
6943 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
6944 NewTL.setKWLoc(TL.getKWLoc());
6945 NewTL.setLParenLoc(TL.getLParenLoc());
6946 NewTL.setRParenLoc(TL.getRParenLoc());
6947
6948 return Result;
6949}
6950
6951template <typename Derived>
6952QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
6953 PipeTypeLoc TL) {
6954 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
6955 if (ValueType.isNull())
6956 return QualType();
6957
6958 QualType Result = TL.getType();
6959 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
6960 const PipeType *PT = Result->castAs<PipeType>();
6961 bool isReadPipe = PT->isReadOnly();
6962 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
6963 if (Result.isNull())
6964 return QualType();
6965 }
6966
6967 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
6968 NewTL.setKWLoc(TL.getKWLoc());
6969
6970 return Result;
6971}
6972
6973template <typename Derived>
6974QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
6975 BitIntTypeLoc TL) {
6976 const BitIntType *EIT = TL.getTypePtr();
6977 QualType Result = TL.getType();
6978
6979 if (getDerived().AlwaysRebuild()) {
6980 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
6981 EIT->getNumBits(), TL.getNameLoc());
6982 if (Result.isNull())
6983 return QualType();
6984 }
6985
6986 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
6987 NewTL.setNameLoc(TL.getNameLoc());
6988 return Result;
6989}
6990
6991template <typename Derived>
6992QualType TreeTransform<Derived>::TransformDependentBitIntType(
6993 TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) {
6994 const DependentBitIntType *EIT = TL.getTypePtr();
6995
6996 EnterExpressionEvaluationContext Unevaluated(
6998 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
6999 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7000
7001 if (BitsExpr.isInvalid())
7002 return QualType();
7003
7004 QualType Result = TL.getType();
7005
7006 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7007 Result = getDerived().RebuildDependentBitIntType(
7008 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7009
7010 if (Result.isNull())
7011 return QualType();
7012 }
7013
7014 if (isa<DependentBitIntType>(Result)) {
7015 DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
7016 NewTL.setNameLoc(TL.getNameLoc());
7017 } else {
7018 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7019 NewTL.setNameLoc(TL.getNameLoc());
7020 }
7021 return Result;
7022}
7023
7024 /// Simple iterator that traverses the template arguments in a
7025 /// container that provides a \c getArgLoc() member function.
7026 ///
7027 /// This iterator is intended to be used with the iterator form of
7028 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7029 template<typename ArgLocContainer>
7031 ArgLocContainer *Container;
7032 unsigned Index;
7033
7034 public:
7037 typedef int difference_type;
7038 typedef std::input_iterator_tag iterator_category;
7039
7040 class pointer {
7042
7043 public:
7044 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7045
7047 return &Arg;
7048 }
7049 };
7050
7051
7053
7054 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7055 unsigned Index)
7056 : Container(&Container), Index(Index) { }
7057
7059 ++Index;
7060 return *this;
7061 }
7062
7065 ++(*this);
7066 return Old;
7067 }
7068
7070 return Container->getArgLoc(Index);
7071 }
7072
7074 return pointer(Container->getArgLoc(Index));
7075 }
7076
7079 return X.Container == Y.Container && X.Index == Y.Index;
7080 }
7081
7084 return !(X == Y);
7085 }
7086 };
7087
7088template<typename Derived>
7089QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7090 AutoTypeLoc TL) {
7091 const AutoType *T = TL.getTypePtr();
7092 QualType OldDeduced = T->getDeducedType();
7093 QualType NewDeduced;
7094 if (!OldDeduced.isNull()) {
7095 NewDeduced = getDerived().TransformType(OldDeduced);
7096 if (NewDeduced.isNull())
7097 return QualType();
7098 }
7099
7100 ConceptDecl *NewCD = nullptr;
7101 TemplateArgumentListInfo NewTemplateArgs;
7102 NestedNameSpecifierLoc NewNestedNameSpec;
7103 if (T->isConstrained()) {
7104 assert(TL.getConceptReference());
7105 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7106 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7107
7108 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7109 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7110 typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator;
7111 if (getDerived().TransformTemplateArguments(
7112 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7113 NewTemplateArgs))
7114 return QualType();
7115
7116 if (TL.getNestedNameSpecifierLoc()) {
7117 NewNestedNameSpec
7118 = getDerived().TransformNestedNameSpecifierLoc(
7119 TL.getNestedNameSpecifierLoc());
7120 if (!NewNestedNameSpec)
7121 return QualType();
7122 }
7123 }
7124
7125 QualType Result = TL.getType();
7126 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7127 T->isDependentType() || T->isConstrained()) {
7128 // FIXME: Maybe don't rebuild if all template arguments are the same.
7130 NewArgList.reserve(NewTemplateArgs.size());
7131 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7132 NewArgList.push_back(ArgLoc.getArgument());
7133 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7134 NewArgList);
7135 if (Result.isNull())
7136 return QualType();
7137 }
7138
7139 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7140 NewTL.setNameLoc(TL.getNameLoc());
7141 NewTL.setRParenLoc(TL.getRParenLoc());
7142 NewTL.setConceptReference(nullptr);
7143
7144 if (T->isConstrained()) {
7145 DeclarationNameInfo DNI = DeclarationNameInfo(
7146 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7147 TL.getConceptNameLoc(),
7148 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7149 auto *CR = ConceptReference::Create(
7150 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7151 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7152 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7153 NewTL.setConceptReference(CR);
7154 }
7155
7156 return Result;
7157}
7158
7159template <typename Derived>
7161 TypeLocBuilder &TLB,
7162 TemplateSpecializationTypeLoc TL,
7163 TemplateName Template) {
7164 TemplateArgumentListInfo NewTemplateArgs;
7165 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7166 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7167 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
7168 ArgIterator;
7169 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7170 ArgIterator(TL, TL.getNumArgs()),
7171 NewTemplateArgs))
7172 return QualType();
7173
7174 // FIXME: maybe don't rebuild if all the template arguments are the same.
7175
7176 QualType Result =
7177 getDerived().RebuildTemplateSpecializationType(Template,
7178 TL.getTemplateNameLoc(),
7179 NewTemplateArgs);
7180
7181 if (!Result.isNull()) {
7182 // Specializations of template template parameters are represented as
7183 // TemplateSpecializationTypes, and substitution of type alias templates
7184 // within a dependent context can transform them into
7185 // DependentTemplateSpecializationTypes.
7186 if (isa<DependentTemplateSpecializationType>(Result)) {
7187 DependentTemplateSpecializationTypeLoc NewTL
7188 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
7189 NewTL.setElaboratedKeywordLoc(SourceLocation());
7190 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
7191 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7192 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7193 NewTL.setLAngleLoc(TL.getLAngleLoc());
7194 NewTL.setRAngleLoc(TL.getRAngleLoc());
7195 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7196 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7197 return Result;
7198 }
7199
7200 TemplateSpecializationTypeLoc NewTL
7201 = TLB.push<TemplateSpecializationTypeLoc>(Result);
7202 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7203 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7204 NewTL.setLAngleLoc(TL.getLAngleLoc());
7205 NewTL.setRAngleLoc(TL.getRAngleLoc());
7206 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7207 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7208 }
7209
7210 return Result;
7211}
7212
7213template <typename Derived>
7215 TypeLocBuilder &TLB,
7217 TemplateName Template,
7218 CXXScopeSpec &SS) {
7219 TemplateArgumentListInfo NewTemplateArgs;
7220 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7221 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7224 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7225 ArgIterator(TL, TL.getNumArgs()),
7226 NewTemplateArgs))
7227 return QualType();
7228
7229 // FIXME: maybe don't rebuild if all the template arguments are the same.
7230
7231 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
7232 QualType Result = getSema().Context.getDependentTemplateSpecializationType(
7233 TL.getTypePtr()->getKeyword(), DTN->getQualifier(),
7234 DTN->getIdentifier(), NewTemplateArgs.arguments());
7235
7239 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
7242 NewTL.setLAngleLoc(TL.getLAngleLoc());
7243 NewTL.setRAngleLoc(TL.getRAngleLoc());
7244 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7245 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7246 return Result;
7247 }
7248
7250 = getDerived().RebuildTemplateSpecializationType(Template,
7251 TL.getTemplateNameLoc(),
7252 NewTemplateArgs);
7253
7254 if (!Result.isNull()) {
7255 /// FIXME: Wrap this in an elaborated-type-specifier?
7260 NewTL.setLAngleLoc(TL.getLAngleLoc());
7261 NewTL.setRAngleLoc(TL.getRAngleLoc());
7262 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7263 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7264 }
7265
7266 return Result;
7267}
7268
7269template<typename Derived>
7272 ElaboratedTypeLoc TL) {
7273 const ElaboratedType *T = TL.getTypePtr();
7274
7275 NestedNameSpecifierLoc QualifierLoc;
7276 // NOTE: the qualifier in an ElaboratedType is optional.
7277 if (TL.getQualifierLoc()) {
7278 QualifierLoc
7279 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7280 if (!QualifierLoc)
7281 return QualType();
7282 }
7283
7284 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
7285 if (NamedT.isNull())
7286 return QualType();
7287
7288 // C++0x [dcl.type.elab]p2:
7289 // If the identifier resolves to a typedef-name or the simple-template-id
7290 // resolves to an alias template specialization, the
7291 // elaborated-type-specifier is ill-formed.
7292 if (T->getKeyword() != ElaboratedTypeKeyword::None &&
7293 T->getKeyword() != ElaboratedTypeKeyword::Typename) {
7294 if (const TemplateSpecializationType *TST =
7295 NamedT->getAs<TemplateSpecializationType>()) {
7296 TemplateName Template = TST->getTemplateName();
7297 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
7298 Template.getAsTemplateDecl())) {
7299 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
7300 diag::err_tag_reference_non_tag)
7302 << llvm::to_underlying(
7304 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
7305 }
7306 }
7307 }
7308
7309 QualType Result = TL.getType();
7310 if (getDerived().AlwaysRebuild() ||
7311 QualifierLoc != TL.getQualifierLoc() ||
7312 NamedT != T->getNamedType()) {
7313 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
7314 T->getKeyword(),
7315 QualifierLoc, NamedT);
7316 if (Result.isNull())
7317 return QualType();
7318 }
7319
7320 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7321 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7322 NewTL.setQualifierLoc(QualifierLoc);
7323 return Result;
7324}
7325
7326template <typename Derived>
7327template <typename Fn>
7329 TypeLocBuilder &TLB, AttributedTypeLoc TL, Fn TransformModifiedTypeFn) {
7330 const AttributedType *oldType = TL.getTypePtr();
7331 QualType modifiedType = TransformModifiedTypeFn(TLB, TL.getModifiedLoc());
7332 if (modifiedType.isNull())
7333 return QualType();
7334
7335 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7336 const Attr *oldAttr = TL.getAttr();
7337 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7338 if (oldAttr && !newAttr)
7339 return QualType();
7340
7341 QualType result = TL.getType();
7342
7343 // FIXME: dependent operand expressions?
7344 if (getDerived().AlwaysRebuild() ||
7345 modifiedType != oldType->getModifiedType()) {
7346 TypeLocBuilder AuxiliaryTLB;
7347 AuxiliaryTLB.reserve(TL.getFullDataSize());
7348 QualType equivalentType =
7349 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7350 if (equivalentType.isNull())
7351 return QualType();
7352
7353 // Check whether we can add nullability; it is only represented as
7354 // type sugar, and therefore cannot be diagnosed in any other way.
7355 if (auto nullability = oldType->getImmediateNullability()) {
7356 if (!modifiedType->canHaveNullability()) {
7357 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7358 : TL.getModifiedLoc().getBeginLoc()),
7359 diag::err_nullability_nonpointer)
7360 << DiagNullabilityKind(*nullability, false) << modifiedType;
7361 return QualType();
7362 }
7363 }
7364
7365 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7366 modifiedType,
7367 equivalentType);
7368 }
7369
7370 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7371 newTL.setAttr(newAttr);
7372 return result;
7373}
7374
7375template <typename Derived>
7377 AttributedTypeLoc TL) {
7378 return getDerived().TransformAttributedType(
7379 TLB, TL, [&](TypeLocBuilder &TLB, TypeLoc ModifiedLoc) -> QualType {
7380 return getDerived().TransformType(TLB, ModifiedLoc);
7381 });
7382}
7383
7384template <typename Derived>
7387 const CountAttributedType *OldTy = TL.getTypePtr();
7388 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7389 if (InnerTy.isNull())
7390 return QualType();
7391
7392 Expr *OldCount = TL.getCountExpr();
7393 Expr *NewCount = nullptr;
7394 if (OldCount) {
7395 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7396 if (CountResult.isInvalid())
7397 return QualType();
7398 NewCount = CountResult.get();
7399 }
7400
7401 QualType Result = TL.getType();
7402 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7403 OldCount != NewCount) {
7404 // Currently, CountAttributedType can only wrap incomplete array types.
7406 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7407 }
7408
7409 TLB.push<CountAttributedTypeLoc>(Result);
7410 return Result;
7411}
7412
7413template <typename Derived>
7414QualType TreeTransform<Derived>::TransformBTFTagAttributedType(
7415 TypeLocBuilder &TLB, BTFTagAttributedTypeLoc TL) {
7416 // The BTFTagAttributedType is available for C only.
7417 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7418}
7419
7420template<typename Derived>
7421QualType
7422TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
7423 ParenTypeLoc TL) {
7424 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7425 if (Inner.isNull())
7426 return QualType();
7427
7428 QualType Result = TL.getType();
7429 if (getDerived().AlwaysRebuild() ||
7430 Inner != TL.getInnerLoc().getType()) {
7431 Result = getDerived().RebuildParenType(Inner);
7432 if (Result.isNull())
7433 return QualType();
7434 }
7435
7436 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7437 NewTL.setLParenLoc(TL.getLParenLoc());
7438 NewTL.setRParenLoc(TL.getRParenLoc());
7439 return Result;
7440}
7441
7442template <typename Derived>
7443QualType
7444TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
7445 MacroQualifiedTypeLoc TL) {
7446 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7447 if (Inner.isNull())
7448 return QualType();
7449
7450 QualType Result = TL.getType();
7451 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7452 Result =
7453 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7454 if (Result.isNull())
7455 return QualType();
7456 }
7457
7458 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
7459 NewTL.setExpansionLoc(TL.getExpansionLoc());
7460 return Result;
7461}
7462
7463template<typename Derived>
7464QualType TreeTransform<Derived>::TransformDependentNameType(
7465 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
7466 return TransformDependentNameType(TLB, TL, false);
7467}
7468
7469template<typename Derived>
7470QualType TreeTransform<Derived>::TransformDependentNameType(
7471 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
7472 const DependentNameType *T = TL.getTypePtr();
7473
7474 NestedNameSpecifierLoc QualifierLoc
7475 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7476 if (!QualifierLoc)
7477 return QualType();
7478
7479 QualType Result
7480 = getDerived().RebuildDependentNameType(T->getKeyword(),
7481 TL.getElaboratedKeywordLoc(),
7482 QualifierLoc,
7483 T->getIdentifier(),
7484 TL.getNameLoc(),
7485 DeducedTSTContext);
7486 if (Result.isNull())
7487 return QualType();
7488
7489 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
7490 QualType NamedT = ElabT->getNamedType();
7491 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
7492
7493 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7494 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7495 NewTL.setQualifierLoc(QualifierLoc);
7496 } else {
7497 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
7498 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7499 NewTL.setQualifierLoc(QualifierLoc);
7500 NewTL.setNameLoc(TL.getNameLoc());
7501 }
7502 return Result;
7503}
7504
7505template<typename Derived>
7508 DependentTemplateSpecializationTypeLoc TL) {
7509 NestedNameSpecifierLoc QualifierLoc;
7510 if (TL.getQualifierLoc()) {
7511 QualifierLoc
7512 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7513 if (!QualifierLoc)
7514 return QualType();
7515 }
7516
7517 return getDerived()
7518 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
7519}
7520
7521template<typename Derived>
7525 NestedNameSpecifierLoc QualifierLoc) {
7527
7528 TemplateArgumentListInfo NewTemplateArgs;
7529 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7530 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7531
7534 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7535 ArgIterator(TL, TL.getNumArgs()),
7536 NewTemplateArgs))
7537 return QualType();
7538
7539 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
7540 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
7541 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
7542 /*AllowInjectedClassName*/ false);
7543 if (Result.isNull())
7544 return QualType();
7545
7546 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
7547 QualType NamedT = ElabT->getNamedType();
7548
7549 // Copy information relevant to the template specialization.
7551 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
7554 NamedTL.setLAngleLoc(TL.getLAngleLoc());
7555 NamedTL.setRAngleLoc(TL.getRAngleLoc());
7556 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7557 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7558
7559 // Copy information relevant to the elaborated type.
7562 NewTL.setQualifierLoc(QualifierLoc);
7563 } else if (isa<DependentTemplateSpecializationType>(Result)) {
7567 SpecTL.setQualifierLoc(QualifierLoc);
7570 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7571 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7572 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7573 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7574 } else {
7579 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7580 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7581 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7582 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7583 }
7584 return Result;
7585}
7586
7587template<typename Derived>
7590 QualType Pattern
7591 = getDerived().TransformType(TLB, TL.getPatternLoc());
7592 if (Pattern.isNull())
7593 return QualType();
7594
7595 QualType Result = TL.getType();
7596 if (getDerived().AlwaysRebuild() ||
7597 Pattern != TL.getPatternLoc().getType()) {
7598 Result = getDerived().RebuildPackExpansionType(Pattern,
7600 TL.getEllipsisLoc(),
7602 if (Result.isNull())
7603 return QualType();
7604 }
7605
7606 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
7607 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7608 return Result;
7609}
7610
7611template<typename Derived>
7612QualType
7613TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
7614 ObjCInterfaceTypeLoc TL) {
7615 // ObjCInterfaceType is never dependent.
7616 TLB.pushFullCopy(TL);
7617 return TL.getType();
7618}
7619
7620template<typename Derived>
7621QualType
7622TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
7623 ObjCTypeParamTypeLoc TL) {
7624 const ObjCTypeParamType *T = TL.getTypePtr();
7625 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7626 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7627 if (!OTP)
7628 return QualType();
7629
7630 QualType Result = TL.getType();
7631 if (getDerived().AlwaysRebuild() ||
7632 OTP != T->getDecl()) {
7633 Result = getDerived().RebuildObjCTypeParamType(
7634 OTP, TL.getProtocolLAngleLoc(),
7635 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7636 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7637 if (Result.isNull())
7638 return QualType();
7639 }
7640
7641 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
7642 if (TL.getNumProtocols()) {
7643 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7644 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7645 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7646 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7647 }
7648 return Result;
7649}
7650
7651template<typename Derived>
7652QualType
7653TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
7654 ObjCObjectTypeLoc TL) {
7655 // Transform base type.
7656 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7657 if (BaseType.isNull())
7658 return QualType();
7659
7660 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7661
7662 // Transform type arguments.
7663 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7664 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7665 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7666 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7667 QualType TypeArg = TypeArgInfo->getType();
7668 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7669 AnyChanged = true;
7670
7671 // We have a pack expansion. Instantiate it.
7672 const auto *PackExpansion = PackExpansionLoc.getType()
7673 ->castAs<PackExpansionType>();
7675 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7676 Unexpanded);
7677 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7678
7679 // Determine whether the set of unexpanded parameter packs can
7680 // and should be expanded.
7681 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7682 bool Expand = false;
7683 bool RetainExpansion = false;
7684 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
7685 if (getDerived().TryExpandParameterPacks(
7686 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7687 Unexpanded, Expand, RetainExpansion, NumExpansions))
7688 return QualType();
7689
7690 if (!Expand) {
7691 // We can't expand this pack expansion into separate arguments yet;
7692 // just substitute into the pattern and create a new pack expansion
7693 // type.
7694 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7695
7696 TypeLocBuilder TypeArgBuilder;
7697 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7698 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7699 PatternLoc);
7700 if (NewPatternType.isNull())
7701 return QualType();
7702
7703 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7704 NewPatternType, NumExpansions);
7705 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7706 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7707 NewTypeArgInfos.push_back(
7708 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7709 continue;
7710 }
7711
7712 // Substitute into the pack expansion pattern for each slice of the
7713 // pack.
7714 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7715 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
7716
7717 TypeLocBuilder TypeArgBuilder;
7718 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7719
7720 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7721 PatternLoc);
7722 if (NewTypeArg.isNull())
7723 return QualType();
7724
7725 NewTypeArgInfos.push_back(
7726 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7727 }
7728
7729 continue;
7730 }
7731
7732 TypeLocBuilder TypeArgBuilder;
7733 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7734 QualType NewTypeArg =
7735 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7736 if (NewTypeArg.isNull())
7737 return QualType();
7738
7739 // If nothing changed, just keep the old TypeSourceInfo.
7740 if (NewTypeArg == TypeArg) {
7741 NewTypeArgInfos.push_back(TypeArgInfo);
7742 continue;
7743 }
7744
7745 NewTypeArgInfos.push_back(
7746 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7747 AnyChanged = true;
7748 }
7749
7750 QualType Result = TL.getType();
7751 if (getDerived().AlwaysRebuild() || AnyChanged) {
7752 // Rebuild the type.
7753 Result = getDerived().RebuildObjCObjectType(
7754 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
7755 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
7756 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7757 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7758
7759 if (Result.isNull())
7760 return QualType();
7761 }
7762
7763 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
7764 NewT.setHasBaseTypeAsWritten(true);
7765 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
7766 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
7767 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
7768 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
7769 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7770 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7771 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
7772 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7773 return Result;
7774}
7775
7776template<typename Derived>
7777QualType
7778TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
7779 ObjCObjectPointerTypeLoc TL) {
7780 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7781 if (PointeeType.isNull())
7782 return QualType();
7783
7784 QualType Result = TL.getType();
7785 if (getDerived().AlwaysRebuild() ||
7786 PointeeType != TL.getPointeeLoc().getType()) {
7787 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7788 TL.getStarLoc());
7789 if (Result.isNull())
7790 return QualType();
7791 }
7792
7793 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
7794 NewT.setStarLoc(TL.getStarLoc());
7795 return Result;
7796}
7797
7798//===----------------------------------------------------------------------===//
7799// Statement transformation
7800//===----------------------------------------------------------------------===//
7801template<typename Derived>
7803TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
7804 return S;
7805}
7806
7807template<typename Derived>
7810 return getDerived().TransformCompoundStmt(S, false);
7811}
7812
7813template<typename Derived>
7816 bool IsStmtExpr) {
7817 Sema::CompoundScopeRAII CompoundScope(getSema());
7818 Sema::FPFeaturesStateRAII FPSave(getSema());
7819 if (S->hasStoredFPFeatures())
7820 getSema().resetFPOptions(
7821 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
7822
7823 const Stmt *ExprResult = S->getStmtExprResult();
7824 bool SubStmtInvalid = false;
7825 bool SubStmtChanged = false;
7826 SmallVector<Stmt*, 8> Statements;
7827 for (auto *B : S->body()) {
7828 StmtResult Result = getDerived().TransformStmt(
7829 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
7830
7831 if (Result.isInvalid()) {
7832 // Immediately fail if this was a DeclStmt, since it's very
7833 // likely that this will cause problems for future statements.
7834 if (isa<DeclStmt>(B))
7835 return StmtError();
7836
7837 // Otherwise, just keep processing substatements and fail later.
7838 SubStmtInvalid = true;
7839 continue;
7840 }
7841
7842 SubStmtChanged = SubStmtChanged || Result.get() != B;
7843 Statements.push_back(Result.getAs<Stmt>());
7844 }
7845
7846 if (SubStmtInvalid)
7847 return StmtError();
7848
7849 if (!getDerived().AlwaysRebuild() &&
7850 !SubStmtChanged)
7851 return S;
7852
7853 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
7854 Statements,
7855 S->getRBracLoc(),
7856 IsStmtExpr);
7857}
7858
7859template<typename Derived>
7861TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
7862 ExprResult LHS, RHS;
7863 {
7864 EnterExpressionEvaluationContext Unevaluated(
7866
7867 // Transform the left-hand case value.
7868 LHS = getDerived().TransformExpr(S->getLHS());
7869 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
7870 if (LHS.isInvalid())
7871 return StmtError();
7872
7873 // Transform the right-hand case value (for the GNU case-range extension).
7874 RHS = getDerived().TransformExpr(S->getRHS());
7875 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
7876 if (RHS.isInvalid())
7877 return StmtError();
7878 }
7879
7880 // Build the case statement.
7881 // Case statements are always rebuilt so that they will attached to their
7882 // transformed switch statement.
7883 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
7884 LHS.get(),
7885 S->getEllipsisLoc(),
7886 RHS.get(),
7887 S->getColonLoc());
7888 if (Case.isInvalid())
7889 return StmtError();
7890
7891 // Transform the statement following the case
7892 StmtResult SubStmt =
7893 getDerived().TransformStmt(S->getSubStmt());
7894 if (SubStmt.isInvalid())
7895 return StmtError();
7896
7897 // Attach the body to the case statement
7898 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
7899}
7900
7901template <typename Derived>
7902StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
7903 // Transform the statement following the default case
7904 StmtResult SubStmt =
7905 getDerived().TransformStmt(S->getSubStmt());
7906 if (SubStmt.isInvalid())
7907 return StmtError();
7908
7909 // Default statements are always rebuilt
7910 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
7911 SubStmt.get());
7912}
7913
7914template<typename Derived>
7916TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
7917 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
7918 if (SubStmt.isInvalid())
7919 return StmtError();
7920
7921 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
7922 S->getDecl());
7923 if (!LD)
7924 return StmtError();
7925
7926 // If we're transforming "in-place" (we're not creating new local
7927 // declarations), assume we're replacing the old label statement
7928 // and clear out the reference to it.
7929 if (LD == S->getDecl())
7930 S->getDecl()->setStmt(nullptr);
7931
7932 // FIXME: Pass the real colon location in.
7933 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
7934 cast<LabelDecl>(LD), SourceLocation(),
7935 SubStmt.get());
7936}
7937
7938template <typename Derived>
7940 if (!R)
7941 return R;
7942
7943 switch (R->getKind()) {
7944// Transform attributes by calling TransformXXXAttr.
7945#define ATTR(X) \
7946 case attr::X: \
7947 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
7948#include "clang/Basic/AttrList.inc"
7949 }
7950 return R;
7951}
7952
7953template <typename Derived>
7955 const Stmt *InstS,
7956 const Attr *R) {
7957 if (!R)
7958 return R;
7959
7960 switch (R->getKind()) {
7961// Transform attributes by calling TransformStmtXXXAttr.
7962#define ATTR(X) \
7963 case attr::X: \
7964 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
7965#include "clang/Basic/AttrList.inc"
7966 }
7967 return TransformAttr(R);
7968}
7969
7970template <typename Derived>
7973 StmtDiscardKind SDK) {
7974 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
7975 if (SubStmt.isInvalid())
7976 return StmtError();
7977
7978 bool AttrsChanged = false;
7980
7981 // Visit attributes and keep track if any are transformed.
7982 for (const auto *I : S->getAttrs()) {
7983 const Attr *R =
7984 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
7985 AttrsChanged |= (I != R);
7986 if (R)
7987 Attrs.push_back(R);
7988 }
7989
7990 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
7991 return S;
7992
7993 // If transforming the attributes failed for all of the attributes in the
7994 // statement, don't make an AttributedStmt without attributes.
7995 if (Attrs.empty())
7996 return SubStmt;
7997
7998 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
7999 SubStmt.get());
8000}
8001
8002template<typename Derived>
8004TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
8005 // Transform the initialization statement
8006 StmtResult Init = getDerived().TransformStmt(S->getInit());
8007 if (Init.isInvalid())
8008 return StmtError();
8009
8010 Sema::ConditionResult Cond;
8011 if (!S->isConsteval()) {
8012 // Transform the condition
8013 Cond = getDerived().TransformCondition(
8014 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8015 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8017 if (Cond.isInvalid())
8018 return StmtError();
8019 }
8020
8021 // If this is a constexpr if, determine which arm we should instantiate.
8022 std::optional<bool> ConstexprConditionValue;
8023 if (S->isConstexpr())
8024 ConstexprConditionValue = Cond.getKnownValue();
8025
8026 // Transform the "then" branch.
8027 StmtResult Then;
8028 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8029 EnterExpressionEvaluationContext Ctx(
8032 S->isNonNegatedConsteval());
8033
8034 Then = getDerived().TransformStmt(S->getThen());
8035 if (Then.isInvalid())
8036 return StmtError();
8037 } else {
8038 // Discarded branch is replaced with empty CompoundStmt so we can keep
8039 // proper source location for start and end of original branch, so
8040 // subsequent transformations like CoverageMapping work properly
8041 Then = new (getSema().Context)
8042 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8043 }
8044
8045 // Transform the "else" branch.
8046 StmtResult Else;
8047 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8048 EnterExpressionEvaluationContext Ctx(
8051 S->isNegatedConsteval());
8052
8053 Else = getDerived().TransformStmt(S->getElse());
8054 if (Else.isInvalid())
8055 return StmtError();
8056 } else if (S->getElse() && ConstexprConditionValue &&
8057 *ConstexprConditionValue) {
8058 // Same thing here as with <then> branch, we are discarding it, we can't
8059 // replace it with NULL nor NullStmt as we need to keep for source location
8060 // range, for CoverageMapping
8061 Else = new (getSema().Context)
8062 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8063 }
8064
8065 if (!getDerived().AlwaysRebuild() &&
8066 Init.get() == S->getInit() &&
8067 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8068 Then.get() == S->getThen() &&
8069 Else.get() == S->getElse())
8070 return S;
8071
8072 return getDerived().RebuildIfStmt(
8073 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8074 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8075}
8076
8077template<typename Derived>
8079TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
8080 // Transform the initialization statement
8081 StmtResult Init = getDerived().TransformStmt(S->getInit());
8082 if (Init.isInvalid())
8083 return StmtError();
8084
8085 // Transform the condition.
8086 Sema::ConditionResult Cond = getDerived().TransformCondition(
8087 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8089 if (Cond.isInvalid())
8090 return StmtError();
8091
8092 // Rebuild the switch statement.
8094 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8095 Init.get(), Cond, S->getRParenLoc());
8096 if (Switch.isInvalid())
8097 return StmtError();
8098
8099 // Transform the body of the switch statement.
8100 StmtResult Body = getDerived().TransformStmt(S->getBody());
8101 if (Body.isInvalid())
8102 return StmtError();
8103
8104 // Complete the switch statement.
8105 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8106 Body.get());
8107}
8108
8109template<typename Derived>
8111TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
8112 // Transform the condition
8113 Sema::ConditionResult Cond = getDerived().TransformCondition(
8114 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8116 if (Cond.isInvalid())
8117 return StmtError();
8118
8119 // Transform the body
8120 StmtResult Body = getDerived().TransformStmt(S->getBody());
8121 if (Body.isInvalid())
8122 return StmtError();
8123
8124 if (!getDerived().AlwaysRebuild() &&
8125 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8126 Body.get() == S->getBody())
8127 return Owned(S);
8128
8129 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8130 Cond, S->getRParenLoc(), Body.get());
8131}
8132
8133template<typename Derived>
8135TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
8136 // Transform the body
8137 StmtResult Body = getDerived().TransformStmt(S->getBody());
8138 if (Body.isInvalid())
8139 return StmtError();
8140
8141 // Transform the condition
8142 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8143 if (Cond.isInvalid())
8144 return StmtError();
8145
8146 if (!getDerived().AlwaysRebuild() &&
8147 Cond.get() == S->getCond() &&
8148 Body.get() == S->getBody())
8149 return S;
8150
8151 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8152 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8153 S->getRParenLoc());
8154}
8155
8156template<typename Derived>
8158TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
8159 if (getSema().getLangOpts().OpenMP)
8160 getSema().OpenMP().startOpenMPLoop();
8161
8162 // Transform the initialization statement
8163 StmtResult Init = getDerived().TransformStmt(S->getInit());
8164 if (Init.isInvalid())
8165 return StmtError();
8166
8167 // In OpenMP loop region loop control variable must be captured and be
8168 // private. Perform analysis of first part (if any).
8169 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8170 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8171 Init.get());
8172
8173 // Transform the condition
8174 Sema::ConditionResult Cond = getDerived().TransformCondition(
8175 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8177 if (Cond.isInvalid())
8178 return StmtError();
8179
8180 // Transform the increment
8181 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8182 if (Inc.isInvalid())
8183 return StmtError();
8184
8185 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8186 if (S->getInc() && !FullInc.get())
8187 return StmtError();
8188
8189 // Transform the body
8190 StmtResult Body = getDerived().TransformStmt(S->getBody());
8191 if (Body.isInvalid())
8192 return StmtError();
8193
8194 if (!getDerived().AlwaysRebuild() &&
8195 Init.get() == S->getInit() &&
8196 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8197 Inc.get() == S->getInc() &&
8198 Body.get() == S->getBody())
8199 return S;
8200
8201 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8202 Init.get(), Cond, FullInc,
8203 S->getRParenLoc(), Body.get());
8204}
8205
8206template<typename Derived>
8208TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
8209 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8210 S->getLabel());
8211 if (!LD)
8212 return StmtError();
8213
8214 // Goto statements must always be rebuilt, to resolve the label.
8215 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8216 cast<LabelDecl>(LD));
8217}
8218
8219template<typename Derived>
8221TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
8222 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8223 if (Target.isInvalid())
8224 return StmtError();
8225 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8226
8227 if (!getDerived().AlwaysRebuild() &&
8228 Target.get() == S->getTarget())
8229 return S;
8230
8231 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8232 Target.get());
8233}
8234
8235template<typename Derived>
8237TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
8238 return S;
8239}
8240
8241template<typename Derived>
8243TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
8244 return S;
8245}
8246
8247template<typename Derived>
8249TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
8250 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8251 /*NotCopyInit*/false);
8252 if (Result.isInvalid())
8253 return StmtError();
8254
8255 // FIXME: We always rebuild the return statement because there is no way
8256 // to tell whether the return type of the function has changed.
8257 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8258}
8259
8260template<typename Derived>
8262TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
8263 bool DeclChanged = false;
8265 for (auto *D : S->decls()) {
8266 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8267 if (!Transformed)
8268 return StmtError();
8269
8270 if (Transformed != D)
8271 DeclChanged = true;
8272
8273 Decls.push_back(Transformed);
8274 }
8275
8276 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8277 return S;
8278
8279 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8280}
8281
8282template<typename Derived>
8284TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
8285
8286 SmallVector<Expr*, 8> Constraints;
8289
8290 ExprResult AsmString;
8291 SmallVector<Expr*, 8> Clobbers;
8292
8293 bool ExprsChanged = false;
8294
8295 // Go through the outputs.
8296 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8297 Names.push_back(S->getOutputIdentifier(I));
8298
8299 // No need to transform the constraint literal.
8300 Constraints.push_back(S->getOutputConstraintLiteral(I));
8301
8302 // Transform the output expr.
8303 Expr *OutputExpr = S->getOutputExpr(I);
8304 ExprResult Result = getDerived().TransformExpr(OutputExpr);
8305 if (Result.isInvalid())
8306 return StmtError();
8307
8308 ExprsChanged |= Result.get() != OutputExpr;
8309
8310 Exprs.push_back(Result.get());
8311 }
8312
8313 // Go through the inputs.
8314 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8315 Names.push_back(S->getInputIdentifier(I));
8316
8317 // No need to transform the constraint literal.
8318 Constraints.push_back(S->getInputConstraintLiteral(I));
8319
8320 // Transform the input expr.
8321 Expr *InputExpr = S->getInputExpr(I);
8322 ExprResult Result = getDerived().TransformExpr(InputExpr);
8323 if (Result.isInvalid())
8324 return StmtError();
8325
8326 ExprsChanged |= Result.get() != InputExpr;
8327
8328 Exprs.push_back(Result.get());
8329 }
8330
8331 // Go through the Labels.
8332 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8333 Names.push_back(S->getLabelIdentifier(I));
8334
8335 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8336 if (Result.isInvalid())
8337 return StmtError();
8338 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8339 Exprs.push_back(Result.get());
8340 }
8341 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8342 return S;
8343
8344 // Go through the clobbers.
8345 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
8346 Clobbers.push_back(S->getClobberStringLiteral(I));
8347
8348 // No need to transform the asm string literal.
8349 AsmString = S->getAsmString();
8350 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8351 S->isVolatile(), S->getNumOutputs(),
8352 S->getNumInputs(), Names.data(),
8353 Constraints, Exprs, AsmString.get(),
8354 Clobbers, S->getNumLabels(),
8355 S->getRParenLoc());
8356}
8357
8358template<typename Derived>
8360TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
8361 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8362
8363 bool HadError = false, HadChange = false;
8364
8365 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8366 SmallVector<Expr*, 8> TransformedExprs;
8367 TransformedExprs.reserve(SrcExprs.size());
8368 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8369 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8370 if (!Result.isUsable()) {
8371 HadError = true;
8372 } else {
8373 HadChange |= (Result.get() != SrcExprs[i]);
8374 TransformedExprs.push_back(Result.get());
8375 }
8376 }
8377
8378 if (HadError) return StmtError();
8379 if (!HadChange && !getDerived().AlwaysRebuild())
8380 return Owned(S);
8381
8382 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8383 AsmToks, S->getAsmString(),
8384 S->getNumOutputs(), S->getNumInputs(),
8385 S->getAllConstraints(), S->getClobbers(),
8386 TransformedExprs, S->getEndLoc());
8387}
8388
8389// C++ Coroutines
8390template<typename Derived>
8392TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
8393 auto *ScopeInfo = SemaRef.getCurFunction();
8394 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8395 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8396 ScopeInfo->NeedsCoroutineSuspends &&
8397 ScopeInfo->CoroutineSuspends.first == nullptr &&
8398 ScopeInfo->CoroutineSuspends.second == nullptr &&
8399 "expected clean scope info");
8400
8401 // Set that we have (possibly-invalid) suspend points before we do anything
8402 // that may fail.
8403 ScopeInfo->setNeedsCoroutineSuspends(false);
8404
8405 // We re-build the coroutine promise object (and the coroutine parameters its
8406 // type and constructor depend on) based on the types used in our current
8407 // function. We must do so, and set it on the current FunctionScopeInfo,
8408 // before attempting to transform the other parts of the coroutine body
8409 // statement, such as the implicit suspend statements (because those
8410 // statements reference the FunctionScopeInfo::CoroutinePromise).
8411 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8412 return StmtError();
8413 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8414 if (!Promise)
8415 return StmtError();
8416 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8417 ScopeInfo->CoroutinePromise = Promise;
8418
8419 // Transform the implicit coroutine statements constructed using dependent
8420 // types during the previous parse: initial and final suspensions, the return
8421 // object, and others. We also transform the coroutine function's body.
8422 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8423 if (InitSuspend.isInvalid())
8424 return StmtError();
8425 StmtResult FinalSuspend =
8426 getDerived().TransformStmt(S->getFinalSuspendStmt());
8427 if (FinalSuspend.isInvalid() ||
8428 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8429 return StmtError();
8430 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8431 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8432
8433 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8434 if (BodyRes.isInvalid())
8435 return StmtError();
8436
8437 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8438 if (Builder.isInvalid())
8439 return StmtError();
8440
8441 Expr *ReturnObject = S->getReturnValueInit();
8442 assert(ReturnObject && "the return object is expected to be valid");
8443 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8444 /*NoCopyInit*/ false);
8445 if (Res.isInvalid())
8446 return StmtError();
8447 Builder.ReturnValue = Res.get();
8448
8449 // If during the previous parse the coroutine still had a dependent promise
8450 // statement, we may need to build some implicit coroutine statements
8451 // (such as exception and fallthrough handlers) for the first time.
8452 if (S->hasDependentPromiseType()) {
8453 // We can only build these statements, however, if the current promise type
8454 // is not dependent.
8455 if (!Promise->getType()->isDependentType()) {
8456 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8457 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8458 "these nodes should not have been built yet");
8459 if (!Builder.buildDependentStatements())
8460 return StmtError();
8461 }
8462 } else {
8463 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8464 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8465 if (Res.isInvalid())
8466 return StmtError();
8467 Builder.OnFallthrough = Res.get();
8468 }
8469
8470 if (auto *OnException = S->getExceptionHandler()) {
8471 StmtResult Res = getDerived().TransformStmt(OnException);
8472 if (Res.isInvalid())
8473 return StmtError();
8474 Builder.OnException = Res.get();
8475 }
8476
8477 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8478 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8479 if (Res.isInvalid())
8480 return StmtError();
8481 Builder.ReturnStmtOnAllocFailure = Res.get();
8482 }
8483
8484 // Transform any additional statements we may have already built
8485 assert(S->getAllocate() && S->getDeallocate() &&
8486 "allocation and deallocation calls must already be built");
8487 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8488 if (AllocRes.isInvalid())
8489 return StmtError();
8490 Builder.Allocate = AllocRes.get();
8491
8492 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8493 if (DeallocRes.isInvalid())
8494 return StmtError();
8495 Builder.Deallocate = DeallocRes.get();
8496
8497 if (auto *ResultDecl = S->getResultDecl()) {
8498 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8499 if (Res.isInvalid())
8500 return StmtError();
8501 Builder.ResultDecl = Res.get();
8502 }
8503
8504 if (auto *ReturnStmt = S->getReturnStmt()) {
8505 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8506 if (Res.isInvalid())
8507 return StmtError();
8508 Builder.ReturnStmt = Res.get();
8509 }
8510 }
8511
8512 return getDerived().RebuildCoroutineBodyStmt(Builder);
8513}
8514
8515template<typename Derived>
8517TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
8518 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8519 /*NotCopyInit*/false);
8520 if (Result.isInvalid())
8521 return StmtError();
8522
8523 // Always rebuild; we don't know if this needs to be injected into a new
8524 // context or if the promise type has changed.
8525 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8526 S->isImplicit());
8527}
8528
8529template <typename Derived>
8530ExprResult TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
8531 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8532 /*NotCopyInit*/ false);
8533 if (Operand.isInvalid())
8534 return ExprError();
8535
8536 // Rebuild the common-expr from the operand rather than transforming it
8537 // separately.
8538
8539 // FIXME: getCurScope() should not be used during template instantiation.
8540 // We should pick up the set of unqualified lookup results for operator
8541 // co_await during the initial parse.
8542 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8543 getSema().getCurScope(), E->getKeywordLoc());
8544
8545 // Always rebuild; we don't know if this needs to be injected into a new
8546 // context or if the promise type has changed.
8547 return getDerived().RebuildCoawaitExpr(
8548 E->getKeywordLoc(), Operand.get(),
8549 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8550}
8551
8552template <typename Derived>
8554TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
8555 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8556 /*NotCopyInit*/ false);
8557 if (OperandResult.isInvalid())
8558 return ExprError();
8559
8560 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8561 E->getOperatorCoawaitLookup());
8562
8563 if (LookupResult.isInvalid())
8564 return ExprError();
8565
8566 // Always rebuild; we don't know if this needs to be injected into a new
8567 // context or if the promise type has changed.
8568 return getDerived().RebuildDependentCoawaitExpr(
8569 E->getKeywordLoc(), OperandResult.get(),
8570 cast<UnresolvedLookupExpr>(LookupResult.get()));
8571}
8572
8573template<typename Derived>
8575TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
8576 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8577 /*NotCopyInit*/false);
8578 if (Result.isInvalid())
8579 return ExprError();
8580
8581 // Always rebuild; we don't know if this needs to be injected into a new
8582 // context or if the promise type has changed.
8583 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8584}
8585
8586// Objective-C Statements.
8587
8588template<typename Derived>
8590TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
8591 // Transform the body of the @try.
8592 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8593 if (TryBody.isInvalid())
8594 return StmtError();
8595
8596 // Transform the @catch statements (if present).
8597 bool AnyCatchChanged = false;
8598 SmallVector<Stmt*, 8> CatchStmts;
8599 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8600 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8601 if (Catch.isInvalid())
8602 return StmtError();
8603 if (Catch.get() != S->getCatchStmt(I))
8604 AnyCatchChanged = true;
8605 CatchStmts.push_back(Catch.get());
8606 }
8607
8608 // Transform the @finally statement (if present).
8609 StmtResult Finally;
8610 if (S->getFinallyStmt()) {
8611 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8612 if (Finally.isInvalid())
8613 return StmtError();
8614 }
8615
8616 // If nothing changed, just retain this statement.
8617 if (!getDerived().AlwaysRebuild() &&
8618 TryBody.get() == S->getTryBody() &&
8619 !AnyCatchChanged &&
8620 Finally.get() == S->getFinallyStmt())
8621 return S;
8622
8623 // Build a new statement.
8624 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8625 CatchStmts, Finally.get());
8626}
8627
8628template<typename Derived>
8630TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
8631 // Transform the @catch parameter, if there is one.
8632 VarDecl *Var = nullptr;
8633 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8634 TypeSourceInfo *TSInfo = nullptr;
8635 if (FromVar->getTypeSourceInfo()) {
8636 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8637 if (!TSInfo)
8638 return StmtError();
8639 }
8640
8641 QualType T;
8642 if (TSInfo)
8643 T = TSInfo->getType();
8644 else {
8645 T = getDerived().TransformType(FromVar->getType());
8646 if (T.isNull())
8647 return StmtError();
8648 }
8649
8650 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8651 if (!Var)
8652 return StmtError();
8653 }
8654
8655 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8656 if (Body.isInvalid())
8657 return StmtError();
8658
8659 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8660 S->getRParenLoc(),
8661 Var, Body.get());
8662}
8663
8664template<typename Derived>
8666TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
8667 // Transform the body.
8668 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8669 if (Body.isInvalid())
8670 return StmtError();
8671
8672 // If nothing changed, just retain this statement.
8673 if (!getDerived().AlwaysRebuild() &&
8674 Body.get() == S->getFinallyBody())
8675 return S;
8676
8677 // Build a new statement.
8678 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8679 Body.get());
8680}
8681
8682template<typename Derived>
8684TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
8686 if (S->getThrowExpr()) {
8687 Operand = getDerived().TransformExpr(S->getThrowExpr());
8688 if (Operand.isInvalid())
8689 return StmtError();
8690 }
8691
8692 if (!getDerived().AlwaysRebuild() &&
8693 Operand.get() == S->getThrowExpr())
8694 return S;
8695
8696 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8697}
8698
8699template<typename Derived>
8701TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
8702 ObjCAtSynchronizedStmt *S) {
8703 // Transform the object we are locking.
8704 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
8705 if (Object.isInvalid())
8706 return StmtError();
8707 Object =
8708 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8709 Object.get());
8710 if (Object.isInvalid())
8711 return StmtError();
8712
8713 // Transform the body.
8714 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8715 if (Body.isInvalid())
8716 return StmtError();
8717
8718 // If nothing change, just retain the current statement.
8719 if (!getDerived().AlwaysRebuild() &&
8720 Object.get() == S->getSynchExpr() &&
8721 Body.get() == S->getSynchBody())
8722 return S;
8723
8724 // Build a new statement.
8725 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
8726 Object.get(), Body.get());
8727}
8728
8729template<typename Derived>
8731TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
8732 ObjCAutoreleasePoolStmt *S) {
8733 // Transform the body.
8734 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
8735 if (Body.isInvalid())
8736 return StmtError();
8737
8738 // If nothing changed, just retain this statement.
8739 if (!getDerived().AlwaysRebuild() &&
8740 Body.get() == S->getSubStmt())
8741 return S;
8742
8743 // Build a new statement.
8744 return getDerived().RebuildObjCAutoreleasePoolStmt(
8745 S->getAtLoc(), Body.get());
8746}
8747
8748template<typename Derived>
8750TreeTransform<Derived>::TransformObjCForCollectionStmt(
8751 ObjCForCollectionStmt *S) {
8752 // Transform the element statement.
8753 StmtResult Element =
8754 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
8755 if (Element.isInvalid())
8756 return StmtError();
8757
8758 // Transform the collection expression.
8759 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
8760 if (Collection.isInvalid())
8761 return StmtError();
8762
8763 // Transform the body.
8764 StmtResult Body = getDerived().TransformStmt(S->getBody());
8765 if (Body.isInvalid())
8766 return StmtError();
8767
8768 // If nothing changed, just retain this statement.
8769 if (!getDerived().AlwaysRebuild() &&
8770 Element.get() == S->getElement() &&
8771 Collection.get() == S->getCollection() &&
8772 Body.get() == S->getBody())
8773 return S;
8774
8775 // Build a new statement.
8776 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
8777 Element.get(),
8778 Collection.get(),
8779 S->getRParenLoc(),
8780 Body.get());
8781}
8782
8783template <typename Derived>
8784StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
8785 // Transform the exception declaration, if any.
8786 VarDecl *Var = nullptr;
8787 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
8788 TypeSourceInfo *T =
8789 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
8790 if (!T)
8791 return StmtError();
8792
8793 Var = getDerived().RebuildExceptionDecl(
8794 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
8795 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
8796 if (!Var || Var->isInvalidDecl())
8797 return StmtError();
8798 }
8799
8800 // Transform the actual exception handler.
8801 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
8802 if (Handler.isInvalid())
8803 return StmtError();
8804
8805 if (!getDerived().AlwaysRebuild() && !Var &&
8806 Handler.get() == S->getHandlerBlock())
8807 return S;
8808
8809 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
8810}
8811
8812template <typename Derived>
8813StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
8814 // Transform the try block itself.
8815 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
8816 if (TryBlock.isInvalid())
8817 return StmtError();
8818
8819 // Transform the handlers.
8820 bool HandlerChanged = false;
8821 SmallVector<Stmt *, 8> Handlers;
8822 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
8823 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
8824 if (Handler.isInvalid())
8825 return StmtError();
8826
8827 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
8828 Handlers.push_back(Handler.getAs<Stmt>());
8829 }
8830
8831 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
8832 !HandlerChanged)
8833 return S;
8834
8835 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
8836 Handlers);
8837}
8838
8839template<typename Derived>
8841TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
8842 EnterExpressionEvaluationContext ForRangeInitContext(
8844 /*LambdaContextDecl=*/nullptr,
8846 getSema().getLangOpts().CPlusPlus23);
8847
8848 // P2718R0 - Lifetime extension in range-based for loops.
8849 if (getSema().getLangOpts().CPlusPlus23) {
8850 auto &LastRecord = getSema().ExprEvalContexts.back();
8851 LastRecord.InLifetimeExtendingContext = true;
8852 }
8854 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
8855 if (Init.isInvalid())
8856 return StmtError();
8857
8858 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
8859 if (Range.isInvalid())
8860 return StmtError();
8861
8862 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
8863 assert(getSema().getLangOpts().CPlusPlus23 ||
8864 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
8865 auto ForRangeLifetimeExtendTemps =
8866 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
8867
8868 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
8869 if (Begin.isInvalid())
8870 return StmtError();
8871 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
8872 if (End.isInvalid())
8873 return StmtError();
8874
8875 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8876 if (Cond.isInvalid())
8877 return StmtError();
8878 if (Cond.get())
8879 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
8880 if (Cond.isInvalid())
8881 return StmtError();
8882 if (Cond.get())
8883 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
8884
8885 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8886 if (Inc.isInvalid())
8887 return StmtError();
8888 if (Inc.get())
8889 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
8890
8891 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
8892 if (LoopVar.isInvalid())
8893 return StmtError();
8894
8895 StmtResult NewStmt = S;
8896 if (getDerived().AlwaysRebuild() ||
8897 Init.get() != S->getInit() ||
8898 Range.get() != S->getRangeStmt() ||
8899 Begin.get() != S->getBeginStmt() ||
8900 End.get() != S->getEndStmt() ||
8901 Cond.get() != S->getCond() ||
8902 Inc.get() != S->getInc() ||
8903 LoopVar.get() != S->getLoopVarStmt()) {
8904 NewStmt = getDerived().RebuildCXXForRangeStmt(
8905 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
8906 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
8907 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
8908 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
8909 // Might not have attached any initializer to the loop variable.
8910 getSema().ActOnInitializerError(
8911 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
8912 return StmtError();
8913 }
8914 }
8915
8916 StmtResult Body = getDerived().TransformStmt(S->getBody());
8917 if (Body.isInvalid())
8918 return StmtError();
8919
8920 // Body has changed but we didn't rebuild the for-range statement. Rebuild
8921 // it now so we have a new statement to attach the body to.
8922 if (Body.get() != S->getBody() && NewStmt.get() == S) {
8923 NewStmt = getDerived().RebuildCXXForRangeStmt(
8924 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
8925 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
8926 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
8927 if (NewStmt.isInvalid())
8928 return StmtError();
8929 }
8930
8931 if (NewStmt.get() == S)
8932 return S;
8933
8934 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
8935}
8936
8937template<typename Derived>
8939TreeTransform<Derived>::TransformMSDependentExistsStmt(
8940 MSDependentExistsStmt *S) {
8941 // Transform the nested-name-specifier, if any.
8942 NestedNameSpecifierLoc QualifierLoc;
8943 if (S->getQualifierLoc()) {
8944 QualifierLoc
8945 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
8946 if (!QualifierLoc)
8947 return StmtError();
8948 }
8949
8950 // Transform the declaration name.
8951 DeclarationNameInfo NameInfo = S->getNameInfo();
8952 if (NameInfo.getName()) {
8953 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8954 if (!NameInfo.getName())
8955 return StmtError();
8956 }
8957
8958 // Check whether anything changed.
8959 if (!getDerived().AlwaysRebuild() &&
8960 QualifierLoc == S->getQualifierLoc() &&
8961 NameInfo.getName() == S->getNameInfo().getName())
8962 return S;
8963
8964 // Determine whether this name exists, if we can.
8965 CXXScopeSpec SS;
8966 SS.Adopt(QualifierLoc);
8967 bool Dependent = false;
8968 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
8969 case Sema::IER_Exists:
8970 if (S->isIfExists())
8971 break;
8972
8973 return new (getSema().Context) NullStmt(S->getKeywordLoc());
8974
8976 if (S->isIfNotExists())
8977 break;
8978
8979 return new (getSema().Context) NullStmt(S->getKeywordLoc());
8980
8982 Dependent = true;
8983 break;
8984
8985 case Sema::IER_Error:
8986 return StmtError();
8987 }
8988
8989 // We need to continue with the instantiation, so do so now.
8990 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
8991 if (SubStmt.isInvalid())
8992 return StmtError();
8993
8994 // If we have resolved the name, just transform to the substatement.
8995 if (!Dependent)
8996 return SubStmt;
8997
8998 // The name is still dependent, so build a dependent expression again.
8999 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9000 S->isIfExists(),
9001 QualifierLoc,
9002 NameInfo,
9003 SubStmt.get());
9004}
9005
9006template<typename Derived>
9008TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
9009 NestedNameSpecifierLoc QualifierLoc;
9010 if (E->getQualifierLoc()) {
9011 QualifierLoc
9012 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9013 if (!QualifierLoc)
9014 return ExprError();
9015 }
9016
9017 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9018 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9019 if (!PD)
9020 return ExprError();
9021
9022 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9023 if (Base.isInvalid())
9024 return ExprError();
9025
9026 return new (SemaRef.getASTContext())
9027 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9029 QualifierLoc, E->getMemberLoc());
9030}
9031
9032template <typename Derived>
9033ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
9034 MSPropertySubscriptExpr *E) {
9035 auto BaseRes = getDerived().TransformExpr(E->getBase());
9036 if (BaseRes.isInvalid())
9037 return ExprError();
9038 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9039 if (IdxRes.isInvalid())
9040 return ExprError();
9041
9042 if (!getDerived().AlwaysRebuild() &&
9043 BaseRes.get() == E->getBase() &&
9044 IdxRes.get() == E->getIdx())
9045 return E;
9046
9047 return getDerived().RebuildArraySubscriptExpr(
9048 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9049}
9050
9051template <typename Derived>
9052StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
9053 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9054 if (TryBlock.isInvalid())
9055 return StmtError();
9056
9057 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9058 if (Handler.isInvalid())
9059 return StmtError();
9060
9061 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9062 Handler.get() == S->getHandler())
9063 return S;
9064
9065 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9066 TryBlock.get(), Handler.get());
9067}
9068
9069template <typename Derived>
9070StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
9071 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9072 if (Block.isInvalid())
9073 return StmtError();
9074
9075 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9076}
9077
9078template <typename Derived>
9079StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
9080 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9081 if (FilterExpr.isInvalid())
9082 return StmtError();
9083
9084 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9085 if (Block.isInvalid())
9086 return StmtError();
9087
9088 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9089 Block.get());
9090}
9091
9092template <typename Derived>
9094 if (isa<SEHFinallyStmt>(Handler))
9095 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9096 else
9097 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9098}
9099
9100template<typename Derived>
9103 return S;
9104}
9105
9106//===----------------------------------------------------------------------===//
9107// OpenMP directive transformation
9108//===----------------------------------------------------------------------===//
9109
9110template <typename Derived>
9112TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9113 // OMPCanonicalLoops are eliminated during transformation, since they will be
9114 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9115 // after transformation.
9116 return getDerived().TransformStmt(L->getLoopStmt());
9117}
9118
9119template <typename Derived>
9122
9123 // Transform the clauses
9125 ArrayRef<OMPClause *> Clauses = D->clauses();
9126 TClauses.reserve(Clauses.size());
9127 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9128 I != E; ++I) {
9129 if (*I) {
9130 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9131 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9132 getDerived().getSema().OpenMP().EndOpenMPClause();
9133 if (Clause)
9134 TClauses.push_back(Clause);
9135 } else {
9136 TClauses.push_back(nullptr);
9137 }
9138 }
9139 StmtResult AssociatedStmt;
9140 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9141 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9142 D->getDirectiveKind(),
9143 /*CurScope=*/nullptr);
9144 StmtResult Body;
9145 {
9146 Sema::CompoundScopeRAII CompoundScope(getSema());
9147 Stmt *CS;
9148 if (D->getDirectiveKind() == OMPD_atomic ||
9149 D->getDirectiveKind() == OMPD_critical ||
9150 D->getDirectiveKind() == OMPD_section ||
9151 D->getDirectiveKind() == OMPD_master)
9152 CS = D->getAssociatedStmt();
9153 else
9154 CS = D->getRawStmt();
9155 Body = getDerived().TransformStmt(CS);
9156 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9157 getSema().getLangOpts().OpenMPIRBuilder)
9158 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9159 }
9160 AssociatedStmt =
9161 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9162 if (AssociatedStmt.isInvalid()) {
9163 return StmtError();
9164 }
9165 }
9166 if (TClauses.size() != Clauses.size()) {
9167 return StmtError();
9168 }
9169
9170 // Transform directive name for 'omp critical' directive.
9171 DeclarationNameInfo DirName;
9172 if (D->getDirectiveKind() == OMPD_critical) {
9173 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9174 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9175 }
9176 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9177 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9178 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9179 } else if (D->getDirectiveKind() == OMPD_cancel) {
9180 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9181 }
9182
9183 return getDerived().RebuildOMPExecutableDirective(
9184 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9185 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9186}
9187
9188template <typename Derived>
9191 // TODO: Fix This
9192 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9193 << getOpenMPDirectiveName(D->getDirectiveKind());
9194 return StmtError();
9195}
9196
9197template <typename Derived>
9199TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9200 DeclarationNameInfo DirName;
9201 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9202 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9203 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9204 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9205 return Res;
9206}
9207
9208template <typename Derived>
9210TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
9211 DeclarationNameInfo DirName;
9212 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9213 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9214 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9215 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9216 return Res;
9217}
9218
9219template <typename Derived>
9221TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
9222 DeclarationNameInfo DirName;
9223 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9224 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9225 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9226 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9227 return Res;
9228}
9229
9230template <typename Derived>
9232TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {
9233 DeclarationNameInfo DirName;
9234 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9235 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9236 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9237 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9238 return Res;
9239}
9240
9241template <typename Derived>
9243TreeTransform<Derived>::TransformOMPReverseDirective(OMPReverseDirective *D) {
9244 DeclarationNameInfo DirName;
9245 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9246 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9247 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9248 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9249 return Res;
9250}
9251
9252template <typename Derived>
9253StmtResult TreeTransform<Derived>::TransformOMPInterchangeDirective(
9254 OMPInterchangeDirective *D) {
9255 DeclarationNameInfo DirName;
9256 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9257 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9258 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9259 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9260 return Res;
9261}
9262
9263template <typename Derived>
9265TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
9266 DeclarationNameInfo DirName;
9267 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9268 OMPD_for, DirName, nullptr, D->getBeginLoc());
9269 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9270 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9271 return Res;
9272}
9273
9274template <typename Derived>
9276TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
9277 DeclarationNameInfo DirName;
9278 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9279 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9280 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9281 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9282 return Res;
9283}
9284
9285template <typename Derived>
9287TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
9288 DeclarationNameInfo DirName;
9289 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9290 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9291 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9292 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9293 return Res;
9294}
9295
9296template <typename Derived>
9298TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
9299 DeclarationNameInfo DirName;
9300 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9301 OMPD_section, DirName, nullptr, D->getBeginLoc());
9302 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9303 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9304 return Res;
9305}
9306
9307template <typename Derived>
9309TreeTransform<Derived>::TransformOMPScopeDirective(OMPScopeDirective *D) {
9310 DeclarationNameInfo DirName;
9311 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9312 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9313 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9314 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9315 return Res;
9316}
9317
9318template <typename Derived>
9320TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
9321 DeclarationNameInfo DirName;
9322 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9323 OMPD_single, DirName, nullptr, D->getBeginLoc());
9324 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9325 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9326 return Res;
9327}
9328
9329template <typename Derived>
9331TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
9332 DeclarationNameInfo DirName;
9333 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9334 OMPD_master, DirName, nullptr, D->getBeginLoc());
9335 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9336 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9337 return Res;
9338}
9339
9340template <typename Derived>
9342TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
9343 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9344 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9345 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9346 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9347 return Res;
9348}
9349
9350template <typename Derived>
9351StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
9352 OMPParallelForDirective *D) {
9353 DeclarationNameInfo DirName;
9354 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9355 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9356 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9357 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9358 return Res;
9359}
9360
9361template <typename Derived>
9362StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
9363 OMPParallelForSimdDirective *D) {
9364 DeclarationNameInfo DirName;
9365 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9366 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9367 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9368 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9369 return Res;
9370}
9371
9372template <typename Derived>
9373StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
9374 OMPParallelMasterDirective *D) {
9375 DeclarationNameInfo DirName;
9376 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9377 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9378 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9379 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9380 return Res;
9381}
9382
9383template <typename Derived>
9384StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective(
9385 OMPParallelMaskedDirective *D) {
9386 DeclarationNameInfo DirName;
9387 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9388 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9389 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9390 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9391 return Res;
9392}
9393
9394template <typename Derived>
9395StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
9396 OMPParallelSectionsDirective *D) {
9397 DeclarationNameInfo DirName;
9398 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9399 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9400 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9401 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9402 return Res;
9403}
9404
9405template <typename Derived>
9407TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
9408 DeclarationNameInfo DirName;
9409 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9410 OMPD_task, DirName, nullptr, D->getBeginLoc());
9411 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9412 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9413 return Res;
9414}
9415
9416template <typename Derived>
9417StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
9418 OMPTaskyieldDirective *D) {
9419 DeclarationNameInfo DirName;
9420 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9421 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9422 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9423 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9424 return Res;
9425}
9426
9427template <typename Derived>
9429TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
9430 DeclarationNameInfo DirName;
9431 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9432 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9433 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9434 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9435 return Res;
9436}
9437
9438template <typename Derived>
9440TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
9441 DeclarationNameInfo DirName;
9442 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9443 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9444 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9445 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9446 return Res;
9447}
9448
9449template <typename Derived>
9451TreeTransform<Derived>::TransformOMPErrorDirective(OMPErrorDirective *D) {
9452 DeclarationNameInfo DirName;
9453 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9454 OMPD_error, DirName, nullptr, D->getBeginLoc());
9455 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9456 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9457 return Res;
9458}
9459
9460template <typename Derived>
9461StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
9462 OMPTaskgroupDirective *D) {
9463 DeclarationNameInfo DirName;
9464 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9465 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9466 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9467 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9468 return Res;
9469}
9470
9471template <typename Derived>
9473TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
9474 DeclarationNameInfo DirName;
9475 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9476 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9477 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9478 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9479 return Res;
9480}
9481
9482template <typename Derived>
9484TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
9485 DeclarationNameInfo DirName;
9486 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9487 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9488 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9489 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9490 return Res;
9491}
9492
9493template <typename Derived>
9495TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
9496 DeclarationNameInfo DirName;
9497 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9498 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9499 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9500 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9501 return Res;
9502}
9503
9504template <typename Derived>
9506TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
9507 DeclarationNameInfo DirName;
9508 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9509 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9510 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9511 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9512 return Res;
9513}
9514
9515template <typename Derived>
9517TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
9518 DeclarationNameInfo DirName;
9519 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9520 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9521 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9522 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9523 return Res;
9524}
9525
9526template <typename Derived>
9528TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
9529 DeclarationNameInfo DirName;
9530 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9531 OMPD_target, DirName, nullptr, D->getBeginLoc());
9532 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9533 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9534 return Res;
9535}
9536
9537template <typename Derived>
9538StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
9539 OMPTargetDataDirective *D) {
9540 DeclarationNameInfo DirName;
9541 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9542 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
9543 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9544 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9545 return Res;
9546}
9547
9548template <typename Derived>
9549StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
9550 OMPTargetEnterDataDirective *D) {
9551 DeclarationNameInfo DirName;
9552 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9553 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
9554 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9555 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9556 return Res;
9557}
9558
9559template <typename Derived>
9560StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
9561 OMPTargetExitDataDirective *D) {
9562 DeclarationNameInfo DirName;
9563 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9564 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
9565 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9566 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9567 return Res;
9568}
9569
9570template <typename Derived>
9571StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
9572 OMPTargetParallelDirective *D) {
9573 DeclarationNameInfo DirName;
9574 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9575 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
9576 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9577 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9578 return Res;
9579}
9580
9581template <typename Derived>
9582StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
9583 OMPTargetParallelForDirective *D) {
9584 DeclarationNameInfo DirName;
9585 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9586 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
9587 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9588 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9589 return Res;
9590}
9591
9592template <typename Derived>
9593StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
9594 OMPTargetUpdateDirective *D) {
9595 DeclarationNameInfo DirName;
9596 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9597 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
9598 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9599 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9600 return Res;
9601}
9602
9603template <typename Derived>
9605TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
9606 DeclarationNameInfo DirName;
9607 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9608 OMPD_teams, DirName, nullptr, D->getBeginLoc());
9609 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9610 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9611 return Res;
9612}
9613
9614template <typename Derived>
9615StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
9616 OMPCancellationPointDirective *D) {
9617 DeclarationNameInfo DirName;
9618 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9619 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
9620 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9621 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9622 return Res;
9623}
9624
9625template <typename Derived>
9627TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
9628 DeclarationNameInfo DirName;
9629 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9630 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
9631 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9632 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9633 return Res;
9634}
9635
9636template <typename Derived>
9638TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
9639 DeclarationNameInfo DirName;
9640 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9641 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
9642 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9643 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9644 return Res;
9645}
9646
9647template <typename Derived>
9648StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
9649 OMPTaskLoopSimdDirective *D) {
9650 DeclarationNameInfo DirName;
9651 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9652 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9653 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9654 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9655 return Res;
9656}
9657
9658template <typename Derived>
9659StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
9660 OMPMasterTaskLoopDirective *D) {
9661 DeclarationNameInfo DirName;
9662 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9663 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
9664 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9665 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9666 return Res;
9667}
9668
9669template <typename Derived>
9670StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopDirective(
9671 OMPMaskedTaskLoopDirective *D) {
9672 DeclarationNameInfo DirName;
9673 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9674 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
9675 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9676 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9677 return Res;
9678}
9679
9680template <typename Derived>
9681StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
9682 OMPMasterTaskLoopSimdDirective *D) {
9683 DeclarationNameInfo DirName;
9684 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9685 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9686 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9687 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9688 return Res;
9689}
9690
9691template <typename Derived>
9692StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopSimdDirective(
9693 OMPMaskedTaskLoopSimdDirective *D) {
9694 DeclarationNameInfo DirName;
9695 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9696 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9697 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9698 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9699 return Res;
9700}
9701
9702template <typename Derived>
9703StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
9704 OMPParallelMasterTaskLoopDirective *D) {
9705 DeclarationNameInfo DirName;
9706 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9707 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
9708 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9709 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9710 return Res;
9711}
9712
9713template <typename Derived>
9714StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopDirective(
9715 OMPParallelMaskedTaskLoopDirective *D) {
9716 DeclarationNameInfo DirName;
9717 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9718 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
9719 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9720 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9721 return Res;
9722}
9723
9724template <typename Derived>
9726TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective(
9727 OMPParallelMasterTaskLoopSimdDirective *D) {
9728 DeclarationNameInfo DirName;
9729 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9730 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9731 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9732 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9733 return Res;
9734}
9735
9736template <typename Derived>
9738TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopSimdDirective(
9739 OMPParallelMaskedTaskLoopSimdDirective *D) {
9740 DeclarationNameInfo DirName;
9741 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9742 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9743 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9744 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9745 return Res;
9746}
9747
9748template <typename Derived>
9749StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
9750 OMPDistributeDirective *D) {
9751 DeclarationNameInfo DirName;
9752 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9753 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
9754 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9755 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9756 return Res;
9757}
9758
9759template <typename Derived>
9760StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
9761 OMPDistributeParallelForDirective *D) {
9762 DeclarationNameInfo DirName;
9763 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9764 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
9765 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9766 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9767 return Res;
9768}
9769
9770template <typename Derived>
9772TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
9773 OMPDistributeParallelForSimdDirective *D) {
9774 DeclarationNameInfo DirName;
9775 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9776 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9777 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9778 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9779 return Res;
9780}
9781
9782template <typename Derived>
9783StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
9784 OMPDistributeSimdDirective *D) {
9785 DeclarationNameInfo DirName;
9786 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9787 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
9788 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9789 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9790 return Res;
9791}
9792
9793template <typename Derived>
9794StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
9795 OMPTargetParallelForSimdDirective *D) {
9796 DeclarationNameInfo DirName;
9797 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9798 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9799 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9800 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9801 return Res;
9802}
9803
9804template <typename Derived>
9805StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
9806 OMPTargetSimdDirective *D) {
9807 DeclarationNameInfo DirName;
9808 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9809 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
9810 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9811 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9812 return Res;
9813}
9814
9815template <typename Derived>
9816StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
9817 OMPTeamsDistributeDirective *D) {
9818 DeclarationNameInfo DirName;
9819 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9820 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
9821 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9822 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9823 return Res;
9824}
9825
9826template <typename Derived>
9827StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
9828 OMPTeamsDistributeSimdDirective *D) {
9829 DeclarationNameInfo DirName;
9830 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9831 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
9832 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9833 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9834 return Res;
9835}
9836
9837template <typename Derived>
9838StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
9839 OMPTeamsDistributeParallelForSimdDirective *D) {
9840 DeclarationNameInfo DirName;
9841 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9842 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
9843 D->getBeginLoc());
9844 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9845 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9846 return Res;
9847}
9848
9849template <typename Derived>
9850StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
9851 OMPTeamsDistributeParallelForDirective *D) {
9852 DeclarationNameInfo DirName;
9853 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9854 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
9855 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9856 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9857 return Res;
9858}
9859
9860template <typename Derived>
9861StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
9862 OMPTargetTeamsDirective *D) {
9863 DeclarationNameInfo DirName;
9864 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9865 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
9866 auto Res = getDerived().TransformOMPExecutableDirective(D);
9867 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9868 return Res;
9869}
9870
9871template <typename Derived>
9872StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
9873 OMPTargetTeamsDistributeDirective *D) {
9874 DeclarationNameInfo DirName;
9875 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9876 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
9877 auto Res = getDerived().TransformOMPExecutableDirective(D);
9878 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9879 return Res;
9880}
9881
9882template <typename Derived>
9884TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
9885 OMPTargetTeamsDistributeParallelForDirective *D) {
9886 DeclarationNameInfo DirName;
9887 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9888 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
9889 D->getBeginLoc());
9890 auto Res = getDerived().TransformOMPExecutableDirective(D);
9891 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9892 return Res;
9893}
9894
9895template <typename Derived>
9896StmtResult TreeTransform<Derived>::
9897 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
9898 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
9899 DeclarationNameInfo DirName;
9900 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9901 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
9902 D->getBeginLoc());
9903 auto Res = getDerived().TransformOMPExecutableDirective(D);
9904 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9905 return Res;
9906}
9907
9908template <typename Derived>
9910TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
9911 OMPTargetTeamsDistributeSimdDirective *D) {
9912 DeclarationNameInfo DirName;
9913 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9914 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
9915 auto Res = getDerived().TransformOMPExecutableDirective(D);
9916 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9917 return Res;
9918}
9919
9920template <typename Derived>
9922TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
9923 DeclarationNameInfo DirName;
9924 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9925 OMPD_interop, DirName, nullptr, D->getBeginLoc());
9926 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9927 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9928 return Res;
9929}
9930
9931template <typename Derived>
9933TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
9934 DeclarationNameInfo DirName;
9935 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9936 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
9937 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9938 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9939 return Res;
9940}
9941
9942template <typename Derived>
9944TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
9945 DeclarationNameInfo DirName;
9946 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9947 OMPD_masked, DirName, nullptr, D->getBeginLoc());
9948 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9949 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9950 return Res;
9951}
9952
9953template <typename Derived>
9954StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
9955 OMPGenericLoopDirective *D) {
9956 DeclarationNameInfo DirName;
9957 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9958 OMPD_loop, DirName, nullptr, D->getBeginLoc());
9959 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9960 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9961 return Res;
9962}
9963
9964template <typename Derived>
9965StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective(
9966 OMPTeamsGenericLoopDirective *D) {
9967 DeclarationNameInfo DirName;
9968 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9969 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
9970 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9971 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9972 return Res;
9973}
9974
9975template <typename Derived>
9976StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsGenericLoopDirective(
9977 OMPTargetTeamsGenericLoopDirective *D) {
9978 DeclarationNameInfo DirName;
9979 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9980 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
9981 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9982 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9983 return Res;
9984}
9985
9986template <typename Derived>
9987StmtResult TreeTransform<Derived>::TransformOMPParallelGenericLoopDirective(
9988 OMPParallelGenericLoopDirective *D) {
9989 DeclarationNameInfo DirName;
9990 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9991 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
9992 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9993 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9994 return Res;
9995}
9996
9997template <typename Derived>
9999TreeTransform<Derived>::TransformOMPTargetParallelGenericLoopDirective(
10000 OMPTargetParallelGenericLoopDirective *D) {
10001 DeclarationNameInfo DirName;
10002 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10003 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10004 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10005 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10006 return Res;
10007}
10008
10009//===----------------------------------------------------------------------===//
10010// OpenMP clause transformation
10011//===----------------------------------------------------------------------===//
10012template <typename Derived>
10013OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
10014 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10015 if (Cond.isInvalid())
10016 return nullptr;
10017 return getDerived().RebuildOMPIfClause(
10018 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10019 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10020}
10021
10022template <typename Derived>
10023OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
10024 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10025 if (Cond.isInvalid())
10026 return nullptr;
10027 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10028 C->getLParenLoc(), C->getEndLoc());
10029}
10030
10031template <typename Derived>
10032OMPClause *
10033TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
10034 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10035 if (NumThreads.isInvalid())
10036 return nullptr;
10037 return getDerived().RebuildOMPNumThreadsClause(
10038 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10039}
10040
10041template <typename Derived>
10042OMPClause *
10043TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
10044 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10045 if (E.isInvalid())
10046 return nullptr;
10047 return getDerived().RebuildOMPSafelenClause(
10048 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10049}
10050
10051template <typename Derived>
10052OMPClause *
10053TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
10054 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10055 if (E.isInvalid())
10056 return nullptr;
10057 return getDerived().RebuildOMPAllocatorClause(
10058 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10059}
10060
10061template <typename Derived>
10062OMPClause *
10063TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
10064 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10065 if (E.isInvalid())
10066 return nullptr;
10067 return getDerived().RebuildOMPSimdlenClause(
10068 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10069}
10070
10071template <typename Derived>
10072OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) {
10073 SmallVector<Expr *, 4> TransformedSizes;
10074 TransformedSizes.reserve(C->getNumSizes());
10075 bool Changed = false;
10076 for (Expr *E : C->getSizesRefs()) {
10077 if (!E) {
10078 TransformedSizes.push_back(nullptr);
10079 continue;
10080 }
10081
10082 ExprResult T = getDerived().TransformExpr(E);
10083 if (T.isInvalid())
10084 return nullptr;
10085 if (E != T.get())
10086 Changed = true;
10087 TransformedSizes.push_back(T.get());
10088 }
10089
10090 if (!Changed && !getDerived().AlwaysRebuild())
10091 return C;
10092 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10093 C->getLParenLoc(), C->getEndLoc());
10094}
10095
10096template <typename Derived>
10097OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) {
10098 if (!getDerived().AlwaysRebuild())
10099 return C;
10100 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10101}
10102
10103template <typename Derived>
10104OMPClause *
10105TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
10106 ExprResult T = getDerived().TransformExpr(C->getFactor());
10107 if (T.isInvalid())
10108 return nullptr;
10109 Expr *Factor = T.get();
10110 bool Changed = Factor != C->getFactor();
10111
10112 if (!Changed && !getDerived().AlwaysRebuild())
10113 return C;
10114 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10115 C->getEndLoc());
10116}
10117
10118template <typename Derived>
10119OMPClause *
10120TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
10121 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10122 if (E.isInvalid())
10123 return nullptr;
10124 return getDerived().RebuildOMPCollapseClause(
10125 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10126}
10127
10128template <typename Derived>
10129OMPClause *
10130TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
10131 return getDerived().RebuildOMPDefaultClause(
10132 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
10133 C->getLParenLoc(), C->getEndLoc());
10134}
10135
10136template <typename Derived>
10137OMPClause *
10138TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
10139 return getDerived().RebuildOMPProcBindClause(
10140 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10141 C->getLParenLoc(), C->getEndLoc());
10142}
10143
10144template <typename Derived>
10145OMPClause *
10146TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
10147 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10148 if (E.isInvalid())
10149 return nullptr;
10150 return getDerived().RebuildOMPScheduleClause(
10151 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10152 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10153 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10154 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10155}
10156
10157template <typename Derived>
10158OMPClause *
10159TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
10160 ExprResult E;
10161 if (auto *Num = C->getNumForLoops()) {
10162 E = getDerived().TransformExpr(Num);
10163 if (E.isInvalid())
10164 return nullptr;
10165 }
10166 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10167 C->getLParenLoc(), E.get());
10168}
10169
10170template <typename Derived>
10171OMPClause *
10172TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
10173 ExprResult E;
10174 if (Expr *Evt = C->getEventHandler()) {
10175 E = getDerived().TransformExpr(Evt);
10176 if (E.isInvalid())
10177 return nullptr;
10178 }
10179 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10180 C->getLParenLoc(), C->getEndLoc());
10181}
10182
10183template <typename Derived>
10184OMPClause *
10185TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
10186 // No need to rebuild this clause, no template-dependent parameters.
10187 return C;
10188}
10189
10190template <typename Derived>
10191OMPClause *
10192TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
10193 // No need to rebuild this clause, no template-dependent parameters.
10194 return C;
10195}
10196
10197template <typename Derived>
10198OMPClause *
10199TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
10200 // No need to rebuild this clause, no template-dependent parameters.
10201 return C;
10202}
10203
10204template <typename Derived>
10205OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
10206 // No need to rebuild this clause, no template-dependent parameters.
10207 return C;
10208}
10209
10210template <typename Derived>
10211OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
10212 // No need to rebuild this clause, no template-dependent parameters.
10213 return C;
10214}
10215
10216template <typename Derived>
10217OMPClause *
10218TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
10219 // No need to rebuild this clause, no template-dependent parameters.
10220 return C;
10221}
10222
10223template <typename Derived>
10224OMPClause *
10225TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
10226 // No need to rebuild this clause, no template-dependent parameters.
10227 return C;
10228}
10229
10230template <typename Derived>
10231OMPClause *
10232TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
10233 // No need to rebuild this clause, no template-dependent parameters.
10234 return C;
10235}
10236
10237template <typename Derived>
10238OMPClause *TreeTransform<Derived>::TransformOMPFailClause(OMPFailClause *C) {
10239 // No need to rebuild this clause, no template-dependent parameters.
10240 return C;
10241}
10242
10243template <typename Derived>
10244OMPClause *
10245TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
10246 // No need to rebuild this clause, no template-dependent parameters.
10247 return C;
10248}
10249
10250template <typename Derived>
10251OMPClause *
10252TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
10253 // No need to rebuild this clause, no template-dependent parameters.
10254 return C;
10255}
10256
10257template <typename Derived>
10258OMPClause *
10259TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
10260 // No need to rebuild this clause, no template-dependent parameters.
10261 return C;
10262}
10263
10264template <typename Derived>
10265OMPClause *
10266TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
10267 // No need to rebuild this clause, no template-dependent parameters.
10268 return C;
10269}
10270
10271template <typename Derived>
10272OMPClause *
10273TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
10274 // No need to rebuild this clause, no template-dependent parameters.
10275 return C;
10276}
10277
10278template <typename Derived>
10279OMPClause *TreeTransform<Derived>::TransformOMPWeakClause(OMPWeakClause *C) {
10280 // No need to rebuild this clause, no template-dependent parameters.
10281 return C;
10282}
10283
10284template <typename Derived>
10285OMPClause *
10286TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
10287 // No need to rebuild this clause, no template-dependent parameters.
10288 return C;
10289}
10290
10291template <typename Derived>
10292OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
10293 // No need to rebuild this clause, no template-dependent parameters.
10294 return C;
10295}
10296
10297template <typename Derived>
10298OMPClause *
10299TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
10300 // No need to rebuild this clause, no template-dependent parameters.
10301 return C;
10302}
10303
10304template <typename Derived>
10305OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
10306 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10307 if (IVR.isInvalid())
10308 return nullptr;
10309
10310 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10311 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10312 for (Expr *E : llvm::drop_begin(C->varlists())) {
10313 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10314 if (ER.isInvalid())
10315 return nullptr;
10316 InteropInfo.PreferTypes.push_back(ER.get());
10317 }
10318 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10319 C->getBeginLoc(), C->getLParenLoc(),
10320 C->getVarLoc(), C->getEndLoc());
10321}
10322
10323template <typename Derived>
10324OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) {
10325 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10326 if (ER.isInvalid())
10327 return nullptr;
10328 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10329 C->getLParenLoc(), C->getVarLoc(),
10330 C->getEndLoc());
10331}
10332
10333template <typename Derived>
10334OMPClause *
10335TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
10336 ExprResult ER;
10337 if (Expr *IV = C->getInteropVar()) {
10338 ER = getDerived().TransformExpr(IV);
10339 if (ER.isInvalid())
10340 return nullptr;
10341 }
10342 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10343 C->getLParenLoc(), C->getVarLoc(),
10344 C->getEndLoc());
10345}
10346
10347template <typename Derived>
10348OMPClause *
10349TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
10350 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10351 if (Cond.isInvalid())
10352 return nullptr;
10353 return getDerived().RebuildOMPNovariantsClause(
10354 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10355}
10356
10357template <typename Derived>
10358OMPClause *
10359TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
10360 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10361 if (Cond.isInvalid())
10362 return nullptr;
10363 return getDerived().RebuildOMPNocontextClause(
10364 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10365}
10366
10367template <typename Derived>
10368OMPClause *
10369TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
10370 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10371 if (ThreadID.isInvalid())
10372 return nullptr;
10373 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10374 C->getLParenLoc(), C->getEndLoc());
10375}
10376
10377template <typename Derived>
10378OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) {
10379 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10380 if (E.isInvalid())
10381 return nullptr;
10382 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10383 C->getLParenLoc(), C->getEndLoc());
10384}
10385
10386template <typename Derived>
10387OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
10388 OMPUnifiedAddressClause *C) {
10389 llvm_unreachable("unified_address clause cannot appear in dependent context");
10390}
10391
10392template <typename Derived>
10393OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
10394 OMPUnifiedSharedMemoryClause *C) {
10395 llvm_unreachable(
10396 "unified_shared_memory clause cannot appear in dependent context");
10397}
10398
10399template <typename Derived>
10400OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
10401 OMPReverseOffloadClause *C) {
10402 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10403}
10404
10405template <typename Derived>
10406OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
10407 OMPDynamicAllocatorsClause *C) {
10408 llvm_unreachable(
10409 "dynamic_allocators clause cannot appear in dependent context");
10410}
10411
10412template <typename Derived>
10413OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
10414 OMPAtomicDefaultMemOrderClause *C) {
10415 llvm_unreachable(
10416 "atomic_default_mem_order clause cannot appear in dependent context");
10417}
10418
10419template <typename Derived>
10420OMPClause *TreeTransform<Derived>::TransformOMPAtClause(OMPAtClause *C) {
10421 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10422 C->getBeginLoc(), C->getLParenLoc(),
10423 C->getEndLoc());
10424}
10425
10426template <typename Derived>
10427OMPClause *
10428TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) {
10429 return getDerived().RebuildOMPSeverityClause(
10430 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10431 C->getLParenLoc(), C->getEndLoc());
10432}
10433
10434template <typename Derived>
10435OMPClause *
10436TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) {
10437 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10438 if (E.isInvalid())
10439 return nullptr;
10440 return getDerived().RebuildOMPMessageClause(
10441 C->getMessageString(), C->getBeginLoc(), C->getLParenLoc(),
10442 C->getEndLoc());
10443}
10444
10445template <typename Derived>
10446OMPClause *
10447TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
10449 Vars.reserve(C->varlist_size());
10450 for (auto *VE : C->varlists()) {
10451 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10452 if (EVar.isInvalid())
10453 return nullptr;
10454 Vars.push_back(EVar.get());
10455 }
10456 return getDerived().RebuildOMPPrivateClause(
10457 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10458}
10459
10460template <typename Derived>
10461OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
10462 OMPFirstprivateClause *C) {
10464 Vars.reserve(C->varlist_size());
10465 for (auto *VE : C->varlists()) {
10466 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10467 if (EVar.isInvalid())
10468 return nullptr;
10469 Vars.push_back(EVar.get());
10470 }
10471 return getDerived().RebuildOMPFirstprivateClause(
10472 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10473}
10474
10475template <typename Derived>
10476OMPClause *
10477TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
10479 Vars.reserve(C->varlist_size());
10480 for (auto *VE : C->varlists()) {
10481 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10482 if (EVar.isInvalid())
10483 return nullptr;
10484 Vars.push_back(EVar.get());
10485 }
10486 return getDerived().RebuildOMPLastprivateClause(
10487 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
10488 C->getLParenLoc(), C->getEndLoc());
10489}
10490
10491template <typename Derived>
10492OMPClause *
10493TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
10495 Vars.reserve(C->varlist_size());
10496 for (auto *VE : C->varlists()) {
10497 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10498 if (EVar.isInvalid())
10499 return nullptr;
10500 Vars.push_back(EVar.get());
10501 }
10502 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
10503 C->getLParenLoc(), C->getEndLoc());
10504}
10505
10506template <typename Derived>
10507OMPClause *
10508TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
10510 Vars.reserve(C->varlist_size());
10511 for (auto *VE : C->varlists()) {
10512 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10513 if (EVar.isInvalid())
10514 return nullptr;
10515 Vars.push_back(EVar.get());
10516 }
10517 CXXScopeSpec ReductionIdScopeSpec;
10518 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10519
10520 DeclarationNameInfo NameInfo = C->getNameInfo();
10521 if (NameInfo.getName()) {
10522 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10523 if (!NameInfo.getName())
10524 return nullptr;
10525 }
10526 // Build a list of all UDR decls with the same names ranged by the Scopes.
10527 // The Scope boundary is a duplication of the previous decl.
10528 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10529 for (auto *E : C->reduction_ops()) {
10530 // Transform all the decls.
10531 if (E) {
10532 auto *ULE = cast<UnresolvedLookupExpr>(E);
10533 UnresolvedSet<8> Decls;
10534 for (auto *D : ULE->decls()) {
10535 NamedDecl *InstD =
10536 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10537 Decls.addDecl(InstD, InstD->getAccess());
10538 }
10539 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10540 SemaRef.Context, /*NamingClass=*/nullptr,
10541 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10542 /*ADL=*/true, Decls.begin(), Decls.end(),
10543 /*KnownDependent=*/false));
10544 } else
10545 UnresolvedReductions.push_back(nullptr);
10546 }
10547 return getDerived().RebuildOMPReductionClause(
10548 Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(),
10549 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
10550 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10551}
10552
10553template <typename Derived>
10554OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
10555 OMPTaskReductionClause *C) {
10557 Vars.reserve(C->varlist_size());
10558 for (auto *VE : C->varlists()) {
10559 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10560 if (EVar.isInvalid())
10561 return nullptr;
10562 Vars.push_back(EVar.get());
10563 }
10564 CXXScopeSpec ReductionIdScopeSpec;
10565 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10566
10567 DeclarationNameInfo NameInfo = C->getNameInfo();
10568 if (NameInfo.getName()) {
10569 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10570 if (!NameInfo.getName())
10571 return nullptr;
10572 }
10573 // Build a list of all UDR decls with the same names ranged by the Scopes.
10574 // The Scope boundary is a duplication of the previous decl.
10575 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10576 for (auto *E : C->reduction_ops()) {
10577 // Transform all the decls.
10578 if (E) {
10579 auto *ULE = cast<UnresolvedLookupExpr>(E);
10580 UnresolvedSet<8> Decls;
10581 for (auto *D : ULE->decls()) {
10582 NamedDecl *InstD =
10583 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10584 Decls.addDecl(InstD, InstD->getAccess());
10585 }
10586 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10587 SemaRef.Context, /*NamingClass=*/nullptr,
10588 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10589 /*ADL=*/true, Decls.begin(), Decls.end(),
10590 /*KnownDependent=*/false));
10591 } else
10592 UnresolvedReductions.push_back(nullptr);
10593 }
10594 return getDerived().RebuildOMPTaskReductionClause(
10595 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10596 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10597}
10598
10599template <typename Derived>
10600OMPClause *
10601TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
10603 Vars.reserve(C->varlist_size());
10604 for (auto *VE : C->varlists()) {
10605 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10606 if (EVar.isInvalid())
10607 return nullptr;
10608 Vars.push_back(EVar.get());
10609 }
10610 CXXScopeSpec ReductionIdScopeSpec;
10611 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10612
10613 DeclarationNameInfo NameInfo = C->getNameInfo();
10614 if (NameInfo.getName()) {
10615 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10616 if (!NameInfo.getName())
10617 return nullptr;
10618 }
10619 // Build a list of all UDR decls with the same names ranged by the Scopes.
10620 // The Scope boundary is a duplication of the previous decl.
10621 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10622 for (auto *E : C->reduction_ops()) {
10623 // Transform all the decls.
10624 if (E) {
10625 auto *ULE = cast<UnresolvedLookupExpr>(E);
10626 UnresolvedSet<8> Decls;
10627 for (auto *D : ULE->decls()) {
10628 NamedDecl *InstD =
10629 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10630 Decls.addDecl(InstD, InstD->getAccess());
10631 }
10632 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10633 SemaRef.Context, /*NamingClass=*/nullptr,
10634 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10635 /*ADL=*/true, Decls.begin(), Decls.end(),
10636 /*KnownDependent=*/false));
10637 } else
10638 UnresolvedReductions.push_back(nullptr);
10639 }
10640 return getDerived().RebuildOMPInReductionClause(
10641 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10642 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10643}
10644
10645template <typename Derived>
10646OMPClause *
10647TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
10649 Vars.reserve(C->varlist_size());
10650 for (auto *VE : C->varlists()) {
10651 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10652 if (EVar.isInvalid())
10653 return nullptr;
10654 Vars.push_back(EVar.get());
10655 }
10656 ExprResult Step = getDerived().TransformExpr(C->getStep());
10657 if (Step.isInvalid())
10658 return nullptr;
10659 return getDerived().RebuildOMPLinearClause(
10660 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
10661 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
10662 C->getEndLoc());
10663}
10664
10665template <typename Derived>
10666OMPClause *
10667TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
10669 Vars.reserve(C->varlist_size());
10670 for (auto *VE : C->varlists()) {
10671 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10672 if (EVar.isInvalid())
10673 return nullptr;
10674 Vars.push_back(EVar.get());
10675 }
10676 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
10677 if (Alignment.isInvalid())
10678 return nullptr;
10679 return getDerived().RebuildOMPAlignedClause(
10680 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
10681 C->getColonLoc(), C->getEndLoc());
10682}
10683
10684template <typename Derived>
10685OMPClause *
10686TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
10688 Vars.reserve(C->varlist_size());
10689 for (auto *VE : C->varlists()) {
10690 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10691 if (EVar.isInvalid())
10692 return nullptr;
10693 Vars.push_back(EVar.get());
10694 }
10695 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
10696 C->getLParenLoc(), C->getEndLoc());
10697}
10698
10699template <typename Derived>
10700OMPClause *
10701TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
10703 Vars.reserve(C->varlist_size());
10704 for (auto *VE : C->varlists()) {
10705 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10706 if (EVar.isInvalid())
10707 return nullptr;
10708 Vars.push_back(EVar.get());
10709 }
10710 return getDerived().RebuildOMPCopyprivateClause(
10711 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10712}
10713
10714template <typename Derived>
10715OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
10717 Vars.reserve(C->varlist_size());
10718 for (auto *VE : C->varlists()) {
10719 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10720 if (EVar.isInvalid())
10721 return nullptr;
10722 Vars.push_back(EVar.get());
10723 }
10724 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
10725 C->getLParenLoc(), C->getEndLoc());
10726}
10727
10728template <typename Derived>
10729OMPClause *
10730TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
10731 ExprResult E = getDerived().TransformExpr(C->getDepobj());
10732 if (E.isInvalid())
10733 return nullptr;
10734 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
10735 C->getLParenLoc(), C->getEndLoc());
10736}
10737
10738template <typename Derived>
10739OMPClause *
10740TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
10742 Expr *DepModifier = C->getModifier();
10743 if (DepModifier) {
10744 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
10745 if (DepModRes.isInvalid())
10746 return nullptr;
10747 DepModifier = DepModRes.get();
10748 }
10749 Vars.reserve(C->varlist_size());
10750 for (auto *VE : C->varlists()) {
10751 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10752 if (EVar.isInvalid())
10753 return nullptr;
10754 Vars.push_back(EVar.get());
10755 }
10756 return getDerived().RebuildOMPDependClause(
10757 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
10758 C->getOmpAllMemoryLoc()},
10759 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10760}
10761
10762template <typename Derived>
10763OMPClause *
10764TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
10765 ExprResult E = getDerived().TransformExpr(C->getDevice());
10766 if (E.isInvalid())
10767 return nullptr;
10768 return getDerived().RebuildOMPDeviceClause(
10769 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10770 C->getModifierLoc(), C->getEndLoc());
10771}
10772
10773template <typename Derived, class T>
10776 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
10777 DeclarationNameInfo &MapperIdInfo,
10778 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
10779 // Transform expressions in the list.
10780 Vars.reserve(C->varlist_size());
10781 for (auto *VE : C->varlists()) {
10782 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
10783 if (EVar.isInvalid())
10784 return true;
10785 Vars.push_back(EVar.get());
10786 }
10787 // Transform mapper scope specifier and identifier.
10788 NestedNameSpecifierLoc QualifierLoc;
10789 if (C->getMapperQualifierLoc()) {
10790 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
10791 C->getMapperQualifierLoc());
10792 if (!QualifierLoc)
10793 return true;
10794 }
10795 MapperIdScopeSpec.Adopt(QualifierLoc);
10796 MapperIdInfo = C->getMapperIdInfo();
10797 if (MapperIdInfo.getName()) {
10798 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
10799 if (!MapperIdInfo.getName())
10800 return true;
10801 }
10802 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
10803 // the previous user-defined mapper lookup in dependent environment.
10804 for (auto *E : C->mapperlists()) {
10805 // Transform all the decls.
10806 if (E) {
10807 auto *ULE = cast<UnresolvedLookupExpr>(E);
10808 UnresolvedSet<8> Decls;
10809 for (auto *D : ULE->decls()) {
10810 NamedDecl *InstD =
10811 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
10812 Decls.addDecl(InstD, InstD->getAccess());
10813 }
10814 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
10815 TT.getSema().Context, /*NamingClass=*/nullptr,
10816 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
10817 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
10818 /*KnownDependent=*/false));
10819 } else {
10820 UnresolvedMappers.push_back(nullptr);
10821 }
10822 }
10823 return false;
10824}
10825
10826template <typename Derived>
10827OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
10828 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10830 Expr *IteratorModifier = C->getIteratorModifier();
10831 if (IteratorModifier) {
10832 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
10833 if (MapModRes.isInvalid())
10834 return nullptr;
10835 IteratorModifier = MapModRes.get();
10836 }
10837 CXXScopeSpec MapperIdScopeSpec;
10838 DeclarationNameInfo MapperIdInfo;
10839 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
10840 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
10841 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
10842 return nullptr;
10843 return getDerived().RebuildOMPMapClause(
10844 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
10845 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
10846 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
10847}
10848
10849template <typename Derived>
10850OMPClause *
10851TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
10852 Expr *Allocator = C->getAllocator();
10853 if (Allocator) {
10854 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
10855 if (AllocatorRes.isInvalid())
10856 return nullptr;
10857 Allocator = AllocatorRes.get();
10858 }
10860 Vars.reserve(C->varlist_size());
10861 for (auto *VE : C->varlists()) {
10862 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10863 if (EVar.isInvalid())
10864 return nullptr;
10865 Vars.push_back(EVar.get());
10866 }
10867 return getDerived().RebuildOMPAllocateClause(
10868 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10869 C->getEndLoc());
10870}
10871
10872template <typename Derived>
10873OMPClause *
10874TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
10875 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
10876 if (E.isInvalid())
10877 return nullptr;
10878 return getDerived().RebuildOMPNumTeamsClause(
10879 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10880}
10881
10882template <typename Derived>
10883OMPClause *
10884TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
10885 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
10886 if (E.isInvalid())
10887 return nullptr;
10888 return getDerived().RebuildOMPThreadLimitClause(
10889 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10890}
10891
10892template <typename Derived>
10893OMPClause *
10894TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
10895 ExprResult E = getDerived().TransformExpr(C->getPriority());
10896 if (E.isInvalid())
10897 return nullptr;
10898 return getDerived().RebuildOMPPriorityClause(
10899 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10900}
10901
10902template <typename Derived>
10903OMPClause *
10904TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
10905 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
10906 if (E.isInvalid())
10907 return nullptr;
10908 return getDerived().RebuildOMPGrainsizeClause(
10909 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10910 C->getModifierLoc(), C->getEndLoc());
10911}
10912
10913template <typename Derived>
10914OMPClause *
10915TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
10916 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
10917 if (E.isInvalid())
10918 return nullptr;
10919 return getDerived().RebuildOMPNumTasksClause(
10920 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10921 C->getModifierLoc(), C->getEndLoc());
10922}
10923
10924template <typename Derived>
10925OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
10926 ExprResult E = getDerived().TransformExpr(C->getHint());
10927 if (E.isInvalid())
10928 return nullptr;
10929 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
10930 C->getLParenLoc(), C->getEndLoc());
10931}
10932
10933template <typename Derived>
10934OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
10935 OMPDistScheduleClause *C) {
10936 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10937 if (E.isInvalid())
10938 return nullptr;
10939 return getDerived().RebuildOMPDistScheduleClause(
10940 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10941 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10942}
10943
10944template <typename Derived>
10945OMPClause *
10946TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
10947 // Rebuild Defaultmap Clause since we need to invoke the checking of
10948 // defaultmap(none:variable-category) after template initialization.
10949 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
10950 C->getDefaultmapKind(),
10951 C->getBeginLoc(),
10952 C->getLParenLoc(),
10953 C->getDefaultmapModifierLoc(),
10954 C->getDefaultmapKindLoc(),
10955 C->getEndLoc());
10956}
10957
10958template <typename Derived>
10959OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
10960 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10962 CXXScopeSpec MapperIdScopeSpec;
10963 DeclarationNameInfo MapperIdInfo;
10964 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
10965 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
10966 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
10967 return nullptr;
10968 return getDerived().RebuildOMPToClause(
10969 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
10970 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
10971}
10972
10973template <typename Derived>
10974OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
10975 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10977 CXXScopeSpec MapperIdScopeSpec;
10978 DeclarationNameInfo MapperIdInfo;
10979 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
10980 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
10981 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
10982 return nullptr;
10983 return getDerived().RebuildOMPFromClause(
10984 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
10985 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
10986}
10987
10988template <typename Derived>
10989OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
10990 OMPUseDevicePtrClause *C) {
10992 Vars.reserve(C->varlist_size());
10993 for (auto *VE : C->varlists()) {
10994 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10995 if (EVar.isInvalid())
10996 return nullptr;
10997 Vars.push_back(EVar.get());
10998 }
10999 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11000 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
11001}
11002
11003template <typename Derived>
11004OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause(
11005 OMPUseDeviceAddrClause *C) {
11007 Vars.reserve(C->varlist_size());
11008 for (auto *VE : C->varlists()) {
11009 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11010 if (EVar.isInvalid())
11011 return nullptr;
11012 Vars.push_back(EVar.get());
11013 }
11014 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11015 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11016}
11017
11018template <typename Derived>
11019OMPClause *
11020TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
11022 Vars.reserve(C->varlist_size());
11023 for (auto *VE : C->varlists()) {
11024 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11025 if (EVar.isInvalid())
11026 return nullptr;
11027 Vars.push_back(EVar.get());
11028 }
11029 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11030 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11031}
11032
11033template <typename Derived>
11034OMPClause *TreeTransform<Derived>::TransformOMPHasDeviceAddrClause(
11035 OMPHasDeviceAddrClause *C) {
11037 Vars.reserve(C->varlist_size());
11038 for (auto *VE : C->varlists()) {
11039 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11040 if (EVar.isInvalid())
11041 return nullptr;
11042 Vars.push_back(EVar.get());
11043 }
11044 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11045 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11046}
11047
11048template <typename Derived>
11049OMPClause *
11050TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) {
11052 Vars.reserve(C->varlist_size());
11053 for (auto *VE : C->varlists()) {
11054 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11055 if (EVar.isInvalid())
11056 return nullptr;
11057 Vars.push_back(EVar.get());
11058 }
11059 return getDerived().RebuildOMPNontemporalClause(
11060 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11061}
11062
11063template <typename Derived>
11064OMPClause *
11065TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) {
11067 Vars.reserve(C->varlist_size());
11068 for (auto *VE : C->varlists()) {
11069 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11070 if (EVar.isInvalid())
11071 return nullptr;
11072 Vars.push_back(EVar.get());
11073 }
11074 return getDerived().RebuildOMPInclusiveClause(
11075 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11076}
11077
11078template <typename Derived>
11079OMPClause *
11080TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) {
11082 Vars.reserve(C->varlist_size());
11083 for (auto *VE : C->varlists()) {
11084 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11085 if (EVar.isInvalid())
11086 return nullptr;
11087 Vars.push_back(EVar.get());
11088 }
11089 return getDerived().RebuildOMPExclusiveClause(
11090 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11091}
11092
11093template <typename Derived>
11094OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause(
11095 OMPUsesAllocatorsClause *C) {
11097 Data.reserve(C->getNumberOfAllocators());
11098 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11099 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11100 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11101 if (Allocator.isInvalid())
11102 continue;
11103 ExprResult AllocatorTraits;
11104 if (Expr *AT = D.AllocatorTraits) {
11105 AllocatorTraits = getDerived().TransformExpr(AT);
11106 if (AllocatorTraits.isInvalid())
11107 continue;
11108 }
11109 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11110 NewD.Allocator = Allocator.get();
11111 NewD.AllocatorTraits = AllocatorTraits.get();
11112 NewD.LParenLoc = D.LParenLoc;
11113 NewD.RParenLoc = D.RParenLoc;
11114 }
11115 return getDerived().RebuildOMPUsesAllocatorsClause(
11116 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11117}
11118
11119template <typename Derived>
11120OMPClause *
11121TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) {
11122 SmallVector<Expr *, 4> Locators;
11123 Locators.reserve(C->varlist_size());
11124 ExprResult ModifierRes;
11125 if (Expr *Modifier = C->getModifier()) {
11126 ModifierRes = getDerived().TransformExpr(Modifier);
11127 if (ModifierRes.isInvalid())
11128 return nullptr;
11129 }
11130 for (Expr *E : C->varlists()) {
11131 ExprResult Locator = getDerived().TransformExpr(E);
11132 if (Locator.isInvalid())
11133 continue;
11134 Locators.push_back(Locator.get());
11135 }
11136 return getDerived().RebuildOMPAffinityClause(
11137 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11138 ModifierRes.get(), Locators);
11139}
11140
11141template <typename Derived>
11142OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) {
11143 return getDerived().RebuildOMPOrderClause(
11144 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11145 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11146}
11147
11148template <typename Derived>
11149OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) {
11150 return getDerived().RebuildOMPBindClause(
11151 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11152 C->getLParenLoc(), C->getEndLoc());
11153}
11154
11155template <typename Derived>
11156OMPClause *TreeTransform<Derived>::TransformOMPXDynCGroupMemClause(
11157 OMPXDynCGroupMemClause *C) {
11158 ExprResult Size = getDerived().TransformExpr(C->getSize());
11159 if (Size.isInvalid())
11160 return nullptr;
11161 return getDerived().RebuildOMPXDynCGroupMemClause(
11162 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11163}
11164
11165template <typename Derived>
11166OMPClause *
11167TreeTransform<Derived>::TransformOMPDoacrossClause(OMPDoacrossClause *C) {
11169 Vars.reserve(C->varlist_size());
11170 for (auto *VE : C->varlists()) {
11171 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11172 if (EVar.isInvalid())
11173 return nullptr;
11174 Vars.push_back(EVar.get());
11175 }
11176 return getDerived().RebuildOMPDoacrossClause(
11177 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11178 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11179}
11180
11181template <typename Derived>
11182OMPClause *
11183TreeTransform<Derived>::TransformOMPXAttributeClause(OMPXAttributeClause *C) {
11185 for (auto *A : C->getAttrs())
11186 NewAttrs.push_back(getDerived().TransformAttr(A));
11187 return getDerived().RebuildOMPXAttributeClause(
11188 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11189}
11190
11191template <typename Derived>
11192OMPClause *TreeTransform<Derived>::TransformOMPXBareClause(OMPXBareClause *C) {
11193 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11194}
11195
11196//===----------------------------------------------------------------------===//
11197// OpenACC transformation
11198//===----------------------------------------------------------------------===//
11199namespace {
11200template <typename Derived>
11201class OpenACCClauseTransform final
11202 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11203 TreeTransform<Derived> &Self;
11204 ArrayRef<const OpenACCClause *> ExistingClauses;
11205 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11206 OpenACCClause *NewClause = nullptr;
11207
11208 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11209 llvm::SmallVector<Expr *> InstantiatedVarList;
11210 for (Expr *CurVar : VarList) {
11211 ExprResult Res = Self.TransformExpr(CurVar);
11212
11213 if (!Res.isUsable())
11214 continue;
11215
11216 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getClauseKind(),
11217 Res.get());
11218
11219 if (Res.isUsable())
11220 InstantiatedVarList.push_back(Res.get());
11221 }
11222
11223 return InstantiatedVarList;
11224 }
11225
11226public:
11227 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11228 ArrayRef<const OpenACCClause *> ExistingClauses,
11229 SemaOpenACC::OpenACCParsedClause &PC)
11230 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11231
11232 OpenACCClause *CreatedClause() const { return NewClause; }
11233
11234#define VISIT_CLAUSE(CLAUSE_NAME) \
11235 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11236#include "clang/Basic/OpenACCClauses.def"
11237};
11238
11239template <typename Derived>
11240void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11241 const OpenACCDefaultClause &C) {
11242 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11243
11244 NewClause = OpenACCDefaultClause::Create(
11245 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11246 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11247 ParsedClause.getEndLoc());
11248}
11249
11250template <typename Derived>
11251void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11252 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11253 assert(Cond && "If constructed with invalid Condition");
11254 Sema::ConditionResult Res = Self.TransformCondition(
11255 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11256
11257 if (Res.isInvalid() || !Res.get().second)
11258 return;
11259
11260 ParsedClause.setConditionDetails(Res.get().second);
11261
11262 NewClause = OpenACCIfClause::Create(
11263 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11264 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11265 ParsedClause.getEndLoc());
11266}
11267
11268template <typename Derived>
11269void OpenACCClauseTransform<Derived>::VisitSelfClause(
11270 const OpenACCSelfClause &C) {
11271
11272 if (C.hasConditionExpr()) {
11273 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11274 Sema::ConditionResult Res =
11275 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11277
11278 if (Res.isInvalid() || !Res.get().second)
11279 return;
11280
11281 ParsedClause.setConditionDetails(Res.get().second);
11282 }
11283
11284 NewClause = OpenACCSelfClause::Create(
11285 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11286 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11287 ParsedClause.getEndLoc());
11288}
11289
11290template <typename Derived>
11291void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11292 const OpenACCNumGangsClause &C) {
11293 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11294
11295 for (Expr *CurIntExpr : C.getIntExprs()) {
11296 ExprResult Res = Self.TransformExpr(CurIntExpr);
11297
11298 if (!Res.isUsable())
11299 return;
11300
11301 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11302 C.getClauseKind(),
11303 C.getBeginLoc(), Res.get());
11304 if (!Res.isUsable())
11305 return;
11306
11307 InstantiatedIntExprs.push_back(Res.get());
11308 }
11309
11310 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11312 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11313 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11314 ParsedClause.getEndLoc());
11315}
11316
11317template <typename Derived>
11318void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11319 const OpenACCPrivateClause &C) {
11320 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11321 /*IsReadOnly=*/false, /*IsZero=*/false);
11322
11323 NewClause = OpenACCPrivateClause::Create(
11324 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11325 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11326 ParsedClause.getEndLoc());
11327}
11328
11329template <typename Derived>
11330void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11331 const OpenACCFirstPrivateClause &C) {
11332 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11333 /*IsReadOnly=*/false, /*IsZero=*/false);
11334
11336 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11337 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11338 ParsedClause.getEndLoc());
11339}
11340
11341template <typename Derived>
11342void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
11343 const OpenACCNoCreateClause &C) {
11344 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11345 /*IsReadOnly=*/false, /*IsZero=*/false);
11346
11348 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11349 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11350 ParsedClause.getEndLoc());
11351}
11352
11353template <typename Derived>
11354void OpenACCClauseTransform<Derived>::VisitPresentClause(
11355 const OpenACCPresentClause &C) {
11356 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11357 /*IsReadOnly=*/false, /*IsZero=*/false);
11358
11359 NewClause = OpenACCPresentClause::Create(
11360 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11361 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11362 ParsedClause.getEndLoc());
11363}
11364
11365template <typename Derived>
11366void OpenACCClauseTransform<Derived>::VisitCopyClause(
11367 const OpenACCCopyClause &C) {
11368 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11369 /*IsReadOnly=*/false, /*IsZero=*/false);
11370
11371 NewClause = OpenACCCopyClause::Create(
11372 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11373 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11374 ParsedClause.getVarList(), ParsedClause.getEndLoc());
11375}
11376
11377template <typename Derived>
11378void OpenACCClauseTransform<Derived>::VisitCopyInClause(
11379 const OpenACCCopyInClause &C) {
11380 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), C.isReadOnly(),
11381 /*IsZero=*/false);
11382
11383 NewClause = OpenACCCopyInClause::Create(
11384 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11385 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11386 ParsedClause.isReadOnly(), ParsedClause.getVarList(),
11387 ParsedClause.getEndLoc());
11388}
11389
11390template <typename Derived>
11391void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
11392 const OpenACCCopyOutClause &C) {
11393 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11394 /*IsReadOnly=*/false, C.isZero());
11395
11396 NewClause = OpenACCCopyOutClause::Create(
11397 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11398 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11399 ParsedClause.isZero(), ParsedClause.getVarList(),
11400 ParsedClause.getEndLoc());
11401}
11402
11403template <typename Derived>
11404void OpenACCClauseTransform<Derived>::VisitCreateClause(
11405 const OpenACCCreateClause &C) {
11406 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11407 /*IsReadOnly=*/false, C.isZero());
11408
11409 NewClause = OpenACCCreateClause::Create(
11410 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11411 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11412 ParsedClause.isZero(), ParsedClause.getVarList(),
11413 ParsedClause.getEndLoc());
11414}
11415template <typename Derived>
11416void OpenACCClauseTransform<Derived>::VisitAttachClause(
11417 const OpenACCAttachClause &C) {
11418 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11419
11420 // Ensure each var is a pointer type.
11421 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11422 return Self.getSema().OpenACC().CheckVarIsPointerType(
11423 OpenACCClauseKind::Attach, E);
11424 }), VarList.end());
11425
11426 ParsedClause.setVarListDetails(VarList,
11427 /*IsReadOnly=*/false, /*IsZero=*/false);
11428 NewClause = OpenACCAttachClause::Create(
11429 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11430 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11431 ParsedClause.getEndLoc());
11432}
11433
11434template <typename Derived>
11435void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
11436 const OpenACCDevicePtrClause &C) {
11437 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11438
11439 // Ensure each var is a pointer type.
11440 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11441 return Self.getSema().OpenACC().CheckVarIsPointerType(
11442 OpenACCClauseKind::DevicePtr, E);
11443 }), VarList.end());
11444
11445 ParsedClause.setVarListDetails(VarList,
11446 /*IsReadOnly=*/false, /*IsZero=*/false);
11448 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11449 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11450 ParsedClause.getEndLoc());
11451}
11452
11453template <typename Derived>
11454void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
11455 const OpenACCNumWorkersClause &C) {
11456 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11457 assert(IntExpr && "num_workers clause constructed with invalid int expr");
11458
11459 ExprResult Res = Self.TransformExpr(IntExpr);
11460 if (!Res.isUsable())
11461 return;
11462
11463 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11464 C.getClauseKind(),
11465 C.getBeginLoc(), Res.get());
11466 if (!Res.isUsable())
11467 return;
11468
11469 ParsedClause.setIntExprDetails(Res.get());
11471 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11472 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11473 ParsedClause.getEndLoc());
11474}
11475
11476template <typename Derived>
11477void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
11478 const OpenACCVectorLengthClause &C) {
11479 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11480 assert(IntExpr && "vector_length clause constructed with invalid int expr");
11481
11482 ExprResult Res = Self.TransformExpr(IntExpr);
11483 if (!Res.isUsable())
11484 return;
11485
11486 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11487 C.getClauseKind(),
11488 C.getBeginLoc(), Res.get());
11489 if (!Res.isUsable())
11490 return;
11491
11492 ParsedClause.setIntExprDetails(Res.get());
11494 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11495 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11496 ParsedClause.getEndLoc());
11497}
11498
11499template <typename Derived>
11500void OpenACCClauseTransform<Derived>::VisitAsyncClause(
11501 const OpenACCAsyncClause &C) {
11502 if (C.hasIntExpr()) {
11503 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
11504 if (!Res.isUsable())
11505 return;
11506
11507 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11508 C.getClauseKind(),
11509 C.getBeginLoc(), Res.get());
11510 if (!Res.isUsable())
11511 return;
11512 ParsedClause.setIntExprDetails(Res.get());
11513 }
11514
11515 NewClause = OpenACCAsyncClause::Create(
11516 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11517 ParsedClause.getLParenLoc(),
11518 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
11519 : nullptr,
11520 ParsedClause.getEndLoc());
11521}
11522template <typename Derived>
11523void OpenACCClauseTransform<Derived>::VisitWaitClause(
11524 const OpenACCWaitClause &C) {
11525 if (!C.getLParenLoc().isInvalid()) {
11526 Expr *DevNumExpr = nullptr;
11527 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
11528
11529 // Instantiate devnum expr if it exists.
11530 if (C.getDevNumExpr()) {
11531 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
11532 if (!Res.isUsable())
11533 return;
11534 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11535 C.getClauseKind(),
11536 C.getBeginLoc(), Res.get());
11537 if (!Res.isUsable())
11538 return;
11539
11540 DevNumExpr = Res.get();
11541 }
11542
11543 // Instantiate queue ids.
11544 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
11545 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
11546 if (!Res.isUsable())
11547 return;
11548 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11549 C.getClauseKind(),
11550 C.getBeginLoc(), Res.get());
11551 if (!Res.isUsable())
11552 return;
11553
11554 InstantiatedQueueIdExprs.push_back(Res.get());
11555 }
11556
11557 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
11558 std::move(InstantiatedQueueIdExprs));
11559 }
11560
11561 NewClause = OpenACCWaitClause::Create(
11562 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11563 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
11564 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
11565 ParsedClause.getEndLoc());
11566}
11567
11568template <typename Derived>
11569void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
11570 const OpenACCDeviceTypeClause &C) {
11571 // Nothing to transform here, just create a new version of 'C'.
11573 Self.getSema().getASTContext(), C.getClauseKind(),
11574 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11575 C.getArchitectures(), ParsedClause.getEndLoc());
11576}
11577
11578template <typename Derived>
11579void OpenACCClauseTransform<Derived>::VisitAutoClause(
11580 const OpenACCAutoClause &C) {
11581 // Nothing to do, so just create a new node.
11582 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
11583 ParsedClause.getBeginLoc(),
11584 ParsedClause.getEndLoc());
11585}
11586
11587template <typename Derived>
11588void OpenACCClauseTransform<Derived>::VisitIndependentClause(
11589 const OpenACCIndependentClause &C) {
11590 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
11591 ParsedClause.getBeginLoc(),
11592 ParsedClause.getEndLoc());
11593}
11594
11595template <typename Derived>
11596void OpenACCClauseTransform<Derived>::VisitSeqClause(
11597 const OpenACCSeqClause &C) {
11598 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
11599 ParsedClause.getBeginLoc(),
11600 ParsedClause.getEndLoc());
11601}
11602
11603template <typename Derived>
11604void OpenACCClauseTransform<Derived>::VisitReductionClause(
11605 const OpenACCReductionClause &C) {
11606 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
11607 SmallVector<Expr *> ValidVars;
11608
11609 for (Expr *Var : TransformedVars) {
11610 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(Var);
11611 if (Res.isUsable())
11612 ValidVars.push_back(Res.get());
11613 }
11614
11616 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11617 ParsedClause.getLParenLoc(), C.getReductionOp(), ValidVars,
11618 ParsedClause.getEndLoc());
11619}
11620} // namespace
11621template <typename Derived>
11622OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
11623 ArrayRef<const OpenACCClause *> ExistingClauses,
11624 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
11625
11626 SemaOpenACC::OpenACCParsedClause ParsedClause(
11627 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
11628 ParsedClause.setEndLoc(OldClause->getEndLoc());
11629
11630 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
11631 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
11632
11633 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
11634 ParsedClause};
11635 Transform.Visit(OldClause);
11636
11637 return Transform.CreatedClause();
11638}
11639
11640template <typename Derived>
11642TreeTransform<Derived>::TransformOpenACCClauseList(
11644 llvm::SmallVector<OpenACCClause *> TransformedClauses;
11645 for (const auto *Clause : OldClauses) {
11646 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
11647 TransformedClauses, DirKind, Clause))
11648 TransformedClauses.push_back(TransformedClause);
11649 }
11650 return TransformedClauses;
11651}
11652
11653template <typename Derived>
11654StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
11655 OpenACCComputeConstruct *C) {
11656 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
11657
11658 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
11659 C->getBeginLoc()))
11660 return StmtError();
11661
11662 llvm::SmallVector<OpenACCClause *> TransformedClauses =
11663 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
11664 C->clauses());
11665 // Transform Structured Block.
11666 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(getSema().OpenACC(),
11667 C->getDirectiveKind());
11668 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
11669 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
11670 C->getBeginLoc(), C->getDirectiveKind(), StrBlock);
11671
11672 return getDerived().RebuildOpenACCComputeConstruct(
11673 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
11674 C->getEndLoc(), TransformedClauses, StrBlock);
11675}
11676
11677template <typename Derived>
11679TreeTransform<Derived>::TransformOpenACCLoopConstruct(OpenACCLoopConstruct *C) {
11680
11681 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
11682
11683 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
11684 C->getBeginLoc()))
11685 return StmtError();
11686
11687 llvm::SmallVector<OpenACCClause *> TransformedClauses =
11688 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
11689 C->clauses());
11690
11691 // Transform Loop.
11692 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(getSema().OpenACC(),
11693 C->getDirectiveKind());
11694 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
11695 Loop = getSema().OpenACC().ActOnAssociatedStmt(C->getBeginLoc(),
11696 C->getDirectiveKind(), Loop);
11697
11698 return getDerived().RebuildOpenACCLoopConstruct(
11699 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
11700 TransformedClauses, Loop);
11701}
11702
11703//===----------------------------------------------------------------------===//
11704// Expression transformation
11705//===----------------------------------------------------------------------===//
11706template<typename Derived>
11708TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
11709 return TransformExpr(E->getSubExpr());
11710}
11711
11712template <typename Derived>
11713ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
11714 SYCLUniqueStableNameExpr *E) {
11715 if (!E->isTypeDependent())
11716 return E;
11717
11718 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
11719
11720 if (!NewT)
11721 return ExprError();
11722
11723 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
11724 return E;
11725
11726 return getDerived().RebuildSYCLUniqueStableNameExpr(
11727 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
11728}
11729
11730template<typename Derived>
11732TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
11733 if (!E->isTypeDependent())
11734 return E;
11735
11736 return getDerived().RebuildPredefinedExpr(E->getLocation(),
11737 E->getIdentKind());
11738}
11739
11740template<typename Derived>
11742TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
11743 NestedNameSpecifierLoc QualifierLoc;
11744 if (E->getQualifierLoc()) {
11745 QualifierLoc
11746 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
11747 if (!QualifierLoc)
11748 return ExprError();
11749 }
11750
11751 ValueDecl *ND
11752 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
11753 E->getDecl()));
11754 if (!ND)
11755 return ExprError();
11756
11757 NamedDecl *Found = ND;
11758 if (E->getFoundDecl() != E->getDecl()) {
11759 Found = cast_or_null<NamedDecl>(
11760 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
11761 if (!Found)
11762 return ExprError();
11763 }
11764
11765 DeclarationNameInfo NameInfo = E->getNameInfo();
11766 if (NameInfo.getName()) {
11767 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11768 if (!NameInfo.getName())
11769 return ExprError();
11770 }
11771
11772 if (!getDerived().AlwaysRebuild() &&
11773 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
11774 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
11775 Found == E->getFoundDecl() &&
11776 NameInfo.getName() == E->getDecl()->getDeclName() &&
11777 !E->hasExplicitTemplateArgs()) {
11778
11779 // Mark it referenced in the new context regardless.
11780 // FIXME: this is a bit instantiation-specific.
11781 SemaRef.MarkDeclRefReferenced(E);
11782
11783 return E;
11784 }
11785
11786 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
11787 if (E->hasExplicitTemplateArgs()) {
11788 TemplateArgs = &TransArgs;
11789 TransArgs.setLAngleLoc(E->getLAngleLoc());
11790 TransArgs.setRAngleLoc(E->getRAngleLoc());
11791 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11792 E->getNumTemplateArgs(),
11793 TransArgs))
11794 return ExprError();
11795 }
11796
11797 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
11798 Found, TemplateArgs);
11799}
11800
11801template<typename Derived>
11803TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
11804 return E;
11805}
11806
11807template <typename Derived>
11808ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
11809 FixedPointLiteral *E) {
11810 return E;
11811}
11812
11813template<typename Derived>
11815TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
11816 return E;
11817}
11818
11819template<typename Derived>
11821TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
11822 return E;
11823}
11824
11825template<typename Derived>
11827TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
11828 return E;
11829}
11830
11831template<typename Derived>
11833TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
11834 return E;
11835}
11836
11837template<typename Derived>
11839TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
11840 return getDerived().TransformCallExpr(E);
11841}
11842
11843template<typename Derived>
11845TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
11846 ExprResult ControllingExpr;
11847 TypeSourceInfo *ControllingType = nullptr;
11848 if (E->isExprPredicate())
11849 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
11850 else
11851 ControllingType = getDerived().TransformType(E->getControllingType());
11852
11853 if (ControllingExpr.isInvalid() && !ControllingType)
11854 return ExprError();
11855
11856 SmallVector<Expr *, 4> AssocExprs;
11858 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
11859 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
11860 if (TSI) {
11861 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
11862 if (!AssocType)
11863 return ExprError();
11864 AssocTypes.push_back(AssocType);
11865 } else {
11866 AssocTypes.push_back(nullptr);
11867 }
11868
11869 ExprResult AssocExpr =
11870 getDerived().TransformExpr(Assoc.getAssociationExpr());
11871 if (AssocExpr.isInvalid())
11872 return ExprError();
11873 AssocExprs.push_back(AssocExpr.get());
11874 }
11875
11876 if (!ControllingType)
11877 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
11878 E->getDefaultLoc(),
11879 E->getRParenLoc(),
11880 ControllingExpr.get(),
11881 AssocTypes,
11882 AssocExprs);
11883 return getDerived().RebuildGenericSelectionExpr(
11884 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
11885 ControllingType, AssocTypes, AssocExprs);
11886}
11887
11888template<typename Derived>
11890TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
11891 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11892 if (SubExpr.isInvalid())
11893 return ExprError();
11894
11895 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
11896 return E;
11897
11898 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
11899 E->getRParen());
11900}
11901
11902/// The operand of a unary address-of operator has special rules: it's
11903/// allowed to refer to a non-static member of a class even if there's no 'this'
11904/// object available.
11905template<typename Derived>
11908 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
11909 return getDerived().TransformDependentScopeDeclRefExpr(
11910 DRE, /*IsAddressOfOperand=*/true, nullptr);
11911 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
11912 return getDerived().TransformUnresolvedLookupExpr(
11913 ULE, /*IsAddressOfOperand=*/true);
11914 else
11915 return getDerived().TransformExpr(E);
11916}
11917
11918template<typename Derived>
11921 ExprResult SubExpr;
11922 if (E->getOpcode() == UO_AddrOf)
11923 SubExpr = TransformAddressOfOperand(E->getSubExpr());
11924 else
11925 SubExpr = TransformExpr(E->getSubExpr());
11926 if (SubExpr.isInvalid())
11927 return ExprError();
11928
11929 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
11930 return E;
11931
11932 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
11933 E->getOpcode(),
11934 SubExpr.get());
11935}
11936
11937template<typename Derived>
11939TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
11940 // Transform the type.
11941 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11942 if (!Type)
11943 return ExprError();
11944
11945 // Transform all of the components into components similar to what the
11946 // parser uses.
11947 // FIXME: It would be slightly more efficient in the non-dependent case to
11948 // just map FieldDecls, rather than requiring the rebuilder to look for
11949 // the fields again. However, __builtin_offsetof is rare enough in
11950 // template code that we don't care.
11951 bool ExprChanged = false;
11952 typedef Sema::OffsetOfComponent Component;
11953 SmallVector<Component, 4> Components;
11954 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
11955 const OffsetOfNode &ON = E->getComponent(I);
11956 Component Comp;
11957 Comp.isBrackets = true;
11958 Comp.LocStart = ON.getSourceRange().getBegin();
11959 Comp.LocEnd = ON.getSourceRange().getEnd();
11960 switch (ON.getKind()) {
11961 case OffsetOfNode::Array: {
11962 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
11963 ExprResult Index = getDerived().TransformExpr(FromIndex);
11964 if (Index.isInvalid())
11965 return ExprError();
11966
11967 ExprChanged = ExprChanged || Index.get() != FromIndex;
11968 Comp.isBrackets = true;
11969 Comp.U.E = Index.get();
11970 break;
11971 }
11972
11975 Comp.isBrackets = false;
11976 Comp.U.IdentInfo = ON.getFieldName();
11977 if (!Comp.U.IdentInfo)
11978 continue;
11979
11980 break;
11981
11982 case OffsetOfNode::Base:
11983 // Will be recomputed during the rebuild.
11984 continue;
11985 }
11986
11987 Components.push_back(Comp);
11988 }
11989
11990 // If nothing changed, retain the existing expression.
11991 if (!getDerived().AlwaysRebuild() &&
11992 Type == E->getTypeSourceInfo() &&
11993 !ExprChanged)
11994 return E;
11995
11996 // Build a new offsetof expression.
11997 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
11998 Components, E->getRParenLoc());
11999}
12000
12001template<typename Derived>
12003TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
12004 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
12005 "opaque value expression requires transformation");
12006 return E;
12007}
12008
12009template<typename Derived>
12011TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
12012 return E;
12013}
12014
12015template <typename Derived>
12016ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) {
12018 bool Changed = false;
12019 for (Expr *C : E->subExpressions()) {
12020 ExprResult NewC = getDerived().TransformExpr(C);
12021 if (NewC.isInvalid())
12022 return ExprError();
12023 Children.push_back(NewC.get());
12024
12025 Changed |= NewC.get() != C;
12026 }
12027 if (!getDerived().AlwaysRebuild() && !Changed)
12028 return E;
12029 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
12030 Children, E->getType());
12031}
12032
12033template<typename Derived>
12035TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
12036 // Rebuild the syntactic form. The original syntactic form has
12037 // opaque-value expressions in it, so strip those away and rebuild
12038 // the result. This is a really awful way of doing this, but the
12039 // better solution (rebuilding the semantic expressions and
12040 // rebinding OVEs as necessary) doesn't work; we'd need
12041 // TreeTransform to not strip away implicit conversions.
12042 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
12043 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
12044 if (result.isInvalid()) return ExprError();
12045
12046 // If that gives us a pseudo-object result back, the pseudo-object
12047 // expression must have been an lvalue-to-rvalue conversion which we
12048 // should reapply.
12049 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
12050 result = SemaRef.PseudoObject().checkRValue(result.get());
12051
12052 return result;
12053}
12054
12055template<typename Derived>
12057TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
12058 UnaryExprOrTypeTraitExpr *E) {
12059 if (E->isArgumentType()) {
12060 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
12061
12062 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
12063 if (!NewT)
12064 return ExprError();
12065
12066 if (!getDerived().AlwaysRebuild() && OldT == NewT)
12067 return E;
12068
12069 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
12070 E->getKind(),
12071 E->getSourceRange());
12072 }
12073
12074 // C++0x [expr.sizeof]p1:
12075 // The operand is either an expression, which is an unevaluated operand
12076 // [...]
12077 EnterExpressionEvaluationContext Unevaluated(
12080
12081 // Try to recover if we have something like sizeof(T::X) where X is a type.
12082 // Notably, there must be *exactly* one set of parens if X is a type.
12083 TypeSourceInfo *RecoveryTSI = nullptr;
12084 ExprResult SubExpr;
12085 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
12086 if (auto *DRE =
12087 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
12088 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
12089 PE, DRE, false, &RecoveryTSI);
12090 else
12091 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
12092
12093 if (RecoveryTSI) {
12094 return getDerived().RebuildUnaryExprOrTypeTrait(
12095 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
12096 } else if (SubExpr.isInvalid())
12097 return ExprError();
12098
12099 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
12100 return E;
12101
12102 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
12103 E->getOperatorLoc(),
12104 E->getKind(),
12105 E->getSourceRange());
12106}
12107
12108template<typename Derived>
12110TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
12111 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
12112 if (LHS.isInvalid())
12113 return ExprError();
12114
12115 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
12116 if (RHS.isInvalid())
12117 return ExprError();
12118
12119
12120 if (!getDerived().AlwaysRebuild() &&
12121 LHS.get() == E->getLHS() &&
12122 RHS.get() == E->getRHS())
12123 return E;
12124
12125 return getDerived().RebuildArraySubscriptExpr(
12126 LHS.get(),
12127 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
12128}
12129
12130template <typename Derived>
12132TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
12133 ExprResult Base = getDerived().TransformExpr(E->getBase());
12134 if (Base.isInvalid())
12135 return ExprError();
12136
12137 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
12138 if (RowIdx.isInvalid())
12139 return ExprError();
12140
12141 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
12142 if (ColumnIdx.isInvalid())
12143 return ExprError();
12144
12145 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
12146 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
12147 return E;
12148
12149 return getDerived().RebuildMatrixSubscriptExpr(
12150 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
12151}
12152
12153template <typename Derived>
12155TreeTransform<Derived>::TransformArraySectionExpr(ArraySectionExpr *E) {
12156 ExprResult Base = getDerived().TransformExpr(E->getBase());
12157 if (Base.isInvalid())
12158 return ExprError();
12159
12160 ExprResult LowerBound;
12161 if (E->getLowerBound()) {
12162 LowerBound = getDerived().TransformExpr(E->getLowerBound());
12163 if (LowerBound.isInvalid())
12164 return ExprError();
12165 }
12166
12167 ExprResult Length;
12168 if (E->getLength()) {
12169 Length = getDerived().TransformExpr(E->getLength());
12170 if (Length.isInvalid())
12171 return ExprError();
12172 }
12173
12174 ExprResult Stride;
12175 if (E->isOMPArraySection()) {
12176 if (Expr *Str = E->getStride()) {
12177 Stride = getDerived().TransformExpr(Str);
12178 if (Stride.isInvalid())
12179 return ExprError();
12180 }
12181 }
12182
12183 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
12184 LowerBound.get() == E->getLowerBound() &&
12185 Length.get() == E->getLength() &&
12186 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
12187 return E;
12188
12189 return getDerived().RebuildArraySectionExpr(
12190 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
12191 LowerBound.get(), E->getColonLocFirst(),
12192 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
12193 Length.get(), Stride.get(), E->getRBracketLoc());
12194}
12195
12196template <typename Derived>
12198TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
12199 ExprResult Base = getDerived().TransformExpr(E->getBase());
12200 if (Base.isInvalid())
12201 return ExprError();
12202
12204 bool ErrorFound = false;
12205 for (Expr *Dim : E->getDimensions()) {
12206 ExprResult DimRes = getDerived().TransformExpr(Dim);
12207 if (DimRes.isInvalid()) {
12208 ErrorFound = true;
12209 continue;
12210 }
12211 Dims.push_back(DimRes.get());
12212 }
12213
12214 if (ErrorFound)
12215 return ExprError();
12216 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
12217 E->getRParenLoc(), Dims,
12218 E->getBracketsRanges());
12219}
12220
12221template <typename Derived>
12223TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) {
12224 unsigned NumIterators = E->numOfIterators();
12226
12227 bool ErrorFound = false;
12228 bool NeedToRebuild = getDerived().AlwaysRebuild();
12229 for (unsigned I = 0; I < NumIterators; ++I) {
12230 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
12231 Data[I].DeclIdent = D->getIdentifier();
12232 Data[I].DeclIdentLoc = D->getLocation();
12233 if (D->getLocation() == D->getBeginLoc()) {
12234 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
12235 "Implicit type must be int.");
12236 } else {
12237 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
12238 QualType DeclTy = getDerived().TransformType(D->getType());
12239 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
12240 }
12241 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
12242 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
12243 ExprResult End = getDerived().TransformExpr(Range.End);
12244 ExprResult Step = getDerived().TransformExpr(Range.Step);
12245 ErrorFound = ErrorFound ||
12246 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
12247 !Data[I].Type.get().isNull())) ||
12248 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
12249 if (ErrorFound)
12250 continue;
12251 Data[I].Range.Begin = Begin.get();
12252 Data[I].Range.End = End.get();
12253 Data[I].Range.Step = Step.get();
12254 Data[I].AssignLoc = E->getAssignLoc(I);
12255 Data[I].ColonLoc = E->getColonLoc(I);
12256 Data[I].SecColonLoc = E->getSecondColonLoc(I);
12257 NeedToRebuild =
12258 NeedToRebuild ||
12259 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
12260 D->getType().getTypePtrOrNull()) ||
12261 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
12262 Range.Step != Data[I].Range.Step;
12263 }
12264 if (ErrorFound)
12265 return ExprError();
12266 if (!NeedToRebuild)
12267 return E;
12268
12269 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
12270 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
12271 if (!Res.isUsable())
12272 return Res;
12273 auto *IE = cast<OMPIteratorExpr>(Res.get());
12274 for (unsigned I = 0; I < NumIterators; ++I)
12275 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
12276 IE->getIteratorDecl(I));
12277 return Res;
12278}
12279
12280template<typename Derived>
12282TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
12283 // Transform the callee.
12284 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
12285 if (Callee.isInvalid())
12286 return ExprError();
12287
12288 // Transform arguments.
12289 bool ArgChanged = false;
12291 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
12292 &ArgChanged))
12293 return ExprError();
12294
12295 if (!getDerived().AlwaysRebuild() &&
12296 Callee.get() == E->getCallee() &&
12297 !ArgChanged)
12298 return SemaRef.MaybeBindToTemporary(E);
12299
12300 // FIXME: Wrong source location information for the '('.
12301 SourceLocation FakeLParenLoc
12302 = ((Expr *)Callee.get())->getSourceRange().getBegin();
12303
12304 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
12305 if (E->hasStoredFPFeatures()) {
12306 FPOptionsOverride NewOverrides = E->getFPFeatures();
12307 getSema().CurFPFeatures =
12308 NewOverrides.applyOverrides(getSema().getLangOpts());
12309 getSema().FpPragmaStack.CurrentValue = NewOverrides;
12310 }
12311
12312 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
12313 Args,
12314 E->getRParenLoc());
12315}
12316
12317template<typename Derived>
12319TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
12320 ExprResult Base = getDerived().TransformExpr(E->getBase());
12321 if (Base.isInvalid())
12322 return ExprError();
12323
12324 NestedNameSpecifierLoc QualifierLoc;
12325 if (E->hasQualifier()) {
12326 QualifierLoc
12327 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12328
12329 if (!QualifierLoc)
12330 return ExprError();
12331 }
12332 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
12333
12334 ValueDecl *Member
12335 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
12336 E->getMemberDecl()));
12337 if (!Member)
12338 return ExprError();
12339
12340 NamedDecl *FoundDecl = E->getFoundDecl();
12341 if (FoundDecl == E->getMemberDecl()) {
12342 FoundDecl = Member;
12343 } else {
12344 FoundDecl = cast_or_null<NamedDecl>(
12345 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
12346 if (!FoundDecl)
12347 return ExprError();
12348 }
12349
12350 if (!getDerived().AlwaysRebuild() &&
12351 Base.get() == E->getBase() &&
12352 QualifierLoc == E->getQualifierLoc() &&
12353 Member == E->getMemberDecl() &&
12354 FoundDecl == E->getFoundDecl() &&
12355 !E->hasExplicitTemplateArgs()) {
12356
12357 // Skip for member expression of (this->f), rebuilt thisi->f is needed
12358 // for Openmp where the field need to be privatizized in the case.
12359 if (!(isa<CXXThisExpr>(E->getBase()) &&
12360 getSema().OpenMP().isOpenMPRebuildMemberExpr(
12361 cast<ValueDecl>(Member)))) {
12362 // Mark it referenced in the new context regardless.
12363 // FIXME: this is a bit instantiation-specific.
12364 SemaRef.MarkMemberReferenced(E);
12365 return E;
12366 }
12367 }
12368
12369 TemplateArgumentListInfo TransArgs;
12370 if (E->hasExplicitTemplateArgs()) {
12371 TransArgs.setLAngleLoc(E->getLAngleLoc());
12372 TransArgs.setRAngleLoc(E->getRAngleLoc());
12373 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
12374 E->getNumTemplateArgs(),
12375 TransArgs))
12376 return ExprError();
12377 }
12378
12379 // FIXME: Bogus source location for the operator
12380 SourceLocation FakeOperatorLoc =
12381 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
12382
12383 // FIXME: to do this check properly, we will need to preserve the
12384 // first-qualifier-in-scope here, just in case we had a dependent
12385 // base (and therefore couldn't do the check) and a
12386 // nested-name-qualifier (and therefore could do the lookup).
12387 NamedDecl *FirstQualifierInScope = nullptr;
12388 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
12389 if (MemberNameInfo.getName()) {
12390 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
12391 if (!MemberNameInfo.getName())
12392 return ExprError();
12393 }
12394
12395 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
12396 E->isArrow(),
12397 QualifierLoc,
12398 TemplateKWLoc,
12399 MemberNameInfo,
12400 Member,
12401 FoundDecl,
12402 (E->hasExplicitTemplateArgs()
12403 ? &TransArgs : nullptr),
12404 FirstQualifierInScope);
12405}
12406
12407template<typename Derived>
12409TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
12410 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
12411 if (LHS.isInvalid())
12412 return ExprError();
12413
12414 ExprResult RHS =
12415 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
12416 if (RHS.isInvalid())
12417 return ExprError();
12418
12419 if (!getDerived().AlwaysRebuild() &&
12420 LHS.get() == E->getLHS() &&
12421 RHS.get() == E->getRHS())
12422 return E;
12423
12424 if (E->isCompoundAssignmentOp())
12425 // FPFeatures has already been established from trailing storage
12426 return getDerived().RebuildBinaryOperator(
12427 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
12428 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
12429 FPOptionsOverride NewOverrides(E->getFPFeatures());
12430 getSema().CurFPFeatures =
12431 NewOverrides.applyOverrides(getSema().getLangOpts());
12432 getSema().FpPragmaStack.CurrentValue = NewOverrides;
12433 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
12434 LHS.get(), RHS.get());
12435}
12436
12437template <typename Derived>
12438ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
12439 CXXRewrittenBinaryOperator *E) {
12440 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
12441
12442 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
12443 if (LHS.isInvalid())
12444 return ExprError();
12445
12446 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
12447 if (RHS.isInvalid())
12448 return ExprError();
12449
12450 // Extract the already-resolved callee declarations so that we can restrict
12451 // ourselves to using them as the unqualified lookup results when rebuilding.
12452 UnresolvedSet<2> UnqualLookups;
12453 bool ChangedAnyLookups = false;
12454 Expr *PossibleBinOps[] = {E->getSemanticForm(),
12455 const_cast<Expr *>(Decomp.InnerBinOp)};
12456 for (Expr *PossibleBinOp : PossibleBinOps) {
12457 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
12458 if (!Op)
12459 continue;
12460 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
12461 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
12462 continue;
12463
12464 // Transform the callee in case we built a call to a local extern
12465 // declaration.
12466 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
12467 E->getOperatorLoc(), Callee->getFoundDecl()));
12468 if (!Found)
12469 return ExprError();
12470 if (Found != Callee->getFoundDecl())
12471 ChangedAnyLookups = true;
12472 UnqualLookups.addDecl(Found);
12473 }
12474
12475 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
12476 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
12477 // Mark all functions used in the rewrite as referenced. Note that when
12478 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
12479 // function calls, and/or there might be a user-defined conversion sequence
12480 // applied to the operands of the <.
12481 // FIXME: this is a bit instantiation-specific.
12482 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
12483 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
12484 return E;
12485 }
12486
12487 return getDerived().RebuildCXXRewrittenBinaryOperator(
12488 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
12489}
12490
12491template<typename Derived>
12493TreeTransform<Derived>::TransformCompoundAssignOperator(
12494 CompoundAssignOperator *E) {
12495 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
12496 FPOptionsOverride NewOverrides(E->getFPFeatures());
12497 getSema().CurFPFeatures =
12498 NewOverrides.applyOverrides(getSema().getLangOpts());
12499 getSema().FpPragmaStack.CurrentValue = NewOverrides;
12500 return getDerived().TransformBinaryOperator(E);
12501}
12502
12503template<typename Derived>
12504ExprResult TreeTransform<Derived>::
12505TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
12506 // Just rebuild the common and RHS expressions and see whether we
12507 // get any changes.
12508
12509 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
12510 if (commonExpr.isInvalid())
12511 return ExprError();
12512
12513 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
12514 if (rhs.isInvalid())
12515 return ExprError();
12516
12517 if (!getDerived().AlwaysRebuild() &&
12518 commonExpr.get() == e->getCommon() &&
12519 rhs.get() == e->getFalseExpr())
12520 return e;
12521
12522 return getDerived().RebuildConditionalOperator(commonExpr.get(),
12523 e->getQuestionLoc(),
12524 nullptr,
12525 e->getColonLoc(),
12526 rhs.get());
12527}
12528
12529template<typename Derived>
12531TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
12532 ExprResult Cond = getDerived().TransformExpr(E->getCond());
12533 if (Cond.isInvalid())
12534 return ExprError();
12535
12536 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
12537 if (LHS.isInvalid())
12538 return ExprError();
12539
12540 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
12541 if (RHS.isInvalid())
12542 return ExprError();
12543
12544 if (!getDerived().AlwaysRebuild() &&
12545 Cond.get() == E->getCond() &&
12546 LHS.get() == E->getLHS() &&
12547 RHS.get() == E->getRHS())
12548 return E;
12549
12550 return getDerived().RebuildConditionalOperator(Cond.get(),
12551 E->getQuestionLoc(),
12552 LHS.get(),
12553 E->getColonLoc(),
12554 RHS.get());
12555}
12556
12557template<typename Derived>
12559TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
12560 // Implicit casts are eliminated during transformation, since they
12561 // will be recomputed by semantic analysis after transformation.
12562 return getDerived().TransformExpr(E->getSubExprAsWritten());
12563}
12564
12565template<typename Derived>
12567TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
12568 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
12569 if (!Type)
12570 return ExprError();
12571
12572 ExprResult SubExpr
12573 = getDerived().TransformExpr(E->getSubExprAsWritten());
12574 if (SubExpr.isInvalid())
12575 return ExprError();
12576
12577 if (!getDerived().AlwaysRebuild() &&
12578 Type == E->getTypeInfoAsWritten() &&
12579 SubExpr.get() == E->getSubExpr())
12580 return E;
12581
12582 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
12583 Type,
12584 E->getRParenLoc(),
12585 SubExpr.get());
12586}
12587
12588template<typename Derived>
12590TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
12591 TypeSourceInfo *OldT = E->getTypeSourceInfo();
12592 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
12593 if (!NewT)
12594 return ExprError();
12595
12596 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
12597 if (Init.isInvalid())
12598 return ExprError();
12599
12600 if (!getDerived().AlwaysRebuild() &&
12601 OldT == NewT &&
12602 Init.get() == E->getInitializer())
12603 return SemaRef.MaybeBindToTemporary(E);
12604
12605 // Note: the expression type doesn't necessarily match the
12606 // type-as-written, but that's okay, because it should always be
12607 // derivable from the initializer.
12608
12609 return getDerived().RebuildCompoundLiteralExpr(
12610 E->getLParenLoc(), NewT,
12611 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
12612}
12613
12614template<typename Derived>
12616TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
12617 ExprResult Base = getDerived().TransformExpr(E->getBase());
12618 if (Base.isInvalid())
12619 return ExprError();
12620
12621 if (!getDerived().AlwaysRebuild() &&
12622 Base.get() == E->getBase())
12623 return E;
12624
12625 // FIXME: Bad source location
12626 SourceLocation FakeOperatorLoc =
12627 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
12628 return getDerived().RebuildExtVectorElementExpr(
12629 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
12630 E->getAccessor());
12631}
12632
12633template<typename Derived>
12635TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
12636 if (InitListExpr *Syntactic = E->getSyntacticForm())
12637 E = Syntactic;
12638
12639 bool InitChanged = false;
12640
12641 EnterExpressionEvaluationContext Context(
12643
12645 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
12646 Inits, &InitChanged))
12647 return ExprError();
12648
12649 if (!getDerived().AlwaysRebuild() && !InitChanged) {
12650 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
12651 // in some cases. We can't reuse it in general, because the syntactic and
12652 // semantic forms are linked, and we can't know that semantic form will
12653 // match even if the syntactic form does.
12654 }
12655
12656 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
12657 E->getRBraceLoc());
12658}
12659
12660template<typename Derived>
12662TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
12663 Designation Desig;
12664
12665 // transform the initializer value
12666 ExprResult Init = getDerived().TransformExpr(E->getInit());
12667 if (Init.isInvalid())
12668 return ExprError();
12669
12670 // transform the designators.
12671 SmallVector<Expr*, 4> ArrayExprs;
12672 bool ExprChanged = false;
12673 for (const DesignatedInitExpr::Designator &D : E->designators()) {
12674 if (D.isFieldDesignator()) {
12675 if (D.getFieldDecl()) {
12676 FieldDecl *Field = cast_or_null<FieldDecl>(
12677 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
12678 if (Field != D.getFieldDecl())
12679 // Rebuild the expression when the transformed FieldDecl is
12680 // different to the already assigned FieldDecl.
12681 ExprChanged = true;
12682 if (Field->isAnonymousStructOrUnion())
12683 continue;
12684 } else {
12685 // Ensure that the designator expression is rebuilt when there isn't
12686 // a resolved FieldDecl in the designator as we don't want to assign
12687 // a FieldDecl to a pattern designator that will be instantiated again.
12688 ExprChanged = true;
12689 }
12690 Desig.AddDesignator(Designator::CreateFieldDesignator(
12691 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
12692 continue;
12693 }
12694
12695 if (D.isArrayDesignator()) {
12696 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
12697 if (Index.isInvalid())
12698 return ExprError();
12699
12700 Desig.AddDesignator(
12701 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
12702
12703 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
12704 ArrayExprs.push_back(Index.get());
12705 continue;
12706 }
12707
12708 assert(D.isArrayRangeDesignator() && "New kind of designator?");
12709 ExprResult Start
12710 = getDerived().TransformExpr(E->getArrayRangeStart(D));
12711 if (Start.isInvalid())
12712 return ExprError();
12713
12714 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
12715 if (End.isInvalid())
12716 return ExprError();
12717
12718 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
12719 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
12720
12721 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
12722 End.get() != E->getArrayRangeEnd(D);
12723
12724 ArrayExprs.push_back(Start.get());
12725 ArrayExprs.push_back(End.get());
12726 }
12727
12728 if (!getDerived().AlwaysRebuild() &&
12729 Init.get() == E->getInit() &&
12730 !ExprChanged)
12731 return E;
12732
12733 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
12734 E->getEqualOrColonLoc(),
12735 E->usesGNUSyntax(), Init.get());
12736}
12737
12738// Seems that if TransformInitListExpr() only works on the syntactic form of an
12739// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
12740template<typename Derived>
12742TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
12743 DesignatedInitUpdateExpr *E) {
12744 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
12745 "initializer");
12746 return ExprError();
12747}
12748
12749template<typename Derived>
12751TreeTransform<Derived>::TransformNoInitExpr(
12752 NoInitExpr *E) {
12753 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
12754 return ExprError();
12755}
12756
12757template<typename Derived>
12759TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
12760 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
12761 return ExprError();
12762}
12763
12764template<typename Derived>
12766TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
12767 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
12768 return ExprError();
12769}
12770
12771template<typename Derived>
12773TreeTransform<Derived>::TransformImplicitValueInitExpr(
12774 ImplicitValueInitExpr *E) {
12775 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
12776
12777 // FIXME: Will we ever have proper type location here? Will we actually
12778 // need to transform the type?
12779 QualType T = getDerived().TransformType(E->getType());
12780 if (T.isNull())
12781 return ExprError();
12782
12783 if (!getDerived().AlwaysRebuild() &&
12784 T == E->getType())
12785 return E;
12786
12787 return getDerived().RebuildImplicitValueInitExpr(T);
12788}
12789
12790template<typename Derived>
12792TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
12793 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
12794 if (!TInfo)
12795 return ExprError();
12796
12797 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12798 if (SubExpr.isInvalid())
12799 return ExprError();
12800
12801 if (!getDerived().AlwaysRebuild() &&
12802 TInfo == E->getWrittenTypeInfo() &&
12803 SubExpr.get() == E->getSubExpr())
12804 return E;
12805
12806 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
12807 TInfo, E->getRParenLoc());
12808}
12809
12810template<typename Derived>
12812TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
12813 bool ArgumentChanged = false;
12815 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
12816 &ArgumentChanged))
12817 return ExprError();
12818
12819 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
12820 Inits,
12821 E->getRParenLoc());
12822}
12823
12824/// Transform an address-of-label expression.
12825///
12826/// By default, the transformation of an address-of-label expression always
12827/// rebuilds the expression, so that the label identifier can be resolved to
12828/// the corresponding label statement by semantic analysis.
12829template<typename Derived>
12831TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
12832 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
12833 E->getLabel());
12834 if (!LD)
12835 return ExprError();
12836
12837 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
12838 cast<LabelDecl>(LD));
12839}
12840
12841template<typename Derived>
12843TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
12844 SemaRef.ActOnStartStmtExpr();
12845 StmtResult SubStmt
12846 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
12847 if (SubStmt.isInvalid()) {
12848 SemaRef.ActOnStmtExprError();
12849 return ExprError();
12850 }
12851
12852 unsigned OldDepth = E->getTemplateDepth();
12853 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
12854
12855 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
12856 SubStmt.get() == E->getSubStmt()) {
12857 // Calling this an 'error' is unintuitive, but it does the right thing.
12858 SemaRef.ActOnStmtExprError();
12859 return SemaRef.MaybeBindToTemporary(E);
12860 }
12861
12862 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
12863 E->getRParenLoc(), NewDepth);
12864}
12865
12866template<typename Derived>
12868TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
12869 ExprResult Cond = getDerived().TransformExpr(E->getCond());
12870 if (Cond.isInvalid())
12871 return ExprError();
12872
12873 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
12874 if (LHS.isInvalid())
12875 return ExprError();
12876
12877 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
12878 if (RHS.isInvalid())
12879 return ExprError();
12880
12881 if (!getDerived().AlwaysRebuild() &&
12882 Cond.get() == E->getCond() &&
12883 LHS.get() == E->getLHS() &&
12884 RHS.get() == E->getRHS())
12885 return E;
12886
12887 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
12888 Cond.get(), LHS.get(), RHS.get(),
12889 E->getRParenLoc());
12890}
12891
12892template<typename Derived>
12894TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
12895 return E;
12896}
12897
12898template<typename Derived>
12900TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
12901 switch (E->getOperator()) {
12902 case OO_New:
12903 case OO_Delete:
12904 case OO_Array_New:
12905 case OO_Array_Delete:
12906 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
12907
12908 case OO_Subscript:
12909 case OO_Call: {
12910 // This is a call to an object's operator().
12911 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
12912
12913 // Transform the object itself.
12914 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
12915 if (Object.isInvalid())
12916 return ExprError();
12917
12918 // FIXME: Poor location information
12919 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
12920 static_cast<Expr *>(Object.get())->getEndLoc());
12921
12922 // Transform the call arguments.
12924 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
12925 Args))
12926 return ExprError();
12927
12928 if (E->getOperator() == OO_Subscript)
12929 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
12930 Args, E->getEndLoc());
12931
12932 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
12933 E->getEndLoc());
12934 }
12935
12936#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
12937 case OO_##Name: \
12938 break;
12939
12940#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
12941#include "clang/Basic/OperatorKinds.def"
12942
12943 case OO_Conditional:
12944 llvm_unreachable("conditional operator is not actually overloadable");
12945
12946 case OO_None:
12948 llvm_unreachable("not an overloaded operator?");
12949 }
12950
12952 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
12953 First = getDerived().TransformAddressOfOperand(E->getArg(0));
12954 else
12955 First = getDerived().TransformExpr(E->getArg(0));
12956 if (First.isInvalid())
12957 return ExprError();
12958
12959 ExprResult Second;
12960 if (E->getNumArgs() == 2) {
12961 Second =
12962 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
12963 if (Second.isInvalid())
12964 return ExprError();
12965 }
12966
12967 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
12968 FPOptionsOverride NewOverrides(E->getFPFeatures());
12969 getSema().CurFPFeatures =
12970 NewOverrides.applyOverrides(getSema().getLangOpts());
12971 getSema().FpPragmaStack.CurrentValue = NewOverrides;
12972
12973 Expr *Callee = E->getCallee();
12974 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
12975 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
12977 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
12978 return ExprError();
12979
12980 return getDerived().RebuildCXXOperatorCallExpr(
12981 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
12982 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
12983 }
12984
12985 UnresolvedSet<1> Functions;
12986 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
12987 Callee = ICE->getSubExprAsWritten();
12988 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
12989 ValueDecl *VD = cast_or_null<ValueDecl>(
12990 getDerived().TransformDecl(DR->getLocation(), DR));
12991 if (!VD)
12992 return ExprError();
12993
12994 if (!isa<CXXMethodDecl>(VD))
12995 Functions.addDecl(VD);
12996
12997 return getDerived().RebuildCXXOperatorCallExpr(
12998 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
12999 /*RequiresADL=*/false, Functions, First.get(), Second.get());
13000}
13001
13002template<typename Derived>
13004TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
13005 return getDerived().TransformCallExpr(E);
13006}
13007
13008template <typename Derived>
13009ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
13010 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
13011 getSema().CurContext != E->getParentContext();
13012
13013 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
13014 return E;
13015
13016 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
13017 E->getBeginLoc(), E->getEndLoc(),
13018 getSema().CurContext);
13019}
13020
13021template <typename Derived>
13022ExprResult TreeTransform<Derived>::TransformEmbedExpr(EmbedExpr *E) {
13023 return E;
13024}
13025
13026template<typename Derived>
13028TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
13029 // Transform the callee.
13030 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13031 if (Callee.isInvalid())
13032 return ExprError();
13033
13034 // Transform exec config.
13035 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
13036 if (EC.isInvalid())
13037 return ExprError();
13038
13039 // Transform arguments.
13040 bool ArgChanged = false;
13042 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13043 &ArgChanged))
13044 return ExprError();
13045
13046 if (!getDerived().AlwaysRebuild() &&
13047 Callee.get() == E->getCallee() &&
13048 !ArgChanged)
13049 return SemaRef.MaybeBindToTemporary(E);
13050
13051 // FIXME: Wrong source location information for the '('.
13052 SourceLocation FakeLParenLoc
13053 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13054 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13055 Args,
13056 E->getRParenLoc(), EC.get());
13057}
13058
13059template<typename Derived>
13062 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13063 if (!Type)
13064 return ExprError();
13065
13066 ExprResult SubExpr
13067 = getDerived().TransformExpr(E->getSubExprAsWritten());
13068 if (SubExpr.isInvalid())
13069 return ExprError();
13070
13071 if (!getDerived().AlwaysRebuild() &&
13072 Type == E->getTypeInfoAsWritten() &&
13073 SubExpr.get() == E->getSubExpr())
13074 return E;
13075 return getDerived().RebuildCXXNamedCastExpr(
13076 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
13077 Type, E->getAngleBrackets().getEnd(),
13078 // FIXME. this should be '(' location
13079 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
13080}
13081
13082template<typename Derived>
13085 TypeSourceInfo *TSI =
13086 getDerived().TransformType(BCE->getTypeInfoAsWritten());
13087 if (!TSI)
13088 return ExprError();
13089
13090 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
13091 if (Sub.isInvalid())
13092 return ExprError();
13093
13094 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
13095 Sub.get(), BCE->getEndLoc());
13096}
13097
13098template<typename Derived>
13100TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
13101 return getDerived().TransformCXXNamedCastExpr(E);
13102}
13103
13104template<typename Derived>
13106TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
13107 return getDerived().TransformCXXNamedCastExpr(E);
13108}
13109
13110template<typename Derived>
13112TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
13113 CXXReinterpretCastExpr *E) {
13114 return getDerived().TransformCXXNamedCastExpr(E);
13115}
13116
13117template<typename Derived>
13119TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
13120 return getDerived().TransformCXXNamedCastExpr(E);
13121}
13122
13123template<typename Derived>
13125TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
13126 return getDerived().TransformCXXNamedCastExpr(E);
13127}
13128
13129template<typename Derived>
13131TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
13132 CXXFunctionalCastExpr *E) {
13133 TypeSourceInfo *Type =
13134 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
13135 if (!Type)
13136 return ExprError();
13137
13138 ExprResult SubExpr
13139 = getDerived().TransformExpr(E->getSubExprAsWritten());
13140 if (SubExpr.isInvalid())
13141 return ExprError();
13142
13143 if (!getDerived().AlwaysRebuild() &&
13144 Type == E->getTypeInfoAsWritten() &&
13145 SubExpr.get() == E->getSubExpr())
13146 return E;
13147
13148 return getDerived().RebuildCXXFunctionalCastExpr(Type,
13149 E->getLParenLoc(),
13150 SubExpr.get(),
13151 E->getRParenLoc(),
13152 E->isListInitialization());
13153}
13154
13155template<typename Derived>
13157TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
13158 if (E->isTypeOperand()) {
13159 TypeSourceInfo *TInfo
13160 = getDerived().TransformType(E->getTypeOperandSourceInfo());
13161 if (!TInfo)
13162 return ExprError();
13163
13164 if (!getDerived().AlwaysRebuild() &&
13165 TInfo == E->getTypeOperandSourceInfo())
13166 return E;
13167
13168 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
13169 TInfo, E->getEndLoc());
13170 }
13171
13172 // Typeid's operand is an unevaluated context, unless it's a polymorphic
13173 // type. We must not unilaterally enter unevaluated context here, as then
13174 // semantic processing can re-transform an already transformed operand.
13175 Expr *Op = E->getExprOperand();
13177 if (E->isGLValue())
13178 if (auto *RecordT = Op->getType()->getAs<RecordType>())
13179 if (cast<CXXRecordDecl>(RecordT->getDecl())->isPolymorphic())
13180 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
13181
13182 EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx,
13184
13185 ExprResult SubExpr = getDerived().TransformExpr(Op);
13186 if (SubExpr.isInvalid())
13187 return ExprError();
13188
13189 if (!getDerived().AlwaysRebuild() &&
13190 SubExpr.get() == E->getExprOperand())
13191 return E;
13192
13193 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
13194 SubExpr.get(), E->getEndLoc());
13195}
13196
13197template<typename Derived>
13199TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
13200 if (E->isTypeOperand()) {
13201 TypeSourceInfo *TInfo
13202 = getDerived().TransformType(E->getTypeOperandSourceInfo());
13203 if (!TInfo)
13204 return ExprError();
13205
13206 if (!getDerived().AlwaysRebuild() &&
13207 TInfo == E->getTypeOperandSourceInfo())
13208 return E;
13209
13210 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
13211 TInfo, E->getEndLoc());
13212 }
13213
13214 EnterExpressionEvaluationContext Unevaluated(
13216
13217 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
13218 if (SubExpr.isInvalid())
13219 return ExprError();
13220
13221 if (!getDerived().AlwaysRebuild() &&
13222 SubExpr.get() == E->getExprOperand())
13223 return E;
13224
13225 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
13226 SubExpr.get(), E->getEndLoc());
13227}
13228
13229template<typename Derived>
13231TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
13232 return E;
13233}
13234
13235template<typename Derived>
13237TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
13238 CXXNullPtrLiteralExpr *E) {
13239 return E;
13240}
13241
13242template<typename Derived>
13244TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
13245
13246 // In lambdas, the qualifiers of the type depends of where in
13247 // the call operator `this` appear, and we do not have a good way to
13248 // rebuild this information, so we transform the type.
13249 //
13250 // In other contexts, the type of `this` may be overrided
13251 // for type deduction, so we need to recompute it.
13252 //
13253 // Always recompute the type if we're in the body of a lambda, and
13254 // 'this' is dependent on a lambda's explicit object parameter.
13255 QualType T = [&]() {
13256 auto &S = getSema();
13257 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
13258 return S.getCurrentThisType();
13259 if (S.getCurLambda())
13260 return getDerived().TransformType(E->getType());
13261 return S.getCurrentThisType();
13262 }();
13263
13264 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
13265 // Mark it referenced in the new context regardless.
13266 // FIXME: this is a bit instantiation-specific.
13267 getSema().MarkThisReferenced(E);
13268 return E;
13269 }
13270
13271 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
13272}
13273
13274template<typename Derived>
13276TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
13277 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13278 if (SubExpr.isInvalid())
13279 return ExprError();
13280
13281 if (!getDerived().AlwaysRebuild() &&
13282 SubExpr.get() == E->getSubExpr())
13283 return E;
13284
13285 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
13286 E->isThrownVariableInScope());
13287}
13288
13289template<typename Derived>
13291TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
13292 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
13293 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
13294 if (!Param)
13295 return ExprError();
13296
13297 ExprResult InitRes;
13298 if (E->hasRewrittenInit()) {
13299 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
13300 if (InitRes.isInvalid())
13301 return ExprError();
13302 }
13303
13304 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
13305 E->getUsedContext() == SemaRef.CurContext &&
13306 InitRes.get() == E->getRewrittenExpr())
13307 return E;
13308
13309 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
13310 InitRes.get());
13311}
13312
13313template<typename Derived>
13315TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
13316 FieldDecl *Field = cast_or_null<FieldDecl>(
13317 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
13318 if (!Field)
13319 return ExprError();
13320
13321 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
13322 E->getUsedContext() == SemaRef.CurContext)
13323 return E;
13324
13325 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
13326}
13327
13328template<typename Derived>
13330TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
13331 CXXScalarValueInitExpr *E) {
13332 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
13333 if (!T)
13334 return ExprError();
13335
13336 if (!getDerived().AlwaysRebuild() &&
13337 T == E->getTypeSourceInfo())
13338 return E;
13339
13340 return getDerived().RebuildCXXScalarValueInitExpr(T,
13341 /*FIXME:*/T->getTypeLoc().getEndLoc(),
13342 E->getRParenLoc());
13343}
13344
13345template<typename Derived>
13347TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
13348 // Transform the type that we're allocating
13349 TypeSourceInfo *AllocTypeInfo =
13350 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
13351 if (!AllocTypeInfo)
13352 return ExprError();
13353
13354 // Transform the size of the array we're allocating (if any).
13355 std::optional<Expr *> ArraySize;
13356 if (E->isArray()) {
13357 ExprResult NewArraySize;
13358 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
13359 NewArraySize = getDerived().TransformExpr(*OldArraySize);
13360 if (NewArraySize.isInvalid())
13361 return ExprError();
13362 }
13363 ArraySize = NewArraySize.get();
13364 }
13365
13366 // Transform the placement arguments (if any).
13367 bool ArgumentChanged = false;
13368 SmallVector<Expr*, 8> PlacementArgs;
13369 if (getDerived().TransformExprs(E->getPlacementArgs(),
13370 E->getNumPlacementArgs(), true,
13371 PlacementArgs, &ArgumentChanged))
13372 return ExprError();
13373
13374 // Transform the initializer (if any).
13375 Expr *OldInit = E->getInitializer();
13376 ExprResult NewInit;
13377 if (OldInit)
13378 NewInit = getDerived().TransformInitializer(OldInit, true);
13379 if (NewInit.isInvalid())
13380 return ExprError();
13381
13382 // Transform new operator and delete operator.
13383 FunctionDecl *OperatorNew = nullptr;
13384 if (E->getOperatorNew()) {
13385 OperatorNew = cast_or_null<FunctionDecl>(
13386 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
13387 if (!OperatorNew)
13388 return ExprError();
13389 }
13390
13391 FunctionDecl *OperatorDelete = nullptr;
13392 if (E->getOperatorDelete()) {
13393 OperatorDelete = cast_or_null<FunctionDecl>(
13394 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
13395 if (!OperatorDelete)
13396 return ExprError();
13397 }
13398
13399 if (!getDerived().AlwaysRebuild() &&
13400 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
13401 ArraySize == E->getArraySize() &&
13402 NewInit.get() == OldInit &&
13403 OperatorNew == E->getOperatorNew() &&
13404 OperatorDelete == E->getOperatorDelete() &&
13405 !ArgumentChanged) {
13406 // Mark any declarations we need as referenced.
13407 // FIXME: instantiation-specific.
13408 if (OperatorNew)
13409 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
13410 if (OperatorDelete)
13411 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
13412
13413 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
13414 QualType ElementType
13415 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
13416 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
13417 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
13418 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
13420 }
13421 }
13422 }
13423
13424 return E;
13425 }
13426
13427 QualType AllocType = AllocTypeInfo->getType();
13428 if (!ArraySize) {
13429 // If no array size was specified, but the new expression was
13430 // instantiated with an array type (e.g., "new T" where T is
13431 // instantiated with "int[4]"), extract the outer bound from the
13432 // array type as our array size. We do this with constant and
13433 // dependently-sized array types.
13434 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
13435 if (!ArrayT) {
13436 // Do nothing
13437 } else if (const ConstantArrayType *ConsArrayT
13438 = dyn_cast<ConstantArrayType>(ArrayT)) {
13439 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
13440 SemaRef.Context.getSizeType(),
13441 /*FIXME:*/ E->getBeginLoc());
13442 AllocType = ConsArrayT->getElementType();
13443 } else if (const DependentSizedArrayType *DepArrayT
13444 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
13445 if (DepArrayT->getSizeExpr()) {
13446 ArraySize = DepArrayT->getSizeExpr();
13447 AllocType = DepArrayT->getElementType();
13448 }
13449 }
13450 }
13451
13452 return getDerived().RebuildCXXNewExpr(
13453 E->getBeginLoc(), E->isGlobalNew(),
13454 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
13455 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
13456 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
13457}
13458
13459template<typename Derived>
13461TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
13462 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
13463 if (Operand.isInvalid())
13464 return ExprError();
13465
13466 // Transform the delete operator, if known.
13467 FunctionDecl *OperatorDelete = nullptr;
13468 if (E->getOperatorDelete()) {
13469 OperatorDelete = cast_or_null<FunctionDecl>(
13470 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
13471 if (!OperatorDelete)
13472 return ExprError();
13473 }
13474
13475 if (!getDerived().AlwaysRebuild() &&
13476 Operand.get() == E->getArgument() &&
13477 OperatorDelete == E->getOperatorDelete()) {
13478 // Mark any declarations we need as referenced.
13479 // FIXME: instantiation-specific.
13480 if (OperatorDelete)
13481 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
13482
13483 if (!E->getArgument()->isTypeDependent()) {
13484 QualType Destroyed = SemaRef.Context.getBaseElementType(
13485 E->getDestroyedType());
13486 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
13487 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
13489 SemaRef.LookupDestructor(Record));
13490 }
13491 }
13492
13493 return E;
13494 }
13495
13496 return getDerived().RebuildCXXDeleteExpr(
13497 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
13498}
13499
13500template<typename Derived>
13502TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
13503 CXXPseudoDestructorExpr *E) {
13504 ExprResult Base = getDerived().TransformExpr(E->getBase());
13505 if (Base.isInvalid())
13506 return ExprError();
13507
13508 ParsedType ObjectTypePtr;
13509 bool MayBePseudoDestructor = false;
13510 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
13511 E->getOperatorLoc(),
13512 E->isArrow()? tok::arrow : tok::period,
13513 ObjectTypePtr,
13514 MayBePseudoDestructor);
13515 if (Base.isInvalid())
13516 return ExprError();
13517
13518 QualType ObjectType = ObjectTypePtr.get();
13519 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
13520 if (QualifierLoc) {
13521 QualifierLoc
13522 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
13523 if (!QualifierLoc)
13524 return ExprError();
13525 }
13526 CXXScopeSpec SS;
13527 SS.Adopt(QualifierLoc);
13528
13529 PseudoDestructorTypeStorage Destroyed;
13530 if (E->getDestroyedTypeInfo()) {
13531 TypeSourceInfo *DestroyedTypeInfo
13532 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
13533 ObjectType, nullptr, SS);
13534 if (!DestroyedTypeInfo)
13535 return ExprError();
13536 Destroyed = DestroyedTypeInfo;
13537 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
13538 // We aren't likely to be able to resolve the identifier down to a type
13539 // now anyway, so just retain the identifier.
13540 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
13541 E->getDestroyedTypeLoc());
13542 } else {
13543 // Look for a destructor known with the given name.
13544 ParsedType T = SemaRef.getDestructorName(
13545 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
13546 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
13547 if (!T)
13548 return ExprError();
13549
13550 Destroyed
13552 E->getDestroyedTypeLoc());
13553 }
13554
13555 TypeSourceInfo *ScopeTypeInfo = nullptr;
13556 if (E->getScopeTypeInfo()) {
13557 CXXScopeSpec EmptySS;
13558 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
13559 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
13560 if (!ScopeTypeInfo)
13561 return ExprError();
13562 }
13563
13564 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
13565 E->getOperatorLoc(),
13566 E->isArrow(),
13567 SS,
13568 ScopeTypeInfo,
13569 E->getColonColonLoc(),
13570 E->getTildeLoc(),
13571 Destroyed);
13572}
13573
13574template <typename Derived>
13576 bool RequiresADL,
13577 LookupResult &R) {
13578 // Transform all the decls.
13579 bool AllEmptyPacks = true;
13580 for (auto *OldD : Old->decls()) {
13581 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
13582 if (!InstD) {
13583 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
13584 // This can happen because of dependent hiding.
13585 if (isa<UsingShadowDecl>(OldD))
13586 continue;
13587 else {
13588 R.clear();
13589 return true;
13590 }
13591 }
13592
13593 // Expand using pack declarations.
13594 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
13595 ArrayRef<NamedDecl*> Decls = SingleDecl;
13596 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
13597 Decls = UPD->expansions();
13598
13599 // Expand using declarations.
13600 for (auto *D : Decls) {
13601 if (auto *UD = dyn_cast<UsingDecl>(D)) {
13602 for (auto *SD : UD->shadows())
13603 R.addDecl(SD);
13604 } else {
13605 R.addDecl(D);
13606 }
13607 }
13608
13609 AllEmptyPacks &= Decls.empty();
13610 };
13611
13612 // C++ [temp.res]/8.4.2:
13613 // The program is ill-formed, no diagnostic required, if [...] lookup for
13614 // a name in the template definition found a using-declaration, but the
13615 // lookup in the corresponding scope in the instantiation odoes not find
13616 // any declarations because the using-declaration was a pack expansion and
13617 // the corresponding pack is empty
13618 if (AllEmptyPacks && !RequiresADL) {
13619 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
13620 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
13621 return true;
13622 }
13623
13624 // Resolve a kind, but don't do any further analysis. If it's
13625 // ambiguous, the callee needs to deal with it.
13626 R.resolveKind();
13627
13628 if (Old->hasTemplateKeyword() && !R.empty()) {
13630 getSema().FilterAcceptableTemplateNames(R,
13631 /*AllowFunctionTemplates=*/true,
13632 /*AllowDependent=*/true);
13633 if (R.empty()) {
13634 // If a 'template' keyword was used, a lookup that finds only non-template
13635 // names is an error.
13636 getSema().Diag(R.getNameLoc(),
13637 diag::err_template_kw_refers_to_non_template)
13639 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
13640 getSema().Diag(FoundDecl->getLocation(),
13641 diag::note_template_kw_refers_to_non_template)
13642 << R.getLookupName();
13643 return true;
13644 }
13645 }
13646
13647 return false;
13648}
13649
13650template <typename Derived>
13652 UnresolvedLookupExpr *Old) {
13653 return TransformUnresolvedLookupExpr(Old, /*IsAddressOfOperand=*/false);
13654}
13655
13656template <typename Derived>
13659 bool IsAddressOfOperand) {
13660 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
13662
13663 // Transform the declaration set.
13664 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
13665 return ExprError();
13666
13667 // Rebuild the nested-name qualifier, if present.
13668 CXXScopeSpec SS;
13669 if (Old->getQualifierLoc()) {
13670 NestedNameSpecifierLoc QualifierLoc
13671 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
13672 if (!QualifierLoc)
13673 return ExprError();
13674
13675 SS.Adopt(QualifierLoc);
13676 }
13677
13678 if (Old->getNamingClass()) {
13679 CXXRecordDecl *NamingClass
13680 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
13681 Old->getNameLoc(),
13682 Old->getNamingClass()));
13683 if (!NamingClass) {
13684 R.clear();
13685 return ExprError();
13686 }
13687
13688 R.setNamingClass(NamingClass);
13689 }
13690
13691 // Rebuild the template arguments, if any.
13692 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
13693 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
13694 if (Old->hasExplicitTemplateArgs() &&
13695 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
13696 Old->getNumTemplateArgs(),
13697 TransArgs)) {
13698 R.clear();
13699 return ExprError();
13700 }
13701
13702 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
13703 // a non-static data member is named in an unevaluated operand, or when
13704 // a member is named in a dependent class scope function template explicit
13705 // specialization that is neither declared static nor with an explicit object
13706 // parameter.
13707 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
13708 return SemaRef.BuildPossibleImplicitMemberExpr(
13709 SS, TemplateKWLoc, R,
13710 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
13711 /*S=*/nullptr);
13712
13713 // If we have neither explicit template arguments, nor the template keyword,
13714 // it's a normal declaration name or member reference.
13715 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
13716 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
13717
13718 // If we have template arguments, then rebuild the template-id expression.
13719 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
13720 Old->requiresADL(), &TransArgs);
13721}
13722
13723template<typename Derived>
13725TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
13726 bool ArgChanged = false;
13728 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
13729 TypeSourceInfo *From = E->getArg(I);
13730 TypeLoc FromTL = From->getTypeLoc();
13731 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
13732 TypeLocBuilder TLB;
13733 TLB.reserve(FromTL.getFullDataSize());
13734 QualType To = getDerived().TransformType(TLB, FromTL);
13735 if (To.isNull())
13736 return ExprError();
13737
13738 if (To == From->getType())
13739 Args.push_back(From);
13740 else {
13741 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
13742 ArgChanged = true;
13743 }
13744 continue;
13745 }
13746
13747 ArgChanged = true;
13748
13749 // We have a pack expansion. Instantiate it.
13750 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
13751 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
13753 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
13754
13755 // Determine whether the set of unexpanded parameter packs can and should
13756 // be expanded.
13757 bool Expand = true;
13758 bool RetainExpansion = false;
13759 std::optional<unsigned> OrigNumExpansions =
13760 ExpansionTL.getTypePtr()->getNumExpansions();
13761 std::optional<unsigned> NumExpansions = OrigNumExpansions;
13762 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
13763 PatternTL.getSourceRange(),
13764 Unexpanded,
13765 Expand, RetainExpansion,
13766 NumExpansions))
13767 return ExprError();
13768
13769 if (!Expand) {
13770 // The transform has determined that we should perform a simple
13771 // transformation on the pack expansion, producing another pack
13772 // expansion.
13773 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
13774
13775 TypeLocBuilder TLB;
13776 TLB.reserve(From->getTypeLoc().getFullDataSize());
13777
13778 QualType To = getDerived().TransformType(TLB, PatternTL);
13779 if (To.isNull())
13780 return ExprError();
13781
13782 To = getDerived().RebuildPackExpansionType(To,
13783 PatternTL.getSourceRange(),
13784 ExpansionTL.getEllipsisLoc(),
13785 NumExpansions);
13786 if (To.isNull())
13787 return ExprError();
13788
13789 PackExpansionTypeLoc ToExpansionTL
13790 = TLB.push<PackExpansionTypeLoc>(To);
13791 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
13792 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
13793 continue;
13794 }
13795
13796 // Expand the pack expansion by substituting for each argument in the
13797 // pack(s).
13798 for (unsigned I = 0; I != *NumExpansions; ++I) {
13799 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
13800 TypeLocBuilder TLB;
13801 TLB.reserve(PatternTL.getFullDataSize());
13802 QualType To = getDerived().TransformType(TLB, PatternTL);
13803 if (To.isNull())
13804 return ExprError();
13805
13806 if (To->containsUnexpandedParameterPack()) {
13807 To = getDerived().RebuildPackExpansionType(To,
13808 PatternTL.getSourceRange(),
13809 ExpansionTL.getEllipsisLoc(),
13810 NumExpansions);
13811 if (To.isNull())
13812 return ExprError();
13813
13814 PackExpansionTypeLoc ToExpansionTL
13815 = TLB.push<PackExpansionTypeLoc>(To);
13816 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
13817 }
13818
13819 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
13820 }
13821
13822 if (!RetainExpansion)
13823 continue;
13824
13825 // If we're supposed to retain a pack expansion, do so by temporarily
13826 // forgetting the partially-substituted parameter pack.
13827 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
13828
13829 TypeLocBuilder TLB;
13830 TLB.reserve(From->getTypeLoc().getFullDataSize());
13831
13832 QualType To = getDerived().TransformType(TLB, PatternTL);
13833 if (To.isNull())
13834 return ExprError();
13835
13836 To = getDerived().RebuildPackExpansionType(To,
13837 PatternTL.getSourceRange(),
13838 ExpansionTL.getEllipsisLoc(),
13839 NumExpansions);
13840 if (To.isNull())
13841 return ExprError();
13842
13843 PackExpansionTypeLoc ToExpansionTL
13844 = TLB.push<PackExpansionTypeLoc>(To);
13845 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
13846 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
13847 }
13848
13849 if (!getDerived().AlwaysRebuild() && !ArgChanged)
13850 return E;
13851
13852 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
13853 E->getEndLoc());
13854}
13855
13856template<typename Derived>
13858TreeTransform<Derived>::TransformConceptSpecializationExpr(
13859 ConceptSpecializationExpr *E) {
13860 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
13861 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
13862 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
13863 Old->NumTemplateArgs, TransArgs))
13864 return ExprError();
13865
13866 return getDerived().RebuildConceptSpecializationExpr(
13867 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
13868 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
13869 &TransArgs);
13870}
13871
13872template<typename Derived>
13874TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) {
13875 SmallVector<ParmVarDecl*, 4> TransParams;
13876 SmallVector<QualType, 4> TransParamTypes;
13877 Sema::ExtParameterInfoBuilder ExtParamInfos;
13878
13879 // C++2a [expr.prim.req]p2
13880 // Expressions appearing within a requirement-body are unevaluated operands.
13881 EnterExpressionEvaluationContext Ctx(
13884
13885 RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
13886 getSema().Context, getSema().CurContext,
13887 E->getBody()->getBeginLoc());
13888
13889 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
13890
13891 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
13892 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
13893 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
13894
13895 for (ParmVarDecl *Param : TransParams)
13896 if (Param)
13897 Param->setDeclContext(Body);
13898
13899 // On failure to transform, TransformRequiresTypeParams returns an expression
13900 // in the event that the transformation of the type params failed in some way.
13901 // It is expected that this will result in a 'not satisfied' Requires clause
13902 // when instantiating.
13903 if (!TypeParamResult.isUnset())
13904 return TypeParamResult;
13905
13907 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
13908 TransReqs))
13909 return ExprError();
13910
13911 for (concepts::Requirement *Req : TransReqs) {
13912 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
13913 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
13914 ER->getReturnTypeRequirement()
13915 .getTypeConstraintTemplateParameterList()->getParam(0)
13916 ->setDeclContext(Body);
13917 }
13918 }
13919 }
13920
13921 return getDerived().RebuildRequiresExpr(
13922 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
13923 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
13924}
13925
13926template<typename Derived>
13930 for (concepts::Requirement *Req : Reqs) {
13931 concepts::Requirement *TransReq = nullptr;
13932 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
13933 TransReq = getDerived().TransformTypeRequirement(TypeReq);
13934 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
13935 TransReq = getDerived().TransformExprRequirement(ExprReq);
13936 else
13937 TransReq = getDerived().TransformNestedRequirement(
13938 cast<concepts::NestedRequirement>(Req));
13939 if (!TransReq)
13940 return true;
13941 Transformed.push_back(TransReq);
13942 }
13943 return false;
13944}
13945
13946template<typename Derived>
13950 if (Req->isSubstitutionFailure()) {
13951 if (getDerived().AlwaysRebuild())
13952 return getDerived().RebuildTypeRequirement(
13954 return Req;
13955 }
13956 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
13957 if (!TransType)
13958 return nullptr;
13959 return getDerived().RebuildTypeRequirement(TransType);
13960}
13961
13962template<typename Derived>
13965 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
13966 if (Req->isExprSubstitutionFailure())
13967 TransExpr = Req->getExprSubstitutionDiagnostic();
13968 else {
13969 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
13970 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
13971 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
13972 if (TransExprRes.isInvalid())
13973 return nullptr;
13974 TransExpr = TransExprRes.get();
13975 }
13976
13977 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
13978 const auto &RetReq = Req->getReturnTypeRequirement();
13979 if (RetReq.isEmpty())
13980 TransRetReq.emplace();
13981 else if (RetReq.isSubstitutionFailure())
13982 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
13983 else if (RetReq.isTypeConstraint()) {
13984 TemplateParameterList *OrigTPL =
13985 RetReq.getTypeConstraintTemplateParameterList();
13987 getDerived().TransformTemplateParameterList(OrigTPL);
13988 if (!TPL)
13989 return nullptr;
13990 TransRetReq.emplace(TPL);
13991 }
13992 assert(TransRetReq && "All code paths leading here must set TransRetReq");
13993 if (Expr *E = TransExpr.dyn_cast<Expr *>())
13994 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
13995 Req->getNoexceptLoc(),
13996 std::move(*TransRetReq));
13997 return getDerived().RebuildExprRequirement(
13999 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
14000}
14001
14002template<typename Derived>
14006 if (Req->hasInvalidConstraint()) {
14007 if (getDerived().AlwaysRebuild())
14008 return getDerived().RebuildNestedRequirement(
14010 return Req;
14011 }
14012 ExprResult TransConstraint =
14013 getDerived().TransformExpr(Req->getConstraintExpr());
14014 if (TransConstraint.isInvalid())
14015 return nullptr;
14016 return getDerived().RebuildNestedRequirement(TransConstraint.get());
14017}
14018
14019template<typename Derived>
14022 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
14023 if (!T)
14024 return ExprError();
14025
14026 if (!getDerived().AlwaysRebuild() &&
14027 T == E->getQueriedTypeSourceInfo())
14028 return E;
14029
14030 ExprResult SubExpr;
14031 {
14034 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
14035 if (SubExpr.isInvalid())
14036 return ExprError();
14037
14038 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
14039 return E;
14040 }
14041
14042 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
14043 SubExpr.get(), E->getEndLoc());
14044}
14045
14046template<typename Derived>
14048TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
14049 ExprResult SubExpr;
14050 {
14051 EnterExpressionEvaluationContext Unevaluated(
14053 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
14054 if (SubExpr.isInvalid())
14055 return ExprError();
14056
14057 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
14058 return E;
14059 }
14060
14061 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
14062 SubExpr.get(), E->getEndLoc());
14063}
14064
14065template <typename Derived>
14067 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
14068 TypeSourceInfo **RecoveryTSI) {
14069 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
14070 DRE, AddrTaken, RecoveryTSI);
14071
14072 // Propagate both errors and recovered types, which return ExprEmpty.
14073 if (!NewDRE.isUsable())
14074 return NewDRE;
14075
14076 // We got an expr, wrap it up in parens.
14077 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
14078 return PE;
14079 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
14080 PE->getRParen());
14081}
14082
14083template <typename Derived>
14086 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
14087 nullptr);
14088}
14089
14090template <typename Derived>
14092 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
14093 TypeSourceInfo **RecoveryTSI) {
14094 assert(E->getQualifierLoc());
14095 NestedNameSpecifierLoc QualifierLoc =
14096 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
14097 if (!QualifierLoc)
14098 return ExprError();
14099 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14100
14101 // TODO: If this is a conversion-function-id, verify that the
14102 // destination type name (if present) resolves the same way after
14103 // instantiation as it did in the local scope.
14104
14105 DeclarationNameInfo NameInfo =
14106 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
14107 if (!NameInfo.getName())
14108 return ExprError();
14109
14110 if (!E->hasExplicitTemplateArgs()) {
14111 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
14112 // Note: it is sufficient to compare the Name component of NameInfo:
14113 // if name has not changed, DNLoc has not changed either.
14114 NameInfo.getName() == E->getDeclName())
14115 return E;
14116
14117 return getDerived().RebuildDependentScopeDeclRefExpr(
14118 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
14119 IsAddressOfOperand, RecoveryTSI);
14120 }
14121
14122 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
14123 if (getDerived().TransformTemplateArguments(
14124 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
14125 return ExprError();
14126
14127 return getDerived().RebuildDependentScopeDeclRefExpr(
14128 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
14129 RecoveryTSI);
14130}
14131
14132template<typename Derived>
14134TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
14135 // CXXConstructExprs other than for list-initialization and
14136 // CXXTemporaryObjectExpr are always implicit, so when we have
14137 // a 1-argument construction we just transform that argument.
14138 if (getDerived().AllowSkippingCXXConstructExpr() &&
14139 ((E->getNumArgs() == 1 ||
14140 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
14141 (!getDerived().DropCallArgument(E->getArg(0))) &&
14142 !E->isListInitialization()))
14143 return getDerived().TransformInitializer(E->getArg(0),
14144 /*DirectInit*/ false);
14145
14146 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
14147
14148 QualType T = getDerived().TransformType(E->getType());
14149 if (T.isNull())
14150 return ExprError();
14151
14152 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
14153 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
14154 if (!Constructor)
14155 return ExprError();
14156
14157 bool ArgumentChanged = false;
14159 {
14160 EnterExpressionEvaluationContext Context(
14162 E->isListInitialization());
14163 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14164 &ArgumentChanged))
14165 return ExprError();
14166 }
14167
14168 if (!getDerived().AlwaysRebuild() &&
14169 T == E->getType() &&
14170 Constructor == E->getConstructor() &&
14171 !ArgumentChanged) {
14172 // Mark the constructor as referenced.
14173 // FIXME: Instantiation-specific
14174 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
14175 return E;
14176 }
14177
14178 return getDerived().RebuildCXXConstructExpr(
14179 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
14180 E->hadMultipleCandidates(), E->isListInitialization(),
14181 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
14182 E->getConstructionKind(), E->getParenOrBraceRange());
14183}
14184
14185template<typename Derived>
14186ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
14187 CXXInheritedCtorInitExpr *E) {
14188 QualType T = getDerived().TransformType(E->getType());
14189 if (T.isNull())
14190 return ExprError();
14191
14192 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
14193 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
14194 if (!Constructor)
14195 return ExprError();
14196
14197 if (!getDerived().AlwaysRebuild() &&
14198 T == E->getType() &&
14199 Constructor == E->getConstructor()) {
14200 // Mark the constructor as referenced.
14201 // FIXME: Instantiation-specific
14202 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
14203 return E;
14204 }
14205
14206 return getDerived().RebuildCXXInheritedCtorInitExpr(
14207 T, E->getLocation(), Constructor,
14208 E->constructsVBase(), E->inheritedFromVBase());
14209}
14210
14211/// Transform a C++ temporary-binding expression.
14212///
14213/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
14214/// transform the subexpression and return that.
14215template<typename Derived>
14217TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
14218 if (auto *Dtor = E->getTemporary()->getDestructor())
14220 const_cast<CXXDestructorDecl *>(Dtor));
14221 return getDerived().TransformExpr(E->getSubExpr());
14222}
14223
14224/// Transform a C++ expression that contains cleanups that should
14225/// be run after the expression is evaluated.
14226///
14227/// Since ExprWithCleanups nodes are implicitly generated, we
14228/// just transform the subexpression and return that.
14229template<typename Derived>
14231TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
14232 return getDerived().TransformExpr(E->getSubExpr());
14233}
14234
14235template<typename Derived>
14237TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
14238 CXXTemporaryObjectExpr *E) {
14239 TypeSourceInfo *T =
14240 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
14241 if (!T)
14242 return ExprError();
14243
14244 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
14245 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
14246 if (!Constructor)
14247 return ExprError();
14248
14249 bool ArgumentChanged = false;
14251 Args.reserve(E->getNumArgs());
14252 {
14253 EnterExpressionEvaluationContext Context(
14255 E->isListInitialization());
14256 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14257 &ArgumentChanged))
14258 return ExprError();
14259 }
14260
14261 if (!getDerived().AlwaysRebuild() &&
14262 T == E->getTypeSourceInfo() &&
14263 Constructor == E->getConstructor() &&
14264 !ArgumentChanged) {
14265 // FIXME: Instantiation-specific
14266 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
14267 return SemaRef.MaybeBindToTemporary(E);
14268 }
14269
14270 // FIXME: We should just pass E->isListInitialization(), but we're not
14271 // prepared to handle list-initialization without a child InitListExpr.
14272 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
14273 return getDerived().RebuildCXXTemporaryObjectExpr(
14274 T, LParenLoc, Args, E->getEndLoc(),
14275 /*ListInitialization=*/LParenLoc.isInvalid());
14276}
14277
14278template<typename Derived>
14280TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
14281 // Transform any init-capture expressions before entering the scope of the
14282 // lambda body, because they are not semantically within that scope.
14283 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
14284 struct TransformedInitCapture {
14285 // The location of the ... if the result is retaining a pack expansion.
14286 SourceLocation EllipsisLoc;
14287 // Zero or more expansions of the init-capture.
14289 };
14291 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
14292 for (LambdaExpr::capture_iterator C = E->capture_begin(),
14293 CEnd = E->capture_end();
14294 C != CEnd; ++C) {
14295 if (!E->isInitCapture(C))
14296 continue;
14297
14298 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
14299 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
14300
14301 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
14302 std::optional<unsigned> NumExpansions) {
14303 ExprResult NewExprInitResult = getDerived().TransformInitializer(
14304 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
14305
14306 if (NewExprInitResult.isInvalid()) {
14307 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
14308 return;
14309 }
14310 Expr *NewExprInit = NewExprInitResult.get();
14311
14312 QualType NewInitCaptureType =
14313 getSema().buildLambdaInitCaptureInitialization(
14314 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
14315 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
14316 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
14318 NewExprInit);
14319 Result.Expansions.push_back(
14320 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
14321 };
14322
14323 // If this is an init-capture pack, consider expanding the pack now.
14324 if (OldVD->isParameterPack()) {
14325 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
14326 ->getTypeLoc()
14327 .castAs<PackExpansionTypeLoc>();
14329 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
14330
14331 // Determine whether the set of unexpanded parameter packs can and should
14332 // be expanded.
14333 bool Expand = true;
14334 bool RetainExpansion = false;
14335 std::optional<unsigned> OrigNumExpansions =
14336 ExpansionTL.getTypePtr()->getNumExpansions();
14337 std::optional<unsigned> NumExpansions = OrigNumExpansions;
14338 if (getDerived().TryExpandParameterPacks(
14339 ExpansionTL.getEllipsisLoc(),
14340 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
14341 RetainExpansion, NumExpansions))
14342 return ExprError();
14343 if (Expand) {
14344 for (unsigned I = 0; I != *NumExpansions; ++I) {
14345 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
14346 SubstInitCapture(SourceLocation(), std::nullopt);
14347 }
14348 }
14349 if (!Expand || RetainExpansion) {
14350 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14351 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
14352 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
14353 }
14354 } else {
14355 SubstInitCapture(SourceLocation(), std::nullopt);
14356 }
14357 }
14358
14359 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
14360 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
14361
14362 // Create the local class that will describe the lambda.
14363
14364 // FIXME: DependencyKind below is wrong when substituting inside a templated
14365 // context that isn't a DeclContext (such as a variable template), or when
14366 // substituting an unevaluated lambda inside of a function's parameter's type
14367 // - as parameter types are not instantiated from within a function's DC. We
14368 // use evaluation contexts to distinguish the function parameter case.
14371 DeclContext *DC = getSema().CurContext;
14372 // A RequiresExprBodyDecl is not interesting for dependencies.
14373 // For the following case,
14374 //
14375 // template <typename>
14376 // concept C = requires { [] {}; };
14377 //
14378 // template <class F>
14379 // struct Widget;
14380 //
14381 // template <C F>
14382 // struct Widget<F> {};
14383 //
14384 // While we are substituting Widget<F>, the parent of DC would be
14385 // the template specialization itself. Thus, the lambda expression
14386 // will be deemed as dependent even if there are no dependent template
14387 // arguments.
14388 // (A ClassTemplateSpecializationDecl is always a dependent context.)
14389 while (DC->isRequiresExprBody())
14390 DC = DC->getParent();
14391 if ((getSema().isUnevaluatedContext() ||
14392 getSema().isConstantEvaluatedContext()) &&
14393 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
14394 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
14395
14396 CXXRecordDecl *OldClass = E->getLambdaClass();
14397 CXXRecordDecl *Class = getSema().createLambdaClosureType(
14398 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
14399 E->getCaptureDefault());
14400 getDerived().transformedLocalDecl(OldClass, {Class});
14401
14402 CXXMethodDecl *NewCallOperator =
14403 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
14404 NewCallOperator->setLexicalDeclContext(getSema().CurContext);
14405
14406 // Enter the scope of the lambda.
14407 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
14408 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
14409 E->hasExplicitParameters(), E->isMutable());
14410
14411 // Introduce the context of the call operator.
14412 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
14413 /*NewThisContext*/false);
14414
14415 bool Invalid = false;
14416
14417 // Transform captures.
14418 for (LambdaExpr::capture_iterator C = E->capture_begin(),
14419 CEnd = E->capture_end();
14420 C != CEnd; ++C) {
14421 // When we hit the first implicit capture, tell Sema that we've finished
14422 // the list of explicit captures.
14423 if (C->isImplicit())
14424 break;
14425
14426 // Capturing 'this' is trivial.
14427 if (C->capturesThis()) {
14428 // If this is a lambda that is part of a default member initialiser
14429 // and which we're instantiating outside the class that 'this' is
14430 // supposed to refer to, adjust the type of 'this' accordingly.
14431 //
14432 // Otherwise, leave the type of 'this' as-is.
14433 Sema::CXXThisScopeRAII ThisScope(
14434 getSema(),
14435 dyn_cast_if_present<CXXRecordDecl>(
14436 getSema().getFunctionLevelDeclContext()),
14437 Qualifiers());
14438 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
14439 /*BuildAndDiagnose*/ true, nullptr,
14440 C->getCaptureKind() == LCK_StarThis);
14441 continue;
14442 }
14443 // Captured expression will be recaptured during captured variables
14444 // rebuilding.
14445 if (C->capturesVLAType())
14446 continue;
14447
14448 // Rebuild init-captures, including the implied field declaration.
14449 if (E->isInitCapture(C)) {
14450 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
14451
14452 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
14454
14455 for (InitCaptureInfoTy &Info : NewC.Expansions) {
14456 ExprResult Init = Info.first;
14457 QualType InitQualType = Info.second;
14458 if (Init.isInvalid() || InitQualType.isNull()) {
14459 Invalid = true;
14460 break;
14461 }
14462 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
14463 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
14464 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
14465 getSema().CurContext);
14466 if (!NewVD) {
14467 Invalid = true;
14468 break;
14469 }
14470 NewVDs.push_back(NewVD);
14471 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
14472 }
14473
14474 if (Invalid)
14475 break;
14476
14477 getDerived().transformedLocalDecl(OldVD, NewVDs);
14478 continue;
14479 }
14480
14481 assert(C->capturesVariable() && "unexpected kind of lambda capture");
14482
14483 // Determine the capture kind for Sema.
14485 = C->isImplicit()? Sema::TryCapture_Implicit
14486 : C->getCaptureKind() == LCK_ByCopy
14489 SourceLocation EllipsisLoc;
14490 if (C->isPackExpansion()) {
14491 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
14492 bool ShouldExpand = false;
14493 bool RetainExpansion = false;
14494 std::optional<unsigned> NumExpansions;
14495 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
14496 C->getLocation(),
14497 Unexpanded,
14498 ShouldExpand, RetainExpansion,
14499 NumExpansions)) {
14500 Invalid = true;
14501 continue;
14502 }
14503
14504 if (ShouldExpand) {
14505 // The transform has determined that we should perform an expansion;
14506 // transform and capture each of the arguments.
14507 // expansion of the pattern. Do so.
14508 auto *Pack = cast<VarDecl>(C->getCapturedVar());
14509 for (unsigned I = 0; I != *NumExpansions; ++I) {
14510 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
14511 VarDecl *CapturedVar
14512 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
14513 Pack));
14514 if (!CapturedVar) {
14515 Invalid = true;
14516 continue;
14517 }
14518
14519 // Capture the transformed variable.
14520 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
14521 }
14522
14523 // FIXME: Retain a pack expansion if RetainExpansion is true.
14524
14525 continue;
14526 }
14527
14528 EllipsisLoc = C->getEllipsisLoc();
14529 }
14530
14531 // Transform the captured variable.
14532 auto *CapturedVar = cast_or_null<ValueDecl>(
14533 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
14534 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
14535 Invalid = true;
14536 continue;
14537 }
14538
14539 // Capture the transformed variable.
14540 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
14541 EllipsisLoc);
14542 }
14543 getSema().finishLambdaExplicitCaptures(LSI);
14544
14545 // Transform the template parameters, and add them to the current
14546 // instantiation scope. The null case is handled correctly.
14547 auto TPL = getDerived().TransformTemplateParameterList(
14548 E->getTemplateParameterList());
14549 LSI->GLTemplateParameterList = TPL;
14550 if (TPL)
14551 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
14552 TPL);
14553
14554 // Transform the type of the original lambda's call operator.
14555 // The transformation MUST be done in the CurrentInstantiationScope since
14556 // it introduces a mapping of the original to the newly created
14557 // transformed parameters.
14558 TypeSourceInfo *NewCallOpTSI = nullptr;
14559 {
14560 auto OldCallOpTypeLoc =
14561 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
14562
14563 auto TransformFunctionProtoTypeLoc =
14564 [this](TypeLocBuilder &TLB, FunctionProtoTypeLoc FPTL) -> QualType {
14565 SmallVector<QualType, 4> ExceptionStorage;
14566 return this->TransformFunctionProtoType(
14567 TLB, FPTL, nullptr, Qualifiers(),
14568 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
14569 return TransformExceptionSpec(FPTL.getBeginLoc(), ESI,
14570 ExceptionStorage, Changed);
14571 });
14572 };
14573
14574 QualType NewCallOpType;
14575 TypeLocBuilder NewCallOpTLBuilder;
14576
14577 if (auto ATL = OldCallOpTypeLoc.getAs<AttributedTypeLoc>()) {
14578 NewCallOpType = this->TransformAttributedType(
14579 NewCallOpTLBuilder, ATL,
14580 [&](TypeLocBuilder &TLB, TypeLoc TL) -> QualType {
14581 return TransformFunctionProtoTypeLoc(
14582 TLB, TL.castAs<FunctionProtoTypeLoc>());
14583 });
14584 } else {
14585 auto FPTL = OldCallOpTypeLoc.castAs<FunctionProtoTypeLoc>();
14586 NewCallOpType = TransformFunctionProtoTypeLoc(NewCallOpTLBuilder, FPTL);
14587 }
14588
14589 if (NewCallOpType.isNull())
14590 return ExprError();
14591 NewCallOpTSI =
14592 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
14593 }
14594
14596 if (auto ATL = NewCallOpTSI->getTypeLoc().getAs<AttributedTypeLoc>()) {
14597 Params = ATL.getModifiedLoc().castAs<FunctionProtoTypeLoc>().getParams();
14598 } else {
14599 auto FPTL = NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
14600 Params = FPTL.getParams();
14601 }
14602
14603 getSema().CompleteLambdaCallOperator(
14604 NewCallOperator, E->getCallOperator()->getLocation(),
14605 E->getCallOperator()->getInnerLocStart(),
14606 E->getCallOperator()->getTrailingRequiresClause(), NewCallOpTSI,
14607 E->getCallOperator()->getConstexprKind(),
14608 E->getCallOperator()->getStorageClass(), Params,
14609 E->hasExplicitResultType());
14610
14611 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
14612 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
14613
14614 {
14615 // Number the lambda for linkage purposes if necessary.
14616 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
14617
14618 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
14619 if (getDerived().ReplacingOriginal()) {
14620 Numbering = OldClass->getLambdaNumbering();
14621 }
14622
14623 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
14624 }
14625
14626 // FIXME: Sema's lambda-building mechanism expects us to push an expression
14627 // evaluation context even if we're not transforming the function body.
14628 getSema().PushExpressionEvaluationContext(
14629 E->getCallOperator()->isConsteval() ?
14632 getSema().currentEvaluationContext().InImmediateEscalatingFunctionContext =
14633 getSema().getLangOpts().CPlusPlus20 &&
14634 E->getCallOperator()->isImmediateEscalating();
14635
14636 Sema::CodeSynthesisContext C;
14638 C.PointOfInstantiation = E->getBody()->getBeginLoc();
14639 getSema().pushCodeSynthesisContext(C);
14640
14641 // Instantiate the body of the lambda expression.
14642 StmtResult Body =
14643 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
14644
14645 getSema().popCodeSynthesisContext();
14646
14647 // ActOnLambda* will pop the function scope for us.
14648 FuncScopeCleanup.disable();
14649
14650 if (Body.isInvalid()) {
14651 SavedContext.pop();
14652 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
14653 /*IsInstantiation=*/true);
14654 return ExprError();
14655 }
14656
14657 // Copy the LSI before ActOnFinishFunctionBody removes it.
14658 // FIXME: This is dumb. Store the lambda information somewhere that outlives
14659 // the call operator.
14660 auto LSICopy = *LSI;
14661 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
14662 /*IsInstantiation*/ true);
14663 SavedContext.pop();
14664
14665 // Recompute the dependency of the lambda so that we can defer the lambda call
14666 // construction until after we have all the necessary template arguments. For
14667 // example, given
14668 //
14669 // template <class> struct S {
14670 // template <class U>
14671 // using Type = decltype([](U){}(42.0));
14672 // };
14673 // void foo() {
14674 // using T = S<int>::Type<float>;
14675 // ^~~~~~
14676 // }
14677 //
14678 // We would end up here from instantiating S<int> when ensuring its
14679 // completeness. That would transform the lambda call expression regardless of
14680 // the absence of the corresponding argument for U.
14681 //
14682 // Going ahead with unsubstituted type U makes things worse: we would soon
14683 // compare the argument type (which is float) against the parameter U
14684 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
14685 // error suggesting unmatched types 'U' and 'float'!
14686 //
14687 // That said, everything will be fine if we defer that semantic checking.
14688 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
14689 // dependent. Since the CallExpr's dependency boils down to the lambda's
14690 // dependency in this case, we can harness that by recomputing the dependency
14691 // from the instantiation arguments.
14692 //
14693 // FIXME: Creating the type of a lambda requires us to have a dependency
14694 // value, which happens before its substitution. We update its dependency
14695 // *after* the substitution in case we can't decide the dependency
14696 // so early, e.g. because we want to see if any of the *substituted*
14697 // parameters are dependent.
14698 DependencyKind = getDerived().ComputeLambdaDependency(&LSICopy);
14699 Class->setLambdaDependencyKind(DependencyKind);
14700 // Clean up the type cache created previously. Then, we re-create a type for
14701 // such Decl with the new DependencyKind.
14702 Class->setTypeForDecl(nullptr);
14703 getSema().Context.getTypeDeclType(Class);
14704
14705 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
14706 &LSICopy);
14707}
14708
14709template<typename Derived>
14712 return TransformStmt(S);
14713}
14714
14715template<typename Derived>
14718 // Transform captures.
14719 for (LambdaExpr::capture_iterator C = E->capture_begin(),
14720 CEnd = E->capture_end();
14721 C != CEnd; ++C) {
14722 // When we hit the first implicit capture, tell Sema that we've finished
14723 // the list of explicit captures.
14724 if (!C->isImplicit())
14725 continue;
14726
14727 // Capturing 'this' is trivial.
14728 if (C->capturesThis()) {
14729 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
14730 /*BuildAndDiagnose*/ true, nullptr,
14731 C->getCaptureKind() == LCK_StarThis);
14732 continue;
14733 }
14734 // Captured expression will be recaptured during captured variables
14735 // rebuilding.
14736 if (C->capturesVLAType())
14737 continue;
14738
14739 assert(C->capturesVariable() && "unexpected kind of lambda capture");
14740 assert(!E->isInitCapture(C) && "implicit init-capture?");
14741
14742 // Transform the captured variable.
14743 VarDecl *CapturedVar = cast_or_null<VarDecl>(
14744 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
14745 if (!CapturedVar || CapturedVar->isInvalidDecl())
14746 return StmtError();
14747
14748 // Capture the transformed variable.
14749 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
14750 }
14751
14752 return S;
14753}
14754
14755template<typename Derived>
14759 TypeSourceInfo *T =
14760 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
14761 if (!T)
14762 return ExprError();
14763
14764 bool ArgumentChanged = false;
14766 Args.reserve(E->getNumArgs());
14767 {
14770 E->isListInitialization());
14771 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
14772 &ArgumentChanged))
14773 return ExprError();
14774 }
14775
14776 if (!getDerived().AlwaysRebuild() &&
14777 T == E->getTypeSourceInfo() &&
14778 !ArgumentChanged)
14779 return E;
14780
14781 // FIXME: we're faking the locations of the commas
14782 return getDerived().RebuildCXXUnresolvedConstructExpr(
14783 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
14784}
14785
14786template<typename Derived>
14788TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
14789 CXXDependentScopeMemberExpr *E) {
14790 // Transform the base of the expression.
14791 ExprResult Base((Expr*) nullptr);
14792 Expr *OldBase;
14793 QualType BaseType;
14794 QualType ObjectType;
14795 if (!E->isImplicitAccess()) {
14796 OldBase = E->getBase();
14797 Base = getDerived().TransformExpr(OldBase);
14798 if (Base.isInvalid())
14799 return ExprError();
14800
14801 // Start the member reference and compute the object's type.
14802 ParsedType ObjectTy;
14803 bool MayBePseudoDestructor = false;
14804 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14805 E->getOperatorLoc(),
14806 E->isArrow()? tok::arrow : tok::period,
14807 ObjectTy,
14808 MayBePseudoDestructor);
14809 if (Base.isInvalid())
14810 return ExprError();
14811
14812 ObjectType = ObjectTy.get();
14813 BaseType = ((Expr*) Base.get())->getType();
14814 } else {
14815 OldBase = nullptr;
14816 BaseType = getDerived().TransformType(E->getBaseType());
14817 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
14818 }
14819
14820 // Transform the first part of the nested-name-specifier that qualifies
14821 // the member name.
14822 NamedDecl *FirstQualifierInScope
14823 = getDerived().TransformFirstQualifierInScope(
14824 E->getFirstQualifierFoundInScope(),
14825 E->getQualifierLoc().getBeginLoc());
14826
14827 NestedNameSpecifierLoc QualifierLoc;
14828 if (E->getQualifier()) {
14829 QualifierLoc
14830 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
14831 ObjectType,
14832 FirstQualifierInScope);
14833 if (!QualifierLoc)
14834 return ExprError();
14835 }
14836
14837 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14838
14839 // TODO: If this is a conversion-function-id, verify that the
14840 // destination type name (if present) resolves the same way after
14841 // instantiation as it did in the local scope.
14842
14843 DeclarationNameInfo NameInfo
14844 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
14845 if (!NameInfo.getName())
14846 return ExprError();
14847
14848 if (!E->hasExplicitTemplateArgs()) {
14849 // This is a reference to a member without an explicitly-specified
14850 // template argument list. Optimize for this common case.
14851 if (!getDerived().AlwaysRebuild() &&
14852 Base.get() == OldBase &&
14853 BaseType == E->getBaseType() &&
14854 QualifierLoc == E->getQualifierLoc() &&
14855 NameInfo.getName() == E->getMember() &&
14856 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
14857 return E;
14858
14859 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
14860 BaseType,
14861 E->isArrow(),
14862 E->getOperatorLoc(),
14863 QualifierLoc,
14864 TemplateKWLoc,
14865 FirstQualifierInScope,
14866 NameInfo,
14867 /*TemplateArgs*/nullptr);
14868 }
14869
14870 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
14871 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
14872 E->getNumTemplateArgs(),
14873 TransArgs))
14874 return ExprError();
14875
14876 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
14877 BaseType,
14878 E->isArrow(),
14879 E->getOperatorLoc(),
14880 QualifierLoc,
14881 TemplateKWLoc,
14882 FirstQualifierInScope,
14883 NameInfo,
14884 &TransArgs);
14885}
14886
14887template <typename Derived>
14888ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
14889 UnresolvedMemberExpr *Old) {
14890 // Transform the base of the expression.
14891 ExprResult Base((Expr *)nullptr);
14892 QualType BaseType;
14893 if (!Old->isImplicitAccess()) {
14894 Base = getDerived().TransformExpr(Old->getBase());
14895 if (Base.isInvalid())
14896 return ExprError();
14897 Base =
14898 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
14899 if (Base.isInvalid())
14900 return ExprError();
14901 BaseType = Base.get()->getType();
14902 } else {
14903 BaseType = getDerived().TransformType(Old->getBaseType());
14904 }
14905
14906 NestedNameSpecifierLoc QualifierLoc;
14907 if (Old->getQualifierLoc()) {
14908 QualifierLoc =
14909 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14910 if (!QualifierLoc)
14911 return ExprError();
14912 }
14913
14914 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14915
14916 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
14917
14918 // Transform the declaration set.
14919 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
14920 return ExprError();
14921
14922 // Determine the naming class.
14923 if (Old->getNamingClass()) {
14924 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
14925 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
14926 if (!NamingClass)
14927 return ExprError();
14928
14929 R.setNamingClass(NamingClass);
14930 }
14931
14932 TemplateArgumentListInfo TransArgs;
14933 if (Old->hasExplicitTemplateArgs()) {
14934 TransArgs.setLAngleLoc(Old->getLAngleLoc());
14935 TransArgs.setRAngleLoc(Old->getRAngleLoc());
14936 if (getDerived().TransformTemplateArguments(
14937 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
14938 return ExprError();
14939 }
14940
14941 // FIXME: to do this check properly, we will need to preserve the
14942 // first-qualifier-in-scope here, just in case we had a dependent
14943 // base (and therefore couldn't do the check) and a
14944 // nested-name-qualifier (and therefore could do the lookup).
14945 NamedDecl *FirstQualifierInScope = nullptr;
14946
14947 return getDerived().RebuildUnresolvedMemberExpr(
14948 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
14949 TemplateKWLoc, FirstQualifierInScope, R,
14950 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
14951}
14952
14953template<typename Derived>
14955TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
14956 EnterExpressionEvaluationContext Unevaluated(
14958 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
14959 if (SubExpr.isInvalid())
14960 return ExprError();
14961
14962 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
14963 return E;
14964
14965 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
14966}
14967
14968template<typename Derived>
14970TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
14971 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
14972 if (Pattern.isInvalid())
14973 return ExprError();
14974
14975 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
14976 return E;
14977
14978 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
14979 E->getNumExpansions());
14980}
14981
14982template<typename Derived>
14984TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
14985 // If E is not value-dependent, then nothing will change when we transform it.
14986 // Note: This is an instantiation-centric view.
14987 if (!E->isValueDependent())
14988 return E;
14989
14990 EnterExpressionEvaluationContext Unevaluated(
14992
14994 TemplateArgument ArgStorage;
14995
14996 // Find the argument list to transform.
14997 if (E->isPartiallySubstituted()) {
14998 PackArgs = E->getPartialArguments();
14999 } else if (E->isValueDependent()) {
15000 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
15001 bool ShouldExpand = false;
15002 bool RetainExpansion = false;
15003 std::optional<unsigned> NumExpansions;
15004 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
15005 Unexpanded,
15006 ShouldExpand, RetainExpansion,
15007 NumExpansions))
15008 return ExprError();
15009
15010 // If we need to expand the pack, build a template argument from it and
15011 // expand that.
15012 if (ShouldExpand) {
15013 auto *Pack = E->getPack();
15014 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
15015 ArgStorage = getSema().Context.getPackExpansionType(
15016 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
15017 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
15018 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
15019 } else {
15020 auto *VD = cast<ValueDecl>(Pack);
15021 ExprResult DRE = getSema().BuildDeclRefExpr(
15022 VD, VD->getType().getNonLValueExprType(getSema().Context),
15023 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
15024 E->getPackLoc());
15025 if (DRE.isInvalid())
15026 return ExprError();
15027 ArgStorage = new (getSema().Context)
15028 PackExpansionExpr(getSema().Context.DependentTy, DRE.get(),
15029 E->getPackLoc(), std::nullopt);
15030 }
15031 PackArgs = ArgStorage;
15032 }
15033 }
15034
15035 // If we're not expanding the pack, just transform the decl.
15036 if (!PackArgs.size()) {
15037 auto *Pack = cast_or_null<NamedDecl>(
15038 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
15039 if (!Pack)
15040 return ExprError();
15041 return getDerived().RebuildSizeOfPackExpr(
15042 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
15043 std::nullopt, std::nullopt);
15044 }
15045
15046 // Try to compute the result without performing a partial substitution.
15047 std::optional<unsigned> Result = 0;
15048 for (const TemplateArgument &Arg : PackArgs) {
15049 if (!Arg.isPackExpansion()) {
15050 Result = *Result + 1;
15051 continue;
15052 }
15053
15054 TemplateArgumentLoc ArgLoc;
15055 InventTemplateArgumentLoc(Arg, ArgLoc);
15056
15057 // Find the pattern of the pack expansion.
15058 SourceLocation Ellipsis;
15059 std::optional<unsigned> OrigNumExpansions;
15060 TemplateArgumentLoc Pattern =
15061 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
15062 OrigNumExpansions);
15063
15064 // Substitute under the pack expansion. Do not expand the pack (yet).
15065 TemplateArgumentLoc OutPattern;
15066 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15067 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
15068 /*Uneval*/ true))
15069 return true;
15070
15071 // See if we can determine the number of arguments from the result.
15072 std::optional<unsigned> NumExpansions =
15073 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
15074 if (!NumExpansions) {
15075 // No: we must be in an alias template expansion, and we're going to need
15076 // to actually expand the packs.
15077 Result = std::nullopt;
15078 break;
15079 }
15080
15081 Result = *Result + *NumExpansions;
15082 }
15083
15084 // Common case: we could determine the number of expansions without
15085 // substituting.
15086 if (Result)
15087 return getDerived().RebuildSizeOfPackExpr(
15088 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
15089 *Result, std::nullopt);
15090
15091 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
15092 E->getPackLoc());
15093 {
15094 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
15095 typedef TemplateArgumentLocInventIterator<
15096 Derived, const TemplateArgument*> PackLocIterator;
15097 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
15098 PackLocIterator(*this, PackArgs.end()),
15099 TransformedPackArgs, /*Uneval*/true))
15100 return ExprError();
15101 }
15102
15103 // Check whether we managed to fully-expand the pack.
15104 // FIXME: Is it possible for us to do so and not hit the early exit path?
15106 bool PartialSubstitution = false;
15107 for (auto &Loc : TransformedPackArgs.arguments()) {
15108 Args.push_back(Loc.getArgument());
15109 if (Loc.getArgument().isPackExpansion())
15110 PartialSubstitution = true;
15111 }
15112
15113 if (PartialSubstitution)
15114 return getDerived().RebuildSizeOfPackExpr(
15115 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
15116 std::nullopt, Args);
15117
15118 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
15119 E->getPackLoc(), E->getRParenLoc(),
15120 Args.size(), std::nullopt);
15121}
15122
15123template <typename Derived>
15125TreeTransform<Derived>::TransformPackIndexingExpr(PackIndexingExpr *E) {
15126 if (!E->isValueDependent())
15127 return E;
15128
15129 // Transform the index
15130 ExprResult IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
15131 if (IndexExpr.isInvalid())
15132 return ExprError();
15133
15134 SmallVector<Expr *, 5> ExpandedExprs;
15135 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
15136 Expr *Pattern = E->getPackIdExpression();
15138 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
15139 Unexpanded);
15140 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
15141
15142 // Determine whether the set of unexpanded parameter packs can and should
15143 // be expanded.
15144 bool ShouldExpand = true;
15145 bool RetainExpansion = false;
15146 std::optional<unsigned> OrigNumExpansions;
15147 std::optional<unsigned> NumExpansions = OrigNumExpansions;
15148 if (getDerived().TryExpandParameterPacks(
15149 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
15150 ShouldExpand, RetainExpansion, NumExpansions))
15151 return true;
15152 if (!ShouldExpand) {
15153 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15154 ExprResult Pack = getDerived().TransformExpr(Pattern);
15155 if (Pack.isInvalid())
15156 return ExprError();
15157 return getDerived().RebuildPackIndexingExpr(
15158 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
15159 std::nullopt);
15160 }
15161 for (unsigned I = 0; I != *NumExpansions; ++I) {
15162 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15163 ExprResult Out = getDerived().TransformExpr(Pattern);
15164 if (Out.isInvalid())
15165 return true;
15166 if (Out.get()->containsUnexpandedParameterPack()) {
15167 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
15168 OrigNumExpansions);
15169 if (Out.isInvalid())
15170 return true;
15171 }
15172 ExpandedExprs.push_back(Out.get());
15173 }
15174 // If we're supposed to retain a pack expansion, do so by temporarily
15175 // forgetting the partially-substituted parameter pack.
15176 if (RetainExpansion) {
15177 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15178
15179 ExprResult Out = getDerived().TransformExpr(Pattern);
15180 if (Out.isInvalid())
15181 return true;
15182
15183 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
15184 OrigNumExpansions);
15185 if (Out.isInvalid())
15186 return true;
15187 ExpandedExprs.push_back(Out.get());
15188 }
15189 } else if (!E->expandsToEmptyPack()) {
15190 if (getDerived().TransformExprs(E->getExpressions().data(),
15191 E->getExpressions().size(), false,
15192 ExpandedExprs))
15193 return ExprError();
15194 }
15195
15196 return getDerived().RebuildPackIndexingExpr(
15197 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
15198 IndexExpr.get(), ExpandedExprs,
15199 /*EmptyPack=*/ExpandedExprs.size() == 0);
15200}
15201
15202template<typename Derived>
15204TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
15205 SubstNonTypeTemplateParmPackExpr *E) {
15206 // Default behavior is to do nothing with this transformation.
15207 return E;
15208}
15209
15210template<typename Derived>
15212TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
15213 SubstNonTypeTemplateParmExpr *E) {
15214 // Default behavior is to do nothing with this transformation.
15215 return E;
15216}
15217
15218template<typename Derived>
15220TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
15221 // Default behavior is to do nothing with this transformation.
15222 return E;
15223}
15224
15225template<typename Derived>
15227TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
15228 MaterializeTemporaryExpr *E) {
15229 return getDerived().TransformExpr(E->getSubExpr());
15230}
15231
15232template<typename Derived>
15234TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
15235 UnresolvedLookupExpr *Callee = nullptr;
15236 if (Expr *OldCallee = E->getCallee()) {
15237 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
15238 if (CalleeResult.isInvalid())
15239 return ExprError();
15240 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
15241 }
15242
15243 Expr *Pattern = E->getPattern();
15244
15246 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
15247 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
15248
15249 // Determine whether the set of unexpanded parameter packs can and should
15250 // be expanded.
15251 bool Expand = true;
15252 bool RetainExpansion = false;
15253 std::optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
15254 NumExpansions = OrigNumExpansions;
15255 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
15256 Pattern->getSourceRange(),
15257 Unexpanded,
15258 Expand, RetainExpansion,
15259 NumExpansions))
15260 return true;
15261
15262 if (!Expand) {
15263 // Do not expand any packs here, just transform and rebuild a fold
15264 // expression.
15265 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15266
15267 ExprResult LHS =
15268 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
15269 if (LHS.isInvalid())
15270 return true;
15271
15272 ExprResult RHS =
15273 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
15274 if (RHS.isInvalid())
15275 return true;
15276
15277 if (!getDerived().AlwaysRebuild() &&
15278 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
15279 return E;
15280
15281 return getDerived().RebuildCXXFoldExpr(
15282 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
15283 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
15284 }
15285
15286 // Formally a fold expression expands to nested parenthesized expressions.
15287 // Enforce this limit to avoid creating trees so deep we can't safely traverse
15288 // them.
15289 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) {
15290 SemaRef.Diag(E->getEllipsisLoc(),
15291 clang::diag::err_fold_expression_limit_exceeded)
15292 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
15293 << E->getSourceRange();
15294 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
15295 return ExprError();
15296 }
15297
15298 // The transform has determined that we should perform an elementwise
15299 // expansion of the pattern. Do so.
15300 ExprResult Result = getDerived().TransformExpr(E->getInit());
15301 if (Result.isInvalid())
15302 return true;
15303 bool LeftFold = E->isLeftFold();
15304
15305 // If we're retaining an expansion for a right fold, it is the innermost
15306 // component and takes the init (if any).
15307 if (!LeftFold && RetainExpansion) {
15308 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15309
15310 ExprResult Out = getDerived().TransformExpr(Pattern);
15311 if (Out.isInvalid())
15312 return true;
15313
15314 Result = getDerived().RebuildCXXFoldExpr(
15315 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
15316 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
15317 if (Result.isInvalid())
15318 return true;
15319 }
15320
15321 for (unsigned I = 0; I != *NumExpansions; ++I) {
15322 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
15323 getSema(), LeftFold ? I : *NumExpansions - I - 1);
15324 ExprResult Out = getDerived().TransformExpr(Pattern);
15325 if (Out.isInvalid())
15326 return true;
15327
15328 if (Out.get()->containsUnexpandedParameterPack()) {
15329 // We still have a pack; retain a pack expansion for this slice.
15330 Result = getDerived().RebuildCXXFoldExpr(
15331 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
15332 E->getOperator(), E->getEllipsisLoc(),
15333 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
15334 OrigNumExpansions);
15335 } else if (Result.isUsable()) {
15336 // We've got down to a single element; build a binary operator.
15337 Expr *LHS = LeftFold ? Result.get() : Out.get();
15338 Expr *RHS = LeftFold ? Out.get() : Result.get();
15339 if (Callee) {
15340 UnresolvedSet<16> Functions;
15341 Functions.append(Callee->decls_begin(), Callee->decls_end());
15342 Result = getDerived().RebuildCXXOperatorCallExpr(
15344 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
15345 Functions, LHS, RHS);
15346 } else {
15347 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
15348 E->getOperator(), LHS, RHS);
15349 }
15350 } else
15351 Result = Out;
15352
15353 if (Result.isInvalid())
15354 return true;
15355 }
15356
15357 // If we're retaining an expansion for a left fold, it is the outermost
15358 // component and takes the complete expansion so far as its init (if any).
15359 if (LeftFold && RetainExpansion) {
15360 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15361
15362 ExprResult Out = getDerived().TransformExpr(Pattern);
15363 if (Out.isInvalid())
15364 return true;
15365
15366 Result = getDerived().RebuildCXXFoldExpr(
15367 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
15368 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
15369 if (Result.isInvalid())
15370 return true;
15371 }
15372
15373 // If we had no init and an empty pack, and we're not retaining an expansion,
15374 // then produce a fallback value or error.
15375 if (Result.isUnset())
15376 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
15377 E->getOperator());
15378
15379 return Result;
15380}
15381
15382template <typename Derived>
15384TreeTransform<Derived>::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) {
15385 SmallVector<Expr *, 4> TransformedInits;
15386 ArrayRef<Expr *> InitExprs = E->getInitExprs();
15387 if (TransformExprs(InitExprs.data(), InitExprs.size(), true,
15388 TransformedInits))
15389 return ExprError();
15390
15391 return getDerived().RebuildParenListExpr(E->getBeginLoc(), TransformedInits,
15392 E->getEndLoc());
15393}
15394
15395template<typename Derived>
15397TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
15398 CXXStdInitializerListExpr *E) {
15399 return getDerived().TransformExpr(E->getSubExpr());
15400}
15401
15402template<typename Derived>
15404TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
15405 return SemaRef.MaybeBindToTemporary(E);
15406}
15407
15408template<typename Derived>
15410TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
15411 return E;
15412}
15413
15414template<typename Derived>
15416TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
15417 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
15418 if (SubExpr.isInvalid())
15419 return ExprError();
15420
15421 if (!getDerived().AlwaysRebuild() &&
15422 SubExpr.get() == E->getSubExpr())
15423 return E;
15424
15425 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
15426}
15427
15428template<typename Derived>
15430TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
15431 // Transform each of the elements.
15432 SmallVector<Expr *, 8> Elements;
15433 bool ArgChanged = false;
15434 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
15435 /*IsCall=*/false, Elements, &ArgChanged))
15436 return ExprError();
15437
15438 if (!getDerived().AlwaysRebuild() && !ArgChanged)
15439 return SemaRef.MaybeBindToTemporary(E);
15440
15441 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
15442 Elements.data(),
15443 Elements.size());
15444}
15445
15446template<typename Derived>
15448TreeTransform<Derived>::TransformObjCDictionaryLiteral(
15449 ObjCDictionaryLiteral *E) {
15450 // Transform each of the elements.
15452 bool ArgChanged = false;
15453 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
15454 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
15455
15456 if (OrigElement.isPackExpansion()) {
15457 // This key/value element is a pack expansion.
15459 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
15460 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
15461 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
15462
15463 // Determine whether the set of unexpanded parameter packs can
15464 // and should be expanded.
15465 bool Expand = true;
15466 bool RetainExpansion = false;
15467 std::optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
15468 std::optional<unsigned> NumExpansions = OrigNumExpansions;
15469 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
15470 OrigElement.Value->getEndLoc());
15471 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
15472 PatternRange, Unexpanded, Expand,
15473 RetainExpansion, NumExpansions))
15474 return ExprError();
15475
15476 if (!Expand) {
15477 // The transform has determined that we should perform a simple
15478 // transformation on the pack expansion, producing another pack
15479 // expansion.
15480 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15481 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
15482 if (Key.isInvalid())
15483 return ExprError();
15484
15485 if (Key.get() != OrigElement.Key)
15486 ArgChanged = true;
15487
15488 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
15489 if (Value.isInvalid())
15490 return ExprError();
15491
15492 if (Value.get() != OrigElement.Value)
15493 ArgChanged = true;
15494
15495 ObjCDictionaryElement Expansion = {
15496 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
15497 };
15498 Elements.push_back(Expansion);
15499 continue;
15500 }
15501
15502 // Record right away that the argument was changed. This needs
15503 // to happen even if the array expands to nothing.
15504 ArgChanged = true;
15505
15506 // The transform has determined that we should perform an elementwise
15507 // expansion of the pattern. Do so.
15508 for (unsigned I = 0; I != *NumExpansions; ++I) {
15509 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15510 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
15511 if (Key.isInvalid())
15512 return ExprError();
15513
15514 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
15515 if (Value.isInvalid())
15516 return ExprError();
15517
15518 ObjCDictionaryElement Element = {
15519 Key.get(), Value.get(), SourceLocation(), NumExpansions
15520 };
15521
15522 // If any unexpanded parameter packs remain, we still have a
15523 // pack expansion.
15524 // FIXME: Can this really happen?
15525 if (Key.get()->containsUnexpandedParameterPack() ||
15526 Value.get()->containsUnexpandedParameterPack())
15527 Element.EllipsisLoc = OrigElement.EllipsisLoc;
15528
15529 Elements.push_back(Element);
15530 }
15531
15532 // FIXME: Retain a pack expansion if RetainExpansion is true.
15533
15534 // We've finished with this pack expansion.
15535 continue;
15536 }
15537
15538 // Transform and check key.
15539 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
15540 if (Key.isInvalid())
15541 return ExprError();
15542
15543 if (Key.get() != OrigElement.Key)
15544 ArgChanged = true;
15545
15546 // Transform and check value.
15548 = getDerived().TransformExpr(OrigElement.Value);
15549 if (Value.isInvalid())
15550 return ExprError();
15551
15552 if (Value.get() != OrigElement.Value)
15553 ArgChanged = true;
15554
15555 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
15556 std::nullopt};
15557 Elements.push_back(Element);
15558 }
15559
15560 if (!getDerived().AlwaysRebuild() && !ArgChanged)
15561 return SemaRef.MaybeBindToTemporary(E);
15562
15563 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
15564 Elements);
15565}
15566
15567template<typename Derived>
15569TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
15570 TypeSourceInfo *EncodedTypeInfo
15571 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
15572 if (!EncodedTypeInfo)
15573 return ExprError();
15574
15575 if (!getDerived().AlwaysRebuild() &&
15576 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
15577 return E;
15578
15579 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
15580 EncodedTypeInfo,
15581 E->getRParenLoc());
15582}
15583
15584template<typename Derived>
15585ExprResult TreeTransform<Derived>::
15586TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
15587 // This is a kind of implicit conversion, and it needs to get dropped
15588 // and recomputed for the same general reasons that ImplicitCastExprs
15589 // do, as well a more specific one: this expression is only valid when
15590 // it appears *immediately* as an argument expression.
15591 return getDerived().TransformExpr(E->getSubExpr());
15592}
15593
15594template<typename Derived>
15595ExprResult TreeTransform<Derived>::
15596TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
15597 TypeSourceInfo *TSInfo
15598 = getDerived().TransformType(E->getTypeInfoAsWritten());
15599 if (!TSInfo)
15600 return ExprError();
15601
15602 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
15603 if (Result.isInvalid())
15604 return ExprError();
15605
15606 if (!getDerived().AlwaysRebuild() &&
15607 TSInfo == E->getTypeInfoAsWritten() &&
15608 Result.get() == E->getSubExpr())
15609 return E;
15610
15611 return SemaRef.ObjC().BuildObjCBridgedCast(
15612 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
15613 Result.get());
15614}
15615
15616template <typename Derived>
15617ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
15618 ObjCAvailabilityCheckExpr *E) {
15619 return E;
15620}
15621
15622template<typename Derived>
15624TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
15625 // Transform arguments.
15626 bool ArgChanged = false;
15628 Args.reserve(E->getNumArgs());
15629 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
15630 &ArgChanged))
15631 return ExprError();
15632
15633 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
15634 // Class message: transform the receiver type.
15635 TypeSourceInfo *ReceiverTypeInfo
15636 = getDerived().TransformType(E->getClassReceiverTypeInfo());
15637 if (!ReceiverTypeInfo)
15638 return ExprError();
15639
15640 // If nothing changed, just retain the existing message send.
15641 if (!getDerived().AlwaysRebuild() &&
15642 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
15643 return SemaRef.MaybeBindToTemporary(E);
15644
15645 // Build a new class message send.
15647 E->getSelectorLocs(SelLocs);
15648 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
15649 E->getSelector(),
15650 SelLocs,
15651 E->getMethodDecl(),
15652 E->getLeftLoc(),
15653 Args,
15654 E->getRightLoc());
15655 }
15656 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
15657 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
15658 if (!E->getMethodDecl())
15659 return ExprError();
15660
15661 // Build a new class message send to 'super'.
15663 E->getSelectorLocs(SelLocs);
15664 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
15665 E->getSelector(),
15666 SelLocs,
15667 E->getReceiverType(),
15668 E->getMethodDecl(),
15669 E->getLeftLoc(),
15670 Args,
15671 E->getRightLoc());
15672 }
15673
15674 // Instance message: transform the receiver
15675 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
15676 "Only class and instance messages may be instantiated");
15677 ExprResult Receiver
15678 = getDerived().TransformExpr(E->getInstanceReceiver());
15679 if (Receiver.isInvalid())
15680 return ExprError();
15681
15682 // If nothing changed, just retain the existing message send.
15683 if (!getDerived().AlwaysRebuild() &&
15684 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
15685 return SemaRef.MaybeBindToTemporary(E);
15686
15687 // Build a new instance message send.
15689 E->getSelectorLocs(SelLocs);
15690 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
15691 E->getSelector(),
15692 SelLocs,
15693 E->getMethodDecl(),
15694 E->getLeftLoc(),
15695 Args,
15696 E->getRightLoc());
15697}
15698
15699template<typename Derived>
15701TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
15702 return E;
15703}
15704
15705template<typename Derived>
15707TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
15708 return E;
15709}
15710
15711template<typename Derived>
15713TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
15714 // Transform the base expression.
15715 ExprResult Base = getDerived().TransformExpr(E->getBase());
15716 if (Base.isInvalid())
15717 return ExprError();
15718
15719 // We don't need to transform the ivar; it will never change.
15720
15721 // If nothing changed, just retain the existing expression.
15722 if (!getDerived().AlwaysRebuild() &&
15723 Base.get() == E->getBase())
15724 return E;
15725
15726 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
15727 E->getLocation(),
15728 E->isArrow(), E->isFreeIvar());
15729}
15730
15731template<typename Derived>
15733TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
15734 // 'super' and types never change. Property never changes. Just
15735 // retain the existing expression.
15736 if (!E->isObjectReceiver())
15737 return E;
15738
15739 // Transform the base expression.
15740 ExprResult Base = getDerived().TransformExpr(E->getBase());
15741 if (Base.isInvalid())
15742 return ExprError();
15743
15744 // We don't need to transform the property; it will never change.
15745
15746 // If nothing changed, just retain the existing expression.
15747 if (!getDerived().AlwaysRebuild() &&
15748 Base.get() == E->getBase())
15749 return E;
15750
15751 if (E->isExplicitProperty())
15752 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
15753 E->getExplicitProperty(),
15754 E->getLocation());
15755
15756 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
15757 SemaRef.Context.PseudoObjectTy,
15758 E->getImplicitPropertyGetter(),
15759 E->getImplicitPropertySetter(),
15760 E->getLocation());
15761}
15762
15763template<typename Derived>
15765TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
15766 // Transform the base expression.
15767 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
15768 if (Base.isInvalid())
15769 return ExprError();
15770
15771 // Transform the key expression.
15772 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
15773 if (Key.isInvalid())
15774 return ExprError();
15775
15776 // If nothing changed, just retain the existing expression.
15777 if (!getDerived().AlwaysRebuild() &&
15778 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
15779 return E;
15780
15781 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
15782 Base.get(), Key.get(),
15783 E->getAtIndexMethodDecl(),
15784 E->setAtIndexMethodDecl());
15785}
15786
15787template<typename Derived>
15789TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
15790 // Transform the base expression.
15791 ExprResult Base = getDerived().TransformExpr(E->getBase());
15792 if (Base.isInvalid())
15793 return ExprError();
15794
15795 // If nothing changed, just retain the existing expression.
15796 if (!getDerived().AlwaysRebuild() &&
15797 Base.get() == E->getBase())
15798 return E;
15799
15800 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
15801 E->getOpLoc(),
15802 E->isArrow());
15803}
15804
15805template<typename Derived>
15807TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
15808 bool ArgumentChanged = false;
15809 SmallVector<Expr*, 8> SubExprs;
15810 SubExprs.reserve(E->getNumSubExprs());
15811 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
15812 SubExprs, &ArgumentChanged))
15813 return ExprError();
15814
15815 if (!getDerived().AlwaysRebuild() &&
15816 !ArgumentChanged)
15817 return E;
15818
15819 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
15820 SubExprs,
15821 E->getRParenLoc());
15822}
15823
15824template<typename Derived>
15826TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
15827 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
15828 if (SrcExpr.isInvalid())
15829 return ExprError();
15830
15831 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
15832 if (!Type)
15833 return ExprError();
15834
15835 if (!getDerived().AlwaysRebuild() &&
15836 Type == E->getTypeSourceInfo() &&
15837 SrcExpr.get() == E->getSrcExpr())
15838 return E;
15839
15840 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
15841 SrcExpr.get(), Type,
15842 E->getRParenLoc());
15843}
15844
15845template<typename Derived>
15847TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
15848 BlockDecl *oldBlock = E->getBlockDecl();
15849
15850 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
15851 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
15852
15853 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
15854 blockScope->TheDecl->setBlockMissingReturnType(
15855 oldBlock->blockMissingReturnType());
15856
15858 SmallVector<QualType, 4> paramTypes;
15859
15860 const FunctionProtoType *exprFunctionType = E->getFunctionType();
15861
15862 // Parameter substitution.
15863 Sema::ExtParameterInfoBuilder extParamInfos;
15864 if (getDerived().TransformFunctionTypeParams(
15865 E->getCaretLocation(), oldBlock->parameters(), nullptr,
15866 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
15867 extParamInfos)) {
15868 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
15869 return ExprError();
15870 }
15871
15872 QualType exprResultType =
15873 getDerived().TransformType(exprFunctionType->getReturnType());
15874
15875 auto epi = exprFunctionType->getExtProtoInfo();
15876 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
15877
15878 QualType functionType =
15879 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
15880 blockScope->FunctionType = functionType;
15881
15882 // Set the parameters on the block decl.
15883 if (!params.empty())
15884 blockScope->TheDecl->setParams(params);
15885
15886 if (!oldBlock->blockMissingReturnType()) {
15887 blockScope->HasImplicitReturnType = false;
15888 blockScope->ReturnType = exprResultType;
15889 }
15890
15891 // Transform the body
15892 StmtResult body = getDerived().TransformStmt(E->getBody());
15893 if (body.isInvalid()) {
15894 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
15895 return ExprError();
15896 }
15897
15898#ifndef NDEBUG
15899 // In builds with assertions, make sure that we captured everything we
15900 // captured before.
15901 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
15902 for (const auto &I : oldBlock->captures()) {
15903 VarDecl *oldCapture = I.getVariable();
15904
15905 // Ignore parameter packs.
15906 if (oldCapture->isParameterPack())
15907 continue;
15908
15909 VarDecl *newCapture =
15910 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
15911 oldCapture));
15912 assert(blockScope->CaptureMap.count(newCapture));
15913 }
15914
15915 // The this pointer may not be captured by the instantiated block, even when
15916 // it's captured by the original block, if the expression causing the
15917 // capture is in the discarded branch of a constexpr if statement.
15918 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
15919 "this pointer isn't captured in the old block");
15920 }
15921#endif
15922
15923 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
15924 /*Scope=*/nullptr);
15925}
15926
15927template<typename Derived>
15929TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
15930 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
15931 if (SrcExpr.isInvalid())
15932 return ExprError();
15933
15934 QualType Type = getDerived().TransformType(E->getType());
15935
15936 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
15937 E->getRParenLoc());
15938}
15939
15940template<typename Derived>
15942TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
15943 bool ArgumentChanged = false;
15944 SmallVector<Expr*, 8> SubExprs;
15945 SubExprs.reserve(E->getNumSubExprs());
15946 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
15947 SubExprs, &ArgumentChanged))
15948 return ExprError();
15949
15950 if (!getDerived().AlwaysRebuild() &&
15951 !ArgumentChanged)
15952 return E;
15953
15954 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
15955 E->getOp(), E->getRParenLoc());
15956}
15957
15958//===----------------------------------------------------------------------===//
15959// Type reconstruction
15960//===----------------------------------------------------------------------===//
15961
15962template<typename Derived>
15965 return SemaRef.BuildPointerType(PointeeType, Star,
15966 getDerived().getBaseEntity());
15967}
15968
15969template<typename Derived>
15972 return SemaRef.BuildBlockPointerType(PointeeType, Star,
15973 getDerived().getBaseEntity());
15974}
15975
15976template<typename Derived>
15979 bool WrittenAsLValue,
15980 SourceLocation Sigil) {
15981 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
15982 Sigil, getDerived().getBaseEntity());
15983}
15984
15985template<typename Derived>
15988 QualType ClassType,
15989 SourceLocation Sigil) {
15990 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
15991 getDerived().getBaseEntity());
15992}
15993
15994template<typename Derived>
15996 const ObjCTypeParamDecl *Decl,
15997 SourceLocation ProtocolLAngleLoc,
15999 ArrayRef<SourceLocation> ProtocolLocs,
16000 SourceLocation ProtocolRAngleLoc) {
16001 return SemaRef.ObjC().BuildObjCTypeParamType(
16002 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16003 /*FailOnError=*/true);
16004}
16005
16006template<typename Derived>
16008 QualType BaseType,
16010 SourceLocation TypeArgsLAngleLoc,
16012 SourceLocation TypeArgsRAngleLoc,
16013 SourceLocation ProtocolLAngleLoc,
16015 ArrayRef<SourceLocation> ProtocolLocs,
16016 SourceLocation ProtocolRAngleLoc) {
16017 return SemaRef.ObjC().BuildObjCObjectType(
16018 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
16019 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16020 /*FailOnError=*/true,
16021 /*Rebuilding=*/true);
16022}
16023
16024template<typename Derived>
16026 QualType PointeeType,
16028 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
16029}
16030
16031template <typename Derived>
16033 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
16034 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16035 if (SizeExpr || !Size)
16036 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
16037 IndexTypeQuals, BracketsRange,
16038 getDerived().getBaseEntity());
16039
16040 QualType Types[] = {
16044 };
16045 QualType SizeType;
16046 for (const auto &T : Types)
16047 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
16048 SizeType = T;
16049 break;
16050 }
16051
16052 // Note that we can return a VariableArrayType here in the case where
16053 // the element type was a dependent VariableArrayType.
16054 IntegerLiteral *ArraySize
16055 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
16056 /*FIXME*/BracketsRange.getBegin());
16057 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
16058 IndexTypeQuals, BracketsRange,
16059 getDerived().getBaseEntity());
16060}
16061
16062template <typename Derived>
16064 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
16065 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16066 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
16067 IndexTypeQuals, BracketsRange);
16068}
16069
16070template <typename Derived>
16072 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
16073 SourceRange BracketsRange) {
16074 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
16075 IndexTypeQuals, BracketsRange);
16076}
16077
16078template <typename Derived>
16080 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16081 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16082 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16083 SizeExpr,
16084 IndexTypeQuals, BracketsRange);
16085}
16086
16087template <typename Derived>
16089 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16090 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16091 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16092 SizeExpr,
16093 IndexTypeQuals, BracketsRange);
16094}
16095
16096template <typename Derived>
16098 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
16099 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
16100 AttributeLoc);
16101}
16102
16103template <typename Derived>
16105 unsigned NumElements,
16106 VectorKind VecKind) {
16107 // FIXME: semantic checking!
16108 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
16109}
16110
16111template <typename Derived>
16113 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
16114 VectorKind VecKind) {
16115 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
16116}
16117
16118template<typename Derived>
16120 unsigned NumElements,
16121 SourceLocation AttributeLoc) {
16122 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
16123 NumElements, true);
16124 IntegerLiteral *VectorSize
16125 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
16126 AttributeLoc);
16127 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
16128}
16129
16130template<typename Derived>
16133 Expr *SizeExpr,
16134 SourceLocation AttributeLoc) {
16135 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
16136}
16137
16138template <typename Derived>
16140 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
16141 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
16142 NumColumns);
16143}
16144
16145template <typename Derived>
16147 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
16148 SourceLocation AttributeLoc) {
16149 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
16150 AttributeLoc);
16151}
16152
16153template<typename Derived>
16155 QualType T,
16156 MutableArrayRef<QualType> ParamTypes,
16158 return SemaRef.BuildFunctionType(T, ParamTypes,
16159 getDerived().getBaseLocation(),
16160 getDerived().getBaseEntity(),
16161 EPI);
16162}
16163
16164template<typename Derived>
16166 return SemaRef.Context.getFunctionNoProtoType(T);
16167}
16168
16169template<typename Derived>
16171 Decl *D) {
16172 assert(D && "no decl found");
16173 if (D->isInvalidDecl()) return QualType();
16174
16175 // FIXME: Doesn't account for ObjCInterfaceDecl!
16176 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
16177 // A valid resolved using typename pack expansion decl can have multiple
16178 // UsingDecls, but they must each have exactly one type, and it must be
16179 // the same type in every case. But we must have at least one expansion!
16180 if (UPD->expansions().empty()) {
16181 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
16182 << UPD->isCXXClassMember() << UPD;
16183 return QualType();
16184 }
16185
16186 // We might still have some unresolved types. Try to pick a resolved type
16187 // if we can. The final instantiation will check that the remaining
16188 // unresolved types instantiate to the type we pick.
16189 QualType FallbackT;
16190 QualType T;
16191 for (auto *E : UPD->expansions()) {
16192 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
16193 if (ThisT.isNull())
16194 continue;
16195 else if (ThisT->getAs<UnresolvedUsingType>())
16196 FallbackT = ThisT;
16197 else if (T.isNull())
16198 T = ThisT;
16199 else
16200 assert(getSema().Context.hasSameType(ThisT, T) &&
16201 "mismatched resolved types in using pack expansion");
16202 }
16203 return T.isNull() ? FallbackT : T;
16204 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
16205 assert(Using->hasTypename() &&
16206 "UnresolvedUsingTypenameDecl transformed to non-typename using");
16207
16208 // A valid resolved using typename decl points to exactly one type decl.
16209 assert(++Using->shadow_begin() == Using->shadow_end());
16210
16211 UsingShadowDecl *Shadow = *Using->shadow_begin();
16212 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), Loc))
16213 return QualType();
16214 return SemaRef.Context.getUsingType(
16215 Shadow, SemaRef.Context.getTypeDeclType(
16216 cast<TypeDecl>(Shadow->getTargetDecl())));
16217 } else {
16218 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
16219 "UnresolvedUsingTypenameDecl transformed to non-using decl");
16220 return SemaRef.Context.getTypeDeclType(
16221 cast<UnresolvedUsingTypenameDecl>(D));
16222 }
16223}
16224
16225template <typename Derived>
16227 TypeOfKind Kind) {
16228 return SemaRef.BuildTypeofExprType(E, Kind);
16229}
16230
16231template<typename Derived>
16233 TypeOfKind Kind) {
16234 return SemaRef.Context.getTypeOfType(Underlying, Kind);
16235}
16236
16237template <typename Derived>
16239 return SemaRef.BuildDecltypeType(E);
16240}
16241
16242template <typename Derived>
16244 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
16245 SourceLocation EllipsisLoc, bool FullySubstituted,
16246 ArrayRef<QualType> Expansions) {
16247 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
16248 FullySubstituted, Expansions);
16249}
16250
16251template<typename Derived>
16255 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
16256}
16257
16258template<typename Derived>
16260 TemplateName Template,
16261 SourceLocation TemplateNameLoc,
16262 TemplateArgumentListInfo &TemplateArgs) {
16263 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
16264}
16265
16266template<typename Derived>
16268 SourceLocation KWLoc) {
16269 return SemaRef.BuildAtomicType(ValueType, KWLoc);
16270}
16271
16272template<typename Derived>
16274 SourceLocation KWLoc,
16275 bool isReadPipe) {
16276 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
16277 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
16278}
16279
16280template <typename Derived>
16282 unsigned NumBits,
16284 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
16285 NumBits, true);
16286 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
16287 SemaRef.Context.IntTy, Loc);
16288 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
16289}
16290
16291template <typename Derived>
16293 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
16294 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
16295}
16296
16297template<typename Derived>
16300 bool TemplateKW,
16301 TemplateDecl *Template) {
16302 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
16303 TemplateName(Template));
16304}
16305
16306template<typename Derived>
16309 SourceLocation TemplateKWLoc,
16310 const IdentifierInfo &Name,
16311 SourceLocation NameLoc,
16312 QualType ObjectType,
16313 NamedDecl *FirstQualifierInScope,
16314 bool AllowInjectedClassName) {
16316 TemplateName.setIdentifier(&Name, NameLoc);
16317 Sema::TemplateTy Template;
16318 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
16319 TemplateName, ParsedType::make(ObjectType),
16320 /*EnteringContext=*/false, Template,
16321 AllowInjectedClassName);
16322 return Template.get();
16323}
16324
16325template<typename Derived>
16328 SourceLocation TemplateKWLoc,
16329 OverloadedOperatorKind Operator,
16330 SourceLocation NameLoc,
16331 QualType ObjectType,
16332 bool AllowInjectedClassName) {
16333 UnqualifiedId Name;
16334 // FIXME: Bogus location information.
16335 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
16336 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
16337 Sema::TemplateTy Template;
16338 getSema().ActOnTemplateName(
16339 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
16340 /*EnteringContext=*/false, Template, AllowInjectedClassName);
16341 return Template.get();
16342}
16343
16344template <typename Derived>
16347 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
16348 Expr *Second) {
16349 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
16350
16351 if (First->getObjectKind() == OK_ObjCProperty) {
16354 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
16355 Opc, First, Second);
16357 if (Result.isInvalid())
16358 return ExprError();
16359 First = Result.get();
16360 }
16361
16362 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
16363 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
16364 if (Result.isInvalid())
16365 return ExprError();
16366 Second = Result.get();
16367 }
16368
16369 // Determine whether this should be a builtin operation.
16370 if (Op == OO_Subscript) {
16371 if (!First->getType()->isOverloadableType() &&
16372 !Second->getType()->isOverloadableType())
16373 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
16374 OpLoc);
16375 } else if (Op == OO_Arrow) {
16376 // It is possible that the type refers to a RecoveryExpr created earlier
16377 // in the tree transformation.
16378 if (First->getType()->isDependentType())
16379 return ExprError();
16380 // -> is never a builtin operation.
16381 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
16382 } else if (Second == nullptr || isPostIncDec) {
16383 if (!First->getType()->isOverloadableType() ||
16384 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
16385 // The argument is not of overloadable type, or this is an expression
16386 // of the form &Class::member, so try to create a built-in unary
16387 // operation.
16389 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
16390
16391 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
16392 }
16393 } else {
16394 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
16395 !First->getType()->isOverloadableType() &&
16396 !Second->getType()->isOverloadableType()) {
16397 // Neither of the arguments is type-dependent or has an overloadable
16398 // type, so try to create a built-in binary operation.
16401 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
16402 if (Result.isInvalid())
16403 return ExprError();
16404
16405 return Result;
16406 }
16407 }
16408
16409 // Create the overloaded operator invocation for unary operators.
16410 if (!Second || isPostIncDec) {
16412 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
16413 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
16414 RequiresADL);
16415 }
16416
16417 // Create the overloaded operator invocation for binary operators.
16419 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
16420 First, Second, RequiresADL);
16421 if (Result.isInvalid())
16422 return ExprError();
16423
16424 return Result;
16425}
16426
16427template<typename Derived>
16430 SourceLocation OperatorLoc,
16431 bool isArrow,
16432 CXXScopeSpec &SS,
16433 TypeSourceInfo *ScopeType,
16434 SourceLocation CCLoc,
16435 SourceLocation TildeLoc,
16436 PseudoDestructorTypeStorage Destroyed) {
16437 QualType BaseType = Base->getType();
16438 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
16439 (!isArrow && !BaseType->getAs<RecordType>()) ||
16440 (isArrow && BaseType->getAs<PointerType>() &&
16441 !BaseType->castAs<PointerType>()->getPointeeType()
16442 ->template getAs<RecordType>())){
16443 // This pseudo-destructor expression is still a pseudo-destructor.
16444 return SemaRef.BuildPseudoDestructorExpr(
16445 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
16446 CCLoc, TildeLoc, Destroyed);
16447 }
16448
16449 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
16451 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
16452 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
16453 NameInfo.setNamedTypeInfo(DestroyedType);
16454
16455 // The scope type is now known to be a valid nested name specifier
16456 // component. Tack it on to the end of the nested name specifier.
16457 if (ScopeType) {
16458 if (!ScopeType->getType()->getAs<TagType>()) {
16459 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
16460 diag::err_expected_class_or_namespace)
16461 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
16462 return ExprError();
16463 }
16464 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
16465 CCLoc);
16466 }
16467
16468 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
16469 return getSema().BuildMemberReferenceExpr(Base, BaseType,
16470 OperatorLoc, isArrow,
16471 SS, TemplateKWLoc,
16472 /*FIXME: FirstQualifier*/ nullptr,
16473 NameInfo,
16474 /*TemplateArgs*/ nullptr,
16475 /*S*/nullptr);
16476}
16477
16478template<typename Derived>
16481 SourceLocation Loc = S->getBeginLoc();
16482 CapturedDecl *CD = S->getCapturedDecl();
16483 unsigned NumParams = CD->getNumParams();
16484 unsigned ContextParamPos = CD->getContextParamPosition();
16486 for (unsigned I = 0; I < NumParams; ++I) {
16487 if (I != ContextParamPos) {
16488 Params.push_back(
16489 std::make_pair(
16490 CD->getParam(I)->getName(),
16491 getDerived().TransformType(CD->getParam(I)->getType())));
16492 } else {
16493 Params.push_back(std::make_pair(StringRef(), QualType()));
16494 }
16495 }
16496 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
16497 S->getCapturedRegionKind(), Params);
16498 StmtResult Body;
16499 {
16500 Sema::CompoundScopeRAII CompoundScope(getSema());
16501 Body = getDerived().TransformStmt(S->getCapturedStmt());
16502 }
16503
16504 if (Body.isInvalid()) {
16505 getSema().ActOnCapturedRegionError();
16506 return StmtError();
16507 }
16508
16509 return getSema().ActOnCapturedRegionEnd(Body.get());
16510}
16511
16512} // end namespace clang
16513
16514#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:1152
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:2993
unsigned Iter
Definition: HTMLLogger.cpp:154
#define X(type, name)
Definition: Value.h:143
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:1143
SourceRange Range
Definition: SemaObjC.cpp:757
SourceLocation Loc
Definition: SemaObjC.cpp:758
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:1100
unsigned getIntWidth(QualType T) const
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType) 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:663
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.
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true)
Form a pack expansion type with the given pattern.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2625
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2641
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 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:1634
IdentifierTable & Idents
Definition: ASTContext.h:659
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:1128
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:1127
CanQualType PseudoObjectTy
Definition: ASTContext.h:1149
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2207
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.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
CanQualType UnsignedInt128Ty
Definition: ASTContext.h:1129
CanQualType BuiltinFnTy
Definition: ASTContext.h:1148
CanQualType UnsignedCharTy
Definition: ASTContext.h:1128
CanQualType UnsignedIntTy
Definition: ASTContext.h:1128
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1129
CanQualType UnsignedShortTy
Definition: ASTContext.h:1128
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 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 getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
Retrieve a substitution-result type.
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:2852
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2634
TypeLoc getValueLoc() const
Definition: TypeLoc.h:2610
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2618
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2626
Attr - This represents one attribute.
Definition: Attr.h:42
attr::Kind getKind() const
Definition: Attr.h:88
SourceLocation getLocation() const
Definition: Attr.h:95
Represents an attribute applied to a statement.
Definition: Stmt.h:2085
Type source information for an attributed type.
Definition: TypeLoc.h:875
const Attr * getAttr() const
The type attribute.
Definition: TypeLoc.h:898
TypeLoc getModifiedLoc() const
The modified type, which is generally canonically different from the attribute type.
Definition: TypeLoc.h:889
TypeLoc getEquivalentTypeLoc() const
Definition: TypeLoc.h:893
void setAttr(const Attr *A)
Definition: TypeLoc.h:901
attr::Kind getAttrKind() const
Definition: TypeLoc.h:877
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:5991
QualType getModifiedType() const
Definition: Type.h:6013
std::optional< NullabilityKind > getImmediateNullability() const
Definition: Type.cpp:4843
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:6368
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:6378
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:6383
AutoTypeKeyword getKeyword() const
Definition: Type.h:6399
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2181
bool isAssignmentOp() const
Definition: Expr.h:3998
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:2143
void setIsVariadic(bool value)
Definition: Decl.h:4543
TypeLoc getInnerLoc() const
Definition: TypeLoc.h:1128
QualType desugar() const
Definition: Type.h:3231
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5290
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:5309
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:5308
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:566
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:560
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:2535
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:1016
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:1856
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2181
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:104
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition: DeclSpec.cpp:152
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:114
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:54
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:132
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:3555
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:1494
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4666
unsigned getNumParams() const
Definition: Decl.h:4708
unsigned getContextParamPosition() const
Definition: Decl.h:4737
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4710
This captures a statement into a function.
Definition: Stmt.h:3762
Expr * getSubExpr()
Definition: Expr.h:3548
SourceLocation getBegin() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1606
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:88
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:421
Expr * getCountExpr() const
Definition: TypeLoc.h:1142
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: Type.h:3269
bool isOrNull() const
Definition: Type.h:3297
bool isCountInBytes() const
Definition: Type.h:3296
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1358
reference front() const
Definition: DeclBase.h:1381
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1425
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1828
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1742
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:1497
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:441
bool isInvalidDecl() const
Definition: DeclBase.h:594
SourceLocation getLocation() const
Definition: DeclBase.h:445
DeclContext * getDeclContext()
Definition: DeclBase.h:454
AccessSpecifier getAccess() const
Definition: DeclBase.h:513
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:437
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:774
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:760
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1900
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:6355
bool isDeduced() const
Definition: Type.h:6356
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3321
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:491
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2472
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2496
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2492
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:2488
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2460
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2516
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2456
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2508
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2524
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2500
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6888
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:843
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition: Type.h:4774
Expr * getCondition() const
Definition: Type.h:4781
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2319
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2331
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2323
TypeLoc getNamedTypeLoc() const
Definition: TypeLoc.h:2361
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2337
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6755
RAII object that enters a new expression evaluation context.
Represents an enum.
Definition: Decl.h:3840
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3772
This represents one expression.
Definition: Expr.h:110
bool isGLValue() const
Definition: Expr.h:280
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition: Expr.h:516
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition: Expr.h:427
Represents difference between two FPOptions values.
Definition: LangOptions.h:919
Represents a member of a struct/union/class.
Definition: Decl.h:3030
Represents a function declaration or definition.
Definition: Decl.h:1932
QualType getReturnType() const
Definition: Decl.h:2717
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Definition: Decl.h:2753
Represents an abstract function effect, using just an enumeration describing its kind.
Definition: Type.h:4673
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition: Type.cpp:5115
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition: Type.cpp:5099
ArrayRef< EffectConditionExpr > conditions() const
Definition: Type.h:4887
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4638
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4973
QualType desugar() const
Definition: Type.h:5517
param_type_iterator param_type_begin() const
Definition: Type.h:5386
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:5424
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:5366
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5237
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:5233
unsigned getNumParams() const
Definition: TypeLoc.h:1500
SourceLocation getLocalRangeEnd() const
Definition: TypeLoc.h:1452
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1448
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1464
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1480
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1507
ArrayRef< ParmVarDecl * > getParams() const
Definition: TypeLoc.h:1491
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1472
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1456
void setExceptionSpecRange(SourceRange R)
Definition: TypeLoc.h:1486
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1509
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1444
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1460
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1468
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:4304
QualType getReturnType() const
Definition: Type.h:4600
AssociationTy< false > Association
Definition: Expr.h:6138
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:3675
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5782
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:977
Represents the declaration of a label.
Definition: Decl.h:499
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:485
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:4726
This represents a decl that may have a name.
Definition: Decl.h:249
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:462
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:270
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
Represents a C++ namespace alias.
Definition: DeclCXX.h:3120
Represent a C++ namespace.
Definition: Decl.h:547
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:1950
@ SuperInstance
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:959
@ Instance
The receiver is an object instance.
Definition: ExprObjC.h:953
@ SuperClass
The receiver is a superclass.
Definition: ExprObjC.h:956
@ Class
The receiver is a class.
Definition: ExprObjC.h:950
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:2374
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2378
@ Field
A field.
Definition: Expr.h:2376
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2381
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 OpenACCCopyClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyInClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsReadOnly, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyOutClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCreateClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDefaultClause * Create(const ASTContext &C, OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static 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 OpenACCFirstPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCIfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static 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 OpenACCReductionClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCReductionOperator Operator, 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 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)
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition: ExprCXX.h:2982
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:3134
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3116
SourceLocation getNameLoc() const
Gets the location of the name.
Definition: ExprCXX.h:3095
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3108
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition: ExprCXX.h:3104
TemplateArgumentLoc const * getTemplateArgs() const
Definition: ExprCXX.h:3136
llvm::iterator_range< decls_iterator > decls() const
Definition: ExprCXX.h:3081
unsigned getNumTemplateArgs() const
Definition: ExprCXX.h:3142
DeclarationName getName() const
Gets the name looked up.
Definition: ExprCXX.h:3092
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3124
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition: ExprCXX.h:3131
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4178
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2582
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2578
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2594
Represents a pack expansion of types.
Definition: Type.h:6953
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:6978
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2135
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2158
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2162
Represents a parameter to a function.
Definition: Decl.h:1722
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1782
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1755
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:2903
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1772
void setSigilLoc(SourceLocation Loc)
Definition: TypeLoc.h:1278
TypeLoc getPointeeLoc() const
Definition: TypeLoc.h:1282
SourceLocation getSigilLoc() const
Definition: TypeLoc.h:1274
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3161
QualType getPointeeType() const
Definition: Type.h:3171
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2565
const IdentifierInfo * getIdentifier() const
Definition: ExprCXX.h:2585
SourceLocation getLocation() const
Definition: ExprCXX.h:2589
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2581
A (possibly-)qualified type.
Definition: Type.h:941
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1008
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:7783
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:7837
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7775
Represents a template name as written in source code.
Definition: TemplateName.h:434
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:319
void removeObjCLifetime()
Definition: Type.h:538
bool hasRestrict() const
Definition: Type.h:464
static Qualifiers fromCVRMask(unsigned CVR)
Definition: Type.h:422
bool hasObjCLifetime() const
Definition: Type.h:531
bool empty() const
Definition: Type.h:634
LangAS getAddressSpace() const
Definition: Type.h:558
Represents a struct/union/class.
Definition: Decl.h:4141
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5936
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3402
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3418
Represents the body of a requires-expression.
Definition: DeclCXX.h:2029
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition: DeclCXX.cpp:2176
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:510
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:1275
Represents a __leave statement.
Definition: Stmt.h:3723
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:35
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement.
Definition: SemaObjC.cpp:197
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:484
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:324
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:222
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Definition: SemaObjC.cpp:217
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
Definition: SemaObjC.cpp:242
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:711
ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *operand)
Definition: SemaObjC.cpp:286
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:206
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Definition: SemaObjC.cpp:333
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:164
void setLParenLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:250
void setConditionDetails(Expr *ConditionExpr)
Definition: SemaOpenACC.h:259
OpenACCClauseKind getClauseKind() const
Definition: SemaOpenACC.h:96
SourceLocation getLParenLoc() const
Definition: SemaOpenACC.h:100
SourceLocation getBeginLoc() const
Definition: SemaOpenACC.h:98
void setDefaultDetails(OpenACCDefaultClauseKind DefKind)
Definition: SemaOpenACC.h:253
SourceLocation getQueuesLoc() const
Definition: SemaOpenACC.h:144
void setVarListDetails(ArrayRef< Expr * > VarList, bool IsReadOnly, bool IsZero)
Definition: SemaOpenACC.h:290
void setWaitDetails(Expr *DevNum, SourceLocation QueuesLoc, llvm::SmallVector< Expr * > &&IntExprs)
Definition: SemaOpenACC.h:368
void setEndLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:251
void setIntExprDetails(ArrayRef< Expr * > IntExprs)
Definition: SemaOpenACC.h:273
OpenACCDefaultClauseKind getDefaultClauseKind() const
Definition: SemaOpenACC.h:104
StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssocStmt)
Called after the directive has been completely parsed, including the declaration group or associated ...
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 * 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 * 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 * ActOnOpenMPReductionClause(ArrayRef< Expr * > VarList, OpenMPReductionClauseModifier Modifier, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions=std::nullopt)
Called on well-formed 'reduction' clause.
OMPClause * ActOnOpenMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'is_device_ptr' clause.
OMPClause * ActOnOpenMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'has_device_addr' clause.
OMPClause * ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'partial' clauses.
OMPClause * ActOnOpenMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'lastprivate' clause.
OMPClause * ActOnOpenMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'firstprivate' clause.
OMPClause * ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'priority' clause.
OMPClause * ActOnOpenMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'dist_schedule' clause.
OMPClause * ActOnOpenMPAllocateClause(Expr *Allocator, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' clause.
OMPClause * ActOnOpenMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nontemporal' clause.
OMPClause * ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'bind' 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 * 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)
OMPClause * ActOnOpenMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers=std::nullopt)
Called on well-formed 'from' clause.
OMPClause * ActOnOpenMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers=std::nullopt)
Called on well-formed 'to' clause.
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 * ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, OpenMPOrderClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'order' 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 * 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 * ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' clause.
OMPClause * ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'message' 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=std::nullopt)
Called on well-formed 'map' clause.
OMPClause * ActOnOpenMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions=std::nullopt)
Called on well-formed 'task_reduction' 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 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 * 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 * ActOnOpenMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions=std::nullopt)
Called on well-formed 'in_reduction' clause.
OMPClause * ActOnOpenMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'exclusive' clause.
OMPClause * ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'thread_limit' clause.
OMPClause * ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'if' clause.
ExprResult checkAssignment(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opcode, Expr *LHS, Expr *RHS)
Expr * recreateSyntacticForm(PseudoObjectExpr *E)
Given a pseudo-object expression, recreate what it looks like syntactically without the attendant Opa...
ExprResult checkRValue(Expr *E)
ExprResult BuildUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition: SemaSYCL.cpp:139
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:13186
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:8057
A RAII object to enter scope of a compound statement.
Definition: Sema.h:1009
A helper class for building up ExtParameterInfos.
Definition: Sema.h:12608
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:12627
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition: Sema.h:12615
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition: Sema.h:13543
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:535
QualType BuildParenType(QualType T)
Build a paren type including T.
Definition: SemaType.cpp:1654
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:6321
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:4375
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:8999
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:9007
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:9002
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:6424
ExprResult ActOnConstantExpression(ExprResult Res)
Definition: SemaExpr.cpp:19378
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:4409
QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc)
Definition: SemaType.cpp:2295
StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: SemaStmt.cpp:606
SemaOpenMP & OpenMP()
Definition: Sema.h:1219
@ IER_DoesNotExist
The symbol does not exist.
Definition: Sema.h:8474
@ IER_Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition: Sema.h:8478
@ IER_Error
An error occurred.
Definition: Sema.h:8481
@ IER_Exists
The symbol exists.
Definition: Sema.h:8471
void ActOnStartStmtExpr()
Definition: SemaExpr.cpp:15607
void ActOnStmtExprError()
Definition: SemaExpr.cpp:15613
std::optional< FunctionEffectMode > ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName)
Try to parse the conditional expression attached to an effect attribute (e.g.
Definition: SemaType.cpp:7488
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:20110
ConditionKind
Definition: Sema.h:7355
@ 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:395
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
Definition: SemaStmt.cpp:3126
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:464
QualType BuildExtVectorType(QualType T, Expr *ArraySize, SourceLocation AttrLoc)
Build an ext-vector type.
Definition: SemaType.cpp:2366
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
Definition: SemaInit.cpp:3475
void MarkDeclarationsReferencedInExpr(Expr *E, bool SkipLocalVariables=false, ArrayRef< const Expr * > StopAt=std::nullopt)
Mark any declarations that appear within this expression or any potentially-evaluated subexpressions ...
Definition: SemaExpr.cpp:19897
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth)
Definition: SemaExpr.cpp:15626
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:1239
ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16274
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:1002
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:2605
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:597
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.
bool diagnoseConflictingFunctionEffect(const FunctionEffectsRef &FX, const FunctionEffectWithCondition &EC, SourceLocation NewAttrLoc)
Warn and return true if adding an effect to a set would create a conflict.
Definition: SemaDecl.cpp:20233
SemaObjC & ObjC()
Definition: Sema.h:1204
ParsedType getDestructorName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, ParsedType ObjectType, bool EnteringContext)
ASTContext & getASTContext() const
Definition: Sema.h:600
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:15544
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:4299
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:694
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Definition: SemaExpr.cpp:3466
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
Definition: SemaExpr.cpp:6968
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Definition: SemaExpr.cpp:15594
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
Definition: SemaExpr.cpp:7823
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
Definition: SemaType.cpp:9380
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:16773
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
Definition: SemaExpr.cpp:2186
QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc)
Build a bit-precise integer type.
Definition: SemaType.cpp:1919
ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc)
Definition: SemaExpr.cpp:15882
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:1653
QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, const DeclSpec *DS=nullptr)
Definition: SemaType.cpp:1560
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Definition: SemaStmt.cpp:1245
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:83
const LangOptions & getLangOpts() const
Definition: Sema.h:593
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:1719
SemaOpenACC & OpenACC()
Definition: Sema.h:1209
@ ReuseLambdaContextDecl
Definition: Sema.h:6535
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:16548
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:15696
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Definition: Sema.cpp:2389
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
Definition: SemaInit.cpp:7445
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:807
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:16748
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:3341
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:1033
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
Definition: SemaDecl.cpp:14746
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:1836
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:13180
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
Definition: SemaExpr.cpp:3163
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition: Sema.cpp:2345
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:1137
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.
ExprResult BuildPackIndexingExpr(Expr *PackExpression, SourceLocation EllipsisLoc, Expr *IndexExpr, SourceLocation RSquareLoc, ArrayRef< Expr * > ExpandedExprs={}, bool EmptyPack=false)
void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base=nullptr)
Perform reference-marking and odr-use handling for a DeclRefExpr.
Definition: SemaExpr.cpp:19739
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:2870
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:2164
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
Definition: SemaStmt.cpp:3141
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
Definition: SemaExpr.cpp:4081
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Definition: SemaExpr.cpp:20694
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:3839
@ NTK_TypeAliasTemplate
Definition: Sema.h:3847
TryCaptureKind
Definition: Sema.h:6597
@ TryCapture_Implicit
Definition: Sema.h:6598
@ TryCapture_ExplicitByVal
Definition: Sema.h:6599
@ TryCapture_ExplicitByRef
Definition: Sema.h:6600
ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Create a new AsTypeExpr node (bitcast) from the arguments.
Definition: SemaExpr.cpp:6623
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:8691
QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted=false, ArrayRef< QualType > Expansions={})
Definition: SemaType.cpp:9502
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:9785
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:13742
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:215
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
Definition: SemaStmt.cpp:3779
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:1784
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:2592
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
Definition: SemaStmt.cpp:1740
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
Definition: SemaStmt.cpp:1121
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:9470
QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, SourceLocation Loc)
Definition: SemaType.cpp:9729
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
Definition: SemaStmt.cpp:4337
ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a sizeof or alignof expression given a type operand.
Definition: SemaExpr.cpp:4588
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition: SemaStmt.cpp:79
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:7930
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:2027
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Definition: SemaExpr.cpp:5515
QualType BuildReadPipeType(QualType T, SourceLocation Loc)
Build a Read-only Pipe type.
Definition: SemaType.cpp:1911
concepts::NestedRequirement * BuildNestedRequirement(Expr *E)
QualType BuildWritePipeType(QualType T, SourceLocation Loc)
Build a Write-only Pipe type.
Definition: SemaType.cpp:1915
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h:10759
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:547
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:16078
QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind)
Definition: SemaType.cpp:9357
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:19761
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
Definition: SemaCast.cpp:297
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:17839
QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, SourceLocation AttrLoc)
Definition: SemaType.cpp:2426
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:20889
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
Definition: SemaExpr.cpp:15112
ExprResult PerformObjectMemberConversion(Expr *From, NestedNameSpecifier *Qualifier, NamedDecl *FoundDecl, NamedDecl *Member)
Cast a base object to a member's actual type.
Definition: SemaExpr.cpp:2943
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
Definition: SemaStmt.cpp:908
ExprResult BuildInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, SourceLocation RBraceLoc)
Definition: SemaExpr.cpp:7168
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
Definition: SemaExpr.cpp:15920
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
Definition: SemaExpr.cpp:4800
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:14577
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:6356
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:2723
static ConditionResult ConditionError()
Definition: Sema.h:7342
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition: SemaStmt.cpp:415
SemaPseudoObject & PseudoObject()
Definition: Sema.h:1229
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
Definition: SemaStmt.cpp:572
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:4186
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition: SemaStmt.cpp:552
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
Definition: SemaExpr.cpp:17666
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition: SemaStmt.cpp:516
QualType BuildMemberPointerType(QualType T, QualType Class, SourceLocation Loc, DeclarationName Entity)
Build a member pointer type T Class::*.
Definition: SemaType.cpp:2654
QualType BuildBlockPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a block pointer type.
Definition: SemaType.cpp:2706
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
Definition: SemaStmt.cpp:3108
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition: Sema.h:8277
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
Definition: SemaExpr.cpp:4975
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=std::nullopt)
Definition: ExprCXX.cpp:1691
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition: Expr.h:4811
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:350
StmtClass
Definition: Stmt.h:86
@ NoStmtClass
Definition: Stmt.h:87
StmtClass getStmtClass() const
Definition: Stmt.h:1358
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:141
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:864
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3557
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:394
Represents a C++ template name within the type system.
Definition: TemplateName.h:203
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:1687
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1663
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1704
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1671
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1700
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1679
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6473
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.
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.
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Build a new C++11 default-initialization expression.
OMPClause * RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'priority' clause.
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, TypeSourceInfo *EncodeTypeInfo, SourceLocation RParenLoc)
Build a new Objective-C @encode expression.
StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body)
Alternative implementation of TransformLambdaBody that skips transforming the body.
QualType TransformAttributedType(TypeLocBuilder &TLB, AttributedTypeLoc TL, Fn TransformModifiedType)
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.
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)
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.
OMPClause * RebuildOMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyin' clause.
QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, bool isReadPipe)
Build a new pipe type given its value type.
StmtResult RebuildCaseStmt(SourceLocation CaseLoc, Expr *LHS, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation ColonLoc)
Build a new case statement.
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
Build a new template-id expression.
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, VarDecl *ExceptionDecl, Stmt *Handler)
Build a new C++ catch statement.
OMPClause * RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'destroy' clause.
ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec step expression with an expression argument.
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new address-of-label expression.
ExprResult RebuildCxxSubscriptExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
TemplateName TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr, bool AllowInjectedClassName=false)
Transform the given template name.
OMPClause * RebuildOMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_bare' clause.
const Attr * TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS, const Attr *A)
ExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, Expr *LHS, SourceLocation ColonLoc, Expr *RHS)
Build a new conditional operator expression.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
Attach body to a C++0x range-based for statement.
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *Object, Stmt *Body)
Build a new Objective-C @synchronized statement.
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.
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...
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.
OMPClause * RebuildOMPAllocateClause(Expr *Allocate, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocate' clause.
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)
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 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.
concepts::ExprRequirement * RebuildExprRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
OMPClause * TransformOMPClause(OMPClause *S)
Transform the given statement.
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc)
Build a new atomic type given its value type.
ExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS)
Build a new binary operator expression.
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *SubExpr)
Build a new C-style cast expression.
OMPClause * RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
ExprResult TransformExpr(Expr *E)
Transform the given expression.
bool AlreadyTransformed(QualType T)
Determine whether the given type T has already been transformed.
concepts::TypeRequirement * RebuildTypeRequirement(TypeSourceInfo *T)
ExprResult RebuildOMPIteratorExpr(SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< SemaOpenMP::OMPIteratorData > Data)
Build a new iterator expression.
ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
OMPClause * RebuildOMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'grainsize' clause.
OMPClause * RebuildOMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
bool TransformTemplateArguments(InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
static ExprResult Owned(Expr *E)
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(expr) expression.
OMPClause * RebuildOMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_tasks' clause.
OMPClause * RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depobj' pseudo clause.
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc)
Build a new __builtin_choose_expr expression.
OMPClause * RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'align' clause.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C class message.
bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, LookupResult &R)
Transform the set of declarations in an OverloadExpr.
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, SourceLocation LParenOrBraceLoc, MultiExprArg Args, SourceLocation RParenOrBraceLoc, bool ListInitialization)
Build a new object-construction expression.
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init, SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps)
Build a new C++0x range-based for statement.
OMPClause * RebuildOMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Num)
Build a new OpenMP 'ordered' clause.
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
QualType RebuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build an Objective-C object type.
llvm::DenseMap< Decl *, Decl * > TransformedLocalDecls
The set of local declarations that have been transformed, for cases where we are forced to build new ...
OMPClause * RebuildOMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'novariants' clause.
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E)
OMPClause * RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' clause.
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.
OMPClause * RebuildOMPThreadLimitClause(Expr *ThreadLimit, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'thread_limit' clause.
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.
ExprResult RebuildPackIndexingExpr(SourceLocation EllipsisLoc, SourceLocation RSquareLoc, Expr *PackIdExpression, Expr *IndexExpr, ArrayRef< Expr * > ExpandedExprs, bool EmptyPack=false)
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 * 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.
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:749
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:2684
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
A container of type source information.
Definition: Type.h:7714
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:7725
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:3165
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:6713
The base class of the type hierarchy.
Definition: Type.h:1829
bool isPointerType() const
Definition: Type.h:7996
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8583
bool isReferenceType() const
Definition: Type.h:8010
bool isEnumeralType() const
Definition: Type.h:8096
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool canHaveNullability(bool ResultIfUnknown=true) const
Determine whether the given type can have a nullability specifier applied to it, i....
Definition: Type.cpp:4699
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2777
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2672
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2336
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: Type.h:8436
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:4961
bool isFunctionType() const
Definition: Type.h:7992
bool isObjCObjectPointerType() const
Definition: Type.h:8134
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8516
bool isRecordType() const
Definition: Type.h:8092
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3405
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:2188
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1414
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:1025
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3202
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent)
Definition: ExprCXX.cpp:419
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:3275
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:3270
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:5538
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3320
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3384
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
QualType getType() const
Definition: Decl.h:678
Represents a variable declaration or definition.
Definition: Decl.h:879
@ CInit
C-style initialization with assignment.
Definition: Decl.h:884
@ CallInit
Call-style initialization (C++98)
Definition: Decl.h:887
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1116
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Definition: Decl.cpp:2651
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
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition: ScopeInfo.h:865
@ 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:776
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
Definition: Interp.h:876
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition: Descriptor.h:28
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.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
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
ArrayTypeTrait
Names for the array type traits.
Definition: TypeTraits.h:42
@ CPlusPlus23
Definition: LangStandard.h:61
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1788
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:24
OpenMPDefaultmapClauseModifier
OpenMP modifiers for 'defaultmap' clause.
Definition: OpenMPKinds.h:118
OpenMPOrderClauseModifier
OpenMP modifiers for 'order' clause.
Definition: OpenMPKinds.h:171
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:158
OpenMPAtClauseKind
OpenMP attributes for 'at' clause.
Definition: OpenMPKinds.h:135
@ 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:186
BinaryOperatorKind
TypeOfKind
The kind of 'typeof' expression we're after.
Definition: Type.h:922
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition: OpenMPKinds.h:38
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Definition: OpenMPKinds.h:103
OpenMPDoacrossClauseModifier
OpenMP dependence types for 'doacross' clause.
Definition: OpenMPKinds.h:219
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:200
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:3537
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
Definition: OpenMPKinds.h:157
OpenMPGrainsizeClauseModifier
Definition: OpenMPKinds.h:206
OpenMPNumTasksClauseModifier
Definition: OpenMPKinds.h:212
UnaryOperatorKind
ActionResult< Expr * > ExprResult
Definition: Ownership.h:248
TagTypeKind
The kind of a tag type.
Definition: Type.h:6683
bool transformOMPMappableExprListClause(TreeTransform< Derived > &TT, OMPMappableExprListClause< T > *C, llvm::SmallVectorImpl< Expr * > &Vars, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperIdInfo, llvm::SmallVectorImpl< Expr * > &UnresolvedMappers)
OpenACCDirectiveKind
Definition: OpenACCKinds.h:25
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:1542
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
Definition: OpenMPKinds.h:142
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:249
OpenMPDefaultmapClauseKind
OpenMP attributes for 'defaultmap' clause.
Definition: OpenMPKinds.h:110
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition: OpenMPKinds.h:62
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:132
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:136
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:258
VectorKind
Definition: Type.h:3954
OpenMPDeviceClauseModifier
OpenMP modifiers for 'device' clause.
Definition: OpenMPKinds.h:47
SourceLocIdentKind
Definition: Expr.h:4738
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:6658
@ 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:164
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:30
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:258
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition: OpenMPKinds.h:70
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:90
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:4791
EffectConditionExpr Cond
Definition: Type.h:4793
Holds information about the various types of exception specification.
Definition: Type.h:5030
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:5046
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5032
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5035
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:5038
Extra information about a function prototype.
Definition: Type.h:5058
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5065
FunctionEffectsRef FunctionEffects
Definition: Type.h:5068
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:5066
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:12685
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:2810
Location information for a TemplateArgument.
Definition: TemplateBase.h:472