clang 19.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 "llvm/ADT/ArrayRef.h"
43#include "llvm/Support/ErrorHandling.h"
44#include <algorithm>
45#include <optional>
46
47using namespace llvm::omp;
48
49namespace clang {
50using namespace sema;
51
52/// A semantic tree transformation that allows one to transform one
53/// abstract syntax tree into another.
54///
55/// A new tree transformation is defined by creating a new subclass \c X of
56/// \c TreeTransform<X> and then overriding certain operations to provide
57/// behavior specific to that transformation. For example, template
58/// instantiation is implemented as a tree transformation where the
59/// transformation of TemplateTypeParmType nodes involves substituting the
60/// template arguments for their corresponding template parameters; a similar
61/// transformation is performed for non-type template parameters and
62/// template template parameters.
63///
64/// This tree-transformation template uses static polymorphism to allow
65/// subclasses to customize any of its operations. Thus, a subclass can
66/// override any of the transformation or rebuild operators by providing an
67/// operation with the same signature as the default implementation. The
68/// overriding function should not be virtual.
69///
70/// Semantic tree transformations are split into two stages, either of which
71/// can be replaced by a subclass. The "transform" step transforms an AST node
72/// or the parts of an AST node using the various transformation functions,
73/// then passes the pieces on to the "rebuild" step, which constructs a new AST
74/// node of the appropriate kind from the pieces. The default transformation
75/// routines recursively transform the operands to composite AST nodes (e.g.,
76/// the pointee type of a PointerType node) and, if any of those operand nodes
77/// were changed by the transformation, invokes the rebuild operation to create
78/// a new AST node.
79///
80/// Subclasses can customize the transformation at various levels. The
81/// most coarse-grained transformations involve replacing TransformType(),
82/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
83/// TransformTemplateName(), or TransformTemplateArgument() with entirely
84/// new implementations.
85///
86/// For more fine-grained transformations, subclasses can replace any of the
87/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
88/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
89/// replacing TransformTemplateTypeParmType() allows template instantiation
90/// to substitute template arguments for their corresponding template
91/// parameters. Additionally, subclasses can override the \c RebuildXXX
92/// functions to control how AST nodes are rebuilt when their operands change.
93/// By default, \c TreeTransform will invoke semantic analysis to rebuild
94/// AST nodes. However, certain other tree transformations (e.g, cloning) may
95/// be able to use more efficient rebuild steps.
96///
97/// There are a handful of other functions that can be overridden, allowing one
98/// to avoid traversing nodes that don't need any transformation
99/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
100/// operands have not changed (\c AlwaysRebuild()), and customize the
101/// default locations and entity names used for type-checking
102/// (\c getBaseLocation(), \c getBaseEntity()).
103template<typename Derived>
105 /// Private RAII object that helps us forget and then re-remember
106 /// the template argument corresponding to a partially-substituted parameter
107 /// pack.
108 class ForgetPartiallySubstitutedPackRAII {
109 Derived &Self;
111
112 public:
113 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
114 Old = Self.ForgetPartiallySubstitutedPack();
115 }
116
117 ~ForgetPartiallySubstitutedPackRAII() {
118 Self.RememberPartiallySubstitutedPack(Old);
119 }
120 };
121
122protected:
124
125 /// The set of local declarations that have been transformed, for
126 /// cases where we are forced to build new declarations within the transformer
127 /// rather than in the subclass (e.g., lambda closure types).
128 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
129
130public:
131 /// Initializes a new tree transformer.
133
134 /// Retrieves a reference to the derived class.
135 Derived &getDerived() { return static_cast<Derived&>(*this); }
136
137 /// Retrieves a reference to the derived class.
138 const Derived &getDerived() const {
139 return static_cast<const Derived&>(*this);
140 }
141
142 static inline ExprResult Owned(Expr *E) { return E; }
143 static inline StmtResult Owned(Stmt *S) { return S; }
144
145 /// Retrieves a reference to the semantic analysis object used for
146 /// this tree transform.
147 Sema &getSema() const { return SemaRef; }
148
149 /// Whether the transformation should always rebuild AST nodes, even
150 /// if none of the children have changed.
151 ///
152 /// Subclasses may override this function to specify when the transformation
153 /// should rebuild all AST nodes.
154 ///
155 /// We must always rebuild all AST nodes when performing variadic template
156 /// pack expansion, in order to avoid violating the AST invariant that each
157 /// statement node appears at most once in its containing declaration.
159
160 /// Whether the transformation is forming an expression or statement that
161 /// replaces the original. In this case, we'll reuse mangling numbers from
162 /// existing lambdas.
163 bool ReplacingOriginal() { return false; }
164
165 /// Wether CXXConstructExpr can be skipped when they are implicit.
166 /// They will be reconstructed when used if needed.
167 /// This is useful when the user that cause rebuilding of the
168 /// CXXConstructExpr is outside of the expression at which the TreeTransform
169 /// started.
170 bool AllowSkippingCXXConstructExpr() { return true; }
171
172 /// Returns the location of the entity being transformed, if that
173 /// information was not available elsewhere in the AST.
174 ///
175 /// By default, returns no source-location information. Subclasses can
176 /// provide an alternative implementation that provides better location
177 /// information.
179
180 /// Returns the name of the entity being transformed, if that
181 /// information was not available elsewhere in the AST.
182 ///
183 /// By default, returns an empty name. Subclasses can provide an alternative
184 /// implementation with a more precise name.
186
187 /// Sets the "base" location and entity when that
188 /// information is known based on another transformation.
189 ///
190 /// By default, the source location and entity are ignored. Subclasses can
191 /// override this function to provide a customized implementation.
193
194 /// RAII object that temporarily sets the base location and entity
195 /// used for reporting diagnostics in types.
197 TreeTransform &Self;
198 SourceLocation OldLocation;
199 DeclarationName OldEntity;
200
201 public:
203 DeclarationName Entity) : Self(Self) {
204 OldLocation = Self.getDerived().getBaseLocation();
205 OldEntity = Self.getDerived().getBaseEntity();
206
207 if (Location.isValid())
208 Self.getDerived().setBase(Location, Entity);
209 }
210
212 Self.getDerived().setBase(OldLocation, OldEntity);
213 }
214 };
215
216 /// Determine whether the given type \p T has already been
217 /// transformed.
218 ///
219 /// Subclasses can provide an alternative implementation of this routine
220 /// to short-circuit evaluation when it is known that a given type will
221 /// not change. For example, template instantiation need not traverse
222 /// non-dependent types.
224 return T.isNull();
225 }
226
227 /// Transform a template parameter depth level.
228 ///
229 /// During a transformation that transforms template parameters, this maps
230 /// an old template parameter depth to a new depth.
231 unsigned TransformTemplateDepth(unsigned Depth) {
232 return Depth;
233 }
234
235 /// Determine whether the given call argument should be dropped, e.g.,
236 /// because it is a default argument.
237 ///
238 /// Subclasses can provide an alternative implementation of this routine to
239 /// determine which kinds of call arguments get dropped. By default,
240 /// CXXDefaultArgument nodes are dropped (prior to transformation).
242 return E->isDefaultArgument();
243 }
244
245 /// Determine whether we should expand a pack expansion with the
246 /// given set of parameter packs into separate arguments by repeatedly
247 /// transforming the pattern.
248 ///
249 /// By default, the transformer never tries to expand pack expansions.
250 /// Subclasses can override this routine to provide different behavior.
251 ///
252 /// \param EllipsisLoc The location of the ellipsis that identifies the
253 /// pack expansion.
254 ///
255 /// \param PatternRange The source range that covers the entire pattern of
256 /// the pack expansion.
257 ///
258 /// \param Unexpanded The set of unexpanded parameter packs within the
259 /// pattern.
260 ///
261 /// \param ShouldExpand Will be set to \c true if the transformer should
262 /// expand the corresponding pack expansions into separate arguments. When
263 /// set, \c NumExpansions must also be set.
264 ///
265 /// \param RetainExpansion Whether the caller should add an unexpanded
266 /// pack expansion after all of the expanded arguments. This is used
267 /// when extending explicitly-specified template argument packs per
268 /// C++0x [temp.arg.explicit]p9.
269 ///
270 /// \param NumExpansions The number of separate arguments that will be in
271 /// the expanded form of the corresponding pack expansion. This is both an
272 /// input and an output parameter, which can be set by the caller if the
273 /// number of expansions is known a priori (e.g., due to a prior substitution)
274 /// and will be set by the callee when the number of expansions is known.
275 /// The callee must set this value when \c ShouldExpand is \c true; it may
276 /// set this value in other cases.
277 ///
278 /// \returns true if an error occurred (e.g., because the parameter packs
279 /// are to be instantiated with arguments of different lengths), false
280 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
281 /// must be set.
283 SourceRange PatternRange,
285 bool &ShouldExpand, bool &RetainExpansion,
286 std::optional<unsigned> &NumExpansions) {
287 ShouldExpand = false;
288 return false;
289 }
290
291 /// "Forget" about the partially-substituted pack template argument,
292 /// when performing an instantiation that must preserve the parameter pack
293 /// use.
294 ///
295 /// This routine is meant to be overridden by the template instantiator.
297 return TemplateArgument();
298 }
299
300 /// "Remember" the partially-substituted pack template argument
301 /// after performing an instantiation that must preserve the parameter pack
302 /// use.
303 ///
304 /// This routine is meant to be overridden by the template instantiator.
306
307 /// Note to the derived class when a function parameter pack is
308 /// being expanded.
310
311 /// Transforms the given type into another type.
312 ///
313 /// By default, this routine transforms a type by creating a
314 /// TypeSourceInfo for it and delegating to the appropriate
315 /// function. This is expensive, but we don't mind, because
316 /// this method is deprecated anyway; all users should be
317 /// switched to storing TypeSourceInfos.
318 ///
319 /// \returns the transformed type.
321
322 /// Transforms the given type-with-location into a new
323 /// type-with-location.
324 ///
325 /// By default, this routine transforms a type by delegating to the
326 /// appropriate TransformXXXType to build a new type. Subclasses
327 /// may override this function (to take over all type
328 /// transformations) or some set of the TransformXXXType functions
329 /// to alter the transformation.
331
332 /// Transform the given type-with-location into a new
333 /// type, collecting location information in the given builder
334 /// as necessary.
335 ///
337
338 /// Transform a type that is permitted to produce a
339 /// DeducedTemplateSpecializationType.
340 ///
341 /// This is used in the (relatively rare) contexts where it is acceptable
342 /// for transformation to produce a class template type with deduced
343 /// template arguments.
344 /// @{
347 /// @}
348
349 /// The reason why the value of a statement is not discarded, if any.
354 };
355
356 /// Transform the given statement.
357 ///
358 /// By default, this routine transforms a statement by delegating to the
359 /// appropriate TransformXXXStmt function to transform a specific kind of
360 /// statement or the TransformExpr() function to transform an expression.
361 /// Subclasses may override this function to transform statements using some
362 /// other mechanism.
363 ///
364 /// \returns the transformed statement.
366
367 /// Transform the given statement.
368 ///
369 /// By default, this routine transforms a statement by delegating to the
370 /// appropriate TransformOMPXXXClause function to transform a specific kind
371 /// of clause. Subclasses may override this function to transform statements
372 /// using some other mechanism.
373 ///
374 /// \returns the transformed OpenMP clause.
376
377 /// Transform the given attribute.
378 ///
379 /// By default, this routine transforms a statement by delegating to the
380 /// appropriate TransformXXXAttr function to transform a specific kind
381 /// of attribute. Subclasses may override this function to transform
382 /// attributed statements/types using some other mechanism.
383 ///
384 /// \returns the transformed attribute
385 const Attr *TransformAttr(const Attr *S);
386
387 // Transform the given statement attribute.
388 //
389 // Delegates to the appropriate TransformXXXAttr function to transform a
390 // specific kind of statement attribute. Unlike the non-statement taking
391 // version of this, this implements all attributes, not just pragmas.
392 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
393 const Attr *A);
394
395 // Transform the specified attribute.
396 //
397 // Subclasses should override the transformation of attributes with a pragma
398 // spelling to transform expressions stored within the attribute.
399 //
400 // \returns the transformed attribute.
401#define ATTR(X) \
402 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
403#include "clang/Basic/AttrList.inc"
404
405 // Transform the specified attribute.
406 //
407 // Subclasses should override the transformation of attributes to do
408 // transformation and checking of statement attributes. By default, this
409 // delegates to the non-statement taking version.
410 //
411 // \returns the transformed attribute.
412#define ATTR(X) \
413 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
414 const X##Attr *A) { \
415 return getDerived().Transform##X##Attr(A); \
416 }
417#include "clang/Basic/AttrList.inc"
418
419 /// Transform the given expression.
420 ///
421 /// By default, this routine transforms an expression by delegating to the
422 /// appropriate TransformXXXExpr function to build a new expression.
423 /// Subclasses may override this function to transform expressions using some
424 /// other mechanism.
425 ///
426 /// \returns the transformed expression.
428
429 /// Transform the given initializer.
430 ///
431 /// By default, this routine transforms an initializer by stripping off the
432 /// semantic nodes added by initialization, then passing the result to
433 /// TransformExpr or TransformExprs.
434 ///
435 /// \returns the transformed initializer.
437
438 /// Transform the given list of expressions.
439 ///
440 /// This routine transforms a list of expressions by invoking
441 /// \c TransformExpr() for each subexpression. However, it also provides
442 /// support for variadic templates by expanding any pack expansions (if the
443 /// derived class permits such expansion) along the way. When pack expansions
444 /// are present, the number of outputs may not equal the number of inputs.
445 ///
446 /// \param Inputs The set of expressions to be transformed.
447 ///
448 /// \param NumInputs The number of expressions in \c Inputs.
449 ///
450 /// \param IsCall If \c true, then this transform is being performed on
451 /// function-call arguments, and any arguments that should be dropped, will
452 /// be.
453 ///
454 /// \param Outputs The transformed input expressions will be added to this
455 /// vector.
456 ///
457 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
458 /// due to transformation.
459 ///
460 /// \returns true if an error occurred, false otherwise.
461 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
463 bool *ArgChanged = nullptr);
464
465 /// Transform the given declaration, which is referenced from a type
466 /// or expression.
467 ///
468 /// By default, acts as the identity function on declarations, unless the
469 /// transformer has had to transform the declaration itself. Subclasses
470 /// may override this function to provide alternate behavior.
472 llvm::DenseMap<Decl *, Decl *>::iterator Known
473 = TransformedLocalDecls.find(D);
474 if (Known != TransformedLocalDecls.end())
475 return Known->second;
476
477 return D;
478 }
479
480 /// Transform the specified condition.
481 ///
482 /// By default, this transforms the variable and expression and rebuilds
483 /// the condition.
485 Expr *Expr,
487
488 /// Transform the attributes associated with the given declaration and
489 /// place them on the new declaration.
490 ///
491 /// By default, this operation does nothing. Subclasses may override this
492 /// behavior to transform attributes.
493 void transformAttrs(Decl *Old, Decl *New) { }
494
495 /// Note that a local declaration has been transformed by this
496 /// transformer.
497 ///
498 /// Local declarations are typically transformed via a call to
499 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
500 /// the transformer itself has to transform the declarations. This routine
501 /// can be overridden by a subclass that keeps track of such mappings.
503 assert(New.size() == 1 &&
504 "must override transformedLocalDecl if performing pack expansion");
505 TransformedLocalDecls[Old] = New.front();
506 }
507
508 /// Transform the definition of the given declaration.
509 ///
510 /// By default, invokes TransformDecl() to transform the declaration.
511 /// Subclasses may override this function to provide alternate behavior.
513 return getDerived().TransformDecl(Loc, D);
514 }
515
516 /// Transform the given declaration, which was the first part of a
517 /// nested-name-specifier in a member access expression.
518 ///
519 /// This specific declaration transformation only applies to the first
520 /// identifier in a nested-name-specifier of a member access expression, e.g.,
521 /// the \c T in \c x->T::member
522 ///
523 /// By default, invokes TransformDecl() to transform the declaration.
524 /// Subclasses may override this function to provide alternate behavior.
526 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
527 }
528
529 /// Transform the set of declarations in an OverloadExpr.
530 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
531 LookupResult &R);
532
533 /// Transform the given nested-name-specifier with source-location
534 /// information.
535 ///
536 /// By default, transforms all of the types and declarations within the
537 /// nested-name-specifier. Subclasses may override this function to provide
538 /// alternate behavior.
541 QualType ObjectType = QualType(),
542 NamedDecl *FirstQualifierInScope = nullptr);
543
544 /// Transform the given declaration name.
545 ///
546 /// By default, transforms the types of conversion function, constructor,
547 /// and destructor names and then (if needed) rebuilds the declaration name.
548 /// Identifiers and selectors are returned unmodified. Subclasses may
549 /// override this function to provide alternate behavior.
552
562
563 /// Transform the given template name.
564 ///
565 /// \param SS The nested-name-specifier that qualifies the template
566 /// name. This nested-name-specifier must already have been transformed.
567 ///
568 /// \param Name The template name to transform.
569 ///
570 /// \param NameLoc The source location of the template name.
571 ///
572 /// \param ObjectType If we're translating a template name within a member
573 /// access expression, this is the type of the object whose member template
574 /// is being referenced.
575 ///
576 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
577 /// also refers to a name within the current (lexical) scope, this is the
578 /// declaration it refers to.
579 ///
580 /// By default, transforms the template name by transforming the declarations
581 /// and nested-name-specifiers that occur within the template name.
582 /// Subclasses may override this function to provide alternate behavior.
585 SourceLocation NameLoc,
586 QualType ObjectType = QualType(),
587 NamedDecl *FirstQualifierInScope = nullptr,
588 bool AllowInjectedClassName = false);
589
590 /// Transform the given template argument.
591 ///
592 /// By default, this operation transforms the type, expression, or
593 /// declaration stored within the template argument and constructs a
594 /// new template argument from the transformed result. Subclasses may
595 /// override this function to provide alternate behavior.
596 ///
597 /// Returns true if there was an error.
599 TemplateArgumentLoc &Output,
600 bool Uneval = false);
601
602 /// Transform the given set of template arguments.
603 ///
604 /// By default, this operation transforms all of the template arguments
605 /// in the input set using \c TransformTemplateArgument(), and appends
606 /// the transformed arguments to the output list.
607 ///
608 /// Note that this overload of \c TransformTemplateArguments() is merely
609 /// a convenience function. Subclasses that wish to override this behavior
610 /// should override the iterator-based member template version.
611 ///
612 /// \param Inputs The set of template arguments to be transformed.
613 ///
614 /// \param NumInputs The number of template arguments in \p Inputs.
615 ///
616 /// \param Outputs The set of transformed template arguments output by this
617 /// routine.
618 ///
619 /// Returns true if an error occurred.
621 unsigned NumInputs,
623 bool Uneval = false) {
624 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
625 Uneval);
626 }
627
628 /// Transform the given set of template arguments.
629 ///
630 /// By default, this operation transforms all of the template arguments
631 /// in the input set using \c TransformTemplateArgument(), and appends
632 /// the transformed arguments to the output list.
633 ///
634 /// \param First An iterator to the first template argument.
635 ///
636 /// \param Last An iterator one step past the last template argument.
637 ///
638 /// \param Outputs The set of transformed template arguments output by this
639 /// routine.
640 ///
641 /// Returns true if an error occurred.
642 template<typename InputIterator>
644 InputIterator Last,
646 bool Uneval = false);
647
648 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
650 TemplateArgumentLoc &ArgLoc);
651
652 /// Fakes up a TypeSourceInfo for a type.
656 }
657
658#define ABSTRACT_TYPELOC(CLASS, PARENT)
659#define TYPELOC(CLASS, PARENT) \
660 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
661#include "clang/AST/TypeLocNodes.def"
662
665 bool SuppressObjCLifetime);
669 bool SuppressObjCLifetime);
670
671 template<typename Fn>
674 CXXRecordDecl *ThisContext,
675 Qualifiers ThisTypeQuals,
677
678 template <typename Fn>
680 Fn TransformModifiedType);
681
684 SmallVectorImpl<QualType> &Exceptions,
685 bool &Changed);
686
688
692 TemplateName Template);
693
697 TemplateName Template,
698 CXXScopeSpec &SS);
699
702 NestedNameSpecifierLoc QualifierLoc);
703
704 /// Transforms the parameters of a function type into the
705 /// given vectors.
706 ///
707 /// The result vectors should be kept in sync; null entries in the
708 /// variables vector are acceptable.
709 ///
710 /// LastParamTransformed, if non-null, will be set to the index of the last
711 /// parameter on which transfromation was started. In the event of an error,
712 /// this will contain the parameter which failed to instantiate.
713 ///
714 /// Return true on error.
717 const QualType *ParamTypes,
718 const FunctionProtoType::ExtParameterInfo *ParamInfos,
720 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
721
724 const QualType *ParamTypes,
725 const FunctionProtoType::ExtParameterInfo *ParamInfos,
728 return getDerived().TransformFunctionTypeParams(
729 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
730 }
731
732 /// Transforms the parameters of a requires expresison into the given vectors.
733 ///
734 /// The result vectors should be kept in sync; null entries in the
735 /// variables vector are acceptable.
736 ///
737 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
738 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
739 /// which are cases where transformation shouldn't continue.
741 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
747 KWLoc, Params, /*ParamTypes=*/nullptr,
748 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
749 return ExprError();
750
751 return ExprResult{};
752 }
753
754 /// Transforms a single function-type parameter. Return null
755 /// on error.
756 ///
757 /// \param indexAdjustment - A number to add to the parameter's
758 /// scope index; can be negative
760 int indexAdjustment,
761 std::optional<unsigned> NumExpansions,
762 bool ExpectParameterPack);
763
764 /// Transform the body of a lambda-expression.
766 /// Alternative implementation of TransformLambdaBody that skips transforming
767 /// the body.
769
771
774
777 return TPL;
778 }
779
781
783 bool IsAddressOfOperand,
784 TypeSourceInfo **RecoveryTSI);
785
787 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
788 TypeSourceInfo **RecoveryTSI);
789
791
792// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
793// amount of stack usage with clang.
794#define STMT(Node, Parent) \
795 LLVM_ATTRIBUTE_NOINLINE \
796 StmtResult Transform##Node(Node *S);
797#define VALUESTMT(Node, Parent) \
798 LLVM_ATTRIBUTE_NOINLINE \
799 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
800#define EXPR(Node, Parent) \
801 LLVM_ATTRIBUTE_NOINLINE \
802 ExprResult Transform##Node(Node *E);
803#define ABSTRACT_STMT(Stmt)
804#include "clang/AST/StmtNodes.inc"
805
806#define GEN_CLANG_CLAUSE_CLASS
807#define CLAUSE_CLASS(Enum, Str, Class) \
808 LLVM_ATTRIBUTE_NOINLINE \
809 OMPClause *Transform##Class(Class *S);
810#include "llvm/Frontend/OpenMP/OMP.inc"
811
812 /// Build a new qualified type given its unqualified type and type location.
813 ///
814 /// By default, this routine adds type qualifiers only to types that can
815 /// have qualifiers, and silently suppresses those qualifiers that are not
816 /// permitted. Subclasses may override this routine to provide different
817 /// behavior.
819
820 /// Build a new pointer type given its pointee type.
821 ///
822 /// By default, performs semantic analysis when building the pointer type.
823 /// Subclasses may override this routine to provide different behavior.
825
826 /// Build a new block pointer type given its pointee type.
827 ///
828 /// By default, performs semantic analysis when building the block pointer
829 /// type. Subclasses may override this routine to provide different behavior.
831
832 /// Build a new reference type given the type it references.
833 ///
834 /// By default, performs semantic analysis when building the
835 /// reference type. Subclasses may override this routine to provide
836 /// different behavior.
837 ///
838 /// \param LValue whether the type was written with an lvalue sigil
839 /// or an rvalue sigil.
841 bool LValue,
842 SourceLocation Sigil);
843
844 /// Build a new member pointer type given the pointee type and the
845 /// class type it refers into.
846 ///
847 /// By default, performs semantic analysis when building the member pointer
848 /// type. Subclasses may override this routine to provide different behavior.
850 SourceLocation Sigil);
851
853 SourceLocation ProtocolLAngleLoc,
855 ArrayRef<SourceLocation> ProtocolLocs,
856 SourceLocation ProtocolRAngleLoc);
857
858 /// Build an Objective-C object type.
859 ///
860 /// By default, performs semantic analysis when building the object type.
861 /// Subclasses may override this routine to provide different behavior.
863 SourceLocation Loc,
864 SourceLocation TypeArgsLAngleLoc,
866 SourceLocation TypeArgsRAngleLoc,
867 SourceLocation ProtocolLAngleLoc,
869 ArrayRef<SourceLocation> ProtocolLocs,
870 SourceLocation ProtocolRAngleLoc);
871
872 /// Build a new Objective-C object pointer type given the pointee type.
873 ///
874 /// By default, directly builds the pointer type, with no additional semantic
875 /// analysis.
878
879 /// Build a new array type given the element type, size
880 /// modifier, size of the array (if known), size expression, and index type
881 /// qualifiers.
882 ///
883 /// By default, performs semantic analysis when building the array type.
884 /// Subclasses may override this routine to provide different behavior.
885 /// Also by default, all of the other Rebuild*Array
887 const llvm::APInt *Size, Expr *SizeExpr,
888 unsigned IndexTypeQuals, SourceRange BracketsRange);
889
890 /// Build a new constant array type given the element type, size
891 /// modifier, (known) size of the array, and index type qualifiers.
892 ///
893 /// By default, performs semantic analysis when building the array type.
894 /// Subclasses may override this routine to provide different behavior.
896 ArraySizeModifier SizeMod,
897 const llvm::APInt &Size, Expr *SizeExpr,
898 unsigned IndexTypeQuals,
899 SourceRange BracketsRange);
900
901 /// Build a new incomplete array type given the element type, size
902 /// modifier, and index type qualifiers.
903 ///
904 /// By default, performs semantic analysis when building the array type.
905 /// Subclasses may override this routine to provide different behavior.
907 ArraySizeModifier SizeMod,
908 unsigned IndexTypeQuals,
909 SourceRange BracketsRange);
910
911 /// Build a new variable-length array type given the element type,
912 /// size modifier, size expression, and index type qualifiers.
913 ///
914 /// By default, performs semantic analysis when building the array type.
915 /// Subclasses may override this routine to provide different behavior.
917 ArraySizeModifier SizeMod, Expr *SizeExpr,
918 unsigned IndexTypeQuals,
919 SourceRange BracketsRange);
920
921 /// Build a new dependent-sized array type given the element type,
922 /// size modifier, size expression, and index type qualifiers.
923 ///
924 /// By default, performs semantic analysis when building the array type.
925 /// Subclasses may override this routine to provide different behavior.
927 ArraySizeModifier SizeMod,
928 Expr *SizeExpr,
929 unsigned IndexTypeQuals,
930 SourceRange BracketsRange);
931
932 /// Build a new vector type given the element type and
933 /// number of elements.
934 ///
935 /// By default, performs semantic analysis when building the vector type.
936 /// Subclasses may override this routine to provide different behavior.
937 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
938 VectorKind VecKind);
939
940 /// Build a new potentially dependently-sized extended vector type
941 /// given the element type and number of elements.
942 ///
943 /// By default, performs semantic analysis when building the vector type.
944 /// Subclasses may override this routine to provide different behavior.
946 SourceLocation AttributeLoc, VectorKind);
947
948 /// Build a new extended vector type given the element type and
949 /// number of elements.
950 ///
951 /// By default, performs semantic analysis when building the vector type.
952 /// Subclasses may override this routine to provide different behavior.
953 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
954 SourceLocation AttributeLoc);
955
956 /// Build a new potentially dependently-sized extended vector type
957 /// given the element type and number of elements.
958 ///
959 /// By default, performs semantic analysis when building the vector type.
960 /// Subclasses may override this routine to provide different behavior.
962 Expr *SizeExpr,
963 SourceLocation AttributeLoc);
964
965 /// Build a new matrix type given the element type and dimensions.
966 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
967 unsigned NumColumns);
968
969 /// Build a new matrix type given the type and dependently-defined
970 /// dimensions.
972 Expr *ColumnExpr,
973 SourceLocation AttributeLoc);
974
975 /// Build a new DependentAddressSpaceType or return the pointee
976 /// type variable with the correct address space (retrieved from
977 /// AddrSpaceExpr) applied to it. The former will be returned in cases
978 /// where the address space remains dependent.
979 ///
980 /// By default, performs semantic analysis when building the type with address
981 /// space applied. Subclasses may override this routine to provide different
982 /// behavior.
984 Expr *AddrSpaceExpr,
985 SourceLocation AttributeLoc);
986
987 /// Build a new function type.
988 ///
989 /// By default, performs semantic analysis when building the function type.
990 /// Subclasses may override this routine to provide different behavior.
992 MutableArrayRef<QualType> ParamTypes,
994
995 /// Build a new unprototyped function type.
997
998 /// Rebuild an unresolved typename type, given the decl that
999 /// the UnresolvedUsingTypenameDecl was transformed to.
1001
1002 /// Build a new type found via an alias.
1004 return SemaRef.Context.getUsingType(Found, Underlying);
1005 }
1006
1007 /// Build a new typedef type.
1009 return SemaRef.Context.getTypeDeclType(Typedef);
1010 }
1011
1012 /// Build a new MacroDefined type.
1014 const IdentifierInfo *MacroII) {
1015 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1016 }
1017
1018 /// Build a new class/struct/union type.
1021 }
1022
1023 /// Build a new Enum type.
1026 }
1027
1028 /// Build a new typeof(expr) type.
1029 ///
1030 /// By default, performs semantic analysis when building the typeof type.
1031 /// Subclasses may override this routine to provide different behavior.
1033 TypeOfKind Kind);
1034
1035 /// Build a new typeof(type) type.
1036 ///
1037 /// By default, builds a new TypeOfType with the given underlying type.
1039
1040 /// Build a new unary transform type.
1043 SourceLocation Loc);
1044
1045 /// Build a new C++11 decltype type.
1046 ///
1047 /// By default, performs semantic analysis when building the decltype type.
1048 /// Subclasses may override this routine to provide different behavior.
1050
1052 SourceLocation Loc,
1053 SourceLocation EllipsisLoc,
1054 bool FullySubstituted,
1055 ArrayRef<QualType> Expansions = {});
1056
1057 /// Build a new C++11 auto type.
1058 ///
1059 /// By default, builds a new AutoType with the given deduced type.
1061 ConceptDecl *TypeConstraintConcept,
1062 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1063 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1064 // which has been deduced to a dependent type into an undeduced 'auto', so
1065 // that we'll retry deduction after the transformation.
1066 return SemaRef.Context.getAutoType(Deduced, Keyword,
1067 /*IsDependent*/ false, /*IsPack=*/false,
1068 TypeConstraintConcept,
1069 TypeConstraintArgs);
1070 }
1071
1072 /// By default, builds a new DeducedTemplateSpecializationType with the given
1073 /// deduced type.
1075 QualType Deduced) {
1077 Template, Deduced, /*IsDependent*/ false);
1078 }
1079
1080 /// Build a new template specialization type.
1081 ///
1082 /// By default, performs semantic analysis when building the template
1083 /// specialization type. Subclasses may override this routine to provide
1084 /// different behavior.
1086 SourceLocation TemplateLoc,
1088
1089 /// Build a new parenthesized type.
1090 ///
1091 /// By default, builds a new ParenType type from the inner type.
1092 /// Subclasses may override this routine to provide different behavior.
1094 return SemaRef.BuildParenType(InnerType);
1095 }
1096
1097 /// Build a new qualified name type.
1098 ///
1099 /// By default, builds a new ElaboratedType type from the keyword,
1100 /// the nested-name-specifier and the named type.
1101 /// Subclasses may override this routine to provide different behavior.
1103 ElaboratedTypeKeyword Keyword,
1104 NestedNameSpecifierLoc QualifierLoc,
1105 QualType Named) {
1106 return SemaRef.Context.getElaboratedType(Keyword,
1107 QualifierLoc.getNestedNameSpecifier(),
1108 Named);
1109 }
1110
1111 /// Build a new typename type that refers to a template-id.
1112 ///
1113 /// By default, builds a new DependentNameType type from the
1114 /// nested-name-specifier and the given type. Subclasses may override
1115 /// this routine to provide different behavior.
1117 ElaboratedTypeKeyword Keyword,
1118 NestedNameSpecifierLoc QualifierLoc,
1119 SourceLocation TemplateKWLoc,
1120 const IdentifierInfo *Name,
1121 SourceLocation NameLoc,
1123 bool AllowInjectedClassName) {
1124 // Rebuild the template name.
1125 // TODO: avoid TemplateName abstraction
1126 CXXScopeSpec SS;
1127 SS.Adopt(QualifierLoc);
1128 TemplateName InstName = getDerived().RebuildTemplateName(
1129 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1130 AllowInjectedClassName);
1131
1132 if (InstName.isNull())
1133 return QualType();
1134
1135 // If it's still dependent, make a dependent specialization.
1136 if (InstName.getAsDependentTemplateName())
1138 Keyword, QualifierLoc.getNestedNameSpecifier(), Name,
1139 Args.arguments());
1140
1141 // Otherwise, make an elaborated type wrapping a non-dependent
1142 // specialization.
1143 QualType T =
1144 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1145 if (T.isNull())
1146 return QualType();
1148 Keyword, QualifierLoc.getNestedNameSpecifier(), T);
1149 }
1150
1151 /// Build a new typename type that refers to an identifier.
1152 ///
1153 /// By default, performs semantic analysis when building the typename type
1154 /// (or elaborated type). Subclasses may override this routine to provide
1155 /// different behavior.
1157 SourceLocation KeywordLoc,
1158 NestedNameSpecifierLoc QualifierLoc,
1159 const IdentifierInfo *Id,
1160 SourceLocation IdLoc,
1161 bool DeducedTSTContext) {
1162 CXXScopeSpec SS;
1163 SS.Adopt(QualifierLoc);
1164
1165 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1166 // If the name is still dependent, just build a new dependent name type.
1167 if (!SemaRef.computeDeclContext(SS))
1168 return SemaRef.Context.getDependentNameType(Keyword,
1169 QualifierLoc.getNestedNameSpecifier(),
1170 Id);
1171 }
1172
1173 if (Keyword == ElaboratedTypeKeyword::None ||
1175 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1176 *Id, IdLoc, DeducedTSTContext);
1177 }
1178
1180
1181 // We had a dependent elaborated-type-specifier that has been transformed
1182 // into a non-dependent elaborated-type-specifier. Find the tag we're
1183 // referring to.
1185 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1186 if (!DC)
1187 return QualType();
1188
1190 return QualType();
1191
1192 TagDecl *Tag = nullptr;
1194 switch (Result.getResultKind()) {
1197 break;
1198
1200 Tag = Result.getAsSingle<TagDecl>();
1201 break;
1202
1205 llvm_unreachable("Tag lookup cannot find non-tags");
1206
1208 // Let the LookupResult structure handle ambiguities.
1209 return QualType();
1210 }
1211
1212 if (!Tag) {
1213 // Check where the name exists but isn't a tag type and use that to emit
1214 // better diagnostics.
1217 switch (Result.getResultKind()) {
1221 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1222 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1223 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1224 << SomeDecl << NTK << llvm::to_underlying(Kind);
1225 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1226 break;
1227 }
1228 default:
1229 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1230 << llvm::to_underlying(Kind) << Id << DC
1231 << QualifierLoc.getSourceRange();
1232 break;
1233 }
1234 return QualType();
1235 }
1236
1237 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1238 IdLoc, Id)) {
1239 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1240 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1241 return QualType();
1242 }
1243
1244 // Build the elaborated-type-specifier type.
1246 return SemaRef.Context.getElaboratedType(Keyword,
1247 QualifierLoc.getNestedNameSpecifier(),
1248 T);
1249 }
1250
1251 /// Build a new pack expansion type.
1252 ///
1253 /// By default, builds a new PackExpansionType type from the given pattern.
1254 /// Subclasses may override this routine to provide different behavior.
1256 SourceLocation EllipsisLoc,
1257 std::optional<unsigned> NumExpansions) {
1258 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1259 NumExpansions);
1260 }
1261
1262 /// Build a new atomic type given its value type.
1263 ///
1264 /// By default, performs semantic analysis when building the atomic type.
1265 /// Subclasses may override this routine to provide different behavior.
1267
1268 /// Build a new pipe type given its value type.
1270 bool isReadPipe);
1271
1272 /// Build a bit-precise int given its value type.
1273 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1274 SourceLocation Loc);
1275
1276 /// Build a dependent bit-precise int given its value type.
1277 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1278 SourceLocation Loc);
1279
1280 /// Build a new template name given a nested name specifier, a flag
1281 /// indicating whether the "template" keyword was provided, and the template
1282 /// that the template name refers to.
1283 ///
1284 /// By default, builds the new template name directly. Subclasses may override
1285 /// this routine to provide different behavior.
1287 bool TemplateKW,
1288 TemplateDecl *Template);
1289
1290 /// Build a new template name given a nested name specifier and the
1291 /// name that is referred to as a template.
1292 ///
1293 /// By default, performs semantic analysis to determine whether the name can
1294 /// be resolved to a specific template, then builds the appropriate kind of
1295 /// template name. Subclasses may override this routine to provide different
1296 /// behavior.
1298 SourceLocation TemplateKWLoc,
1299 const IdentifierInfo &Name,
1300 SourceLocation NameLoc, QualType ObjectType,
1301 NamedDecl *FirstQualifierInScope,
1302 bool AllowInjectedClassName);
1303
1304 /// Build a new template name given a nested name specifier and the
1305 /// overloaded operator 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 OverloadedOperatorKind Operator,
1314 SourceLocation NameLoc, QualType ObjectType,
1315 bool AllowInjectedClassName);
1316
1317 /// Build a new template name given a template template parameter pack
1318 /// and the
1319 ///
1320 /// By default, performs semantic analysis to determine whether the name can
1321 /// be resolved to a specific template, then builds the appropriate kind of
1322 /// template name. Subclasses may override this routine to provide different
1323 /// behavior.
1325 Decl *AssociatedDecl, unsigned Index,
1326 bool Final) {
1328 ArgPack, AssociatedDecl, Index, Final);
1329 }
1330
1331 /// Build a new compound statement.
1332 ///
1333 /// By default, performs semantic analysis to build the new statement.
1334 /// Subclasses may override this routine to provide different behavior.
1336 MultiStmtArg Statements,
1337 SourceLocation RBraceLoc,
1338 bool IsStmtExpr) {
1339 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1340 IsStmtExpr);
1341 }
1342
1343 /// Build a new case statement.
1344 ///
1345 /// By default, performs semantic analysis to build the new statement.
1346 /// Subclasses may override this routine to provide different behavior.
1348 Expr *LHS,
1349 SourceLocation EllipsisLoc,
1350 Expr *RHS,
1351 SourceLocation ColonLoc) {
1352 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1353 ColonLoc);
1354 }
1355
1356 /// Attach the body to a new case statement.
1357 ///
1358 /// By default, performs semantic analysis to build the new statement.
1359 /// Subclasses may override this routine to provide different behavior.
1361 getSema().ActOnCaseStmtBody(S, Body);
1362 return S;
1363 }
1364
1365 /// Build a new default statement.
1366 ///
1367 /// By default, performs semantic analysis to build the new statement.
1368 /// Subclasses may override this routine to provide different behavior.
1370 SourceLocation ColonLoc,
1371 Stmt *SubStmt) {
1372 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1373 /*CurScope=*/nullptr);
1374 }
1375
1376 /// Build a new label statement.
1377 ///
1378 /// By default, performs semantic analysis to build the new statement.
1379 /// Subclasses may override this routine to provide different behavior.
1381 SourceLocation ColonLoc, Stmt *SubStmt) {
1382 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1383 }
1384
1385 /// Build a new attributed statement.
1386 ///
1387 /// By default, performs semantic analysis to build the new statement.
1388 /// Subclasses may override this routine to provide different behavior.
1391 Stmt *SubStmt) {
1393 return StmtError();
1394 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1395 }
1396
1397 /// Build a new "if" statement.
1398 ///
1399 /// By default, performs semantic analysis to build the new statement.
1400 /// Subclasses may override this routine to provide different behavior.
1402 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1403 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1404 SourceLocation ElseLoc, Stmt *Else) {
1405 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1406 Then, ElseLoc, Else);
1407 }
1408
1409 /// Start building a new switch statement.
1410 ///
1411 /// By default, performs semantic analysis to build the new statement.
1412 /// Subclasses may override this routine to provide different behavior.
1414 SourceLocation LParenLoc, Stmt *Init,
1416 SourceLocation RParenLoc) {
1417 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1418 RParenLoc);
1419 }
1420
1421 /// Attach the body to the switch statement.
1422 ///
1423 /// By default, performs semantic analysis to build the new statement.
1424 /// Subclasses may override this routine to provide different behavior.
1426 Stmt *Switch, Stmt *Body) {
1427 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1428 }
1429
1430 /// Build a new while statement.
1431 ///
1432 /// By default, performs semantic analysis to build the new statement.
1433 /// Subclasses may override this routine to provide different behavior.
1436 SourceLocation RParenLoc, Stmt *Body) {
1437 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1438 }
1439
1440 /// Build a new do-while statement.
1441 ///
1442 /// By default, performs semantic analysis to build the new statement.
1443 /// Subclasses may override this routine to provide different behavior.
1445 SourceLocation WhileLoc, SourceLocation LParenLoc,
1446 Expr *Cond, SourceLocation RParenLoc) {
1447 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1448 Cond, RParenLoc);
1449 }
1450
1451 /// Build a new for statement.
1452 ///
1453 /// By default, performs semantic analysis to build the new statement.
1454 /// Subclasses may override this routine to provide different behavior.
1457 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1458 Stmt *Body) {
1459 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1460 Inc, RParenLoc, Body);
1461 }
1462
1463 /// Build a new goto statement.
1464 ///
1465 /// By default, performs semantic analysis to build the new statement.
1466 /// Subclasses may override this routine to provide different behavior.
1468 LabelDecl *Label) {
1469 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1470 }
1471
1472 /// Build a new indirect goto statement.
1473 ///
1474 /// By default, performs semantic analysis to build the new statement.
1475 /// Subclasses may override this routine to provide different behavior.
1477 SourceLocation StarLoc,
1478 Expr *Target) {
1479 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1480 }
1481
1482 /// Build a new return statement.
1483 ///
1484 /// By default, performs semantic analysis to build the new statement.
1485 /// Subclasses may override this routine to provide different behavior.
1487 return getSema().BuildReturnStmt(ReturnLoc, Result);
1488 }
1489
1490 /// Build a new declaration statement.
1491 ///
1492 /// By default, performs semantic analysis to build the new statement.
1493 /// Subclasses may override this routine to provide different behavior.
1495 SourceLocation StartLoc, SourceLocation EndLoc) {
1497 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1498 }
1499
1500 /// Build a new inline asm statement.
1501 ///
1502 /// By default, performs semantic analysis to build the new statement.
1503 /// Subclasses may override this routine to provide different behavior.
1505 bool IsVolatile, unsigned NumOutputs,
1506 unsigned NumInputs, IdentifierInfo **Names,
1507 MultiExprArg Constraints, MultiExprArg Exprs,
1508 Expr *AsmString, MultiExprArg Clobbers,
1509 unsigned NumLabels,
1510 SourceLocation RParenLoc) {
1511 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1512 NumInputs, Names, Constraints, Exprs,
1513 AsmString, Clobbers, NumLabels, RParenLoc);
1514 }
1515
1516 /// Build a new MS style inline asm statement.
1517 ///
1518 /// By default, performs semantic analysis to build the new statement.
1519 /// Subclasses may override this routine to provide different behavior.
1521 ArrayRef<Token> AsmToks,
1522 StringRef AsmString,
1523 unsigned NumOutputs, unsigned NumInputs,
1524 ArrayRef<StringRef> Constraints,
1525 ArrayRef<StringRef> Clobbers,
1526 ArrayRef<Expr*> Exprs,
1527 SourceLocation EndLoc) {
1528 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1529 NumOutputs, NumInputs,
1530 Constraints, Clobbers, Exprs, EndLoc);
1531 }
1532
1533 /// Build a new co_return statement.
1534 ///
1535 /// By default, performs semantic analysis to build the new statement.
1536 /// Subclasses may override this routine to provide different behavior.
1538 bool IsImplicit) {
1539 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1540 }
1541
1542 /// Build a new co_await expression.
1543 ///
1544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
1547 UnresolvedLookupExpr *OpCoawaitLookup,
1548 bool IsImplicit) {
1549 // This function rebuilds a coawait-expr given its operator.
1550 // For an explicit coawait-expr, the rebuild involves the full set
1551 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1552 // including calling await_transform().
1553 // For an implicit coawait-expr, we need to rebuild the "operator
1554 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1555 // This mirrors how the implicit CoawaitExpr is originally created
1556 // in Sema::ActOnCoroutineBodyStart().
1557 if (IsImplicit) {
1559 CoawaitLoc, Operand, OpCoawaitLookup);
1560 if (Suspend.isInvalid())
1561 return ExprError();
1562 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1563 Suspend.get(), true);
1564 }
1565
1566 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1567 OpCoawaitLookup);
1568 }
1569
1570 /// Build a new co_await expression.
1571 ///
1572 /// By default, performs semantic analysis to build the new expression.
1573 /// Subclasses may override this routine to provide different behavior.
1575 Expr *Result,
1576 UnresolvedLookupExpr *Lookup) {
1577 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1578 }
1579
1580 /// Build a new co_yield expression.
1581 ///
1582 /// By default, performs semantic analysis to build the new expression.
1583 /// Subclasses may override this routine to provide different behavior.
1585 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1586 }
1587
1589 return getSema().BuildCoroutineBodyStmt(Args);
1590 }
1591
1592 /// Build a new Objective-C \@try statement.
1593 ///
1594 /// By default, performs semantic analysis to build the new statement.
1595 /// Subclasses may override this routine to provide different behavior.
1597 Stmt *TryBody,
1598 MultiStmtArg CatchStmts,
1599 Stmt *Finally) {
1600 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1601 Finally);
1602 }
1603
1604 /// Rebuild an Objective-C exception declaration.
1605 ///
1606 /// By default, performs semantic analysis to build the new declaration.
1607 /// Subclasses may override this routine to provide different behavior.
1609 TypeSourceInfo *TInfo, QualType T) {
1610 return getSema().BuildObjCExceptionDecl(TInfo, T,
1611 ExceptionDecl->getInnerLocStart(),
1612 ExceptionDecl->getLocation(),
1613 ExceptionDecl->getIdentifier());
1614 }
1615
1616 /// Build a new Objective-C \@catch statement.
1617 ///
1618 /// By default, performs semantic analysis to build the new statement.
1619 /// Subclasses may override this routine to provide different behavior.
1621 SourceLocation RParenLoc,
1622 VarDecl *Var,
1623 Stmt *Body) {
1624 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
1625 Var, Body);
1626 }
1627
1628 /// Build a new Objective-C \@finally statement.
1629 ///
1630 /// By default, performs semantic analysis to build the new statement.
1631 /// Subclasses may override this routine to provide different behavior.
1633 Stmt *Body) {
1634 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
1635 }
1636
1637 /// Build a new Objective-C \@throw statement.
1638 ///
1639 /// By default, performs semantic analysis to build the new statement.
1640 /// Subclasses may override this routine to provide different behavior.
1642 Expr *Operand) {
1643 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
1644 }
1645
1646 /// Build a new OpenMP Canonical loop.
1647 ///
1648 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1649 /// OMPCanonicalLoop.
1651 return getSema().ActOnOpenMPCanonicalLoop(LoopStmt);
1652 }
1653
1654 /// Build a new OpenMP executable directive.
1655 ///
1656 /// By default, performs semantic analysis to build the new statement.
1657 /// Subclasses may override this routine to provide different behavior.
1660 OpenMPDirectiveKind CancelRegion, ArrayRef<OMPClause *> Clauses,
1661 Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc,
1662 OpenMPDirectiveKind PrevMappedDirective = OMPD_unknown) {
1663
1665 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc,
1666 PrevMappedDirective);
1667 }
1668
1669 /// Build a new OpenMP 'if' clause.
1670 ///
1671 /// By default, performs semantic analysis to build the new OpenMP clause.
1672 /// Subclasses may override this routine to provide different behavior.
1674 Expr *Condition, SourceLocation StartLoc,
1675 SourceLocation LParenLoc,
1676 SourceLocation NameModifierLoc,
1677 SourceLocation ColonLoc,
1678 SourceLocation EndLoc) {
1679 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1680 LParenLoc, NameModifierLoc, ColonLoc,
1681 EndLoc);
1682 }
1683
1684 /// Build a new OpenMP 'final' clause.
1685 ///
1686 /// By default, performs semantic analysis to build the new OpenMP clause.
1687 /// Subclasses may override this routine to provide different behavior.
1689 SourceLocation LParenLoc,
1690 SourceLocation EndLoc) {
1691 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1692 EndLoc);
1693 }
1694
1695 /// Build a new OpenMP 'num_threads' clause.
1696 ///
1697 /// By default, performs semantic analysis to build the new OpenMP clause.
1698 /// Subclasses may override this routine to provide different behavior.
1700 SourceLocation StartLoc,
1701 SourceLocation LParenLoc,
1702 SourceLocation EndLoc) {
1703 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1704 LParenLoc, EndLoc);
1705 }
1706
1707 /// Build a new OpenMP 'safelen' 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 LParenLoc,
1713 SourceLocation EndLoc) {
1714 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1715 }
1716
1717 /// Build a new OpenMP 'simdlen' clause.
1718 ///
1719 /// By default, performs semantic analysis to build the new OpenMP clause.
1720 /// Subclasses may override this routine to provide different behavior.
1722 SourceLocation LParenLoc,
1723 SourceLocation EndLoc) {
1724 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1725 }
1726
1728 SourceLocation StartLoc,
1729 SourceLocation LParenLoc,
1730 SourceLocation EndLoc) {
1731 return getSema().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc, EndLoc);
1732 }
1733
1734 /// Build a new OpenMP 'full' clause.
1736 SourceLocation EndLoc) {
1737 return getSema().ActOnOpenMPFullClause(StartLoc, EndLoc);
1738 }
1739
1740 /// Build a new OpenMP 'partial' clause.
1742 SourceLocation LParenLoc,
1743 SourceLocation EndLoc) {
1744 return getSema().ActOnOpenMPPartialClause(Factor, StartLoc, LParenLoc,
1745 EndLoc);
1746 }
1747
1748 /// Build a new OpenMP 'allocator' clause.
1749 ///
1750 /// By default, performs semantic analysis to build the new OpenMP clause.
1751 /// Subclasses may override this routine to provide different behavior.
1753 SourceLocation LParenLoc,
1754 SourceLocation EndLoc) {
1755 return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc);
1756 }
1757
1758 /// Build a new OpenMP 'collapse' clause.
1759 ///
1760 /// By default, performs semantic analysis to build the new OpenMP clause.
1761 /// Subclasses may override this routine to provide different behavior.
1763 SourceLocation LParenLoc,
1764 SourceLocation EndLoc) {
1765 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1766 EndLoc);
1767 }
1768
1769 /// Build a new OpenMP 'default' clause.
1770 ///
1771 /// By default, performs semantic analysis to build the new OpenMP clause.
1772 /// Subclasses may override this routine to provide different behavior.
1774 SourceLocation StartLoc,
1775 SourceLocation LParenLoc,
1776 SourceLocation EndLoc) {
1777 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1778 StartLoc, LParenLoc, EndLoc);
1779 }
1780
1781 /// Build a new OpenMP 'proc_bind' clause.
1782 ///
1783 /// By default, performs semantic analysis to build the new OpenMP clause.
1784 /// Subclasses may override this routine to provide different behavior.
1786 SourceLocation KindKwLoc,
1787 SourceLocation StartLoc,
1788 SourceLocation LParenLoc,
1789 SourceLocation EndLoc) {
1790 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1791 StartLoc, LParenLoc, EndLoc);
1792 }
1793
1794 /// Build a new OpenMP 'schedule' clause.
1795 ///
1796 /// By default, performs semantic analysis to build the new OpenMP clause.
1797 /// Subclasses may override this routine to provide different behavior.
1800 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1801 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1802 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1804 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1805 CommaLoc, EndLoc);
1806 }
1807
1808 /// Build a new OpenMP 'ordered' clause.
1809 ///
1810 /// By default, performs semantic analysis to build the new OpenMP clause.
1811 /// Subclasses may override this routine to provide different behavior.
1813 SourceLocation EndLoc,
1814 SourceLocation LParenLoc, Expr *Num) {
1815 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1816 }
1817
1818 /// Build a new OpenMP 'private' clause.
1819 ///
1820 /// By default, performs semantic analysis to build the new OpenMP clause.
1821 /// Subclasses may override this routine to provide different behavior.
1823 SourceLocation StartLoc,
1824 SourceLocation LParenLoc,
1825 SourceLocation EndLoc) {
1826 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1827 EndLoc);
1828 }
1829
1830 /// Build a new OpenMP 'firstprivate' clause.
1831 ///
1832 /// By default, performs semantic analysis to build the new OpenMP clause.
1833 /// Subclasses may override this routine to provide different behavior.
1835 SourceLocation StartLoc,
1836 SourceLocation LParenLoc,
1837 SourceLocation EndLoc) {
1838 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1839 EndLoc);
1840 }
1841
1842 /// Build a new OpenMP 'lastprivate' clause.
1843 ///
1844 /// By default, performs semantic analysis to build the new OpenMP clause.
1845 /// Subclasses may override this routine to provide different behavior.
1848 SourceLocation LPKindLoc,
1849 SourceLocation ColonLoc,
1850 SourceLocation StartLoc,
1851 SourceLocation LParenLoc,
1852 SourceLocation EndLoc) {
1854 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1855 }
1856
1857 /// Build a new OpenMP 'shared' clause.
1858 ///
1859 /// By default, performs semantic analysis to build the new OpenMP clause.
1860 /// Subclasses may override this routine to provide different behavior.
1862 SourceLocation StartLoc,
1863 SourceLocation LParenLoc,
1864 SourceLocation EndLoc) {
1865 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1866 EndLoc);
1867 }
1868
1869 /// Build a new OpenMP 'reduction' clause.
1870 ///
1871 /// By default, performs semantic analysis to build the new statement.
1872 /// Subclasses may override this routine to provide different behavior.
1875 SourceLocation StartLoc, SourceLocation LParenLoc,
1876 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1877 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1878 const DeclarationNameInfo &ReductionId,
1879 ArrayRef<Expr *> UnresolvedReductions) {
1881 VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1882 ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1883 }
1884
1885 /// Build a new OpenMP 'task_reduction' clause.
1886 ///
1887 /// By default, performs semantic analysis to build the new statement.
1888 /// Subclasses may override this routine to provide different behavior.
1890 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1891 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1892 CXXScopeSpec &ReductionIdScopeSpec,
1893 const DeclarationNameInfo &ReductionId,
1894 ArrayRef<Expr *> UnresolvedReductions) {
1896 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1897 ReductionId, UnresolvedReductions);
1898 }
1899
1900 /// Build a new OpenMP 'in_reduction' clause.
1901 ///
1902 /// By default, performs semantic analysis to build the new statement.
1903 /// Subclasses may override this routine to provide different behavior.
1904 OMPClause *
1906 SourceLocation LParenLoc, SourceLocation ColonLoc,
1907 SourceLocation EndLoc,
1908 CXXScopeSpec &ReductionIdScopeSpec,
1909 const DeclarationNameInfo &ReductionId,
1910 ArrayRef<Expr *> UnresolvedReductions) {
1912 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1913 ReductionId, UnresolvedReductions);
1914 }
1915
1916 /// Build a new OpenMP 'linear' clause.
1917 ///
1918 /// By default, performs semantic analysis to build the new OpenMP clause.
1919 /// Subclasses may override this routine to provide different behavior.
1921 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1922 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1923 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1924 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1925 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
1926 Modifier, ModifierLoc, ColonLoc,
1927 StepModifierLoc, EndLoc);
1928 }
1929
1930 /// Build a new OpenMP 'aligned' clause.
1931 ///
1932 /// By default, performs semantic analysis to build the new OpenMP clause.
1933 /// Subclasses may override this routine to provide different behavior.
1935 SourceLocation StartLoc,
1936 SourceLocation LParenLoc,
1937 SourceLocation ColonLoc,
1938 SourceLocation EndLoc) {
1939 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1940 LParenLoc, ColonLoc, EndLoc);
1941 }
1942
1943 /// Build a new OpenMP 'copyin' clause.
1944 ///
1945 /// By default, performs semantic analysis to build the new OpenMP clause.
1946 /// Subclasses may override this routine to provide different behavior.
1948 SourceLocation StartLoc,
1949 SourceLocation LParenLoc,
1950 SourceLocation EndLoc) {
1951 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1952 EndLoc);
1953 }
1954
1955 /// Build a new OpenMP 'copyprivate' clause.
1956 ///
1957 /// By default, performs semantic analysis to build the new OpenMP clause.
1958 /// Subclasses may override this routine to provide different behavior.
1960 SourceLocation StartLoc,
1961 SourceLocation LParenLoc,
1962 SourceLocation EndLoc) {
1963 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1964 EndLoc);
1965 }
1966
1967 /// Build a new OpenMP 'flush' pseudo clause.
1968 ///
1969 /// By default, performs semantic analysis to build the new OpenMP clause.
1970 /// Subclasses may override this routine to provide different behavior.
1972 SourceLocation StartLoc,
1973 SourceLocation LParenLoc,
1974 SourceLocation EndLoc) {
1975 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1976 EndLoc);
1977 }
1978
1979 /// Build a new OpenMP 'depobj' pseudo clause.
1980 ///
1981 /// By default, performs semantic analysis to build the new OpenMP clause.
1982 /// Subclasses may override this routine to provide different behavior.
1984 SourceLocation LParenLoc,
1985 SourceLocation EndLoc) {
1986 return getSema().ActOnOpenMPDepobjClause(Depobj, StartLoc, LParenLoc,
1987 EndLoc);
1988 }
1989
1990 /// Build a new OpenMP 'depend' pseudo clause.
1991 ///
1992 /// By default, performs semantic analysis to build the new OpenMP clause.
1993 /// Subclasses may override this routine to provide different behavior.
1995 Expr *DepModifier, ArrayRef<Expr *> VarList,
1996 SourceLocation StartLoc,
1997 SourceLocation LParenLoc,
1998 SourceLocation EndLoc) {
1999 return getSema().ActOnOpenMPDependClause(Data, DepModifier, VarList,
2000 StartLoc, LParenLoc, EndLoc);
2001 }
2002
2003 /// Build a new OpenMP 'device' clause.
2004 ///
2005 /// By default, performs semantic analysis to build the new statement.
2006 /// Subclasses may override this routine to provide different behavior.
2008 Expr *Device, SourceLocation StartLoc,
2009 SourceLocation LParenLoc,
2010 SourceLocation ModifierLoc,
2011 SourceLocation EndLoc) {
2012 return getSema().ActOnOpenMPDeviceClause(Modifier, Device, StartLoc,
2013 LParenLoc, ModifierLoc, EndLoc);
2014 }
2015
2016 /// Build a new OpenMP 'map' clause.
2017 ///
2018 /// By default, performs semantic analysis to build the new OpenMP clause.
2019 /// Subclasses may override this routine to provide different behavior.
2021 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2022 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2023 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2024 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2025 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2026 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2028 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2029 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2030 ColonLoc, VarList, Locs,
2031 /*NoDiagnose=*/false, UnresolvedMappers);
2032 }
2033
2034 /// Build a new OpenMP 'allocate' clause.
2035 ///
2036 /// By default, performs semantic analysis to build the new OpenMP clause.
2037 /// Subclasses may override this routine to provide different behavior.
2039 SourceLocation StartLoc,
2040 SourceLocation LParenLoc,
2041 SourceLocation ColonLoc,
2042 SourceLocation EndLoc) {
2043 return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc,
2044 LParenLoc, ColonLoc, EndLoc);
2045 }
2046
2047 /// Build a new OpenMP 'num_teams' clause.
2048 ///
2049 /// By default, performs semantic analysis to build the new statement.
2050 /// Subclasses may override this routine to provide different behavior.
2052 SourceLocation LParenLoc,
2053 SourceLocation EndLoc) {
2054 return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc,
2055 EndLoc);
2056 }
2057
2058 /// Build a new OpenMP 'thread_limit' clause.
2059 ///
2060 /// By default, performs semantic analysis to build the new statement.
2061 /// Subclasses may override this routine to provide different behavior.
2063 SourceLocation StartLoc,
2064 SourceLocation LParenLoc,
2065 SourceLocation EndLoc) {
2066 return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc,
2067 LParenLoc, EndLoc);
2068 }
2069
2070 /// Build a new OpenMP 'priority' clause.
2071 ///
2072 /// By default, performs semantic analysis to build the new statement.
2073 /// Subclasses may override this routine to provide different behavior.
2075 SourceLocation LParenLoc,
2076 SourceLocation EndLoc) {
2077 return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc,
2078 EndLoc);
2079 }
2080
2081 /// Build a new OpenMP 'grainsize' clause.
2082 ///
2083 /// By default, performs semantic analysis to build the new statement.
2084 /// Subclasses may override this routine to provide different behavior.
2086 Expr *Device, SourceLocation StartLoc,
2087 SourceLocation LParenLoc,
2088 SourceLocation ModifierLoc,
2089 SourceLocation EndLoc) {
2090 return getSema().ActOnOpenMPGrainsizeClause(Modifier, Device, StartLoc,
2091 LParenLoc, ModifierLoc, EndLoc);
2092 }
2093
2094 /// Build a new OpenMP 'num_tasks' clause.
2095 ///
2096 /// By default, performs semantic analysis to build the new statement.
2097 /// Subclasses may override this routine to provide different behavior.
2099 Expr *NumTasks, SourceLocation StartLoc,
2100 SourceLocation LParenLoc,
2101 SourceLocation ModifierLoc,
2102 SourceLocation EndLoc) {
2103 return getSema().ActOnOpenMPNumTasksClause(Modifier, NumTasks, StartLoc,
2104 LParenLoc, ModifierLoc, EndLoc);
2105 }
2106
2107 /// Build a new OpenMP 'hint' clause.
2108 ///
2109 /// By default, performs semantic analysis to build the new statement.
2110 /// Subclasses may override this routine to provide different behavior.
2112 SourceLocation LParenLoc,
2113 SourceLocation EndLoc) {
2114 return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc);
2115 }
2116
2117 /// Build a new OpenMP 'detach' clause.
2118 ///
2119 /// By default, performs semantic analysis to build the new statement.
2120 /// Subclasses may override this routine to provide different behavior.
2122 SourceLocation LParenLoc,
2123 SourceLocation EndLoc) {
2124 return getSema().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc);
2125 }
2126
2127 /// Build a new OpenMP 'dist_schedule' clause.
2128 ///
2129 /// By default, performs semantic analysis to build the new OpenMP clause.
2130 /// Subclasses may override this routine to provide different behavior.
2131 OMPClause *
2133 Expr *ChunkSize, SourceLocation StartLoc,
2134 SourceLocation LParenLoc, SourceLocation KindLoc,
2135 SourceLocation CommaLoc, SourceLocation EndLoc) {
2137 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2138 }
2139
2140 /// Build a new OpenMP 'to' clause.
2141 ///
2142 /// By default, performs semantic analysis to build the new statement.
2143 /// Subclasses may override this routine to provide different behavior.
2144 OMPClause *
2146 ArrayRef<SourceLocation> MotionModifiersLoc,
2147 CXXScopeSpec &MapperIdScopeSpec,
2148 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2149 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2150 ArrayRef<Expr *> UnresolvedMappers) {
2151 return getSema().ActOnOpenMPToClause(MotionModifiers, MotionModifiersLoc,
2152 MapperIdScopeSpec, MapperId, ColonLoc,
2153 VarList, Locs, UnresolvedMappers);
2154 }
2155
2156 /// Build a new OpenMP 'from' clause.
2157 ///
2158 /// By default, performs semantic analysis to build the new statement.
2159 /// Subclasses may override this routine to provide different behavior.
2160 OMPClause *
2162 ArrayRef<SourceLocation> MotionModifiersLoc,
2163 CXXScopeSpec &MapperIdScopeSpec,
2164 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2165 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2166 ArrayRef<Expr *> UnresolvedMappers) {
2168 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2169 ColonLoc, VarList, Locs, UnresolvedMappers);
2170 }
2171
2172 /// Build a new OpenMP 'use_device_ptr' clause.
2173 ///
2174 /// By default, performs semantic analysis to build the new OpenMP clause.
2175 /// Subclasses may override this routine to provide different behavior.
2177 const OMPVarListLocTy &Locs) {
2178 return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2179 }
2180
2181 /// Build a new OpenMP 'use_device_addr' clause.
2182 ///
2183 /// By default, performs semantic analysis to build the new OpenMP clause.
2184 /// Subclasses may override this routine to provide different behavior.
2186 const OMPVarListLocTy &Locs) {
2187 return getSema().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2188 }
2189
2190 /// Build a new OpenMP 'is_device_ptr' clause.
2191 ///
2192 /// By default, performs semantic analysis to build the new OpenMP clause.
2193 /// Subclasses may override this routine to provide different behavior.
2195 const OMPVarListLocTy &Locs) {
2196 return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2197 }
2198
2199 /// Build a new OpenMP 'has_device_addr' clause.
2200 ///
2201 /// By default, performs semantic analysis to build the new OpenMP clause.
2202 /// Subclasses may override this routine to provide different behavior.
2204 const OMPVarListLocTy &Locs) {
2205 return getSema().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2206 }
2207
2208 /// Build a new OpenMP 'defaultmap' clause.
2209 ///
2210 /// By default, performs semantic analysis to build the new OpenMP clause.
2211 /// Subclasses may override this routine to provide different behavior.
2214 SourceLocation StartLoc,
2215 SourceLocation LParenLoc,
2216 SourceLocation MLoc,
2217 SourceLocation KindLoc,
2218 SourceLocation EndLoc) {
2219 return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc,
2220 MLoc, KindLoc, EndLoc);
2221 }
2222
2223 /// Build a new OpenMP 'nontemporal' clause.
2224 ///
2225 /// By default, performs semantic analysis to build the new OpenMP clause.
2226 /// Subclasses may override this routine to provide different behavior.
2228 SourceLocation StartLoc,
2229 SourceLocation LParenLoc,
2230 SourceLocation EndLoc) {
2231 return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc,
2232 EndLoc);
2233 }
2234
2235 /// Build a new OpenMP 'inclusive' clause.
2236 ///
2237 /// By default, performs semantic analysis to build the new OpenMP clause.
2238 /// Subclasses may override this routine to provide different behavior.
2240 SourceLocation StartLoc,
2241 SourceLocation LParenLoc,
2242 SourceLocation EndLoc) {
2243 return getSema().ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc,
2244 EndLoc);
2245 }
2246
2247 /// Build a new OpenMP 'exclusive' clause.
2248 ///
2249 /// By default, performs semantic analysis to build the new OpenMP clause.
2250 /// Subclasses may override this routine to provide different behavior.
2252 SourceLocation StartLoc,
2253 SourceLocation LParenLoc,
2254 SourceLocation EndLoc) {
2255 return getSema().ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc,
2256 EndLoc);
2257 }
2258
2259 /// Build a new OpenMP 'uses_allocators' clause.
2260 ///
2261 /// By default, performs semantic analysis to build the new OpenMP clause.
2262 /// Subclasses may override this routine to provide different behavior.
2265 SourceLocation LParenLoc, SourceLocation EndLoc) {
2266 return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc, LParenLoc, EndLoc,
2267 Data);
2268 }
2269
2270 /// Build a new OpenMP 'affinity' clause.
2271 ///
2272 /// By default, performs semantic analysis to build the new OpenMP clause.
2273 /// Subclasses may override this routine to provide different behavior.
2275 SourceLocation LParenLoc,
2276 SourceLocation ColonLoc,
2277 SourceLocation EndLoc, Expr *Modifier,
2278 ArrayRef<Expr *> Locators) {
2279 return getSema().ActOnOpenMPAffinityClause(StartLoc, LParenLoc, ColonLoc,
2280 EndLoc, Modifier, Locators);
2281 }
2282
2283 /// Build a new OpenMP 'order' clause.
2284 ///
2285 /// By default, performs semantic analysis to build the new OpenMP clause.
2286 /// Subclasses may override this routine to provide different behavior.
2288 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2289 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2290 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2291 return getSema().ActOnOpenMPOrderClause(Modifier, Kind, StartLoc, LParenLoc,
2292 ModifierKwLoc, KindKwLoc, EndLoc);
2293 }
2294
2295 /// Build a new OpenMP 'init' clause.
2296 ///
2297 /// By default, performs semantic analysis to build the new OpenMP clause.
2298 /// Subclasses may override this routine to provide different behavior.
2300 SourceLocation StartLoc,
2301 SourceLocation LParenLoc,
2302 SourceLocation VarLoc,
2303 SourceLocation EndLoc) {
2304 return getSema().ActOnOpenMPInitClause(InteropVar, InteropInfo, StartLoc,
2305 LParenLoc, VarLoc, EndLoc);
2306 }
2307
2308 /// Build a new OpenMP 'use' clause.
2309 ///
2310 /// By default, performs semantic analysis to build the new OpenMP clause.
2311 /// Subclasses may override this routine to provide different behavior.
2313 SourceLocation LParenLoc,
2314 SourceLocation VarLoc, SourceLocation EndLoc) {
2315 return getSema().ActOnOpenMPUseClause(InteropVar, StartLoc, LParenLoc,
2316 VarLoc, EndLoc);
2317 }
2318
2319 /// Build a new OpenMP 'destroy' clause.
2320 ///
2321 /// By default, performs semantic analysis to build the new OpenMP clause.
2322 /// Subclasses may override this routine to provide different behavior.
2324 SourceLocation LParenLoc,
2325 SourceLocation VarLoc,
2326 SourceLocation EndLoc) {
2327 return getSema().ActOnOpenMPDestroyClause(InteropVar, StartLoc, LParenLoc,
2328 VarLoc, EndLoc);
2329 }
2330
2331 /// Build a new OpenMP 'novariants' clause.
2332 ///
2333 /// By default, performs semantic analysis to build the new OpenMP clause.
2334 /// Subclasses may override this routine to provide different behavior.
2336 SourceLocation StartLoc,
2337 SourceLocation LParenLoc,
2338 SourceLocation EndLoc) {
2339 return getSema().ActOnOpenMPNovariantsClause(Condition, StartLoc, LParenLoc,
2340 EndLoc);
2341 }
2342
2343 /// Build a new OpenMP 'nocontext' clause.
2344 ///
2345 /// By default, performs semantic analysis to build the new OpenMP clause.
2346 /// Subclasses may override this routine to provide different behavior.
2348 SourceLocation LParenLoc,
2349 SourceLocation EndLoc) {
2350 return getSema().ActOnOpenMPNocontextClause(Condition, StartLoc, LParenLoc,
2351 EndLoc);
2352 }
2353
2354 /// Build a new OpenMP 'filter' clause.
2355 ///
2356 /// By default, performs semantic analysis to build the new OpenMP clause.
2357 /// Subclasses may override this routine to provide different behavior.
2359 SourceLocation LParenLoc,
2360 SourceLocation EndLoc) {
2361 return getSema().ActOnOpenMPFilterClause(ThreadID, StartLoc, LParenLoc,
2362 EndLoc);
2363 }
2364
2365 /// Build a new OpenMP 'bind' clause.
2366 ///
2367 /// By default, performs semantic analysis to build the new OpenMP clause.
2368 /// Subclasses may override this routine to provide different behavior.
2370 SourceLocation KindLoc,
2371 SourceLocation StartLoc,
2372 SourceLocation LParenLoc,
2373 SourceLocation EndLoc) {
2374 return getSema().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc, LParenLoc,
2375 EndLoc);
2376 }
2377
2378 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2379 ///
2380 /// By default, performs semantic analysis to build the new OpenMP clause.
2381 /// Subclasses may override this routine to provide different behavior.
2383 SourceLocation LParenLoc,
2384 SourceLocation EndLoc) {
2385 return getSema().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc, LParenLoc,
2386 EndLoc);
2387 }
2388
2389 /// Build a new OpenMP 'ompx_attribute' clause.
2390 ///
2391 /// By default, performs semantic analysis to build the new OpenMP clause.
2392 /// Subclasses may override this routine to provide different behavior.
2394 SourceLocation StartLoc,
2395 SourceLocation LParenLoc,
2396 SourceLocation EndLoc) {
2397 return getSema().ActOnOpenMPXAttributeClause(Attrs, StartLoc, LParenLoc,
2398 EndLoc);
2399 }
2400
2401 /// Build a new OpenMP 'ompx_bare' clause.
2402 ///
2403 /// By default, performs semantic analysis to build the new OpenMP clause.
2404 /// Subclasses may override this routine to provide different behavior.
2406 SourceLocation EndLoc) {
2407 return getSema().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2408 }
2409
2410 /// Build a new OpenMP 'align' clause.
2411 ///
2412 /// By default, performs semantic analysis to build the new OpenMP clause.
2413 /// Subclasses may override this routine to provide different behavior.
2415 SourceLocation LParenLoc,
2416 SourceLocation EndLoc) {
2417 return getSema().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc, EndLoc);
2418 }
2419
2420 /// Build a new OpenMP 'at' 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 StartLoc,
2426 SourceLocation LParenLoc,
2427 SourceLocation EndLoc) {
2428 return getSema().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc, LParenLoc,
2429 EndLoc);
2430 }
2431
2432 /// Build a new OpenMP 'severity' clause.
2433 ///
2434 /// By default, performs semantic analysis to build the new OpenMP clause.
2435 /// Subclasses may override this routine to provide different behavior.
2437 SourceLocation KwLoc,
2438 SourceLocation StartLoc,
2439 SourceLocation LParenLoc,
2440 SourceLocation EndLoc) {
2441 return getSema().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc, LParenLoc,
2442 EndLoc);
2443 }
2444
2445 /// Build a new OpenMP 'message' clause.
2446 ///
2447 /// By default, performs semantic analysis to build the new OpenMP clause.
2448 /// Subclasses may override this routine to provide different behavior.
2450 SourceLocation LParenLoc,
2451 SourceLocation EndLoc) {
2452 return getSema().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc, EndLoc);
2453 }
2454
2455 /// Build a new OpenMP 'doacross' clause.
2456 ///
2457 /// By default, performs semantic analysis to build the new OpenMP clause.
2458 /// Subclasses may override this routine to provide different behavior.
2459 OMPClause *
2461 SourceLocation DepLoc, SourceLocation ColonLoc,
2462 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2463 SourceLocation LParenLoc, SourceLocation EndLoc) {
2465 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2466 }
2467
2468 /// Rebuild the operand to an Objective-C \@synchronized statement.
2469 ///
2470 /// By default, performs semantic analysis to build the new statement.
2471 /// Subclasses may override this routine to provide different behavior.
2473 Expr *object) {
2474 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
2475 }
2476
2477 /// Build a new Objective-C \@synchronized statement.
2478 ///
2479 /// By default, performs semantic analysis to build the new statement.
2480 /// Subclasses may override this routine to provide different behavior.
2482 Expr *Object, Stmt *Body) {
2483 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2484 }
2485
2486 /// Build a new Objective-C \@autoreleasepool statement.
2487 ///
2488 /// By default, performs semantic analysis to build the new statement.
2489 /// Subclasses may override this routine to provide different behavior.
2491 Stmt *Body) {
2492 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2493 }
2494
2495 /// Build a new Objective-C fast enumeration statement.
2496 ///
2497 /// By default, performs semantic analysis to build the new statement.
2498 /// Subclasses may override this routine to provide different behavior.
2500 Stmt *Element,
2501 Expr *Collection,
2502 SourceLocation RParenLoc,
2503 Stmt *Body) {
2504 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
2505 Element,
2506 Collection,
2507 RParenLoc);
2508 if (ForEachStmt.isInvalid())
2509 return StmtError();
2510
2511 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
2512 }
2513
2514 /// Build a new C++ exception declaration.
2515 ///
2516 /// By default, performs semantic analysis to build the new decaration.
2517 /// Subclasses may override this routine to provide different behavior.
2520 SourceLocation StartLoc,
2521 SourceLocation IdLoc,
2522 IdentifierInfo *Id) {
2524 StartLoc, IdLoc, Id);
2525 if (Var)
2526 getSema().CurContext->addDecl(Var);
2527 return Var;
2528 }
2529
2530 /// Build a new C++ catch statement.
2531 ///
2532 /// By default, performs semantic analysis to build the new statement.
2533 /// Subclasses may override this routine to provide different behavior.
2535 VarDecl *ExceptionDecl,
2536 Stmt *Handler) {
2537 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2538 Handler));
2539 }
2540
2541 /// Build a new C++ try statement.
2542 ///
2543 /// By default, performs semantic analysis to build the new statement.
2544 /// Subclasses may override this routine to provide different behavior.
2546 ArrayRef<Stmt *> Handlers) {
2547 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2548 }
2549
2550 /// Build a new C++0x range-based for statement.
2551 ///
2552 /// By default, performs semantic analysis to build the new statement.
2553 /// Subclasses may override this routine to provide different behavior.
2555 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2556 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2557 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2558 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2559 // If we've just learned that the range is actually an Objective-C
2560 // collection, treat this as an Objective-C fast enumeration loop.
2561 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2562 if (RangeStmt->isSingleDecl()) {
2563 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2564 if (RangeVar->isInvalidDecl())
2565 return StmtError();
2566
2567 Expr *RangeExpr = RangeVar->getInit();
2568 if (!RangeExpr->isTypeDependent() &&
2569 RangeExpr->getType()->isObjCObjectPointerType()) {
2570 // FIXME: Support init-statements in Objective-C++20 ranged for
2571 // statement.
2572 if (Init) {
2573 return SemaRef.Diag(Init->getBeginLoc(),
2574 diag::err_objc_for_range_init_stmt)
2575 << Init->getSourceRange();
2576 }
2577 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar,
2578 RangeExpr, RParenLoc);
2579 }
2580 }
2581 }
2582 }
2583
2585 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2586 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2587 }
2588
2589 /// Build a new C++0x range-based for statement.
2590 ///
2591 /// By default, performs semantic analysis to build the new statement.
2592 /// Subclasses may override this routine to provide different behavior.
2594 bool IsIfExists,
2595 NestedNameSpecifierLoc QualifierLoc,
2596 DeclarationNameInfo NameInfo,
2597 Stmt *Nested) {
2598 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2599 QualifierLoc, NameInfo, Nested);
2600 }
2601
2602 /// Attach body to a C++0x range-based for statement.
2603 ///
2604 /// By default, performs semantic analysis to finish the new statement.
2605 /// Subclasses may override this routine to provide different behavior.
2607 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2608 }
2609
2611 Stmt *TryBlock, Stmt *Handler) {
2612 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2613 }
2614
2616 Stmt *Block) {
2617 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2618 }
2619
2621 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2622 }
2623
2625 SourceLocation LParen,
2626 SourceLocation RParen,
2627 TypeSourceInfo *TSI) {
2628 return getSema().BuildSYCLUniqueStableNameExpr(OpLoc, LParen, RParen, TSI);
2629 }
2630
2631 /// Build a new predefined expression.
2632 ///
2633 /// By default, performs semantic analysis to build the new expression.
2634 /// Subclasses may override this routine to provide different behavior.
2636 return getSema().BuildPredefinedExpr(Loc, IK);
2637 }
2638
2639 /// Build a new expression that references a declaration.
2640 ///
2641 /// By default, performs semantic analysis to build the new expression.
2642 /// Subclasses may override this routine to provide different behavior.
2644 LookupResult &R,
2645 bool RequiresADL) {
2646 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2647 }
2648
2649
2650 /// Build a new expression that references a declaration.
2651 ///
2652 /// By default, performs semantic analysis to build the new expression.
2653 /// Subclasses may override this routine to provide different behavior.
2655 ValueDecl *VD,
2656 const DeclarationNameInfo &NameInfo,
2657 NamedDecl *Found,
2658 TemplateArgumentListInfo *TemplateArgs) {
2659 CXXScopeSpec SS;
2660 SS.Adopt(QualifierLoc);
2661 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2662 TemplateArgs);
2663 }
2664
2665 /// Build a new expression in parentheses.
2666 ///
2667 /// By default, performs semantic analysis to build the new expression.
2668 /// Subclasses may override this routine to provide different behavior.
2670 SourceLocation RParen) {
2671 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2672 }
2673
2674 /// Build a new pseudo-destructor expression.
2675 ///
2676 /// By default, performs semantic analysis to build the new expression.
2677 /// Subclasses may override this routine to provide different behavior.
2679 SourceLocation OperatorLoc,
2680 bool isArrow,
2681 CXXScopeSpec &SS,
2682 TypeSourceInfo *ScopeType,
2683 SourceLocation CCLoc,
2684 SourceLocation TildeLoc,
2685 PseudoDestructorTypeStorage Destroyed);
2686
2687 /// Build a new unary operator expression.
2688 ///
2689 /// By default, performs semantic analysis to build the new expression.
2690 /// Subclasses may override this routine to provide different behavior.
2693 Expr *SubExpr) {
2694 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2695 }
2696
2697 /// Build a new builtin offsetof expression.
2698 ///
2699 /// By default, performs semantic analysis to build the new expression.
2700 /// Subclasses may override this routine to provide different behavior.
2704 SourceLocation RParenLoc) {
2705 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2706 RParenLoc);
2707 }
2708
2709 /// Build a new sizeof, alignof or vec_step expression with a
2710 /// type argument.
2711 ///
2712 /// By default, performs semantic analysis to build the new expression.
2713 /// Subclasses may override this routine to provide different behavior.
2715 SourceLocation OpLoc,
2716 UnaryExprOrTypeTrait ExprKind,
2717 SourceRange R) {
2718 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2719 }
2720
2721 /// Build a new sizeof, alignof or vec step expression with an
2722 /// expression argument.
2723 ///
2724 /// By default, performs semantic analysis to build the new expression.
2725 /// Subclasses may override this routine to provide different behavior.
2727 UnaryExprOrTypeTrait ExprKind,
2728 SourceRange R) {
2730 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2731 if (Result.isInvalid())
2732 return ExprError();
2733
2734 return Result;
2735 }
2736
2737 /// Build a new array subscript expression.
2738 ///
2739 /// By default, performs semantic analysis to build the new expression.
2740 /// Subclasses may override this routine to provide different behavior.
2742 SourceLocation LBracketLoc,
2743 Expr *RHS,
2744 SourceLocation RBracketLoc) {
2745 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2746 LBracketLoc, RHS,
2747 RBracketLoc);
2748 }
2749
2750 /// Build a new matrix subscript expression.
2751 ///
2752 /// By default, performs semantic analysis to build the new expression.
2753 /// Subclasses may override this routine to provide different behavior.
2755 Expr *ColumnIdx,
2756 SourceLocation RBracketLoc) {
2757 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2758 RBracketLoc);
2759 }
2760
2761 /// Build a new array section expression.
2762 ///
2763 /// By default, performs semantic analysis to build the new expression.
2764 /// Subclasses may override this routine to provide different behavior.
2766 Expr *LowerBound,
2767 SourceLocation ColonLocFirst,
2768 SourceLocation ColonLocSecond,
2769 Expr *Length, Expr *Stride,
2770 SourceLocation RBracketLoc) {
2771 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
2772 ColonLocFirst, ColonLocSecond,
2773 Length, Stride, RBracketLoc);
2774 }
2775
2776 /// Build a new array shaping expression.
2777 ///
2778 /// By default, performs semantic analysis to build the new expression.
2779 /// Subclasses may override this routine to provide different behavior.
2781 SourceLocation RParenLoc,
2782 ArrayRef<Expr *> Dims,
2783 ArrayRef<SourceRange> BracketsRanges) {
2784 return getSema().ActOnOMPArrayShapingExpr(Base, LParenLoc, RParenLoc, Dims,
2785 BracketsRanges);
2786 }
2787
2788 /// Build a new iterator expression.
2789 ///
2790 /// By default, performs semantic analysis to build the new expression.
2791 /// Subclasses may override this routine to provide different behavior.
2793 SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc,
2795 return getSema().ActOnOMPIteratorExpr(/*Scope=*/nullptr, IteratorKwLoc,
2796 LLoc, RLoc, Data);
2797 }
2798
2799 /// Build a new call expression.
2800 ///
2801 /// By default, performs semantic analysis to build the new expression.
2802 /// Subclasses may override this routine to provide different behavior.
2804 MultiExprArg Args,
2805 SourceLocation RParenLoc,
2806 Expr *ExecConfig = nullptr) {
2807 return getSema().ActOnCallExpr(
2808 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2809 }
2810
2812 MultiExprArg Args,
2813 SourceLocation RParenLoc) {
2815 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2816 }
2817
2818 /// Build a new member access expression.
2819 ///
2820 /// By default, performs semantic analysis to build the new expression.
2821 /// Subclasses may override this routine to provide different behavior.
2823 bool isArrow,
2824 NestedNameSpecifierLoc QualifierLoc,
2825 SourceLocation TemplateKWLoc,
2826 const DeclarationNameInfo &MemberNameInfo,
2828 NamedDecl *FoundDecl,
2829 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2830 NamedDecl *FirstQualifierInScope) {
2832 isArrow);
2833 if (!Member->getDeclName()) {
2834 // We have a reference to an unnamed field. This is always the
2835 // base of an anonymous struct/union member access, i.e. the
2836 // field is always of record type.
2837 assert(Member->getType()->isRecordType() &&
2838 "unnamed member not of record type?");
2839
2840 BaseResult =
2842 QualifierLoc.getNestedNameSpecifier(),
2843 FoundDecl, Member);
2844 if (BaseResult.isInvalid())
2845 return ExprError();
2846 Base = BaseResult.get();
2847
2848 CXXScopeSpec EmptySS;
2850 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2851 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo);
2852 }
2853
2854 CXXScopeSpec SS;
2855 SS.Adopt(QualifierLoc);
2856
2857 Base = BaseResult.get();
2858 QualType BaseType = Base->getType();
2859
2860 if (isArrow && !BaseType->isPointerType())
2861 return ExprError();
2862
2863 // FIXME: this involves duplicating earlier analysis in a lot of
2864 // cases; we should avoid this when possible.
2865 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2866 R.addDecl(FoundDecl);
2867 R.resolveKind();
2868
2869 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2870 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2871 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2872 ->getType()
2873 ->getPointeeType()
2874 ->getAsCXXRecordDecl()) {
2875 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2876 // In unevaluated contexts, an expression supposed to be a member access
2877 // might reference a member in an unrelated class.
2878 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2879 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2880 VK_LValue, Member->getLocation());
2881 }
2882 }
2883
2884 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2885 SS, TemplateKWLoc,
2886 FirstQualifierInScope,
2887 R, ExplicitTemplateArgs,
2888 /*S*/nullptr);
2889 }
2890
2891 /// Build a new binary operator expression.
2892 ///
2893 /// By default, performs semantic analysis to build the new expression.
2894 /// Subclasses may override this routine to provide different behavior.
2897 Expr *LHS, Expr *RHS) {
2898 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2899 }
2900
2901 /// Build a new rewritten operator expression.
2902 ///
2903 /// By default, performs semantic analysis to build the new expression.
2904 /// Subclasses may override this routine to provide different behavior.
2906 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2907 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2908 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2909 RHS, /*RequiresADL*/false);
2910 }
2911
2912 /// Build a new conditional operator expression.
2913 ///
2914 /// By default, performs semantic analysis to build the new expression.
2915 /// Subclasses may override this routine to provide different behavior.
2917 SourceLocation QuestionLoc,
2918 Expr *LHS,
2919 SourceLocation ColonLoc,
2920 Expr *RHS) {
2921 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2922 LHS, RHS);
2923 }
2924
2925 /// Build a new C-style cast expression.
2926 ///
2927 /// By default, performs semantic analysis to build the new expression.
2928 /// Subclasses may override this routine to provide different behavior.
2930 TypeSourceInfo *TInfo,
2931 SourceLocation RParenLoc,
2932 Expr *SubExpr) {
2933 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
2934 SubExpr);
2935 }
2936
2937 /// Build a new compound literal expression.
2938 ///
2939 /// By default, performs semantic analysis to build the new expression.
2940 /// Subclasses may override this routine to provide different behavior.
2942 TypeSourceInfo *TInfo,
2943 SourceLocation RParenLoc,
2944 Expr *Init) {
2945 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
2946 Init);
2947 }
2948
2949 /// Build a new extended vector element access expression.
2950 ///
2951 /// By default, performs semantic analysis to build the new expression.
2952 /// Subclasses may override this routine to provide different behavior.
2954 bool IsArrow,
2955 SourceLocation AccessorLoc,
2956 IdentifierInfo &Accessor) {
2957
2958 CXXScopeSpec SS;
2959 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
2961 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
2962 /*FirstQualifierInScope*/ nullptr, NameInfo,
2963 /* TemplateArgs */ nullptr,
2964 /*S*/ nullptr);
2965 }
2966
2967 /// Build a new initializer list expression.
2968 ///
2969 /// By default, performs semantic analysis to build the new expression.
2970 /// Subclasses may override this routine to provide different behavior.
2972 MultiExprArg Inits,
2973 SourceLocation RBraceLoc) {
2974 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
2975 }
2976
2977 /// Build a new designated initializer expression.
2978 ///
2979 /// By default, performs semantic analysis to build the new expression.
2980 /// Subclasses may override this routine to provide different behavior.
2982 MultiExprArg ArrayExprs,
2983 SourceLocation EqualOrColonLoc,
2984 bool GNUSyntax,
2985 Expr *Init) {
2987 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
2988 Init);
2989 if (Result.isInvalid())
2990 return ExprError();
2991
2992 return Result;
2993 }
2994
2995 /// Build a new value-initialized expression.
2996 ///
2997 /// By default, builds the implicit value initialization without performing
2998 /// any semantic analysis. Subclasses may override this routine to provide
2999 /// different behavior.
3001 return new (SemaRef.Context) ImplicitValueInitExpr(T);
3002 }
3003
3004 /// Build a new \c va_arg expression.
3005 ///
3006 /// By default, performs semantic analysis to build the new expression.
3007 /// Subclasses may override this routine to provide different behavior.
3009 Expr *SubExpr, TypeSourceInfo *TInfo,
3010 SourceLocation RParenLoc) {
3011 return getSema().BuildVAArgExpr(BuiltinLoc,
3012 SubExpr, TInfo,
3013 RParenLoc);
3014 }
3015
3016 /// Build a new expression list in parentheses.
3017 ///
3018 /// By default, performs semantic analysis to build the new expression.
3019 /// Subclasses may override this routine to provide different behavior.
3021 MultiExprArg SubExprs,
3022 SourceLocation RParenLoc) {
3023 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3024 }
3025
3026 /// Build a new address-of-label expression.
3027 ///
3028 /// By default, performs semantic analysis, using the name of the label
3029 /// rather than attempting to map the label statement itself.
3030 /// Subclasses may override this routine to provide different behavior.
3032 SourceLocation LabelLoc, LabelDecl *Label) {
3033 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3034 }
3035
3036 /// Build a new GNU statement expression.
3037 ///
3038 /// By default, performs semantic analysis to build the new expression.
3039 /// Subclasses may override this routine to provide different behavior.
3041 SourceLocation RParenLoc, unsigned TemplateDepth) {
3042 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3043 TemplateDepth);
3044 }
3045
3046 /// Build a new __builtin_choose_expr expression.
3047 ///
3048 /// By default, performs semantic analysis to build the new expression.
3049 /// Subclasses may override this routine to provide different behavior.
3051 Expr *Cond, Expr *LHS, Expr *RHS,
3052 SourceLocation RParenLoc) {
3053 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3054 Cond, LHS, RHS,
3055 RParenLoc);
3056 }
3057
3058 /// Build a new generic selection expression with an expression predicate.
3059 ///
3060 /// By default, performs semantic analysis to build the new expression.
3061 /// Subclasses may override this routine to provide different behavior.
3063 SourceLocation DefaultLoc,
3064 SourceLocation RParenLoc,
3065 Expr *ControllingExpr,
3067 ArrayRef<Expr *> Exprs) {
3068 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3069 /*PredicateIsExpr=*/true,
3070 ControllingExpr, Types, Exprs);
3071 }
3072
3073 /// Build a new generic selection expression with a type predicate.
3074 ///
3075 /// By default, performs semantic analysis to build the new expression.
3076 /// Subclasses may override this routine to provide different behavior.
3078 SourceLocation DefaultLoc,
3079 SourceLocation RParenLoc,
3080 TypeSourceInfo *ControllingType,
3082 ArrayRef<Expr *> Exprs) {
3083 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3084 /*PredicateIsExpr=*/false,
3085 ControllingType, Types, Exprs);
3086 }
3087
3088 /// Build a new overloaded operator call expression.
3089 ///
3090 /// By default, performs semantic analysis to build the new expression.
3091 /// The semantic analysis provides the behavior of template instantiation,
3092 /// copying with transformations that turn what looks like an overloaded
3093 /// operator call into a use of a builtin operator, performing
3094 /// argument-dependent lookup, etc. Subclasses may override this routine to
3095 /// provide different behavior.
3097 SourceLocation OpLoc,
3098 SourceLocation CalleeLoc,
3099 bool RequiresADL,
3100 const UnresolvedSetImpl &Functions,
3101 Expr *First, Expr *Second);
3102
3103 /// Build a new C++ "named" cast expression, such as static_cast or
3104 /// reinterpret_cast.
3105 ///
3106 /// By default, this routine dispatches to one of the more-specific routines
3107 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3108 /// Subclasses may override this routine to provide different behavior.
3111 SourceLocation LAngleLoc,
3112 TypeSourceInfo *TInfo,
3113 SourceLocation RAngleLoc,
3114 SourceLocation LParenLoc,
3115 Expr *SubExpr,
3116 SourceLocation RParenLoc) {
3117 switch (Class) {
3118 case Stmt::CXXStaticCastExprClass:
3119 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3120 RAngleLoc, LParenLoc,
3121 SubExpr, RParenLoc);
3122
3123 case Stmt::CXXDynamicCastExprClass:
3124 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3125 RAngleLoc, LParenLoc,
3126 SubExpr, RParenLoc);
3127
3128 case Stmt::CXXReinterpretCastExprClass:
3129 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3130 RAngleLoc, LParenLoc,
3131 SubExpr,
3132 RParenLoc);
3133
3134 case Stmt::CXXConstCastExprClass:
3135 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3136 RAngleLoc, LParenLoc,
3137 SubExpr, RParenLoc);
3138
3139 case Stmt::CXXAddrspaceCastExprClass:
3140 return getDerived().RebuildCXXAddrspaceCastExpr(
3141 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3142
3143 default:
3144 llvm_unreachable("Invalid C++ named cast");
3145 }
3146 }
3147
3148 /// Build a new C++ static_cast expression.
3149 ///
3150 /// By default, performs semantic analysis to build the new expression.
3151 /// Subclasses may override this routine to provide different behavior.
3153 SourceLocation LAngleLoc,
3154 TypeSourceInfo *TInfo,
3155 SourceLocation RAngleLoc,
3156 SourceLocation LParenLoc,
3157 Expr *SubExpr,
3158 SourceLocation RParenLoc) {
3159 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3160 TInfo, SubExpr,
3161 SourceRange(LAngleLoc, RAngleLoc),
3162 SourceRange(LParenLoc, RParenLoc));
3163 }
3164
3165 /// Build a new C++ dynamic_cast expression.
3166 ///
3167 /// By default, performs semantic analysis to build the new expression.
3168 /// Subclasses may override this routine to provide different behavior.
3170 SourceLocation LAngleLoc,
3171 TypeSourceInfo *TInfo,
3172 SourceLocation RAngleLoc,
3173 SourceLocation LParenLoc,
3174 Expr *SubExpr,
3175 SourceLocation RParenLoc) {
3176 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3177 TInfo, SubExpr,
3178 SourceRange(LAngleLoc, RAngleLoc),
3179 SourceRange(LParenLoc, RParenLoc));
3180 }
3181
3182 /// Build a new C++ reinterpret_cast expression.
3183 ///
3184 /// By default, performs semantic analysis to build the new expression.
3185 /// Subclasses may override this routine to provide different behavior.
3187 SourceLocation LAngleLoc,
3188 TypeSourceInfo *TInfo,
3189 SourceLocation RAngleLoc,
3190 SourceLocation LParenLoc,
3191 Expr *SubExpr,
3192 SourceLocation RParenLoc) {
3193 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3194 TInfo, SubExpr,
3195 SourceRange(LAngleLoc, RAngleLoc),
3196 SourceRange(LParenLoc, RParenLoc));
3197 }
3198
3199 /// Build a new C++ const_cast expression.
3200 ///
3201 /// By default, performs semantic analysis to build the new expression.
3202 /// Subclasses may override this routine to provide different behavior.
3204 SourceLocation LAngleLoc,
3205 TypeSourceInfo *TInfo,
3206 SourceLocation RAngleLoc,
3207 SourceLocation LParenLoc,
3208 Expr *SubExpr,
3209 SourceLocation RParenLoc) {
3210 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3211 TInfo, SubExpr,
3212 SourceRange(LAngleLoc, RAngleLoc),
3213 SourceRange(LParenLoc, RParenLoc));
3214 }
3215
3218 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3219 SourceLocation LParenLoc, Expr *SubExpr,
3220 SourceLocation RParenLoc) {
3221 return getSema().BuildCXXNamedCast(
3222 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3223 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3224 }
3225
3226 /// Build a new C++ functional-style 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 LParenLoc,
3232 Expr *Sub,
3233 SourceLocation RParenLoc,
3234 bool ListInitialization) {
3235 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3236 // CXXParenListInitExpr. Pass its expanded arguments so that the
3237 // CXXParenListInitExpr can be rebuilt.
3238 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3240 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3241 RParenLoc, ListInitialization);
3242 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3243 MultiExprArg(&Sub, 1), RParenLoc,
3244 ListInitialization);
3245 }
3246
3247 /// Build a new C++ __builtin_bit_cast expression.
3248 ///
3249 /// By default, performs semantic analysis to build the new expression.
3250 /// Subclasses may override this routine to provide different behavior.
3252 TypeSourceInfo *TSI, Expr *Sub,
3253 SourceLocation RParenLoc) {
3254 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3255 }
3256
3257 /// Build a new C++ typeid(type) expression.
3258 ///
3259 /// By default, performs semantic analysis to build the new expression.
3260 /// Subclasses may override this routine to provide different behavior.
3262 SourceLocation TypeidLoc,
3263 TypeSourceInfo *Operand,
3264 SourceLocation RParenLoc) {
3265 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3266 RParenLoc);
3267 }
3268
3269
3270 /// Build a new C++ typeid(expr) 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 TypeidLoc,
3276 Expr *Operand,
3277 SourceLocation RParenLoc) {
3278 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3279 RParenLoc);
3280 }
3281
3282 /// Build a new C++ __uuidof(type) expression.
3283 ///
3284 /// By default, performs semantic analysis to build the new expression.
3285 /// Subclasses may override this routine to provide different behavior.
3287 TypeSourceInfo *Operand,
3288 SourceLocation RParenLoc) {
3289 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3290 }
3291
3292 /// Build a new C++ __uuidof(expr) expression.
3293 ///
3294 /// By default, performs semantic analysis to build the new expression.
3295 /// Subclasses may override this routine to provide different behavior.
3297 Expr *Operand, SourceLocation RParenLoc) {
3298 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3299 }
3300
3301 /// Build a new C++ "this" expression.
3302 ///
3303 /// By default, builds a new "this" expression without performing any
3304 /// semantic analysis. Subclasses may override this routine to provide
3305 /// different behavior.
3307 QualType ThisType,
3308 bool isImplicit) {
3309 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3310 }
3311
3312 /// Build a new C++ throw expression.
3313 ///
3314 /// By default, performs semantic analysis to build the new expression.
3315 /// Subclasses may override this routine to provide different behavior.
3317 bool IsThrownVariableInScope) {
3318 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3319 }
3320
3321 /// Build a new C++ default-argument expression.
3322 ///
3323 /// By default, builds a new default-argument expression, which does not
3324 /// require any semantic analysis. Subclasses may override this routine to
3325 /// provide different behavior.
3327 Expr *RewrittenExpr) {
3328 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3329 RewrittenExpr, getSema().CurContext);
3330 }
3331
3332 /// Build a new C++11 default-initialization expression.
3333 ///
3334 /// By default, builds a new default field initialization expression, which
3335 /// does not require any semantic analysis. Subclasses may override this
3336 /// routine to provide different behavior.
3338 FieldDecl *Field) {
3339 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3340 }
3341
3342 /// Build a new C++ zero-initialization expression.
3343 ///
3344 /// By default, performs semantic analysis to build the new expression.
3345 /// Subclasses may override this routine to provide different behavior.
3347 SourceLocation LParenLoc,
3348 SourceLocation RParenLoc) {
3349 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, std::nullopt,
3350 RParenLoc,
3351 /*ListInitialization=*/false);
3352 }
3353
3354 /// Build a new C++ "new" expression.
3355 ///
3356 /// By default, performs semantic analysis to build the new expression.
3357 /// Subclasses may override this routine to provide different behavior.
3359 SourceLocation PlacementLParen,
3360 MultiExprArg PlacementArgs,
3361 SourceLocation PlacementRParen,
3362 SourceRange TypeIdParens, QualType AllocatedType,
3363 TypeSourceInfo *AllocatedTypeInfo,
3364 std::optional<Expr *> ArraySize,
3365 SourceRange DirectInitRange, Expr *Initializer) {
3366 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3367 PlacementLParen,
3368 PlacementArgs,
3369 PlacementRParen,
3370 TypeIdParens,
3371 AllocatedType,
3372 AllocatedTypeInfo,
3373 ArraySize,
3374 DirectInitRange,
3375 Initializer);
3376 }
3377
3378 /// Build a new C++ "delete" expression.
3379 ///
3380 /// By default, performs semantic analysis to build the new expression.
3381 /// Subclasses may override this routine to provide different behavior.
3383 bool IsGlobalDelete,
3384 bool IsArrayForm,
3385 Expr *Operand) {
3386 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3387 Operand);
3388 }
3389
3390 /// Build a new type trait expression.
3391 ///
3392 /// By default, performs semantic analysis to build the new expression.
3393 /// Subclasses may override this routine to provide different behavior.
3395 SourceLocation StartLoc,
3397 SourceLocation RParenLoc) {
3398 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3399 }
3400
3401 /// Build a new array type trait expression.
3402 ///
3403 /// By default, performs semantic analysis to build the new expression.
3404 /// Subclasses may override this routine to provide different behavior.
3406 SourceLocation StartLoc,
3407 TypeSourceInfo *TSInfo,
3408 Expr *DimExpr,
3409 SourceLocation RParenLoc) {
3410 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3411 }
3412
3413 /// Build a new expression trait expression.
3414 ///
3415 /// By default, performs semantic analysis to build the new expression.
3416 /// Subclasses may override this routine to provide different behavior.
3418 SourceLocation StartLoc,
3419 Expr *Queried,
3420 SourceLocation RParenLoc) {
3421 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3422 }
3423
3424 /// Build a new (previously unresolved) declaration reference
3425 /// expression.
3426 ///
3427 /// By default, performs semantic analysis to build the new expression.
3428 /// Subclasses may override this routine to provide different behavior.
3430 NestedNameSpecifierLoc QualifierLoc,
3431 SourceLocation TemplateKWLoc,
3432 const DeclarationNameInfo &NameInfo,
3433 const TemplateArgumentListInfo *TemplateArgs,
3434 bool IsAddressOfOperand,
3435 TypeSourceInfo **RecoveryTSI) {
3436 CXXScopeSpec SS;
3437 SS.Adopt(QualifierLoc);
3438
3439 if (TemplateArgs || TemplateKWLoc.isValid())
3440 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
3441 TemplateArgs);
3442
3444 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
3445 }
3446
3447 /// Build a new template-id expression.
3448 ///
3449 /// By default, performs semantic analysis to build the new expression.
3450 /// Subclasses may override this routine to provide different behavior.
3452 SourceLocation TemplateKWLoc,
3453 LookupResult &R,
3454 bool RequiresADL,
3455 const TemplateArgumentListInfo *TemplateArgs) {
3456 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3457 TemplateArgs);
3458 }
3459
3460 /// Build a new object-construction expression.
3461 ///
3462 /// By default, performs semantic analysis to build the new expression.
3463 /// Subclasses may override this routine to provide different behavior.
3465 QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor,
3466 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3467 bool ListInitialization, bool StdInitListInitialization,
3468 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3469 SourceRange ParenRange) {
3470 // Reconstruct the constructor we originally found, which might be
3471 // different if this is a call to an inherited constructor.
3472 CXXConstructorDecl *FoundCtor = Constructor;
3473 if (Constructor->isInheritingConstructor())
3474 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3475
3476 SmallVector<Expr *, 8> ConvertedArgs;
3477 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3478 ConvertedArgs))
3479 return ExprError();
3480
3481 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3482 IsElidable,
3483 ConvertedArgs,
3484 HadMultipleCandidates,
3485 ListInitialization,
3486 StdInitListInitialization,
3487 RequiresZeroInit, ConstructKind,
3488 ParenRange);
3489 }
3490
3491 /// Build a new implicit construction via inherited constructor
3492 /// expression.
3494 CXXConstructorDecl *Constructor,
3495 bool ConstructsVBase,
3496 bool InheritedFromVBase) {
3498 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3499 }
3500
3501 /// Build a new object-construction expression.
3502 ///
3503 /// By default, performs semantic analysis to build the new expression.
3504 /// Subclasses may override this routine to provide different behavior.
3506 SourceLocation LParenOrBraceLoc,
3507 MultiExprArg Args,
3508 SourceLocation RParenOrBraceLoc,
3509 bool ListInitialization) {
3511 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3512 }
3513
3514 /// Build a new object-construction expression.
3515 ///
3516 /// By default, performs semantic analysis to build the new expression.
3517 /// Subclasses may override this routine to provide different behavior.
3519 SourceLocation LParenLoc,
3520 MultiExprArg Args,
3521 SourceLocation RParenLoc,
3522 bool ListInitialization) {
3523 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3524 RParenLoc, ListInitialization);
3525 }
3526
3527 /// Build a new member reference expression.
3528 ///
3529 /// By default, performs semantic analysis to build the new expression.
3530 /// Subclasses may override this routine to provide different behavior.
3532 QualType BaseType,
3533 bool IsArrow,
3534 SourceLocation OperatorLoc,
3535 NestedNameSpecifierLoc QualifierLoc,
3536 SourceLocation TemplateKWLoc,
3537 NamedDecl *FirstQualifierInScope,
3538 const DeclarationNameInfo &MemberNameInfo,
3539 const TemplateArgumentListInfo *TemplateArgs) {
3540 CXXScopeSpec SS;
3541 SS.Adopt(QualifierLoc);
3542
3543 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3544 OperatorLoc, IsArrow,
3545 SS, TemplateKWLoc,
3546 FirstQualifierInScope,
3547 MemberNameInfo,
3548 TemplateArgs, /*S*/nullptr);
3549 }
3550
3551 /// Build a new member reference expression.
3552 ///
3553 /// By default, performs semantic analysis to build the new expression.
3554 /// Subclasses may override this routine to provide different behavior.
3556 SourceLocation OperatorLoc,
3557 bool IsArrow,
3558 NestedNameSpecifierLoc QualifierLoc,
3559 SourceLocation TemplateKWLoc,
3560 NamedDecl *FirstQualifierInScope,
3561 LookupResult &R,
3562 const TemplateArgumentListInfo *TemplateArgs) {
3563 CXXScopeSpec SS;
3564 SS.Adopt(QualifierLoc);
3565
3566 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3567 OperatorLoc, IsArrow,
3568 SS, TemplateKWLoc,
3569 FirstQualifierInScope,
3570 R, TemplateArgs, /*S*/nullptr);
3571 }
3572
3573 /// Build a new noexcept expression.
3574 ///
3575 /// By default, performs semantic analysis to build the new expression.
3576 /// Subclasses may override this routine to provide different behavior.
3578 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3579 }
3580
3581 /// Build a new expression to compute the length of a parameter pack.
3583 SourceLocation PackLoc,
3584 SourceLocation RParenLoc,
3585 std::optional<unsigned> Length,
3586 ArrayRef<TemplateArgument> PartialArgs) {
3587 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3588 RParenLoc, Length, PartialArgs);
3589 }
3590
3592 SourceLocation RSquareLoc,
3593 Expr *PackIdExpression, Expr *IndexExpr,
3594 ArrayRef<Expr *> ExpandedExprs,
3595 bool EmptyPack = false) {
3596 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3597 IndexExpr, RSquareLoc, ExpandedExprs,
3598 EmptyPack);
3599 }
3600
3601 /// Build a new expression representing a call to a source location
3602 /// builtin.
3603 ///
3604 /// By default, performs semantic analysis to build the new expression.
3605 /// Subclasses may override this routine to provide different behavior.
3607 SourceLocation BuiltinLoc,
3608 SourceLocation RPLoc,
3609 DeclContext *ParentContext) {
3610 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3611 ParentContext);
3612 }
3613
3614 /// Build a new Objective-C boxed expression.
3615 ///
3616 /// By default, performs semantic analysis to build the new expression.
3617 /// Subclasses may override this routine to provide different behavior.
3619 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3620 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3622 CXXScopeSpec SS;
3623 SS.Adopt(NNS);
3624 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3625 ConceptNameInfo,
3626 FoundDecl,
3627 NamedConcept, TALI);
3628 if (Result.isInvalid())
3629 return ExprError();
3630 return Result;
3631 }
3632
3633 /// \brief Build a new requires expression.
3634 ///
3635 /// By default, performs semantic analysis to build the new expression.
3636 /// Subclasses may override this routine to provide different behavior.
3639 SourceLocation LParenLoc,
3640 ArrayRef<ParmVarDecl *> LocalParameters,
3641 SourceLocation RParenLoc,
3643 SourceLocation ClosingBraceLoc) {
3644 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3645 LocalParameters, RParenLoc, Requirements,
3646 ClosingBraceLoc);
3647 }
3648
3652 return SemaRef.BuildTypeRequirement(SubstDiag);
3653 }
3654
3656 return SemaRef.BuildTypeRequirement(T);
3657 }
3658
3661 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3662 SourceLocation NoexceptLoc,
3664 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3665 std::move(Ret));
3666 }
3667
3669 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3671 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3672 std::move(Ret));
3673 }
3674
3676 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3677 const ASTConstraintSatisfaction &Satisfaction) {
3678 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3679 Satisfaction);
3680 }
3681
3683 return SemaRef.BuildNestedRequirement(Constraint);
3684 }
3685
3686 /// \brief Build a new Objective-C boxed expression.
3687 ///
3688 /// By default, performs semantic analysis to build the new expression.
3689 /// Subclasses may override this routine to provide different behavior.
3691 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
3692 }
3693
3694 /// Build a new Objective-C array literal.
3695 ///
3696 /// By default, performs semantic analysis to build the new expression.
3697 /// Subclasses may override this routine to provide different behavior.
3699 Expr **Elements, unsigned NumElements) {
3700 return getSema().BuildObjCArrayLiteral(Range,
3701 MultiExprArg(Elements, NumElements));
3702 }
3703
3705 Expr *Base, Expr *Key,
3706 ObjCMethodDecl *getterMethod,
3707 ObjCMethodDecl *setterMethod) {
3708 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
3709 getterMethod, setterMethod);
3710 }
3711
3712 /// Build a new Objective-C dictionary literal.
3713 ///
3714 /// By default, performs semantic analysis to build the new expression.
3715 /// Subclasses may override this routine to provide different behavior.
3718 return getSema().BuildObjCDictionaryLiteral(Range, Elements);
3719 }
3720
3721 /// Build a new Objective-C \@encode expression.
3722 ///
3723 /// By default, performs semantic analysis to build the new expression.
3724 /// Subclasses may override this routine to provide different behavior.
3726 TypeSourceInfo *EncodeTypeInfo,
3727 SourceLocation RParenLoc) {
3728 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
3729 }
3730
3731 /// Build a new Objective-C class message.
3733 Selector Sel,
3734 ArrayRef<SourceLocation> SelectorLocs,
3735 ObjCMethodDecl *Method,
3736 SourceLocation LBracLoc,
3737 MultiExprArg Args,
3738 SourceLocation RBracLoc) {
3739 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
3740 ReceiverTypeInfo->getType(),
3741 /*SuperLoc=*/SourceLocation(),
3742 Sel, Method, LBracLoc, SelectorLocs,
3743 RBracLoc, Args);
3744 }
3745
3746 /// Build a new Objective-C instance message.
3748 Selector Sel,
3749 ArrayRef<SourceLocation> SelectorLocs,
3750 ObjCMethodDecl *Method,
3751 SourceLocation LBracLoc,
3752 MultiExprArg Args,
3753 SourceLocation RBracLoc) {
3754 return SemaRef.BuildInstanceMessage(Receiver,
3755 Receiver->getType(),
3756 /*SuperLoc=*/SourceLocation(),
3757 Sel, Method, LBracLoc, SelectorLocs,
3758 RBracLoc, Args);
3759 }
3760
3761 /// Build a new Objective-C instance/class message to 'super'.
3763 Selector Sel,
3764 ArrayRef<SourceLocation> SelectorLocs,
3765 QualType SuperType,
3766 ObjCMethodDecl *Method,
3767 SourceLocation LBracLoc,
3768 MultiExprArg Args,
3769 SourceLocation RBracLoc) {
3770 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
3771 SuperType,
3772 SuperLoc,
3773 Sel, Method, LBracLoc, SelectorLocs,
3774 RBracLoc, Args)
3775 : SemaRef.BuildClassMessage(nullptr,
3776 SuperType,
3777 SuperLoc,
3778 Sel, Method, LBracLoc, SelectorLocs,
3779 RBracLoc, Args);
3780
3781
3782 }
3783
3784 /// Build a new Objective-C ivar reference expression.
3785 ///
3786 /// By default, performs semantic analysis to build the new expression.
3787 /// Subclasses may override this routine to provide different behavior.
3789 SourceLocation IvarLoc,
3790 bool IsArrow, bool IsFreeIvar) {
3791 CXXScopeSpec SS;
3792 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3794 BaseArg, BaseArg->getType(),
3795 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3796 /*FirstQualifierInScope=*/nullptr, NameInfo,
3797 /*TemplateArgs=*/nullptr,
3798 /*S=*/nullptr);
3799 if (IsFreeIvar && Result.isUsable())
3800 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3801 return Result;
3802 }
3803
3804 /// Build a new Objective-C property reference expression.
3805 ///
3806 /// By default, performs semantic analysis to build the new expression.
3807 /// Subclasses may override this routine to provide different behavior.
3810 SourceLocation PropertyLoc) {
3811 CXXScopeSpec SS;
3812 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3813 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3814 /*FIXME:*/PropertyLoc,
3815 /*IsArrow=*/false,
3816 SS, SourceLocation(),
3817 /*FirstQualifierInScope=*/nullptr,
3818 NameInfo,
3819 /*TemplateArgs=*/nullptr,
3820 /*S=*/nullptr);
3821 }
3822
3823 /// Build a new Objective-C property 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 ObjCMethodDecl *Getter,
3829 ObjCMethodDecl *Setter,
3830 SourceLocation PropertyLoc) {
3831 // Since these expressions can only be value-dependent, we do not
3832 // need to perform semantic analysis again.
3833 return Owned(
3834 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3836 PropertyLoc, Base));
3837 }
3838
3839 /// Build a new Objective-C "isa" expression.
3840 ///
3841 /// By default, performs semantic analysis to build the new expression.
3842 /// Subclasses may override this routine to provide different behavior.
3844 SourceLocation OpLoc, bool IsArrow) {
3845 CXXScopeSpec SS;
3846 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3847 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3848 OpLoc, IsArrow,
3849 SS, SourceLocation(),
3850 /*FirstQualifierInScope=*/nullptr,
3851 NameInfo,
3852 /*TemplateArgs=*/nullptr,
3853 /*S=*/nullptr);
3854 }
3855
3856 /// Build a new shuffle vector expression.
3857 ///
3858 /// By default, performs semantic analysis to build the new expression.
3859 /// Subclasses may override this routine to provide different behavior.
3861 MultiExprArg SubExprs,
3862 SourceLocation RParenLoc) {
3863 // Find the declaration for __builtin_shufflevector
3864 const IdentifierInfo &Name
3865 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3867 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3868 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3869
3870 // Build a reference to the __builtin_shufflevector builtin
3871 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3872 Expr *Callee = new (SemaRef.Context)
3873 DeclRefExpr(SemaRef.Context, Builtin, false,
3874 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3875 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3876 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3877 CK_BuiltinFnToFnPtr).get();
3878
3879 // Build the CallExpr
3880 ExprResult TheCall = CallExpr::Create(
3881 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3882 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3884
3885 // Type-check the __builtin_shufflevector expression.
3886 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3887 }
3888
3889 /// Build a new convert vector expression.
3891 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3892 SourceLocation RParenLoc) {
3893 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
3894 BuiltinLoc, RParenLoc);
3895 }
3896
3897 /// Build a new template argument pack expansion.
3898 ///
3899 /// By default, performs semantic analysis to build a new pack expansion
3900 /// for a template argument. Subclasses may override this routine to provide
3901 /// different behavior.
3904 std::optional<unsigned> NumExpansions) {
3905 switch (Pattern.getArgument().getKind()) {
3909 EllipsisLoc, NumExpansions);
3910 if (Result.isInvalid())
3911 return TemplateArgumentLoc();
3912
3913 return TemplateArgumentLoc(Result.get(), Result.get());
3914 }
3915
3917 return TemplateArgumentLoc(
3920 NumExpansions),
3921 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3922 EllipsisLoc);
3923
3931 llvm_unreachable("Pack expansion pattern has no parameter packs");
3932
3934 if (TypeSourceInfo *Expansion
3935 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
3936 EllipsisLoc,
3937 NumExpansions))
3938 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
3939 Expansion);
3940 break;
3941 }
3942
3943 return TemplateArgumentLoc();
3944 }
3945
3946 /// Build a new expression pack expansion.
3947 ///
3948 /// By default, performs semantic analysis to build a new pack expansion
3949 /// for an expression. Subclasses may override this routine to provide
3950 /// different behavior.
3952 std::optional<unsigned> NumExpansions) {
3953 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
3954 }
3955
3956 /// Build a new C++1z fold-expression.
3957 ///
3958 /// By default, performs semantic analysis in order to build a new fold
3959 /// expression.
3961 SourceLocation LParenLoc, Expr *LHS,
3962 BinaryOperatorKind Operator,
3963 SourceLocation EllipsisLoc, Expr *RHS,
3964 SourceLocation RParenLoc,
3965 std::optional<unsigned> NumExpansions) {
3966 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
3967 EllipsisLoc, RHS, RParenLoc,
3968 NumExpansions);
3969 }
3970
3971 /// Build an empty C++1z fold-expression with the given operator.
3972 ///
3973 /// By default, produces the fallback value for the fold-expression, or
3974 /// produce an error if there is no fallback value.
3976 BinaryOperatorKind Operator) {
3977 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
3978 }
3979
3980 /// Build a new atomic operation expression.
3981 ///
3982 /// By default, performs semantic analysis to build the new expression.
3983 /// Subclasses may override this routine to provide different behavior.
3986 SourceLocation RParenLoc) {
3987 // Use this for all of the locations, since we don't know the difference
3988 // between the call and the expr at this point.
3989 SourceRange Range{BuiltinLoc, RParenLoc};
3990 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
3992 }
3993
3995 ArrayRef<Expr *> SubExprs, QualType Type) {
3996 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
3997 }
3998
4000 SourceLocation BeginLoc,
4001 SourceLocation EndLoc,
4002 StmtResult StrBlock) {
4003 getSema().ActOnOpenACCConstruct(K, BeginLoc);
4004
4005 // TODO OpenACC: Include clauses.
4006 if (getSema().ActOnStartOpenACCStmtDirective(K, BeginLoc))
4007 return StmtError();
4008
4009 StrBlock = getSema().ActOnOpenACCAssociatedStmt(K, StrBlock);
4010
4011 return getSema().ActOnEndOpenACCStmtDirective(K, BeginLoc, EndLoc,
4012 StrBlock);
4013 }
4014
4015private:
4016 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
4017 QualType ObjectType,
4018 NamedDecl *FirstQualifierInScope,
4019 CXXScopeSpec &SS);
4020
4021 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4022 QualType ObjectType,
4023 NamedDecl *FirstQualifierInScope,
4024 CXXScopeSpec &SS);
4025
4026 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
4027 NamedDecl *FirstQualifierInScope,
4028 CXXScopeSpec &SS);
4029
4030 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4032 bool DeducibleTSTContext);
4033};
4034
4035template <typename Derived>
4037 if (!S)
4038 return S;
4039
4040 switch (S->getStmtClass()) {
4041 case Stmt::NoStmtClass: break;
4042
4043 // Transform individual statement nodes
4044 // Pass SDK into statements that can produce a value
4045#define STMT(Node, Parent) \
4046 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4047#define VALUESTMT(Node, Parent) \
4048 case Stmt::Node##Class: \
4049 return getDerived().Transform##Node(cast<Node>(S), SDK);
4050#define ABSTRACT_STMT(Node)
4051#define EXPR(Node, Parent)
4052#include "clang/AST/StmtNodes.inc"
4053
4054 // Transform expressions by calling TransformExpr.
4055#define STMT(Node, Parent)
4056#define ABSTRACT_STMT(Stmt)
4057#define EXPR(Node, Parent) case Stmt::Node##Class:
4058#include "clang/AST/StmtNodes.inc"
4059 {
4060 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4061
4062 if (SDK == SDK_StmtExprResult)
4063 E = getSema().ActOnStmtExprResult(E);
4064 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
4065 }
4066 }
4067
4068 return S;
4069}
4070
4071template<typename Derived>
4073 if (!S)
4074 return S;
4075
4076 switch (S->getClauseKind()) {
4077 default: break;
4078 // Transform individual clause nodes
4079#define GEN_CLANG_CLAUSE_CLASS
4080#define CLAUSE_CLASS(Enum, Str, Class) \
4081 case Enum: \
4082 return getDerived().Transform##Class(cast<Class>(S));
4083#include "llvm/Frontend/OpenMP/OMP.inc"
4084 }
4085
4086 return S;
4087}
4088
4089
4090template<typename Derived>
4092 if (!E)
4093 return E;
4094
4095 switch (E->getStmtClass()) {
4096 case Stmt::NoStmtClass: break;
4097#define STMT(Node, Parent) case Stmt::Node##Class: break;
4098#define ABSTRACT_STMT(Stmt)
4099#define EXPR(Node, Parent) \
4100 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4101#include "clang/AST/StmtNodes.inc"
4102 }
4103
4104 return E;
4105}
4106
4107template<typename Derived>
4109 bool NotCopyInit) {
4110 // Initializers are instantiated like expressions, except that various outer
4111 // layers are stripped.
4112 if (!Init)
4113 return Init;
4114
4115 if (auto *FE = dyn_cast<FullExpr>(Init))
4116 Init = FE->getSubExpr();
4117
4118 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4119 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4120 Init = OVE->getSourceExpr();
4121 }
4122
4123 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4124 Init = MTE->getSubExpr();
4125
4126 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4127 Init = Binder->getSubExpr();
4128
4129 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4130 Init = ICE->getSubExprAsWritten();
4131
4132 if (CXXStdInitializerListExpr *ILE =
4133 dyn_cast<CXXStdInitializerListExpr>(Init))
4134 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4135
4136 // If this is copy-initialization, we only need to reconstruct
4137 // InitListExprs. Other forms of copy-initialization will be a no-op if
4138 // the initializer is already the right type.
4139 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4140 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4141 return getDerived().TransformExpr(Init);
4142
4143 // Revert value-initialization back to empty parens.
4144 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4145 SourceRange Parens = VIE->getSourceRange();
4146 return getDerived().RebuildParenListExpr(Parens.getBegin(), std::nullopt,
4147 Parens.getEnd());
4148 }
4149
4150 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4151 if (isa<ImplicitValueInitExpr>(Init))
4152 return getDerived().RebuildParenListExpr(SourceLocation(), std::nullopt,
4153 SourceLocation());
4154
4155 // Revert initialization by constructor back to a parenthesized or braced list
4156 // of expressions. Any other form of initializer can just be reused directly.
4157 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4158 return getDerived().TransformExpr(Init);
4159
4160 // If the initialization implicitly converted an initializer list to a
4161 // std::initializer_list object, unwrap the std::initializer_list too.
4162 if (Construct && Construct->isStdInitListInitialization())
4163 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4164
4165 // Enter a list-init context if this was list initialization.
4168 Construct->isListInitialization());
4169
4170 getSema().keepInLifetimeExtendingContext();
4171 getSema().keepInLifetimeExtendingContext();
4172 SmallVector<Expr*, 8> NewArgs;
4173 bool ArgChanged = false;
4174 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4175 /*IsCall*/true, NewArgs, &ArgChanged))
4176 return ExprError();
4177
4178 // If this was list initialization, revert to syntactic list form.
4179 if (Construct->isListInitialization())
4180 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4181 Construct->getEndLoc());
4182
4183 // Build a ParenListExpr to represent anything else.
4185 if (Parens.isInvalid()) {
4186 // This was a variable declaration's initialization for which no initializer
4187 // was specified.
4188 assert(NewArgs.empty() &&
4189 "no parens or braces but have direct init with arguments?");
4190 return ExprEmpty();
4191 }
4192 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4193 Parens.getEnd());
4194}
4195
4196template<typename Derived>
4198 unsigned NumInputs,
4199 bool IsCall,
4200 SmallVectorImpl<Expr *> &Outputs,
4201 bool *ArgChanged) {
4202 for (unsigned I = 0; I != NumInputs; ++I) {
4203 // If requested, drop call arguments that need to be dropped.
4204 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4205 if (ArgChanged)
4206 *ArgChanged = true;
4207
4208 break;
4209 }
4210
4211 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4212 Expr *Pattern = Expansion->getPattern();
4213
4215 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4216 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4217
4218 // Determine whether the set of unexpanded parameter packs can and should
4219 // be expanded.
4220 bool Expand = true;
4221 bool RetainExpansion = false;
4222 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4223 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4224 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4225 Pattern->getSourceRange(),
4226 Unexpanded,
4227 Expand, RetainExpansion,
4228 NumExpansions))
4229 return true;
4230
4231 if (!Expand) {
4232 // The transform has determined that we should perform a simple
4233 // transformation on the pack expansion, producing another pack
4234 // expansion.
4235 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4236 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4237 if (OutPattern.isInvalid())
4238 return true;
4239
4240 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4241 Expansion->getEllipsisLoc(),
4242 NumExpansions);
4243 if (Out.isInvalid())
4244 return true;
4245
4246 if (ArgChanged)
4247 *ArgChanged = true;
4248 Outputs.push_back(Out.get());
4249 continue;
4250 }
4251
4252 // Record right away that the argument was changed. This needs
4253 // to happen even if the array expands to nothing.
4254 if (ArgChanged) *ArgChanged = true;
4255
4256 // The transform has determined that we should perform an elementwise
4257 // expansion of the pattern. Do so.
4258 for (unsigned I = 0; I != *NumExpansions; ++I) {
4259 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4260 ExprResult Out = getDerived().TransformExpr(Pattern);
4261 if (Out.isInvalid())
4262 return true;
4263
4264 if (Out.get()->containsUnexpandedParameterPack()) {
4265 Out = getDerived().RebuildPackExpansion(
4266 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4267 if (Out.isInvalid())
4268 return true;
4269 }
4270
4271 Outputs.push_back(Out.get());
4272 }
4273
4274 // If we're supposed to retain a pack expansion, do so by temporarily
4275 // forgetting the partially-substituted parameter pack.
4276 if (RetainExpansion) {
4277 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4278
4279 ExprResult Out = getDerived().TransformExpr(Pattern);
4280 if (Out.isInvalid())
4281 return true;
4282
4283 Out = getDerived().RebuildPackExpansion(
4284 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4285 if (Out.isInvalid())
4286 return true;
4287
4288 Outputs.push_back(Out.get());
4289 }
4290
4291 continue;
4292 }
4293
4295 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4296 : getDerived().TransformExpr(Inputs[I]);
4297 if (Result.isInvalid())
4298 return true;
4299
4300 if (Result.get() != Inputs[I] && ArgChanged)
4301 *ArgChanged = true;
4302
4303 Outputs.push_back(Result.get());
4304 }
4305
4306 return false;
4307}
4308
4309template <typename Derived>
4312 if (Var) {
4313 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4314 getDerived().TransformDefinition(Var->getLocation(), Var));
4315
4316 if (!ConditionVar)
4317 return Sema::ConditionError();
4318
4319 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4320 }
4321
4322 if (Expr) {
4323 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4324
4325 if (CondExpr.isInvalid())
4326 return Sema::ConditionError();
4327
4328 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4329 /*MissingOK=*/true);
4330 }
4331
4332 return Sema::ConditionResult();
4333}
4334
4335template <typename Derived>
4337 NestedNameSpecifierLoc NNS, QualType ObjectType,
4338 NamedDecl *FirstQualifierInScope) {
4340
4341 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4342 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4343 Qualifier = Qualifier.getPrefix())
4344 Qualifiers.push_back(Qualifier);
4345 };
4346 insertNNS(NNS);
4347
4348 CXXScopeSpec SS;
4349 while (!Qualifiers.empty()) {
4350 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4352
4353 switch (QNNS->getKind()) {
4357 ObjectType);
4358 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4359 SS, FirstQualifierInScope, false))
4360 return NestedNameSpecifierLoc();
4361 break;
4362 }
4363
4365 NamespaceDecl *NS =
4366 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4367 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4368 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4369 break;
4370 }
4371
4373 NamespaceAliasDecl *Alias =
4374 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4376 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4377 Q.getLocalEndLoc());
4378 break;
4379 }
4380
4382 // There is no meaningful transformation that one could perform on the
4383 // global scope.
4384 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4385 break;
4386
4388 CXXRecordDecl *RD =
4389 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4390 SourceLocation(), QNNS->getAsRecordDecl()));
4391 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4392 break;
4393 }
4394
4397 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4398 FirstQualifierInScope, SS);
4399
4400 if (!TL)
4401 return NestedNameSpecifierLoc();
4402
4403 QualType T = TL.getType();
4404 if (T->isDependentType() || T->isRecordType() ||
4405 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4406 if (T->isEnumeralType())
4407 SemaRef.Diag(TL.getBeginLoc(),
4408 diag::warn_cxx98_compat_enum_nested_name_spec);
4409
4410 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) {
4411 SS.Adopt(ETL.getQualifierLoc());
4412 TL = ETL.getNamedTypeLoc();
4413 }
4414
4415 SS.Extend(SemaRef.Context, TL.getTemplateKeywordLoc(), TL,
4416 Q.getLocalEndLoc());
4417 break;
4418 }
4419 // If the nested-name-specifier is an invalid type def, don't emit an
4420 // error because a previous error should have already been emitted.
4422 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4423 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4424 << T << SS.getRange();
4425 }
4426 return NestedNameSpecifierLoc();
4427 }
4428 }
4429
4430 // The qualifier-in-scope and object type only apply to the leftmost entity.
4431 FirstQualifierInScope = nullptr;
4432 ObjectType = QualType();
4433 }
4434
4435 // Don't rebuild the nested-name-specifier if we don't have to.
4436 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4437 !getDerived().AlwaysRebuild())
4438 return NNS;
4439
4440 // If we can re-use the source-location data from the original
4441 // nested-name-specifier, do so.
4442 if (SS.location_size() == NNS.getDataLength() &&
4443 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4445
4446 // Allocate new nested-name-specifier location information.
4447 return SS.getWithLocInContext(SemaRef.Context);
4448}
4449
4450template<typename Derived>
4454 DeclarationName Name = NameInfo.getName();
4455 if (!Name)
4456 return DeclarationNameInfo();
4457
4458 switch (Name.getNameKind()) {
4466 return NameInfo;
4467
4469 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4470 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4471 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4472 if (!NewTemplate)
4473 return DeclarationNameInfo();
4474
4475 DeclarationNameInfo NewNameInfo(NameInfo);
4476 NewNameInfo.setName(
4478 return NewNameInfo;
4479 }
4480
4484 TypeSourceInfo *NewTInfo;
4485 CanQualType NewCanTy;
4486 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4487 NewTInfo = getDerived().TransformType(OldTInfo);
4488 if (!NewTInfo)
4489 return DeclarationNameInfo();
4490 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4491 }
4492 else {
4493 NewTInfo = nullptr;
4494 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4495 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4496 if (NewT.isNull())
4497 return DeclarationNameInfo();
4498 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4499 }
4500
4501 DeclarationName NewName
4502 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4503 NewCanTy);
4504 DeclarationNameInfo NewNameInfo(NameInfo);
4505 NewNameInfo.setName(NewName);
4506 NewNameInfo.setNamedTypeInfo(NewTInfo);
4507 return NewNameInfo;
4508 }
4509 }
4510
4511 llvm_unreachable("Unknown name kind.");
4512}
4513
4514template<typename Derived>
4517 TemplateName Name,
4518 SourceLocation NameLoc,
4519 QualType ObjectType,
4520 NamedDecl *FirstQualifierInScope,
4521 bool AllowInjectedClassName) {
4522 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4523 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
4524 assert(Template && "qualified template name must refer to a template");
4525
4526 TemplateDecl *TransTemplate
4527 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4528 Template));
4529 if (!TransTemplate)
4530 return TemplateName();
4531
4532 if (!getDerived().AlwaysRebuild() &&
4533 SS.getScopeRep() == QTN->getQualifier() &&
4534 TransTemplate == Template)
4535 return Name;
4536
4537 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4538 TransTemplate);
4539 }
4540
4541 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4542 if (SS.getScopeRep()) {
4543 // These apply to the scope specifier, not the template.
4544 ObjectType = QualType();
4545 FirstQualifierInScope = nullptr;
4546 }
4547
4548 if (!getDerived().AlwaysRebuild() &&
4549 SS.getScopeRep() == DTN->getQualifier() &&
4550 ObjectType.isNull())
4551 return Name;
4552
4553 // FIXME: Preserve the location of the "template" keyword.
4554 SourceLocation TemplateKWLoc = NameLoc;
4555
4556 if (DTN->isIdentifier()) {
4557 return getDerived().RebuildTemplateName(SS,
4558 TemplateKWLoc,
4559 *DTN->getIdentifier(),
4560 NameLoc,
4561 ObjectType,
4562 FirstQualifierInScope,
4563 AllowInjectedClassName);
4564 }
4565
4566 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4567 DTN->getOperator(), NameLoc,
4568 ObjectType, AllowInjectedClassName);
4569 }
4570
4571 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4572 TemplateDecl *TransTemplate
4573 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4574 Template));
4575 if (!TransTemplate)
4576 return TemplateName();
4577
4578 if (!getDerived().AlwaysRebuild() &&
4579 TransTemplate == Template)
4580 return Name;
4581
4582 return TemplateName(TransTemplate);
4583 }
4584
4586 = Name.getAsSubstTemplateTemplateParmPack()) {
4587 return getDerived().RebuildTemplateName(
4588 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4589 SubstPack->getIndex(), SubstPack->getFinal());
4590 }
4591
4592 // These should be getting filtered out before they reach the AST.
4593 llvm_unreachable("overloaded function decl survived to here");
4594}
4595
4596template<typename Derived>
4598 const TemplateArgument &Arg,
4599 TemplateArgumentLoc &Output) {
4600 Output = getSema().getTrivialTemplateArgumentLoc(
4601 Arg, QualType(), getDerived().getBaseLocation());
4602}
4603
4604template <typename Derived>
4606 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4607 bool Uneval) {
4608 const TemplateArgument &Arg = Input.getArgument();
4609 switch (Arg.getKind()) {
4612 llvm_unreachable("Unexpected TemplateArgument");
4613
4618 // Transform a resolved template argument straight to a resolved template
4619 // argument. We get here when substituting into an already-substituted
4620 // template type argument during concept satisfaction checking.
4622 QualType NewT = getDerived().TransformType(T);
4623 if (NewT.isNull())
4624 return true;
4625
4627 ? Arg.getAsDecl()
4628 : nullptr;
4629 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4630 getDerived().getBaseLocation(), D))
4631 : nullptr;
4632 if (D && !NewD)
4633 return true;
4634
4635 if (NewT == T && D == NewD)
4636 Output = Input;
4637 else if (Arg.getKind() == TemplateArgument::Integral)
4638 Output = TemplateArgumentLoc(
4639 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4641 else if (Arg.getKind() == TemplateArgument::NullPtr)
4642 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4644 else if (Arg.getKind() == TemplateArgument::Declaration)
4645 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4648 Output = TemplateArgumentLoc(
4649 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4651 else
4652 llvm_unreachable("unexpected template argument kind");
4653
4654 return false;
4655 }
4656
4658 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4659 if (!DI)
4660 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4661
4662 DI = getDerived().TransformType(DI);
4663 if (!DI)
4664 return true;
4665
4666 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4667 return false;
4668 }
4669
4671 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4672 if (QualifierLoc) {
4673 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4674 if (!QualifierLoc)
4675 return true;
4676 }
4677
4678 CXXScopeSpec SS;
4679 SS.Adopt(QualifierLoc);
4680 TemplateName Template = getDerived().TransformTemplateName(
4681 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4682 if (Template.isNull())
4683 return true;
4684
4685 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4686 QualifierLoc, Input.getTemplateNameLoc());
4687 return false;
4688 }
4689
4691 llvm_unreachable("Caller should expand pack expansions");
4692
4694 // Template argument expressions are constant expressions.
4696 getSema(),
4699 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
4701
4702 Expr *InputExpr = Input.getSourceExpression();
4703 if (!InputExpr)
4704 InputExpr = Input.getArgument().getAsExpr();
4705
4706 ExprResult E = getDerived().TransformExpr(InputExpr);
4707 E = SemaRef.ActOnConstantExpression(E);
4708 if (E.isInvalid())
4709 return true;
4710 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4711 return false;
4712 }
4713 }
4714
4715 // Work around bogus GCC warning
4716 return true;
4717}
4718
4719/// Iterator adaptor that invents template argument location information
4720/// for each of the template arguments in its underlying iterator.
4721template<typename Derived, typename InputIterator>
4724 InputIterator Iter;
4725
4726public:
4729 typedef typename std::iterator_traits<InputIterator>::difference_type
4731 typedef std::input_iterator_tag iterator_category;
4732
4733 class pointer {
4735
4736 public:
4737 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4738
4739 const TemplateArgumentLoc *operator->() const { return &Arg; }
4740 };
4741
4743
4745 InputIterator Iter)
4746 : Self(Self), Iter(Iter) { }
4747
4749 ++Iter;
4750 return *this;
4751 }
4752
4755 ++(*this);
4756 return Old;
4757 }
4758
4761 Self.InventTemplateArgumentLoc(*Iter, Result);
4762 return Result;
4763 }
4764
4765 pointer operator->() const { return pointer(**this); }
4766
4769 return X.Iter == Y.Iter;
4770 }
4771
4774 return X.Iter != Y.Iter;
4775 }
4776};
4777
4778template<typename Derived>
4779template<typename InputIterator>
4781 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4782 bool Uneval) {
4783 for (; First != Last; ++First) {
4786
4787 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4788 // When building the deduction guides, we rewrite the argument packs
4789 // instead of unpacking.
4790 if (getSema().CodeSynthesisContexts.back().Kind ==
4792 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4793 return true;
4794 continue;
4795 }
4796 // Unpack argument packs, which we translate them into separate
4797 // arguments.
4798 // FIXME: We could do much better if we could guarantee that the
4799 // TemplateArgumentLocInfo for the pack expansion would be usable for
4800 // all of the template arguments in the argument pack.
4801 typedef TemplateArgumentLocInventIterator<Derived,
4803 PackLocIterator;
4804 if (TransformTemplateArguments(PackLocIterator(*this,
4805 In.getArgument().pack_begin()),
4806 PackLocIterator(*this,
4807 In.getArgument().pack_end()),
4808 Outputs, Uneval))
4809 return true;
4810
4811 continue;
4812 }
4813
4814 if (In.getArgument().isPackExpansion()) {
4815 // We have a pack expansion, for which we will be substituting into
4816 // the pattern.
4817 SourceLocation Ellipsis;
4818 std::optional<unsigned> OrigNumExpansions;
4819 TemplateArgumentLoc Pattern
4820 = getSema().getTemplateArgumentPackExpansionPattern(
4821 In, Ellipsis, OrigNumExpansions);
4822
4824 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4825 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4826
4827 // Determine whether the set of unexpanded parameter packs can and should
4828 // be expanded.
4829 bool Expand = true;
4830 bool RetainExpansion = false;
4831 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4832 if (getDerived().TryExpandParameterPacks(Ellipsis,
4833 Pattern.getSourceRange(),
4834 Unexpanded,
4835 Expand,
4836 RetainExpansion,
4837 NumExpansions))
4838 return true;
4839
4840 if (!Expand) {
4841 // The transform has determined that we should perform a simple
4842 // transformation on the pack expansion, producing another pack
4843 // expansion.
4844 TemplateArgumentLoc OutPattern;
4845 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4846 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
4847 return true;
4848
4849 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
4850 NumExpansions);
4851 if (Out.getArgument().isNull())
4852 return true;
4853
4854 Outputs.addArgument(Out);
4855 continue;
4856 }
4857
4858 // The transform has determined that we should perform an elementwise
4859 // expansion of the pattern. Do so.
4860 for (unsigned I = 0; I != *NumExpansions; ++I) {
4861 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4862
4863 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4864 return true;
4865
4866 if (Out.getArgument().containsUnexpandedParameterPack()) {
4867 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4868 OrigNumExpansions);
4869 if (Out.getArgument().isNull())
4870 return true;
4871 }
4872
4873 Outputs.addArgument(Out);
4874 }
4875
4876 // If we're supposed to retain a pack expansion, do so by temporarily
4877 // forgetting the partially-substituted parameter pack.
4878 if (RetainExpansion) {
4879 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4880
4881 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
4882 return true;
4883
4884 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
4885 OrigNumExpansions);
4886 if (Out.getArgument().isNull())
4887 return true;
4888
4889 Outputs.addArgument(Out);
4890 }
4891
4892 continue;
4893 }
4894
4895 // The simple case:
4896 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
4897 return true;
4898
4899 Outputs.addArgument(Out);
4900 }
4901
4902 return false;
4903
4904}
4905
4906//===----------------------------------------------------------------------===//
4907// Type transformation
4908//===----------------------------------------------------------------------===//
4909
4910template<typename Derived>
4912 if (getDerived().AlreadyTransformed(T))
4913 return T;
4914
4915 // Temporary workaround. All of these transformations should
4916 // eventually turn into transformations on TypeLocs.
4917 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4918 getDerived().getBaseLocation());
4919
4920 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
4921
4922 if (!NewDI)
4923 return QualType();
4924
4925 return NewDI->getType();
4926}
4927
4928template<typename Derived>
4930 // Refine the base location to the type's location.
4931 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4932 getDerived().getBaseEntity());
4933 if (getDerived().AlreadyTransformed(DI->getType()))
4934 return DI;
4935
4936 TypeLocBuilder TLB;
4937
4938 TypeLoc TL = DI->getTypeLoc();
4939 TLB.reserve(TL.getFullDataSize());
4940
4941 QualType Result = getDerived().TransformType(TLB, TL);
4942 if (Result.isNull())
4943 return nullptr;
4944
4945 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
4946}
4947
4948template<typename Derived>
4951 switch (T.getTypeLocClass()) {
4952#define ABSTRACT_TYPELOC(CLASS, PARENT)
4953#define TYPELOC(CLASS, PARENT) \
4954 case TypeLoc::CLASS: \
4955 return getDerived().Transform##CLASS##Type(TLB, \
4956 T.castAs<CLASS##TypeLoc>());
4957#include "clang/AST/TypeLocNodes.def"
4958 }
4959
4960 llvm_unreachable("unhandled type loc!");
4961}
4962
4963template<typename Derived>
4965 if (!isa<DependentNameType>(T))
4966 return TransformType(T);
4967
4968 if (getDerived().AlreadyTransformed(T))
4969 return T;
4970 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
4971 getDerived().getBaseLocation());
4972 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
4973 return NewDI ? NewDI->getType() : QualType();
4974}
4975
4976template<typename Derived>
4979 if (!isa<DependentNameType>(DI->getType()))
4980 return TransformType(DI);
4981
4982 // Refine the base location to the type's location.
4983 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
4984 getDerived().getBaseEntity());
4985 if (getDerived().AlreadyTransformed(DI->getType()))
4986 return DI;
4987
4988 TypeLocBuilder TLB;
4989
4990 TypeLoc TL = DI->getTypeLoc();
4991 TLB.reserve(TL.getFullDataSize());
4992
4993 auto QTL = TL.getAs<QualifiedTypeLoc>();
4994 if (QTL)
4995 TL = QTL.getUnqualifiedLoc();
4996
4997 auto DNTL = TL.castAs<DependentNameTypeLoc>();
4998
4999 QualType Result = getDerived().TransformDependentNameType(
5000 TLB, DNTL, /*DeducedTSTContext*/true);
5001 if (Result.isNull())
5002 return nullptr;
5003
5004 if (QTL) {
5005 Result = getDerived().RebuildQualifiedType(Result, QTL);
5006 if (Result.isNull())
5007 return nullptr;
5009 }
5010
5011 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5012}
5013
5014template<typename Derived>
5017 QualifiedTypeLoc T) {
5019 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5020 auto SuppressObjCLifetime =
5022 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5023 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5024 SuppressObjCLifetime);
5025 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5026 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5027 TLB, STTP, SuppressObjCLifetime);
5028 } else {
5029 Result = getDerived().TransformType(TLB, UnqualTL);
5030 }
5031
5032 if (Result.isNull())
5033 return QualType();
5034
5035 Result = getDerived().RebuildQualifiedType(Result, T);
5036
5037 if (Result.isNull())
5038 return QualType();
5039
5040 // RebuildQualifiedType might have updated the type, but not in a way
5041 // that invalidates the TypeLoc. (There's no location information for
5042 // qualifiers.)
5044
5045 return Result;
5046}
5047
5048template <typename Derived>
5050 QualifiedTypeLoc TL) {
5051
5052 SourceLocation Loc = TL.getBeginLoc();
5053 Qualifiers Quals = TL.getType().getLocalQualifiers();
5054
5055 if ((T.getAddressSpace() != LangAS::Default &&
5056 Quals.getAddressSpace() != LangAS::Default) &&
5057 T.getAddressSpace() != Quals.getAddressSpace()) {
5058 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5059 << TL.getType() << T;
5060 return QualType();
5061 }
5062
5063 // C++ [dcl.fct]p7:
5064 // [When] adding cv-qualifications on top of the function type [...] the
5065 // cv-qualifiers are ignored.
5066 if (T->isFunctionType()) {
5067 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
5068 Quals.getAddressSpace());
5069 return T;
5070 }
5071
5072 // C++ [dcl.ref]p1:
5073 // when the cv-qualifiers are introduced through the use of a typedef-name
5074 // or decltype-specifier [...] the cv-qualifiers are ignored.
5075 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5076 // applied to a reference type.
5077 if (T->isReferenceType()) {
5078 // The only qualifier that applies to a reference type is restrict.
5079 if (!Quals.hasRestrict())
5080 return T;
5082 }
5083
5084 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5085 // resulting type.
5086 if (Quals.hasObjCLifetime()) {
5087 if (!T->isObjCLifetimeType() && !T->isDependentType())
5088 Quals.removeObjCLifetime();
5089 else if (T.getObjCLifetime()) {
5090 // Objective-C ARC:
5091 // A lifetime qualifier applied to a substituted template parameter
5092 // overrides the lifetime qualifier from the template argument.
5093 const AutoType *AutoTy;
5094 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5095 // 'auto' types behave the same way as template parameters.
5096 QualType Deduced = AutoTy->getDeducedType();
5097 Qualifiers Qs = Deduced.getQualifiers();
5098 Qs.removeObjCLifetime();
5099 Deduced =
5100 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5101 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5102 AutoTy->isDependentType(),
5103 /*isPack=*/false,
5104 AutoTy->getTypeConstraintConcept(),
5105 AutoTy->getTypeConstraintArguments());
5106 } else {
5107 // Otherwise, complain about the addition of a qualifier to an
5108 // already-qualified type.
5109 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5110 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5111 Quals.removeObjCLifetime();
5112 }
5113 }
5114 }
5115
5116 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5117}
5118
5119template<typename Derived>
5120TypeLoc
5122 QualType ObjectType,
5123 NamedDecl *UnqualLookup,
5124 CXXScopeSpec &SS) {
5125 if (getDerived().AlreadyTransformed(TL.getType()))
5126 return TL;
5127
5128 TypeSourceInfo *TSI =
5129 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
5130 if (TSI)
5131 return TSI->getTypeLoc();
5132 return TypeLoc();
5133}
5134
5135template<typename Derived>
5136TypeSourceInfo *
5137TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
5138 QualType ObjectType,
5139 NamedDecl *UnqualLookup,
5140 CXXScopeSpec &SS) {
5141 if (getDerived().AlreadyTransformed(TSInfo->getType()))
5142 return TSInfo;
5143
5144 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
5145 UnqualLookup, SS);
5146}
5147
5148template <typename Derived>
5149TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
5150 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
5151 CXXScopeSpec &SS) {
5152 QualType T = TL.getType();
5153 assert(!getDerived().AlreadyTransformed(T));
5154
5155 TypeLocBuilder TLB;
5156 QualType Result;
5157
5158 if (isa<TemplateSpecializationType>(T)) {
5159 TemplateSpecializationTypeLoc SpecTL =
5160 TL.castAs<TemplateSpecializationTypeLoc>();
5161
5162 TemplateName Template = getDerived().TransformTemplateName(
5163 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
5164 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
5165 if (Template.isNull())
5166 return nullptr;
5167
5168 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
5169 Template);
5170 } else if (isa<DependentTemplateSpecializationType>(T)) {
5171 DependentTemplateSpecializationTypeLoc SpecTL =
5172 TL.castAs<DependentTemplateSpecializationTypeLoc>();
5173
5174 TemplateName Template
5175 = getDerived().RebuildTemplateName(SS,
5176 SpecTL.getTemplateKeywordLoc(),
5177 *SpecTL.getTypePtr()->getIdentifier(),
5178 SpecTL.getTemplateNameLoc(),
5179 ObjectType, UnqualLookup,
5180 /*AllowInjectedClassName*/true);
5181 if (Template.isNull())
5182 return nullptr;
5183
5184 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
5185 SpecTL,
5186 Template,
5187 SS);
5188 } else {
5189 // Nothing special needs to be done for these.
5190 Result = getDerived().TransformType(TLB, TL);
5191 }
5192
5193 if (Result.isNull())
5194 return nullptr;
5195
5196 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5197}
5198
5199template <class TyLoc> static inline
5201 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5202 NewT.setNameLoc(T.getNameLoc());
5203 return T.getType();
5204}
5205
5206template<typename Derived>
5207QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5208 BuiltinTypeLoc T) {
5209 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5210 NewT.setBuiltinLoc(T.getBuiltinLoc());
5211 if (T.needsExtraLocalData())
5212 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5213 return T.getType();
5214}
5215
5216template<typename Derived>
5217QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
5218 ComplexTypeLoc T) {
5219 // FIXME: recurse?
5220 return TransformTypeSpecType(TLB, T);
5221}
5222
5223template <typename Derived>
5224QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
5225 AdjustedTypeLoc TL) {
5226 // Adjustments applied during transformation are handled elsewhere.
5227 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5228}
5229
5230template<typename Derived>
5231QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
5232 DecayedTypeLoc TL) {
5233 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5234 if (OriginalType.isNull())
5235 return QualType();
5236
5237 QualType Result = TL.getType();
5238 if (getDerived().AlwaysRebuild() ||
5239 OriginalType != TL.getOriginalLoc().getType())
5240 Result = SemaRef.Context.getDecayedType(OriginalType);
5241 TLB.push<DecayedTypeLoc>(Result);
5242 // Nothing to set for DecayedTypeLoc.
5243 return Result;
5244}
5245
5246template<typename Derived>
5247QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
5248 PointerTypeLoc TL) {
5249 QualType PointeeType
5250 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5251 if (PointeeType.isNull())
5252 return QualType();
5253
5254 QualType Result = TL.getType();
5255 if (PointeeType->getAs<ObjCObjectType>()) {
5256 // A dependent pointer type 'T *' has is being transformed such
5257 // that an Objective-C class type is being replaced for 'T'. The
5258 // resulting pointer type is an ObjCObjectPointerType, not a
5259 // PointerType.
5260 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5261
5262 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5263 NewT.setStarLoc(TL.getStarLoc());
5264 return Result;
5265 }
5266
5267 if (getDerived().AlwaysRebuild() ||
5268 PointeeType != TL.getPointeeLoc().getType()) {
5269 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5270 if (Result.isNull())
5271 return QualType();
5272 }
5273
5274 // Objective-C ARC can add lifetime qualifiers to the type that we're
5275 // pointing to.
5276 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5277
5278 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5279 NewT.setSigilLoc(TL.getSigilLoc());
5280 return Result;
5281}
5282
5283template<typename Derived>
5284QualType
5285TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
5286 BlockPointerTypeLoc TL) {
5287 QualType PointeeType
5288 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5289 if (PointeeType.isNull())
5290 return QualType();
5291
5292 QualType Result = TL.getType();
5293 if (getDerived().AlwaysRebuild() ||
5294 PointeeType != TL.getPointeeLoc().getType()) {
5295 Result = getDerived().RebuildBlockPointerType(PointeeType,
5296 TL.getSigilLoc());
5297 if (Result.isNull())
5298 return QualType();
5299 }
5300
5301 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5302 NewT.setSigilLoc(TL.getSigilLoc());
5303 return Result;
5304}
5305
5306/// Transforms a reference type. Note that somewhat paradoxically we
5307/// don't care whether the type itself is an l-value type or an r-value
5308/// type; we only care if the type was *written* as an l-value type
5309/// or an r-value type.
5310template<typename Derived>
5311QualType
5313 ReferenceTypeLoc TL) {
5314 const ReferenceType *T = TL.getTypePtr();
5315
5316 // Note that this works with the pointee-as-written.
5317 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5318 if (PointeeType.isNull())
5319 return QualType();
5320
5321 QualType Result = TL.getType();
5322 if (getDerived().AlwaysRebuild() ||
5323 PointeeType != T->getPointeeTypeAsWritten()) {
5324 Result = getDerived().RebuildReferenceType(PointeeType,
5325 T->isSpelledAsLValue(),
5326 TL.getSigilLoc());
5327 if (Result.isNull())
5328 return QualType();
5329 }
5330
5331 // Objective-C ARC can add lifetime qualifiers to the type that we're
5332 // referring to.
5335
5336 // r-value references can be rebuilt as l-value references.
5337 ReferenceTypeLoc NewTL;
5338 if (isa<LValueReferenceType>(Result))
5339 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5340 else
5341 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5342 NewTL.setSigilLoc(TL.getSigilLoc());
5343
5344 return Result;
5345}
5346
5347template<typename Derived>
5351 return TransformReferenceType(TLB, TL);
5352}
5353
5354template<typename Derived>
5355QualType
5356TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5357 RValueReferenceTypeLoc TL) {
5358 return TransformReferenceType(TLB, TL);
5359}
5360
5361template<typename Derived>
5362QualType
5363TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5364 MemberPointerTypeLoc TL) {
5365 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5366 if (PointeeType.isNull())
5367 return QualType();
5368
5369 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
5370 TypeSourceInfo *NewClsTInfo = nullptr;
5371 if (OldClsTInfo) {
5372 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
5373 if (!NewClsTInfo)
5374 return QualType();
5375 }
5376
5377 const MemberPointerType *T = TL.getTypePtr();
5378 QualType OldClsType = QualType(T->getClass(), 0);
5379 QualType NewClsType;
5380 if (NewClsTInfo)
5381 NewClsType = NewClsTInfo->getType();
5382 else {
5383 NewClsType = getDerived().TransformType(OldClsType);
5384 if (NewClsType.isNull())
5385 return QualType();
5386 }
5387
5388 QualType Result = TL.getType();
5389 if (getDerived().AlwaysRebuild() ||
5390 PointeeType != T->getPointeeType() ||
5391 NewClsType != OldClsType) {
5392 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
5393 TL.getStarLoc());
5394 if (Result.isNull())
5395 return QualType();
5396 }
5397
5398 // If we had to adjust the pointee type when building a member pointer, make
5399 // sure to push TypeLoc info for it.
5400 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5401 if (MPT && PointeeType != MPT->getPointeeType()) {
5402 assert(isa<AdjustedType>(MPT->getPointeeType()));
5403 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5404 }
5405
5406 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
5407 NewTL.setSigilLoc(TL.getSigilLoc());
5408 NewTL.setClassTInfo(NewClsTInfo);
5409
5410 return Result;
5411}
5412
5413template<typename Derived>
5414QualType
5415TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
5416 ConstantArrayTypeLoc TL) {
5417 const ConstantArrayType *T = TL.getTypePtr();
5418 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5419 if (ElementType.isNull())
5420 return QualType();
5421
5422 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5423 Expr *OldSize = TL.getSizeExpr();
5424 if (!OldSize)
5425 OldSize = const_cast<Expr*>(T->getSizeExpr());
5426 Expr *NewSize = nullptr;
5427 if (OldSize) {
5428 EnterExpressionEvaluationContext Unevaluated(
5430 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5431 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5432 }
5433
5434 QualType Result = TL.getType();
5435 if (getDerived().AlwaysRebuild() ||
5436 ElementType != T->getElementType() ||
5437 (T->getSizeExpr() && NewSize != OldSize)) {
5438 Result = getDerived().RebuildConstantArrayType(ElementType,
5439 T->getSizeModifier(),
5440 T->getSize(), NewSize,
5441 T->getIndexTypeCVRQualifiers(),
5442 TL.getBracketsRange());
5443 if (Result.isNull())
5444 return QualType();
5445 }
5446
5447 // We might have either a ConstantArrayType or a VariableArrayType now:
5448 // a ConstantArrayType is allowed to have an element type which is a
5449 // VariableArrayType if the type is dependent. Fortunately, all array
5450 // types have the same location layout.
5451 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5452 NewTL.setLBracketLoc(TL.getLBracketLoc());
5453 NewTL.setRBracketLoc(TL.getRBracketLoc());
5454 NewTL.setSizeExpr(NewSize);
5455
5456 return Result;
5457}
5458
5459template<typename Derived>
5460QualType TreeTransform<Derived>::TransformIncompleteArrayType(
5461 TypeLocBuilder &TLB,
5462 IncompleteArrayTypeLoc TL) {
5463 const IncompleteArrayType *T = TL.getTypePtr();
5464 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5465 if (ElementType.isNull())
5466 return QualType();
5467
5468 QualType Result = TL.getType();
5469 if (getDerived().AlwaysRebuild() ||
5470 ElementType != T->getElementType()) {
5471 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5472 T->getSizeModifier(),
5473 T->getIndexTypeCVRQualifiers(),
5474 TL.getBracketsRange());
5475 if (Result.isNull())
5476 return QualType();
5477 }
5478
5479 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5480 NewTL.setLBracketLoc(TL.getLBracketLoc());
5481 NewTL.setRBracketLoc(TL.getRBracketLoc());
5482 NewTL.setSizeExpr(nullptr);
5483
5484 return Result;
5485}
5486
5487template<typename Derived>
5488QualType
5489TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
5490 VariableArrayTypeLoc TL) {
5491 const VariableArrayType *T = TL.getTypePtr();
5492 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5493 if (ElementType.isNull())
5494 return QualType();
5495
5496 ExprResult SizeResult;
5497 {
5498 EnterExpressionEvaluationContext Context(
5500 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5501 }
5502 if (SizeResult.isInvalid())
5503 return QualType();
5504 SizeResult =
5505 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5506 if (SizeResult.isInvalid())
5507 return QualType();
5508
5509 Expr *Size = SizeResult.get();
5510
5511 QualType Result = TL.getType();
5512 if (getDerived().AlwaysRebuild() ||
5513 ElementType != T->getElementType() ||
5514 Size != T->getSizeExpr()) {
5515 Result = getDerived().RebuildVariableArrayType(ElementType,
5516 T->getSizeModifier(),
5517 Size,
5518 T->getIndexTypeCVRQualifiers(),
5519 TL.getBracketsRange());
5520 if (Result.isNull())
5521 return QualType();
5522 }
5523
5524 // We might have constant size array now, but fortunately it has the same
5525 // location layout.
5526 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5527 NewTL.setLBracketLoc(TL.getLBracketLoc());
5528 NewTL.setRBracketLoc(TL.getRBracketLoc());
5529 NewTL.setSizeExpr(Size);
5530
5531 return Result;
5532}
5533
5534template<typename Derived>
5535QualType
5536TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
5537 DependentSizedArrayTypeLoc TL) {
5538 const DependentSizedArrayType *T = TL.getTypePtr();
5539 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5540 if (ElementType.isNull())
5541 return QualType();
5542
5543 // Array bounds are constant expressions.
5544 EnterExpressionEvaluationContext Unevaluated(
5546
5547 // If we have a VLA then it won't be a constant.
5548 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5549
5550 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5551 Expr *origSize = TL.getSizeExpr();
5552 if (!origSize) origSize = T->getSizeExpr();
5553
5554 ExprResult sizeResult
5555 = getDerived().TransformExpr(origSize);
5556 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5557 if (sizeResult.isInvalid())
5558 return QualType();
5559
5560 Expr *size = sizeResult.get();
5561
5562 QualType Result = TL.getType();
5563 if (getDerived().AlwaysRebuild() ||
5564 ElementType != T->getElementType() ||
5565 size != origSize) {
5566 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5567 T->getSizeModifier(),
5568 size,
5569 T->getIndexTypeCVRQualifiers(),
5570 TL.getBracketsRange());
5571 if (Result.isNull())
5572 return QualType();
5573 }
5574
5575 // We might have any sort of array type now, but fortunately they
5576 // all have the same location layout.
5577 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5578 NewTL.setLBracketLoc(TL.getLBracketLoc());
5579 NewTL.setRBracketLoc(TL.getRBracketLoc());
5580 NewTL.setSizeExpr(size);
5581
5582 return Result;
5583}
5584
5585template <typename Derived>
5586QualType TreeTransform<Derived>::TransformDependentVectorType(
5587 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
5588 const DependentVectorType *T = TL.getTypePtr();
5589 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5590 if (ElementType.isNull())
5591 return QualType();
5592
5593 EnterExpressionEvaluationContext Unevaluated(
5595
5596 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5597 Size = SemaRef.ActOnConstantExpression(Size);
5598 if (Size.isInvalid())
5599 return QualType();
5600
5601 QualType Result = TL.getType();
5602 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5603 Size.get() != T->getSizeExpr()) {
5604 Result = getDerived().RebuildDependentVectorType(
5605 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5606 if (Result.isNull())
5607 return QualType();
5608 }
5609
5610 // Result might be dependent or not.
5611 if (isa<DependentVectorType>(Result)) {
5612 DependentVectorTypeLoc NewTL =
5613 TLB.push<DependentVectorTypeLoc>(Result);
5614 NewTL.setNameLoc(TL.getNameLoc());
5615 } else {
5616 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5617 NewTL.setNameLoc(TL.getNameLoc());
5618 }
5619
5620 return Result;
5621}
5622
5623template<typename Derived>
5624QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
5625 TypeLocBuilder &TLB,
5626 DependentSizedExtVectorTypeLoc TL) {
5627 const DependentSizedExtVectorType *T = TL.getTypePtr();
5628
5629 // FIXME: ext vector locs should be nested
5630 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5631 if (ElementType.isNull())
5632 return QualType();
5633
5634 // Vector sizes are constant expressions.
5635 EnterExpressionEvaluationContext Unevaluated(
5637
5638 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5639 Size = SemaRef.ActOnConstantExpression(Size);
5640 if (Size.isInvalid())
5641 return QualType();
5642
5643 QualType Result = TL.getType();
5644 if (getDerived().AlwaysRebuild() ||
5645 ElementType != T->getElementType() ||
5646 Size.get() != T->getSizeExpr()) {
5647 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5648 Size.get(),
5649 T->getAttributeLoc());
5650 if (Result.isNull())
5651 return QualType();
5652 }
5653
5654 // Result might be dependent or not.
5655 if (isa<DependentSizedExtVectorType>(Result)) {
5656 DependentSizedExtVectorTypeLoc NewTL
5657 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
5658 NewTL.setNameLoc(TL.getNameLoc());
5659 } else {
5660 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5661 NewTL.setNameLoc(TL.getNameLoc());
5662 }
5663
5664 return Result;
5665}
5666
5667template <typename Derived>
5668QualType
5669TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
5670 ConstantMatrixTypeLoc TL) {
5671 const ConstantMatrixType *T = TL.getTypePtr();
5672 QualType ElementType = getDerived().TransformType(T->getElementType());
5673 if (ElementType.isNull())
5674 return QualType();
5675
5676 QualType Result = TL.getType();
5677 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
5678 Result = getDerived().RebuildConstantMatrixType(
5679 ElementType, T->getNumRows(), T->getNumColumns());
5680 if (Result.isNull())
5681 return QualType();
5682 }
5683
5684 ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
5685 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5686 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5687 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
5688 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
5689
5690 return Result;
5691}
5692
5693template <typename Derived>
5694QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
5695 TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
5696 const DependentSizedMatrixType *T = TL.getTypePtr();
5697
5698 QualType ElementType = getDerived().TransformType(T->getElementType());
5699 if (ElementType.isNull()) {
5700 return QualType();
5701 }
5702
5703 // Matrix dimensions are constant expressions.
5704 EnterExpressionEvaluationContext Unevaluated(
5706
5707 Expr *origRows = TL.getAttrRowOperand();
5708 if (!origRows)
5709 origRows = T->getRowExpr();
5710 Expr *origColumns = TL.getAttrColumnOperand();
5711 if (!origColumns)
5712 origColumns = T->getColumnExpr();
5713
5714 ExprResult rowResult = getDerived().TransformExpr(origRows);
5715 rowResult = SemaRef.ActOnConstantExpression(rowResult);
5716 if (rowResult.isInvalid())
5717 return QualType();
5718
5719 ExprResult columnResult = getDerived().TransformExpr(origColumns);
5720 columnResult = SemaRef.ActOnConstantExpression(columnResult);
5721 if (columnResult.isInvalid())
5722 return QualType();
5723
5724 Expr *rows = rowResult.get();
5725 Expr *columns = columnResult.get();
5726
5727 QualType Result = TL.getType();
5728 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5729 rows != origRows || columns != origColumns) {
5730 Result = getDerived().RebuildDependentSizedMatrixType(
5731 ElementType, rows, columns, T->getAttributeLoc());
5732
5733 if (Result.isNull())
5734 return QualType();
5735 }
5736
5737 // We might have any sort of matrix type now, but fortunately they
5738 // all have the same location layout.
5739 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
5740 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5741 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5742 NewTL.setAttrRowOperand(rows);
5743 NewTL.setAttrColumnOperand(columns);
5744 return Result;
5745}
5746
5747template <typename Derived>
5748QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
5749 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
5750 const DependentAddressSpaceType *T = TL.getTypePtr();
5751
5752 QualType pointeeType = getDerived().TransformType(T->getPointeeType());
5753
5754 if (pointeeType.isNull())
5755 return QualType();
5756
5757 // Address spaces are constant expressions.
5758 EnterExpressionEvaluationContext Unevaluated(
5760
5761 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
5762 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
5763 if (AddrSpace.isInvalid())
5764 return QualType();
5765
5766 QualType Result = TL.getType();
5767 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
5768 AddrSpace.get() != T->getAddrSpaceExpr()) {
5769 Result = getDerived().RebuildDependentAddressSpaceType(
5770 pointeeType, AddrSpace.get(), T->getAttributeLoc());
5771 if (Result.isNull())
5772 return QualType();
5773 }
5774
5775 // Result might be dependent or not.
5776 if (isa<DependentAddressSpaceType>(Result)) {
5777 DependentAddressSpaceTypeLoc NewTL =
5778 TLB.push<DependentAddressSpaceTypeLoc>(Result);
5779
5780 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5781 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5782 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5783
5784 } else {
5785 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(
5786 Result, getDerived().getBaseLocation());
5787 TransformType(TLB, DI->getTypeLoc());
5788 }
5789
5790 return Result;
5791}
5792
5793template <typename Derived>
5794QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
5795 VectorTypeLoc TL) {
5796 const VectorType *T = TL.getTypePtr();
5797 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5798 if (ElementType.isNull())
5799 return QualType();
5800
5801 QualType Result = TL.getType();
5802 if (getDerived().AlwaysRebuild() ||
5803 ElementType != T->getElementType()) {
5804 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
5805 T->getVectorKind());
5806 if (Result.isNull())
5807 return QualType();
5808 }
5809
5810 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5811 NewTL.setNameLoc(TL.getNameLoc());
5812
5813 return Result;
5814}
5815
5816template<typename Derived>
5817QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
5818 ExtVectorTypeLoc TL) {
5819 const VectorType *T = TL.getTypePtr();
5820 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5821 if (ElementType.isNull())
5822 return QualType();
5823
5824 QualType Result = TL.getType();
5825 if (getDerived().AlwaysRebuild() ||
5826 ElementType != T->getElementType()) {
5827 Result = getDerived().RebuildExtVectorType(ElementType,
5828 T->getNumElements(),
5829 /*FIXME*/ SourceLocation());
5830 if (Result.isNull())
5831 return QualType();
5832 }
5833
5834 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5835 NewTL.setNameLoc(TL.getNameLoc());
5836
5837 return Result;
5838}
5839
5840template <typename Derived>
5842 ParmVarDecl *OldParm, int indexAdjustment,
5843 std::optional<unsigned> NumExpansions, bool ExpectParameterPack) {
5844 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
5845 TypeSourceInfo *NewDI = nullptr;
5846
5847 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
5848 // If we're substituting into a pack expansion type and we know the
5849 // length we want to expand to, just substitute for the pattern.
5850 TypeLoc OldTL = OldDI->getTypeLoc();
5851 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
5852
5853 TypeLocBuilder TLB;
5854 TypeLoc NewTL = OldDI->getTypeLoc();
5855 TLB.reserve(NewTL.getFullDataSize());
5856
5857 QualType Result = getDerived().TransformType(TLB,
5858 OldExpansionTL.getPatternLoc());
5859 if (Result.isNull())
5860 return nullptr;
5861
5862 Result = RebuildPackExpansionType(Result,
5863 OldExpansionTL.getPatternLoc().getSourceRange(),
5864 OldExpansionTL.getEllipsisLoc(),
5865 NumExpansions);
5866 if (Result.isNull())
5867 return nullptr;
5868
5869 PackExpansionTypeLoc NewExpansionTL
5870 = TLB.push<PackExpansionTypeLoc>(Result);
5871 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
5872 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
5873 } else
5874 NewDI = getDerived().TransformType(OldDI);
5875 if (!NewDI)
5876 return nullptr;
5877
5878 if (NewDI == OldDI && indexAdjustment == 0)
5879 return OldParm;
5880
5881 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
5882 OldParm->getDeclContext(),
5883 OldParm->getInnerLocStart(),
5884 OldParm->getLocation(),
5885 OldParm->getIdentifier(),
5886 NewDI->getType(),
5887 NewDI,
5888 OldParm->getStorageClass(),
5889 /* DefArg */ nullptr);
5890 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
5891 OldParm->getFunctionScopeIndex() + indexAdjustment);
5892 transformedLocalDecl(OldParm, {newParm});
5893 return newParm;
5894}
5895
5896template <typename Derived>
5899 const QualType *ParamTypes,
5900 const FunctionProtoType::ExtParameterInfo *ParamInfos,
5901 SmallVectorImpl<QualType> &OutParamTypes,
5904 unsigned *LastParamTransformed) {
5905 int indexAdjustment = 0;
5906
5907 unsigned NumParams = Params.size();
5908 for (unsigned i = 0; i != NumParams; ++i) {
5909 if (LastParamTransformed)
5910 *LastParamTransformed = i;
5911 if (ParmVarDecl *OldParm = Params[i]) {
5912 assert(OldParm->getFunctionScopeIndex() == i);
5913
5914 std::optional<unsigned> NumExpansions;
5915 ParmVarDecl *NewParm = nullptr;
5916 if (OldParm->isParameterPack()) {
5917 // We have a function parameter pack that may need to be expanded.
5919
5920 // Find the parameter packs that could be expanded.
5921 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
5923 TypeLoc Pattern = ExpansionTL.getPatternLoc();
5924 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
5925
5926 // Determine whether we should expand the parameter packs.
5927 bool ShouldExpand = false;
5928 bool RetainExpansion = false;
5929 std::optional<unsigned> OrigNumExpansions;
5930 if (Unexpanded.size() > 0) {
5931 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
5932 NumExpansions = OrigNumExpansions;
5933 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
5934 Pattern.getSourceRange(),
5935 Unexpanded,
5936 ShouldExpand,
5937 RetainExpansion,
5938 NumExpansions)) {
5939 return true;
5940 }
5941 } else {
5942#ifndef NDEBUG
5943 const AutoType *AT =
5944 Pattern.getType().getTypePtr()->getContainedAutoType();
5945 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
5946 "Could not find parameter packs or undeduced auto type!");
5947#endif
5948 }
5949
5950 if (ShouldExpand) {
5951 // Expand the function parameter pack into multiple, separate
5952 // parameters.
5953 getDerived().ExpandingFunctionParameterPack(OldParm);
5954 for (unsigned I = 0; I != *NumExpansions; ++I) {
5955 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5956 ParmVarDecl *NewParm
5957 = getDerived().TransformFunctionTypeParam(OldParm,
5958 indexAdjustment++,
5959 OrigNumExpansions,
5960 /*ExpectParameterPack=*/false);
5961 if (!NewParm)
5962 return true;
5963
5964 if (ParamInfos)
5965 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5966 OutParamTypes.push_back(NewParm->getType());
5967 if (PVars)
5968 PVars->push_back(NewParm);
5969 }
5970
5971 // If we're supposed to retain a pack expansion, do so by temporarily
5972 // forgetting the partially-substituted parameter pack.
5973 if (RetainExpansion) {
5974 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5975 ParmVarDecl *NewParm
5976 = getDerived().TransformFunctionTypeParam(OldParm,
5977 indexAdjustment++,
5978 OrigNumExpansions,
5979 /*ExpectParameterPack=*/false);
5980 if (!NewParm)
5981 return true;
5982
5983 if (ParamInfos)
5984 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
5985 OutParamTypes.push_back(NewParm->getType());
5986 if (PVars)
5987 PVars->push_back(NewParm);
5988 }
5989
5990 // The next parameter should have the same adjustment as the
5991 // last thing we pushed, but we post-incremented indexAdjustment
5992 // on every push. Also, if we push nothing, the adjustment should
5993 // go down by one.
5994 indexAdjustment--;
5995
5996 // We're done with the pack expansion.
5997 continue;
5998 }
5999
6000 // We'll substitute the parameter now without expanding the pack
6001 // expansion.
6002 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6003 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6004 indexAdjustment,
6005 NumExpansions,
6006 /*ExpectParameterPack=*/true);
6007 assert(NewParm->isParameterPack() &&
6008 "Parameter pack no longer a parameter pack after "
6009 "transformation.");
6010 } else {
6011 NewParm = getDerived().TransformFunctionTypeParam(
6012 OldParm, indexAdjustment, std::nullopt,
6013 /*ExpectParameterPack=*/false);
6014 }
6015
6016 if (!NewParm)
6017 return true;
6018
6019 if (ParamInfos)
6020 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6021 OutParamTypes.push_back(NewParm->getType());
6022 if (PVars)
6023 PVars->push_back(NewParm);
6024 continue;
6025 }
6026
6027 // Deal with the possibility that we don't have a parameter
6028 // declaration for this parameter.
6029 assert(ParamTypes);
6030 QualType OldType = ParamTypes[i];
6031 bool IsPackExpansion = false;
6032 std::optional<unsigned> NumExpansions;
6033 QualType NewType;
6034 if (const PackExpansionType *Expansion
6035 = dyn_cast<PackExpansionType>(OldType)) {
6036 // We have a function parameter pack that may need to be expanded.
6037 QualType Pattern = Expansion->getPattern();
6039 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6040
6041 // Determine whether we should expand the parameter packs.
6042 bool ShouldExpand = false;
6043 bool RetainExpansion = false;
6044 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
6045 Unexpanded,
6046 ShouldExpand,
6047 RetainExpansion,
6048 NumExpansions)) {
6049 return true;
6050 }
6051
6052 if (ShouldExpand) {
6053 // Expand the function parameter pack into multiple, separate
6054 // parameters.
6055 for (unsigned I = 0; I != *NumExpansions; ++I) {
6056 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6057 QualType NewType = getDerived().TransformType(Pattern);
6058 if (NewType.isNull())
6059 return true;
6060
6061 if (NewType->containsUnexpandedParameterPack()) {
6062 NewType = getSema().getASTContext().getPackExpansionType(
6063 NewType, std::nullopt);
6064
6065 if (NewType.isNull())
6066 return true;
6067 }
6068
6069 if (ParamInfos)
6070 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6071 OutParamTypes.push_back(NewType);
6072 if (PVars)
6073 PVars->push_back(nullptr);
6074 }
6075
6076 // We're done with the pack expansion.
6077 continue;
6078 }
6079
6080 // If we're supposed to retain a pack expansion, do so by temporarily
6081 // forgetting the partially-substituted parameter pack.
6082 if (RetainExpansion) {
6083 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6084 QualType NewType = getDerived().TransformType(Pattern);
6085 if (NewType.isNull())
6086 return true;
6087
6088 if (ParamInfos)
6089 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6090 OutParamTypes.push_back(NewType);
6091 if (PVars)
6092 PVars->push_back(nullptr);
6093 }
6094
6095 // We'll substitute the parameter now without expanding the pack
6096 // expansion.
6097 OldType = Expansion->getPattern();
6098 IsPackExpansion = true;
6099 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6100 NewType = getDerived().TransformType(OldType);
6101 } else {
6102 NewType = getDerived().TransformType(OldType);
6103 }
6104
6105 if (NewType.isNull())
6106 return true;
6107
6108 if (IsPackExpansion)
6109 NewType = getSema().Context.getPackExpansionType(NewType,
6110 NumExpansions);
6111
6112 if (ParamInfos)
6113 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6114 OutParamTypes.push_back(NewType);
6115 if (PVars)
6116 PVars->push_back(nullptr);
6117 }
6118
6119#ifndef NDEBUG
6120 if (PVars) {
6121 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6122 if (ParmVarDecl *parm = (*PVars)[i])
6123 assert(parm->getFunctionScopeIndex() == i);
6124 }
6125#endif
6126
6127 return false;
6128}
6129
6130template<typename Derived>
6134 SmallVector<QualType, 4> ExceptionStorage;
6135 return getDerived().TransformFunctionProtoType(
6136 TLB, TL, nullptr, Qualifiers(),
6137 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6138 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6139 ExceptionStorage, Changed);
6140 });
6141}
6142
6143template<typename Derived> template<typename Fn>
6145 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6146 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6147
6148 // Transform the parameters and return type.
6149 //
6150 // We are required to instantiate the params and return type in source order.
6151 // When the function has a trailing return type, we instantiate the
6152 // parameters before the return type, since the return type can then refer
6153 // to the parameters themselves (via decltype, sizeof, etc.).
6154 //
6155 SmallVector<QualType, 4> ParamTypes;
6157 Sema::ExtParameterInfoBuilder ExtParamInfos;
6158 const FunctionProtoType *T = TL.getTypePtr();
6159
6160 QualType ResultType;
6161
6162 if (T->hasTrailingReturn()) {
6163 if (getDerived().TransformFunctionTypeParams(
6164 TL.getBeginLoc(), TL.getParams(),
6167 ParamTypes, &ParamDecls, ExtParamInfos))
6168 return QualType();
6169
6170 {
6171 // C++11 [expr.prim.general]p3:
6172 // If a declaration declares a member function or member function
6173 // template of a class X, the expression this is a prvalue of type
6174 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6175 // and the end of the function-definition, member-declarator, or
6176 // declarator.
6177 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6178 Sema::CXXThisScopeRAII ThisScope(
6179 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6180
6181 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6182 if (ResultType.isNull())
6183 return QualType();
6184 }
6185 }
6186 else {
6187 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6188 if (ResultType.isNull())
6189 return QualType();
6190
6191 if (getDerived().TransformFunctionTypeParams(
6192 TL.getBeginLoc(), TL.getParams(),
6195 ParamTypes, &ParamDecls, ExtParamInfos))
6196 return QualType();
6197 }
6198
6200
6201 bool EPIChanged = false;
6202 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6203 return QualType();
6204
6205 // Handle extended parameter information.
6206 if (auto NewExtParamInfos =
6207 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6208 if (!EPI.ExtParameterInfos ||
6210 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6211 EPIChanged = true;
6212 }
6213 EPI.ExtParameterInfos = NewExtParamInfos;
6214 } else if (EPI.ExtParameterInfos) {
6215 EPIChanged = true;
6216 EPI.ExtParameterInfos = nullptr;
6217 }
6218
6219 QualType Result = TL.getType();
6220 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6221 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6222 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6223 if (Result.isNull())
6224 return QualType();
6225 }
6226
6229 NewTL.setLParenLoc(TL.getLParenLoc());
6230 NewTL.setRParenLoc(TL.getRParenLoc());
6233 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6234 NewTL.setParam(i, ParamDecls[i]);
6235
6236 return Result;
6237}
6238
6239template<typename Derived>
6242 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6243 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6244
6245 // Instantiate a dynamic noexcept expression, if any.
6246 if (isComputedNoexcept(ESI.Type)) {
6247 // Update this scrope because ContextDecl in Sema will be used in
6248 // TransformExpr.
6249 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6250 Sema::CXXThisScopeRAII ThisScope(
6251 SemaRef, Method ? Method->getParent() : nullptr,
6252 Method ? Method->getMethodQualifiers() : Qualifiers{},
6253 Method != nullptr);
6256 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6257 if (NoexceptExpr.isInvalid())
6258 return true;
6259
6261 NoexceptExpr =
6262 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6263 if (NoexceptExpr.isInvalid())
6264 return true;
6265
6266 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6267 Changed = true;
6268 ESI.NoexceptExpr = NoexceptExpr.get();
6269 ESI.Type = EST;
6270 }
6271
6272 if (ESI.Type != EST_Dynamic)
6273 return false;
6274
6275 // Instantiate a dynamic exception specification's type.
6276 for (QualType T : ESI.Exceptions) {
6277 if (const PackExpansionType *PackExpansion =
6278 T->getAs<PackExpansionType>()) {
6279 Changed = true;
6280
6281 // We have a pack expansion. Instantiate it.
6283 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6284 Unexpanded);
6285 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6286
6287 // Determine whether the set of unexpanded parameter packs can and
6288 // should
6289 // be expanded.
6290 bool Expand = false;
6291 bool RetainExpansion = false;
6292 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6293 // FIXME: Track the location of the ellipsis (and track source location
6294 // information for the types in the exception specification in general).
6295 if (getDerived().TryExpandParameterPacks(
6296 Loc, SourceRange(), Unexpanded, Expand,
6297 RetainExpansion, NumExpansions))
6298 return true;
6299
6300 if (!Expand) {
6301 // We can't expand this pack expansion into separate arguments yet;
6302 // just substitute into the pattern and create a new pack expansion
6303 // type.
6304 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6305 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6306 if (U.isNull())
6307 return true;
6308
6309 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6310 Exceptions.push_back(U);
6311 continue;
6312 }
6313
6314 // Substitute into the pack expansion pattern for each slice of the
6315 // pack.
6316 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6317 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6318
6319 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6320 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6321 return true;
6322
6323 Exceptions.push_back(U);
6324 }
6325 } else {
6326 QualType U = getDerived().TransformType(T);
6327 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6328 return true;
6329 if (T != U)
6330 Changed = true;
6331
6332 Exceptions.push_back(U);
6333 }
6334 }
6335
6336 ESI.Exceptions = Exceptions;
6337 if (ESI.Exceptions.empty())
6338 ESI.Type = EST_DynamicNone;
6339 return false;
6340}
6341
6342template<typename Derived>
6344 TypeLocBuilder &TLB,
6346 const FunctionNoProtoType *T = TL.getTypePtr();
6347 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6348 if (ResultType.isNull())
6349 return QualType();
6350
6351 QualType Result = TL.getType();
6352 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6353 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6354
6357 NewTL.setLParenLoc(TL.getLParenLoc());
6358 NewTL.setRParenLoc(TL.getRParenLoc());
6360
6361 return Result;
6362}
6363
6364template <typename Derived>
6365QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6366 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6367 const UnresolvedUsingType *T = TL.getTypePtr();
6368 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6369 if (!D)
6370 return QualType();
6371
6372 QualType Result = TL.getType();
6373 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
6374 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
6375 if (Result.isNull())
6376 return QualType();
6377 }
6378
6379 // We might get an arbitrary type spec type back. We should at
6380 // least always get a type spec type, though.
6381 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
6382 NewTL.setNameLoc(TL.getNameLoc());
6383
6384 return Result;
6385}
6386
6387template <typename Derived>
6388QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
6389 UsingTypeLoc TL) {
6390 const UsingType *T = TL.getTypePtr();
6391
6392 auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl(
6393 TL.getLocalSourceRange().getBegin(), T->getFoundDecl()));
6394 if (!Found)
6395 return QualType();
6396
6397 QualType Underlying = getDerived().TransformType(T->desugar());
6398 if (Underlying.isNull())
6399 return QualType();
6400
6401 QualType Result = TL.getType();
6402 if (getDerived().AlwaysRebuild() || Found != T->getFoundDecl() ||
6403 Underlying != T->getUnderlyingType()) {
6404 Result = getDerived().RebuildUsingType(Found, Underlying);
6405 if (Result.isNull())
6406 return QualType();
6407 }
6408
6409 TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc());
6410 return Result;
6411}
6412
6413template<typename Derived>
6414QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
6415 TypedefTypeLoc TL) {
6416 const TypedefType *T = TL.getTypePtr();
6417 TypedefNameDecl *Typedef
6418 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6419 T->getDecl()));
6420 if (!Typedef)
6421 return QualType();
6422
6423 QualType Result = TL.getType();
6424 if (getDerived().AlwaysRebuild() ||
6425 Typedef != T->getDecl()) {
6426 Result = getDerived().RebuildTypedefType(Typedef);
6427 if (Result.isNull())
6428 return QualType();
6429 }
6430
6431 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
6432 NewTL.setNameLoc(TL.getNameLoc());
6433
6434 return Result;
6435}
6436
6437template<typename Derived>
6438QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
6439 TypeOfExprTypeLoc TL) {
6440 // typeof expressions are not potentially evaluated contexts
6441 EnterExpressionEvaluationContext Unevaluated(
6444
6445 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6446 if (E.isInvalid())
6447 return QualType();
6448
6449 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6450 if (E.isInvalid())
6451 return QualType();
6452
6453 QualType Result = TL.getType();
6454 TypeOfKind Kind = Result->getAs<TypeOfExprType>()->getKind();
6455 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6456 Result =
6457 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6458 if (Result.isNull())
6459 return QualType();
6460 }
6461
6462 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6463 NewTL.setTypeofLoc(TL.getTypeofLoc());
6464 NewTL.setLParenLoc(TL.getLParenLoc());
6465 NewTL.setRParenLoc(TL.getRParenLoc());
6466
6467 return Result;
6468}
6469
6470template<typename Derived>
6471QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
6472 TypeOfTypeLoc TL) {
6473 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6474 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6475 if (!New_Under_TI)
6476 return QualType();
6477
6478 QualType Result = TL.getType();
6479 TypeOfKind Kind = Result->getAs<TypeOfType>()->getKind();
6480 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6481 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6482 if (Result.isNull())
6483 return QualType();
6484 }
6485
6486 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6487 NewTL.setTypeofLoc(TL.getTypeofLoc());
6488 NewTL.setLParenLoc(TL.getLParenLoc());
6489 NewTL.setRParenLoc(TL.getRParenLoc());
6490 NewTL.setUnmodifiedTInfo(New_Under_TI);
6491
6492 return Result;
6493}
6494
6495template<typename Derived>
6496QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
6497 DecltypeTypeLoc TL) {
6498 const DecltypeType *T = TL.getTypePtr();
6499
6500 // decltype expressions are not potentially evaluated contexts
6501 EnterExpressionEvaluationContext Unevaluated(
6504
6505 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6506 if (E.isInvalid())
6507 return QualType();
6508
6509 E = getSema().ActOnDecltypeExpression(E.get());
6510 if (E.isInvalid())
6511 return QualType();
6512
6513 QualType Result = TL.getType();
6514 if (getDerived().AlwaysRebuild() ||
6515 E.get() != T->getUnderlyingExpr()) {
6516 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6517 if (Result.isNull())
6518 return QualType();
6519 }
6520 else E.get();
6521
6522 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6523 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6524 NewTL.setRParenLoc(TL.getRParenLoc());
6525 return Result;
6526}
6527
6528template <typename Derived>
6529QualType
6530TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
6531 PackIndexingTypeLoc TL) {
6532 // Transform the index
6533 ExprResult IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6534 if (IndexExpr.isInvalid())
6535 return QualType();
6536 QualType Pattern = TL.getPattern();
6537
6538 const PackIndexingType *PIT = TL.getTypePtr();
6539 SmallVector<QualType, 5> SubtitutedTypes;
6540 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6541
6542 bool NotYetExpanded = Types.empty();
6543 bool FullySubstituted = true;
6544
6545 if (Types.empty())
6546 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
6547
6548 for (const QualType &T : Types) {
6549 if (!T->containsUnexpandedParameterPack()) {
6550 QualType Transformed = getDerived().TransformType(T);
6551 if (Transformed.isNull())
6552 return QualType();
6553 SubtitutedTypes.push_back(Transformed);
6554 continue;
6555 }
6556
6558 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
6559 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6560 // Determine whether the set of unexpanded parameter packs can and should
6561 // be expanded.
6562 bool ShouldExpand = true;
6563 bool RetainExpansion = false;
6564 std::optional<unsigned> OrigNumExpansions;
6565 std::optional<unsigned> NumExpansions = OrigNumExpansions;
6566 if (getDerived().TryExpandParameterPacks(TL.getEllipsisLoc(), SourceRange(),
6567 Unexpanded, ShouldExpand,
6568 RetainExpansion, NumExpansions))
6569 return QualType();
6570 if (!ShouldExpand) {
6571 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6572 // FIXME: should we keep TypeLoc for individual expansions in
6573 // PackIndexingTypeLoc?
6574 TypeSourceInfo *TI =
6575 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
6576 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
6577 if (Pack.isNull())
6578 return QualType();
6579 if (NotYetExpanded) {
6580 FullySubstituted = false;
6581 QualType Out = getDerived().RebuildPackIndexingType(
6582 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6583 FullySubstituted);
6584 if (Out.isNull())
6585 return QualType();
6586
6587 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6588 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6589 return Out;
6590 }
6591 SubtitutedTypes.push_back(Pack);
6592 continue;
6593 }
6594 for (unsigned I = 0; I != *NumExpansions; ++I) {
6595 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6596 QualType Out = getDerived().TransformType(T);
6597 if (Out.isNull())
6598 return QualType();
6599 SubtitutedTypes.push_back(Out);
6600 }
6601 // If we're supposed to retain a pack expansion, do so by temporarily
6602 // forgetting the partially-substituted parameter pack.
6603 if (RetainExpansion) {
6604 FullySubstituted = false;
6605 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6606 QualType Out = getDerived().TransformType(T);
6607 if (Out.isNull())
6608 return QualType();
6609 SubtitutedTypes.push_back(Out);
6610 }
6611 }
6612
6613 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
6614
6615 QualType Out = getDerived().RebuildPackIndexingType(
6616 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6617 FullySubstituted, SubtitutedTypes);
6618 if (Out.isNull())
6619 return Out;
6620
6621 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6622 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6623 return Out;
6624}
6625
6626template<typename Derived>
6627QualType TreeTransform<Derived>::TransformUnaryTransformType(
6628 TypeLocBuilder &TLB,
6629 UnaryTransformTypeLoc TL) {
6630 QualType Result = TL.getType();
6631 if (Result->isDependentType()) {
6632 const UnaryTransformType *T = TL.getTypePtr();
6633 QualType NewBase =
6634 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
6635 Result = getDerived().RebuildUnaryTransformType(NewBase,
6636 T->getUTTKind(),
6637 TL.getKWLoc());
6638 if (Result.isNull())
6639 return QualType();
6640 }
6641
6642 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
6643 NewTL.setKWLoc(TL.getKWLoc());
6644 NewTL.setParensRange(TL.getParensRange());
6645 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
6646 return Result;
6647}
6648
6649template<typename Derived>
6650QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
6651 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
6652 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
6653
6654 CXXScopeSpec SS;
6655 TemplateName TemplateName = getDerived().TransformTemplateName(
6656 SS, T->getTemplateName(), TL.getTemplateNameLoc());
6657 if (TemplateName.isNull())
6658 return QualType();
6659
6660 QualType OldDeduced = T->getDeducedType();
6661 QualType NewDeduced;
6662 if (!OldDeduced.isNull()) {
6663 NewDeduced = getDerived().TransformType(OldDeduced);
6664 if (NewDeduced.isNull())
6665 return QualType();
6666 }
6667
6668 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
6669 TemplateName, NewDeduced);
6670 if (Result.isNull())
6671 return QualType();
6672
6673 DeducedTemplateSpecializationTypeLoc NewTL =
6674 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
6675 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6676
6677 return Result;
6678}
6679
6680template<typename Derived>
6681QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
6682 RecordTypeLoc TL) {
6683 const RecordType *T = TL.getTypePtr();
6684 RecordDecl *Record
6685 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6686 T->getDecl()));
6687 if (!Record)
6688 return QualType();
6689
6690 QualType Result = TL.getType();
6691 if (getDerived().AlwaysRebuild() ||
6692 Record != T->getDecl()) {
6693 Result = getDerived().RebuildRecordType(Record);
6694 if (Result.isNull())
6695 return QualType();
6696 }
6697
6698 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
6699 NewTL.setNameLoc(TL.getNameLoc());
6700
6701 return Result;
6702}
6703
6704template<typename Derived>
6705QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
6706 EnumTypeLoc TL) {
6707 const EnumType *T = TL.getTypePtr();
6708 EnumDecl *Enum
6709 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6710 T->getDecl()));
6711 if (!Enum)
6712 return QualType();
6713
6714 QualType Result = TL.getType();
6715 if (getDerived().AlwaysRebuild() ||
6716 Enum != T->getDecl()) {
6717 Result = getDerived().RebuildEnumType(Enum);
6718 if (Result.isNull())
6719 return QualType();
6720 }
6721
6722 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
6723 NewTL.setNameLoc(TL.getNameLoc());
6724
6725 return Result;
6726}
6727
6728template<typename Derived>
6729QualType TreeTransform<Derived>::TransformInjectedClassNameType(
6730 TypeLocBuilder &TLB,
6731 InjectedClassNameTypeLoc TL) {
6732 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
6733 TL.getTypePtr()->getDecl());
6734 if (!D) return QualType();
6735
6736 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
6737 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
6738 return T;
6739}
6740
6741template<typename Derived>
6743 TypeLocBuilder &TLB,
6745 return getDerived().TransformTemplateTypeParmType(
6746 TLB, TL,
6747 /*SuppressObjCLifetime=*/false);
6748}
6749
6750template <typename Derived>
6752 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
6753 return TransformTypeSpecType(TLB, TL);
6754}
6755
6756template<typename Derived>
6757QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
6758 TypeLocBuilder &TLB,
6759 SubstTemplateTypeParmTypeLoc TL) {
6760 const SubstTemplateTypeParmType *T = TL.getTypePtr();
6761
6762 Decl *NewReplaced =
6763 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
6764
6765 // Substitute into the replacement type, which itself might involve something
6766 // that needs to be transformed. This only tends to occur with default
6767 // template arguments of template template parameters.
6768 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
6769 QualType Replacement = getDerived().TransformType(T->getReplacementType());
6770 if (Replacement.isNull())
6771 return QualType();
6772
6773 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
6774 Replacement, NewReplaced, T->getIndex(), T->getPackIndex());
6775
6776 // Propagate type-source information.
6777 SubstTemplateTypeParmTypeLoc NewTL
6778 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
6779 NewTL.setNameLoc(TL.getNameLoc());
6780 return Result;
6781
6782}
6783
6784template<typename Derived>
6786 TypeLocBuilder &TLB,
6788 return getDerived().TransformSubstTemplateTypeParmPackType(
6789 TLB, TL, /*SuppressObjCLifetime=*/false);
6790}
6791
6792template <typename Derived>
6795 return TransformTypeSpecType(TLB, TL);
6796}
6797
6798template<typename Derived>
6800 TypeLocBuilder &TLB,
6802 const TemplateSpecializationType *T = TL.getTypePtr();
6803
6804 // The nested-name-specifier never matters in a TemplateSpecializationType,
6805 // because we can't have a dependent nested-name-specifier anyway.
6806 CXXScopeSpec SS;
6807 TemplateName Template
6808 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
6809 TL.getTemplateNameLoc());
6810 if (Template.isNull())
6811 return QualType();
6812
6813 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
6814}
6815
6816template<typename Derived>
6818 AtomicTypeLoc TL) {
6819 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
6820 if (ValueType.isNull())
6821 return QualType();
6822
6823 QualType Result = TL.getType();
6824 if (getDerived().AlwaysRebuild() ||
6825 ValueType != TL.getValueLoc().getType()) {
6826 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
6827 if (Result.isNull())
6828 return QualType();
6829 }
6830
6831 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
6832 NewTL.setKWLoc(TL.getKWLoc());
6833 NewTL.setLParenLoc(TL.getLParenLoc());
6834 NewTL.setRParenLoc(TL.getRParenLoc());
6835
6836 return Result;
6837}
6838
6839template <typename Derived>
6840QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
6841 PipeTypeLoc TL) {
6842 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
6843 if (ValueType.isNull())
6844 return QualType();
6845
6846 QualType Result = TL.getType();
6847 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
6848 const PipeType *PT = Result->castAs<PipeType>();
6849 bool isReadPipe = PT->isReadOnly();
6850 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
6851 if (Result.isNull())
6852 return QualType();
6853 }
6854
6855 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
6856 NewTL.setKWLoc(TL.getKWLoc());
6857
6858 return Result;
6859}
6860
6861template <typename Derived>
6862QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
6863 BitIntTypeLoc TL) {
6864 const BitIntType *EIT = TL.getTypePtr();
6865 QualType Result = TL.getType();
6866
6867 if (getDerived().AlwaysRebuild()) {
6868 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
6869 EIT->getNumBits(), TL.getNameLoc());
6870 if (Result.isNull())
6871 return QualType();
6872 }
6873
6874 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
6875 NewTL.setNameLoc(TL.getNameLoc());
6876 return Result;
6877}
6878
6879template <typename Derived>
6880QualType TreeTransform<Derived>::TransformDependentBitIntType(
6881 TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) {
6882 const DependentBitIntType *EIT = TL.getTypePtr();
6883
6884 EnterExpressionEvaluationContext Unevaluated(
6886 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
6887 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
6888
6889 if (BitsExpr.isInvalid())
6890 return QualType();
6891
6892 QualType Result = TL.getType();
6893
6894 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
6895 Result = getDerived().RebuildDependentBitIntType(
6896 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
6897
6898 if (Result.isNull())
6899 return QualType();
6900 }
6901
6902 if (isa<DependentBitIntType>(Result)) {
6903 DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
6904 NewTL.setNameLoc(TL.getNameLoc());
6905 } else {
6906 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
6907 NewTL.setNameLoc(TL.getNameLoc());
6908 }
6909 return Result;
6910}
6911
6912 /// Simple iterator that traverses the template arguments in a
6913 /// container that provides a \c getArgLoc() member function.
6914 ///
6915 /// This iterator is intended to be used with the iterator form of
6916 /// \c TreeTransform<Derived>::TransformTemplateArguments().
6917 template<typename ArgLocContainer>
6919 ArgLocContainer *Container;
6920 unsigned Index;
6921
6922 public:
6925 typedef int difference_type;
6926 typedef std::input_iterator_tag iterator_category;
6927
6928 class pointer {
6930
6931 public:
6932 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
6933
6935 return &Arg;
6936 }
6937 };
6938
6939
6941
6942 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
6943 unsigned Index)
6944 : Container(&Container), Index(Index) { }
6945
6947 ++Index;
6948 return *this;
6949 }
6950
6953 ++(*this);
6954 return Old;
6955 }
6956
6958 return Container->getArgLoc(Index);
6959 }
6960
6962 return pointer(Container->getArgLoc(Index));
6963 }
6964
6967 return X.Container == Y.Container && X.Index == Y.Index;
6968 }
6969
6972 return !(X == Y);
6973 }
6974 };
6975
6976template<typename Derived>
6977QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
6978 AutoTypeLoc TL) {
6979 const AutoType *T = TL.getTypePtr();
6980 QualType OldDeduced = T->getDeducedType();
6981 QualType NewDeduced;
6982 if (!OldDeduced.isNull()) {
6983 NewDeduced = getDerived().TransformType(OldDeduced);
6984 if (NewDeduced.isNull())
6985 return QualType();
6986 }
6987
6988 ConceptDecl *NewCD = nullptr;
6989 TemplateArgumentListInfo NewTemplateArgs;
6990 NestedNameSpecifierLoc NewNestedNameSpec;
6991 if (T->isConstrained()) {
6992 assert(TL.getConceptReference());
6993 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
6994 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
6995
6996 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
6997 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
6998 typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator;
6999 if (getDerived().TransformTemplateArguments(
7000 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7001 NewTemplateArgs))
7002 return QualType();
7003
7004 if (TL.getNestedNameSpecifierLoc()) {
7005 NewNestedNameSpec
7006 = getDerived().TransformNestedNameSpecifierLoc(
7007 TL.getNestedNameSpecifierLoc());
7008 if (!NewNestedNameSpec)
7009 return QualType();
7010 }
7011 }
7012
7013 QualType Result = TL.getType();
7014 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7015 T->isDependentType() || T->isConstrained()) {
7016 // FIXME: Maybe don't rebuild if all template arguments are the same.
7018 NewArgList.reserve(NewTemplateArgs.size());
7019 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7020 NewArgList.push_back(ArgLoc.getArgument());
7021 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7022 NewArgList);
7023 if (Result.isNull())
7024 return QualType();
7025 }
7026
7027 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7028 NewTL.setNameLoc(TL.getNameLoc());
7029 NewTL.setRParenLoc(TL.getRParenLoc());
7030 NewTL.setConceptReference(nullptr);
7031
7032 if (T->isConstrained()) {
7033 DeclarationNameInfo DNI = DeclarationNameInfo(
7034 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7035 TL.getConceptNameLoc(),
7036 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7037 auto *CR = ConceptReference::Create(
7038 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7039 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7040 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7041 NewTL.setConceptReference(CR);
7042 }
7043
7044 return Result;
7045}
7046
7047template <typename Derived>
7049 TypeLocBuilder &TLB,
7050 TemplateSpecializationTypeLoc TL,
7051 TemplateName Template) {
7052 TemplateArgumentListInfo NewTemplateArgs;
7053 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7054 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7055 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
7056 ArgIterator;
7057 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7058 ArgIterator(TL, TL.getNumArgs()),
7059 NewTemplateArgs))
7060 return QualType();
7061
7062 // FIXME: maybe don't rebuild if all the template arguments are the same.
7063
7064 QualType Result =
7065 getDerived().RebuildTemplateSpecializationType(Template,
7066 TL.getTemplateNameLoc(),
7067 NewTemplateArgs);
7068
7069 if (!Result.isNull()) {
7070 // Specializations of template template parameters are represented as
7071 // TemplateSpecializationTypes, and substitution of type alias templates
7072 // within a dependent context can transform them into
7073 // DependentTemplateSpecializationTypes.
7074 if (isa<DependentTemplateSpecializationType>(Result)) {
7075 DependentTemplateSpecializationTypeLoc NewTL
7076 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
7077 NewTL.setElaboratedKeywordLoc(SourceLocation());
7078 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
7079 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7080 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7081 NewTL.setLAngleLoc(TL.getLAngleLoc());
7082 NewTL.setRAngleLoc(TL.getRAngleLoc());
7083 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7084 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7085 return Result;
7086 }
7087
7088 TemplateSpecializationTypeLoc NewTL
7089 = TLB.push<TemplateSpecializationTypeLoc>(Result);
7090 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7091 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7092 NewTL.setLAngleLoc(TL.getLAngleLoc());
7093 NewTL.setRAngleLoc(TL.getRAngleLoc());
7094 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7095 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7096 }
7097
7098 return Result;
7099}
7100
7101template <typename Derived>
7103 TypeLocBuilder &TLB,
7105 TemplateName Template,
7106 CXXScopeSpec &SS) {
7107 TemplateArgumentListInfo NewTemplateArgs;
7108 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7109 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7112 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7113 ArgIterator(TL, TL.getNumArgs()),
7114 NewTemplateArgs))
7115 return QualType();
7116
7117 // FIXME: maybe don't rebuild if all the template arguments are the same.
7118
7119 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
7120 QualType Result = getSema().Context.getDependentTemplateSpecializationType(
7121 TL.getTypePtr()->getKeyword(), DTN->getQualifier(),
7122 DTN->getIdentifier(), NewTemplateArgs.arguments());
7123
7127 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
7130 NewTL.setLAngleLoc(TL.getLAngleLoc());
7131 NewTL.setRAngleLoc(TL.getRAngleLoc());
7132 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7133 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7134 return Result;
7135 }
7136
7138 = getDerived().RebuildTemplateSpecializationType(Template,
7139 TL.getTemplateNameLoc(),
7140 NewTemplateArgs);
7141
7142 if (!Result.isNull()) {
7143 /// FIXME: Wrap this in an elaborated-type-specifier?
7148 NewTL.setLAngleLoc(TL.getLAngleLoc());
7149 NewTL.setRAngleLoc(TL.getRAngleLoc());
7150 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7151 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7152 }
7153
7154 return Result;
7155}
7156
7157template<typename Derived>
7160 ElaboratedTypeLoc TL) {
7161 const ElaboratedType *T = TL.getTypePtr();
7162
7163 NestedNameSpecifierLoc QualifierLoc;
7164 // NOTE: the qualifier in an ElaboratedType is optional.
7165 if (TL.getQualifierLoc()) {
7166 QualifierLoc
7167 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7168 if (!QualifierLoc)
7169 return QualType();
7170 }
7171
7172 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
7173 if (NamedT.isNull())
7174 return QualType();
7175
7176 // C++0x [dcl.type.elab]p2:
7177 // If the identifier resolves to a typedef-name or the simple-template-id
7178 // resolves to an alias template specialization, the
7179 // elaborated-type-specifier is ill-formed.
7182 if (const TemplateSpecializationType *TST =
7183 NamedT->getAs<TemplateSpecializationType>()) {
7184 TemplateName Template = TST->getTemplateName();
7185 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
7186 Template.getAsTemplateDecl())) {
7187 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
7188 diag::err_tag_reference_non_tag)
7190 << llvm::to_underlying(
7192 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
7193 }
7194 }
7195 }
7196
7197 QualType Result = TL.getType();
7198 if (getDerived().AlwaysRebuild() ||
7199 QualifierLoc != TL.getQualifierLoc() ||
7200 NamedT != T->getNamedType()) {
7201 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
7202 T->getKeyword(),
7203 QualifierLoc, NamedT);
7204 if (Result.isNull())
7205 return QualType();
7206 }
7207
7208 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7209 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7210 NewTL.setQualifierLoc(QualifierLoc);
7211 return Result;
7212}
7213
7214template <typename Derived>
7215template <typename Fn>
7217 TypeLocBuilder &TLB, AttributedTypeLoc TL, Fn TransformModifiedTypeFn) {
7218 const AttributedType *oldType = TL.getTypePtr();
7219 QualType modifiedType = TransformModifiedTypeFn(TLB, TL.getModifiedLoc());
7220 if (modifiedType.isNull())
7221 return QualType();
7222
7223 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7224 const Attr *oldAttr = TL.getAttr();
7225 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7226 if (oldAttr && !newAttr)
7227 return QualType();
7228
7229 QualType result = TL.getType();
7230
7231 // FIXME: dependent operand expressions?
7232 if (getDerived().AlwaysRebuild() ||
7233 modifiedType != oldType->getModifiedType()) {
7234 TypeLocBuilder AuxiliaryTLB;
7235 AuxiliaryTLB.reserve(TL.getFullDataSize());
7236 QualType equivalentType =
7237 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7238 if (equivalentType.isNull())
7239 return QualType();
7240
7241 // Check whether we can add nullability; it is only represented as
7242 // type sugar, and therefore cannot be diagnosed in any other way.
7243 if (auto nullability = oldType->getImmediateNullability()) {
7244 if (!modifiedType->canHaveNullability()) {
7245 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7246 : TL.getModifiedLoc().getBeginLoc()),
7247 diag::err_nullability_nonpointer)
7248 << DiagNullabilityKind(*nullability, false) << modifiedType;
7249 return QualType();
7250 }
7251 }
7252
7253 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7254 modifiedType,
7255 equivalentType);
7256 }
7257
7258 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7259 newTL.setAttr(newAttr);
7260 return result;
7261}
7262
7263template <typename Derived>
7265 AttributedTypeLoc TL) {
7266 return getDerived().TransformAttributedType(
7267 TLB, TL, [&](TypeLocBuilder &TLB, TypeLoc ModifiedLoc) -> QualType {
7268 return getDerived().TransformType(TLB, ModifiedLoc);
7269 });
7270}
7271
7272template <typename Derived>
7275 // The BTFTagAttributedType is available for C only.
7276 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7277}
7278
7279template<typename Derived>
7280QualType
7281TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
7282 ParenTypeLoc TL) {
7283 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7284 if (Inner.isNull())
7285 return QualType();
7286
7287 QualType Result = TL.getType();
7288 if (getDerived().AlwaysRebuild() ||
7289 Inner != TL.getInnerLoc().getType()) {
7290 Result = getDerived().RebuildParenType(Inner);
7291 if (Result.isNull())
7292 return QualType();
7293 }
7294
7295 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7296 NewTL.setLParenLoc(TL.getLParenLoc());
7297 NewTL.setRParenLoc(TL.getRParenLoc());
7298 return Result;
7299}
7300
7301template <typename Derived>
7302QualType
7303TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
7304 MacroQualifiedTypeLoc TL) {
7305 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7306 if (Inner.isNull())
7307 return QualType();
7308
7309 QualType Result = TL.getType();
7310 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7311 Result =
7312 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7313 if (Result.isNull())
7314 return QualType();
7315 }
7316
7317 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
7318 NewTL.setExpansionLoc(TL.getExpansionLoc());
7319 return Result;
7320}
7321
7322template<typename Derived>
7323QualType TreeTransform<Derived>::TransformDependentNameType(
7324 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
7325 return TransformDependentNameType(TLB, TL, false);
7326}
7327
7328template<typename Derived>
7329QualType TreeTransform<Derived>::TransformDependentNameType(
7330 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
7331 const DependentNameType *T = TL.getTypePtr();
7332
7333 NestedNameSpecifierLoc QualifierLoc
7334 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7335 if (!QualifierLoc)
7336 return QualType();
7337
7338 QualType Result
7339 = getDerived().RebuildDependentNameType(T->getKeyword(),
7340 TL.getElaboratedKeywordLoc(),
7341 QualifierLoc,
7342 T->getIdentifier(),
7343 TL.getNameLoc(),
7344 DeducedTSTContext);
7345 if (Result.isNull())
7346 return QualType();
7347
7348 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
7349 QualType NamedT = ElabT->getNamedType();
7350 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
7351
7352 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7353 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7354 NewTL.setQualifierLoc(QualifierLoc);
7355 } else {
7356 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
7357 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7358 NewTL.setQualifierLoc(QualifierLoc);
7359 NewTL.setNameLoc(TL.getNameLoc());
7360 }
7361 return Result;
7362}
7363
7364template<typename Derived>
7367 DependentTemplateSpecializationTypeLoc TL) {
7368 NestedNameSpecifierLoc QualifierLoc;
7369 if (TL.getQualifierLoc()) {
7370 QualifierLoc
7371 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7372 if (!QualifierLoc)
7373 return QualType();
7374 }
7375
7376 return getDerived()
7377 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
7378}
7379
7380template<typename Derived>
7384 NestedNameSpecifierLoc QualifierLoc) {
7386
7387 TemplateArgumentListInfo NewTemplateArgs;
7388 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7389 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7390
7393 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7394 ArgIterator(TL, TL.getNumArgs()),
7395 NewTemplateArgs))
7396 return QualType();
7397
7398 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
7399 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
7400 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
7401 /*AllowInjectedClassName*/ false);
7402 if (Result.isNull())
7403 return QualType();
7404
7405 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
7406 QualType NamedT = ElabT->getNamedType();
7407
7408 // Copy information relevant to the template specialization.
7410 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
7413 NamedTL.setLAngleLoc(TL.getLAngleLoc());
7414 NamedTL.setRAngleLoc(TL.getRAngleLoc());
7415 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7416 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7417
7418 // Copy information relevant to the elaborated type.
7421 NewTL.setQualifierLoc(QualifierLoc);
7422 } else if (isa<DependentTemplateSpecializationType>(Result)) {
7426 SpecTL.setQualifierLoc(QualifierLoc);
7429 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7430 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7431 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7432 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7433 } else {
7438 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7439 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7440 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7441 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7442 }
7443 return Result;
7444}
7445
7446template<typename Derived>
7449 QualType Pattern
7450 = getDerived().TransformType(TLB, TL.getPatternLoc());
7451 if (Pattern.isNull())
7452 return QualType();
7453
7454 QualType Result = TL.getType();
7455 if (getDerived().AlwaysRebuild() ||
7456 Pattern != TL.getPatternLoc().getType()) {
7457 Result = getDerived().RebuildPackExpansionType(Pattern,
7459 TL.getEllipsisLoc(),
7461 if (Result.isNull())
7462 return QualType();
7463 }
7464
7465 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
7466 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7467 return Result;
7468}
7469
7470template<typename Derived>
7471QualType
7472TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
7473 ObjCInterfaceTypeLoc TL) {
7474 // ObjCInterfaceType is never dependent.
7475 TLB.pushFullCopy(TL);
7476 return TL.getType();
7477}
7478
7479template<typename Derived>
7480QualType
7481TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
7482 ObjCTypeParamTypeLoc TL) {
7483 const ObjCTypeParamType *T = TL.getTypePtr();
7484 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7485 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7486 if (!OTP)
7487 return QualType();
7488
7489 QualType Result = TL.getType();
7490 if (getDerived().AlwaysRebuild() ||
7491 OTP != T->getDecl()) {
7492 Result = getDerived().RebuildObjCTypeParamType(
7493 OTP, TL.getProtocolLAngleLoc(),
7494 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7495 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7496 if (Result.isNull())
7497 return QualType();
7498 }
7499
7500 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
7501 if (TL.getNumProtocols()) {
7502 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7503 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7504 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7505 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7506 }
7507 return Result;
7508}
7509
7510template<typename Derived>
7511QualType
7512TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
7513 ObjCObjectTypeLoc TL) {
7514 // Transform base type.
7515 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7516 if (BaseType.isNull())
7517 return QualType();
7518
7519 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7520
7521 // Transform type arguments.
7522 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7523 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7524 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7525 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7526 QualType TypeArg = TypeArgInfo->getType();
7527 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7528 AnyChanged = true;
7529
7530 // We have a pack expansion. Instantiate it.
7531 const auto *PackExpansion = PackExpansionLoc.getType()
7532 ->castAs<PackExpansionType>();
7534 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7535 Unexpanded);
7536 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7537
7538 // Determine whether the set of unexpanded parameter packs can
7539 // and should be expanded.
7540 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7541 bool Expand = false;
7542 bool RetainExpansion = false;
7543 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
7544 if (getDerived().TryExpandParameterPacks(
7545 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7546 Unexpanded, Expand, RetainExpansion, NumExpansions))
7547 return QualType();
7548
7549 if (!Expand) {
7550 // We can't expand this pack expansion into separate arguments yet;
7551 // just substitute into the pattern and create a new pack expansion
7552 // type.
7553 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7554
7555 TypeLocBuilder TypeArgBuilder;
7556 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7557 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7558 PatternLoc);
7559 if (NewPatternType.isNull())
7560 return QualType();
7561
7562 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7563 NewPatternType, NumExpansions);
7564 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7565 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7566 NewTypeArgInfos.push_back(
7567 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7568 continue;
7569 }
7570
7571 // Substitute into the pack expansion pattern for each slice of the
7572 // pack.
7573 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7574 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
7575
7576 TypeLocBuilder TypeArgBuilder;
7577 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7578
7579 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7580 PatternLoc);
7581 if (NewTypeArg.isNull())
7582 return QualType();
7583
7584 NewTypeArgInfos.push_back(
7585 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7586 }
7587
7588 continue;
7589 }
7590
7591 TypeLocBuilder TypeArgBuilder;
7592 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7593 QualType NewTypeArg =
7594 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7595 if (NewTypeArg.isNull())
7596 return QualType();
7597
7598 // If nothing changed, just keep the old TypeSourceInfo.
7599 if (NewTypeArg == TypeArg) {
7600 NewTypeArgInfos.push_back(TypeArgInfo);
7601 continue;
7602 }
7603
7604 NewTypeArgInfos.push_back(
7605 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7606 AnyChanged = true;
7607 }
7608
7609 QualType Result = TL.getType();
7610 if (getDerived().AlwaysRebuild() || AnyChanged) {
7611 // Rebuild the type.
7612 Result = getDerived().RebuildObjCObjectType(
7613 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
7614 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
7615 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7616 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7617
7618 if (Result.isNull())
7619 return QualType();
7620 }
7621
7622 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
7623 NewT.setHasBaseTypeAsWritten(true);
7624 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
7625 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
7626 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
7627 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
7628 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7629 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7630 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
7631 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7632 return Result;
7633}
7634
7635template<typename Derived>
7636QualType
7637TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
7638 ObjCObjectPointerTypeLoc TL) {
7639 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7640 if (PointeeType.isNull())
7641 return QualType();
7642
7643 QualType Result = TL.getType();
7644 if (getDerived().AlwaysRebuild() ||
7645 PointeeType != TL.getPointeeLoc().getType()) {
7646 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7647 TL.getStarLoc());
7648 if (Result.isNull())
7649 return QualType();
7650 }
7651
7652 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
7653 NewT.setStarLoc(TL.getStarLoc());
7654 return Result;
7655}
7656
7657//===----------------------------------------------------------------------===//
7658// Statement transformation
7659//===----------------------------------------------------------------------===//
7660template<typename Derived>
7662TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
7663 return S;
7664}
7665
7666template<typename Derived>
7669 return getDerived().TransformCompoundStmt(S, false);
7670}
7671
7672template<typename Derived>
7675 bool IsStmtExpr) {
7676 Sema::CompoundScopeRAII CompoundScope(getSema());
7677 Sema::FPFeaturesStateRAII FPSave(getSema());
7678 if (S->hasStoredFPFeatures())
7679 getSema().resetFPOptions(
7680 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
7681
7682 const Stmt *ExprResult = S->getStmtExprResult();
7683 bool SubStmtInvalid = false;
7684 bool SubStmtChanged = false;
7685 SmallVector<Stmt*, 8> Statements;
7686 for (auto *B : S->body()) {
7687 StmtResult Result = getDerived().TransformStmt(
7688 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
7689
7690 if (Result.isInvalid()) {
7691 // Immediately fail if this was a DeclStmt, since it's very
7692 // likely that this will cause problems for future statements.
7693 if (isa<DeclStmt>(B))
7694 return StmtError();
7695
7696 // Otherwise, just keep processing substatements and fail later.
7697 SubStmtInvalid = true;
7698 continue;
7699 }
7700
7701 SubStmtChanged = SubStmtChanged || Result.get() != B;
7702 Statements.push_back(Result.getAs<Stmt>());
7703 }
7704
7705 if (SubStmtInvalid)
7706 return StmtError();
7707
7708 if (!getDerived().AlwaysRebuild() &&
7709 !SubStmtChanged)
7710 return S;
7711
7712 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
7713 Statements,
7714 S->getRBracLoc(),
7715 IsStmtExpr);
7716}
7717
7718template<typename Derived>
7720TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
7721 ExprResult LHS, RHS;
7722 {
7723 EnterExpressionEvaluationContext Unevaluated(
7725
7726 // Transform the left-hand case value.
7727 LHS = getDerived().TransformExpr(S->getLHS());
7728 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
7729 if (LHS.isInvalid())
7730 return StmtError();
7731
7732 // Transform the right-hand case value (for the GNU case-range extension).
7733 RHS = getDerived().TransformExpr(S->getRHS());
7734 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
7735 if (RHS.isInvalid())
7736 return StmtError();
7737 }
7738
7739 // Build the case statement.
7740 // Case statements are always rebuilt so that they will attached to their
7741 // transformed switch statement.
7742 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
7743 LHS.get(),
7744 S->getEllipsisLoc(),
7745 RHS.get(),
7746 S->getColonLoc());
7747 if (Case.isInvalid())
7748 return StmtError();
7749
7750 // Transform the statement following the case
7751 StmtResult SubStmt =
7752 getDerived().TransformStmt(S->getSubStmt());
7753 if (SubStmt.isInvalid())
7754 return StmtError();
7755
7756 // Attach the body to the case statement
7757 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
7758}
7759
7760template <typename Derived>
7761StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
7762 // Transform the statement following the default case
7763 StmtResult SubStmt =
7764 getDerived().TransformStmt(S->getSubStmt());
7765 if (SubStmt.isInvalid())
7766 return StmtError();
7767
7768 // Default statements are always rebuilt
7769 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
7770 SubStmt.get());
7771}
7772
7773template<typename Derived>
7775TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
7776 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
7777 if (SubStmt.isInvalid())
7778 return StmtError();
7779
7780 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
7781 S->getDecl());
7782 if (!LD)
7783 return StmtError();
7784
7785 // If we're transforming "in-place" (we're not creating new local
7786 // declarations), assume we're replacing the old label statement
7787 // and clear out the reference to it.
7788 if (LD == S->getDecl())
7789 S->getDecl()->setStmt(nullptr);
7790
7791 // FIXME: Pass the real colon location in.
7792 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
7793 cast<LabelDecl>(LD), SourceLocation(),
7794 SubStmt.get());
7795}
7796
7797template <typename Derived>
7799 if (!R)
7800 return R;
7801
7802 switch (R->getKind()) {
7803// Transform attributes by calling TransformXXXAttr.
7804#define ATTR(X) \
7805 case attr::X: \
7806 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
7807#include "clang/Basic/AttrList.inc"
7808 }
7809 return R;
7810}
7811
7812template <typename Derived>
7814 const Stmt *InstS,
7815 const Attr *R) {
7816 if (!R)
7817 return R;
7818
7819 switch (R->getKind()) {
7820// Transform attributes by calling TransformStmtXXXAttr.
7821#define ATTR(X) \
7822 case attr::X: \
7823 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
7824#include "clang/Basic/AttrList.inc"
7825 }
7826 return TransformAttr(R);
7827}
7828
7829template <typename Derived>
7832 StmtDiscardKind SDK) {
7833 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
7834 if (SubStmt.isInvalid())
7835 return StmtError();
7836
7837 bool AttrsChanged = false;
7839
7840 // Visit attributes and keep track if any are transformed.
7841 for (const auto *I : S->getAttrs()) {
7842 const Attr *R =
7843 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
7844 AttrsChanged |= (I != R);
7845 if (R)
7846 Attrs.push_back(R);
7847 }
7848
7849 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
7850 return S;
7851
7852 // If transforming the attributes failed for all of the attributes in the
7853 // statement, don't make an AttributedStmt without attributes.
7854 if (Attrs.empty())
7855 return SubStmt;
7856
7857 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
7858 SubStmt.get());
7859}
7860
7861template<typename Derived>
7863TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
7864 // Transform the initialization statement
7865 StmtResult Init = getDerived().TransformStmt(S->getInit());
7866 if (Init.isInvalid())
7867 return StmtError();
7868
7869 Sema::ConditionResult Cond;
7870 if (!S->isConsteval()) {
7871 // Transform the condition
7872 Cond = getDerived().TransformCondition(
7873 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
7874 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
7876 if (Cond.isInvalid())
7877 return StmtError();
7878 }
7879
7880 // If this is a constexpr if, determine which arm we should instantiate.
7881 std::optional<bool> ConstexprConditionValue;
7882 if (S->isConstexpr())
7883 ConstexprConditionValue = Cond.getKnownValue();
7884
7885 // Transform the "then" branch.
7886 StmtResult Then;
7887 if (!ConstexprConditionValue || *ConstexprConditionValue) {
7888 Then = getDerived().TransformStmt(S->getThen());
7889 if (Then.isInvalid())
7890 return StmtError();
7891 } else {
7892 // Discarded branch is replaced with empty CompoundStmt so we can keep
7893 // proper source location for start and end of original branch, so
7894 // subsequent transformations like CoverageMapping work properly
7895 Then = new (getSema().Context)
7896 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
7897 }
7898
7899 // Transform the "else" branch.
7900 StmtResult Else;
7901 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
7902 Else = getDerived().TransformStmt(S->getElse());
7903 if (Else.isInvalid())
7904 return StmtError();
7905 } else if (S->getElse() && ConstexprConditionValue &&
7906 *ConstexprConditionValue) {
7907 // Same thing here as with <then> branch, we are discarding it, we can't
7908 // replace it with NULL nor NullStmt as we need to keep for source location
7909 // range, for CoverageMapping
7910 Else = new (getSema().Context)
7911 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
7912 }
7913
7914 if (!getDerived().AlwaysRebuild() &&
7915 Init.get() == S->getInit() &&
7916 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
7917 Then.get() == S->getThen() &&
7918 Else.get() == S->getElse())
7919 return S;
7920
7921 return getDerived().RebuildIfStmt(
7922 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
7923 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
7924}
7925
7926template<typename Derived>
7928TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
7929 // Transform the initialization statement
7930 StmtResult Init = getDerived().TransformStmt(S->getInit());
7931 if (Init.isInvalid())
7932 return StmtError();
7933
7934 // Transform the condition.
7935 Sema::ConditionResult Cond = getDerived().TransformCondition(
7936 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
7938 if (Cond.isInvalid())
7939 return StmtError();
7940
7941 // Rebuild the switch statement.
7943 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
7944 Init.get(), Cond, S->getRParenLoc());
7945 if (Switch.isInvalid())
7946 return StmtError();
7947
7948 // Transform the body of the switch statement.
7949 StmtResult Body = getDerived().TransformStmt(S->getBody());
7950 if (Body.isInvalid())
7951 return StmtError();
7952
7953 // Complete the switch statement.
7954 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
7955 Body.get());
7956}
7957
7958template<typename Derived>
7960TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
7961 // Transform the condition
7962 Sema::ConditionResult Cond = getDerived().TransformCondition(
7963 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
7965 if (Cond.isInvalid())
7966 return StmtError();
7967
7968 // Transform the body
7969 StmtResult Body = getDerived().TransformStmt(S->getBody());
7970 if (Body.isInvalid())
7971 return StmtError();
7972
7973 if (!getDerived().AlwaysRebuild() &&
7974 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
7975 Body.get() == S->getBody())
7976 return Owned(S);
7977
7978 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
7979 Cond, S->getRParenLoc(), Body.get());
7980}
7981
7982template<typename Derived>
7984TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
7985 // Transform the body
7986 StmtResult Body = getDerived().TransformStmt(S->getBody());
7987 if (Body.isInvalid())
7988 return StmtError();
7989
7990 // Transform the condition
7991 ExprResult Cond = getDerived().TransformExpr(S->getCond());
7992 if (Cond.isInvalid())
7993 return StmtError();
7994
7995 if (!getDerived().AlwaysRebuild() &&
7996 Cond.get() == S->getCond() &&
7997 Body.get() == S->getBody())
7998 return S;
7999
8000 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8001 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8002 S->getRParenLoc());
8003}
8004
8005template<typename Derived>
8007TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
8008 if (getSema().getLangOpts().OpenMP)
8009 getSema().startOpenMPLoop();
8010
8011 // Transform the initialization statement
8012 StmtResult Init = getDerived().TransformStmt(S->getInit());
8013 if (Init.isInvalid())
8014 return StmtError();
8015
8016 // In OpenMP loop region loop control variable must be captured and be
8017 // private. Perform analysis of first part (if any).
8018 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8019 getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get());
8020
8021 // Transform the condition
8022 Sema::ConditionResult Cond = getDerived().TransformCondition(
8023 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8025 if (Cond.isInvalid())
8026 return StmtError();
8027
8028 // Transform the increment
8029 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8030 if (Inc.isInvalid())
8031 return StmtError();
8032
8033 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8034 if (S->getInc() && !FullInc.get())
8035 return StmtError();
8036
8037 // Transform the body
8038 StmtResult Body = getDerived().TransformStmt(S->getBody());
8039 if (Body.isInvalid())
8040 return StmtError();
8041
8042 if (!getDerived().AlwaysRebuild() &&
8043 Init.get() == S->getInit() &&
8044 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8045 Inc.get() == S->getInc() &&
8046 Body.get() == S->getBody())
8047 return S;
8048
8049 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8050 Init.get(), Cond, FullInc,
8051 S->getRParenLoc(), Body.get());
8052}
8053
8054template<typename Derived>
8056TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
8057 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8058 S->getLabel());
8059 if (!LD)
8060 return StmtError();
8061
8062 // Goto statements must always be rebuilt, to resolve the label.
8063 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8064 cast<LabelDecl>(LD));
8065}
8066
8067template<typename Derived>
8069TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
8070 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8071 if (Target.isInvalid())
8072 return StmtError();
8073 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8074
8075 if (!getDerived().AlwaysRebuild() &&
8076 Target.get() == S->getTarget())
8077 return S;
8078
8079 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8080 Target.get());
8081}
8082
8083template<typename Derived>
8085TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
8086 return S;
8087}
8088
8089template<typename Derived>
8091TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
8092 return S;
8093}
8094
8095template<typename Derived>
8097TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
8098 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8099 /*NotCopyInit*/false);
8100 if (Result.isInvalid())
8101 return StmtError();
8102
8103 // FIXME: We always rebuild the return statement because there is no way
8104 // to tell whether the return type of the function has changed.
8105 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8106}
8107
8108template<typename Derived>
8110TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
8111 bool DeclChanged = false;
8113 for (auto *D : S->decls()) {
8114 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8115 if (!Transformed)
8116 return StmtError();
8117
8118 if (Transformed != D)
8119 DeclChanged = true;
8120
8121 Decls.push_back(Transformed);
8122 }
8123
8124 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8125 return S;
8126
8127 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8128}
8129
8130template<typename Derived>
8132TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
8133
8134 SmallVector<Expr*, 8> Constraints;
8137
8138 ExprResult AsmString;
8139 SmallVector<Expr*, 8> Clobbers;
8140
8141 bool ExprsChanged = false;
8142
8143 // Go through the outputs.
8144 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8145 Names.push_back(S->getOutputIdentifier(I));
8146
8147 // No need to transform the constraint literal.
8148 Constraints.push_back(S->getOutputConstraintLiteral(I));
8149
8150 // Transform the output expr.
8151 Expr *OutputExpr = S->getOutputExpr(I);
8152 ExprResult Result = getDerived().TransformExpr(OutputExpr);
8153 if (Result.isInvalid())
8154 return StmtError();
8155
8156 ExprsChanged |= Result.get() != OutputExpr;
8157
8158 Exprs.push_back(Result.get());
8159 }
8160
8161 // Go through the inputs.
8162 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8163 Names.push_back(S->getInputIdentifier(I));
8164
8165 // No need to transform the constraint literal.
8166 Constraints.push_back(S->getInputConstraintLiteral(I));
8167
8168 // Transform the input expr.
8169 Expr *InputExpr = S->getInputExpr(I);
8170 ExprResult Result = getDerived().TransformExpr(InputExpr);
8171 if (Result.isInvalid())
8172 return StmtError();
8173
8174 ExprsChanged |= Result.get() != InputExpr;
8175
8176 Exprs.push_back(Result.get());
8177 }
8178
8179 // Go through the Labels.
8180 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8181 Names.push_back(S->getLabelIdentifier(I));
8182
8183 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8184 if (Result.isInvalid())
8185 return StmtError();
8186 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8187 Exprs.push_back(Result.get());
8188 }
8189 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8190 return S;
8191
8192 // Go through the clobbers.
8193 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
8194 Clobbers.push_back(S->getClobberStringLiteral(I));
8195
8196 // No need to transform the asm string literal.
8197 AsmString = S->getAsmString();
8198 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8199 S->isVolatile(), S->getNumOutputs(),
8200 S->getNumInputs(), Names.data(),
8201 Constraints, Exprs, AsmString.get(),
8202 Clobbers, S->getNumLabels(),
8203 S->getRParenLoc());
8204}
8205
8206template<typename Derived>
8208TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
8209 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8210
8211 bool HadError = false, HadChange = false;
8212
8213 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8214 SmallVector<Expr*, 8> TransformedExprs;
8215 TransformedExprs.reserve(SrcExprs.size());
8216 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8217 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8218 if (!Result.isUsable()) {
8219 HadError = true;
8220 } else {
8221 HadChange |= (Result.get() != SrcExprs[i]);
8222 TransformedExprs.push_back(Result.get());
8223 }
8224 }
8225
8226 if (HadError) return StmtError();
8227 if (!HadChange && !getDerived().AlwaysRebuild())
8228 return Owned(S);
8229
8230 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8231 AsmToks, S->getAsmString(),
8232 S->getNumOutputs(), S->getNumInputs(),
8233 S->getAllConstraints(), S->getClobbers(),
8234 TransformedExprs, S->getEndLoc());
8235}
8236
8237// C++ Coroutines
8238template<typename Derived>
8240TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
8241 auto *ScopeInfo = SemaRef.getCurFunction();
8242 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8243 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8244 ScopeInfo->NeedsCoroutineSuspends &&
8245 ScopeInfo->CoroutineSuspends.first == nullptr &&
8246 ScopeInfo->CoroutineSuspends.second == nullptr &&
8247 "expected clean scope info");
8248
8249 // Set that we have (possibly-invalid) suspend points before we do anything
8250 // that may fail.
8251 ScopeInfo->setNeedsCoroutineSuspends(false);
8252
8253 // We re-build the coroutine promise object (and the coroutine parameters its
8254 // type and constructor depend on) based on the types used in our current
8255 // function. We must do so, and set it on the current FunctionScopeInfo,
8256 // before attempting to transform the other parts of the coroutine body
8257 // statement, such as the implicit suspend statements (because those
8258 // statements reference the FunctionScopeInfo::CoroutinePromise).
8259 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8260 return StmtError();
8261 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8262 if (!Promise)
8263 return StmtError();
8264 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8265 ScopeInfo->CoroutinePromise = Promise;
8266
8267 // Transform the implicit coroutine statements constructed using dependent
8268 // types during the previous parse: initial and final suspensions, the return
8269 // object, and others. We also transform the coroutine function's body.
8270 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8271 if (InitSuspend.isInvalid())
8272 return StmtError();
8273 StmtResult FinalSuspend =
8274 getDerived().TransformStmt(S->getFinalSuspendStmt());
8275 if (FinalSuspend.isInvalid() ||
8276 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8277 return StmtError();
8278 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8279 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8280
8281 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8282 if (BodyRes.isInvalid())
8283 return StmtError();
8284
8285 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8286 if (Builder.isInvalid())
8287 return StmtError();
8288
8289 Expr *ReturnObject = S->getReturnValueInit();
8290 assert(ReturnObject && "the return object is expected to be valid");
8291 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8292 /*NoCopyInit*/ false);
8293 if (Res.isInvalid())
8294 return StmtError();
8295 Builder.ReturnValue = Res.get();
8296
8297 // If during the previous parse the coroutine still had a dependent promise
8298 // statement, we may need to build some implicit coroutine statements
8299 // (such as exception and fallthrough handlers) for the first time.
8300 if (S->hasDependentPromiseType()) {
8301 // We can only build these statements, however, if the current promise type
8302 // is not dependent.
8303 if (!Promise->getType()->isDependentType()) {
8304 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8305 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8306 "these nodes should not have been built yet");
8307 if (!Builder.buildDependentStatements())
8308 return StmtError();
8309 }
8310 } else {
8311 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8312 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8313 if (Res.isInvalid())
8314 return StmtError();
8315 Builder.OnFallthrough = Res.get();
8316 }
8317
8318 if (auto *OnException = S->getExceptionHandler()) {
8319 StmtResult Res = getDerived().TransformStmt(OnException);
8320 if (Res.isInvalid())
8321 return StmtError();
8322 Builder.OnException = Res.get();
8323 }
8324
8325 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8326 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8327 if (Res.isInvalid())
8328 return StmtError();
8329 Builder.ReturnStmtOnAllocFailure = Res.get();
8330 }
8331
8332 // Transform any additional statements we may have already built
8333 assert(S->getAllocate() && S->getDeallocate() &&
8334 "allocation and deallocation calls must already be built");
8335 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8336 if (AllocRes.isInvalid())
8337 return StmtError();
8338 Builder.Allocate = AllocRes.get();
8339
8340 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8341 if (DeallocRes.isInvalid())
8342 return StmtError();
8343 Builder.Deallocate = DeallocRes.get();
8344
8345 if (auto *ResultDecl = S->getResultDecl()) {
8346 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8347 if (Res.isInvalid())
8348 return StmtError();
8349 Builder.ResultDecl = Res.get();
8350 }
8351
8352 if (auto *ReturnStmt = S->getReturnStmt()) {
8353 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8354 if (Res.isInvalid())
8355 return StmtError();
8356 Builder.ReturnStmt = Res.get();
8357 }
8358 }
8359
8360 return getDerived().RebuildCoroutineBodyStmt(Builder);
8361}
8362
8363template<typename Derived>
8365TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
8366 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8367 /*NotCopyInit*/false);
8368 if (Result.isInvalid())
8369 return StmtError();
8370
8371 // Always rebuild; we don't know if this needs to be injected into a new
8372 // context or if the promise type has changed.
8373 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8374 S->isImplicit());
8375}
8376
8377template <typename Derived>
8378ExprResult TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
8379 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8380 /*NotCopyInit*/ false);
8381 if (Operand.isInvalid())
8382 return ExprError();
8383
8384 // Rebuild the common-expr from the operand rather than transforming it
8385 // separately.
8386
8387 // FIXME: getCurScope() should not be used during template instantiation.
8388 // We should pick up the set of unqualified lookup results for operator
8389 // co_await during the initial parse.
8390 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8391 getSema().getCurScope(), E->getKeywordLoc());
8392
8393 // Always rebuild; we don't know if this needs to be injected into a new
8394 // context or if the promise type has changed.
8395 return getDerived().RebuildCoawaitExpr(
8396 E->getKeywordLoc(), Operand.get(),
8397 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8398}
8399
8400template <typename Derived>
8402TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
8403 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8404 /*NotCopyInit*/ false);
8405 if (OperandResult.isInvalid())
8406 return ExprError();
8407
8408 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8409 E->getOperatorCoawaitLookup());
8410
8411 if (LookupResult.isInvalid())
8412 return ExprError();
8413
8414 // Always rebuild; we don't know if this needs to be injected into a new
8415 // context or if the promise type has changed.
8416 return getDerived().RebuildDependentCoawaitExpr(
8417 E->getKeywordLoc(), OperandResult.get(),
8418 cast<UnresolvedLookupExpr>(LookupResult.get()));
8419}
8420
8421template<typename Derived>
8423TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
8424 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8425 /*NotCopyInit*/false);
8426 if (Result.isInvalid())
8427 return ExprError();
8428
8429 // Always rebuild; we don't know if this needs to be injected into a new
8430 // context or if the promise type has changed.
8431 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8432}
8433
8434// Objective-C Statements.
8435
8436template<typename Derived>
8438TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
8439 // Transform the body of the @try.
8440 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8441 if (TryBody.isInvalid())
8442 return StmtError();
8443
8444 // Transform the @catch statements (if present).
8445 bool AnyCatchChanged = false;
8446 SmallVector<Stmt*, 8> CatchStmts;
8447 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8448 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8449 if (Catch.isInvalid())
8450 return StmtError();
8451 if (Catch.get() != S->getCatchStmt(I))
8452 AnyCatchChanged = true;
8453 CatchStmts.push_back(Catch.get());
8454 }
8455
8456 // Transform the @finally statement (if present).
8457 StmtResult Finally;
8458 if (S->getFinallyStmt()) {
8459 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8460 if (Finally.isInvalid())
8461 return StmtError();
8462 }
8463
8464 // If nothing changed, just retain this statement.
8465 if (!getDerived().AlwaysRebuild() &&
8466 TryBody.get() == S->getTryBody() &&
8467 !AnyCatchChanged &&
8468 Finally.get() == S->getFinallyStmt())
8469 return S;
8470
8471 // Build a new statement.
8472 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8473 CatchStmts, Finally.get());
8474}
8475
8476template<typename Derived>
8478TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
8479 // Transform the @catch parameter, if there is one.
8480 VarDecl *Var = nullptr;
8481 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8482 TypeSourceInfo *TSInfo = nullptr;
8483 if (FromVar->getTypeSourceInfo()) {
8484 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8485 if (!TSInfo)
8486 return StmtError();
8487 }
8488
8489 QualType T;
8490 if (TSInfo)
8491 T = TSInfo->getType();
8492 else {
8493 T = getDerived().TransformType(FromVar->getType());
8494 if (T.isNull())
8495 return StmtError();
8496 }
8497
8498 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8499 if (!Var)
8500 return StmtError();
8501 }
8502
8503 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8504 if (Body.isInvalid())
8505 return StmtError();
8506
8507 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8508 S->getRParenLoc(),
8509 Var, Body.get());
8510}
8511
8512template<typename Derived>
8514TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
8515 // Transform the body.
8516 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8517 if (Body.isInvalid())
8518 return StmtError();
8519
8520 // If nothing changed, just retain this statement.
8521 if (!getDerived().AlwaysRebuild() &&
8522 Body.get() == S->getFinallyBody())
8523 return S;
8524
8525 // Build a new statement.
8526 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8527 Body.get());
8528}
8529
8530template<typename Derived>
8532TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
8534 if (S->getThrowExpr()) {
8535 Operand = getDerived().TransformExpr(S->getThrowExpr());
8536 if (Operand.isInvalid())
8537 return StmtError();
8538 }
8539
8540 if (!getDerived().AlwaysRebuild() &&
8541 Operand.get() == S->getThrowExpr())
8542 return S;
8543
8544 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8545}
8546
8547template<typename Derived>
8549TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
8550 ObjCAtSynchronizedStmt *S) {
8551 // Transform the object we are locking.
8552 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
8553 if (Object.isInvalid())
8554 return StmtError();
8555 Object =
8556 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8557 Object.get());
8558 if (Object.isInvalid())
8559 return StmtError();
8560
8561 // Transform the body.
8562 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8563 if (Body.isInvalid())
8564 return StmtError();
8565
8566 // If nothing change, just retain the current statement.
8567 if (!getDerived().AlwaysRebuild() &&
8568 Object.get() == S->getSynchExpr() &&
8569 Body.get() == S->getSynchBody())
8570 return S;
8571
8572 // Build a new statement.
8573 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
8574 Object.get(), Body.get());
8575}
8576
8577template<typename Derived>
8579TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
8580 ObjCAutoreleasePoolStmt *S) {
8581 // Transform the body.
8582 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
8583 if (Body.isInvalid())
8584 return StmtError();
8585
8586 // If nothing changed, just retain this statement.
8587 if (!getDerived().AlwaysRebuild() &&
8588 Body.get() == S->getSubStmt())
8589 return S;
8590
8591 // Build a new statement.
8592 return getDerived().RebuildObjCAutoreleasePoolStmt(
8593 S->getAtLoc(), Body.get());
8594}
8595
8596template<typename Derived>
8598TreeTransform<Derived>::TransformObjCForCollectionStmt(
8599 ObjCForCollectionStmt *S) {
8600 // Transform the element statement.
8601 StmtResult Element =
8602 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
8603 if (Element.isInvalid())
8604 return StmtError();
8605
8606 // Transform the collection expression.
8607 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
8608 if (Collection.isInvalid())
8609 return StmtError();
8610
8611 // Transform the body.
8612 StmtResult Body = getDerived().TransformStmt(S->getBody());
8613 if (Body.isInvalid())
8614 return StmtError();
8615
8616 // If nothing changed, just retain this statement.
8617 if (!getDerived().AlwaysRebuild() &&
8618 Element.get() == S->getElement() &&
8619 Collection.get() == S->getCollection() &&
8620 Body.get() == S->getBody())
8621 return S;
8622
8623 // Build a new statement.
8624 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
8625 Element.get(),
8626 Collection.get(),
8627 S->getRParenLoc(),
8628 Body.get());
8629}
8630
8631template <typename Derived>
8632StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
8633 // Transform the exception declaration, if any.
8634 VarDecl *Var = nullptr;
8635 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
8636 TypeSourceInfo *T =
8637 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
8638 if (!T)
8639 return StmtError();
8640
8641 Var = getDerived().RebuildExceptionDecl(
8642 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
8643 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
8644 if (!Var || Var->isInvalidDecl())
8645 return StmtError();
8646 }
8647
8648 // Transform the actual exception handler.
8649 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
8650 if (Handler.isInvalid())
8651 return StmtError();
8652
8653 if (!getDerived().AlwaysRebuild() && !Var &&
8654 Handler.get() == S->getHandlerBlock())
8655 return S;
8656
8657 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
8658}
8659
8660template <typename Derived>
8661StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
8662 // Transform the try block itself.
8663 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
8664 if (TryBlock.isInvalid())
8665 return StmtError();
8666
8667 // Transform the handlers.
8668 bool HandlerChanged = false;
8669 SmallVector<Stmt *, 8> Handlers;
8670 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
8671 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
8672 if (Handler.isInvalid())
8673 return StmtError();
8674
8675 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
8676 Handlers.push_back(Handler.getAs<Stmt>());
8677 }
8678
8679 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
8680 !HandlerChanged)
8681 return S;
8682
8683 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
8684 Handlers);
8685}
8686
8687template<typename Derived>
8689TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
8690 EnterExpressionEvaluationContext ForRangeInitContext(
8692 /*LambdaContextDecl=*/nullptr,
8694 getSema().getLangOpts().CPlusPlus23);
8695
8696 // P2718R0 - Lifetime extension in range-based for loops.
8697 if (getSema().getLangOpts().CPlusPlus23) {
8698 auto &LastRecord = getSema().ExprEvalContexts.back();
8699 LastRecord.InLifetimeExtendingContext = true;
8700
8701 // Materialize non-`cv void` prvalue temporaries in discarded
8702 // expressions. These materialized temporaries may be lifetime-extented.
8703 LastRecord.InMaterializeTemporaryObjectContext = true;
8704 }
8706 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
8707 if (Init.isInvalid())
8708 return StmtError();
8709
8710 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
8711 if (Range.isInvalid())
8712 return StmtError();
8713
8714 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
8715 assert(getSema().getLangOpts().CPlusPlus23 ||
8716 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
8717 auto ForRangeLifetimeExtendTemps =
8718 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
8719
8720 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
8721 if (Begin.isInvalid())
8722 return StmtError();
8723 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
8724 if (End.isInvalid())
8725 return StmtError();
8726
8727 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8728 if (Cond.isInvalid())
8729 return StmtError();
8730 if (Cond.get())
8731 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
8732 if (Cond.isInvalid())
8733 return StmtError();
8734 if (Cond.get())
8735 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
8736
8737 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8738 if (Inc.isInvalid())
8739 return StmtError();
8740 if (Inc.get())
8741 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
8742
8743 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
8744 if (LoopVar.isInvalid())
8745 return StmtError();
8746
8747 StmtResult NewStmt = S;
8748 if (getDerived().AlwaysRebuild() ||
8749 Init.get() != S->getInit() ||
8750 Range.get() != S->getRangeStmt() ||
8751 Begin.get() != S->getBeginStmt() ||
8752 End.get() != S->getEndStmt() ||
8753 Cond.get() != S->getCond() ||
8754 Inc.get() != S->getInc() ||
8755 LoopVar.get() != S->getLoopVarStmt()) {
8756 NewStmt = getDerived().RebuildCXXForRangeStmt(
8757 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
8758 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
8759 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
8760 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
8761 // Might not have attached any initializer to the loop variable.
8762 getSema().ActOnInitializerError(
8763 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
8764 return StmtError();
8765 }
8766 }
8767
8768 StmtResult Body = getDerived().TransformStmt(S->getBody());
8769 if (Body.isInvalid())
8770 return StmtError();
8771
8772 // Body has changed but we didn't rebuild the for-range statement. Rebuild
8773 // it now so we have a new statement to attach the body to.
8774 if (Body.get() != S->getBody() && NewStmt.get() == S) {
8775 NewStmt = getDerived().RebuildCXXForRangeStmt(
8776 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
8777 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
8778 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
8779 if (NewStmt.isInvalid())
8780 return StmtError();
8781 }
8782
8783 if (NewStmt.get() == S)
8784 return S;
8785
8786 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
8787}
8788
8789template<typename Derived>
8791TreeTransform<Derived>::TransformMSDependentExistsStmt(
8792 MSDependentExistsStmt *S) {
8793 // Transform the nested-name-specifier, if any.
8794 NestedNameSpecifierLoc QualifierLoc;
8795 if (S->getQualifierLoc()) {
8796 QualifierLoc
8797 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
8798 if (!QualifierLoc)
8799 return StmtError();
8800 }
8801
8802 // Transform the declaration name.
8803 DeclarationNameInfo NameInfo = S->getNameInfo();
8804 if (NameInfo.getName()) {
8805 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
8806 if (!NameInfo.getName())
8807 return StmtError();
8808 }
8809
8810 // Check whether anything changed.
8811 if (!getDerived().AlwaysRebuild() &&
8812 QualifierLoc == S->getQualifierLoc() &&
8813 NameInfo.getName() == S->getNameInfo().getName())
8814 return S;
8815
8816 // Determine whether this name exists, if we can.
8817 CXXScopeSpec SS;
8818 SS.Adopt(QualifierLoc);
8819 bool Dependent = false;
8820 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
8821 case Sema::IER_Exists:
8822 if (S->isIfExists())
8823 break;
8824
8825 return new (getSema().Context) NullStmt(S->getKeywordLoc());
8826
8828 if (S->isIfNotExists())
8829 break;
8830
8831 return new (getSema().Context) NullStmt(S->getKeywordLoc());
8832
8834 Dependent = true;
8835 break;
8836
8837 case Sema::IER_Error:
8838 return StmtError();
8839 }
8840
8841 // We need to continue with the instantiation, so do so now.
8842 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
8843 if (SubStmt.isInvalid())
8844 return StmtError();
8845
8846 // If we have resolved the name, just transform to the substatement.
8847 if (!Dependent)
8848 return SubStmt;
8849
8850 // The name is still dependent, so build a dependent expression again.
8851 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
8852 S->isIfExists(),
8853 QualifierLoc,
8854 NameInfo,
8855 SubStmt.get());
8856}
8857
8858template<typename Derived>
8860TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
8861 NestedNameSpecifierLoc QualifierLoc;
8862 if (E->getQualifierLoc()) {
8863 QualifierLoc
8864 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
8865 if (!QualifierLoc)
8866 return ExprError();
8867 }
8868
8869 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
8870 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
8871 if (!PD)
8872 return ExprError();
8873
8874 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
8875 if (Base.isInvalid())
8876 return ExprError();
8877
8878 return new (SemaRef.getASTContext())
8879 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
8881 QualifierLoc, E->getMemberLoc());
8882}
8883
8884template <typename Derived>
8885ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
8886 MSPropertySubscriptExpr *E) {
8887 auto BaseRes = getDerived().TransformExpr(E->getBase());
8888 if (BaseRes.isInvalid())
8889 return ExprError();
8890 auto IdxRes = getDerived().TransformExpr(E->getIdx());
8891 if (IdxRes.isInvalid())
8892 return ExprError();
8893
8894 if (!getDerived().AlwaysRebuild() &&
8895 BaseRes.get() == E->getBase() &&
8896 IdxRes.get() == E->getIdx())
8897 return E;
8898
8899 return getDerived().RebuildArraySubscriptExpr(
8900 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
8901}
8902
8903template <typename Derived>
8904StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
8905 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
8906 if (TryBlock.isInvalid())
8907 return StmtError();
8908
8909 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
8910 if (Handler.isInvalid())
8911 return StmtError();
8912
8913 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
8914 Handler.get() == S->getHandler())
8915 return S;
8916
8917 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
8918 TryBlock.get(), Handler.get());
8919}
8920
8921template <typename Derived>
8922StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
8923 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
8924 if (Block.isInvalid())
8925 return StmtError();
8926
8927 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
8928}
8929
8930template <typename Derived>
8931StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
8932 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
8933 if (FilterExpr.isInvalid())
8934 return StmtError();
8935
8936 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
8937 if (Block.isInvalid())
8938 return StmtError();
8939
8940 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
8941 Block.get());
8942}
8943
8944template <typename Derived>
8946 if (isa<SEHFinallyStmt>(Handler))
8947 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
8948 else
8949 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
8950}
8951
8952template<typename Derived>
8955 return S;
8956}
8957
8958//===----------------------------------------------------------------------===//
8959// OpenMP directive transformation
8960//===----------------------------------------------------------------------===//
8961
8962template <typename Derived>
8964TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
8965 // OMPCanonicalLoops are eliminated during transformation, since they will be
8966 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
8967 // after transformation.
8968 return getDerived().TransformStmt(L->getLoopStmt());
8969}
8970
8971template <typename Derived>
8974
8975 // Transform the clauses
8977 ArrayRef<OMPClause *> Clauses = D->clauses();
8978 TClauses.reserve(Clauses.size());
8979 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
8980 I != E; ++I) {
8981 if (*I) {
8982 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
8983 OMPClause *Clause = getDerived().TransformOMPClause(*I);
8984 getDerived().getSema().EndOpenMPClause();
8985 if (Clause)
8986 TClauses.push_back(Clause);
8987 } else {
8988 TClauses.push_back(nullptr);
8989 }
8990 }
8991 StmtResult AssociatedStmt;
8992 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
8993 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
8994 /*CurScope=*/nullptr);
8995 StmtResult Body;
8996 {
8997 Sema::CompoundScopeRAII CompoundScope(getSema());
8998 Stmt *CS;
8999 if (D->getDirectiveKind() == OMPD_atomic ||
9000 D->getDirectiveKind() == OMPD_critical ||
9001 D->getDirectiveKind() == OMPD_section ||
9002 D->getDirectiveKind() == OMPD_master)
9003 CS = D->getAssociatedStmt();
9004 else
9005 CS = D->getRawStmt();
9006 Body = getDerived().TransformStmt(CS);
9007 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9008 getSema().getLangOpts().OpenMPIRBuilder)
9009 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9010 }
9011 AssociatedStmt =
9012 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
9013 if (AssociatedStmt.isInvalid()) {
9014 return StmtError();
9015 }
9016 }
9017 if (TClauses.size() != Clauses.size()) {
9018 return StmtError();
9019 }
9020
9021 // Transform directive name for 'omp critical' directive.
9022 DeclarationNameInfo DirName;
9023 if (D->getDirectiveKind() == OMPD_critical) {
9024 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9025 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9026 }
9027 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9028 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9029 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9030 } else if (D->getDirectiveKind() == OMPD_cancel) {
9031 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9032 }
9033
9034 return getDerived().RebuildOMPExecutableDirective(
9035 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9036 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc(),
9037 D->getMappedDirective());
9038}
9039
9040template <typename Derived>
9043 // TODO: Fix This
9044 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9045 << getOpenMPDirectiveName(D->getDirectiveKind());
9046 return StmtError();
9047}
9048
9049template <typename Derived>
9051TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9052 DeclarationNameInfo DirName;
9053 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
9054 D->getBeginLoc());
9055 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9056 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9057 return Res;
9058}
9059
9060template <typename Derived>
9062TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
9063 DeclarationNameInfo DirName;
9064 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
9065 D->getBeginLoc());
9066 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9067 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9068 return Res;
9069}
9070
9071template <typename Derived>
9073TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
9074 DeclarationNameInfo DirName;
9075 getDerived().getSema().StartOpenMPDSABlock(D->getDirectiveKind(), DirName,
9076 nullptr, D->getBeginLoc());
9077 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9078 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9079 return Res;
9080}
9081
9082template <typename Derived>
9084TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {
9085 DeclarationNameInfo DirName;
9086 getDerived().getSema().StartOpenMPDSABlock(D->getDirectiveKind(), DirName,
9087 nullptr, D->getBeginLoc());
9088 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9089 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9090 return Res;
9091}
9092
9093template <typename Derived>
9095TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
9096 DeclarationNameInfo DirName;
9097 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
9098 D->getBeginLoc());
9099 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9100 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9101 return Res;
9102}
9103
9104template <typename Derived>
9106TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
9107 DeclarationNameInfo DirName;
9108 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
9109 D->getBeginLoc());
9110 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9111 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9112 return Res;
9113}
9114
9115template <typename Derived>
9117TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
9118 DeclarationNameInfo DirName;
9119 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
9120 D->getBeginLoc());
9121 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9122 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9123 return Res;
9124}
9125
9126template <typename Derived>
9128TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
9129 DeclarationNameInfo DirName;
9130 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
9131 D->getBeginLoc());
9132 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9133 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9134 return Res;
9135}
9136
9137template <typename Derived>
9139TreeTransform<Derived>::TransformOMPScopeDirective(OMPScopeDirective *D) {
9140 DeclarationNameInfo DirName;
9141 getDerived().getSema().StartOpenMPDSABlock(OMPD_scope, DirName, nullptr,
9142 D->getBeginLoc());
9143 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9144 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9145 return Res;
9146}
9147
9148template <typename Derived>
9150TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
9151 DeclarationNameInfo DirName;
9152 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
9153 D->getBeginLoc());
9154 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9155 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9156 return Res;
9157}
9158
9159template <typename Derived>
9161TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
9162 DeclarationNameInfo DirName;
9163 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
9164 D->getBeginLoc());
9165 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9166 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9167 return Res;
9168}
9169
9170template <typename Derived>
9172TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
9173 getDerived().getSema().StartOpenMPDSABlock(
9174 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9175 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9176 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9177 return Res;
9178}
9179
9180template <typename Derived>
9181StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
9182 OMPParallelForDirective *D) {
9183 DeclarationNameInfo DirName;
9184 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
9185 nullptr, D->getBeginLoc());
9186 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9187 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9188 return Res;
9189}
9190
9191template <typename Derived>
9192StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
9193 OMPParallelForSimdDirective *D) {
9194 DeclarationNameInfo DirName;
9195 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
9196 nullptr, D->getBeginLoc());
9197 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9198 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9199 return Res;
9200}
9201
9202template <typename Derived>
9203StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
9204 OMPParallelMasterDirective *D) {
9205 DeclarationNameInfo DirName;
9206 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_master, DirName,
9207 nullptr, D->getBeginLoc());
9208 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9209 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9210 return Res;
9211}
9212
9213template <typename Derived>
9214StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective(
9215 OMPParallelMaskedDirective *D) {
9216 DeclarationNameInfo DirName;
9217 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_masked, DirName,
9218 nullptr, D->getBeginLoc());
9219 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9220 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9221 return Res;
9222}
9223
9224template <typename Derived>
9225StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
9226 OMPParallelSectionsDirective *D) {
9227 DeclarationNameInfo DirName;
9228 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
9229 nullptr, D->getBeginLoc());
9230 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9231 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9232 return Res;
9233}
9234
9235template <typename Derived>
9237TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
9238 DeclarationNameInfo DirName;
9239 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
9240 D->getBeginLoc());
9241 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9242 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9243 return Res;
9244}
9245
9246template <typename Derived>
9247StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
9248 OMPTaskyieldDirective *D) {
9249 DeclarationNameInfo DirName;
9250 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
9251 D->getBeginLoc());
9252 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9253 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9254 return Res;
9255}
9256
9257template <typename Derived>
9259TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
9260 DeclarationNameInfo DirName;
9261 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
9262 D->getBeginLoc());
9263 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9264 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9265 return Res;
9266}
9267
9268template <typename Derived>
9270TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
9271 DeclarationNameInfo DirName;
9272 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
9273 D->getBeginLoc());
9274 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9275 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9276 return Res;
9277}
9278
9279template <typename Derived>
9281TreeTransform<Derived>::TransformOMPErrorDirective(OMPErrorDirective *D) {
9282 DeclarationNameInfo DirName;
9283 getDerived().getSema().StartOpenMPDSABlock(OMPD_error, DirName, nullptr,
9284 D->getBeginLoc());
9285 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9286 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9287 return Res;
9288}
9289
9290template <typename Derived>
9291StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
9292 OMPTaskgroupDirective *D) {
9293 DeclarationNameInfo DirName;
9294 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
9295 D->getBeginLoc());
9296 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9297 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9298 return Res;
9299}
9300
9301template <typename Derived>
9303TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
9304 DeclarationNameInfo DirName;
9305 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
9306 D->getBeginLoc());
9307 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9308 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9309 return Res;
9310}
9311
9312template <typename Derived>
9314TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
9315 DeclarationNameInfo DirName;
9316 getDerived().getSema().StartOpenMPDSABlock(OMPD_depobj, DirName, nullptr,
9317 D->getBeginLoc());
9318 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9319 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9320 return Res;
9321}
9322
9323template <typename Derived>
9325TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
9326 DeclarationNameInfo DirName;
9327 getDerived().getSema().StartOpenMPDSABlock(OMPD_scan, DirName, nullptr,
9328 D->getBeginLoc());
9329 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9330 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9331 return Res;
9332}
9333
9334template <typename Derived>
9336TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
9337 DeclarationNameInfo DirName;
9338 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
9339 D->getBeginLoc());
9340 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9341 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9342 return Res;
9343}
9344
9345template <typename Derived>
9347TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
9348 DeclarationNameInfo DirName;
9349 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
9350 D->getBeginLoc());
9351 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9352 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9353 return Res;
9354}
9355
9356template <typename Derived>
9358TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
9359 DeclarationNameInfo DirName;
9360 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
9361 D->getBeginLoc());
9362 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9363 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9364 return Res;
9365}
9366
9367template <typename Derived>
9368StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
9369 OMPTargetDataDirective *D) {
9370 DeclarationNameInfo DirName;
9371 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
9372 D->getBeginLoc());
9373 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9374 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9375 return Res;
9376}
9377
9378template <typename Derived>
9379StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
9380 OMPTargetEnterDataDirective *D) {
9381 DeclarationNameInfo DirName;
9382 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName,
9383 nullptr, D->getBeginLoc());
9384 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9385 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9386 return Res;
9387}
9388
9389template <typename Derived>
9390StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
9391 OMPTargetExitDataDirective *D) {
9392 DeclarationNameInfo DirName;
9393 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName,
9394 nullptr, D->getBeginLoc());
9395 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9396 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9397 return Res;
9398}
9399
9400template <typename Derived>
9401StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
9402 OMPTargetParallelDirective *D) {
9403 DeclarationNameInfo DirName;
9404 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName,
9405 nullptr, D->getBeginLoc());
9406 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9407 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9408 return Res;
9409}
9410
9411template <typename Derived>
9412StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
9413 OMPTargetParallelForDirective *D) {
9414 DeclarationNameInfo DirName;
9415 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName,
9416 nullptr, D->getBeginLoc());
9417 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9418 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9419 return Res;
9420}
9421
9422template <typename Derived>
9423StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
9424 OMPTargetUpdateDirective *D) {
9425 DeclarationNameInfo DirName;
9426 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName,
9427 nullptr, D->getBeginLoc());
9428 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9429 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9430 return Res;
9431}
9432
9433template <typename Derived>
9435TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
9436 DeclarationNameInfo DirName;
9437 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
9438 D->getBeginLoc());
9439 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9440 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9441 return Res;
9442}
9443
9444template <typename Derived>
9445StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
9446 OMPCancellationPointDirective *D) {
9447 DeclarationNameInfo DirName;
9448 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
9449 nullptr, D->getBeginLoc());
9450 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9451 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9452 return Res;
9453}
9454
9455template <typename Derived>
9457TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
9458 DeclarationNameInfo DirName;
9459 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
9460 D->getBeginLoc());
9461 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9462 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9463 return Res;
9464}
9465
9466template <typename Derived>
9468TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
9469 DeclarationNameInfo DirName;
9470 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr,
9471 D->getBeginLoc());
9472 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9473 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9474 return Res;
9475}
9476
9477template <typename Derived>
9478StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
9479 OMPTaskLoopSimdDirective *D) {
9480 DeclarationNameInfo DirName;
9481 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName,
9482 nullptr, D->getBeginLoc());
9483 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9484 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9485 return Res;
9486}
9487
9488template <typename Derived>
9489StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
9490 OMPMasterTaskLoopDirective *D) {
9491 DeclarationNameInfo DirName;
9492 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop, DirName,
9493 nullptr, D->getBeginLoc());
9494 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9495 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9496 return Res;
9497}
9498
9499template <typename Derived>
9500StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopDirective(
9501 OMPMaskedTaskLoopDirective *D) {
9502 DeclarationNameInfo DirName;
9503 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked_taskloop, DirName,
9504 nullptr, D->getBeginLoc());
9505 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9506 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9507 return Res;
9508}
9509
9510template <typename Derived>
9511StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
9512 OMPMasterTaskLoopSimdDirective *D) {
9513 DeclarationNameInfo DirName;
9514 getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop_simd, DirName,
9515 nullptr, D->getBeginLoc());
9516 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9517 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9518 return Res;
9519}
9520
9521template <typename Derived>
9522StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopSimdDirective(
9523 OMPMaskedTaskLoopSimdDirective *D) {
9524 DeclarationNameInfo DirName;
9525 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked_taskloop_simd, DirName,
9526 nullptr, D->getBeginLoc());
9527 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9528 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9529 return Res;
9530}
9531
9532template <typename Derived>
9533StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
9534 OMPParallelMasterTaskLoopDirective *D) {
9535 DeclarationNameInfo DirName;
9536 getDerived().getSema().StartOpenMPDSABlock(
9537 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
9538 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9539 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9540 return Res;
9541}
9542
9543template <typename Derived>
9544StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopDirective(
9545 OMPParallelMaskedTaskLoopDirective *D) {
9546 DeclarationNameInfo DirName;
9547 getDerived().getSema().StartOpenMPDSABlock(
9548 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
9549 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9550 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9551 return Res;
9552}
9553
9554template <typename Derived>
9556TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective(
9557 OMPParallelMasterTaskLoopSimdDirective *D) {
9558 DeclarationNameInfo DirName;
9559 getDerived().getSema().StartOpenMPDSABlock(
9560 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9561 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9562 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9563 return Res;
9564}
9565
9566template <typename Derived>
9568TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopSimdDirective(
9569 OMPParallelMaskedTaskLoopSimdDirective *D) {
9570 DeclarationNameInfo DirName;
9571 getDerived().getSema().StartOpenMPDSABlock(
9572 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9573 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9574 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9575 return Res;
9576}
9577
9578template <typename Derived>
9579StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
9580 OMPDistributeDirective *D) {
9581 DeclarationNameInfo DirName;
9582 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr,
9583 D->getBeginLoc());
9584 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9585 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9586 return Res;
9587}
9588
9589template <typename Derived>
9590StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
9591 OMPDistributeParallelForDirective *D) {
9592 DeclarationNameInfo DirName;
9593 getDerived().getSema().StartOpenMPDSABlock(
9594 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
9595 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9596 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9597 return Res;
9598}
9599
9600template <typename Derived>
9602TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
9603 OMPDistributeParallelForSimdDirective *D) {
9604 DeclarationNameInfo DirName;
9605 getDerived().getSema().StartOpenMPDSABlock(
9606 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9607 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9608 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9609 return Res;
9610}
9611
9612template <typename Derived>
9613StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
9614 OMPDistributeSimdDirective *D) {
9615 DeclarationNameInfo DirName;
9616 getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName,
9617 nullptr, D->getBeginLoc());
9618 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9619 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9620 return Res;
9621}
9622
9623template <typename Derived>
9624StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
9625 OMPTargetParallelForSimdDirective *D) {
9626 DeclarationNameInfo DirName;
9627 getDerived().getSema().StartOpenMPDSABlock(
9628 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9629 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9630 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9631 return Res;
9632}
9633
9634template <typename Derived>
9635StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
9636 OMPTargetSimdDirective *D) {
9637 DeclarationNameInfo DirName;
9638 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr,
9639 D->getBeginLoc());
9640 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9641 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9642 return Res;
9643}
9644
9645template <typename Derived>
9646StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
9647 OMPTeamsDistributeDirective *D) {
9648 DeclarationNameInfo DirName;
9649 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName,
9650 nullptr, D->getBeginLoc());
9651 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9652 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9653 return Res;
9654}
9655
9656template <typename Derived>
9657StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
9658 OMPTeamsDistributeSimdDirective *D) {
9659 DeclarationNameInfo DirName;
9660 getDerived().getSema().StartOpenMPDSABlock(
9661 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
9662 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9663 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9664 return Res;
9665}
9666
9667template <typename Derived>
9668StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
9669 OMPTeamsDistributeParallelForSimdDirective *D) {
9670 DeclarationNameInfo DirName;
9671 getDerived().getSema().StartOpenMPDSABlock(
9672 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
9673 D->getBeginLoc());
9674 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9675 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9676 return Res;
9677}
9678
9679template <typename Derived>
9680StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
9681 OMPTeamsDistributeParallelForDirective *D) {
9682 DeclarationNameInfo DirName;
9683 getDerived().getSema().StartOpenMPDSABlock(
9684 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
9685 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9686 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9687 return Res;
9688}
9689
9690template <typename Derived>
9691StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
9692 OMPTargetTeamsDirective *D) {
9693 DeclarationNameInfo DirName;
9694 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName,
9695 nullptr, D->getBeginLoc());
9696 auto Res = getDerived().TransformOMPExecutableDirective(D);
9697 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9698 return Res;
9699}
9700
9701template <typename Derived>
9702StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
9703 OMPTargetTeamsDistributeDirective *D) {
9704 DeclarationNameInfo DirName;
9705 getDerived().getSema().StartOpenMPDSABlock(
9706 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
9707 auto Res = getDerived().TransformOMPExecutableDirective(D);
9708 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9709 return Res;
9710}
9711
9712template <typename Derived>
9714TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
9715 OMPTargetTeamsDistributeParallelForDirective *D) {
9716 DeclarationNameInfo DirName;
9717 getDerived().getSema().StartOpenMPDSABlock(
9718 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
9719 D->getBeginLoc());
9720 auto Res = getDerived().TransformOMPExecutableDirective(D);
9721 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9722 return Res;
9723}
9724
9725template <typename Derived>
9726StmtResult TreeTransform<Derived>::
9727 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
9728 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
9729 DeclarationNameInfo DirName;
9730 getDerived().getSema().StartOpenMPDSABlock(
9731 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
9732 D->getBeginLoc());
9733 auto Res = getDerived().TransformOMPExecutableDirective(D);
9734 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9735 return Res;
9736}
9737
9738template <typename Derived>
9740TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
9741 OMPTargetTeamsDistributeSimdDirective *D) {
9742 DeclarationNameInfo DirName;
9743 getDerived().getSema().StartOpenMPDSABlock(
9744 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
9745 auto Res = getDerived().TransformOMPExecutableDirective(D);
9746 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9747 return Res;
9748}
9749
9750template <typename Derived>
9752TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
9753 DeclarationNameInfo DirName;
9754 getDerived().getSema().StartOpenMPDSABlock(OMPD_interop, DirName, nullptr,
9755 D->getBeginLoc());
9756 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9757 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9758 return Res;
9759}
9760
9761template <typename Derived>
9763TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
9764 DeclarationNameInfo DirName;
9765 getDerived().getSema().StartOpenMPDSABlock(OMPD_dispatch, DirName, nullptr,
9766 D->getBeginLoc());
9767 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9768 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9769 return Res;
9770}
9771
9772template <typename Derived>
9774TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
9775 DeclarationNameInfo DirName;
9776 getDerived().getSema().StartOpenMPDSABlock(OMPD_masked, DirName, nullptr,
9777 D->getBeginLoc());
9778 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9779 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9780 return Res;
9781}
9782
9783template <typename Derived>
9784StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
9785 OMPGenericLoopDirective *D) {
9786 DeclarationNameInfo DirName;
9787 getDerived().getSema().StartOpenMPDSABlock(OMPD_loop, DirName, nullptr,
9788 D->getBeginLoc());
9789 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9790 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9791 return Res;
9792}
9793
9794template <typename Derived>
9795StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective(
9796 OMPTeamsGenericLoopDirective *D) {
9797 DeclarationNameInfo DirName;
9798 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_loop, DirName, nullptr,
9799 D->getBeginLoc());
9800 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9801 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9802 return Res;
9803}
9804
9805template <typename Derived>
9806StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsGenericLoopDirective(
9807 OMPTargetTeamsGenericLoopDirective *D) {
9808 DeclarationNameInfo DirName;
9809 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams_loop, DirName,
9810 nullptr, D->getBeginLoc());
9811 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9812 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9813 return Res;
9814}
9815
9816template <typename Derived>
9817StmtResult TreeTransform<Derived>::TransformOMPParallelGenericLoopDirective(
9818 OMPParallelGenericLoopDirective *D) {
9819 DeclarationNameInfo DirName;
9820 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_loop, DirName,
9821 nullptr, D->getBeginLoc());
9822 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9823 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9824 return Res;
9825}
9826
9827template <typename Derived>
9829TreeTransform<Derived>::TransformOMPTargetParallelGenericLoopDirective(
9830 OMPTargetParallelGenericLoopDirective *D) {
9831 DeclarationNameInfo DirName;
9832 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_loop, DirName,
9833 nullptr, D->getBeginLoc());
9834 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9835 getDerived().getSema().EndOpenMPDSABlock(Res.get());
9836 return Res;
9837}
9838
9839//===----------------------------------------------------------------------===//
9840// OpenMP clause transformation
9841//===----------------------------------------------------------------------===//
9842template <typename Derived>
9843OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
9844 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
9845 if (Cond.isInvalid())
9846 return nullptr;
9847 return getDerived().RebuildOMPIfClause(
9848 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
9849 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
9850}
9851
9852template <typename Derived>
9853OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
9854 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
9855 if (Cond.isInvalid())
9856 return nullptr;
9857 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
9858 C->getLParenLoc(), C->getEndLoc());
9859}
9860
9861template <typename Derived>
9862OMPClause *
9863TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
9864 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
9865 if (NumThreads.isInvalid())
9866 return nullptr;
9867 return getDerived().RebuildOMPNumThreadsClause(
9868 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9869}
9870
9871template <typename Derived>
9872OMPClause *
9873TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
9874 ExprResult E = getDerived().TransformExpr(C->getSafelen());
9875 if (E.isInvalid())
9876 return nullptr;
9877 return getDerived().RebuildOMPSafelenClause(
9878 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9879}
9880
9881template <typename Derived>
9882OMPClause *
9883TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
9884 ExprResult E = getDerived().TransformExpr(C->getAllocator());
9885 if (E.isInvalid())
9886 return nullptr;
9887 return getDerived().RebuildOMPAllocatorClause(
9888 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9889}
9890
9891template <typename Derived>
9892OMPClause *
9893TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
9894 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
9895 if (E.isInvalid())
9896 return nullptr;
9897 return getDerived().RebuildOMPSimdlenClause(
9898 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9899}
9900
9901template <typename Derived>
9902OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) {
9903 SmallVector<Expr *, 4> TransformedSizes;
9904 TransformedSizes.reserve(C->getNumSizes());
9905 bool Changed = false;
9906 for (Expr *E : C->getSizesRefs()) {
9907 if (!E) {
9908 TransformedSizes.push_back(nullptr);
9909 continue;
9910 }
9911
9912 ExprResult T = getDerived().TransformExpr(E);
9913 if (T.isInvalid())
9914 return nullptr;
9915 if (E != T.get())
9916 Changed = true;
9917 TransformedSizes.push_back(T.get());
9918 }
9919
9920 if (!Changed && !getDerived().AlwaysRebuild())
9921 return C;
9922 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
9923 C->getLParenLoc(), C->getEndLoc());
9924}
9925
9926template <typename Derived>
9927OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) {
9928 if (!getDerived().AlwaysRebuild())
9929 return C;
9930 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
9931}
9932
9933template <typename Derived>
9934OMPClause *
9935TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
9936 ExprResult T = getDerived().TransformExpr(C->getFactor());
9937 if (T.isInvalid())
9938 return nullptr;
9939 Expr *Factor = T.get();
9940 bool Changed = Factor != C->getFactor();
9941
9942 if (!Changed && !getDerived().AlwaysRebuild())
9943 return C;
9944 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
9945 C->getEndLoc());
9946}
9947
9948template <typename Derived>
9949OMPClause *
9950TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
9951 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
9952 if (E.isInvalid())
9953 return nullptr;
9954 return getDerived().RebuildOMPCollapseClause(
9955 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
9956}
9957
9958template <typename Derived>
9959OMPClause *
9960TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
9961 return getDerived().RebuildOMPDefaultClause(
9962 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
9963 C->getLParenLoc(), C->getEndLoc());
9964}
9965
9966template <typename Derived>
9967OMPClause *
9968TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
9969 return getDerived().RebuildOMPProcBindClause(
9970 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
9971 C->getLParenLoc(), C->getEndLoc());
9972}
9973
9974template <typename Derived>
9975OMPClause *
9976TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
9977 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
9978 if (E.isInvalid())
9979 return nullptr;
9980 return getDerived().RebuildOMPScheduleClause(
9981 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
9982 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
9983 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
9984 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
9985}
9986
9987template <typename Derived>
9988OMPClause *
9989TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
9990 ExprResult E;
9991 if (auto *Num = C->getNumForLoops()) {
9992 E = getDerived().TransformExpr(Num);
9993 if (E.isInvalid())
9994 return nullptr;
9995 }
9996 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
9997 C->getLParenLoc(), E.get());
9998}
9999
10000template <typename Derived>
10001OMPClause *
10002TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
10003 ExprResult E;
10004 if (Expr *Evt = C->getEventHandler()) {
10005 E = getDerived().TransformExpr(Evt);
10006 if (E.isInvalid())
10007 return nullptr;
10008 }
10009 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10010 C->getLParenLoc(), C->getEndLoc());
10011}
10012
10013template <typename Derived>
10014OMPClause *
10015TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
10016 // No need to rebuild this clause, no template-dependent parameters.
10017 return C;
10018}
10019
10020template <typename Derived>
10021OMPClause *
10022TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
10023 // No need to rebuild this clause, no template-dependent parameters.
10024 return C;
10025}
10026
10027template <typename Derived>
10028OMPClause *
10029TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
10030 // No need to rebuild this clause, no template-dependent parameters.
10031 return C;
10032}
10033
10034template <typename Derived>
10035OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
10036 // No need to rebuild this clause, no template-dependent parameters.
10037 return C;
10038}
10039
10040template <typename Derived>
10041OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
10042 // No need to rebuild this clause, no template-dependent parameters.
10043 return C;
10044}
10045
10046template <typename Derived>
10047OMPClause *
10048TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
10049 // No need to rebuild this clause, no template-dependent parameters.
10050 return C;
10051}
10052
10053template <typename Derived>
10054OMPClause *
10055TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
10056 // No need to rebuild this clause, no template-dependent parameters.
10057 return C;
10058}
10059
10060template <typename Derived>
10061OMPClause *
10062TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
10063 // No need to rebuild this clause, no template-dependent parameters.
10064 return C;
10065}
10066
10067template <typename Derived>
10068OMPClause *TreeTransform<Derived>::TransformOMPFailClause(OMPFailClause *C) {
10069 // No need to rebuild this clause, no template-dependent parameters.
10070 return C;
10071}
10072
10073template <typename Derived>
10074OMPClause *
10075TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
10076 // No need to rebuild this clause, no template-dependent parameters.
10077 return C;
10078}
10079
10080template <typename Derived>
10081OMPClause *
10082TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
10083 // No need to rebuild this clause, no template-dependent parameters.
10084 return C;
10085}
10086
10087template <typename Derived>
10088OMPClause *
10089TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
10090 // No need to rebuild this clause, no template-dependent parameters.
10091 return C;
10092}
10093
10094template <typename Derived>
10095OMPClause *
10096TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
10097 // No need to rebuild this clause, no template-dependent parameters.
10098 return C;
10099}
10100
10101template <typename Derived>
10102OMPClause *
10103TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
10104 // No need to rebuild this clause, no template-dependent parameters.
10105 return C;
10106}
10107
10108template <typename Derived>
10109OMPClause *TreeTransform<Derived>::TransformOMPWeakClause(OMPWeakClause *C) {
10110 // No need to rebuild this clause, no template-dependent parameters.
10111 return C;
10112}
10113
10114template <typename Derived>
10115OMPClause *
10116TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
10117 // No need to rebuild this clause, no template-dependent parameters.
10118 return C;
10119}
10120
10121template <typename Derived>
10122OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
10123 // No need to rebuild this clause, no template-dependent parameters.
10124 return C;
10125}
10126
10127template <typename Derived>
10128OMPClause *
10129TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
10130 // No need to rebuild this clause, no template-dependent parameters.
10131 return C;
10132}
10133
10134template <typename Derived>
10135OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
10136 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10137 if (IVR.isInvalid())
10138 return nullptr;
10139
10140 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10141 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10142 for (Expr *E : llvm::drop_begin(C->varlists())) {
10143 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10144 if (ER.isInvalid())
10145 return nullptr;
10146 InteropInfo.PreferTypes.push_back(ER.get());
10147 }
10148 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10149 C->getBeginLoc(), C->getLParenLoc(),
10150 C->getVarLoc(), C->getEndLoc());
10151}
10152
10153template <typename Derived>
10154OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) {
10155 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10156 if (ER.isInvalid())
10157 return nullptr;
10158 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10159 C->getLParenLoc(), C->getVarLoc(),
10160 C->getEndLoc());
10161}
10162
10163template <typename Derived>
10164OMPClause *
10165TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
10166 ExprResult ER;
10167 if (Expr *IV = C->getInteropVar()) {
10168 ER = getDerived().TransformExpr(IV);
10169 if (ER.isInvalid())
10170 return nullptr;
10171 }
10172 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10173 C->getLParenLoc(), C->getVarLoc(),
10174 C->getEndLoc());
10175}
10176
10177template <typename Derived>
10178OMPClause *
10179TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
10180 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10181 if (Cond.isInvalid())
10182 return nullptr;
10183 return getDerived().RebuildOMPNovariantsClause(
10184 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10185}
10186
10187template <typename Derived>
10188OMPClause *
10189TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
10190 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10191 if (Cond.isInvalid())
10192 return nullptr;
10193 return getDerived().RebuildOMPNocontextClause(
10194 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10195}
10196
10197template <typename Derived>
10198OMPClause *
10199TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
10200 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10201 if (ThreadID.isInvalid())
10202 return nullptr;
10203 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10204 C->getLParenLoc(), C->getEndLoc());
10205}
10206
10207template <typename Derived>
10208OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) {
10209 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10210 if (E.isInvalid())
10211 return nullptr;
10212 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10213 C->getLParenLoc(), C->getEndLoc());
10214}
10215
10216template <typename Derived>
10217OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
10218 OMPUnifiedAddressClause *C) {
10219 llvm_unreachable("unified_address clause cannot appear in dependent context");
10220}
10221
10222template <typename Derived>
10223OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
10224 OMPUnifiedSharedMemoryClause *C) {
10225 llvm_unreachable(
10226 "unified_shared_memory clause cannot appear in dependent context");
10227}
10228
10229template <typename Derived>
10230OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
10231 OMPReverseOffloadClause *C) {
10232 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10233}
10234
10235template <typename Derived>
10236OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
10237 OMPDynamicAllocatorsClause *C) {
10238 llvm_unreachable(
10239 "dynamic_allocators clause cannot appear in dependent context");
10240}
10241
10242template <typename Derived>
10243OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
10244 OMPAtomicDefaultMemOrderClause *C) {
10245 llvm_unreachable(
10246 "atomic_default_mem_order clause cannot appear in dependent context");
10247}
10248
10249template <typename Derived>
10250OMPClause *TreeTransform<Derived>::TransformOMPAtClause(OMPAtClause *C) {
10251 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10252 C->getBeginLoc(), C->getLParenLoc(),
10253 C->getEndLoc());
10254}
10255
10256template <typename Derived>
10257OMPClause *
10258TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) {
10259 return getDerived().RebuildOMPSeverityClause(
10260 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10261 C->getLParenLoc(), C->getEndLoc());
10262}
10263
10264template <typename Derived>
10265OMPClause *
10266TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) {
10267 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10268 if (E.isInvalid())
10269 return nullptr;
10270 return getDerived().RebuildOMPMessageClause(
10271 C->getMessageString(), C->getBeginLoc(), C->getLParenLoc(),
10272 C->getEndLoc());
10273}
10274
10275template <typename Derived>
10276OMPClause *
10277TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
10279 Vars.reserve(C->varlist_size());
10280 for (auto *VE : C->varlists()) {
10281 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10282 if (EVar.isInvalid())
10283 return nullptr;
10284 Vars.push_back(EVar.get());
10285 }
10286 return getDerived().RebuildOMPPrivateClause(
10287 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10288}
10289
10290template <typename Derived>
10291OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
10292 OMPFirstprivateClause *C) {
10294 Vars.reserve(C->varlist_size());
10295 for (auto *VE : C->varlists()) {
10296 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10297 if (EVar.isInvalid())
10298 return nullptr;
10299 Vars.push_back(EVar.get());
10300 }
10301 return getDerived().RebuildOMPFirstprivateClause(
10302 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10303}
10304
10305template <typename Derived>
10306OMPClause *
10307TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
10309 Vars.reserve(C->varlist_size());
10310 for (auto *VE : C->varlists()) {
10311 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10312 if (EVar.isInvalid())
10313 return nullptr;
10314 Vars.push_back(EVar.get());
10315 }
10316 return getDerived().RebuildOMPLastprivateClause(
10317 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
10318 C->getLParenLoc(), C->getEndLoc());
10319}
10320
10321template <typename Derived>
10322OMPClause *
10323TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
10325 Vars.reserve(C->varlist_size());
10326 for (auto *VE : C->varlists()) {
10327 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10328 if (EVar.isInvalid())
10329 return nullptr;
10330 Vars.push_back(EVar.get());
10331 }
10332 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
10333 C->getLParenLoc(), C->getEndLoc());
10334}
10335
10336template <typename Derived>
10337OMPClause *
10338TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
10340 Vars.reserve(C->varlist_size());
10341 for (auto *VE : C->varlists()) {
10342 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10343 if (EVar.isInvalid())
10344 return nullptr;
10345 Vars.push_back(EVar.get());
10346 }
10347 CXXScopeSpec ReductionIdScopeSpec;
10348 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10349
10350 DeclarationNameInfo NameInfo = C->getNameInfo();
10351 if (NameInfo.getName()) {
10352 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10353 if (!NameInfo.getName())
10354 return nullptr;
10355 }
10356 // Build a list of all UDR decls with the same names ranged by the Scopes.
10357 // The Scope boundary is a duplication of the previous decl.
10358 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10359 for (auto *E : C->reduction_ops()) {
10360 // Transform all the decls.
10361 if (E) {
10362 auto *ULE = cast<UnresolvedLookupExpr>(E);
10363 UnresolvedSet<8> Decls;
10364 for (auto *D : ULE->decls()) {
10365 NamedDecl *InstD =
10366 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10367 Decls.addDecl(InstD, InstD->getAccess());
10368 }
10369 UnresolvedReductions.push_back(
10371 SemaRef.Context, /*NamingClass=*/nullptr,
10372 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context),
10373 NameInfo, /*ADL=*/true, ULE->isOverloaded(),
10374 Decls.begin(), Decls.end()));
10375 } else
10376 UnresolvedReductions.push_back(nullptr);
10377 }
10378 return getDerived().RebuildOMPReductionClause(
10379 Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(),
10380 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
10381 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10382}
10383
10384template <typename Derived>
10385OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
10386 OMPTaskReductionClause *C) {
10388 Vars.reserve(C->varlist_size());
10389 for (auto *VE : C->varlists()) {
10390 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10391 if (EVar.isInvalid())
10392 return nullptr;
10393 Vars.push_back(EVar.get());
10394 }
10395 CXXScopeSpec ReductionIdScopeSpec;
10396 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10397
10398 DeclarationNameInfo NameInfo = C->getNameInfo();
10399 if (NameInfo.getName()) {
10400 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10401 if (!NameInfo.getName())
10402 return nullptr;
10403 }
10404 // Build a list of all UDR decls with the same names ranged by the Scopes.
10405 // The Scope boundary is a duplication of the previous decl.
10406 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10407 for (auto *E : C->reduction_ops()) {
10408 // Transform all the decls.
10409 if (E) {
10410 auto *ULE = cast<UnresolvedLookupExpr>(E);
10411 UnresolvedSet<8> Decls;
10412 for (auto *D : ULE->decls()) {
10413 NamedDecl *InstD =
10414 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10415 Decls.addDecl(InstD, InstD->getAccess());
10416 }
10417 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10418 SemaRef.Context, /*NamingClass=*/nullptr,
10419 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10420 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
10421 } else
10422 UnresolvedReductions.push_back(nullptr);
10423 }
10424 return getDerived().RebuildOMPTaskReductionClause(
10425 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10426 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10427}
10428
10429template <typename Derived>
10430OMPClause *
10431TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
10433 Vars.reserve(C->varlist_size());
10434 for (auto *VE : C->varlists()) {
10435 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10436 if (EVar.isInvalid())
10437 return nullptr;
10438 Vars.push_back(EVar.get());
10439 }
10440 CXXScopeSpec ReductionIdScopeSpec;
10441 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10442
10443 DeclarationNameInfo NameInfo = C->getNameInfo();
10444 if (NameInfo.getName()) {
10445 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10446 if (!NameInfo.getName())
10447 return nullptr;
10448 }
10449 // Build a list of all UDR decls with the same names ranged by the Scopes.
10450 // The Scope boundary is a duplication of the previous decl.
10451 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10452 for (auto *E : C->reduction_ops()) {
10453 // Transform all the decls.
10454 if (E) {
10455 auto *ULE = cast<UnresolvedLookupExpr>(E);
10456 UnresolvedSet<8> Decls;
10457 for (auto *D : ULE->decls()) {
10458 NamedDecl *InstD =
10459 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10460 Decls.addDecl(InstD, InstD->getAccess());
10461 }
10462 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10463 SemaRef.Context, /*NamingClass=*/nullptr,
10464 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10465 /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end()));
10466 } else
10467 UnresolvedReductions.push_back(nullptr);
10468 }
10469 return getDerived().RebuildOMPInReductionClause(
10470 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10471 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10472}
10473
10474template <typename Derived>
10475OMPClause *
10476TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
10478 Vars.reserve(C->varlist_size());
10479 for (auto *VE : C->varlists()) {
10480 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10481 if (EVar.isInvalid())
10482 return nullptr;
10483 Vars.push_back(EVar.get());
10484 }
10485 ExprResult Step = getDerived().TransformExpr(C->getStep());
10486 if (Step.isInvalid())
10487 return nullptr;
10488 return getDerived().RebuildOMPLinearClause(
10489 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
10490 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
10491 C->getEndLoc());
10492}
10493
10494template <typename Derived>
10495OMPClause *
10496TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
10498 Vars.reserve(C->varlist_size());
10499 for (auto *VE : C->varlists()) {
10500 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10501 if (EVar.isInvalid())
10502 return nullptr;
10503 Vars.push_back(EVar.get());
10504 }
10505 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
10506 if (Alignment.isInvalid())
10507 return nullptr;
10508 return getDerived().RebuildOMPAlignedClause(
10509 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
10510 C->getColonLoc(), C->getEndLoc());
10511}
10512
10513template <typename Derived>
10514OMPClause *
10515TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
10517 Vars.reserve(C->varlist_size());
10518 for (auto *VE : C->varlists()) {
10519 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10520 if (EVar.isInvalid())
10521 return nullptr;
10522 Vars.push_back(EVar.get());
10523 }
10524 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
10525 C->getLParenLoc(), C->getEndLoc());
10526}
10527
10528template <typename Derived>
10529OMPClause *
10530TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
10532 Vars.reserve(C->varlist_size());
10533 for (auto *VE : C->varlists()) {
10534 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10535 if (EVar.isInvalid())
10536 return nullptr;
10537 Vars.push_back(EVar.get());
10538 }
10539 return getDerived().RebuildOMPCopyprivateClause(
10540 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10541}
10542
10543template <typename Derived>
10544OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
10546 Vars.reserve(C->varlist_size());
10547 for (auto *VE : C->varlists()) {
10548 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10549 if (EVar.isInvalid())
10550 return nullptr;
10551 Vars.push_back(EVar.get());
10552 }
10553 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
10554 C->getLParenLoc(), C->getEndLoc());
10555}
10556
10557template <typename Derived>
10558OMPClause *
10559TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
10560 ExprResult E = getDerived().TransformExpr(C->getDepobj());
10561 if (E.isInvalid())
10562 return nullptr;
10563 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
10564 C->getLParenLoc(), C->getEndLoc());
10565}
10566
10567template <typename Derived>
10568OMPClause *
10569TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
10571 Expr *DepModifier = C->getModifier();
10572 if (DepModifier) {
10573 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
10574 if (DepModRes.isInvalid())
10575 return nullptr;
10576 DepModifier = DepModRes.get();
10577 }
10578 Vars.reserve(C->varlist_size());
10579 for (auto *VE : C->varlists()) {
10580 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10581 if (EVar.isInvalid())
10582 return nullptr;
10583 Vars.push_back(EVar.get());
10584 }
10585 return getDerived().RebuildOMPDependClause(
10586 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
10587 C->getOmpAllMemoryLoc()},
10588 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10589}
10590
10591template <typename Derived>
10592OMPClause *
10593TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
10594 ExprResult E = getDerived().TransformExpr(C->getDevice());
10595 if (E.isInvalid())
10596 return nullptr;
10597 return getDerived().RebuildOMPDeviceClause(
10598 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10599 C->getModifierLoc(), C->getEndLoc());
10600}
10601
10602template <typename Derived, class T>
10605 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
10606 DeclarationNameInfo &MapperIdInfo,
10607 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
10608 // Transform expressions in the list.
10609 Vars.reserve(C->varlist_size());
10610 for (auto *VE : C->varlists()) {
10611 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
10612 if (EVar.isInvalid())
10613 return true;
10614 Vars.push_back(EVar.get());
10615 }
10616 // Transform mapper scope specifier and identifier.
10617 NestedNameSpecifierLoc QualifierLoc;
10618 if (C->getMapperQualifierLoc()) {
10619 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
10620 C->getMapperQualifierLoc());
10621 if (!QualifierLoc)
10622 return true;
10623 }
10624 MapperIdScopeSpec.Adopt(QualifierLoc);
10625 MapperIdInfo = C->getMapperIdInfo();
10626 if (MapperIdInfo.getName()) {
10627 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
10628 if (!MapperIdInfo.getName())
10629 return true;
10630 }
10631 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
10632 // the previous user-defined mapper lookup in dependent environment.
10633 for (auto *E : C->mapperlists()) {
10634 // Transform all the decls.
10635 if (E) {
10636 auto *ULE = cast<UnresolvedLookupExpr>(E);
10637 UnresolvedSet<8> Decls;
10638 for (auto *D : ULE->decls()) {
10639 NamedDecl *InstD =
10640 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
10641 Decls.addDecl(InstD, InstD->getAccess());
10642 }
10643 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
10644 TT.getSema().Context, /*NamingClass=*/nullptr,
10645 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
10646 MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(),
10647 Decls.end()));
10648 } else {
10649 UnresolvedMappers.push_back(nullptr);
10650 }
10651 }
10652 return false;
10653}
10654
10655template <typename Derived>
10656OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
10657 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10659 Expr *IteratorModifier = C->getIteratorModifier();
10660 if (IteratorModifier) {
10661 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
10662 if (MapModRes.isInvalid())
10663 return nullptr;
10664 IteratorModifier = MapModRes.get();
10665 }
10666 CXXScopeSpec MapperIdScopeSpec;
10667 DeclarationNameInfo MapperIdInfo;
10668 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
10669 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
10670 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
10671 return nullptr;
10672 return getDerived().RebuildOMPMapClause(
10673 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
10674 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
10675 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
10676}
10677
10678template <typename Derived>
10679OMPClause *
10680TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
10681 Expr *Allocator = C->getAllocator();
10682 if (Allocator) {
10683 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
10684 if (AllocatorRes.isInvalid())
10685 return nullptr;
10686 Allocator = AllocatorRes.get();
10687 }
10689 Vars.reserve(C->varlist_size());
10690 for (auto *VE : C->varlists()) {
10691 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10692 if (EVar.isInvalid())
10693 return nullptr;
10694 Vars.push_back(EVar.get());
10695 }
10696 return getDerived().RebuildOMPAllocateClause(
10697 Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10698 C->getEndLoc());
10699}
10700
10701template <typename Derived>
10702OMPClause *
10703TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
10704 ExprResult E = getDerived().TransformExpr(C->getNumTeams());
10705 if (E.isInvalid())
10706 return nullptr;
10707 return getDerived().RebuildOMPNumTeamsClause(
10708 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10709}
10710
10711template <typename Derived>
10712OMPClause *
10713TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
10714 ExprResult E = getDerived().TransformExpr(C->getThreadLimit());
10715 if (E.isInvalid())
10716 return nullptr;
10717 return getDerived().RebuildOMPThreadLimitClause(
10718 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10719}
10720
10721template <typename Derived>
10722OMPClause *
10723TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
10724 ExprResult E = getDerived().TransformExpr(C->getPriority());
10725 if (E.isInvalid())
10726 return nullptr;
10727 return getDerived().RebuildOMPPriorityClause(
10728 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10729}
10730
10731template <typename Derived>
10732OMPClause *
10733TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
10734 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
10735 if (E.isInvalid())
10736 return nullptr;
10737 return getDerived().RebuildOMPGrainsizeClause(
10738 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10739 C->getModifierLoc(), C->getEndLoc());
10740}
10741
10742template <typename Derived>
10743OMPClause *
10744TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
10745 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
10746 if (E.isInvalid())
10747 return nullptr;
10748 return getDerived().RebuildOMPNumTasksClause(
10749 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10750 C->getModifierLoc(), C->getEndLoc());
10751}
10752
10753template <typename Derived>
10754OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
10755 ExprResult E = getDerived().TransformExpr(C->getHint());
10756 if (E.isInvalid())
10757 return nullptr;
10758 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
10759 C->getLParenLoc(), C->getEndLoc());
10760}
10761
10762template <typename Derived>
10763OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
10764 OMPDistScheduleClause *C) {
10765 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10766 if (E.isInvalid())
10767 return nullptr;
10768 return getDerived().RebuildOMPDistScheduleClause(
10769 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10770 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10771}
10772
10773template <typename Derived>
10774OMPClause *
10775TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
10776 // Rebuild Defaultmap Clause since we need to invoke the checking of
10777 // defaultmap(none:variable-category) after template initialization.
10778 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
10779 C->getDefaultmapKind(),
10780 C->getBeginLoc(),
10781 C->getLParenLoc(),
10782 C->getDefaultmapModifierLoc(),
10783 C->getDefaultmapKindLoc(),
10784 C->getEndLoc());
10785}
10786
10787template <typename Derived>
10788OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
10789 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10791 CXXScopeSpec MapperIdScopeSpec;
10792 DeclarationNameInfo MapperIdInfo;
10793 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
10794 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
10795 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
10796 return nullptr;
10797 return getDerived().RebuildOMPToClause(
10798 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
10799 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
10800}
10801
10802template <typename Derived>
10803OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
10804 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10806 CXXScopeSpec MapperIdScopeSpec;
10807 DeclarationNameInfo MapperIdInfo;
10808 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
10809 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
10810 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
10811 return nullptr;
10812 return getDerived().RebuildOMPFromClause(
10813 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
10814 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
10815}
10816
10817template <typename Derived>
10818OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
10819 OMPUseDevicePtrClause *C) {
10821 Vars.reserve(C->varlist_size());
10822 for (auto *VE : C->varlists()) {
10823 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10824 if (EVar.isInvalid())
10825 return nullptr;
10826 Vars.push_back(EVar.get());
10827 }
10828 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10829 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
10830}
10831
10832template <typename Derived>
10833OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause(
10834 OMPUseDeviceAddrClause *C) {
10836 Vars.reserve(C->varlist_size());
10837 for (auto *VE : C->varlists()) {
10838 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10839 if (EVar.isInvalid())
10840 return nullptr;
10841 Vars.push_back(EVar.get());
10842 }
10843 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10844 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
10845}
10846
10847template <typename Derived>
10848OMPClause *
10849TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
10851 Vars.reserve(C->varlist_size());
10852 for (auto *VE : C->varlists()) {
10853 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10854 if (EVar.isInvalid())
10855 return nullptr;
10856 Vars.push_back(EVar.get());
10857 }
10858 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10859 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
10860}
10861
10862template <typename Derived>
10863OMPClause *TreeTransform<Derived>::TransformOMPHasDeviceAddrClause(
10864 OMPHasDeviceAddrClause *C) {
10866 Vars.reserve(C->varlist_size());
10867 for (auto *VE : C->varlists()) {
10868 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10869 if (EVar.isInvalid())
10870 return nullptr;
10871 Vars.push_back(EVar.get());
10872 }
10873 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10874 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
10875}
10876
10877template <typename Derived>
10878OMPClause *
10879TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) {
10881 Vars.reserve(C->varlist_size());
10882 for (auto *VE : C->varlists()) {
10883 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10884 if (EVar.isInvalid())
10885 return nullptr;
10886 Vars.push_back(EVar.get());
10887 }
10888 return getDerived().RebuildOMPNontemporalClause(
10889 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10890}
10891
10892template <typename Derived>
10893OMPClause *
10894TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) {
10896 Vars.reserve(C->varlist_size());
10897 for (auto *VE : C->varlists()) {
10898 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10899 if (EVar.isInvalid())
10900 return nullptr;
10901 Vars.push_back(EVar.get());
10902 }
10903 return getDerived().RebuildOMPInclusiveClause(
10904 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10905}
10906
10907template <typename Derived>
10908OMPClause *
10909TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) {
10911 Vars.reserve(C->varlist_size());
10912 for (auto *VE : C->varlists()) {
10913 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10914 if (EVar.isInvalid())
10915 return nullptr;
10916 Vars.push_back(EVar.get());
10917 }
10918 return getDerived().RebuildOMPExclusiveClause(
10919 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10920}
10921
10922template <typename Derived>
10923OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause(
10924 OMPUsesAllocatorsClause *C) {
10926 Data.reserve(C->getNumberOfAllocators());
10927 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
10928 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
10929 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
10930 if (Allocator.isInvalid())
10931 continue;
10932 ExprResult AllocatorTraits;
10933 if (Expr *AT = D.AllocatorTraits) {
10934 AllocatorTraits = getDerived().TransformExpr(AT);
10935 if (AllocatorTraits.isInvalid())
10936 continue;
10937 }
10938 Sema::UsesAllocatorsData &NewD = Data.emplace_back();
10939 NewD.Allocator = Allocator.get();
10940 NewD.AllocatorTraits = AllocatorTraits.get();
10941 NewD.LParenLoc = D.LParenLoc;
10942 NewD.RParenLoc = D.RParenLoc;
10943 }
10944 return getDerived().RebuildOMPUsesAllocatorsClause(
10945 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10946}
10947
10948template <typename Derived>
10949OMPClause *
10950TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) {
10951 SmallVector<Expr *, 4> Locators;
10952 Locators.reserve(C->varlist_size());
10953 ExprResult ModifierRes;
10954 if (Expr *Modifier = C->getModifier()) {
10955 ModifierRes = getDerived().TransformExpr(Modifier);
10956 if (ModifierRes.isInvalid())
10957 return nullptr;
10958 }
10959 for (Expr *E : C->varlists()) {
10960 ExprResult Locator = getDerived().TransformExpr(E);
10961 if (Locator.isInvalid())
10962 continue;
10963 Locators.push_back(Locator.get());
10964 }
10965 return getDerived().RebuildOMPAffinityClause(
10966 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
10967 ModifierRes.get(), Locators);
10968}
10969
10970template <typename Derived>
10971OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) {
10972 return getDerived().RebuildOMPOrderClause(
10973 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
10974 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
10975}
10976
10977template <typename Derived>
10978OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) {
10979 return getDerived().RebuildOMPBindClause(
10980 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
10981 C->getLParenLoc(), C->getEndLoc());
10982}
10983
10984template <typename Derived>
10985OMPClause *TreeTransform<Derived>::TransformOMPXDynCGroupMemClause(
10986 OMPXDynCGroupMemClause *C) {
10987 ExprResult Size = getDerived().TransformExpr(C->getSize());
10988 if (Size.isInvalid())
10989 return nullptr;
10990 return getDerived().RebuildOMPXDynCGroupMemClause(
10991 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10992}
10993
10994template <typename Derived>
10995OMPClause *
10996TreeTransform<Derived>::TransformOMPDoacrossClause(OMPDoacrossClause *C) {
10998 Vars.reserve(C->varlist_size());
10999 for (auto *VE : C->varlists()) {
11000 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11001 if (EVar.isInvalid())
11002 return nullptr;
11003 Vars.push_back(EVar.get());
11004 }
11005 return getDerived().RebuildOMPDoacrossClause(
11006 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11007 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11008}
11009
11010template <typename Derived>
11011OMPClause *
11012TreeTransform<Derived>::TransformOMPXAttributeClause(OMPXAttributeClause *C) {
11014 for (auto *A : C->getAttrs())
11015 NewAttrs.push_back(getDerived().TransformAttr(A));
11016 return getDerived().RebuildOMPXAttributeClause(
11017 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11018}
11019
11020template <typename Derived>
11021OMPClause *TreeTransform<Derived>::TransformOMPXBareClause(OMPXBareClause *C) {
11022 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11023}
11024
11025//===----------------------------------------------------------------------===//
11026// OpenACC transformation
11027//===----------------------------------------------------------------------===//
11028template <typename Derived>
11029StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
11030 OpenACCComputeConstruct *C) {
11031 // TODO OpenACC: Transform clauses.
11032
11033 // Transform Structured Block.
11034 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
11035
11036 return getDerived().RebuildOpenACCComputeConstruct(
11037 C->getDirectiveKind(), C->getBeginLoc(), C->getEndLoc(), StrBlock);
11038}
11039
11040//===----------------------------------------------------------------------===//
11041// Expression transformation
11042//===----------------------------------------------------------------------===//
11043template<typename Derived>
11045TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
11046 return TransformExpr(E->getSubExpr());
11047}
11048
11049template <typename Derived>
11050ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
11051 SYCLUniqueStableNameExpr *E) {
11052 if (!E->isTypeDependent())
11053 return E;
11054
11055 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
11056
11057 if (!NewT)
11058 return ExprError();
11059
11060 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
11061 return E;
11062
11063 return getDerived().RebuildSYCLUniqueStableNameExpr(
11064 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
11065}
11066
11067template<typename Derived>
11069TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
11070 if (!E->isTypeDependent())
11071 return E;
11072
11073 return getDerived().RebuildPredefinedExpr(E->getLocation(),
11074 E->getIdentKind());
11075}
11076
11077template<typename Derived>
11079TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
11080 NestedNameSpecifierLoc QualifierLoc;
11081 if (E->getQualifierLoc()) {
11082 QualifierLoc
11083 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
11084 if (!QualifierLoc)
11085 return ExprError();
11086 }
11087
11088 ValueDecl *ND
11089 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
11090 E->getDecl()));
11091 if (!ND)
11092 return ExprError();
11093
11094 NamedDecl *Found = ND;
11095 if (E->getFoundDecl() != E->getDecl()) {
11096 Found = cast_or_null<NamedDecl>(
11097 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
11098 if (!Found)
11099 return ExprError();
11100 }
11101
11102 DeclarationNameInfo NameInfo = E->getNameInfo();
11103 if (NameInfo.getName()) {
11104 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11105 if (!NameInfo.getName())
11106 return ExprError();
11107 }
11108
11109 if (!getDerived().AlwaysRebuild() &&
11110 QualifierLoc == E->getQualifierLoc() &&
11111 ND == E->getDecl() &&
11112 Found == E->getFoundDecl() &&
11113 NameInfo.getName() == E->getDecl()->getDeclName() &&
11114 !E->hasExplicitTemplateArgs()) {
11115
11116 // Mark it referenced in the new context regardless.
11117 // FIXME: this is a bit instantiation-specific.
11118 SemaRef.MarkDeclRefReferenced(E);
11119
11120 return E;
11121 }
11122
11123 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
11124 if (E->hasExplicitTemplateArgs()) {
11125 TemplateArgs = &TransArgs;
11126 TransArgs.setLAngleLoc(E->getLAngleLoc());
11127 TransArgs.setRAngleLoc(E->getRAngleLoc());
11128 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11129 E->getNumTemplateArgs(),
11130 TransArgs))
11131 return ExprError();
11132 }
11133
11134 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
11135 Found, TemplateArgs);
11136}
11137
11138template<typename Derived>
11140TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
11141 return E;
11142}
11143
11144template <typename Derived>
11145ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
11146 FixedPointLiteral *E) {
11147 return E;
11148}
11149
11150template<typename Derived>
11152TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
11153 return E;
11154}
11155
11156template<typename Derived>
11158TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
11159 return E;
11160}
11161
11162template<typename Derived>
11164TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
11165 return E;
11166}
11167
11168template<typename Derived>
11170TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
11171 return E;
11172}
11173
11174template<typename Derived>
11176TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
11177 return getDerived().TransformCallExpr(E);
11178}
11179
11180template<typename Derived>
11182TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
11183 ExprResult ControllingExpr;
11184 TypeSourceInfo *ControllingType = nullptr;
11185 if (E->isExprPredicate())
11186 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
11187 else
11188 ControllingType = getDerived().TransformType(E->getControllingType());
11189
11190 if (ControllingExpr.isInvalid() && !ControllingType)
11191 return ExprError();
11192
11193 SmallVector<Expr *, 4> AssocExprs;
11195 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
11196 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
11197 if (TSI) {
11198 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
11199 if (!AssocType)
11200 return ExprError();
11201 AssocTypes.push_back(AssocType);
11202 } else {
11203 AssocTypes.push_back(nullptr);
11204 }
11205
11206 ExprResult AssocExpr =
11207 getDerived().TransformExpr(Assoc.getAssociationExpr());
11208 if (AssocExpr.isInvalid())
11209 return ExprError();
11210 AssocExprs.push_back(AssocExpr.get());
11211 }
11212
11213 if (!ControllingType)
11214 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
11215 E->getDefaultLoc(),
11216 E->getRParenLoc(),
11217 ControllingExpr.get(),
11218 AssocTypes,
11219 AssocExprs);
11220 return getDerived().RebuildGenericSelectionExpr(
11221 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
11222 ControllingType, AssocTypes, AssocExprs);
11223}
11224
11225template<typename Derived>
11227TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
11228 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
11229 if (SubExpr.isInvalid())
11230 return ExprError();
11231
11232 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
11233 return E;
11234
11235 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
11236 E->getRParen());
11237}
11238
11239/// The operand of a unary address-of operator has special rules: it's
11240/// allowed to refer to a non-static member of a class even if there's no 'this'
11241/// object available.
11242template<typename Derived>
11245 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
11246 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
11247 else
11248 return getDerived().TransformExpr(E);
11249}
11250
11251template<typename Derived>
11254 ExprResult SubExpr;
11255 if (E->getOpcode() == UO_AddrOf)
11256 SubExpr = TransformAddressOfOperand(E->getSubExpr());
11257 else
11258 SubExpr = TransformExpr(E->getSubExpr());
11259 if (SubExpr.isInvalid())
11260 return ExprError();
11261
11262 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
11263 return E;
11264
11265 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
11266 E->getOpcode(),
11267 SubExpr.get());
11268}
11269
11270template<typename Derived>
11272TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
11273 // Transform the type.
11274 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
11275 if (!Type)
11276 return ExprError();
11277
11278 // Transform all of the components into components similar to what the
11279 // parser uses.
11280 // FIXME: It would be slightly more efficient in the non-dependent case to
11281 // just map FieldDecls, rather than requiring the rebuilder to look for
11282 // the fields again. However, __builtin_offsetof is rare enough in
11283 // template code that we don't care.
11284 bool ExprChanged = false;
11285 typedef Sema::OffsetOfComponent Component;
11286 SmallVector<Component, 4> Components;
11287 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
11288 const OffsetOfNode &ON = E->getComponent(I);
11289 Component Comp;
11290 Comp.isBrackets = true;
11291 Comp.LocStart = ON.getSourceRange().getBegin();
11292 Comp.LocEnd = ON.getSourceRange().getEnd();
11293 switch (ON.getKind()) {
11294 case OffsetOfNode::Array: {
11295 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
11296 ExprResult Index = getDerived().TransformExpr(FromIndex);
11297 if (Index.isInvalid())
11298 return ExprError();
11299
11300 ExprChanged = ExprChanged || Index.get() != FromIndex;
11301 Comp.isBrackets = true;
11302 Comp.U.E = Index.get();
11303 break;
11304 }
11305
11308 Comp.isBrackets = false;
11309 Comp.U.IdentInfo = ON.getFieldName();
11310 if (!Comp.U.IdentInfo)
11311 continue;
11312
11313 break;
11314
11315 case OffsetOfNode::Base:
11316 // Will be recomputed during the rebuild.
11317 continue;
11318 }
11319
11320 Components.push_back(Comp);
11321 }
11322
11323 // If nothing changed, retain the existing expression.
11324 if (!getDerived().AlwaysRebuild() &&
11325 Type == E->getTypeSourceInfo() &&
11326 !ExprChanged)
11327 return E;
11328
11329 // Build a new offsetof expression.
11330 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
11331 Components, E->getRParenLoc());
11332}
11333
11334template<typename Derived>
11336TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
11337 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
11338 "opaque value expression requires transformation");
11339 return E;
11340}
11341
11342template<typename Derived>
11344TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
11345 return E;
11346}
11347
11348template <typename Derived>
11349ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) {
11351 bool Changed = false;
11352 for (Expr *C : E->subExpressions()) {
11353 ExprResult NewC = getDerived().TransformExpr(C);
11354 if (NewC.isInvalid())
11355 return ExprError();
11356 Children.push_back(NewC.get());
11357
11358 Changed |= NewC.get() != C;
11359 }
11360 if (!getDerived().AlwaysRebuild() && !Changed)
11361 return E;
11362 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
11363 Children, E->getType());
11364}
11365
11366template<typename Derived>
11368TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
11369 // Rebuild the syntactic form. The original syntactic form has
11370 // opaque-value expressions in it, so strip those away and rebuild
11371 // the result. This is a really awful way of doing this, but the
11372 // better solution (rebuilding the semantic expressions and
11373 // rebinding OVEs as necessary) doesn't work; we'd need
11374 // TreeTransform to not strip away implicit conversions.
11375 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
11376 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
11377 if (result.isInvalid()) return ExprError();
11378
11379 // If that gives us a pseudo-object result back, the pseudo-object
11380 // expression must have been an lvalue-to-rvalue conversion which we
11381 // should reapply.
11382 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
11383 result = SemaRef.checkPseudoObjectRValue(result.get());
11384
11385 return result;
11386}
11387
11388template<typename Derived>
11390TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
11391 UnaryExprOrTypeTraitExpr *E) {
11392 if (E->isArgumentType()) {
11393 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
11394
11395 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
11396 if (!NewT)
11397 return ExprError();
11398
11399 if (!getDerived().AlwaysRebuild() && OldT == NewT)
11400 return E;
11401
11402 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
11403 E->getKind(),
11404 E->getSourceRange());
11405 }
11406
11407 // C++0x [expr.sizeof]p1:
11408 // The operand is either an expression, which is an unevaluated operand
11409 // [...]
11410 EnterExpressionEvaluationContext Unevaluated(
11413
11414 // Try to recover if we have something like sizeof(T::X) where X is a type.
11415 // Notably, there must be *exactly* one set of parens if X is a type.
11416 TypeSourceInfo *RecoveryTSI = nullptr;
11417 ExprResult SubExpr;
11418 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
11419 if (auto *DRE =
11420 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
11421 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
11422 PE, DRE, false, &RecoveryTSI);
11423 else
11424 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
11425
11426 if (RecoveryTSI) {
11427 return getDerived().RebuildUnaryExprOrTypeTrait(
11428 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
11429 } else if (SubExpr.isInvalid())
11430 return ExprError();
11431
11432 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
11433 return E;
11434
11435 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
11436 E->getOperatorLoc(),
11437 E->getKind(),
11438 E->getSourceRange());
11439}
11440
11441template<typename Derived>
11443TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
11444 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
11445 if (LHS.isInvalid())
11446 return ExprError();
11447
11448 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
11449 if (RHS.isInvalid())
11450 return ExprError();
11451
11452
11453 if (!getDerived().AlwaysRebuild() &&
11454 LHS.get() == E->getLHS() &&
11455 RHS.get() == E->getRHS())
11456 return E;
11457
11458 return getDerived().RebuildArraySubscriptExpr(
11459 LHS.get(),
11460 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
11461}
11462
11463template <typename Derived>
11465TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
11466 ExprResult Base = getDerived().TransformExpr(E->getBase());
11467 if (Base.isInvalid())
11468 return ExprError();
11469
11470 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
11471 if (RowIdx.isInvalid())
11472 return ExprError();
11473
11474 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
11475 if (ColumnIdx.isInvalid())
11476 return ExprError();
11477
11478 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
11479 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
11480 return E;
11481
11482 return getDerived().RebuildMatrixSubscriptExpr(
11483 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
11484}
11485
11486template <typename Derived>
11488TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
11489 ExprResult Base = getDerived().TransformExpr(E->getBase());
11490 if (Base.isInvalid())
11491 return ExprError();
11492
11493 ExprResult LowerBound;
11494 if (E->getLowerBound()) {
11495 LowerBound = getDerived().TransformExpr(E->getLowerBound());
11496 if (LowerBound.isInvalid())
11497 return ExprError();
11498 }
11499
11500 ExprResult Length;
11501 if (E->getLength()) {
11502 Length = getDerived().TransformExpr(E->getLength());
11503 if (Length.isInvalid())
11504 return ExprError();
11505 }
11506
11507 ExprResult Stride;
11508 if (Expr *Str = E->getStride()) {
11509 Stride = getDerived().TransformExpr(Str);
11510 if (Stride.isInvalid())
11511 return ExprError();
11512 }
11513
11514 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
11515 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
11516 return E;
11517
11518 return getDerived().RebuildOMPArraySectionExpr(
11519 Base.get(), E->getBase()->getEndLoc(), LowerBound.get(),
11520 E->getColonLocFirst(), E->getColonLocSecond(), Length.get(), Stride.get(),
11521 E->getRBracketLoc());
11522}
11523
11524template <typename Derived>
11526TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
11527 ExprResult Base = getDerived().TransformExpr(E->getBase());
11528 if (Base.isInvalid())
11529 return ExprError();
11530
11532 bool ErrorFound = false;
11533 for (Expr *Dim : E->getDimensions()) {
11534 ExprResult DimRes = getDerived().TransformExpr(Dim);
11535 if (DimRes.isInvalid()) {
11536 ErrorFound = true;
11537 continue;
11538 }
11539 Dims.push_back(DimRes.get());
11540 }
11541
11542 if (ErrorFound)
11543 return ExprError();
11544 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
11545 E->getRParenLoc(), Dims,
11546 E->getBracketsRanges());
11547}
11548
11549template <typename Derived>
11551TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) {
11552 unsigned NumIterators = E->numOfIterators();
11554
11555 bool ErrorFound = false;
11556 bool NeedToRebuild = getDerived().AlwaysRebuild();
11557 for (unsigned I = 0; I < NumIterators; ++I) {
11558 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
11559 Data[I].DeclIdent = D->getIdentifier();
11560 Data[I].DeclIdentLoc = D->getLocation();
11561 if (D->getLocation() == D->getBeginLoc()) {
11562 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
11563 "Implicit type must be int.");
11564 } else {
11565 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
11566 QualType DeclTy = getDerived().TransformType(D->getType());
11567 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
11568 }
11569 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
11570 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
11571 ExprResult End = getDerived().TransformExpr(Range.End);
11572 ExprResult Step = getDerived().TransformExpr(Range.Step);
11573 ErrorFound = ErrorFound ||
11574 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
11575 !Data[I].Type.get().isNull())) ||
11576 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
11577 if (ErrorFound)
11578 continue;
11579 Data[I].Range.Begin = Begin.get();
11580 Data[I].Range.End = End.get();
11581 Data[I].Range.Step = Step.get();
11582 Data[I].AssignLoc = E->getAssignLoc(I);
11583 Data[I].ColonLoc = E->getColonLoc(I);
11584 Data[I].SecColonLoc = E->getSecondColonLoc(I);
11585 NeedToRebuild =
11586 NeedToRebuild ||
11587 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
11588 D->getType().getTypePtrOrNull()) ||
11589 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
11590 Range.Step != Data[I].Range.Step;
11591 }
11592 if (ErrorFound)
11593 return ExprError();
11594 if (!NeedToRebuild)
11595 return E;
11596
11597 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
11598 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
11599 if (!Res.isUsable())
11600 return Res;
11601 auto *IE = cast<OMPIteratorExpr>(Res.get());
11602 for (unsigned I = 0; I < NumIterators; ++I)
11603 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
11604 IE->getIteratorDecl(I));
11605 return Res;
11606}
11607
11608template<typename Derived>
11610TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
11611 // Transform the callee.
11612 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
11613 if (Callee.isInvalid())
11614 return ExprError();
11615
11616 // Transform arguments.
11617 bool ArgChanged = false;
11619 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
11620 &ArgChanged))
11621 return ExprError();
11622
11623 if (!getDerived().AlwaysRebuild() &&
11624 Callee.get() == E->getCallee() &&
11625 !ArgChanged)
11626 return SemaRef.MaybeBindToTemporary(E);
11627
11628 // FIXME: Wrong source location information for the '('.
11629 SourceLocation FakeLParenLoc
11630 = ((Expr *)Callee.get())->getSourceRange().getBegin();
11631
11632 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
11633 if (E->hasStoredFPFeatures()) {
11634 FPOptionsOverride NewOverrides = E->getFPFeatures();
11635 getSema().CurFPFeatures =
11636 NewOverrides.applyOverrides(getSema().getLangOpts());
11637 getSema().FpPragmaStack.CurrentValue = NewOverrides;
11638 }
11639
11640 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
11641 Args,
11642 E->getRParenLoc());
11643}
11644
11645template<typename Derived>
11647TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
11648 ExprResult Base = getDerived().TransformExpr(E->getBase());
11649 if (Base.isInvalid())
11650 return ExprError();
11651
11652 NestedNameSpecifierLoc QualifierLoc;
11653 if (E->hasQualifier()) {
11654 QualifierLoc
11655 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
11656
11657 if (!QualifierLoc)
11658 return ExprError();
11659 }
11660 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
11661
11662 ValueDecl *Member
11663 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
11664 E->getMemberDecl()));
11665 if (!Member)
11666 return ExprError();
11667
11668 NamedDecl *FoundDecl = E->getFoundDecl();
11669 if (FoundDecl == E->getMemberDecl()) {
11670 FoundDecl = Member;
11671 } else {
11672 FoundDecl = cast_or_null<NamedDecl>(
11673 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
11674 if (!FoundDecl)
11675 return ExprError();
11676 }
11677
11678 if (!getDerived().AlwaysRebuild() &&
11679 Base.get() == E->getBase() &&
11680 QualifierLoc == E->getQualifierLoc() &&
11681 Member == E->getMemberDecl() &&
11682 FoundDecl == E->getFoundDecl() &&
11683 !E->hasExplicitTemplateArgs()) {
11684
11685 // Skip for member expression of (this->f), rebuilt thisi->f is needed
11686 // for Openmp where the field need to be privatizized in the case.
11687 if (!(isa<CXXThisExpr>(E->getBase()) &&
11688 getSema().isOpenMPRebuildMemberExpr(cast<ValueDecl>(Member)))) {
11689 // Mark it referenced in the new context regardless.
11690 // FIXME: this is a bit instantiation-specific.
11691 SemaRef.MarkMemberReferenced(E);
11692 return E;
11693 }
11694 }
11695
11696 TemplateArgumentListInfo TransArgs;
11697 if (E->hasExplicitTemplateArgs()) {
11698 TransArgs.setLAngleLoc(E->getLAngleLoc());
11699 TransArgs.setRAngleLoc(E->getRAngleLoc());
11700 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
11701 E->getNumTemplateArgs(),
11702 TransArgs))
11703 return ExprError();
11704 }
11705
11706 // FIXME: Bogus source location for the operator
11707 SourceLocation FakeOperatorLoc =
11708 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
11709
11710 // FIXME: to do this check properly, we will need to preserve the
11711 // first-qualifier-in-scope here, just in case we had a dependent
11712 // base (and therefore couldn't do the check) and a
11713 // nested-name-qualifier (and therefore could do the lookup).
11714 NamedDecl *FirstQualifierInScope = nullptr;
11715 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
11716 if (MemberNameInfo.getName()) {
11717 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
11718 if (!MemberNameInfo.getName())
11719 return ExprError();
11720 }
11721
11722 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
11723 E->isArrow(),
11724 QualifierLoc,
11725 TemplateKWLoc,
11726 MemberNameInfo,
11727 Member,
11728 FoundDecl,
11729 (E->hasExplicitTemplateArgs()
11730 ? &TransArgs : nullptr),
11731 FirstQualifierInScope);
11732}
11733
11734template<typename Derived>
11736TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
11737 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
11738 if (LHS.isInvalid())
11739 return ExprError();
11740
11741 ExprResult RHS =
11742 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
11743 if (RHS.isInvalid())
11744 return ExprError();
11745
11746 if (!getDerived().AlwaysRebuild() &&
11747 LHS.get() == E->getLHS() &&
11748 RHS.get() == E->getRHS())
11749 return E;
11750
11751 if (E->isCompoundAssignmentOp())
11752 // FPFeatures has already been established from trailing storage
11753 return getDerived().RebuildBinaryOperator(
11754 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
11755 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
11756 FPOptionsOverride NewOverrides(E->getFPFeatures());
11757 getSema().CurFPFeatures =
11758 NewOverrides.applyOverrides(getSema().getLangOpts());
11759 getSema().FpPragmaStack.CurrentValue = NewOverrides;
11760 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
11761 LHS.get(), RHS.get());
11762}
11763
11764template <typename Derived>
11765ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
11766 CXXRewrittenBinaryOperator *E) {
11767 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
11768
11769 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
11770 if (LHS.isInvalid())
11771 return ExprError();
11772
11773 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
11774 if (RHS.isInvalid())
11775 return ExprError();
11776
11777 // Extract the already-resolved callee declarations so that we can restrict
11778 // ourselves to using them as the unqualified lookup results when rebuilding.
11779 UnresolvedSet<2> UnqualLookups;
11780 bool ChangedAnyLookups = false;
11781 Expr *PossibleBinOps[] = {E->getSemanticForm(),
11782 const_cast<Expr *>(Decomp.InnerBinOp)};
11783 for (Expr *PossibleBinOp : PossibleBinOps) {
11784 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
11785 if (!Op)
11786 continue;
11787 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
11788 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
11789 continue;
11790
11791 // Transform the callee in case we built a call to a local extern
11792 // declaration.
11793 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
11794 E->getOperatorLoc(), Callee->getFoundDecl()));
11795 if (!Found)
11796 return ExprError();
11797 if (Found != Callee->getFoundDecl())
11798 ChangedAnyLookups = true;
11799 UnqualLookups.addDecl(Found);
11800 }
11801
11802 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
11803 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
11804 // Mark all functions used in the rewrite as referenced. Note that when
11805 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
11806 // function calls, and/or there might be a user-defined conversion sequence
11807 // applied to the operands of the <.
11808 // FIXME: this is a bit instantiation-specific.
11809 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
11810 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
11811 return E;
11812 }
11813
11814 return getDerived().RebuildCXXRewrittenBinaryOperator(
11815 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
11816}
11817
11818template<typename Derived>
11820TreeTransform<Derived>::TransformCompoundAssignOperator(
11821 CompoundAssignOperator *E) {
11822 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
11823 FPOptionsOverride NewOverrides(E->getFPFeatures());
11824 getSema().CurFPFeatures =
11825 NewOverrides.applyOverrides(getSema().getLangOpts());
11826 getSema().FpPragmaStack.CurrentValue = NewOverrides;
11827 return getDerived().TransformBinaryOperator(E);
11828}
11829
11830template<typename Derived>
11831ExprResult TreeTransform<Derived>::
11832TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
11833 // Just rebuild the common and RHS expressions and see whether we
11834 // get any changes.
11835
11836 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
11837 if (commonExpr.isInvalid())
11838 return ExprError();
11839
11840 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
11841 if (rhs.isInvalid())
11842 return ExprError();
11843
11844 if (!getDerived().AlwaysRebuild() &&
11845 commonExpr.get() == e->getCommon() &&
11846 rhs.get() == e->getFalseExpr())
11847 return e;
11848
11849 return getDerived().RebuildConditionalOperator(commonExpr.get(),
11850 e->getQuestionLoc(),
11851 nullptr,
11852 e->getColonLoc(),
11853 rhs.get());
11854}
11855
11856template<typename Derived>
11858TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
11859 ExprResult Cond = getDerived().TransformExpr(E->getCond());
11860 if (Cond.isInvalid())
11861 return ExprError();
11862
11863 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
11864 if (LHS.isInvalid())
11865 return ExprError();
11866
11867 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
11868 if (RHS.isInvalid())
11869 return ExprError();
11870
11871 if (!getDerived().AlwaysRebuild() &&
11872 Cond.get() == E->getCond() &&
11873 LHS.get() == E->getLHS() &&
11874 RHS.get() == E->getRHS())
11875 return E;
11876
11877 return getDerived().RebuildConditionalOperator(Cond.get(),
11878 E->getQuestionLoc(),
11879 LHS.get(),
11880 E->getColonLoc(),
11881 RHS.get());
11882}
11883
11884template<typename Derived>
11886TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
11887 // Implicit casts are eliminated during transformation, since they
11888 // will be recomputed by semantic analysis after transformation.
11889 return getDerived().TransformExpr(E->getSubExprAsWritten());
11890}
11891
11892template<typename Derived>
11894TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
11895 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
11896 if (!Type)
11897 return ExprError();
11898
11899 ExprResult SubExpr
11900 = getDerived().TransformExpr(E->getSubExprAsWritten());
11901 if (SubExpr.isInvalid())
11902 return ExprError();
11903
11904 if (!getDerived().AlwaysRebuild() &&
11905 Type == E->getTypeInfoAsWritten() &&
11906 SubExpr.get() == E->getSubExpr())
11907 return E;
11908
11909 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
11910 Type,
11911 E->getRParenLoc(),
11912 SubExpr.get());
11913}
11914
11915template<typename Derived>
11917TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
11918 TypeSourceInfo *OldT = E->getTypeSourceInfo();
11919 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
11920 if (!NewT)
11921 return ExprError();
11922
11923 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
11924 if (Init.isInvalid())
11925 return ExprError();
11926
11927 if (!getDerived().AlwaysRebuild() &&
11928 OldT == NewT &&
11929 Init.get() == E->getInitializer())
11930 return SemaRef.MaybeBindToTemporary(E);
11931
11932 // Note: the expression type doesn't necessarily match the
11933 // type-as-written, but that's okay, because it should always be
11934 // derivable from the initializer.
11935
11936 return getDerived().RebuildCompoundLiteralExpr(
11937 E->getLParenLoc(), NewT,
11938 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
11939}
11940
11941template<typename Derived>
11943TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
11944 ExprResult Base = getDerived().TransformExpr(E->getBase());
11945 if (Base.isInvalid())
11946 return ExprError();
11947
11948 if (!getDerived().AlwaysRebuild() &&
11949 Base.get() == E->getBase())
11950 return E;
11951
11952 // FIXME: Bad source location
11953 SourceLocation FakeOperatorLoc =
11954 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
11955 return getDerived().RebuildExtVectorElementExpr(
11956 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
11957 E->getAccessor());
11958}
11959
11960template<typename Derived>
11962TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
11963 if (InitListExpr *Syntactic = E->getSyntacticForm())
11964 E = Syntactic;
11965
11966 bool InitChanged = false;
11967
11968 EnterExpressionEvaluationContext Context(
11970
11972 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
11973 Inits, &InitChanged))
11974 return ExprError();
11975
11976 if (!getDerived().AlwaysRebuild() && !InitChanged) {
11977 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
11978 // in some cases. We can't reuse it in general, because the syntactic and
11979 // semantic forms are linked, and we can't know that semantic form will
11980 // match even if the syntactic form does.
11981 }
11982
11983 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
11984 E->getRBraceLoc());
11985}
11986
11987template<typename Derived>
11989TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
11990 Designation Desig;
11991
11992 // transform the initializer value
11993 ExprResult Init = getDerived().TransformExpr(E->getInit());
11994 if (Init.isInvalid())
11995 return ExprError();
11996
11997 // transform the designators.
11998 SmallVector<Expr*, 4> ArrayExprs;
11999 bool ExprChanged = false;
12000 for (const DesignatedInitExpr::Designator &D : E->designators()) {
12001 if (D.isFieldDesignator()) {
12002 if (D.getFieldDecl()) {
12003 FieldDecl *Field = cast_or_null<FieldDecl>(
12004 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
12005 if (Field != D.getFieldDecl())
12006 // Rebuild the expression when the transformed FieldDecl is
12007 // different to the already assigned FieldDecl.
12008 ExprChanged = true;
12009 if (Field->isAnonymousStructOrUnion())
12010 continue;
12011 } else {
12012 // Ensure that the designator expression is rebuilt when there isn't
12013 // a resolved FieldDecl in the designator as we don't want to assign
12014 // a FieldDecl to a pattern designator that will be instantiated again.
12015 ExprChanged = true;
12016 }
12017 Desig.AddDesignator(Designator::CreateFieldDesignator(
12018 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
12019 continue;
12020 }
12021
12022 if (D.isArrayDesignator()) {
12023 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
12024 if (Index.isInvalid())
12025 return ExprError();
12026
12027 Desig.AddDesignator(
12028 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
12029
12030 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
12031 ArrayExprs.push_back(Index.get());
12032 continue;
12033 }
12034
12035 assert(D.isArrayRangeDesignator() && "New kind of designator?");
12036 ExprResult Start
12037 = getDerived().TransformExpr(E->getArrayRangeStart(D));
12038 if (Start.isInvalid())
12039 return ExprError();
12040
12041 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
12042 if (End.isInvalid())
12043 return ExprError();
12044
12045 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
12046 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
12047
12048 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
12049 End.get() != E->getArrayRangeEnd(D);
12050
12051 ArrayExprs.push_back(Start.get());
12052 ArrayExprs.push_back(End.get());
12053 }
12054
12055 if (!getDerived().AlwaysRebuild() &&
12056 Init.get() == E->getInit() &&
12057 !ExprChanged)
12058 return E;
12059
12060 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
12061 E->getEqualOrColonLoc(),
12062 E->usesGNUSyntax(), Init.get());
12063}
12064
12065// Seems that if TransformInitListExpr() only works on the syntactic form of an
12066// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
12067template<typename Derived>
12069TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
12070 DesignatedInitUpdateExpr *E) {
12071 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
12072 "initializer");
12073 return ExprError();
12074}
12075
12076template<typename Derived>
12078TreeTransform<Derived>::TransformNoInitExpr(
12079 NoInitExpr *E) {
12080 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
12081 return ExprError();
12082}
12083
12084template<typename Derived>
12086TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
12087 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
12088 return ExprError();
12089}
12090
12091template<typename Derived>
12093TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
12094 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
12095 return ExprError();
12096}
12097
12098template<typename Derived>
12100TreeTransform<Derived>::TransformImplicitValueInitExpr(
12101 ImplicitValueInitExpr *E) {
12102 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
12103
12104 // FIXME: Will we ever have proper type location here? Will we actually
12105 // need to transform the type?
12106 QualType T = getDerived().TransformType(E->getType());
12107 if (T.isNull())
12108 return ExprError();
12109
12110 if (!getDerived().AlwaysRebuild() &&
12111 T == E->getType())
12112 return E;
12113
12114 return getDerived().RebuildImplicitValueInitExpr(T);
12115}
12116
12117template<typename Derived>
12119TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
12120 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
12121 if (!TInfo)
12122 return ExprError();
12123
12124 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12125 if (SubExpr.isInvalid())
12126 return ExprError();
12127
12128 if (!getDerived().AlwaysRebuild() &&
12129 TInfo == E->getWrittenTypeInfo() &&
12130 SubExpr.get() == E->getSubExpr())
12131 return E;
12132
12133 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
12134 TInfo, E->getRParenLoc());
12135}
12136
12137template<typename Derived>
12139TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
12140 bool ArgumentChanged = false;
12142 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
12143 &ArgumentChanged))
12144 return ExprError();
12145
12146 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
12147 Inits,
12148 E->getRParenLoc());
12149}
12150
12151/// Transform an address-of-label expression.
12152///
12153/// By default, the transformation of an address-of-label expression always
12154/// rebuilds the expression, so that the label identifier can be resolved to
12155/// the corresponding label statement by semantic analysis.
12156template<typename Derived>
12158TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
12159 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
12160 E->getLabel());
12161 if (!LD)
12162 return ExprError();
12163
12164 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
12165 cast<LabelDecl>(LD));
12166}
12167
12168template<typename Derived>
12170TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
12171 SemaRef.ActOnStartStmtExpr();
12172 StmtResult SubStmt
12173 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
12174 if (SubStmt.isInvalid()) {
12175 SemaRef.ActOnStmtExprError();
12176 return ExprError();
12177 }
12178
12179 unsigned OldDepth = E->getTemplateDepth();
12180 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
12181
12182 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
12183 SubStmt.get() == E->getSubStmt()) {
12184 // Calling this an 'error' is unintuitive, but it does the right thing.
12185 SemaRef.ActOnStmtExprError();
12186 return SemaRef.MaybeBindToTemporary(E);
12187 }
12188
12189 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
12190 E->getRParenLoc(), NewDepth);
12191}
12192
12193template<typename Derived>
12195TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
12196 ExprResult Cond = getDerived().TransformExpr(E->getCond());
12197 if (Cond.isInvalid())
12198 return ExprError();
12199
12200 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
12201 if (LHS.isInvalid())
12202 return ExprError();
12203
12204 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
12205 if (RHS.isInvalid())
12206 return ExprError();
12207
12208 if (!getDerived().AlwaysRebuild() &&
12209 Cond.get() == E->getCond() &&
12210 LHS.get() == E->getLHS() &&
12211 RHS.get() == E->getRHS())
12212 return E;
12213
12214 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
12215 Cond.get(), LHS.get(), RHS.get(),
12216 E->getRParenLoc());
12217}
12218
12219template<typename Derived>
12221TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
12222 return E;
12223}
12224
12225template<typename Derived>
12227TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
12228 switch (E->getOperator()) {
12229 case OO_New:
12230 case OO_Delete:
12231 case OO_Array_New:
12232 case OO_Array_Delete:
12233 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
12234
12235 case OO_Subscript:
12236 case OO_Call: {
12237 // This is a call to an object's operator().
12238 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
12239
12240 // Transform the object itself.
12241 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
12242 if (Object.isInvalid())
12243 return ExprError();
12244
12245 // FIXME: Poor location information
12246 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
12247 static_cast<Expr *>(Object.get())->getEndLoc());
12248
12249 // Transform the call arguments.
12251 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
12252 Args))
12253 return ExprError();
12254
12255 if (E->getOperator() == OO_Subscript)
12256 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
12257 Args, E->getEndLoc());
12258
12259 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
12260 E->getEndLoc());
12261 }
12262
12263#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
12264 case OO_##Name: \
12265 break;
12266
12267#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
12268#include "clang/Basic/OperatorKinds.def"
12269
12270 case OO_Conditional:
12271 llvm_unreachable("conditional operator is not actually overloadable");
12272
12273 case OO_None:
12275 llvm_unreachable("not an overloaded operator?");
12276 }
12277
12279 if (E->getOperator() == OO_Amp)
12280 First = getDerived().TransformAddressOfOperand(E->getArg(0));
12281 else
12282 First = getDerived().TransformExpr(E->getArg(0));
12283 if (First.isInvalid())
12284 return ExprError();
12285
12286 ExprResult Second;
12287 if (E->getNumArgs() == 2) {
12288 Second =
12289 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
12290 if (Second.isInvalid())
12291 return ExprError();
12292 }
12293
12294 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
12295 FPOptionsOverride NewOverrides(E->getFPFeatures());
12296 getSema().CurFPFeatures =
12297 NewOverrides.applyOverrides(getSema().getLangOpts());
12298 getSema().FpPragmaStack.CurrentValue = NewOverrides;
12299
12300 Expr *Callee = E->getCallee();
12301 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
12302 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
12304 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
12305 return ExprError();
12306
12307 return getDerived().RebuildCXXOperatorCallExpr(
12308 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
12309 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
12310 }
12311
12312 UnresolvedSet<1> Functions;
12313 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
12314 Callee = ICE->getSubExprAsWritten();
12315 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
12316 ValueDecl *VD = cast_or_null<ValueDecl>(
12317 getDerived().TransformDecl(DR->getLocation(), DR));
12318 if (!VD)
12319 return ExprError();
12320
12321 if (!isa<CXXMethodDecl>(VD))
12322 Functions.addDecl(VD);
12323
12324 return getDerived().RebuildCXXOperatorCallExpr(
12325 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
12326 /*RequiresADL=*/false, Functions, First.get(), Second.get());
12327}
12328
12329template<typename Derived>
12331TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
12332 return getDerived().TransformCallExpr(E);
12333}
12334
12335template <typename Derived>
12336ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
12337 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
12338 getSema().CurContext != E->getParentContext();
12339
12340 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
12341 return E;
12342
12343 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
12344 E->getBeginLoc(), E->getEndLoc(),
12345 getSema().CurContext);
12346}
12347
12348template<typename Derived>
12350TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
12351 // Transform the callee.
12352 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
12353 if (Callee.isInvalid())
12354 return ExprError();
12355
12356 // Transform exec config.
12357 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
12358 if (EC.isInvalid())
12359 return ExprError();
12360
12361 // Transform arguments.
12362 bool ArgChanged = false;
12364 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
12365 &ArgChanged))
12366 return ExprError();
12367
12368 if (!getDerived().AlwaysRebuild() &&
12369 Callee.get() == E->getCallee() &&
12370 !ArgChanged)
12371 return SemaRef.MaybeBindToTemporary(E);
12372
12373 // FIXME: Wrong source location information for the '('.
12374 SourceLocation FakeLParenLoc
12375 = ((Expr *)Callee.get())->getSourceRange().getBegin();
12376 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
12377 Args,
12378 E->getRParenLoc(), EC.get());
12379}
12380
12381template<typename Derived>
12384 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
12385 if (!Type)
12386 return ExprError();
12387
12388 ExprResult SubExpr
12389 = getDerived().TransformExpr(E->getSubExprAsWritten());
12390 if (SubExpr.isInvalid())
12391 return ExprError();
12392
12393 if (!getDerived().AlwaysRebuild() &&
12394 Type == E->getTypeInfoAsWritten() &&
12395 SubExpr.get() == E->getSubExpr())
12396 return E;
12397 return getDerived().RebuildCXXNamedCastExpr(
12400 // FIXME. this should be '(' location
12401 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
12402}
12403
12404template<typename Derived>
12407 TypeSourceInfo *TSI =
12408 getDerived().TransformType(BCE->getTypeInfoAsWritten());
12409 if (!TSI)
12410 return ExprError();
12411
12412 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
12413 if (Sub.isInvalid())
12414 return ExprError();
12415
12416 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
12417 Sub.get(), BCE->getEndLoc());
12418}
12419
12420template<typename Derived>
12422TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
12423 return getDerived().TransformCXXNamedCastExpr(E);
12424}
12425
12426template<typename Derived>
12428TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
12429 return getDerived().TransformCXXNamedCastExpr(E);
12430}
12431
12432template<typename Derived>
12434TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
12435 CXXReinterpretCastExpr *E) {
12436 return getDerived().TransformCXXNamedCastExpr(E);
12437}
12438
12439template<typename Derived>
12441TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
12442 return getDerived().TransformCXXNamedCastExpr(E);
12443}
12444
12445template<typename Derived>
12447TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
12448 return getDerived().TransformCXXNamedCastExpr(E);
12449}
12450
12451template<typename Derived>
12453TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
12454 CXXFunctionalCastExpr *E) {
12455 TypeSourceInfo *Type =
12456 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
12457 if (!Type)
12458 return ExprError();
12459
12460 ExprResult SubExpr
12461 = getDerived().TransformExpr(E->getSubExprAsWritten());
12462 if (SubExpr.isInvalid())
12463 return ExprError();
12464
12465 if (!getDerived().AlwaysRebuild() &&
12466 Type == E->getTypeInfoAsWritten() &&
12467 SubExpr.get() == E->getSubExpr())
12468 return E;
12469
12470 return getDerived().RebuildCXXFunctionalCastExpr(Type,
12471 E->getLParenLoc(),
12472 SubExpr.get(),
12473 E->getRParenLoc(),
12474 E->isListInitialization());
12475}
12476
12477template<typename Derived>
12479TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
12480 if (E->isTypeOperand()) {
12481 TypeSourceInfo *TInfo
12482 = getDerived().TransformType(E->getTypeOperandSourceInfo());
12483 if (!TInfo)
12484 return ExprError();
12485
12486 if (!getDerived().AlwaysRebuild() &&
12487 TInfo == E->getTypeOperandSourceInfo())
12488 return E;
12489
12490 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
12491 TInfo, E->getEndLoc());
12492 }
12493
12494 // Typeid's operand is an unevaluated context, unless it's a polymorphic
12495 // type. We must not unilaterally enter unevaluated context here, as then
12496 // semantic processing can re-transform an already transformed operand.
12497 Expr *Op = E->getExprOperand();
12499 if (E->isGLValue())
12500 if (auto *RecordT = Op->getType()->getAs<RecordType>())
12501 if (cast<CXXRecordDecl>(RecordT->getDecl())->isPolymorphic())
12502 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
12503
12504 EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx,
12506
12507 ExprResult SubExpr = getDerived().TransformExpr(Op);
12508 if (SubExpr.isInvalid())
12509 return ExprError();
12510
12511 if (!getDerived().AlwaysRebuild() &&
12512 SubExpr.get() == E->getExprOperand())
12513 return E;
12514
12515 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
12516 SubExpr.get(), E->getEndLoc());
12517}
12518
12519template<typename Derived>
12521TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
12522 if (E->isTypeOperand()) {
12523 TypeSourceInfo *TInfo
12524 = getDerived().TransformType(E->getTypeOperandSourceInfo());
12525 if (!TInfo)
12526 return ExprError();
12527
12528 if (!getDerived().AlwaysRebuild() &&
12529 TInfo == E->getTypeOperandSourceInfo())
12530 return E;
12531
12532 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
12533 TInfo, E->getEndLoc());
12534 }
12535
12536 EnterExpressionEvaluationContext Unevaluated(
12538
12539 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
12540 if (SubExpr.isInvalid())
12541 return ExprError();
12542
12543 if (!getDerived().AlwaysRebuild() &&
12544 SubExpr.get() == E->getExprOperand())
12545 return E;
12546
12547 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
12548 SubExpr.get(), E->getEndLoc());
12549}
12550
12551template<typename Derived>
12553TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
12554 return E;
12555}
12556
12557template<typename Derived>
12559TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
12560 CXXNullPtrLiteralExpr *E) {
12561 return E;
12562}
12563
12564template<typename Derived>
12566TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
12567
12568 // In lambdas, the qualifiers of the type depends of where in
12569 // the call operator `this` appear, and we do not have a good way to
12570 // rebuild this information, so we transform the type.
12571 //
12572 // In other contexts, the type of `this` may be overrided
12573 // for type deduction, so we need to recompute it.
12574 QualType T = getSema().getCurLambda() ?
12575 getDerived().TransformType(E->getType())
12576 : getSema().getCurrentThisType();
12577
12578 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
12579 // Mark it referenced in the new context regardless.
12580 // FIXME: this is a bit instantiation-specific.
12581 getSema().MarkThisReferenced(E);
12582 return E;
12583 }
12584
12585 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
12586}
12587
12588template<typename Derived>
12590TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
12591 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12592 if (SubExpr.isInvalid())
12593 return ExprError();
12594
12595 if (!getDerived().AlwaysRebuild() &&
12596 SubExpr.get() == E->getSubExpr())
12597 return E;
12598
12599 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
12600 E->isThrownVariableInScope());
12601}
12602
12603template<typename Derived>
12605TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
12606 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
12607 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
12608 if (!Param)
12609 return ExprError();
12610
12611 ExprResult InitRes;
12612 if (E->hasRewrittenInit()) {
12613 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
12614 if (InitRes.isInvalid())
12615 return ExprError();
12616 }
12617
12618 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
12619 E->getUsedContext() == SemaRef.CurContext &&
12620 InitRes.get() == E->getRewrittenExpr())
12621 return E;
12622
12623 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
12624 InitRes.get());
12625}
12626
12627template<typename Derived>
12629TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
12630 FieldDecl *Field = cast_or_null<FieldDecl>(
12631 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
12632 if (!Field)
12633 return ExprError();
12634
12635 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
12636 E->getUsedContext() == SemaRef.CurContext)
12637 return E;
12638
12639 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
12640}
12641
12642template<typename Derived>
12644TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
12645 CXXScalarValueInitExpr *E) {
12646 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
12647 if (!T)
12648 return ExprError();
12649
12650 if (!getDerived().AlwaysRebuild() &&
12651 T == E->getTypeSourceInfo())
12652 return E;
12653
12654 return getDerived().RebuildCXXScalarValueInitExpr(T,
12655 /*FIXME:*/T->getTypeLoc().getEndLoc(),
12656 E->getRParenLoc());
12657}
12658
12659template<typename Derived>
12661TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
12662 // Transform the type that we're allocating
12663 TypeSourceInfo *AllocTypeInfo =
12664 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
12665 if (!AllocTypeInfo)
12666 return ExprError();
12667
12668 // Transform the size of the array we're allocating (if any).
12669 std::optional<Expr *> ArraySize;
12670 if (E->isArray()) {
12671 ExprResult NewArraySize;
12672 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
12673 NewArraySize = getDerived().TransformExpr(*OldArraySize);
12674 if (NewArraySize.isInvalid())
12675 return ExprError();
12676 }
12677 ArraySize = NewArraySize.get();
12678 }
12679
12680 // Transform the placement arguments (if any).
12681 bool ArgumentChanged = false;
12682 SmallVector<Expr*, 8> PlacementArgs;
12683 if (getDerived().TransformExprs(E->getPlacementArgs(),
12684 E->getNumPlacementArgs(), true,
12685 PlacementArgs, &ArgumentChanged))
12686 return ExprError();
12687
12688 // Transform the initializer (if any).
12689 Expr *OldInit = E->getInitializer();
12690 ExprResult NewInit;
12691 if (OldInit)
12692 NewInit = getDerived().TransformInitializer(OldInit, true);
12693 if (NewInit.isInvalid())
12694 return ExprError();
12695
12696 // Transform new operator and delete operator.
12697 FunctionDecl *OperatorNew = nullptr;
12698 if (E->getOperatorNew()) {
12699 OperatorNew = cast_or_null<FunctionDecl>(
12700 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
12701 if (!OperatorNew)
12702 return ExprError();
12703 }
12704
12705 FunctionDecl *OperatorDelete = nullptr;
12706 if (E->getOperatorDelete()) {
12707 OperatorDelete = cast_or_null<FunctionDecl>(
12708 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
12709 if (!OperatorDelete)
12710 return ExprError();
12711 }
12712
12713 if (!getDerived().AlwaysRebuild() &&
12714 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
12715 ArraySize == E->getArraySize() &&
12716 NewInit.get() == OldInit &&
12717 OperatorNew == E->getOperatorNew() &&
12718 OperatorDelete == E->getOperatorDelete() &&
12719 !ArgumentChanged) {
12720 // Mark any declarations we need as referenced.
12721 // FIXME: instantiation-specific.
12722 if (OperatorNew)
12723 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
12724 if (OperatorDelete)
12725 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
12726
12727 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
12728 QualType ElementType
12729 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
12730 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
12731 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
12732 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
12733 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
12734 }
12735 }
12736 }
12737
12738 return E;
12739 }
12740
12741 QualType AllocType = AllocTypeInfo->getType();
12742 if (!ArraySize) {
12743 // If no array size was specified, but the new expression was
12744 // instantiated with an array type (e.g., "new T" where T is
12745 // instantiated with "int[4]"), extract the outer bound from the
12746 // array type as our array size. We do this with constant and
12747 // dependently-sized array types.
12748 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
12749 if (!ArrayT) {
12750 // Do nothing
12751 } else if (const ConstantArrayType *ConsArrayT
12752 = dyn_cast<ConstantArrayType>(ArrayT)) {
12753 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
12754 SemaRef.Context.getSizeType(),
12755 /*FIXME:*/ E->getBeginLoc());
12756 AllocType = ConsArrayT->getElementType();
12757 } else if (const DependentSizedArrayType *DepArrayT
12758 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
12759 if (DepArrayT->getSizeExpr()) {
12760 ArraySize = DepArrayT->getSizeExpr();
12761 AllocType = DepArrayT->getElementType();
12762 }
12763 }
12764 }
12765
12766 return getDerived().RebuildCXXNewExpr(
12767 E->getBeginLoc(), E->isGlobalNew(),
12768 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
12769 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
12770 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
12771}
12772
12773template<typename Derived>
12775TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
12776 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
12777 if (Operand.isInvalid())
12778 return ExprError();
12779
12780 // Transform the delete operator, if known.
12781 FunctionDecl *OperatorDelete = nullptr;
12782 if (E->getOperatorDelete()) {
12783 OperatorDelete = cast_or_null<FunctionDecl>(
12784 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
12785 if (!OperatorDelete)
12786 return ExprError();
12787 }
12788
12789 if (!getDerived().AlwaysRebuild() &&
12790 Operand.get() == E->getArgument() &&
12791 OperatorDelete == E->getOperatorDelete()) {
12792 // Mark any declarations we need as referenced.
12793 // FIXME: instantiation-specific.
12794 if (OperatorDelete)
12795 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
12796
12797 if (!E->getArgument()->isTypeDependent()) {
12798 QualType Destroyed = SemaRef.Context.getBaseElementType(
12799 E->getDestroyedType());
12800 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
12801 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
12802 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
12803 SemaRef.LookupDestructor(Record));
12804 }
12805 }
12806
12807 return E;
12808 }
12809
12810 return getDerived().RebuildCXXDeleteExpr(
12811 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
12812}
12813
12814template<typename Derived>
12816TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
12817 CXXPseudoDestructorExpr *E) {
12818 ExprResult Base = getDerived().TransformExpr(E->getBase());
12819 if (Base.isInvalid())
12820 return ExprError();
12821
12822 ParsedType ObjectTypePtr;
12823 bool MayBePseudoDestructor = false;
12824 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
12825 E->getOperatorLoc(),
12826 E->isArrow()? tok::arrow : tok::period,
12827 ObjectTypePtr,
12828 MayBePseudoDestructor);
12829 if (Base.isInvalid())
12830 return ExprError();
12831
12832 QualType ObjectType = ObjectTypePtr.get();
12833 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
12834 if (QualifierLoc) {
12835 QualifierLoc
12836 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
12837 if (!QualifierLoc)
12838 return ExprError();
12839 }
12840 CXXScopeSpec SS;
12841 SS.Adopt(QualifierLoc);
12842
12843 PseudoDestructorTypeStorage Destroyed;
12844 if (E->getDestroyedTypeInfo()) {
12845 TypeSourceInfo *DestroyedTypeInfo
12846 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
12847 ObjectType, nullptr, SS);
12848 if (!DestroyedTypeInfo)
12849 return ExprError();
12850 Destroyed = DestroyedTypeInfo;
12851 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
12852 // We aren't likely to be able to resolve the identifier down to a type
12853 // now anyway, so just retain the identifier.
12854 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
12855 E->getDestroyedTypeLoc());
12856 } else {
12857 // Look for a destructor known with the given name.
12858 ParsedType T = SemaRef.getDestructorName(
12859 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
12860 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
12861 if (!T)
12862 return ExprError();
12863
12864 Destroyed
12866 E->getDestroyedTypeLoc());
12867 }
12868
12869 TypeSourceInfo *ScopeTypeInfo = nullptr;
12870 if (E->getScopeTypeInfo()) {
12871 CXXScopeSpec EmptySS;
12872 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
12873 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
12874 if (!ScopeTypeInfo)
12875 return ExprError();
12876 }
12877
12878 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
12879 E->getOperatorLoc(),
12880 E->isArrow(),
12881 SS,
12882 ScopeTypeInfo,
12883 E->getColonColonLoc(),
12884 E->getTildeLoc(),
12885 Destroyed);
12886}
12887
12888template <typename Derived>
12890 bool RequiresADL,
12891 LookupResult &R) {
12892 // Transform all the decls.
12893 bool AllEmptyPacks = true;
12894 for (auto *OldD : Old->decls()) {
12895 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
12896 if (!InstD) {
12897 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
12898 // This can happen because of dependent hiding.
12899 if (isa<UsingShadowDecl>(OldD))
12900 continue;
12901 else {
12902 R.clear();
12903 return true;
12904 }
12905 }
12906
12907 // Expand using pack declarations.
12908 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
12909 ArrayRef<NamedDecl*> Decls = SingleDecl;
12910 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
12911 Decls = UPD->expansions();
12912
12913 // Expand using declarations.
12914 for (auto *D : Decls) {
12915 if (auto *UD = dyn_cast<UsingDecl>(D)) {
12916 for (auto *SD : UD->shadows())
12917 R.addDecl(SD);
12918 } else {
12919 R.addDecl(D);
12920 }
12921 }
12922
12923 AllEmptyPacks &= Decls.empty();
12924 };
12925
12926 // C++ [temp.res]/8.4.2:
12927 // The program is ill-formed, no diagnostic required, if [...] lookup for
12928 // a name in the template definition found a using-declaration, but the
12929 // lookup in the corresponding scope in the instantiation odoes not find
12930 // any declarations because the using-declaration was a pack expansion and
12931 // the corresponding pack is empty
12932 if (AllEmptyPacks && !RequiresADL) {
12933 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
12934 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
12935 return true;
12936 }
12937
12938 // Resolve a kind, but don't do any further analysis. If it's
12939 // ambiguous, the callee needs to deal with it.
12940 R.resolveKind();
12941 return false;
12942}
12943
12944template<typename Derived>
12947 UnresolvedLookupExpr *Old) {
12948 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
12950
12951 // Transform the declaration set.
12952 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
12953 return ExprError();
12954
12955 // Rebuild the nested-name qualifier, if present.
12956 CXXScopeSpec SS;
12957 if (Old->getQualifierLoc()) {
12958 NestedNameSpecifierLoc QualifierLoc
12959 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
12960 if (!QualifierLoc)
12961 return ExprError();
12962
12963 SS.Adopt(QualifierLoc);
12964 }
12965
12966 if (Old->getNamingClass()) {
12967 CXXRecordDecl *NamingClass
12968 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
12969 Old->getNameLoc(),
12970 Old->getNamingClass()));
12971 if (!NamingClass) {
12972 R.clear();
12973 return ExprError();
12974 }
12975
12976 R.setNamingClass(NamingClass);
12977 }
12978
12979 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
12980
12981 // If we have neither explicit template arguments, nor the template keyword,
12982 // it's a normal declaration name or member reference.
12983 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
12984 NamedDecl *D = R.getAsSingle<NamedDecl>();
12985 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
12986 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
12987 // give a good diagnostic.
12988 if (D && D->isCXXInstanceMember()) {
12989 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
12990 /*TemplateArgs=*/nullptr,
12991 /*Scope=*/nullptr);
12992 }
12993
12994 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
12995 }
12996
12997 // If we have template arguments, rebuild them, then rebuild the
12998 // templateid expression.
12999 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
13000 if (Old->hasExplicitTemplateArgs() &&
13001 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
13002 Old->getNumTemplateArgs(),
13003 TransArgs)) {
13004 R.clear();
13005 return ExprError();
13006 }
13007
13008 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
13009 Old->requiresADL(), &TransArgs);
13010}
13011
13012template<typename Derived>
13014TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
13015 bool ArgChanged = false;
13017 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
13018 TypeSourceInfo *From = E->getArg(I);
13019 TypeLoc FromTL = From->getTypeLoc();
13020 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
13021 TypeLocBuilder TLB;
13022 TLB.reserve(FromTL.getFullDataSize());
13023 QualType To = getDerived().TransformType(TLB, FromTL);
13024 if (To.isNull())
13025 return ExprError();
13026
13027 if (To == From->getType())
13028 Args.push_back(From);
13029 else {
13030 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
13031 ArgChanged = true;
13032 }
13033 continue;
13034 }
13035
13036 ArgChanged = true;
13037
13038 // We have a pack expansion. Instantiate it.
13039 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
13040 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
13042 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
13043
13044 // Determine whether the set of unexpanded parameter packs can and should
13045 // be expanded.
13046 bool Expand = true;
13047 bool RetainExpansion = false;
13048 std::optional<unsigned> OrigNumExpansions =
13049 ExpansionTL.getTypePtr()->getNumExpansions();
13050 std::optional<unsigned> NumExpansions = OrigNumExpansions;
13051 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
13052 PatternTL.getSourceRange(),
13053 Unexpanded,
13054 Expand, RetainExpansion,
13055 NumExpansions))
13056 return ExprError();
13057
13058 if (!Expand) {
13059 // The transform has determined that we should perform a simple
13060 // transformation on the pack expansion, producing another pack
13061 // expansion.
13062 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
13063
13064 TypeLocBuilder TLB;
13065 TLB.reserve(From->getTypeLoc().getFullDataSize());
13066
13067 QualType To = getDerived().TransformType(TLB, PatternTL);
13068 if (To.isNull())
13069 return ExprError();
13070
13071 To = getDerived().RebuildPackExpansionType(To,
13072 PatternTL.getSourceRange(),
13073 ExpansionTL.getEllipsisLoc(),
13074 NumExpansions);
13075 if (To.isNull())
13076 return ExprError();
13077
13078 PackExpansionTypeLoc ToExpansionTL
13079 = TLB.push<PackExpansionTypeLoc>(To);
13080 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
13081 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
13082 continue;
13083 }
13084
13085 // Expand the pack expansion by substituting for each argument in the
13086 // pack(s).
13087 for (unsigned I = 0; I != *NumExpansions; ++I) {
13088 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
13089 TypeLocBuilder TLB;
13090 TLB.reserve(PatternTL.getFullDataSize());
13091 QualType To = getDerived().TransformType(TLB, PatternTL);
13092 if (To.isNull())
13093 return ExprError();
13094
13095 if (To->containsUnexpandedParameterPack()) {
13096 To = getDerived().RebuildPackExpansionType(To,
13097 PatternTL.getSourceRange(),
13098 ExpansionTL.getEllipsisLoc(),
13099 NumExpansions);
13100 if (To.isNull())
13101 return ExprError();
13102
13103 PackExpansionTypeLoc ToExpansionTL
13104 = TLB.push<PackExpansionTypeLoc>(To);
13105 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
13106 }
13107
13108 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
13109 }
13110
13111 if (!RetainExpansion)
13112 continue;
13113
13114 // If we're supposed to retain a pack expansion, do so by temporarily
13115 // forgetting the partially-substituted parameter pack.
13116 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
13117
13118 TypeLocBuilder TLB;
13119 TLB.reserve(From->getTypeLoc().getFullDataSize());
13120
13121 QualType To = getDerived().TransformType(TLB, PatternTL);
13122 if (To.isNull())
13123 return ExprError();
13124
13125 To = getDerived().RebuildPackExpansionType(To,
13126 PatternTL.getSourceRange(),
13127 ExpansionTL.getEllipsisLoc(),
13128 NumExpansions);
13129 if (To.isNull())
13130 return ExprError();
13131
13132 PackExpansionTypeLoc ToExpansionTL
13133 = TLB.push<PackExpansionTypeLoc>(To);
13134 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
13135 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
13136 }
13137
13138 if (!getDerived().AlwaysRebuild() && !ArgChanged)
13139 return E;
13140
13141 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
13142 E->getEndLoc());
13143}
13144
13145template<typename Derived>
13147TreeTransform<Derived>::TransformConceptSpecializationExpr(
13148 ConceptSpecializationExpr *E) {
13149 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
13150 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
13151 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
13152 Old->NumTemplateArgs, TransArgs))
13153 return ExprError();
13154
13155 return getDerived().RebuildConceptSpecializationExpr(
13156 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
13157 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
13158 &TransArgs);
13159}
13160
13161template<typename Derived>
13163TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) {
13164 SmallVector<ParmVarDecl*, 4> TransParams;
13165 SmallVector<QualType, 4> TransParamTypes;
13166 Sema::ExtParameterInfoBuilder ExtParamInfos;
13167
13168 // C++2a [expr.prim.req]p2
13169 // Expressions appearing within a requirement-body are unevaluated operands.
13170 EnterExpressionEvaluationContext Ctx(
13173
13174 RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
13175 getSema().Context, getSema().CurContext,
13176 E->getBody()->getBeginLoc());
13177
13178 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
13179
13180 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
13181 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
13182 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
13183
13184 for (ParmVarDecl *Param : TransParams)
13185 if (Param)
13186 Param->setDeclContext(Body);
13187
13188 // On failure to transform, TransformRequiresTypeParams returns an expression
13189 // in the event that the transformation of the type params failed in some way.
13190 // It is expected that this will result in a 'not satisfied' Requires clause
13191 // when instantiating.
13192 if (!TypeParamResult.isUnset())
13193 return TypeParamResult;
13194
13196 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
13197 TransReqs))
13198 return ExprError();
13199
13200 for (concepts::Requirement *Req : TransReqs) {
13201 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
13202 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
13203 ER->getReturnTypeRequirement()
13204 .getTypeConstraintTemplateParameterList()->getParam(0)
13205 ->setDeclContext(Body);
13206 }
13207 }
13208 }
13209
13210 return getDerived().RebuildRequiresExpr(
13211 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
13212 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
13213}
13214
13215template<typename Derived>
13219 for (concepts::Requirement *Req : Reqs) {
13220 concepts::Requirement *TransReq = nullptr;
13221 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
13222 TransReq = getDerived().TransformTypeRequirement(TypeReq);
13223 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
13224 TransReq = getDerived().TransformExprRequirement(ExprReq);
13225 else
13226 TransReq = getDerived().TransformNestedRequirement(
13227 cast<concepts::NestedRequirement>(Req));
13228 if (!TransReq)
13229 return true;
13230 Transformed.push_back(TransReq);
13231 }
13232 return false;
13233}
13234
13235template<typename Derived>
13239 if (Req->isSubstitutionFailure()) {
13240 if (getDerived().AlwaysRebuild())
13241 return getDerived().RebuildTypeRequirement(
13243 return Req;
13244 }
13245 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
13246 if (!TransType)
13247 return nullptr;
13248 return getDerived().RebuildTypeRequirement(TransType);
13249}
13250
13251template<typename Derived>
13254 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
13255 if (Req->isExprSubstitutionFailure())
13256 TransExpr = Req->getExprSubstitutionDiagnostic();
13257 else {
13258 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
13259 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
13260 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
13261 if (TransExprRes.isInvalid())
13262 return nullptr;
13263 TransExpr = TransExprRes.get();
13264 }
13265
13266 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
13267 const auto &RetReq = Req->getReturnTypeRequirement();
13268 if (RetReq.isEmpty())
13269 TransRetReq.emplace();
13270 else if (RetReq.isSubstitutionFailure())
13271 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
13272 else if (RetReq.isTypeConstraint()) {
13273 TemplateParameterList *OrigTPL =
13274 RetReq.getTypeConstraintTemplateParameterList();
13276 getDerived().TransformTemplateParameterList(OrigTPL);
13277 if (!TPL)
13278 return nullptr;
13279 TransRetReq.emplace(TPL);
13280 }
13281 assert(TransRetReq && "All code paths leading here must set TransRetReq");
13282 if (Expr *E = TransExpr.dyn_cast<Expr *>())
13283 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
13284 Req->getNoexceptLoc(),
13285 std::move(*TransRetReq));
13286 return getDerived().RebuildExprRequirement(
13288 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
13289}
13290
13291template<typename Derived>
13295 if (Req->hasInvalidConstraint()) {
13296 if (getDerived().AlwaysRebuild())
13297 return getDerived().RebuildNestedRequirement(
13299 return Req;
13300 }
13301 ExprResult TransConstraint =
13302 getDerived().TransformExpr(Req->getConstraintExpr());
13303 if (TransConstraint.isInvalid())
13304 return nullptr;
13305 return getDerived().RebuildNestedRequirement(TransConstraint.get());
13306}
13307
13308template<typename Derived>
13311 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
13312 if (!T)
13313 return ExprError();
13314
13315 if (!getDerived().AlwaysRebuild() &&
13316 T == E->getQueriedTypeSourceInfo())
13317 return E;
13318
13319 ExprResult SubExpr;
13320 {
13323 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
13324 if (SubExpr.isInvalid())
13325 return ExprError();
13326
13327 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
13328 return E;
13329 }
13330
13331 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
13332 SubExpr.get(), E->getEndLoc());
13333}
13334
13335template<typename Derived>
13337TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
13338 ExprResult SubExpr;
13339 {
13340 EnterExpressionEvaluationContext Unevaluated(
13342 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
13343 if (SubExpr.isInvalid())
13344 return ExprError();
13345
13346 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
13347 return E;
13348 }
13349
13350 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
13351 SubExpr.get(), E->getEndLoc());
13352}
13353
13354template <typename Derived>
13356 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
13357 TypeSourceInfo **RecoveryTSI) {
13358 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
13359 DRE, AddrTaken, RecoveryTSI);
13360
13361 // Propagate both errors and recovered types, which return ExprEmpty.
13362 if (!NewDRE.isUsable())
13363 return NewDRE;
13364
13365 // We got an expr, wrap it up in parens.
13366 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
13367 return PE;
13368 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
13369 PE->getRParen());
13370}
13371
13372template <typename Derived>
13375 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
13376 nullptr);
13377}
13378
13379template <typename Derived>
13381 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
13382 TypeSourceInfo **RecoveryTSI) {
13383 assert(E->getQualifierLoc());
13384 NestedNameSpecifierLoc QualifierLoc =
13385 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13386 if (!QualifierLoc)
13387 return ExprError();
13388 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13389
13390 // TODO: If this is a conversion-function-id, verify that the
13391 // destination type name (if present) resolves the same way after
13392 // instantiation as it did in the local scope.
13393
13394 DeclarationNameInfo NameInfo =
13395 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
13396 if (!NameInfo.getName())
13397 return ExprError();
13398
13399 if (!E->hasExplicitTemplateArgs()) {
13400 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
13401 // Note: it is sufficient to compare the Name component of NameInfo:
13402 // if name has not changed, DNLoc has not changed either.
13403 NameInfo.getName() == E->getDeclName())
13404 return E;
13405
13406 return getDerived().RebuildDependentScopeDeclRefExpr(
13407 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
13408 IsAddressOfOperand, RecoveryTSI);
13409 }
13410
13411 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
13412 if (getDerived().TransformTemplateArguments(
13413 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
13414 return ExprError();
13415
13416 return getDerived().RebuildDependentScopeDeclRefExpr(
13417 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
13418 RecoveryTSI);
13419}
13420
13421template<typename Derived>
13423TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
13424 // CXXConstructExprs other than for list-initialization and
13425 // CXXTemporaryObjectExpr are always implicit, so when we have
13426 // a 1-argument construction we just transform that argument.
13427 if (getDerived().AllowSkippingCXXConstructExpr() &&
13428 ((E->getNumArgs() == 1 ||
13429 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
13430 (!getDerived().DropCallArgument(E->getArg(0))) &&
13431 !E->isListInitialization()))
13432 return getDerived().TransformInitializer(E->getArg(0),
13433 /*DirectInit*/ false);
13434
13435 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
13436
13437 QualType T = getDerived().TransformType(E->getType());
13438 if (T.isNull())
13439 return ExprError();
13440
13441 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
13442 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
13443 if (!Constructor)
13444 return ExprError();
13445
13446 bool ArgumentChanged = false;
13448 {
13449 EnterExpressionEvaluationContext Context(
13451 E->isListInitialization());
13452 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13453 &ArgumentChanged))
13454 return ExprError();
13455 }
13456
13457 if (!getDerived().AlwaysRebuild() &&
13458 T == E->getType() &&
13459 Constructor == E->getConstructor() &&
13460 !ArgumentChanged) {
13461 // Mark the constructor as referenced.
13462 // FIXME: Instantiation-specific
13463 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
13464 return E;
13465 }
13466
13467 return getDerived().RebuildCXXConstructExpr(
13468 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
13469 E->hadMultipleCandidates(), E->isListInitialization(),
13470 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
13471 E->getConstructionKind(), E->getParenOrBraceRange());
13472}
13473
13474template<typename Derived>
13475ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
13476 CXXInheritedCtorInitExpr *E) {
13477 QualType T = getDerived().TransformType(E->getType());
13478 if (T.isNull())
13479 return ExprError();
13480
13481 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
13482 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
13483 if (!Constructor)
13484 return ExprError();
13485
13486 if (!getDerived().AlwaysRebuild() &&
13487 T == E->getType() &&
13488 Constructor == E->getConstructor()) {
13489 // Mark the constructor as referenced.
13490 // FIXME: Instantiation-specific
13491 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
13492 return E;
13493 }
13494
13495 return getDerived().RebuildCXXInheritedCtorInitExpr(
13496 T, E->getLocation(), Constructor,
13497 E->constructsVBase(), E->inheritedFromVBase());
13498}
13499
13500/// Transform a C++ temporary-binding expression.
13501///
13502/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
13503/// transform the subexpression and return that.
13504template<typename Derived>
13506TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
13507 if (auto *Dtor = E->getTemporary()->getDestructor())
13508 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
13509 const_cast<CXXDestructorDecl *>(Dtor));
13510 return getDerived().TransformExpr(E->getSubExpr());
13511}
13512
13513/// Transform a C++ expression that contains cleanups that should
13514/// be run after the expression is evaluated.
13515///
13516/// Since ExprWithCleanups nodes are implicitly generated, we
13517/// just transform the subexpression and return that.
13518template<typename Derived>
13520TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
13521 return getDerived().TransformExpr(E->getSubExpr());
13522}
13523
13524template<typename Derived>
13526TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
13527 CXXTemporaryObjectExpr *E) {
13528 TypeSourceInfo *T =
13529 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
13530 if (!T)
13531 return ExprError();
13532
13533 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
13534 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
13535 if (!Constructor)
13536 return ExprError();
13537
13538 bool ArgumentChanged = false;
13540 Args.reserve(E->getNumArgs());
13541 {
13542 EnterExpressionEvaluationContext Context(
13544 E->isListInitialization());
13545 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13546 &ArgumentChanged))
13547 return ExprError();
13548 }
13549
13550 if (!getDerived().AlwaysRebuild() &&
13551 T == E->getTypeSourceInfo() &&
13552 Constructor == E->getConstructor() &&
13553 !ArgumentChanged) {
13554 // FIXME: Instantiation-specific
13555 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
13556 return SemaRef.MaybeBindToTemporary(E);
13557 }
13558
13559 // FIXME: We should just pass E->isListInitialization(), but we're not
13560 // prepared to handle list-initialization without a child InitListExpr.
13561 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
13562 return getDerived().RebuildCXXTemporaryObjectExpr(
13563 T, LParenLoc, Args, E->getEndLoc(),
13564 /*ListInitialization=*/LParenLoc.isInvalid());
13565}
13566
13567template<typename Derived>
13569TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
13570 // Transform any init-capture expressions before entering the scope of the
13571 // lambda body, because they are not semantically within that scope.
13572 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
13573 struct TransformedInitCapture {
13574 // The location of the ... if the result is retaining a pack expansion.
13575 SourceLocation EllipsisLoc;
13576 // Zero or more expansions of the init-capture.
13578 };
13580 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
13581 for (LambdaExpr::capture_iterator C = E->capture_begin(),
13582 CEnd = E->capture_end();
13583 C != CEnd; ++C) {
13584 if (!E->isInitCapture(C))
13585 continue;
13586
13587 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
13588 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
13589
13590 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
13591 std::optional<unsigned> NumExpansions) {
13592 ExprResult NewExprInitResult = getDerived().TransformInitializer(
13593 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
13594
13595 if (NewExprInitResult.isInvalid()) {
13596 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
13597 return;
13598 }
13599 Expr *NewExprInit = NewExprInitResult.get();
13600
13601 QualType NewInitCaptureType =
13602 getSema().buildLambdaInitCaptureInitialization(
13603 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
13604 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
13605 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
13607 NewExprInit);
13608 Result.Expansions.push_back(
13609 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
13610 };
13611
13612 // If this is an init-capture pack, consider expanding the pack now.
13613 if (OldVD->isParameterPack()) {
13614 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
13615 ->getTypeLoc()
13616 .castAs<PackExpansionTypeLoc>();
13618 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
13619
13620 // Determine whether the set of unexpanded parameter packs can and should
13621 // be expanded.
13622 bool Expand = true;
13623 bool RetainExpansion = false;
13624 std::optional<unsigned> OrigNumExpansions =
13625 ExpansionTL.getTypePtr()->getNumExpansions();
13626 std::optional<unsigned> NumExpansions = OrigNumExpansions;
13627 if (getDerived().TryExpandParameterPacks(
13628 ExpansionTL.getEllipsisLoc(),
13629 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
13630 RetainExpansion, NumExpansions))
13631 return ExprError();
13632 if (Expand) {
13633 for (unsigned I = 0; I != *NumExpansions; ++I) {
13634 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
13635 SubstInitCapture(SourceLocation(), std::nullopt);
13636 }
13637 }
13638 if (!Expand || RetainExpansion) {
13639 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
13640 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
13641 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
13642 }
13643 } else {
13644 SubstInitCapture(SourceLocation(), std::nullopt);
13645 }
13646 }
13647
13648 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
13649 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
13650
13651 // Create the local class that will describe the lambda.
13652
13653 // FIXME: DependencyKind below is wrong when substituting inside a templated
13654 // context that isn't a DeclContext (such as a variable template), or when
13655 // substituting an unevaluated lambda inside of a function's parameter's type
13656 // - as parameter types are not instantiated from within a function's DC. We
13657 // use evaluation contexts to distinguish the function parameter case.
13660 DeclContext *DC = getSema().CurContext;
13661 // A RequiresExprBodyDecl is not interesting for dependencies.
13662 // For the following case,
13663 //
13664 // template <typename>
13665 // concept C = requires { [] {}; };
13666 //
13667 // template <class F>
13668 // struct Widget;
13669 //
13670 // template <C F>
13671 // struct Widget<F> {};
13672 //
13673 // While we are substituting Widget<F>, the parent of DC would be
13674 // the template specialization itself. Thus, the lambda expression
13675 // will be deemed as dependent even if there are no dependent template
13676 // arguments.
13677 // (A ClassTemplateSpecializationDecl is always a dependent context.)
13678 while (DC->getDeclKind() == Decl::Kind::RequiresExprBody)
13679 DC = DC->getParent();
13680 if ((getSema().isUnevaluatedContext() ||
13681 getSema().isConstantEvaluatedContext()) &&
13682 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
13683 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
13684
13685 CXXRecordDecl *OldClass = E->getLambdaClass();
13686 CXXRecordDecl *Class = getSema().createLambdaClosureType(
13687 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
13688 E->getCaptureDefault());
13689 getDerived().transformedLocalDecl(OldClass, {Class});
13690
13691 CXXMethodDecl *NewCallOperator =
13692 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
13693 NewCallOperator->setLexicalDeclContext(getSema().CurContext);
13694
13695 // Enter the scope of the lambda.
13696 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
13697 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
13698 E->hasExplicitParameters(), E->isMutable());
13699
13700 // Introduce the context of the call operator.
13701 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
13702 /*NewThisContext*/false);
13703
13704 bool Invalid = false;
13705
13706 // Transform captures.
13707 for (LambdaExpr::capture_iterator C = E->capture_begin(),
13708 CEnd = E->capture_end();
13709 C != CEnd; ++C) {
13710 // When we hit the first implicit capture, tell Sema that we've finished
13711 // the list of explicit captures.
13712 if (C->isImplicit())
13713 break;
13714
13715 // Capturing 'this' is trivial.
13716 if (C->capturesThis()) {
13717 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
13718 /*BuildAndDiagnose*/ true, nullptr,
13719 C->getCaptureKind() == LCK_StarThis);
13720 continue;
13721 }
13722 // Captured expression will be recaptured during captured variables
13723 // rebuilding.
13724 if (C->capturesVLAType())
13725 continue;
13726
13727 // Rebuild init-captures, including the implied field declaration.
13728 if (E->isInitCapture(C)) {
13729 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
13730
13731 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
13733
13734 for (InitCaptureInfoTy &Info : NewC.Expansions) {
13735 ExprResult Init = Info.first;
13736 QualType InitQualType = Info.second;
13737 if (Init.isInvalid() || InitQualType.isNull()) {
13738 Invalid = true;
13739 break;
13740 }
13741 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
13742 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
13743 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
13744 getSema().CurContext);
13745 if (!NewVD) {
13746 Invalid = true;
13747 break;
13748 }
13749 NewVDs.push_back(NewVD);
13750 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
13751 }
13752
13753 if (Invalid)
13754 break;
13755
13756 getDerived().transformedLocalDecl(OldVD, NewVDs);
13757 continue;
13758 }
13759
13760 assert(C->capturesVariable() && "unexpected kind of lambda capture");
13761
13762 // Determine the capture kind for Sema.
13764 = C->isImplicit()? Sema::TryCapture_Implicit
13765 : C->getCaptureKind() == LCK_ByCopy
13768 SourceLocation EllipsisLoc;
13769 if (C->isPackExpansion()) {
13770 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
13771 bool ShouldExpand = false;
13772 bool RetainExpansion = false;
13773 std::optional<unsigned> NumExpansions;
13774 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
13775 C->getLocation(),
13776 Unexpanded,
13777 ShouldExpand, RetainExpansion,
13778 NumExpansions)) {
13779 Invalid = true;
13780 continue;
13781 }
13782
13783 if (ShouldExpand) {
13784 // The transform has determined that we should perform an expansion;
13785 // transform and capture each of the arguments.
13786 // expansion of the pattern. Do so.
13787 auto *Pack = cast<VarDecl>(C->getCapturedVar());
13788 for (unsigned I = 0; I != *NumExpansions; ++I) {
13789 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
13790 VarDecl *CapturedVar
13791 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
13792 Pack));
13793 if (!CapturedVar) {
13794 Invalid = true;
13795 continue;
13796 }
13797
13798 // Capture the transformed variable.
13799 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
13800 }
13801
13802 // FIXME: Retain a pack expansion if RetainExpansion is true.
13803
13804 continue;
13805 }
13806
13807 EllipsisLoc = C->getEllipsisLoc();
13808 }
13809
13810 // Transform the captured variable.
13811 auto *CapturedVar = cast_or_null<ValueDecl>(
13812 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
13813 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
13814 Invalid = true;
13815 continue;
13816 }
13817
13818 // Capture the transformed variable.
13819 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
13820 EllipsisLoc);
13821 }
13822 getSema().finishLambdaExplicitCaptures(LSI);
13823
13824 // Transform the template parameters, and add them to the current
13825 // instantiation scope. The null case is handled correctly.
13826 auto TPL = getDerived().TransformTemplateParameterList(
13827 E->getTemplateParameterList());
13828 LSI->GLTemplateParameterList = TPL;
13829 if (TPL)
13830 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
13831 TPL);
13832
13833 // Transform the type of the original lambda's call operator.
13834 // The transformation MUST be done in the CurrentInstantiationScope since
13835 // it introduces a mapping of the original to the newly created
13836 // transformed parameters.
13837 TypeSourceInfo *NewCallOpTSI = nullptr;
13838 {
13839 auto OldCallOpTypeLoc =
13840 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
13841
13842 auto TransformFunctionProtoTypeLoc =
13843 [this](TypeLocBuilder &TLB, FunctionProtoTypeLoc FPTL) -> QualType {
13844 SmallVector<QualType, 4> ExceptionStorage;
13845 return this->TransformFunctionProtoType(
13846 TLB, FPTL, nullptr, Qualifiers(),
13847 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
13848 return TransformExceptionSpec(FPTL.getBeginLoc(), ESI,
13849 ExceptionStorage, Changed);
13850 });
13851 };
13852
13853 QualType NewCallOpType;
13854 TypeLocBuilder NewCallOpTLBuilder;
13855
13856 if (auto ATL = OldCallOpTypeLoc.getAs<AttributedTypeLoc>()) {
13857 NewCallOpType = this->TransformAttributedType(
13858 NewCallOpTLBuilder, ATL,
13859 [&](TypeLocBuilder &TLB, TypeLoc TL) -> QualType {
13860 return TransformFunctionProtoTypeLoc(
13861 TLB, TL.castAs<FunctionProtoTypeLoc>());
13862 });
13863 } else {
13864 auto FPTL = OldCallOpTypeLoc.castAs<FunctionProtoTypeLoc>();
13865 NewCallOpType = TransformFunctionProtoTypeLoc(NewCallOpTLBuilder, FPTL);
13866 }
13867
13868 if (NewCallOpType.isNull())
13869 return ExprError();
13870 NewCallOpTSI =
13871 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
13872 }
13873
13875 if (auto ATL = NewCallOpTSI->getTypeLoc().getAs<AttributedTypeLoc>()) {
13876 Params = ATL.getModifiedLoc().castAs<FunctionProtoTypeLoc>().getParams();
13877 } else {
13878 auto FPTL = NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>();
13879 Params = FPTL.getParams();
13880 }
13881
13882 getSema().CompleteLambdaCallOperator(
13883 NewCallOperator, E->getCallOperator()->getLocation(),
13884 E->getCallOperator()->getInnerLocStart(),
13885 E->getCallOperator()->getTrailingRequiresClause(), NewCallOpTSI,
13886 E->getCallOperator()->getConstexprKind(),
13887 E->getCallOperator()->getStorageClass(), Params,
13888 E->hasExplicitResultType());
13889
13890 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
13891 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
13892
13893 {
13894 // Number the lambda for linkage purposes if necessary.
13895 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
13896
13897 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
13898 if (getDerived().ReplacingOriginal()) {
13899 Numbering = OldClass->getLambdaNumbering();
13900 }
13901
13902 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
13903 }
13904
13905 // FIXME: Sema's lambda-building mechanism expects us to push an expression
13906 // evaluation context even if we're not transforming the function body.
13907 getSema().PushExpressionEvaluationContext(
13909
13910 Sema::CodeSynthesisContext C;
13912 C.PointOfInstantiation = E->getBody()->getBeginLoc();
13913 getSema().pushCodeSynthesisContext(C);
13914
13915 // Instantiate the body of the lambda expression.
13916 StmtResult Body =
13917 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
13918
13919 getSema().popCodeSynthesisContext();
13920
13921 // ActOnLambda* will pop the function scope for us.
13922 FuncScopeCleanup.disable();
13923
13924 if (Body.isInvalid()) {
13925 SavedContext.pop();
13926 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
13927 /*IsInstantiation=*/true);
13928 return ExprError();
13929 }
13930
13931 // Copy the LSI before ActOnFinishFunctionBody removes it.
13932 // FIXME: This is dumb. Store the lambda information somewhere that outlives
13933 // the call operator.
13934 auto LSICopy = *LSI;
13935 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
13936 /*IsInstantiation*/ true);
13937 SavedContext.pop();
13938
13939 return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(),
13940 &LSICopy);
13941}
13942
13943template<typename Derived>
13946 return TransformStmt(S);
13947}
13948
13949template<typename Derived>
13952 // Transform captures.
13954 CEnd = E->capture_end();
13955 C != CEnd; ++C) {
13956 // When we hit the first implicit capture, tell Sema that we've finished
13957 // the list of explicit captures.
13958 if (!C->isImplicit())
13959 continue;
13960
13961 // Capturing 'this' is trivial.
13962 if (C->capturesThis()) {
13963 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
13964 /*BuildAndDiagnose*/ true, nullptr,
13965 C->getCaptureKind() == LCK_StarThis);
13966 continue;
13967 }
13968 // Captured expression will be recaptured during captured variables
13969 // rebuilding.
13970 if (C->capturesVLAType())
13971 continue;
13972
13973 assert(C->capturesVariable() && "unexpected kind of lambda capture");
13974 assert(!E->isInitCapture(C) && "implicit init-capture?");
13975
13976 // Transform the captured variable.
13977 VarDecl *CapturedVar = cast_or_null<VarDecl>(
13978 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
13979 if (!CapturedVar || CapturedVar->isInvalidDecl())
13980 return StmtError();
13981
13982 // Capture the transformed variable.
13983 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
13984 }
13985
13986 return S;
13987}
13988
13989template<typename Derived>
13993 TypeSourceInfo *T =
13994 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
13995 if (!T)
13996 return ExprError();
13997
13998 bool ArgumentChanged = false;
14000 Args.reserve(E->getNumArgs());
14001 {
14005 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
14006 &ArgumentChanged))
14007 return ExprError();
14008 }
14009
14010 if (!getDerived().AlwaysRebuild() &&
14011 T == E->getTypeSourceInfo() &&
14012 !ArgumentChanged)
14013 return E;
14014
14015 // FIXME: we're faking the locations of the commas
14016 return getDerived().RebuildCXXUnresolvedConstructExpr(
14017 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
14018}
14019
14020template<typename Derived>
14022TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
14023 CXXDependentScopeMemberExpr *E) {
14024 // Transform the base of the expression.
14025 ExprResult Base((Expr*) nullptr);
14026 Expr *OldBase;
14027 QualType BaseType;
14028 QualType ObjectType;
14029 if (!E->isImplicitAccess()) {
14030 OldBase = E->getBase();
14031 Base = getDerived().TransformExpr(OldBase);
14032 if (Base.isInvalid())
14033 return ExprError();
14034
14035 // Start the member reference and compute the object's type.
14036 ParsedType ObjectTy;
14037 bool MayBePseudoDestructor = false;
14038 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14039 E->getOperatorLoc(),
14040 E->isArrow()? tok::arrow : tok::period,
14041 ObjectTy,
14042 MayBePseudoDestructor);
14043 if (Base.isInvalid())
14044 return ExprError();
14045
14046 ObjectType = ObjectTy.get();
14047 BaseType = ((Expr*) Base.get())->getType();
14048 } else {
14049 OldBase = nullptr;
14050 BaseType = getDerived().TransformType(E->getBaseType());
14051 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
14052 }
14053
14054 // Transform the first part of the nested-name-specifier that qualifies
14055 // the member name.
14056 NamedDecl *FirstQualifierInScope
14057 = getDerived().TransformFirstQualifierInScope(
14058 E->getFirstQualifierFoundInScope(),
14059 E->getQualifierLoc().getBeginLoc());
14060
14061 NestedNameSpecifierLoc QualifierLoc;
14062 if (E->getQualifier()) {
14063 QualifierLoc
14064 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
14065 ObjectType,
14066 FirstQualifierInScope);
14067 if (!QualifierLoc)
14068 return ExprError();
14069 }
14070
14071 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14072
14073 // TODO: If this is a conversion-function-id, verify that the
14074 // destination type name (if present) resolves the same way after
14075 // instantiation as it did in the local scope.
14076
14077 DeclarationNameInfo NameInfo
14078 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
14079 if (!NameInfo.getName())
14080 return ExprError();
14081
14082 if (!E->hasExplicitTemplateArgs()) {
14083 // This is a reference to a member without an explicitly-specified
14084 // template argument list. Optimize for this common case.
14085 if (!getDerived().AlwaysRebuild() &&
14086 Base.get() == OldBase &&
14087 BaseType == E->getBaseType() &&
14088 QualifierLoc == E->getQualifierLoc() &&
14089 NameInfo.getName() == E->getMember() &&
14090 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
14091 return E;
14092
14093 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
14094 BaseType,
14095 E->isArrow(),
14096 E->getOperatorLoc(),
14097 QualifierLoc,
14098 TemplateKWLoc,
14099 FirstQualifierInScope,
14100 NameInfo,
14101 /*TemplateArgs*/nullptr);
14102 }
14103
14104 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
14105 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
14106 E->getNumTemplateArgs(),
14107 TransArgs))
14108 return ExprError();
14109
14110 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
14111 BaseType,
14112 E->isArrow(),
14113 E->getOperatorLoc(),
14114 QualifierLoc,
14115 TemplateKWLoc,
14116 FirstQualifierInScope,
14117 NameInfo,
14118 &TransArgs);
14119}
14120
14121template <typename Derived>
14122ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
14123 UnresolvedMemberExpr *Old) {
14124 // Transform the base of the expression.
14125 ExprResult Base((Expr *)nullptr);
14126 QualType BaseType;
14127 if (!Old->isImplicitAccess()) {
14128 Base = getDerived().TransformExpr(Old->getBase());
14129 if (Base.isInvalid())
14130 return ExprError();
14131 Base =
14132 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
14133 if (Base.isInvalid())
14134 return ExprError();
14135 BaseType = Base.get()->getType();
14136 } else {
14137 BaseType = getDerived().TransformType(Old->getBaseType());
14138 }
14139
14140 NestedNameSpecifierLoc QualifierLoc;
14141 if (Old->getQualifierLoc()) {
14142 QualifierLoc =
14143 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14144 if (!QualifierLoc)
14145 return ExprError();
14146 }
14147
14148 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14149
14150 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
14151
14152 // Transform the declaration set.
14153 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
14154 return ExprError();
14155
14156 // Determine the naming class.
14157 if (Old->getNamingClass()) {
14158 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
14159 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
14160 if (!NamingClass)
14161 return ExprError();
14162
14163 R.setNamingClass(NamingClass);
14164 }
14165
14166 TemplateArgumentListInfo TransArgs;
14167 if (Old->hasExplicitTemplateArgs()) {
14168 TransArgs.setLAngleLoc(Old->getLAngleLoc());
14169 TransArgs.setRAngleLoc(Old->getRAngleLoc());
14170 if (getDerived().TransformTemplateArguments(
14171 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
14172 return ExprError();
14173 }
14174
14175 // FIXME: to do this check properly, we will need to preserve the
14176 // first-qualifier-in-scope here, just in case we had a dependent
14177 // base (and therefore couldn't do the check) and a
14178 // nested-name-qualifier (and therefore could do the lookup).
14179 NamedDecl *FirstQualifierInScope = nullptr;
14180
14181 return getDerived().RebuildUnresolvedMemberExpr(
14182 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
14183 TemplateKWLoc, FirstQualifierInScope, R,
14184 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
14185}
14186
14187template<typename Derived>
14189TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
14190 EnterExpressionEvaluationContext Unevaluated(
14192 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
14193 if (SubExpr.isInvalid())
14194 return ExprError();
14195
14196 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
14197 return E;
14198
14199 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
14200}
14201
14202template<typename Derived>
14204TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
14205 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
14206 if (Pattern.isInvalid())
14207 return ExprError();
14208
14209 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
14210 return E;
14211
14212 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
14213 E->getNumExpansions());
14214}
14215
14216template<typename Derived>
14218TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
14219 // If E is not value-dependent, then nothing will change when we transform it.
14220 // Note: This is an instantiation-centric view.
14221 if (!E->isValueDependent())
14222 return E;
14223
14224 EnterExpressionEvaluationContext Unevaluated(
14226
14228 TemplateArgument ArgStorage;
14229
14230 // Find the argument list to transform.
14231 if (E->isPartiallySubstituted()) {
14232 PackArgs = E->getPartialArguments();
14233 } else if (E->isValueDependent()) {
14234 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
14235 bool ShouldExpand = false;
14236 bool RetainExpansion = false;
14237 std::optional<unsigned> NumExpansions;
14238 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
14239 Unexpanded,
14240 ShouldExpand, RetainExpansion,
14241 NumExpansions))
14242 return ExprError();
14243
14244 // If we need to expand the pack, build a template argument from it and
14245 // expand that.
14246 if (ShouldExpand) {
14247 auto *Pack = E->getPack();
14248 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
14249 ArgStorage = getSema().Context.getPackExpansionType(
14250 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
14251 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
14252 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
14253 } else {
14254 auto *VD = cast<ValueDecl>(Pack);
14255 ExprResult DRE = getSema().BuildDeclRefExpr(
14256 VD, VD->getType().getNonLValueExprType(getSema().Context),
14257 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
14258 E->getPackLoc());
14259 if (DRE.isInvalid())
14260 return ExprError();
14261 ArgStorage = new (getSema().Context)
14262 PackExpansionExpr(getSema().Context.DependentTy, DRE.get(),
14263 E->getPackLoc(), std::nullopt);
14264 }
14265 PackArgs = ArgStorage;
14266 }
14267 }
14268
14269 // If we're not expanding the pack, just transform the decl.
14270 if (!PackArgs.size()) {
14271 auto *Pack = cast_or_null<NamedDecl>(
14272 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
14273 if (!Pack)
14274 return ExprError();
14275 return getDerived().RebuildSizeOfPackExpr(
14276 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
14277 std::nullopt, std::nullopt);
14278 }
14279
14280 // Try to compute the result without performing a partial substitution.
14281 std::optional<unsigned> Result = 0;
14282 for (const TemplateArgument &Arg : PackArgs) {
14283 if (!Arg.isPackExpansion()) {
14284 Result = *Result + 1;
14285 continue;
14286 }
14287
14288 TemplateArgumentLoc ArgLoc;
14289 InventTemplateArgumentLoc(Arg, ArgLoc);
14290
14291 // Find the pattern of the pack expansion.
14292 SourceLocation Ellipsis;
14293 std::optional<unsigned> OrigNumExpansions;
14294 TemplateArgumentLoc Pattern =
14295 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
14296 OrigNumExpansions);
14297
14298 // Substitute under the pack expansion. Do not expand the pack (yet).
14299 TemplateArgumentLoc OutPattern;
14300 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
14301 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
14302 /*Uneval*/ true))
14303 return true;
14304
14305 // See if we can determine the number of arguments from the result.
14306 std::optional<unsigned> NumExpansions =
14307 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
14308 if (!NumExpansions) {
14309 // No: we must be in an alias template expansion, and we're going to need
14310 // to actually expand the packs.
14311 Result = std::nullopt;
14312 break;
14313 }
14314
14315 Result = *Result + *NumExpansions;
14316 }
14317
14318 // Common case: we could determine the number of expansions without
14319 // substituting.
14320 if (Result)
14321 return getDerived().RebuildSizeOfPackExpr(
14322 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
14323 *Result, std::nullopt);
14324
14325 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
14326 E->getPackLoc());
14327 {
14328 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
14329 typedef TemplateArgumentLocInventIterator<
14330 Derived, const TemplateArgument*> PackLocIterator;
14331 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
14332 PackLocIterator(*this, PackArgs.end()),
14333 TransformedPackArgs, /*Uneval*/true))
14334 return ExprError();
14335 }
14336
14337 // Check whether we managed to fully-expand the pack.
14338 // FIXME: Is it possible for us to do so and not hit the early exit path?
14340 bool PartialSubstitution = false;
14341 for (auto &Loc : TransformedPackArgs.arguments()) {
14342 Args.push_back(Loc.getArgument());
14343 if (Loc.getArgument().isPackExpansion())
14344 PartialSubstitution = true;
14345 }
14346
14347 if (PartialSubstitution)
14348 return getDerived().RebuildSizeOfPackExpr(
14349 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
14350 std::nullopt, Args);
14351
14352 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
14353 E->getPackLoc(), E->getRParenLoc(),
14354 Args.size(), std::nullopt);
14355}
14356
14357template <typename Derived>
14359TreeTransform<Derived>::TransformPackIndexingExpr(PackIndexingExpr *E) {
14360 if (!E->isValueDependent())
14361 return E;
14362
14363 // Transform the index
14364 ExprResult IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
14365 if (IndexExpr.isInvalid())
14366 return ExprError();
14367
14368 SmallVector<Expr *, 5> ExpandedExprs;
14369 if (E->getExpressions().empty()) {
14370 Expr *Pattern = E->getPackIdExpression();
14372 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
14373 Unexpanded);
14374 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
14375
14376 // Determine whether the set of unexpanded parameter packs can and should
14377 // be expanded.
14378 bool ShouldExpand = true;
14379 bool RetainExpansion = false;
14380 std::optional<unsigned> OrigNumExpansions;
14381 std::optional<unsigned> NumExpansions = OrigNumExpansions;
14382 if (getDerived().TryExpandParameterPacks(
14383 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
14384 ShouldExpand, RetainExpansion, NumExpansions))
14385 return true;
14386 if (!ShouldExpand) {
14387 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
14388 ExprResult Pack = getDerived().TransformExpr(Pattern);
14389 if (Pack.isInvalid())
14390 return ExprError();
14391 return getDerived().RebuildPackIndexingExpr(
14392 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
14393 std::nullopt);
14394 }
14395 for (unsigned I = 0; I != *NumExpansions; ++I) {
14396 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
14397 ExprResult Out = getDerived().TransformExpr(Pattern);
14398 if (Out.isInvalid())
14399 return true;
14400 if (Out.get()->containsUnexpandedParameterPack()) {
14401 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
14402 OrigNumExpansions);
14403 if (Out.isInvalid())
14404 return true;
14405 }
14406 ExpandedExprs.push_back(Out.get());
14407 }
14408 // If we're supposed to retain a pack expansion, do so by temporarily
14409 // forgetting the partially-substituted parameter pack.
14410 if (RetainExpansion) {
14411 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14412
14413 ExprResult Out = getDerived().TransformExpr(Pattern);
14414 if (Out.isInvalid())
14415 return true;
14416
14417 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
14418 OrigNumExpansions);
14419 if (Out.isInvalid())
14420 return true;
14421 ExpandedExprs.push_back(Out.get());
14422 }
14423 }
14424
14425 else {
14426 if (getDerived().TransformExprs(E->getExpressions().data(),
14427 E->getExpressions().size(), false,
14428 ExpandedExprs))
14429 return ExprError();
14430 }
14431
14432 return getDerived().RebuildPackIndexingExpr(
14433 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
14434 IndexExpr.get(), ExpandedExprs,
14435 /*EmptyPack=*/ExpandedExprs.size() == 0);
14436}
14437
14438template<typename Derived>
14440TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
14441 SubstNonTypeTemplateParmPackExpr *E) {
14442 // Default behavior is to do nothing with this transformation.
14443 return E;
14444}
14445
14446template<typename Derived>
14448TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
14449 SubstNonTypeTemplateParmExpr *E) {
14450 // Default behavior is to do nothing with this transformation.
14451 return E;
14452}
14453
14454template<typename Derived>
14456TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
14457 // Default behavior is to do nothing with this transformation.
14458 return E;
14459}
14460
14461template<typename Derived>
14463TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
14464 MaterializeTemporaryExpr *E) {
14465 return getDerived().TransformExpr(E->getSubExpr());
14466}
14467
14468template<typename Derived>
14470TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
14471 UnresolvedLookupExpr *Callee = nullptr;
14472 if (Expr *OldCallee = E->getCallee()) {
14473 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
14474 if (CalleeResult.isInvalid())
14475 return ExprError();
14476 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
14477 }
14478
14479 Expr *Pattern = E->getPattern();
14480
14482 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
14483 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
14484
14485 // Determine whether the set of unexpanded parameter packs can and should
14486 // be expanded.
14487 bool Expand = true;
14488 bool RetainExpansion = false;
14489 std::optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
14490 NumExpansions = OrigNumExpansions;
14491 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
14492 Pattern->getSourceRange(),
14493 Unexpanded,
14494 Expand, RetainExpansion,
14495 NumExpansions))
14496 return true;
14497
14498 if (!Expand) {
14499 // Do not expand any packs here, just transform and rebuild a fold
14500 // expression.
14501 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
14502
14503 ExprResult LHS =
14504 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
14505 if (LHS.isInvalid())
14506 return true;
14507
14508 ExprResult RHS =
14509 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
14510 if (RHS.isInvalid())
14511 return true;
14512
14513 if (!getDerived().AlwaysRebuild() &&
14514 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
14515 return E;
14516
14517 return getDerived().RebuildCXXFoldExpr(
14518 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
14519 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
14520 }
14521
14522 // Formally a fold expression expands to nested parenthesized expressions.
14523 // Enforce this limit to avoid creating trees so deep we can't safely traverse
14524 // them.
14525 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) {
14526 SemaRef.Diag(E->getEllipsisLoc(),
14527 clang::diag::err_fold_expression_limit_exceeded)
14528 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
14529 << E->getSourceRange();
14530 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
14531 return ExprError();
14532 }
14533
14534 // The transform has determined that we should perform an elementwise
14535 // expansion of the pattern. Do so.
14536 ExprResult Result = getDerived().TransformExpr(E->getInit());
14537 if (Result.isInvalid())
14538 return true;
14539 bool LeftFold = E->isLeftFold();
14540
14541 // If we're retaining an expansion for a right fold, it is the innermost
14542 // component and takes the init (if any).
14543 if (!LeftFold && RetainExpansion) {
14544 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14545
14546 ExprResult Out = getDerived().TransformExpr(Pattern);
14547 if (Out.isInvalid())
14548 return true;
14549
14550 Result = getDerived().RebuildCXXFoldExpr(
14551 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
14552 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
14553 if (Result.isInvalid())
14554 return true;
14555 }
14556
14557 for (unsigned I = 0; I != *NumExpansions; ++I) {
14558 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
14559 getSema(), LeftFold ? I : *NumExpansions - I - 1);
14560 ExprResult Out = getDerived().TransformExpr(Pattern);
14561 if (Out.isInvalid())
14562 return true;
14563
14564 if (Out.get()->containsUnexpandedParameterPack()) {
14565 // We still have a pack; retain a pack expansion for this slice.
14566 Result = getDerived().RebuildCXXFoldExpr(
14567 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
14568 E->getOperator(), E->getEllipsisLoc(),
14569 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
14570 OrigNumExpansions);
14571 } else if (Result.isUsable()) {
14572 // We've got down to a single element; build a binary operator.
14573 Expr *LHS = LeftFold ? Result.get() : Out.get();
14574 Expr *RHS = LeftFold ? Out.get() : Result.get();
14575 if (Callee) {
14576 UnresolvedSet<16> Functions;
14577 Functions.append(Callee->decls_begin(), Callee->decls_end());
14578 Result = getDerived().RebuildCXXOperatorCallExpr(
14579 BinaryOperator::getOverloadedOperator(E->getOperator()),
14580 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
14581 Functions, LHS, RHS);
14582 } else {
14583 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
14584 E->getOperator(), LHS, RHS);
14585 }
14586 } else
14587 Result = Out;
14588
14589 if (Result.isInvalid())
14590 return true;
14591 }
14592
14593 // If we're retaining an expansion for a left fold, it is the outermost
14594 // component and takes the complete expansion so far as its init (if any).
14595 if (LeftFold && RetainExpansion) {
14596 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14597
14598 ExprResult Out = getDerived().TransformExpr(Pattern);
14599 if (Out.isInvalid())
14600 return true;
14601
14602 Result = getDerived().RebuildCXXFoldExpr(
14603 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
14604 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
14605 if (Result.isInvalid())
14606 return true;
14607 }
14608
14609 // If we had no init and an empty pack, and we're not retaining an expansion,
14610 // then produce a fallback value or error.
14611 if (Result.isUnset())
14612 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
14613 E->getOperator());
14614
14615 return Result;
14616}
14617
14618template <typename Derived>
14620TreeTransform<Derived>::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) {
14621 SmallVector<Expr *, 4> TransformedInits;
14622 ArrayRef<Expr *> InitExprs = E->getInitExprs();
14623 if (TransformExprs(InitExprs.data(), InitExprs.size(), true,
14624 TransformedInits))
14625 return ExprError();
14626
14627 return getDerived().RebuildParenListExpr(E->getBeginLoc(), TransformedInits,
14628 E->getEndLoc());
14629}
14630
14631template<typename Derived>
14633TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
14634 CXXStdInitializerListExpr *E) {
14635 return getDerived().TransformExpr(E->getSubExpr());
14636}
14637
14638template<typename Derived>
14640TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
14641 return SemaRef.MaybeBindToTemporary(E);
14642}
14643
14644template<typename Derived>
14646TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
14647 return E;
14648}
14649
14650template<typename Derived>
14652TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
14653 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14654 if (SubExpr.isInvalid())
14655 return ExprError();
14656
14657 if (!getDerived().AlwaysRebuild() &&
14658 SubExpr.get() == E->getSubExpr())
14659 return E;
14660
14661 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
14662}
14663
14664template<typename Derived>
14666TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
14667 // Transform each of the elements.
14668 SmallVector<Expr *, 8> Elements;
14669 bool ArgChanged = false;
14670 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
14671 /*IsCall=*/false, Elements, &ArgChanged))
14672 return ExprError();
14673
14674 if (!getDerived().AlwaysRebuild() && !ArgChanged)
14675 return SemaRef.MaybeBindToTemporary(E);
14676
14677 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
14678 Elements.data(),
14679 Elements.size());
14680}
14681
14682template<typename Derived>
14684TreeTransform<Derived>::TransformObjCDictionaryLiteral(
14685 ObjCDictionaryLiteral *E) {
14686 // Transform each of the elements.
14688 bool ArgChanged = false;
14689 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
14690 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
14691
14692 if (OrigElement.isPackExpansion()) {
14693 // This key/value element is a pack expansion.
14695 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
14696 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
14697 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
14698
14699 // Determine whether the set of unexpanded parameter packs can
14700 // and should be expanded.
14701 bool Expand = true;
14702 bool RetainExpansion = false;
14703 std::optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
14704 std::optional<unsigned> NumExpansions = OrigNumExpansions;
14705 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
14706 OrigElement.Value->getEndLoc());
14707 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
14708 PatternRange, Unexpanded, Expand,
14709 RetainExpansion, NumExpansions))
14710 return ExprError();
14711
14712 if (!Expand) {
14713 // The transform has determined that we should perform a simple
14714 // transformation on the pack expansion, producing another pack
14715 // expansion.
14716 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
14717 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
14718 if (Key.isInvalid())
14719 return ExprError();
14720
14721 if (Key.get() != OrigElement.Key)
14722 ArgChanged = true;
14723
14724 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
14725 if (Value.isInvalid())
14726 return ExprError();
14727
14728 if (Value.get() != OrigElement.Value)
14729 ArgChanged = true;
14730
14731 ObjCDictionaryElement Expansion = {
14732 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
14733 };
14734 Elements.push_back(Expansion);
14735 continue;
14736 }
14737
14738 // Record right away that the argument was changed. This needs
14739 // to happen even if the array expands to nothing.
14740 ArgChanged = true;
14741
14742 // The transform has determined that we should perform an elementwise
14743 // expansion of the pattern. Do so.
14744 for (unsigned I = 0; I != *NumExpansions; ++I) {
14745 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
14746 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
14747 if (Key.isInvalid())
14748 return ExprError();
14749
14750 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
14751 if (Value.isInvalid())
14752 return ExprError();
14753
14754 ObjCDictionaryElement Element = {
14755 Key.get(), Value.get(), SourceLocation(), NumExpansions
14756 };
14757
14758 // If any unexpanded parameter packs remain, we still have a
14759 // pack expansion.
14760 // FIXME: Can this really happen?
14761 if (Key.get()->containsUnexpandedParameterPack() ||
14762 Value.get()->containsUnexpandedParameterPack())
14763 Element.EllipsisLoc = OrigElement.EllipsisLoc;
14764
14765 Elements.push_back(Element);
14766 }
14767
14768 // FIXME: Retain a pack expansion if RetainExpansion is true.
14769
14770 // We've finished with this pack expansion.
14771 continue;
14772 }
14773
14774 // Transform and check key.
14775 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
14776 if (Key.isInvalid())
14777 return ExprError();
14778
14779 if (Key.get() != OrigElement.Key)
14780 ArgChanged = true;
14781
14782 // Transform and check value.
14784 = getDerived().TransformExpr(OrigElement.Value);
14785 if (Value.isInvalid())
14786 return ExprError();
14787
14788 if (Value.get() != OrigElement.Value)
14789 ArgChanged = true;
14790
14791 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
14792 std::nullopt};
14793 Elements.push_back(Element);
14794 }
14795
14796 if (!getDerived().AlwaysRebuild() && !ArgChanged)
14797 return SemaRef.MaybeBindToTemporary(E);
14798
14799 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
14800 Elements);
14801}
14802
14803template<typename Derived>
14805TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
14806 TypeSourceInfo *EncodedTypeInfo
14807 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
14808 if (!EncodedTypeInfo)
14809 return ExprError();
14810
14811 if (!getDerived().AlwaysRebuild() &&
14812 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
14813 return E;
14814
14815 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
14816 EncodedTypeInfo,
14817 E->getRParenLoc());
14818}
14819
14820template<typename Derived>
14821ExprResult TreeTransform<Derived>::
14822TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
14823 // This is a kind of implicit conversion, and it needs to get dropped
14824 // and recomputed for the same general reasons that ImplicitCastExprs
14825 // do, as well a more specific one: this expression is only valid when
14826 // it appears *immediately* as an argument expression.
14827 return getDerived().TransformExpr(E->getSubExpr());
14828}
14829
14830template<typename Derived>
14831ExprResult TreeTransform<Derived>::
14832TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
14833 TypeSourceInfo *TSInfo
14834 = getDerived().TransformType(E->getTypeInfoAsWritten());
14835 if (!TSInfo)
14836 return ExprError();
14837
14838 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
14839 if (Result.isInvalid())
14840 return ExprError();
14841
14842 if (!getDerived().AlwaysRebuild() &&
14843 TSInfo == E->getTypeInfoAsWritten() &&
14844 Result.get() == E->getSubExpr())
14845 return E;
14846
14847 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
14848 E->getBridgeKeywordLoc(), TSInfo,
14849 Result.get());
14850}
14851
14852template <typename Derived>
14853ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
14854 ObjCAvailabilityCheckExpr *E) {
14855 return E;
14856}
14857
14858template<typename Derived>
14860TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
14861 // Transform arguments.
14862 bool ArgChanged = false;
14864 Args.reserve(E->getNumArgs());
14865 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
14866 &ArgChanged))
14867 return ExprError();
14868
14869 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
14870 // Class message: transform the receiver type.
14871 TypeSourceInfo *ReceiverTypeInfo
14872 = getDerived().TransformType(E->getClassReceiverTypeInfo());
14873 if (!ReceiverTypeInfo)
14874 return ExprError();
14875
14876 // If nothing changed, just retain the existing message send.
14877 if (!getDerived().AlwaysRebuild() &&
14878 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
14879 return SemaRef.MaybeBindToTemporary(E);
14880
14881 // Build a new class message send.
14883 E->getSelectorLocs(SelLocs);
14884 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
14885 E->getSelector(),
14886 SelLocs,
14887 E->getMethodDecl(),
14888 E->getLeftLoc(),
14889 Args,
14890 E->getRightLoc());
14891 }
14892 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
14893 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
14894 if (!E->getMethodDecl())
14895 return ExprError();
14896
14897 // Build a new class message send to 'super'.
14899 E->getSelectorLocs(SelLocs);
14900 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
14901 E->getSelector(),
14902 SelLocs,
14903 E->getReceiverType(),
14904 E->getMethodDecl(),
14905 E->getLeftLoc(),
14906 Args,
14907 E->getRightLoc());
14908 }
14909
14910 // Instance message: transform the receiver
14911 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
14912 "Only class and instance messages may be instantiated");
14913 ExprResult Receiver
14914 = getDerived().TransformExpr(E->getInstanceReceiver());
14915 if (Receiver.isInvalid())
14916 return ExprError();
14917
14918 // If nothing changed, just retain the existing message send.
14919 if (!getDerived().AlwaysRebuild() &&
14920 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
14921 return SemaRef.MaybeBindToTemporary(E);
14922
14923 // Build a new instance message send.
14925 E->getSelectorLocs(SelLocs);
14926 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
14927 E->getSelector(),
14928 SelLocs,
14929 E->getMethodDecl(),
14930 E->getLeftLoc(),
14931 Args,
14932 E->getRightLoc());
14933}
14934
14935template<typename Derived>
14937TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
14938 return E;
14939}
14940
14941template<typename Derived>
14943TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
14944 return E;
14945}
14946
14947template<typename Derived>
14949TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
14950 // Transform the base expression.
14951 ExprResult Base = getDerived().TransformExpr(E->getBase());
14952 if (Base.isInvalid())
14953 return ExprError();
14954
14955 // We don't need to transform the ivar; it will never change.
14956
14957 // If nothing changed, just retain the existing expression.
14958 if (!getDerived().AlwaysRebuild() &&
14959 Base.get() == E->getBase())
14960 return E;
14961
14962 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
14963 E->getLocation(),
14964 E->isArrow(), E->isFreeIvar());
14965}
14966
14967template<typename Derived>
14969TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
14970 // 'super' and types never change. Property never changes. Just
14971 // retain the existing expression.
14972 if (!E->isObjectReceiver())
14973 return E;
14974
14975 // Transform the base expression.
14976 ExprResult Base = getDerived().TransformExpr(E->getBase());
14977 if (Base.isInvalid())
14978 return ExprError();
14979
14980 // We don't need to transform the property; it will never change.
14981
14982 // If nothing changed, just retain the existing expression.
14983 if (!getDerived().AlwaysRebuild() &&
14984 Base.get() == E->getBase())
14985 return E;
14986
14987 if (E->isExplicitProperty())
14988 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
14989 E->getExplicitProperty(),
14990 E->getLocation());
14991
14992 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
14993 SemaRef.Context.PseudoObjectTy,
14994 E->getImplicitPropertyGetter(),
14995 E->getImplicitPropertySetter(),
14996 E->getLocation());
14997}
14998
14999template<typename Derived>
15001TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
15002 // Transform the base expression.
15003 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
15004 if (Base.isInvalid())
15005 return ExprError();
15006
15007 // Transform the key expression.
15008 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
15009 if (Key.isInvalid())
15010 return ExprError();
15011
15012 // If nothing changed, just retain the existing expression.
15013 if (!getDerived().AlwaysRebuild() &&
15014 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
15015 return E;
15016
15017 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
15018 Base.get(), Key.get(),
15019 E->getAtIndexMethodDecl(),
15020 E->setAtIndexMethodDecl());
15021}
15022
15023template<typename Derived>
15025TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
15026 // Transform the base expression.
15027 ExprResult Base = getDerived().TransformExpr(E->getBase());
15028 if (Base.isInvalid())
15029 return ExprError();
15030
15031 // If nothing changed, just retain the existing expression.
15032 if (!getDerived().AlwaysRebuild() &&
15033 Base.get() == E->getBase())
15034 return E;
15035
15036 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
15037 E->getOpLoc(),
15038 E->isArrow());
15039}
15040
15041template<typename Derived>
15043TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
15044 bool ArgumentChanged = false;
15045 SmallVector<Expr*, 8> SubExprs;
15046 SubExprs.reserve(E->getNumSubExprs());
15047 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
15048 SubExprs, &ArgumentChanged))
15049 return ExprError();
15050
15051 if (!getDerived().AlwaysRebuild() &&
15052 !ArgumentChanged)
15053 return E;
15054
15055 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
15056 SubExprs,
15057 E->getRParenLoc());
15058}
15059
15060template<typename Derived>
15062TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
15063 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
15064 if (SrcExpr.isInvalid())
15065 return ExprError();
15066
15067 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
15068 if (!Type)
15069 return ExprError();
15070
15071 if (!getDerived().AlwaysRebuild() &&
15072 Type == E->getTypeSourceInfo() &&
15073 SrcExpr.get() == E->getSrcExpr())
15074 return E;
15075
15076 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
15077 SrcExpr.get(), Type,
15078 E->getRParenLoc());
15079}
15080
15081template<typename Derived>
15083TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
15084 BlockDecl *oldBlock = E->getBlockDecl();
15085
15086 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
15087 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
15088
15089 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
15090 blockScope->TheDecl->setBlockMissingReturnType(
15091 oldBlock->blockMissingReturnType());
15092
15094 SmallVector<QualType, 4> paramTypes;
15095
15096 const FunctionProtoType *exprFunctionType = E->getFunctionType();
15097
15098 // Parameter substitution.
15099 Sema::ExtParameterInfoBuilder extParamInfos;
15100 if (getDerived().TransformFunctionTypeParams(
15101 E->getCaretLocation(), oldBlock->parameters(), nullptr,
15102 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
15103 extParamInfos)) {
15104 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
15105 return ExprError();
15106 }
15107
15108 QualType exprResultType =
15109 getDerived().TransformType(exprFunctionType->getReturnType());
15110
15111 auto epi = exprFunctionType->getExtProtoInfo();
15112 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
15113
15114 QualType functionType =
15115 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
15116 blockScope->FunctionType = functionType;
15117
15118 // Set the parameters on the block decl.
15119 if (!params.empty())
15120 blockScope->TheDecl->setParams(params);
15121
15122 if (!oldBlock->blockMissingReturnType()) {
15123 blockScope->HasImplicitReturnType = false;
15124 blockScope->ReturnType = exprResultType;
15125 }
15126
15127 // Transform the body
15128 StmtResult body = getDerived().TransformStmt(E->getBody());
15129 if (body.isInvalid()) {
15130 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
15131 return ExprError();
15132 }
15133
15134#ifndef NDEBUG
15135 // In builds with assertions, make sure that we captured everything we
15136 // captured before.
15137 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
15138 for (const auto &I : oldBlock->captures()) {
15139 VarDecl *oldCapture = I.getVariable();
15140
15141 // Ignore parameter packs.
15142 if (oldCapture->isParameterPack())
15143 continue;
15144
15145 VarDecl *newCapture =
15146 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
15147 oldCapture));
15148 assert(blockScope->CaptureMap.count(newCapture));
15149 }
15150
15151 // The this pointer may not be captured by the instantiated block, even when
15152 // it's captured by the original block, if the expression causing the
15153 // capture is in the discarded branch of a constexpr if statement.
15154 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
15155 "this pointer isn't captured in the old block");
15156 }
15157#endif
15158
15159 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
15160 /*Scope=*/nullptr);
15161}
15162
15163template<typename Derived>
15165TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
15166 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
15167 if (SrcExpr.isInvalid())
15168 return ExprError();
15169
15170 QualType Type = getDerived().TransformType(E->getType());
15171
15172 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
15173 E->getRParenLoc());
15174}
15175
15176template<typename Derived>
15178TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
15179 bool ArgumentChanged = false;
15180 SmallVector<Expr*, 8> SubExprs;
15181 SubExprs.reserve(E->getNumSubExprs());
15182 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
15183 SubExprs, &ArgumentChanged))
15184 return ExprError();
15185
15186 if (!getDerived().AlwaysRebuild() &&
15187 !ArgumentChanged)
15188 return E;
15189
15190 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
15191 E->getOp(), E->getRParenLoc());
15192}
15193
15194//===----------------------------------------------------------------------===//
15195// Type reconstruction
15196//===----------------------------------------------------------------------===//
15197
15198template<typename Derived>
15201 return SemaRef.BuildPointerType(PointeeType, Star,
15202 getDerived().getBaseEntity());
15203}
15204
15205template<typename Derived>
15208 return SemaRef.BuildBlockPointerType(PointeeType, Star,
15209 getDerived().getBaseEntity());
15210}
15211
15212template<typename Derived>
15215 bool WrittenAsLValue,
15216 SourceLocation Sigil) {
15217 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
15218 Sigil, getDerived().getBaseEntity());
15219}
15220
15221template<typename Derived>
15224 QualType ClassType,
15225 SourceLocation Sigil) {
15226 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
15227 getDerived().getBaseEntity());
15228}
15229
15230template<typename Derived>
15232 const ObjCTypeParamDecl *Decl,
15233 SourceLocation ProtocolLAngleLoc,
15235 ArrayRef<SourceLocation> ProtocolLocs,
15236 SourceLocation ProtocolRAngleLoc) {
15237 return SemaRef.BuildObjCTypeParamType(Decl,
15238 ProtocolLAngleLoc, Protocols,
15239 ProtocolLocs, ProtocolRAngleLoc,
15240 /*FailOnError=*/true);
15241}
15242
15243template<typename Derived>
15245 QualType BaseType,
15246 SourceLocation Loc,
15247 SourceLocation TypeArgsLAngleLoc,
15249 SourceLocation TypeArgsRAngleLoc,
15250 SourceLocation ProtocolLAngleLoc,
15252 ArrayRef<SourceLocation> ProtocolLocs,
15253 SourceLocation ProtocolRAngleLoc) {
15254 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, TypeArgs,
15255 TypeArgsRAngleLoc, ProtocolLAngleLoc,
15256 Protocols, ProtocolLocs, ProtocolRAngleLoc,
15257 /*FailOnError=*/true,
15258 /*Rebuilding=*/true);
15259}
15260
15261template<typename Derived>
15263 QualType PointeeType,
15265 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
15266}
15267
15268template <typename Derived>
15270 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
15271 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
15272 if (SizeExpr || !Size)
15273 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
15274 IndexTypeQuals, BracketsRange,
15275 getDerived().getBaseEntity());
15276
15277 QualType Types[] = {
15281 };
15282 QualType SizeType;
15283 for (const auto &T : Types)
15284 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
15285 SizeType = T;
15286 break;
15287 }
15288
15289 // Note that we can return a VariableArrayType here in the case where
15290 // the element type was a dependent VariableArrayType.
15291 IntegerLiteral *ArraySize
15292 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
15293 /*FIXME*/BracketsRange.getBegin());
15294 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
15295 IndexTypeQuals, BracketsRange,
15296 getDerived().getBaseEntity());
15297}
15298
15299template <typename Derived>
15301 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
15302 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
15303 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
15304 IndexTypeQuals, BracketsRange);
15305}
15306
15307template <typename Derived>
15309 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
15310 SourceRange BracketsRange) {
15311 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
15312 IndexTypeQuals, BracketsRange);
15313}
15314
15315template <typename Derived>
15317 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
15318 unsigned IndexTypeQuals, SourceRange BracketsRange) {
15319 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
15320 SizeExpr,
15321 IndexTypeQuals, BracketsRange);
15322}
15323
15324template <typename Derived>
15326 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
15327 unsigned IndexTypeQuals, SourceRange BracketsRange) {
15328 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
15329 SizeExpr,
15330 IndexTypeQuals, BracketsRange);
15331}
15332
15333template <typename Derived>
15335 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
15336 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
15337 AttributeLoc);
15338}
15339
15340template <typename Derived>
15342 unsigned NumElements,
15343 VectorKind VecKind) {
15344 // FIXME: semantic checking!
15345 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
15346}
15347
15348template <typename Derived>
15350 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
15351 VectorKind VecKind) {
15352 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
15353}
15354
15355template<typename Derived>
15357 unsigned NumElements,
15358 SourceLocation AttributeLoc) {
15359 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
15360 NumElements, true);
15361 IntegerLiteral *VectorSize
15362 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
15363 AttributeLoc);
15364 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
15365}
15366
15367template<typename Derived>
15370 Expr *SizeExpr,
15371 SourceLocation AttributeLoc) {
15372 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
15373}
15374
15375template <typename Derived>
15377 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
15378 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
15379 NumColumns);
15380}
15381
15382template <typename Derived>
15384 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
15385 SourceLocation AttributeLoc) {
15386 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
15387 AttributeLoc);
15388}
15389
15390template<typename Derived>
15392 QualType T,
15393 MutableArrayRef<QualType> ParamTypes,
15395 return SemaRef.BuildFunctionType(T, ParamTypes,
15396 getDerived().getBaseLocation(),
15397 getDerived().getBaseEntity(),
15398 EPI);
15399}
15400
15401template<typename Derived>
15403 return SemaRef.Context.getFunctionNoProtoType(T);
15404}
15405
15406template<typename Derived>
15408 Decl *D) {
15409 assert(D && "no decl found");
15410 if (D->isInvalidDecl()) return QualType();
15411
15412 // FIXME: Doesn't account for ObjCInterfaceDecl!
15413 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
15414 // A valid resolved using typename pack expansion decl can have multiple
15415 // UsingDecls, but they must each have exactly one type, and it must be
15416 // the same type in every case. But we must have at least one expansion!
15417 if (UPD->expansions().empty()) {
15418 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
15419 << UPD->isCXXClassMember() << UPD;
15420 return QualType();
15421 }
15422
15423 // We might still have some unresolved types. Try to pick a resolved type
15424 // if we can. The final instantiation will check that the remaining
15425 // unresolved types instantiate to the type we pick.
15426 QualType FallbackT;
15427 QualType T;
15428 for (auto *E : UPD->expansions()) {
15429 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
15430 if (ThisT.isNull())
15431 continue;
15432 else if (ThisT->getAs<UnresolvedUsingType>())
15433 FallbackT = ThisT;
15434 else if (T.isNull())
15435 T = ThisT;
15436 else
15437 assert(getSema().Context.hasSameType(ThisT, T) &&
15438 "mismatched resolved types in using pack expansion");
15439 }
15440 return T.isNull() ? FallbackT : T;
15441 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
15442 assert(Using->hasTypename() &&
15443 "UnresolvedUsingTypenameDecl transformed to non-typename using");
15444
15445 // A valid resolved using typename decl points to exactly one type decl.
15446 assert(++Using->shadow_begin() == Using->shadow_end());
15447
15448 UsingShadowDecl *Shadow = *Using->shadow_begin();
15449 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), Loc))
15450 return QualType();
15451 return SemaRef.Context.getUsingType(
15452 Shadow, SemaRef.Context.getTypeDeclType(
15453 cast<TypeDecl>(Shadow->getTargetDecl())));
15454 } else {
15455 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
15456 "UnresolvedUsingTypenameDecl transformed to non-using decl");
15457 return SemaRef.Context.getTypeDeclType(
15458 cast<UnresolvedUsingTypenameDecl>(D));
15459 }
15460}
15461
15462template <typename Derived>
15464 TypeOfKind Kind) {
15465 return SemaRef.BuildTypeofExprType(E, Kind);
15466}
15467
15468template<typename Derived>
15470 TypeOfKind Kind) {
15471 return SemaRef.Context.getTypeOfType(Underlying, Kind);
15472}
15473
15474template <typename Derived>
15476 return SemaRef.BuildDecltypeType(E);
15477}
15478
15479template <typename Derived>
15481 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
15482 SourceLocation EllipsisLoc, bool FullySubstituted,
15483 ArrayRef<QualType> Expansions) {
15484 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
15485 FullySubstituted, Expansions);
15486}
15487
15488template<typename Derived>
15491 SourceLocation Loc) {
15492 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
15493}
15494
15495template<typename Derived>
15497 TemplateName Template,
15498 SourceLocation TemplateNameLoc,
15499 TemplateArgumentListInfo &TemplateArgs) {
15500 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
15501}
15502
15503template<typename Derived>
15505 SourceLocation KWLoc) {
15506 return SemaRef.BuildAtomicType(ValueType, KWLoc);
15507}
15508
15509template<typename Derived>
15511 SourceLocation KWLoc,
15512 bool isReadPipe) {
15513 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
15514 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
15515}
15516
15517template <typename Derived>
15519 unsigned NumBits,
15520 SourceLocation Loc) {
15521 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
15522 NumBits, true);
15523 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
15524 SemaRef.Context.IntTy, Loc);
15525 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
15526}
15527
15528template <typename Derived>
15530 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
15531 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
15532}
15533
15534template<typename Derived>
15537 bool TemplateKW,
15538 TemplateDecl *Template) {
15539 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
15540 TemplateName(Template));
15541}
15542
15543template<typename Derived>
15546 SourceLocation TemplateKWLoc,
15547 const IdentifierInfo &Name,
15548 SourceLocation NameLoc,
15549 QualType ObjectType,
15550 NamedDecl *FirstQualifierInScope,
15551 bool AllowInjectedClassName) {
15553 TemplateName.setIdentifier(&Name, NameLoc);
15554 Sema::TemplateTy Template;
15555 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
15556 TemplateName, ParsedType::make(ObjectType),
15557 /*EnteringContext=*/false, Template,
15558 AllowInjectedClassName);
15559 return Template.get();
15560}
15561
15562template<typename Derived>
15565 SourceLocation TemplateKWLoc,
15566 OverloadedOperatorKind Operator,
15567 SourceLocation NameLoc,
15568 QualType ObjectType,
15569 bool AllowInjectedClassName) {
15570 UnqualifiedId Name;
15571 // FIXME: Bogus location information.
15572 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
15573 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
15574 Sema::TemplateTy Template;
15575 getSema().ActOnTemplateName(
15576 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
15577 /*EnteringContext=*/false, Template, AllowInjectedClassName);
15578 return Template.get();
15579}
15580
15581template <typename Derived>
15584 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
15585 Expr *Second) {
15586 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
15587
15588 if (First->getObjectKind() == OK_ObjCProperty) {
15591 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
15592 First, Second);
15594 if (Result.isInvalid())
15595 return ExprError();
15596 First = Result.get();
15597 }
15598
15599 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
15600 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
15601 if (Result.isInvalid())
15602 return ExprError();
15603 Second = Result.get();
15604 }
15605
15606 // Determine whether this should be a builtin operation.
15607 if (Op == OO_Subscript) {
15608 if (!First->getType()->isOverloadableType() &&
15609 !Second->getType()->isOverloadableType())
15610 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
15611 OpLoc);
15612 } else if (Op == OO_Arrow) {
15613 // It is possible that the type refers to a RecoveryExpr created earlier
15614 // in the tree transformation.
15615 if (First->getType()->isDependentType())
15616 return ExprError();
15617 // -> is never a builtin operation.
15618 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
15619 } else if (Second == nullptr || isPostIncDec) {
15620 if (!First->getType()->isOverloadableType() ||
15621 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
15622 // The argument is not of overloadable type, or this is an expression
15623 // of the form &Class::member, so try to create a built-in unary
15624 // operation.
15626 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
15627
15628 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
15629 }
15630 } else {
15631 if (!First->getType()->isOverloadableType() &&
15632 !Second->getType()->isOverloadableType()) {
15633 // Neither of the arguments is an overloadable type, so try to
15634 // create a built-in binary operation.
15637 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
15638 if (Result.isInvalid())
15639 return ExprError();
15640
15641 return Result;
15642 }
15643 }
15644
15645 // Add any functions found via argument-dependent lookup.
15646 Expr *Args[2] = { First, Second };
15647 unsigned NumArgs = 1 + (Second != nullptr);
15648
15649 // Create the overloaded operator invocation for unary operators.
15650 if (NumArgs == 1 || isPostIncDec) {
15652 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
15653 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
15654 RequiresADL);
15655 }
15656
15657 // Create the overloaded operator invocation for binary operators.
15660 OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL);
15661 if (Result.isInvalid())
15662 return ExprError();
15663
15664 return Result;
15665}
15666
15667template<typename Derived>
15670 SourceLocation OperatorLoc,
15671 bool isArrow,
15672 CXXScopeSpec &SS,
15673 TypeSourceInfo *ScopeType,
15674 SourceLocation CCLoc,
15675 SourceLocation TildeLoc,
15676 PseudoDestructorTypeStorage Destroyed) {
15677 QualType BaseType = Base->getType();
15678 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
15679 (!isArrow && !BaseType->getAs<RecordType>()) ||
15680 (isArrow && BaseType->getAs<PointerType>() &&
15681 !BaseType->castAs<PointerType>()->getPointeeType()
15682 ->template getAs<RecordType>())){
15683 // This pseudo-destructor expression is still a pseudo-destructor.
15684 return SemaRef.BuildPseudoDestructorExpr(
15685 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
15686 CCLoc, TildeLoc, Destroyed);
15687 }
15688
15689 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
15691 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
15692 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
15693 NameInfo.setNamedTypeInfo(DestroyedType);
15694
15695 // The scope type is now known to be a valid nested name specifier
15696 // component. Tack it on to the end of the nested name specifier.
15697 if (ScopeType) {
15698 if (!ScopeType->getType()->getAs<TagType>()) {
15699 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
15700 diag::err_expected_class_or_namespace)
15701 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
15702 return ExprError();
15703 }
15704 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
15705 CCLoc);
15706 }
15707
15708 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
15709 return getSema().BuildMemberReferenceExpr(Base, BaseType,
15710 OperatorLoc, isArrow,
15711 SS, TemplateKWLoc,
15712 /*FIXME: FirstQualifier*/ nullptr,
15713 NameInfo,
15714 /*TemplateArgs*/ nullptr,
15715 /*S*/nullptr);
15716}
15717
15718template<typename Derived>
15721 SourceLocation Loc = S->getBeginLoc();
15722 CapturedDecl *CD = S->getCapturedDecl();
15723 unsigned NumParams = CD->getNumParams();
15724 unsigned ContextParamPos = CD->getContextParamPosition();
15726 for (unsigned I = 0; I < NumParams; ++I) {
15727 if (I != ContextParamPos) {
15728 Params.push_back(
15729 std::make_pair(
15730 CD->getParam(I)->getName(),
15731 getDerived().TransformType(CD->getParam(I)->getType())));
15732 } else {
15733 Params.push_back(std::make_pair(StringRef(), QualType()));
15734 }
15735 }
15736 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
15737 S->getCapturedRegionKind(), Params);
15738 StmtResult Body;
15739 {
15740 Sema::CompoundScopeRAII CompoundScope(getSema());
15741 Body = getDerived().TransformStmt(S->getCapturedStmt());
15742 }
15743
15744 if (Body.isInvalid()) {
15745 getSema().ActOnCapturedRegionError();
15746 return StmtError();
15747 }
15748
15749 return getSema().ActOnCapturedRegionEnd(Body.get());
15750}
15751
15752} // end namespace clang
15753
15754#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
int Id
Definition: ASTDiff.cpp:190
MatchType Type
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1110
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:2956
unsigned Iter
Definition: HTMLLogger.cpp:154
#define X(type, name)
Definition: Value.h:142
llvm::MachO::Target Target
Definition: MachO.h:40
llvm::MachO::Record Record
Definition: MachO.h:28
This file defines OpenMP AST classes for clauses.
Defines some OpenMP-specific enums and functions.
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.
SourceLocation Begin
std::string Label
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1068
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:643
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
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:2549
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2565
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:1575
IdentifierTable & Idents
Definition: ASTContext.h:639
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:1096
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:1095
CanQualType PseudoObjectTy
Definition: ASTContext.h:1116
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2141
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:1097
CanQualType BuiltinFnTy
Definition: ASTContext.h:1115
CanQualType UnsignedCharTy
Definition: ASTContext.h:1096
CanQualType UnsignedIntTy
Definition: ASTContext.h:1096
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1097
CanQualType UnsignedShortTy
Definition: ASTContext.h:1096
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:2836
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:2874
ArrayTypeTrait getTrait() const
Definition: ExprCXX.h:2876
Expr * getDimensionExpression() const
Definition: ExprCXX.h:2884
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition: ExprCXX.h:2880
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:2873
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2603
TypeLoc getValueLoc() const
Definition: TypeLoc.h:2579
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2587
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2595
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:2078
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:5147
QualType getModifiedType() const
Definition: Type.h:5169
std::optional< NullabilityKind > getImmediateNullability() const
Definition: Type.cpp:4660
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:5524
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:5534
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:5539
AutoTypeKeyword getKeyword() const
Definition: Type.h:5555
Type source information for an btf_tag attributed type.
Definition: TypeLoc.h:925
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2167
bool isAssignmentOp() const
Definition: Expr.h:3972
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:2129
void setIsVariadic(bool value)
Definition: Decl.h:4535
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5251
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:5270
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:5269
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1475
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1530
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1698
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1673
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition: ExprCXX.h:1623
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:519
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:513
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1612
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1670
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2528
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:969
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1721
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition: ExprCXX.h:403
SourceRange getAngleBrackets() const LLVM_READONLY
Definition: ExprCXX.h:410
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition: ExprCXX.h:406
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2165
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:73
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:235
SourceRange getRange() const
Definition: DeclSpec.h:79
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:94
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:239
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:3519
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition: ExprCXX.h:3563
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition: ExprCXX.h:3574
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition: ExprCXX.h:3557
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition: ExprCXX.h:3568
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition: ExprCXX.h:3577
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:1474
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4651
unsigned getNumParams() const
Definition: Decl.h:4693
unsigned getContextParamPosition() const
Definition: Decl.h:4722
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4695
This captures a statement into a function.
Definition: Stmt.h:3755
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition: Expr.cpp:1967
Expr * getSubExpr()
Definition: Expr.h:3539
SourceLocation getBegin() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1604
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:93
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:421
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1379
reference front() const
Definition: DeclBase.h:1402
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1446
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1785
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1699
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1260
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1495
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
bool isInvalidDecl() const
Definition: DeclBase.h:593
SourceLocation getLocation() const
Definition: DeclBase.h:444
DeclContext * getDeclContext()
Definition: DeclBase.h:453
AccessSpecifier getAccess() const
Definition: DeclBase.h:512
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:813
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:799
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1899
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:5511
bool isDeduced() const
Definition: Type.h:5512
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3285
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3359
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition: ExprCXX.h:3333
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3351
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition: ExprCXX.h:3369
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3343
unsigned getNumTemplateArgs() const
Definition: ExprCXX.h:3386
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:3324
TemplateArgumentLoc const * getTemplateArgs() const
Definition: ExprCXX.h:3379
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition: ExprCXX.h:3321
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:488
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2441
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2465
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2461
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:2457
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2429
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2485
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2425
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2477
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2493
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2469
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6047
const IdentifierInfo * getIdentifier() const
Definition: Type.h:6064
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
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2288
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2300
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2292
TypeLoc getNamedTypeLoc() const
Definition: TypeLoc.h:2330
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2306
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:5914
QualType getNamedType() const
Retrieve the type named by the qualified-id.
Definition: Type.h:5952
RAII object that enters a new expression evaluation context.
Represents an enum.
Definition: Decl.h:3832
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3746
This represents one expression.
Definition: Expr.h:110
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
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition: Expr.cpp:3140
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:870
Represents a member of a struct/union/class.
Definition: Decl.h:3025
Represents a function declaration or definition.
Definition: Decl.h:1959
QualType getReturnType() const
Definition: Decl.h:2722
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Definition: Decl.h:2758
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4154
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4199
param_type_iterator param_type_begin() const
Definition: Type.h:4591
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:4629
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:4571
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:4443
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:4439
unsigned getNumParams() const
Definition: TypeLoc.h:1474
SourceLocation getLocalRangeEnd() const
Definition: TypeLoc.h:1426
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1422
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1438
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1454
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1481
ArrayRef< ParmVarDecl * > getParams() const
Definition: TypeLoc.h:1465
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1446
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1430
void setExceptionSpecRange(SourceRange R)
Definition: TypeLoc.h:1460
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1483
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1418
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1434
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1442
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:3825
QualType getReturnType() const
Definition: Type.h:4116
AssociationTy< false > Association
Definition: Expr.h:5950
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:3649
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5594
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:957
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:1938
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition: ExprCXX.cpp:1295
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition: ExprCXX.cpp:1290
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition: ExprCXX.cpp:1299
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition: ExprCXX.h:2003
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:600
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:472
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition: SemaLookup.cpp:483
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4679
This represents a decl that may have a name.
Definition: Decl.h:249
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:3113
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
bool hasAssociatedStmt() const
Returns true if directive has associated statement.
Definition: StmtOpenMP.h:531
OpenMPDirectiveKind getDirectiveKind() const
Definition: StmtOpenMP.h:569
const Stmt * getAssociatedStmt() const
Returns statement associated with the directive.
Definition: StmtOpenMP.h:534
SourceLocation getBeginLoc() const
Returns starting location of directive kind.
Definition: StmtOpenMP.h:502
const Stmt * getRawStmt() const
Definition: StmtOpenMP.h:606
ArrayRef< OMPClause * > clauses() const
Definition: StmtOpenMP.h:586
OpenMPDirectiveKind getMappedDirective() const
Definition: StmtOpenMP.h:615
SourceLocation getEndLoc() const
Returns ending location of directive.
Definition: StmtOpenMP.h:504
This represents clauses with a list of expressions that are mappable.
This represents '#pragma omp metadirective' directive.
Definition: StmtOpenMP.h:5943
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1947
@ 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:729
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:2363
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2367
@ Field
A field.
Definition: Expr.h:2365
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2370
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:1168
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1218
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition: ExprCXX.h:2966
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:3117
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3099
SourceLocation getNameLoc() const
Gets the location of the name.
Definition: ExprCXX.h:3078
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3091
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition: ExprCXX.h:3087
TemplateArgumentLoc const * getTemplateArgs() const
Definition: ExprCXX.h:3119
llvm::iterator_range< decls_iterator > decls() const
Definition: ExprCXX.h:3064
unsigned getNumTemplateArgs() const
Definition: ExprCXX.h:3125
DeclarationName getName() const
Gets the name looked up.
Definition: ExprCXX.h:3075
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3107
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4142
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2551
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2547
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2563
Represents a pack expansion of types.
Definition: Type.h:6112
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:6137
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2129
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2152
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2156
Represents a parameter to a function.
Definition: Decl.h:1749
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1809
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1782
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2915
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1799
void setSigilLoc(SourceLocation Loc)
Definition: TypeLoc.h:1252
TypeLoc getPointeeLoc() const
Definition: TypeLoc.h:1256
SourceLocation getSigilLoc() const
Definition: TypeLoc.h:1248
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:2898
QualType getPointeeType() const
Definition: Type.h:2908
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2549
SourceLocation getLocation() const
Definition: ExprCXX.h:2573
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2565
IdentifierInfo * getIdentifier() const
Definition: ExprCXX.h:2569
A (possibly-)qualified type.
Definition: Type.h:737
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:804
LangAS getAddressSpace() const
Return the address space of this type.
Definition: Type.h:7027
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:6942
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
Definition: Type.h:1229
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:6995
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:6934
Represents a template name that was expressed as a qualified name.
Definition: TemplateName.h:431
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition: TypeLoc.h:289
UnqualTypeLoc getUnqualifiedLoc() const
Definition: TypeLoc.h:293
The collection of all-type qualifiers we support.
Definition: Type.h:147
void removeObjCLifetime()
Definition: Type.h:358
bool hasRestrict() const
Definition: Type.h:284
static Qualifiers fromCVRMask(unsigned CVR)
Definition: Type.h:240
bool hasObjCLifetime() const
Definition: Type.h:351
bool empty() const
Definition: Type.h:440
LangAS getAddressSpace() const
Definition: Type.h:378
Represents a struct/union/class.
Definition: Decl.h:4133
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5092
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3009
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3025
bool isSpelledAsLValue() const
Definition: Type.h:3022
Represents the body of a requires-expression.
Definition: DeclCXX.h:2023
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition: DeclCXX.cpp:2173
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:3716
Smart pointer class that efficiently represents Objective-C method names.
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:10543
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:6786
A RAII object to enter scope of a compound statement.
Definition: Sema.h:1037
A helper class for building up ExtParameterInfos.
Definition: Sema.h:10005
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:10024
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition: Sema.h:10012
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition: Sema.h:10794
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:426
OMPClause * ActOnOpenMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_bare' 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.
QualType BuildParenType(QualType T)
Build a paren type including T.
Definition: SemaType.cpp:2056
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:6768
OMPClause * ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depend' clause.
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.
OMPClause * ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'init' clause.
OMPClause * ActOnOpenMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_threads' clause.
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:4747
OMPClause * ActOnOpenMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'novariants' clause.
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:7607
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:7615
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:7610
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:6877
ExprResult ActOnConstantExpression(ExprResult Res)
Definition: SemaExpr.cpp:20416
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)
OMPClause * ActOnOpenMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'exclusive' clause.
OMPClause * ActOnOpenMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_ptr' clause.
StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs)
ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E)
ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *operand)
Definition: SemaStmt.cpp:4382
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: Sema.cpp:1911
QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc)
Definition: SemaType.cpp:2762
StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: SemaStmt.cpp:603
@ IER_DoesNotExist
The symbol does not exist.
Definition: Sema.h:7112
@ IER_Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition: Sema.h:7116
@ IER_Error
An error occurred.
Definition: Sema.h:7119
@ IER_Exists
The symbol exists.
Definition: Sema.h:7109
void ActOnStartStmtExpr()
Definition: SemaExpr.cpp:16636
OMPClause * ActOnOpenMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'flush' pseudo clause.
void ActOnStmtExprError()
Definition: SemaExpr.cpp:16642
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
Definition: SemaStmt.cpp:2312
OMPClause * ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'device' clause.
OMPClause * ActOnOpenMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_addr' clause.
OMPClause * ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'priority' clause.
OMPClause * ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, OpenMPOrderClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'order' clause.
VarDecl * buildCoroutinePromise(SourceLocation Loc)
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: SemaType.cpp:1080
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:21143
ConditionKind
Definition: Sema.h:6116
@ 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:399
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
Definition: SemaStmt.cpp:3322
ExprResult BuildObjCDictionaryLiteral(SourceRange SR, MutableArrayRef< ObjCDictionaryElement > Elements)
OMPClause * ActOnOpenMPAllocateClause(Expr *Allocator, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' clause.
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:460
QualType BuildExtVectorType(QualType T, Expr *ArraySize, SourceLocation AttrLoc)
Build an ext-vector type.
Definition: SemaType.cpp:2836
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
Definition: SemaInit.cpp:3363
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:20928
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth)
Definition: SemaExpr.cpp:16655
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
Definition: SemaExpr.cpp:5345
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)
ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc)
Definition: SemaExpr.cpp:17308
OMPClause * ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'destroy' clause.
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
Definition: SemaStmt.cpp:4338
OMPClause * ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'bind' clause.
ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, bool ArrayForm, Expr *Operand)
ActOnCXXDelete - Parsed a C++ 'delete' expression.
ASTContext & Context
Definition: Sema.h:1030
OMPClause * ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'final' clause.
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:3075
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, bool IsAddressOfOperand, const Scope *S, TypeSourceInfo **RecoveryTSI=nullptr)
BuildQualifiedDeclarationNameExpr - Build a C++ qualified declaration name, generally during template...
Definition: SemaExpr.cpp:2937
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:498
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.
OMPClause * ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'hint' clause.
ExprResult checkPseudoObjectAssignment(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opcode, Expr *LHS, Expr *RHS)
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Definition: SemaStmt.cpp:4438
StmtResult ActOnEndOpenACCStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation EndLoc, StmtResult AssocStmt)
Called after the directive has been completely parsed, including the declaration group or associated ...
Definition: SemaOpenACC.cpp:76
ASTContext & getASTContext() const
Definition: Sema.h:501
OMPClause * ActOnOpenMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'shared' clause.
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:16571
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.
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:4671
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Definition: SemaExpr.cpp:3728
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
Definition: SemaExpr.cpp:7787
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Definition: SemaExpr.cpp:16623
Expr * recreateSyntacticForm(PseudoObjectExpr *E)
Given a pseudo-object expression, recreate what it looks like syntactically without the attendant Opa...
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
Definition: SemaExpr.cpp:8694
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)
ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, TypeSourceInfo *TSInfo, Expr *SubExpr)
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:17092
OMPClause * ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'at' clause.
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
Definition: SemaExpr.cpp:2199
QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc)
Build a bit-precise integer type.
Definition: SemaType.cpp:2371
ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16911
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:1668
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.
QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, const DeclSpec *DS=nullptr)
Definition: SemaType.cpp:1961
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Definition: SemaStmt.cpp:1242
OMPClause * ActOnOpenMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'firstprivate' clause.
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:58
StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, MultiStmtArg Catch, Stmt *Finally)
Definition: SemaStmt.cpp:4320
OMPClause * ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_dyn_cgroup_mem' clause.
const LangOptions & getLangOpts() const
Definition: Sema.h:494
ExprResult BuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition: SemaExpr.cpp:3773
OMPClause * ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'severity' clause.
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:1716
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.
@ ReuseLambdaContextDecl
Definition: Sema.h:5416
StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc, OpenMPDirectiveKind PrevMappedDirective=llvm::omp::OMPD_unknown)
void ActOnOpenACCConstruct(OpenACCDirectiveKind K, SourceLocation StartLoc)
Called after the construct has been parsed, but clauses haven't been parsed.
Definition: SemaOpenACC.cpp:50
OMPClause * ActOnOpenMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'has_device_addr' clause.
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, std::optional< unsigned > NumExpansions)
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:17581
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CCK_ImplicitConversion)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Definition: Sema.cpp:636
ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, SourceLocation LParenLoc, MultiExprArg Exprs, SourceLocation RParenLoc, bool ListInitialization)
OMPClause * ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'simdlen' clause.
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement.
Definition: SemaStmt.cpp:3111
ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, ArrayRef< OffsetOfComponent > Components, SourceLocation RParenLoc)
__builtin_offsetof(type, a.b[123][456].c)
Definition: SemaExpr.cpp:16725
OMPClause * ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'filter' clause.
ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, TypeSourceInfo *EncodedTypeInfo, SourceLocation RParenLoc)
OMPClause * ActOnOpenMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Called on well-formed 'affinity' clause.
QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo &II, SourceLocation IILoc, TypeSourceInfo **TSI, bool DeducedTSTContext)
OMPClause * ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'proc_bind' clause.
OMPClause * ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'align' clause.
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
DeclContext * getCurLexicalContext() const
Definition: Sema.h:873
OMPClause * ActOnOpenMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' clause.
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:17063
ExprResult BuildExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, Expr *Queried, SourceLocation RParen)
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.
bool buildCoroutineParameterMoves(SourceLocation Loc)
OMPClause * ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'default' clause.
ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, SourceLocation RParenLoc, Expr *Op)
Definition: SemaCast.cpp:3331
OMPClause * ActOnOpenMPNocontextClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nocontext' clause.
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:1064
OMPClause * ActOnOpenMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'aligned' clause.
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
Definition: SemaDecl.cpp:15025
Expr * BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit)
Build a CXXThisExpr and mark it referenced in the current context.
OMPClause * ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'if' clause.
QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, DeclarationName Entity)
Build a reference type.
Definition: SemaType.cpp:2264
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.
OMPClause * ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< UsesAllocatorsData > Data)
Called on well-formed 'uses_allocators' clause.
VarDecl * BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id)
Perform semantic analysis for the variable declaration that occurs within a C++ catch clause,...
OMPClause * ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc=SourceLocation(), Expr *NumForLoops=nullptr)
Called on well-formed 'ordered' clause.
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition: Sema.h:10537
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
Definition: SemaExpr.cpp:3423
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition: Sema.cpp:2331
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:1163
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.
OMPClause * ActOnOpenMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyin' clause.
ExprResult BuildPackIndexingExpr(Expr *PackExpression, SourceLocation EllipsisLoc, Expr *IndexExpr, SourceLocation RSquareLoc, ArrayRef< Expr * > ExpandedExprs={}, bool EmptyPack=false)
VarDecl * BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, bool Invalid=false)
Build a type-check a new Objective-C exception variable declaration.
void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base=nullptr)
Perform reference-marking and odr-use handling for a DeclRefExpr.
Definition: SemaExpr.cpp:20762
ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, SourceLocation RParen)
OMPClause * ActOnOpenMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'dist_schedule' clause.
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:2161
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
Definition: SemaStmt.cpp:3337
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
Definition: SemaExpr.cpp:4341
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Definition: SemaExpr.cpp:21731
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...
OMPClause * ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'use' clause.
OMPClause * ActOnOpenMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on well-form 'full' clauses.
NonTagKind
Common ways to introduce type names without a tag for use in diagnostics.
Definition: Sema.h:3298
@ NTK_TypeAliasTemplate
Definition: Sema.h:3306
TryCaptureKind
Definition: Sema.h:5458
@ TryCapture_Implicit
Definition: Sema.h:5459
@ TryCapture_ExplicitByVal
Definition: Sema.h:5460
@ TryCapture_ExplicitByRef
Definition: Sema.h:5461
ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Create a new AsTypeExpr node (bitcast) from the arguments.
Definition: SemaExpr.cpp:7430
ExprResult checkPseudoObjectRValue(Expr *E)
ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, FieldDecl *Field, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo)
bool CheckRebuiltStmtAttributes(ArrayRef< const Attr * > Attrs)
OMPClause * ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'detach' clause.
ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr)
ActOnConditionalOp - Parse a ?: operation.
Definition: SemaExpr.cpp:9709
QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted=false, ArrayRef< QualType > Expansions={})
Definition: SemaType.cpp:9860
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.
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the '@' prefixed parenthesized expression.
ExprResult SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
SemaConvertVectorExpr - Handle __builtin_convertvector.
OMPClause * ActOnOpenMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_attribute' clause.
concepts::ExprRequirement * BuildExprRequirement(Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement)
ParsedType getDestructorName(IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, ParsedType ObjectType, bool EnteringContext)
QualType BuildAtomicType(QualType T, SourceLocation Loc)
Definition: SemaType.cpp:10143
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:14015
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:224
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Definition: SemaStmt.cpp:4315
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
Definition: SemaStmt.cpp:4017
ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
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:2199
ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > Brackets)
Definition: SemaExpr.cpp:5531
OMPClause * ActOnOpenMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyprivate' clause.
OMPClause * ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depobj' pseudo clause.
OMPClause * ActOnOpenMPThreadLimitClause(Expr *ThreadLimit, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'thread_limit' clause.
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:2773
OMPClause * ActOnOpenMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'private' clause.
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
Definition: SemaStmt.cpp:1737
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.
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
Definition: SemaStmt.cpp:1118
OMPClause * ActOnOpenMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nontemporal' 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.
@ 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),...
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:9828
QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, SourceLocation Loc)
Definition: SemaType.cpp:10087
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
Definition: SemaStmt.cpp:4709
ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a sizeof or alignof expression given a type operand.
Definition: SemaExpr.cpp:4840
OMPClause * ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'grainsize' clause.
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition: SemaStmt.cpp:75
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,...
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.
OMPClause * ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'doacross' clause.
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition: Sema.h:6669
OMPClause * ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_tasks' clause.
OMPClause * ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'partial' clauses.
OMPClause * ActOnOpenMPSafelenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'safelen' clause.
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:2494
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Definition: SemaExpr.cpp:6331
QualType BuildReadPipeType(QualType T, SourceLocation Loc)
Build a Read-only Pipe type.
Definition: SemaType.cpp:2347
concepts::NestedRequirement * BuildNestedRequirement(Expr *E)
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: SemaType.cpp:1057
QualType BuildWritePipeType(QualType T, SourceLocation Loc)
Build a Write-only Pipe type.
Definition: SemaType.cpp:2359
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h:8829
ExprResult CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs)
OMPClause * ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'message' clause.
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition: SemaStmt.cpp:544
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:17112
QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind)
Definition: SemaType.cpp:9742
OMPClause * ActOnOpenMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'lastprivate' clause.
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:20785
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
Definition: SemaCast.cpp:301
OMPClause * ActOnOpenMPSizesClause(ArrayRef< Expr * > SizeExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'sizes' clause.
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:18892
QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, SourceLocation AttrLoc)
Definition: SemaType.cpp:2896
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:21957
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
Definition: SemaExpr.cpp:16135
StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, Decl *Parm, Stmt *Body)
Definition: SemaStmt.cpp:4304
ExprResult PerformObjectMemberConversion(Expr *From, NestedNameSpecifier *Qualifier, NamedDecl *FoundDecl, NamedDecl *Member)
Cast a base object to a member's actual type.
Definition: SemaExpr.cpp:3203
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
Definition: SemaStmt.cpp:905
ExprResult BuildInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, SourceLocation RBraceLoc)
Definition: SemaExpr.cpp:7980
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
Definition: SemaExpr.cpp:16950
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
Definition: SemaExpr.cpp:5064
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:15604
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:7162
ExprResult SemaBuiltinShuffleVector(CallExpr *TheCall)
SemaBuiltinShuffleVector - Handle __builtin_shufflevector.
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:3213
StmtResult ActOnOpenACCAssociatedStmt(OpenACCDirectiveKind K, StmtResult AssocStmt)
Called when we encounter an associated statement for our construct, this should check legality of the...
Definition: SemaOpenACC.cpp:95
OMPClause * ActOnOpenMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'defaultmap' clause.
static ConditionResult ConditionError()
Definition: Sema.h:6103
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition: SemaStmt.cpp:411
StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt)
Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to an OpenMP loop directive.
ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< OMPIteratorData > Data)
Definition: SemaExpr.cpp:5606
ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs, const Scope *S, UnresolvedLookupExpr *AsULE=nullptr)
Builds an expression which might be an implicit member expression.
OMPClause * ActOnOpenMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'inclusive' clause.
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
Definition: SemaStmt.cpp:4420
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
Definition: SemaStmt.cpp:569
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:4558
OMPClause * ActOnOpenMPCollapseClause(Expr *NumForLoops, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'collapse' clause.
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition: SemaStmt.cpp:549
ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements)
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
Definition: SemaExpr.cpp:18717
OMPClause * ActOnOpenMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'is_device_ptr' clause.
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition: SemaStmt.cpp:512
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.
OMPClause * ActOnOpenMPAllocatorClause(Expr *Allocator, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocator' clause.
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.
QualType BuildMemberPointerType(QualType T, QualType Class, SourceLocation Loc, DeclarationName Entity)
Build a member pointer type T Class::*.
Definition: SemaType.cpp:3133
QualType BuildBlockPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a block pointer type.
Definition: SemaType.cpp:3196
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
Definition: SemaStmt.cpp:3304
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition: Sema.h:6967
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
Definition: SemaExpr.cpp:5231
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:1644
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition: Expr.h:4781
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.
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
StmtClass
Definition: Stmt.h:86
@ NoStmtClass
Definition: Stmt.h:87
StmtClass getStmtClass() const
Definition: Stmt.h:1356
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
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:3549
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:202
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:1656
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1632
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1673
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1640
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1669
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1648
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:5632
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
Definition: Type.h:5698
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 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.
StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc, OpenMPDirectiveKind PrevMappedDirective=OMPD_unknown)
Build a new OpenMP executable directive.
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.
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.
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.
OMPClause * RebuildOMPUsesAllocatorsClause(ArrayRef< Sema::UsesAllocatorsData > Data, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'uses_allocators' 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)
ExprResult RebuildOMPIteratorExpr(SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< Sema::OMPIteratorData > Data)
Build a new iterator expression.
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 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.
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)
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation EndLoc, StmtResult StrBlock)
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)
ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBracketLoc)
Build a new array section expression.
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.
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.
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:742
TypeLocClass getTypeLocClass() const
Definition: TypeLoc.h:116
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:2653
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
A container of type source information.
Definition: Type.h:6873
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:6884
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:3105
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:5872
The base class of the type hierarchy.
Definition: Type.h:1606
bool isPointerType() const
Definition: Type.h:7154
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7724
bool isReferenceType() const
Definition: Type.h:7166
bool isEnumeralType() const
Definition: Type.h:7248
bool canHaveNullability(bool ResultIfUnknown=true) const
Determine whether the given type can have a nullability specifier applied to it, i....
Definition: Type.cpp:4529
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2525
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2420
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2094
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: Type.h:7580
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:4778
bool isFunctionType() const
Definition: Type.h:7150
bool isObjCObjectPointerType() const
Definition: Type.h:7282
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7657
bool isRecordType() const
Definition: Type.h:7244
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3399
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:2182
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition: Expr.h:2231
Expr * getSubExpr() const
Definition: Expr.h:2227
Opcode getOpcode() const
Definition: Expr.h:2222
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1394
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:1024
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3163
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:3239
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:3231
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, bool Overloaded, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:373
A set of unresolved declarations.
Definition: UnresolvedSet.h:61
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:91
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:4687
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3313
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3377
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:706
QualType getType() const
Definition: Decl.h:717
Represents a variable declaration or definition.
Definition: Decl.h:918
@ CInit
C-style initialization with assignment.
Definition: Decl.h:923
@ CallInit
Call-style initialization (C++98)
Definition: Decl.h:926
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1152
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Definition: Decl.cpp:2663
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
@ 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:589
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
Definition: Interp.h:708
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition: Descriptor.h:27
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'.
@ Device
'device' clause, allowed on the 'update' construct.
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:59
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1565
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:1522
@ 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:718
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:3144
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:5842
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
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
Definition: Sema.h:246
VectorKind
Definition: Type.h:3475
OpenMPDeviceClauseModifier
OpenMP modifiers for 'device' clause.
Definition: OpenMPKinds.h:47
SourceLocIdentKind
Definition: Expr.h:4708
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:5817
@ 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:1970
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:93
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.
Holds information about the various types of exception specification.
Definition: Type.h:4250
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:4266
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:4252
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:4255
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:4258
Extra information about a function prototype.
Definition: Type.h:4278
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:4285
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:4286
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:10082
@ BuildingDeductionGuides
We are building deduction guides for a class.
Definition: Sema.h:10158
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:2508
Location information for a TemplateArgument.
Definition: TemplateBase.h:472