clang 20.0.0git
TreeTransform.h
Go to the documentation of this file.
1//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//===----------------------------------------------------------------------===//
7//
8// This file implements a semantic tree transformation that takes a given
9// AST and rebuilds it, possibly transforming some nodes in the process.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15
17#include "TypeLocBuilder.h"
18#include "clang/AST/Decl.h"
19#include "clang/AST/DeclObjC.h"
21#include "clang/AST/Expr.h"
22#include "clang/AST/ExprCXX.h"
24#include "clang/AST/ExprObjC.h"
27#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
36#include "clang/Sema/Lookup.h"
42#include "clang/Sema/SemaObjC.h"
46#include "clang/Sema/SemaSYCL.h"
47#include "llvm/ADT/ArrayRef.h"
48#include "llvm/Support/ErrorHandling.h"
49#include <algorithm>
50#include <optional>
51
52using namespace llvm::omp;
53
54namespace clang {
55using namespace sema;
56
57/// A semantic tree transformation that allows one to transform one
58/// abstract syntax tree into another.
59///
60/// A new tree transformation is defined by creating a new subclass \c X of
61/// \c TreeTransform<X> and then overriding certain operations to provide
62/// behavior specific to that transformation. For example, template
63/// instantiation is implemented as a tree transformation where the
64/// transformation of TemplateTypeParmType nodes involves substituting the
65/// template arguments for their corresponding template parameters; a similar
66/// transformation is performed for non-type template parameters and
67/// template template parameters.
68///
69/// This tree-transformation template uses static polymorphism to allow
70/// subclasses to customize any of its operations. Thus, a subclass can
71/// override any of the transformation or rebuild operators by providing an
72/// operation with the same signature as the default implementation. The
73/// overriding function should not be virtual.
74///
75/// Semantic tree transformations are split into two stages, either of which
76/// can be replaced by a subclass. The "transform" step transforms an AST node
77/// or the parts of an AST node using the various transformation functions,
78/// then passes the pieces on to the "rebuild" step, which constructs a new AST
79/// node of the appropriate kind from the pieces. The default transformation
80/// routines recursively transform the operands to composite AST nodes (e.g.,
81/// the pointee type of a PointerType node) and, if any of those operand nodes
82/// were changed by the transformation, invokes the rebuild operation to create
83/// a new AST node.
84///
85/// Subclasses can customize the transformation at various levels. The
86/// most coarse-grained transformations involve replacing TransformType(),
87/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
88/// TransformTemplateName(), or TransformTemplateArgument() with entirely
89/// new implementations.
90///
91/// For more fine-grained transformations, subclasses can replace any of the
92/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
93/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
94/// replacing TransformTemplateTypeParmType() allows template instantiation
95/// to substitute template arguments for their corresponding template
96/// parameters. Additionally, subclasses can override the \c RebuildXXX
97/// functions to control how AST nodes are rebuilt when their operands change.
98/// By default, \c TreeTransform will invoke semantic analysis to rebuild
99/// AST nodes. However, certain other tree transformations (e.g, cloning) may
100/// be able to use more efficient rebuild steps.
101///
102/// There are a handful of other functions that can be overridden, allowing one
103/// to avoid traversing nodes that don't need any transformation
104/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
105/// operands have not changed (\c AlwaysRebuild()), and customize the
106/// default locations and entity names used for type-checking
107/// (\c getBaseLocation(), \c getBaseEntity()).
108template<typename Derived>
110 /// Private RAII object that helps us forget and then re-remember
111 /// the template argument corresponding to a partially-substituted parameter
112 /// pack.
113 class ForgetPartiallySubstitutedPackRAII {
114 Derived &Self;
116 // Set the pack expansion index to -1 to avoid pack substitution and
117 // indicate that parameter packs should be instantiated as themselves.
118 Sema::ArgumentPackSubstitutionIndexRAII ResetPackSubstIndex;
119
120 public:
121 ForgetPartiallySubstitutedPackRAII(Derived &Self)
122 : Self(Self), ResetPackSubstIndex(Self.getSema(), -1) {
123 Old = Self.ForgetPartiallySubstitutedPack();
124 }
125
126 ~ForgetPartiallySubstitutedPackRAII() {
127 Self.RememberPartiallySubstitutedPack(Old);
128 }
129 };
130
131protected:
133
134 /// The set of local declarations that have been transformed, for
135 /// cases where we are forced to build new declarations within the transformer
136 /// rather than in the subclass (e.g., lambda closure types).
137 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
138
139public:
140 /// Initializes a new tree transformer.
142
143 /// Retrieves a reference to the derived class.
144 Derived &getDerived() { return static_cast<Derived&>(*this); }
145
146 /// Retrieves a reference to the derived class.
147 const Derived &getDerived() const {
148 return static_cast<const Derived&>(*this);
149 }
150
151 static inline ExprResult Owned(Expr *E) { return E; }
152 static inline StmtResult Owned(Stmt *S) { return S; }
153
154 /// Retrieves a reference to the semantic analysis object used for
155 /// this tree transform.
156 Sema &getSema() const { return SemaRef; }
157
158 /// Whether the transformation should always rebuild AST nodes, even
159 /// if none of the children have changed.
160 ///
161 /// Subclasses may override this function to specify when the transformation
162 /// should rebuild all AST nodes.
163 ///
164 /// We must always rebuild all AST nodes when performing variadic template
165 /// pack expansion, in order to avoid violating the AST invariant that each
166 /// statement node appears at most once in its containing declaration.
168
169 /// Whether the transformation is forming an expression or statement that
170 /// replaces the original. In this case, we'll reuse mangling numbers from
171 /// existing lambdas.
172 bool ReplacingOriginal() { return false; }
173
174 /// Wether CXXConstructExpr can be skipped when they are implicit.
175 /// They will be reconstructed when used if needed.
176 /// This is useful when the user that cause rebuilding of the
177 /// CXXConstructExpr is outside of the expression at which the TreeTransform
178 /// started.
179 bool AllowSkippingCXXConstructExpr() { return true; }
180
181 /// Returns the location of the entity being transformed, if that
182 /// information was not available elsewhere in the AST.
183 ///
184 /// By default, returns no source-location information. Subclasses can
185 /// provide an alternative implementation that provides better location
186 /// information.
188
189 /// Returns the name of the entity being transformed, if that
190 /// information was not available elsewhere in the AST.
191 ///
192 /// By default, returns an empty name. Subclasses can provide an alternative
193 /// implementation with a more precise name.
195
196 /// Sets the "base" location and entity when that
197 /// information is known based on another transformation.
198 ///
199 /// By default, the source location and entity are ignored. Subclasses can
200 /// override this function to provide a customized implementation.
202
203 /// RAII object that temporarily sets the base location and entity
204 /// used for reporting diagnostics in types.
206 TreeTransform &Self;
207 SourceLocation OldLocation;
208 DeclarationName OldEntity;
209
210 public:
212 DeclarationName Entity) : Self(Self) {
213 OldLocation = Self.getDerived().getBaseLocation();
214 OldEntity = Self.getDerived().getBaseEntity();
215
216 if (Location.isValid())
217 Self.getDerived().setBase(Location, Entity);
218 }
219
221 Self.getDerived().setBase(OldLocation, OldEntity);
222 }
223 };
224
225 /// Determine whether the given type \p T has already been
226 /// transformed.
227 ///
228 /// Subclasses can provide an alternative implementation of this routine
229 /// to short-circuit evaluation when it is known that a given type will
230 /// not change. For example, template instantiation need not traverse
231 /// non-dependent types.
233 return T.isNull();
234 }
235
236 /// Transform a template parameter depth level.
237 ///
238 /// During a transformation that transforms template parameters, this maps
239 /// an old template parameter depth to a new depth.
240 unsigned TransformTemplateDepth(unsigned Depth) {
241 return Depth;
242 }
243
244 /// Determine whether the given call argument should be dropped, e.g.,
245 /// because it is a default argument.
246 ///
247 /// Subclasses can provide an alternative implementation of this routine to
248 /// determine which kinds of call arguments get dropped. By default,
249 /// CXXDefaultArgument nodes are dropped (prior to transformation).
251 return E->isDefaultArgument();
252 }
253
254 /// Determine whether we should expand a pack expansion with the
255 /// given set of parameter packs into separate arguments by repeatedly
256 /// transforming the pattern.
257 ///
258 /// By default, the transformer never tries to expand pack expansions.
259 /// Subclasses can override this routine to provide different behavior.
260 ///
261 /// \param EllipsisLoc The location of the ellipsis that identifies the
262 /// pack expansion.
263 ///
264 /// \param PatternRange The source range that covers the entire pattern of
265 /// the pack expansion.
266 ///
267 /// \param Unexpanded The set of unexpanded parameter packs within the
268 /// pattern.
269 ///
270 /// \param ShouldExpand Will be set to \c true if the transformer should
271 /// expand the corresponding pack expansions into separate arguments. When
272 /// set, \c NumExpansions must also be set.
273 ///
274 /// \param RetainExpansion Whether the caller should add an unexpanded
275 /// pack expansion after all of the expanded arguments. This is used
276 /// when extending explicitly-specified template argument packs per
277 /// C++0x [temp.arg.explicit]p9.
278 ///
279 /// \param NumExpansions The number of separate arguments that will be in
280 /// the expanded form of the corresponding pack expansion. This is both an
281 /// input and an output parameter, which can be set by the caller if the
282 /// number of expansions is known a priori (e.g., due to a prior substitution)
283 /// and will be set by the callee when the number of expansions is known.
284 /// The callee must set this value when \c ShouldExpand is \c true; it may
285 /// set this value in other cases.
286 ///
287 /// \returns true if an error occurred (e.g., because the parameter packs
288 /// are to be instantiated with arguments of different lengths), false
289 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
290 /// must be set.
292 SourceRange PatternRange,
294 bool &ShouldExpand, bool &RetainExpansion,
295 std::optional<unsigned> &NumExpansions) {
296 ShouldExpand = false;
297 return false;
298 }
299
300 /// "Forget" about the partially-substituted pack template argument,
301 /// when performing an instantiation that must preserve the parameter pack
302 /// use.
303 ///
304 /// This routine is meant to be overridden by the template instantiator.
306 return TemplateArgument();
307 }
308
309 /// "Remember" the partially-substituted pack template argument
310 /// after performing an instantiation that must preserve the parameter pack
311 /// use.
312 ///
313 /// This routine is meant to be overridden by the template instantiator.
315
316 /// Note to the derived class when a function parameter pack is
317 /// being expanded.
319
320 /// Transforms the given type into another type.
321 ///
322 /// By default, this routine transforms a type by creating a
323 /// TypeSourceInfo for it and delegating to the appropriate
324 /// function. This is expensive, but we don't mind, because
325 /// this method is deprecated anyway; all users should be
326 /// switched to storing TypeSourceInfos.
327 ///
328 /// \returns the transformed type.
330
331 /// Transforms the given type-with-location into a new
332 /// type-with-location.
333 ///
334 /// By default, this routine transforms a type by delegating to the
335 /// appropriate TransformXXXType to build a new type. Subclasses
336 /// may override this function (to take over all type
337 /// transformations) or some set of the TransformXXXType functions
338 /// to alter the transformation.
340
341 /// Transform the given type-with-location into a new
342 /// type, collecting location information in the given builder
343 /// as necessary.
344 ///
346
347 /// Transform a type that is permitted to produce a
348 /// DeducedTemplateSpecializationType.
349 ///
350 /// This is used in the (relatively rare) contexts where it is acceptable
351 /// for transformation to produce a class template type with deduced
352 /// template arguments.
353 /// @{
356 /// @}
357
358 /// The reason why the value of a statement is not discarded, if any.
363 };
364
365 /// Transform the given statement.
366 ///
367 /// By default, this routine transforms a statement by delegating to the
368 /// appropriate TransformXXXStmt function to transform a specific kind of
369 /// statement or the TransformExpr() function to transform an expression.
370 /// Subclasses may override this function to transform statements using some
371 /// other mechanism.
372 ///
373 /// \returns the transformed statement.
375
376 /// Transform the given statement.
377 ///
378 /// By default, this routine transforms a statement by delegating to the
379 /// appropriate TransformOMPXXXClause function to transform a specific kind
380 /// of clause. Subclasses may override this function to transform statements
381 /// using some other mechanism.
382 ///
383 /// \returns the transformed OpenMP clause.
385
386 /// Transform the given attribute.
387 ///
388 /// By default, this routine transforms a statement by delegating to the
389 /// appropriate TransformXXXAttr function to transform a specific kind
390 /// of attribute. Subclasses may override this function to transform
391 /// attributed statements/types using some other mechanism.
392 ///
393 /// \returns the transformed attribute
394 const Attr *TransformAttr(const Attr *S);
395
396 // Transform the given statement attribute.
397 //
398 // Delegates to the appropriate TransformXXXAttr function to transform a
399 // specific kind of statement attribute. Unlike the non-statement taking
400 // version of this, this implements all attributes, not just pragmas.
401 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
402 const Attr *A);
403
404 // Transform the specified attribute.
405 //
406 // Subclasses should override the transformation of attributes with a pragma
407 // spelling to transform expressions stored within the attribute.
408 //
409 // \returns the transformed attribute.
410#define ATTR(X) \
411 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
412#include "clang/Basic/AttrList.inc"
413
414 // Transform the specified attribute.
415 //
416 // Subclasses should override the transformation of attributes to do
417 // transformation and checking of statement attributes. By default, this
418 // delegates to the non-statement taking version.
419 //
420 // \returns the transformed attribute.
421#define ATTR(X) \
422 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
423 const X##Attr *A) { \
424 return getDerived().Transform##X##Attr(A); \
425 }
426#include "clang/Basic/AttrList.inc"
427
428 /// Transform the given expression.
429 ///
430 /// By default, this routine transforms an expression by delegating to the
431 /// appropriate TransformXXXExpr function to build a new expression.
432 /// Subclasses may override this function to transform expressions using some
433 /// other mechanism.
434 ///
435 /// \returns the transformed expression.
437
438 /// Transform the given initializer.
439 ///
440 /// By default, this routine transforms an initializer by stripping off the
441 /// semantic nodes added by initialization, then passing the result to
442 /// TransformExpr or TransformExprs.
443 ///
444 /// \returns the transformed initializer.
446
447 /// Transform the given list of expressions.
448 ///
449 /// This routine transforms a list of expressions by invoking
450 /// \c TransformExpr() for each subexpression. However, it also provides
451 /// support for variadic templates by expanding any pack expansions (if the
452 /// derived class permits such expansion) along the way. When pack expansions
453 /// are present, the number of outputs may not equal the number of inputs.
454 ///
455 /// \param Inputs The set of expressions to be transformed.
456 ///
457 /// \param NumInputs The number of expressions in \c Inputs.
458 ///
459 /// \param IsCall If \c true, then this transform is being performed on
460 /// function-call arguments, and any arguments that should be dropped, will
461 /// be.
462 ///
463 /// \param Outputs The transformed input expressions will be added to this
464 /// vector.
465 ///
466 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
467 /// due to transformation.
468 ///
469 /// \returns true if an error occurred, false otherwise.
470 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
472 bool *ArgChanged = nullptr);
473
474 /// Transform the given declaration, which is referenced from a type
475 /// or expression.
476 ///
477 /// By default, acts as the identity function on declarations, unless the
478 /// transformer has had to transform the declaration itself. Subclasses
479 /// may override this function to provide alternate behavior.
481 llvm::DenseMap<Decl *, Decl *>::iterator Known
482 = TransformedLocalDecls.find(D);
483 if (Known != TransformedLocalDecls.end())
484 return Known->second;
485
486 return D;
487 }
488
489 /// Transform the specified condition.
490 ///
491 /// By default, this transforms the variable and expression and rebuilds
492 /// the condition.
494 Expr *Expr,
496
497 /// Transform the attributes associated with the given declaration and
498 /// place them on the new declaration.
499 ///
500 /// By default, this operation does nothing. Subclasses may override this
501 /// behavior to transform attributes.
502 void transformAttrs(Decl *Old, Decl *New) { }
503
504 /// Note that a local declaration has been transformed by this
505 /// transformer.
506 ///
507 /// Local declarations are typically transformed via a call to
508 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
509 /// the transformer itself has to transform the declarations. This routine
510 /// can be overridden by a subclass that keeps track of such mappings.
512 assert(New.size() == 1 &&
513 "must override transformedLocalDecl if performing pack expansion");
514 TransformedLocalDecls[Old] = New.front();
515 }
516
517 /// Transform the definition of the given declaration.
518 ///
519 /// By default, invokes TransformDecl() to transform the declaration.
520 /// Subclasses may override this function to provide alternate behavior.
522 return getDerived().TransformDecl(Loc, D);
523 }
524
525 /// Transform the given declaration, which was the first part of a
526 /// nested-name-specifier in a member access expression.
527 ///
528 /// This specific declaration transformation only applies to the first
529 /// identifier in a nested-name-specifier of a member access expression, e.g.,
530 /// the \c T in \c x->T::member
531 ///
532 /// By default, invokes TransformDecl() to transform the declaration.
533 /// Subclasses may override this function to provide alternate behavior.
535 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
536 }
537
538 /// Transform the set of declarations in an OverloadExpr.
539 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
540 LookupResult &R);
541
542 /// Transform the given nested-name-specifier with source-location
543 /// information.
544 ///
545 /// By default, transforms all of the types and declarations within the
546 /// nested-name-specifier. Subclasses may override this function to provide
547 /// alternate behavior.
550 QualType ObjectType = QualType(),
551 NamedDecl *FirstQualifierInScope = nullptr);
552
553 /// Transform the given declaration name.
554 ///
555 /// By default, transforms the types of conversion function, constructor,
556 /// and destructor names and then (if needed) rebuilds the declaration name.
557 /// Identifiers and selectors are returned unmodified. Subclasses may
558 /// override this function to provide alternate behavior.
561
571
572 /// Transform the given template name.
573 ///
574 /// \param SS The nested-name-specifier that qualifies the template
575 /// name. This nested-name-specifier must already have been transformed.
576 ///
577 /// \param Name The template name to transform.
578 ///
579 /// \param NameLoc The source location of the template name.
580 ///
581 /// \param ObjectType If we're translating a template name within a member
582 /// access expression, this is the type of the object whose member template
583 /// is being referenced.
584 ///
585 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
586 /// also refers to a name within the current (lexical) scope, this is the
587 /// declaration it refers to.
588 ///
589 /// By default, transforms the template name by transforming the declarations
590 /// and nested-name-specifiers that occur within the template name.
591 /// Subclasses may override this function to provide alternate behavior.
594 SourceLocation NameLoc,
595 QualType ObjectType = QualType(),
596 NamedDecl *FirstQualifierInScope = nullptr,
597 bool AllowInjectedClassName = false);
598
599 /// Transform the given template argument.
600 ///
601 /// By default, this operation transforms the type, expression, or
602 /// declaration stored within the template argument and constructs a
603 /// new template argument from the transformed result. Subclasses may
604 /// override this function to provide alternate behavior.
605 ///
606 /// Returns true if there was an error.
608 TemplateArgumentLoc &Output,
609 bool Uneval = false);
610
611 /// Transform the given set of template arguments.
612 ///
613 /// By default, this operation transforms all of the template arguments
614 /// in the input set using \c TransformTemplateArgument(), and appends
615 /// the transformed arguments to the output list.
616 ///
617 /// Note that this overload of \c TransformTemplateArguments() is merely
618 /// a convenience function. Subclasses that wish to override this behavior
619 /// should override the iterator-based member template version.
620 ///
621 /// \param Inputs The set of template arguments to be transformed.
622 ///
623 /// \param NumInputs The number of template arguments in \p Inputs.
624 ///
625 /// \param Outputs The set of transformed template arguments output by this
626 /// routine.
627 ///
628 /// Returns true if an error occurred.
630 unsigned NumInputs,
632 bool Uneval = false) {
633 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
634 Uneval);
635 }
636
637 /// Transform the given set of template arguments.
638 ///
639 /// By default, this operation transforms all of the template arguments
640 /// in the input set using \c TransformTemplateArgument(), and appends
641 /// the transformed arguments to the output list.
642 ///
643 /// \param First An iterator to the first template argument.
644 ///
645 /// \param Last An iterator one step past the last template argument.
646 ///
647 /// \param Outputs The set of transformed template arguments output by this
648 /// routine.
649 ///
650 /// Returns true if an error occurred.
651 template<typename InputIterator>
653 InputIterator Last,
655 bool Uneval = false);
656
657 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
659 TemplateArgumentLoc &ArgLoc);
660
661 /// Fakes up a TypeSourceInfo for a type.
665 }
666
667#define ABSTRACT_TYPELOC(CLASS, PARENT)
668#define TYPELOC(CLASS, PARENT) \
669 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
670#include "clang/AST/TypeLocNodes.def"
671
674 bool SuppressObjCLifetime);
678 bool SuppressObjCLifetime);
679
680 template<typename Fn>
683 CXXRecordDecl *ThisContext,
684 Qualifiers ThisTypeQuals,
686
689 SmallVectorImpl<QualType> &Exceptions,
690 bool &Changed);
691
693
697 TemplateName Template);
698
702 TemplateName Template,
703 CXXScopeSpec &SS);
704
707 NestedNameSpecifierLoc QualifierLoc);
708
709 /// Transforms the parameters of a function type into the
710 /// given vectors.
711 ///
712 /// The result vectors should be kept in sync; null entries in the
713 /// variables vector are acceptable.
714 ///
715 /// LastParamTransformed, if non-null, will be set to the index of the last
716 /// parameter on which transformation was started. In the event of an error,
717 /// this will contain the parameter which failed to instantiate.
718 ///
719 /// Return true on error.
722 const QualType *ParamTypes,
723 const FunctionProtoType::ExtParameterInfo *ParamInfos,
725 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
726
729 const QualType *ParamTypes,
730 const FunctionProtoType::ExtParameterInfo *ParamInfos,
733 return getDerived().TransformFunctionTypeParams(
734 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
735 }
736
737 /// Transforms the parameters of a requires expresison into the given vectors.
738 ///
739 /// The result vectors should be kept in sync; null entries in the
740 /// variables vector are acceptable.
741 ///
742 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
743 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
744 /// which are cases where transformation shouldn't continue.
746 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
752 KWLoc, Params, /*ParamTypes=*/nullptr,
753 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
754 return ExprError();
755
756 return ExprResult{};
757 }
758
759 /// Transforms a single function-type parameter. Return null
760 /// on error.
761 ///
762 /// \param indexAdjustment - A number to add to the parameter's
763 /// scope index; can be negative
765 int indexAdjustment,
766 std::optional<unsigned> NumExpansions,
767 bool ExpectParameterPack);
768
769 /// Transform the body of a lambda-expression.
771 /// Alternative implementation of TransformLambdaBody that skips transforming
772 /// the body.
774
777 return static_cast<CXXRecordDecl::LambdaDependencyKind>(
779 }
780
782
785
788 return TPL;
789 }
790
792
794 bool IsAddressOfOperand,
795 TypeSourceInfo **RecoveryTSI);
796
798 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
799 TypeSourceInfo **RecoveryTSI);
800
802 bool IsAddressOfOperand);
803
805
807
808// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
809// amount of stack usage with clang.
810#define STMT(Node, Parent) \
811 LLVM_ATTRIBUTE_NOINLINE \
812 StmtResult Transform##Node(Node *S);
813#define VALUESTMT(Node, Parent) \
814 LLVM_ATTRIBUTE_NOINLINE \
815 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
816#define EXPR(Node, Parent) \
817 LLVM_ATTRIBUTE_NOINLINE \
818 ExprResult Transform##Node(Node *E);
819#define ABSTRACT_STMT(Stmt)
820#include "clang/AST/StmtNodes.inc"
821
822#define GEN_CLANG_CLAUSE_CLASS
823#define CLAUSE_CLASS(Enum, Str, Class) \
824 LLVM_ATTRIBUTE_NOINLINE \
825 OMPClause *Transform##Class(Class *S);
826#include "llvm/Frontend/OpenMP/OMP.inc"
827
828 /// Build a new qualified type given its unqualified type and type location.
829 ///
830 /// By default, this routine adds type qualifiers only to types that can
831 /// have qualifiers, and silently suppresses those qualifiers that are not
832 /// permitted. Subclasses may override this routine to provide different
833 /// behavior.
835
836 /// Build a new pointer type given its pointee type.
837 ///
838 /// By default, performs semantic analysis when building the pointer type.
839 /// Subclasses may override this routine to provide different behavior.
841
842 /// Build a new block pointer type given its pointee type.
843 ///
844 /// By default, performs semantic analysis when building the block pointer
845 /// type. Subclasses may override this routine to provide different behavior.
847
848 /// Build a new reference type given the type it references.
849 ///
850 /// By default, performs semantic analysis when building the
851 /// reference type. Subclasses may override this routine to provide
852 /// different behavior.
853 ///
854 /// \param LValue whether the type was written with an lvalue sigil
855 /// or an rvalue sigil.
857 bool LValue,
858 SourceLocation Sigil);
859
860 /// Build a new member pointer type given the pointee type and the
861 /// class type it refers into.
862 ///
863 /// By default, performs semantic analysis when building the member pointer
864 /// type. Subclasses may override this routine to provide different behavior.
866 SourceLocation Sigil);
867
869 SourceLocation ProtocolLAngleLoc,
871 ArrayRef<SourceLocation> ProtocolLocs,
872 SourceLocation ProtocolRAngleLoc);
873
874 /// Build an Objective-C object type.
875 ///
876 /// By default, performs semantic analysis when building the object type.
877 /// Subclasses may override this routine to provide different behavior.
880 SourceLocation TypeArgsLAngleLoc,
882 SourceLocation TypeArgsRAngleLoc,
883 SourceLocation ProtocolLAngleLoc,
885 ArrayRef<SourceLocation> ProtocolLocs,
886 SourceLocation ProtocolRAngleLoc);
887
888 /// Build a new Objective-C object pointer type given the pointee type.
889 ///
890 /// By default, directly builds the pointer type, with no additional semantic
891 /// analysis.
894
895 /// Build a new array type given the element type, size
896 /// modifier, size of the array (if known), size expression, and index type
897 /// qualifiers.
898 ///
899 /// By default, performs semantic analysis when building the array type.
900 /// Subclasses may override this routine to provide different behavior.
901 /// Also by default, all of the other Rebuild*Array
903 const llvm::APInt *Size, Expr *SizeExpr,
904 unsigned IndexTypeQuals, SourceRange BracketsRange);
905
906 /// Build a new constant array type given the element type, size
907 /// modifier, (known) size of the array, and index type qualifiers.
908 ///
909 /// By default, performs semantic analysis when building the array type.
910 /// Subclasses may override this routine to provide different behavior.
912 ArraySizeModifier SizeMod,
913 const llvm::APInt &Size, Expr *SizeExpr,
914 unsigned IndexTypeQuals,
915 SourceRange BracketsRange);
916
917 /// Build a new incomplete array type given the element type, size
918 /// modifier, and index type qualifiers.
919 ///
920 /// By default, performs semantic analysis when building the array type.
921 /// Subclasses may override this routine to provide different behavior.
923 ArraySizeModifier SizeMod,
924 unsigned IndexTypeQuals,
925 SourceRange BracketsRange);
926
927 /// Build a new variable-length array type given the element type,
928 /// size modifier, size expression, and index type qualifiers.
929 ///
930 /// By default, performs semantic analysis when building the array type.
931 /// Subclasses may override this routine to provide different behavior.
933 ArraySizeModifier SizeMod, Expr *SizeExpr,
934 unsigned IndexTypeQuals,
935 SourceRange BracketsRange);
936
937 /// Build a new dependent-sized array type given the element type,
938 /// size modifier, size expression, and index type qualifiers.
939 ///
940 /// By default, performs semantic analysis when building the array type.
941 /// Subclasses may override this routine to provide different behavior.
943 ArraySizeModifier SizeMod,
944 Expr *SizeExpr,
945 unsigned IndexTypeQuals,
946 SourceRange BracketsRange);
947
948 /// Build a new vector type given the element type and
949 /// number of elements.
950 ///
951 /// By default, performs semantic analysis when building the vector type.
952 /// Subclasses may override this routine to provide different behavior.
953 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
954 VectorKind VecKind);
955
956 /// Build a new potentially dependently-sized extended vector type
957 /// given the element type and number of elements.
958 ///
959 /// By default, performs semantic analysis when building the vector type.
960 /// Subclasses may override this routine to provide different behavior.
962 SourceLocation AttributeLoc, VectorKind);
963
964 /// Build a new extended vector type given the element type and
965 /// number of elements.
966 ///
967 /// By default, performs semantic analysis when building the vector type.
968 /// Subclasses may override this routine to provide different behavior.
969 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
970 SourceLocation AttributeLoc);
971
972 /// Build a new potentially dependently-sized extended vector type
973 /// given the element type and number of elements.
974 ///
975 /// By default, performs semantic analysis when building the vector type.
976 /// Subclasses may override this routine to provide different behavior.
978 Expr *SizeExpr,
979 SourceLocation AttributeLoc);
980
981 /// Build a new matrix type given the element type and dimensions.
982 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
983 unsigned NumColumns);
984
985 /// Build a new matrix type given the type and dependently-defined
986 /// dimensions.
988 Expr *ColumnExpr,
989 SourceLocation AttributeLoc);
990
991 /// Build a new DependentAddressSpaceType or return the pointee
992 /// type variable with the correct address space (retrieved from
993 /// AddrSpaceExpr) applied to it. The former will be returned in cases
994 /// where the address space remains dependent.
995 ///
996 /// By default, performs semantic analysis when building the type with address
997 /// space applied. Subclasses may override this routine to provide different
998 /// behavior.
1000 Expr *AddrSpaceExpr,
1001 SourceLocation AttributeLoc);
1002
1003 /// Build a new function type.
1004 ///
1005 /// By default, performs semantic analysis when building the function type.
1006 /// Subclasses may override this routine to provide different behavior.
1008 MutableArrayRef<QualType> ParamTypes,
1010
1011 /// Build a new unprototyped function type.
1013
1014 /// Rebuild an unresolved typename type, given the decl that
1015 /// the UnresolvedUsingTypenameDecl was transformed to.
1017
1018 /// Build a new type found via an alias.
1020 return SemaRef.Context.getUsingType(Found, Underlying);
1021 }
1022
1023 /// Build a new typedef type.
1025 return SemaRef.Context.getTypeDeclType(Typedef);
1026 }
1027
1028 /// Build a new MacroDefined type.
1030 const IdentifierInfo *MacroII) {
1031 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1032 }
1033
1034 /// Build a new class/struct/union type.
1037 }
1038
1039 /// Build a new Enum type.
1042 }
1043
1044 /// Build a new typeof(expr) type.
1045 ///
1046 /// By default, performs semantic analysis when building the typeof type.
1047 /// Subclasses may override this routine to provide different behavior.
1049 TypeOfKind Kind);
1050
1051 /// Build a new typeof(type) type.
1052 ///
1053 /// By default, builds a new TypeOfType with the given underlying type.
1055
1056 /// Build a new unary transform type.
1060
1061 /// Build a new C++11 decltype type.
1062 ///
1063 /// By default, performs semantic analysis when building the decltype type.
1064 /// Subclasses may override this routine to provide different behavior.
1066
1069 SourceLocation EllipsisLoc,
1070 bool FullySubstituted,
1071 ArrayRef<QualType> Expansions = {});
1072
1073 /// Build a new C++11 auto type.
1074 ///
1075 /// By default, builds a new AutoType with the given deduced type.
1077 ConceptDecl *TypeConstraintConcept,
1078 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1079 // Note, IsDependent is always false here: we implicitly convert an 'auto'
1080 // which has been deduced to a dependent type into an undeduced 'auto', so
1081 // that we'll retry deduction after the transformation.
1082 return SemaRef.Context.getAutoType(Deduced, Keyword,
1083 /*IsDependent*/ false, /*IsPack=*/false,
1084 TypeConstraintConcept,
1085 TypeConstraintArgs);
1086 }
1087
1088 /// By default, builds a new DeducedTemplateSpecializationType with the given
1089 /// deduced type.
1091 QualType Deduced) {
1093 Template, Deduced, /*IsDependent*/ false);
1094 }
1095
1096 /// Build a new template specialization type.
1097 ///
1098 /// By default, performs semantic analysis when building the template
1099 /// specialization type. Subclasses may override this routine to provide
1100 /// different behavior.
1102 SourceLocation TemplateLoc,
1104
1105 /// Build a new parenthesized type.
1106 ///
1107 /// By default, builds a new ParenType type from the inner type.
1108 /// Subclasses may override this routine to provide different behavior.
1110 return SemaRef.BuildParenType(InnerType);
1111 }
1112
1113 /// Build a new qualified name type.
1114 ///
1115 /// By default, builds a new ElaboratedType type from the keyword,
1116 /// the nested-name-specifier and the named type.
1117 /// Subclasses may override this routine to provide different behavior.
1119 ElaboratedTypeKeyword Keyword,
1120 NestedNameSpecifierLoc QualifierLoc,
1121 QualType Named) {
1122 return SemaRef.Context.getElaboratedType(Keyword,
1123 QualifierLoc.getNestedNameSpecifier(),
1124 Named);
1125 }
1126
1127 /// Build a new typename type that refers to a template-id.
1128 ///
1129 /// By default, builds a new DependentNameType type from the
1130 /// nested-name-specifier and the given type. Subclasses may override
1131 /// this routine to provide different behavior.
1133 ElaboratedTypeKeyword Keyword,
1134 NestedNameSpecifierLoc QualifierLoc,
1135 SourceLocation TemplateKWLoc,
1136 const IdentifierInfo *Name,
1137 SourceLocation NameLoc,
1139 bool AllowInjectedClassName) {
1140 // Rebuild the template name.
1141 // TODO: avoid TemplateName abstraction
1142 CXXScopeSpec SS;
1143 SS.Adopt(QualifierLoc);
1144 TemplateName InstName = getDerived().RebuildTemplateName(
1145 SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr,
1146 AllowInjectedClassName);
1147
1148 if (InstName.isNull())
1149 return QualType();
1150
1151 // If it's still dependent, make a dependent specialization.
1152 if (InstName.getAsDependentTemplateName())
1154 Keyword, QualifierLoc.getNestedNameSpecifier(), Name,
1155 Args.arguments());
1156
1157 // Otherwise, make an elaborated type wrapping a non-dependent
1158 // specialization.
1159 QualType T =
1160 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
1161 if (T.isNull())
1162 return QualType();
1164 Keyword, QualifierLoc.getNestedNameSpecifier(), T);
1165 }
1166
1167 /// Build a new typename type that refers to an identifier.
1168 ///
1169 /// By default, performs semantic analysis when building the typename type
1170 /// (or elaborated type). Subclasses may override this routine to provide
1171 /// different behavior.
1173 SourceLocation KeywordLoc,
1174 NestedNameSpecifierLoc QualifierLoc,
1175 const IdentifierInfo *Id,
1176 SourceLocation IdLoc,
1177 bool DeducedTSTContext) {
1178 CXXScopeSpec SS;
1179 SS.Adopt(QualifierLoc);
1180
1181 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
1182 // If the name is still dependent, just build a new dependent name type.
1183 if (!SemaRef.computeDeclContext(SS))
1184 return SemaRef.Context.getDependentNameType(Keyword,
1185 QualifierLoc.getNestedNameSpecifier(),
1186 Id);
1187 }
1188
1189 if (Keyword == ElaboratedTypeKeyword::None ||
1191 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1192 *Id, IdLoc, DeducedTSTContext);
1193 }
1194
1196
1197 // We had a dependent elaborated-type-specifier that has been transformed
1198 // into a non-dependent elaborated-type-specifier. Find the tag we're
1199 // referring to.
1201 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1202 if (!DC)
1203 return QualType();
1204
1206 return QualType();
1207
1208 TagDecl *Tag = nullptr;
1210 switch (Result.getResultKind()) {
1213 break;
1214
1216 Tag = Result.getAsSingle<TagDecl>();
1217 break;
1218
1221 llvm_unreachable("Tag lookup cannot find non-tags");
1222
1224 // Let the LookupResult structure handle ambiguities.
1225 return QualType();
1226 }
1227
1228 if (!Tag) {
1229 // Check where the name exists but isn't a tag type and use that to emit
1230 // better diagnostics.
1233 switch (Result.getResultKind()) {
1237 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1238 Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1239 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1240 << SomeDecl << NTK << llvm::to_underlying(Kind);
1241 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1242 break;
1243 }
1244 default:
1245 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1246 << llvm::to_underlying(Kind) << Id << DC
1247 << QualifierLoc.getSourceRange();
1248 break;
1249 }
1250 return QualType();
1251 }
1252
1253 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1254 IdLoc, Id)) {
1255 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1256 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1257 return QualType();
1258 }
1259
1260 // Build the elaborated-type-specifier type.
1262 return SemaRef.Context.getElaboratedType(Keyword,
1263 QualifierLoc.getNestedNameSpecifier(),
1264 T);
1265 }
1266
1267 /// Build a new pack expansion type.
1268 ///
1269 /// By default, builds a new PackExpansionType type from the given pattern.
1270 /// Subclasses may override this routine to provide different behavior.
1272 SourceLocation EllipsisLoc,
1273 std::optional<unsigned> NumExpansions) {
1274 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1275 NumExpansions);
1276 }
1277
1278 /// Build a new atomic type given its value type.
1279 ///
1280 /// By default, performs semantic analysis when building the atomic type.
1281 /// Subclasses may override this routine to provide different behavior.
1283
1284 /// Build a new pipe type given its value type.
1286 bool isReadPipe);
1287
1288 /// Build a bit-precise int given its value type.
1289 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1291
1292 /// Build a dependent bit-precise int given its value type.
1293 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1295
1296 /// Build a new template name given a nested name specifier, a flag
1297 /// indicating whether the "template" keyword was provided, and the template
1298 /// that the template name refers to.
1299 ///
1300 /// By default, builds the new template name directly. Subclasses may override
1301 /// this routine to provide different behavior.
1303 bool TemplateKW,
1304 TemplateDecl *Template);
1305
1306 /// Build a new template name given a nested name specifier and the
1307 /// name that is referred to as a template.
1308 ///
1309 /// By default, performs semantic analysis to determine whether the name can
1310 /// be resolved to a specific template, then builds the appropriate kind of
1311 /// template name. Subclasses may override this routine to provide different
1312 /// behavior.
1314 SourceLocation TemplateKWLoc,
1315 const IdentifierInfo &Name,
1316 SourceLocation NameLoc, QualType ObjectType,
1317 NamedDecl *FirstQualifierInScope,
1318 bool AllowInjectedClassName);
1319
1320 /// Build a new template name given a nested name specifier and the
1321 /// overloaded operator name that is referred to as a template.
1322 ///
1323 /// By default, performs semantic analysis to determine whether the name can
1324 /// be resolved to a specific template, then builds the appropriate kind of
1325 /// template name. Subclasses may override this routine to provide different
1326 /// behavior.
1328 SourceLocation TemplateKWLoc,
1329 OverloadedOperatorKind Operator,
1330 SourceLocation NameLoc, QualType ObjectType,
1331 bool AllowInjectedClassName);
1332
1333 /// Build a new template name given a template template parameter pack
1334 /// and the
1335 ///
1336 /// By default, performs semantic analysis to determine whether the name can
1337 /// be resolved to a specific template, then builds the appropriate kind of
1338 /// template name. Subclasses may override this routine to provide different
1339 /// behavior.
1341 Decl *AssociatedDecl, unsigned Index,
1342 bool Final) {
1344 ArgPack, AssociatedDecl, Index, Final);
1345 }
1346
1347 /// Build a new compound statement.
1348 ///
1349 /// By default, performs semantic analysis to build the new statement.
1350 /// Subclasses may override this routine to provide different behavior.
1352 MultiStmtArg Statements,
1353 SourceLocation RBraceLoc,
1354 bool IsStmtExpr) {
1355 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1356 IsStmtExpr);
1357 }
1358
1359 /// Build a new case statement.
1360 ///
1361 /// By default, performs semantic analysis to build the new statement.
1362 /// Subclasses may override this routine to provide different behavior.
1364 Expr *LHS,
1365 SourceLocation EllipsisLoc,
1366 Expr *RHS,
1367 SourceLocation ColonLoc) {
1368 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1369 ColonLoc);
1370 }
1371
1372 /// Attach the body to a new case statement.
1373 ///
1374 /// By default, performs semantic analysis to build the new statement.
1375 /// Subclasses may override this routine to provide different behavior.
1377 getSema().ActOnCaseStmtBody(S, Body);
1378 return S;
1379 }
1380
1381 /// Build a new default statement.
1382 ///
1383 /// By default, performs semantic analysis to build the new statement.
1384 /// Subclasses may override this routine to provide different behavior.
1386 SourceLocation ColonLoc,
1387 Stmt *SubStmt) {
1388 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1389 /*CurScope=*/nullptr);
1390 }
1391
1392 /// Build a new label statement.
1393 ///
1394 /// By default, performs semantic analysis to build the new statement.
1395 /// Subclasses may override this routine to provide different behavior.
1397 SourceLocation ColonLoc, Stmt *SubStmt) {
1398 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1399 }
1400
1401 /// Build a new attributed statement.
1402 ///
1403 /// By default, performs semantic analysis to build the new statement.
1404 /// Subclasses may override this routine to provide different behavior.
1407 Stmt *SubStmt) {
1409 return StmtError();
1410 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1411 }
1412
1413 /// Build a new "if" statement.
1414 ///
1415 /// By default, performs semantic analysis to build the new statement.
1416 /// Subclasses may override this routine to provide different behavior.
1418 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1419 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1420 SourceLocation ElseLoc, Stmt *Else) {
1421 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1422 Then, ElseLoc, Else);
1423 }
1424
1425 /// Start building a new switch statement.
1426 ///
1427 /// By default, performs semantic analysis to build the new statement.
1428 /// Subclasses may override this routine to provide different behavior.
1430 SourceLocation LParenLoc, Stmt *Init,
1432 SourceLocation RParenLoc) {
1433 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1434 RParenLoc);
1435 }
1436
1437 /// Attach the body to the switch statement.
1438 ///
1439 /// By default, performs semantic analysis to build the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
1442 Stmt *Switch, Stmt *Body) {
1443 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1444 }
1445
1446 /// Build a new while statement.
1447 ///
1448 /// By default, performs semantic analysis to build the new statement.
1449 /// Subclasses may override this routine to provide different behavior.
1452 SourceLocation RParenLoc, Stmt *Body) {
1453 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1454 }
1455
1456 /// Build a new do-while statement.
1457 ///
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
1461 SourceLocation WhileLoc, SourceLocation LParenLoc,
1462 Expr *Cond, SourceLocation RParenLoc) {
1463 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1464 Cond, RParenLoc);
1465 }
1466
1467 /// Build a new for statement.
1468 ///
1469 /// By default, performs semantic analysis to build the new statement.
1470 /// Subclasses may override this routine to provide different behavior.
1473 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1474 Stmt *Body) {
1475 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1476 Inc, RParenLoc, Body);
1477 }
1478
1479 /// Build a new goto statement.
1480 ///
1481 /// By default, performs semantic analysis to build the new statement.
1482 /// Subclasses may override this routine to provide different behavior.
1484 LabelDecl *Label) {
1485 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1486 }
1487
1488 /// Build a new indirect goto statement.
1489 ///
1490 /// By default, performs semantic analysis to build the new statement.
1491 /// Subclasses may override this routine to provide different behavior.
1493 SourceLocation StarLoc,
1494 Expr *Target) {
1495 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1496 }
1497
1498 /// Build a new return statement.
1499 ///
1500 /// By default, performs semantic analysis to build the new statement.
1501 /// Subclasses may override this routine to provide different behavior.
1503 return getSema().BuildReturnStmt(ReturnLoc, Result);
1504 }
1505
1506 /// Build a new declaration statement.
1507 ///
1508 /// By default, performs semantic analysis to build the new statement.
1509 /// Subclasses may override this routine to provide different behavior.
1511 SourceLocation StartLoc, SourceLocation EndLoc) {
1513 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1514 }
1515
1516 /// Build a new inline asm statement.
1517 ///
1518 /// By default, performs semantic analysis to build the new statement.
1519 /// Subclasses may override this routine to provide different behavior.
1521 bool IsVolatile, unsigned NumOutputs,
1522 unsigned NumInputs, IdentifierInfo **Names,
1523 MultiExprArg Constraints, MultiExprArg Exprs,
1524 Expr *AsmString, MultiExprArg Clobbers,
1525 unsigned NumLabels,
1526 SourceLocation RParenLoc) {
1527 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1528 NumInputs, Names, Constraints, Exprs,
1529 AsmString, Clobbers, NumLabels, RParenLoc);
1530 }
1531
1532 /// Build a new MS style inline asm statement.
1533 ///
1534 /// By default, performs semantic analysis to build the new statement.
1535 /// Subclasses may override this routine to provide different behavior.
1537 ArrayRef<Token> AsmToks,
1538 StringRef AsmString,
1539 unsigned NumOutputs, unsigned NumInputs,
1540 ArrayRef<StringRef> Constraints,
1541 ArrayRef<StringRef> Clobbers,
1542 ArrayRef<Expr*> Exprs,
1543 SourceLocation EndLoc) {
1544 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1545 NumOutputs, NumInputs,
1546 Constraints, Clobbers, Exprs, EndLoc);
1547 }
1548
1549 /// Build a new co_return statement.
1550 ///
1551 /// By default, performs semantic analysis to build the new statement.
1552 /// Subclasses may override this routine to provide different behavior.
1554 bool IsImplicit) {
1555 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1556 }
1557
1558 /// Build a new co_await expression.
1559 ///
1560 /// By default, performs semantic analysis to build the new expression.
1561 /// Subclasses may override this routine to provide different behavior.
1563 UnresolvedLookupExpr *OpCoawaitLookup,
1564 bool IsImplicit) {
1565 // This function rebuilds a coawait-expr given its operator.
1566 // For an explicit coawait-expr, the rebuild involves the full set
1567 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1568 // including calling await_transform().
1569 // For an implicit coawait-expr, we need to rebuild the "operator
1570 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1571 // This mirrors how the implicit CoawaitExpr is originally created
1572 // in Sema::ActOnCoroutineBodyStart().
1573 if (IsImplicit) {
1575 CoawaitLoc, Operand, OpCoawaitLookup);
1576 if (Suspend.isInvalid())
1577 return ExprError();
1578 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1579 Suspend.get(), true);
1580 }
1581
1582 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1583 OpCoawaitLookup);
1584 }
1585
1586 /// Build a new co_await expression.
1587 ///
1588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
1591 Expr *Result,
1592 UnresolvedLookupExpr *Lookup) {
1593 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1594 }
1595
1596 /// Build a new co_yield expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
1601 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1602 }
1603
1605 return getSema().BuildCoroutineBodyStmt(Args);
1606 }
1607
1608 /// Build a new Objective-C \@try statement.
1609 ///
1610 /// By default, performs semantic analysis to build the new statement.
1611 /// Subclasses may override this routine to provide different behavior.
1613 Stmt *TryBody,
1614 MultiStmtArg CatchStmts,
1615 Stmt *Finally) {
1616 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1617 Finally);
1618 }
1619
1620 /// Rebuild an Objective-C exception declaration.
1621 ///
1622 /// By default, performs semantic analysis to build the new declaration.
1623 /// Subclasses may override this routine to provide different behavior.
1625 TypeSourceInfo *TInfo, QualType T) {
1627 TInfo, T, ExceptionDecl->getInnerLocStart(),
1628 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1629 }
1630
1631 /// Build a new Objective-C \@catch statement.
1632 ///
1633 /// By default, performs semantic analysis to build the new statement.
1634 /// Subclasses may override this routine to provide different behavior.
1636 SourceLocation RParenLoc,
1637 VarDecl *Var,
1638 Stmt *Body) {
1639 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1640 }
1641
1642 /// Build a new Objective-C \@finally statement.
1643 ///
1644 /// By default, performs semantic analysis to build the new statement.
1645 /// Subclasses may override this routine to provide different behavior.
1647 Stmt *Body) {
1648 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1649 }
1650
1651 /// Build a new Objective-C \@throw statement.
1652 ///
1653 /// By default, performs semantic analysis to build the new statement.
1654 /// Subclasses may override this routine to provide different behavior.
1656 Expr *Operand) {
1657 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1658 }
1659
1660 /// Build a new OpenMP Canonical loop.
1661 ///
1662 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1663 /// OMPCanonicalLoop.
1665 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1666 }
1667
1668 /// Build a new OpenMP executable directive.
1669 ///
1670 /// By default, performs semantic analysis to build the new statement.
1671 /// Subclasses may override this routine to provide different behavior.
1673 DeclarationNameInfo DirName,
1674 OpenMPDirectiveKind CancelRegion,
1675 ArrayRef<OMPClause *> Clauses,
1676 Stmt *AStmt, SourceLocation StartLoc,
1677 SourceLocation EndLoc) {
1678
1680 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1681 }
1682
1683 /// Build a new OpenMP informational directive.
1685 DeclarationNameInfo DirName,
1686 ArrayRef<OMPClause *> Clauses,
1687 Stmt *AStmt,
1688 SourceLocation StartLoc,
1689 SourceLocation EndLoc) {
1690
1692 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1693 }
1694
1695 /// Build a new OpenMP 'if' clause.
1696 ///
1697 /// By default, performs semantic analysis to build the new OpenMP clause.
1698 /// Subclasses may override this routine to provide different behavior.
1700 Expr *Condition, SourceLocation StartLoc,
1701 SourceLocation LParenLoc,
1702 SourceLocation NameModifierLoc,
1703 SourceLocation ColonLoc,
1704 SourceLocation EndLoc) {
1706 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1707 EndLoc);
1708 }
1709
1710 /// Build a new OpenMP 'final' clause.
1711 ///
1712 /// By default, performs semantic analysis to build the new OpenMP clause.
1713 /// Subclasses may override this routine to provide different behavior.
1715 SourceLocation LParenLoc,
1716 SourceLocation EndLoc) {
1717 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1718 LParenLoc, EndLoc);
1719 }
1720
1721 /// Build a new OpenMP 'num_threads' clause.
1722 ///
1723 /// By default, performs semantic analysis to build the new OpenMP clause.
1724 /// Subclasses may override this routine to provide different behavior.
1726 SourceLocation StartLoc,
1727 SourceLocation LParenLoc,
1728 SourceLocation EndLoc) {
1729 return getSema().OpenMP().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1730 LParenLoc, EndLoc);
1731 }
1732
1733 /// Build a new OpenMP 'safelen' clause.
1734 ///
1735 /// By default, performs semantic analysis to build the new OpenMP clause.
1736 /// Subclasses may override this routine to provide different behavior.
1738 SourceLocation LParenLoc,
1739 SourceLocation EndLoc) {
1740 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1741 EndLoc);
1742 }
1743
1744 /// Build a new OpenMP 'simdlen' clause.
1745 ///
1746 /// By default, performs semantic analysis to build the new OpenMP clause.
1747 /// Subclasses may override this routine to provide different behavior.
1749 SourceLocation LParenLoc,
1750 SourceLocation EndLoc) {
1751 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1752 EndLoc);
1753 }
1754
1756 SourceLocation StartLoc,
1757 SourceLocation LParenLoc,
1758 SourceLocation EndLoc) {
1759 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1760 EndLoc);
1761 }
1762
1763 /// Build a new OpenMP 'permutation' clause.
1765 SourceLocation StartLoc,
1766 SourceLocation LParenLoc,
1767 SourceLocation EndLoc) {
1768 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1769 LParenLoc, EndLoc);
1770 }
1771
1772 /// Build a new OpenMP 'full' clause.
1774 SourceLocation EndLoc) {
1775 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1776 }
1777
1778 /// Build a new OpenMP 'partial' clause.
1780 SourceLocation LParenLoc,
1781 SourceLocation EndLoc) {
1782 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1783 LParenLoc, EndLoc);
1784 }
1785
1786 /// Build a new OpenMP 'allocator' clause.
1787 ///
1788 /// By default, performs semantic analysis to build the new OpenMP clause.
1789 /// Subclasses may override this routine to provide different behavior.
1791 SourceLocation LParenLoc,
1792 SourceLocation EndLoc) {
1793 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1794 EndLoc);
1795 }
1796
1797 /// Build a new OpenMP 'collapse' clause.
1798 ///
1799 /// By default, performs semantic analysis to build the new OpenMP clause.
1800 /// Subclasses may override this routine to provide different behavior.
1802 SourceLocation LParenLoc,
1803 SourceLocation EndLoc) {
1804 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1805 LParenLoc, EndLoc);
1806 }
1807
1808 /// Build a new OpenMP 'default' clause.
1809 ///
1810 /// By default, performs semantic analysis to build the new OpenMP clause.
1811 /// Subclasses may override this routine to provide different behavior.
1813 SourceLocation StartLoc,
1814 SourceLocation LParenLoc,
1815 SourceLocation EndLoc) {
1817 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1818 }
1819
1820 /// Build a new OpenMP 'proc_bind' clause.
1821 ///
1822 /// By default, performs semantic analysis to build the new OpenMP clause.
1823 /// Subclasses may override this routine to provide different behavior.
1825 SourceLocation KindKwLoc,
1826 SourceLocation StartLoc,
1827 SourceLocation LParenLoc,
1828 SourceLocation EndLoc) {
1830 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1831 }
1832
1833 /// Build a new OpenMP 'schedule' clause.
1834 ///
1835 /// By default, performs semantic analysis to build the new OpenMP clause.
1836 /// Subclasses may override this routine to provide different behavior.
1839 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1840 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1841 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1843 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1844 CommaLoc, EndLoc);
1845 }
1846
1847 /// Build a new OpenMP 'ordered' clause.
1848 ///
1849 /// By default, performs semantic analysis to build the new OpenMP clause.
1850 /// Subclasses may override this routine to provide different behavior.
1852 SourceLocation EndLoc,
1853 SourceLocation LParenLoc, Expr *Num) {
1854 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1855 LParenLoc, Num);
1856 }
1857
1858 /// Build a new OpenMP 'private' clause.
1859 ///
1860 /// By default, performs semantic analysis to build the new OpenMP clause.
1861 /// Subclasses may override this routine to provide different behavior.
1863 SourceLocation StartLoc,
1864 SourceLocation LParenLoc,
1865 SourceLocation EndLoc) {
1866 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1867 LParenLoc, EndLoc);
1868 }
1869
1870 /// Build a new OpenMP 'firstprivate' clause.
1871 ///
1872 /// By default, performs semantic analysis to build the new OpenMP clause.
1873 /// Subclasses may override this routine to provide different behavior.
1875 SourceLocation StartLoc,
1876 SourceLocation LParenLoc,
1877 SourceLocation EndLoc) {
1878 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1879 LParenLoc, EndLoc);
1880 }
1881
1882 /// Build a new OpenMP 'lastprivate' clause.
1883 ///
1884 /// By default, performs semantic analysis to build the new OpenMP clause.
1885 /// Subclasses may override this routine to provide different behavior.
1888 SourceLocation LPKindLoc,
1889 SourceLocation ColonLoc,
1890 SourceLocation StartLoc,
1891 SourceLocation LParenLoc,
1892 SourceLocation EndLoc) {
1894 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1895 }
1896
1897 /// Build a new OpenMP 'shared' clause.
1898 ///
1899 /// By default, performs semantic analysis to build the new OpenMP clause.
1900 /// Subclasses may override this routine to provide different behavior.
1902 SourceLocation StartLoc,
1903 SourceLocation LParenLoc,
1904 SourceLocation EndLoc) {
1905 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1906 LParenLoc, EndLoc);
1907 }
1908
1909 /// Build a new OpenMP 'reduction' clause.
1910 ///
1911 /// By default, performs semantic analysis to build the new statement.
1912 /// Subclasses may override this routine to provide different behavior.
1915 SourceLocation StartLoc, SourceLocation LParenLoc,
1916 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1917 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1918 const DeclarationNameInfo &ReductionId,
1919 ArrayRef<Expr *> UnresolvedReductions) {
1921 VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc,
1922 ReductionIdScopeSpec, ReductionId, UnresolvedReductions);
1923 }
1924
1925 /// Build a new OpenMP 'task_reduction' clause.
1926 ///
1927 /// By default, performs semantic analysis to build the new statement.
1928 /// Subclasses may override this routine to provide different behavior.
1930 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1931 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1932 CXXScopeSpec &ReductionIdScopeSpec,
1933 const DeclarationNameInfo &ReductionId,
1934 ArrayRef<Expr *> UnresolvedReductions) {
1936 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1937 ReductionId, UnresolvedReductions);
1938 }
1939
1940 /// Build a new OpenMP 'in_reduction' clause.
1941 ///
1942 /// By default, performs semantic analysis to build the new statement.
1943 /// Subclasses may override this routine to provide different behavior.
1944 OMPClause *
1946 SourceLocation LParenLoc, SourceLocation ColonLoc,
1947 SourceLocation EndLoc,
1948 CXXScopeSpec &ReductionIdScopeSpec,
1949 const DeclarationNameInfo &ReductionId,
1950 ArrayRef<Expr *> UnresolvedReductions) {
1952 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1953 ReductionId, UnresolvedReductions);
1954 }
1955
1956 /// Build a new OpenMP 'linear' clause.
1957 ///
1958 /// By default, performs semantic analysis to build the new OpenMP clause.
1959 /// Subclasses may override this routine to provide different behavior.
1961 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
1962 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
1963 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1964 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
1966 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
1967 StepModifierLoc, EndLoc);
1968 }
1969
1970 /// Build a new OpenMP 'aligned' clause.
1971 ///
1972 /// By default, performs semantic analysis to build the new OpenMP clause.
1973 /// Subclasses may override this routine to provide different behavior.
1975 SourceLocation StartLoc,
1976 SourceLocation LParenLoc,
1977 SourceLocation ColonLoc,
1978 SourceLocation EndLoc) {
1980 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
1981 }
1982
1983 /// Build a new OpenMP 'copyin' clause.
1984 ///
1985 /// By default, performs semantic analysis to build the new OpenMP clause.
1986 /// Subclasses may override this routine to provide different behavior.
1988 SourceLocation StartLoc,
1989 SourceLocation LParenLoc,
1990 SourceLocation EndLoc) {
1991 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
1992 LParenLoc, EndLoc);
1993 }
1994
1995 /// Build a new OpenMP 'copyprivate' clause.
1996 ///
1997 /// By default, performs semantic analysis to build the new OpenMP clause.
1998 /// Subclasses may override this routine to provide different behavior.
2000 SourceLocation StartLoc,
2001 SourceLocation LParenLoc,
2002 SourceLocation EndLoc) {
2003 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2004 LParenLoc, EndLoc);
2005 }
2006
2007 /// Build a new OpenMP 'flush' pseudo clause.
2008 ///
2009 /// By default, performs semantic analysis to build the new OpenMP clause.
2010 /// Subclasses may override this routine to provide different behavior.
2012 SourceLocation StartLoc,
2013 SourceLocation LParenLoc,
2014 SourceLocation EndLoc) {
2015 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2016 LParenLoc, EndLoc);
2017 }
2018
2019 /// Build a new OpenMP 'depobj' pseudo clause.
2020 ///
2021 /// By default, performs semantic analysis to build the new OpenMP clause.
2022 /// Subclasses may override this routine to provide different behavior.
2024 SourceLocation LParenLoc,
2025 SourceLocation EndLoc) {
2026 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2027 LParenLoc, EndLoc);
2028 }
2029
2030 /// Build a new OpenMP 'depend' pseudo clause.
2031 ///
2032 /// By default, performs semantic analysis to build the new OpenMP clause.
2033 /// Subclasses may override this routine to provide different behavior.
2035 Expr *DepModifier, ArrayRef<Expr *> VarList,
2036 SourceLocation StartLoc,
2037 SourceLocation LParenLoc,
2038 SourceLocation EndLoc) {
2040 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2041 }
2042
2043 /// Build a new OpenMP 'device' clause.
2044 ///
2045 /// By default, performs semantic analysis to build the new statement.
2046 /// Subclasses may override this routine to provide different behavior.
2048 Expr *Device, SourceLocation StartLoc,
2049 SourceLocation LParenLoc,
2050 SourceLocation ModifierLoc,
2051 SourceLocation EndLoc) {
2053 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2054 }
2055
2056 /// Build a new OpenMP 'map' clause.
2057 ///
2058 /// By default, performs semantic analysis to build the new OpenMP clause.
2059 /// Subclasses may override this routine to provide different behavior.
2061 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2062 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2063 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2064 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2065 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2066 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2068 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2069 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2070 ColonLoc, VarList, Locs,
2071 /*NoDiagnose=*/false, UnresolvedMappers);
2072 }
2073
2074 /// Build a new OpenMP 'allocate' clause.
2075 ///
2076 /// By default, performs semantic analysis to build the new OpenMP clause.
2077 /// Subclasses may override this routine to provide different behavior.
2080 ArrayRef<Expr *> VarList,
2081 SourceLocation StartLoc,
2082 SourceLocation LParenLoc,
2083 SourceLocation ColonLoc,
2084 SourceLocation EndLoc) {
2086 Allocate, ACModifier, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2087 }
2088
2089 /// Build a new OpenMP 'num_teams' clause.
2090 ///
2091 /// By default, performs semantic analysis to build the new statement.
2092 /// Subclasses may override this routine to provide different behavior.
2094 SourceLocation StartLoc,
2095 SourceLocation LParenLoc,
2096 SourceLocation EndLoc) {
2097 return getSema().OpenMP().ActOnOpenMPNumTeamsClause(VarList, StartLoc,
2098 LParenLoc, EndLoc);
2099 }
2100
2101 /// Build a new OpenMP 'thread_limit' clause.
2102 ///
2103 /// By default, performs semantic analysis to build the new statement.
2104 /// Subclasses may override this routine to provide different behavior.
2106 SourceLocation StartLoc,
2107 SourceLocation LParenLoc,
2108 SourceLocation EndLoc) {
2109 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2110 LParenLoc, EndLoc);
2111 }
2112
2113 /// Build a new OpenMP 'priority' clause.
2114 ///
2115 /// By default, performs semantic analysis to build the new statement.
2116 /// Subclasses may override this routine to provide different behavior.
2118 SourceLocation LParenLoc,
2119 SourceLocation EndLoc) {
2120 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2121 LParenLoc, EndLoc);
2122 }
2123
2124 /// Build a new OpenMP 'grainsize' clause.
2125 ///
2126 /// By default, performs semantic analysis to build the new statement.
2127 /// Subclasses may override this routine to provide different behavior.
2129 Expr *Device, SourceLocation StartLoc,
2130 SourceLocation LParenLoc,
2131 SourceLocation ModifierLoc,
2132 SourceLocation EndLoc) {
2134 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2135 }
2136
2137 /// Build a new OpenMP 'num_tasks' clause.
2138 ///
2139 /// By default, performs semantic analysis to build the new statement.
2140 /// Subclasses may override this routine to provide different behavior.
2142 Expr *NumTasks, SourceLocation StartLoc,
2143 SourceLocation LParenLoc,
2144 SourceLocation ModifierLoc,
2145 SourceLocation EndLoc) {
2147 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2148 }
2149
2150 /// Build a new OpenMP 'hint' clause.
2151 ///
2152 /// By default, performs semantic analysis to build the new statement.
2153 /// Subclasses may override this routine to provide different behavior.
2155 SourceLocation LParenLoc,
2156 SourceLocation EndLoc) {
2157 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2158 EndLoc);
2159 }
2160
2161 /// Build a new OpenMP 'detach' clause.
2162 ///
2163 /// By default, performs semantic analysis to build the new statement.
2164 /// Subclasses may override this routine to provide different behavior.
2166 SourceLocation LParenLoc,
2167 SourceLocation EndLoc) {
2168 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2169 EndLoc);
2170 }
2171
2172 /// Build a new OpenMP 'dist_schedule' clause.
2173 ///
2174 /// By default, performs semantic analysis to build the new OpenMP clause.
2175 /// Subclasses may override this routine to provide different behavior.
2176 OMPClause *
2178 Expr *ChunkSize, SourceLocation StartLoc,
2179 SourceLocation LParenLoc, SourceLocation KindLoc,
2180 SourceLocation CommaLoc, SourceLocation EndLoc) {
2182 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2183 }
2184
2185 /// Build a new OpenMP 'to' clause.
2186 ///
2187 /// By default, performs semantic analysis to build the new statement.
2188 /// Subclasses may override this routine to provide different behavior.
2189 OMPClause *
2191 ArrayRef<SourceLocation> MotionModifiersLoc,
2192 CXXScopeSpec &MapperIdScopeSpec,
2193 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2194 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2195 ArrayRef<Expr *> UnresolvedMappers) {
2197 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2198 ColonLoc, VarList, Locs, UnresolvedMappers);
2199 }
2200
2201 /// Build a new OpenMP 'from' clause.
2202 ///
2203 /// By default, performs semantic analysis to build the new statement.
2204 /// Subclasses may override this routine to provide different behavior.
2205 OMPClause *
2207 ArrayRef<SourceLocation> MotionModifiersLoc,
2208 CXXScopeSpec &MapperIdScopeSpec,
2209 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2210 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2211 ArrayRef<Expr *> UnresolvedMappers) {
2213 MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId,
2214 ColonLoc, VarList, Locs, UnresolvedMappers);
2215 }
2216
2217 /// Build a new OpenMP 'use_device_ptr' clause.
2218 ///
2219 /// By default, performs semantic analysis to build the new OpenMP clause.
2220 /// Subclasses may override this routine to provide different behavior.
2222 const OMPVarListLocTy &Locs) {
2223 return getSema().OpenMP().ActOnOpenMPUseDevicePtrClause(VarList, Locs);
2224 }
2225
2226 /// Build a new OpenMP 'use_device_addr' clause.
2227 ///
2228 /// By default, performs semantic analysis to build the new OpenMP clause.
2229 /// Subclasses may override this routine to provide different behavior.
2231 const OMPVarListLocTy &Locs) {
2232 return getSema().OpenMP().ActOnOpenMPUseDeviceAddrClause(VarList, Locs);
2233 }
2234
2235 /// Build a new OpenMP 'is_device_ptr' clause.
2236 ///
2237 /// By default, performs semantic analysis to build the new OpenMP clause.
2238 /// Subclasses may override this routine to provide different behavior.
2240 const OMPVarListLocTy &Locs) {
2241 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2242 }
2243
2244 /// Build a new OpenMP 'has_device_addr' clause.
2245 ///
2246 /// By default, performs semantic analysis to build the new OpenMP clause.
2247 /// Subclasses may override this routine to provide different behavior.
2249 const OMPVarListLocTy &Locs) {
2250 return getSema().OpenMP().ActOnOpenMPHasDeviceAddrClause(VarList, Locs);
2251 }
2252
2253 /// Build a new OpenMP 'defaultmap' clause.
2254 ///
2255 /// By default, performs semantic analysis to build the new OpenMP clause.
2256 /// Subclasses may override this routine to provide different behavior.
2259 SourceLocation StartLoc,
2260 SourceLocation LParenLoc,
2261 SourceLocation MLoc,
2262 SourceLocation KindLoc,
2263 SourceLocation EndLoc) {
2265 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2266 }
2267
2268 /// Build a new OpenMP 'nontemporal' clause.
2269 ///
2270 /// By default, performs semantic analysis to build the new OpenMP clause.
2271 /// Subclasses may override this routine to provide different behavior.
2273 SourceLocation StartLoc,
2274 SourceLocation LParenLoc,
2275 SourceLocation EndLoc) {
2276 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2277 LParenLoc, EndLoc);
2278 }
2279
2280 /// Build a new OpenMP 'inclusive' clause.
2281 ///
2282 /// By default, performs semantic analysis to build the new OpenMP clause.
2283 /// Subclasses may override this routine to provide different behavior.
2285 SourceLocation StartLoc,
2286 SourceLocation LParenLoc,
2287 SourceLocation EndLoc) {
2288 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2289 LParenLoc, EndLoc);
2290 }
2291
2292 /// Build a new OpenMP 'exclusive' clause.
2293 ///
2294 /// By default, performs semantic analysis to build the new OpenMP clause.
2295 /// Subclasses may override this routine to provide different behavior.
2297 SourceLocation StartLoc,
2298 SourceLocation LParenLoc,
2299 SourceLocation EndLoc) {
2300 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2301 LParenLoc, EndLoc);
2302 }
2303
2304 /// Build a new OpenMP 'uses_allocators' clause.
2305 ///
2306 /// By default, performs semantic analysis to build the new OpenMP clause.
2307 /// Subclasses may override this routine to provide different behavior.
2310 SourceLocation LParenLoc, SourceLocation EndLoc) {
2312 StartLoc, LParenLoc, EndLoc, Data);
2313 }
2314
2315 /// Build a new OpenMP 'affinity' clause.
2316 ///
2317 /// By default, performs semantic analysis to build the new OpenMP clause.
2318 /// Subclasses may override this routine to provide different behavior.
2320 SourceLocation LParenLoc,
2321 SourceLocation ColonLoc,
2322 SourceLocation EndLoc, Expr *Modifier,
2323 ArrayRef<Expr *> Locators) {
2325 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2326 }
2327
2328 /// Build a new OpenMP 'order' clause.
2329 ///
2330 /// By default, performs semantic analysis to build the new OpenMP clause.
2331 /// Subclasses may override this routine to provide different behavior.
2333 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2334 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2335 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2337 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2338 }
2339
2340 /// Build a new OpenMP 'init' clause.
2341 ///
2342 /// By default, performs semantic analysis to build the new OpenMP clause.
2343 /// Subclasses may override this routine to provide different behavior.
2345 SourceLocation StartLoc,
2346 SourceLocation LParenLoc,
2347 SourceLocation VarLoc,
2348 SourceLocation EndLoc) {
2350 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2351 }
2352
2353 /// Build a new OpenMP 'use' clause.
2354 ///
2355 /// By default, performs semantic analysis to build the new OpenMP clause.
2356 /// Subclasses may override this routine to provide different behavior.
2358 SourceLocation LParenLoc,
2359 SourceLocation VarLoc, SourceLocation EndLoc) {
2360 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2361 LParenLoc, VarLoc, EndLoc);
2362 }
2363
2364 /// Build a new OpenMP 'destroy' clause.
2365 ///
2366 /// By default, performs semantic analysis to build the new OpenMP clause.
2367 /// Subclasses may override this routine to provide different behavior.
2369 SourceLocation LParenLoc,
2370 SourceLocation VarLoc,
2371 SourceLocation EndLoc) {
2373 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2374 }
2375
2376 /// Build a new OpenMP 'novariants' clause.
2377 ///
2378 /// By default, performs semantic analysis to build the new OpenMP clause.
2379 /// Subclasses may override this routine to provide different behavior.
2381 SourceLocation StartLoc,
2382 SourceLocation LParenLoc,
2383 SourceLocation EndLoc) {
2385 LParenLoc, EndLoc);
2386 }
2387
2388 /// Build a new OpenMP 'nocontext' clause.
2389 ///
2390 /// By default, performs semantic analysis to build the new OpenMP clause.
2391 /// Subclasses may override this routine to provide different behavior.
2393 SourceLocation LParenLoc,
2394 SourceLocation EndLoc) {
2396 LParenLoc, EndLoc);
2397 }
2398
2399 /// Build a new OpenMP 'filter' clause.
2400 ///
2401 /// By default, performs semantic analysis to build the new OpenMP clause.
2402 /// Subclasses may override this routine to provide different behavior.
2404 SourceLocation LParenLoc,
2405 SourceLocation EndLoc) {
2406 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2407 LParenLoc, EndLoc);
2408 }
2409
2410 /// Build a new OpenMP 'bind' clause.
2411 ///
2412 /// By default, performs semantic analysis to build the new OpenMP clause.
2413 /// Subclasses may override this routine to provide different behavior.
2415 SourceLocation KindLoc,
2416 SourceLocation StartLoc,
2417 SourceLocation LParenLoc,
2418 SourceLocation EndLoc) {
2419 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2420 LParenLoc, EndLoc);
2421 }
2422
2423 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2424 ///
2425 /// By default, performs semantic analysis to build the new OpenMP clause.
2426 /// Subclasses may override this routine to provide different behavior.
2428 SourceLocation LParenLoc,
2429 SourceLocation EndLoc) {
2430 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2431 LParenLoc, EndLoc);
2432 }
2433
2434 /// Build a new OpenMP 'ompx_attribute' clause.
2435 ///
2436 /// By default, performs semantic analysis to build the new OpenMP clause.
2437 /// Subclasses may override this routine to provide different behavior.
2439 SourceLocation StartLoc,
2440 SourceLocation LParenLoc,
2441 SourceLocation EndLoc) {
2442 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2443 LParenLoc, EndLoc);
2444 }
2445
2446 /// Build a new OpenMP 'ompx_bare' clause.
2447 ///
2448 /// By default, performs semantic analysis to build the new OpenMP clause.
2449 /// Subclasses may override this routine to provide different behavior.
2451 SourceLocation EndLoc) {
2452 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2453 }
2454
2455 /// Build a new OpenMP 'align' clause.
2456 ///
2457 /// By default, performs semantic analysis to build the new OpenMP clause.
2458 /// Subclasses may override this routine to provide different behavior.
2460 SourceLocation LParenLoc,
2461 SourceLocation EndLoc) {
2462 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2463 EndLoc);
2464 }
2465
2466 /// Build a new OpenMP 'at' clause.
2467 ///
2468 /// By default, performs semantic analysis to build the new OpenMP clause.
2469 /// Subclasses may override this routine to provide different behavior.
2471 SourceLocation StartLoc,
2472 SourceLocation LParenLoc,
2473 SourceLocation EndLoc) {
2474 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2475 LParenLoc, EndLoc);
2476 }
2477
2478 /// Build a new OpenMP 'severity' clause.
2479 ///
2480 /// By default, performs semantic analysis to build the new OpenMP clause.
2481 /// Subclasses may override this routine to provide different behavior.
2483 SourceLocation KwLoc,
2484 SourceLocation StartLoc,
2485 SourceLocation LParenLoc,
2486 SourceLocation EndLoc) {
2487 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2488 LParenLoc, EndLoc);
2489 }
2490
2491 /// Build a new OpenMP 'message' clause.
2492 ///
2493 /// By default, performs semantic analysis to build the new OpenMP clause.
2494 /// Subclasses may override this routine to provide different behavior.
2496 SourceLocation LParenLoc,
2497 SourceLocation EndLoc) {
2498 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2499 EndLoc);
2500 }
2501
2502 /// Build a new OpenMP 'doacross' clause.
2503 ///
2504 /// By default, performs semantic analysis to build the new OpenMP clause.
2505 /// Subclasses may override this routine to provide different behavior.
2506 OMPClause *
2508 SourceLocation DepLoc, SourceLocation ColonLoc,
2509 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2510 SourceLocation LParenLoc, SourceLocation EndLoc) {
2512 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2513 }
2514
2515 /// Build a new OpenMP 'holds' clause.
2517 SourceLocation LParenLoc,
2518 SourceLocation EndLoc) {
2519 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2520 EndLoc);
2521 }
2522
2523 /// Rebuild the operand to an Objective-C \@synchronized statement.
2524 ///
2525 /// By default, performs semantic analysis to build the new statement.
2526 /// Subclasses may override this routine to provide different behavior.
2528 Expr *object) {
2529 return getSema().ObjC().ActOnObjCAtSynchronizedOperand(atLoc, object);
2530 }
2531
2532 /// Build a new Objective-C \@synchronized statement.
2533 ///
2534 /// By default, performs semantic analysis to build the new statement.
2535 /// Subclasses may override this routine to provide different behavior.
2537 Expr *Object, Stmt *Body) {
2538 return getSema().ObjC().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
2539 }
2540
2541 /// Build a new Objective-C \@autoreleasepool statement.
2542 ///
2543 /// By default, performs semantic analysis to build the new statement.
2544 /// Subclasses may override this routine to provide different behavior.
2546 Stmt *Body) {
2547 return getSema().ObjC().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
2548 }
2549
2550 /// Build a new Objective-C fast enumeration statement.
2551 ///
2552 /// By default, performs semantic analysis to build the new statement.
2553 /// Subclasses may override this routine to provide different behavior.
2555 Stmt *Element,
2556 Expr *Collection,
2557 SourceLocation RParenLoc,
2558 Stmt *Body) {
2560 ForLoc, Element, Collection, RParenLoc);
2561 if (ForEachStmt.isInvalid())
2562 return StmtError();
2563
2564 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2565 Body);
2566 }
2567
2568 /// Build a new C++ exception declaration.
2569 ///
2570 /// By default, performs semantic analysis to build the new decaration.
2571 /// Subclasses may override this routine to provide different behavior.
2574 SourceLocation StartLoc,
2575 SourceLocation IdLoc,
2576 IdentifierInfo *Id) {
2578 StartLoc, IdLoc, Id);
2579 if (Var)
2580 getSema().CurContext->addDecl(Var);
2581 return Var;
2582 }
2583
2584 /// Build a new C++ catch statement.
2585 ///
2586 /// By default, performs semantic analysis to build the new statement.
2587 /// Subclasses may override this routine to provide different behavior.
2589 VarDecl *ExceptionDecl,
2590 Stmt *Handler) {
2591 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2592 Handler));
2593 }
2594
2595 /// Build a new C++ try statement.
2596 ///
2597 /// By default, performs semantic analysis to build the new statement.
2598 /// Subclasses may override this routine to provide different behavior.
2600 ArrayRef<Stmt *> Handlers) {
2601 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2602 }
2603
2604 /// Build a new C++0x range-based for statement.
2605 ///
2606 /// By default, performs semantic analysis to build the new statement.
2607 /// Subclasses may override this routine to provide different behavior.
2609 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2610 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2611 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2612 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2613 // If we've just learned that the range is actually an Objective-C
2614 // collection, treat this as an Objective-C fast enumeration loop.
2615 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2616 if (RangeStmt->isSingleDecl()) {
2617 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2618 if (RangeVar->isInvalidDecl())
2619 return StmtError();
2620
2621 Expr *RangeExpr = RangeVar->getInit();
2622 if (!RangeExpr->isTypeDependent() &&
2623 RangeExpr->getType()->isObjCObjectPointerType()) {
2624 // FIXME: Support init-statements in Objective-C++20 ranged for
2625 // statement.
2626 if (Init) {
2627 return SemaRef.Diag(Init->getBeginLoc(),
2628 diag::err_objc_for_range_init_stmt)
2629 << Init->getSourceRange();
2630 }
2632 ForLoc, LoopVar, RangeExpr, RParenLoc);
2633 }
2634 }
2635 }
2636 }
2637
2639 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2640 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2641 }
2642
2643 /// Build a new C++0x range-based for statement.
2644 ///
2645 /// By default, performs semantic analysis to build the new statement.
2646 /// Subclasses may override this routine to provide different behavior.
2648 bool IsIfExists,
2649 NestedNameSpecifierLoc QualifierLoc,
2650 DeclarationNameInfo NameInfo,
2651 Stmt *Nested) {
2652 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2653 QualifierLoc, NameInfo, Nested);
2654 }
2655
2656 /// Attach body to a C++0x range-based for statement.
2657 ///
2658 /// By default, performs semantic analysis to finish the new statement.
2659 /// Subclasses may override this routine to provide different behavior.
2661 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2662 }
2663
2665 Stmt *TryBlock, Stmt *Handler) {
2666 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2667 }
2668
2670 Stmt *Block) {
2671 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2672 }
2673
2675 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2676 }
2677
2679 SourceLocation LParen,
2680 SourceLocation RParen,
2681 TypeSourceInfo *TSI) {
2682 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2683 TSI);
2684 }
2685
2686 /// Build a new predefined expression.
2687 ///
2688 /// By default, performs semantic analysis to build the new expression.
2689 /// Subclasses may override this routine to provide different behavior.
2691 return getSema().BuildPredefinedExpr(Loc, IK);
2692 }
2693
2694 /// Build a new expression that references a declaration.
2695 ///
2696 /// By default, performs semantic analysis to build the new expression.
2697 /// Subclasses may override this routine to provide different behavior.
2699 LookupResult &R,
2700 bool RequiresADL) {
2701 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2702 }
2703
2704
2705 /// Build a new expression that references a declaration.
2706 ///
2707 /// By default, performs semantic analysis to build the new expression.
2708 /// Subclasses may override this routine to provide different behavior.
2710 ValueDecl *VD,
2711 const DeclarationNameInfo &NameInfo,
2713 TemplateArgumentListInfo *TemplateArgs) {
2714 CXXScopeSpec SS;
2715 SS.Adopt(QualifierLoc);
2716 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2717 TemplateArgs);
2718 }
2719
2720 /// Build a new expression in parentheses.
2721 ///
2722 /// By default, performs semantic analysis to build the new expression.
2723 /// Subclasses may override this routine to provide different behavior.
2725 SourceLocation RParen) {
2726 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2727 }
2728
2729 /// Build a new pseudo-destructor expression.
2730 ///
2731 /// By default, performs semantic analysis to build the new expression.
2732 /// Subclasses may override this routine to provide different behavior.
2734 SourceLocation OperatorLoc,
2735 bool isArrow,
2736 CXXScopeSpec &SS,
2737 TypeSourceInfo *ScopeType,
2738 SourceLocation CCLoc,
2739 SourceLocation TildeLoc,
2740 PseudoDestructorTypeStorage Destroyed);
2741
2742 /// Build a new unary operator expression.
2743 ///
2744 /// By default, performs semantic analysis to build the new expression.
2745 /// Subclasses may override this routine to provide different behavior.
2748 Expr *SubExpr) {
2749 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2750 }
2751
2752 /// Build a new builtin offsetof expression.
2753 ///
2754 /// By default, performs semantic analysis to build the new expression.
2755 /// Subclasses may override this routine to provide different behavior.
2759 SourceLocation RParenLoc) {
2760 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
2761 RParenLoc);
2762 }
2763
2764 /// Build a new sizeof, alignof or vec_step expression with a
2765 /// type argument.
2766 ///
2767 /// By default, performs semantic analysis to build the new expression.
2768 /// Subclasses may override this routine to provide different behavior.
2770 SourceLocation OpLoc,
2771 UnaryExprOrTypeTrait ExprKind,
2772 SourceRange R) {
2773 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2774 }
2775
2776 /// Build a new sizeof, alignof or vec step expression with an
2777 /// expression argument.
2778 ///
2779 /// By default, performs semantic analysis to build the new expression.
2780 /// Subclasses may override this routine to provide different behavior.
2782 UnaryExprOrTypeTrait ExprKind,
2783 SourceRange R) {
2785 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2786 if (Result.isInvalid())
2787 return ExprError();
2788
2789 return Result;
2790 }
2791
2792 /// Build a new array subscript expression.
2793 ///
2794 /// By default, performs semantic analysis to build the new expression.
2795 /// Subclasses may override this routine to provide different behavior.
2797 SourceLocation LBracketLoc,
2798 Expr *RHS,
2799 SourceLocation RBracketLoc) {
2800 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2801 LBracketLoc, RHS,
2802 RBracketLoc);
2803 }
2804
2805 /// Build a new matrix subscript expression.
2806 ///
2807 /// By default, performs semantic analysis to build the new expression.
2808 /// Subclasses may override this routine to provide different behavior.
2810 Expr *ColumnIdx,
2811 SourceLocation RBracketLoc) {
2812 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2813 RBracketLoc);
2814 }
2815
2816 /// Build a new array section expression.
2817 ///
2818 /// By default, performs semantic analysis to build the new expression.
2819 /// Subclasses may override this routine to provide different behavior.
2821 SourceLocation LBracketLoc,
2822 Expr *LowerBound,
2823 SourceLocation ColonLocFirst,
2824 SourceLocation ColonLocSecond,
2825 Expr *Length, Expr *Stride,
2826 SourceLocation RBracketLoc) {
2827 if (IsOMPArraySection)
2829 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2830 Stride, RBracketLoc);
2831
2832 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2833 "Stride/second colon not allowed for OpenACC");
2834
2836 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2837 }
2838
2839 /// Build a new array shaping expression.
2840 ///
2841 /// By default, performs semantic analysis to build the new expression.
2842 /// Subclasses may override this routine to provide different behavior.
2844 SourceLocation RParenLoc,
2845 ArrayRef<Expr *> Dims,
2846 ArrayRef<SourceRange> BracketsRanges) {
2848 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2849 }
2850
2851 /// Build a new iterator expression.
2852 ///
2853 /// By default, performs semantic analysis to build the new expression.
2854 /// Subclasses may override this routine to provide different behavior.
2857 SourceLocation RLoc,
2860 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2861 }
2862
2863 /// Build a new call expression.
2864 ///
2865 /// By default, performs semantic analysis to build the new expression.
2866 /// Subclasses may override this routine to provide different behavior.
2868 MultiExprArg Args,
2869 SourceLocation RParenLoc,
2870 Expr *ExecConfig = nullptr) {
2871 return getSema().ActOnCallExpr(
2872 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2873 }
2874
2876 MultiExprArg Args,
2877 SourceLocation RParenLoc) {
2879 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2880 }
2881
2882 /// Build a new member access expression.
2883 ///
2884 /// By default, performs semantic analysis to build the new expression.
2885 /// Subclasses may override this routine to provide different behavior.
2887 bool isArrow,
2888 NestedNameSpecifierLoc QualifierLoc,
2889 SourceLocation TemplateKWLoc,
2890 const DeclarationNameInfo &MemberNameInfo,
2892 NamedDecl *FoundDecl,
2893 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2894 NamedDecl *FirstQualifierInScope) {
2896 isArrow);
2897 if (!Member->getDeclName()) {
2898 // We have a reference to an unnamed field. This is always the
2899 // base of an anonymous struct/union member access, i.e. the
2900 // field is always of record type.
2901 assert(Member->getType()->isRecordType() &&
2902 "unnamed member not of record type?");
2903
2904 BaseResult =
2906 QualifierLoc.getNestedNameSpecifier(),
2907 FoundDecl, Member);
2908 if (BaseResult.isInvalid())
2909 return ExprError();
2910 Base = BaseResult.get();
2911
2912 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2913 // from the AST, so we need to re-insert them if needed (since
2914 // `BuildFieldRefereneExpr()` doesn't do this).
2915 if (!isArrow && Base->isPRValue()) {
2917 if (BaseResult.isInvalid())
2918 return ExprError();
2919 Base = BaseResult.get();
2920 }
2921
2922 CXXScopeSpec EmptySS;
2924 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
2925 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
2926 MemberNameInfo);
2927 }
2928
2929 CXXScopeSpec SS;
2930 SS.Adopt(QualifierLoc);
2931
2932 Base = BaseResult.get();
2933 if (Base->containsErrors())
2934 return ExprError();
2935
2936 QualType BaseType = Base->getType();
2937
2938 if (isArrow && !BaseType->isPointerType())
2939 return ExprError();
2940
2941 // FIXME: this involves duplicating earlier analysis in a lot of
2942 // cases; we should avoid this when possible.
2943 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
2944 R.addDecl(FoundDecl);
2945 R.resolveKind();
2946
2947 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
2948 isa<FieldDecl, IndirectFieldDecl, MSPropertyDecl>(Member)) {
2949 if (auto *ThisClass = cast<CXXThisExpr>(Base)
2950 ->getType()
2951 ->getPointeeType()
2952 ->getAsCXXRecordDecl()) {
2953 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
2954 // In unevaluated contexts, an expression supposed to be a member access
2955 // might reference a member in an unrelated class.
2956 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
2957 return getSema().BuildDeclRefExpr(Member, Member->getType(),
2958 VK_LValue, Member->getLocation());
2959 }
2960 }
2961
2962 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
2963 SS, TemplateKWLoc,
2964 FirstQualifierInScope,
2965 R, ExplicitTemplateArgs,
2966 /*S*/nullptr);
2967 }
2968
2969 /// Build a new binary operator expression.
2970 ///
2971 /// By default, performs semantic analysis to build the new expression.
2972 /// Subclasses may override this routine to provide different behavior.
2975 Expr *LHS, Expr *RHS) {
2976 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
2977 }
2978
2979 /// Build a new rewritten operator expression.
2980 ///
2981 /// By default, performs semantic analysis to build the new expression.
2982 /// Subclasses may override this routine to provide different behavior.
2984 SourceLocation OpLoc, BinaryOperatorKind Opcode,
2985 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
2986 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
2987 RHS, /*RequiresADL*/false);
2988 }
2989
2990 /// Build a new conditional operator expression.
2991 ///
2992 /// By default, performs semantic analysis to build the new expression.
2993 /// Subclasses may override this routine to provide different behavior.
2995 SourceLocation QuestionLoc,
2996 Expr *LHS,
2997 SourceLocation ColonLoc,
2998 Expr *RHS) {
2999 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3000 LHS, RHS);
3001 }
3002
3003 /// Build a new C-style cast expression.
3004 ///
3005 /// By default, performs semantic analysis to build the new expression.
3006 /// Subclasses may override this routine to provide different behavior.
3008 TypeSourceInfo *TInfo,
3009 SourceLocation RParenLoc,
3010 Expr *SubExpr) {
3011 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3012 SubExpr);
3013 }
3014
3015 /// Build a new compound literal expression.
3016 ///
3017 /// By default, performs semantic analysis to build the new expression.
3018 /// Subclasses may override this routine to provide different behavior.
3020 TypeSourceInfo *TInfo,
3021 SourceLocation RParenLoc,
3022 Expr *Init) {
3023 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3024 Init);
3025 }
3026
3027 /// Build a new extended vector element access expression.
3028 ///
3029 /// By default, performs semantic analysis to build the new expression.
3030 /// Subclasses may override this routine to provide different behavior.
3032 bool IsArrow,
3033 SourceLocation AccessorLoc,
3034 IdentifierInfo &Accessor) {
3035
3036 CXXScopeSpec SS;
3037 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3039 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3040 /*FirstQualifierInScope*/ nullptr, NameInfo,
3041 /* TemplateArgs */ nullptr,
3042 /*S*/ nullptr);
3043 }
3044
3045 /// Build a new initializer list expression.
3046 ///
3047 /// By default, performs semantic analysis to build the new expression.
3048 /// Subclasses may override this routine to provide different behavior.
3050 MultiExprArg Inits,
3051 SourceLocation RBraceLoc) {
3052 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc);
3053 }
3054
3055 /// Build a new designated initializer expression.
3056 ///
3057 /// By default, performs semantic analysis to build the new expression.
3058 /// Subclasses may override this routine to provide different behavior.
3060 MultiExprArg ArrayExprs,
3061 SourceLocation EqualOrColonLoc,
3062 bool GNUSyntax,
3063 Expr *Init) {
3065 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3066 Init);
3067 if (Result.isInvalid())
3068 return ExprError();
3069
3070 return Result;
3071 }
3072
3073 /// Build a new value-initialized expression.
3074 ///
3075 /// By default, builds the implicit value initialization without performing
3076 /// any semantic analysis. Subclasses may override this routine to provide
3077 /// different behavior.
3079 return new (SemaRef.Context) ImplicitValueInitExpr(T);
3080 }
3081
3082 /// Build a new \c va_arg expression.
3083 ///
3084 /// By default, performs semantic analysis to build the new expression.
3085 /// Subclasses may override this routine to provide different behavior.
3087 Expr *SubExpr, TypeSourceInfo *TInfo,
3088 SourceLocation RParenLoc) {
3089 return getSema().BuildVAArgExpr(BuiltinLoc,
3090 SubExpr, TInfo,
3091 RParenLoc);
3092 }
3093
3094 /// Build a new expression list in parentheses.
3095 ///
3096 /// By default, performs semantic analysis to build the new expression.
3097 /// Subclasses may override this routine to provide different behavior.
3099 MultiExprArg SubExprs,
3100 SourceLocation RParenLoc) {
3101 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3102 }
3103
3104 /// Build a new address-of-label expression.
3105 ///
3106 /// By default, performs semantic analysis, using the name of the label
3107 /// rather than attempting to map the label statement itself.
3108 /// Subclasses may override this routine to provide different behavior.
3110 SourceLocation LabelLoc, LabelDecl *Label) {
3111 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3112 }
3113
3114 /// Build a new GNU statement expression.
3115 ///
3116 /// By default, performs semantic analysis to build the new expression.
3117 /// Subclasses may override this routine to provide different behavior.
3119 SourceLocation RParenLoc, unsigned TemplateDepth) {
3120 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3121 TemplateDepth);
3122 }
3123
3124 /// Build a new __builtin_choose_expr expression.
3125 ///
3126 /// By default, performs semantic analysis to build the new expression.
3127 /// Subclasses may override this routine to provide different behavior.
3129 Expr *Cond, Expr *LHS, Expr *RHS,
3130 SourceLocation RParenLoc) {
3131 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3132 Cond, LHS, RHS,
3133 RParenLoc);
3134 }
3135
3136 /// Build a new generic selection expression with an expression predicate.
3137 ///
3138 /// By default, performs semantic analysis to build the new expression.
3139 /// Subclasses may override this routine to provide different behavior.
3141 SourceLocation DefaultLoc,
3142 SourceLocation RParenLoc,
3143 Expr *ControllingExpr,
3145 ArrayRef<Expr *> Exprs) {
3146 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3147 /*PredicateIsExpr=*/true,
3148 ControllingExpr, Types, Exprs);
3149 }
3150
3151 /// Build a new generic selection expression with a type predicate.
3152 ///
3153 /// By default, performs semantic analysis to build the new expression.
3154 /// Subclasses may override this routine to provide different behavior.
3156 SourceLocation DefaultLoc,
3157 SourceLocation RParenLoc,
3158 TypeSourceInfo *ControllingType,
3160 ArrayRef<Expr *> Exprs) {
3161 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3162 /*PredicateIsExpr=*/false,
3163 ControllingType, Types, Exprs);
3164 }
3165
3166 /// Build a new overloaded operator call expression.
3167 ///
3168 /// By default, performs semantic analysis to build the new expression.
3169 /// The semantic analysis provides the behavior of template instantiation,
3170 /// copying with transformations that turn what looks like an overloaded
3171 /// operator call into a use of a builtin operator, performing
3172 /// argument-dependent lookup, etc. Subclasses may override this routine to
3173 /// provide different behavior.
3175 SourceLocation OpLoc,
3176 SourceLocation CalleeLoc,
3177 bool RequiresADL,
3178 const UnresolvedSetImpl &Functions,
3179 Expr *First, Expr *Second);
3180
3181 /// Build a new C++ "named" cast expression, such as static_cast or
3182 /// reinterpret_cast.
3183 ///
3184 /// By default, this routine dispatches to one of the more-specific routines
3185 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3186 /// Subclasses may override this routine to provide different behavior.
3189 SourceLocation LAngleLoc,
3190 TypeSourceInfo *TInfo,
3191 SourceLocation RAngleLoc,
3192 SourceLocation LParenLoc,
3193 Expr *SubExpr,
3194 SourceLocation RParenLoc) {
3195 switch (Class) {
3196 case Stmt::CXXStaticCastExprClass:
3197 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3198 RAngleLoc, LParenLoc,
3199 SubExpr, RParenLoc);
3200
3201 case Stmt::CXXDynamicCastExprClass:
3202 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3203 RAngleLoc, LParenLoc,
3204 SubExpr, RParenLoc);
3205
3206 case Stmt::CXXReinterpretCastExprClass:
3207 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3208 RAngleLoc, LParenLoc,
3209 SubExpr,
3210 RParenLoc);
3211
3212 case Stmt::CXXConstCastExprClass:
3213 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3214 RAngleLoc, LParenLoc,
3215 SubExpr, RParenLoc);
3216
3217 case Stmt::CXXAddrspaceCastExprClass:
3218 return getDerived().RebuildCXXAddrspaceCastExpr(
3219 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3220
3221 default:
3222 llvm_unreachable("Invalid C++ named cast");
3223 }
3224 }
3225
3226 /// Build a new C++ static_cast expression.
3227 ///
3228 /// By default, performs semantic analysis to build the new expression.
3229 /// Subclasses may override this routine to provide different behavior.
3231 SourceLocation LAngleLoc,
3232 TypeSourceInfo *TInfo,
3233 SourceLocation RAngleLoc,
3234 SourceLocation LParenLoc,
3235 Expr *SubExpr,
3236 SourceLocation RParenLoc) {
3237 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3238 TInfo, SubExpr,
3239 SourceRange(LAngleLoc, RAngleLoc),
3240 SourceRange(LParenLoc, RParenLoc));
3241 }
3242
3243 /// Build a new C++ dynamic_cast expression.
3244 ///
3245 /// By default, performs semantic analysis to build the new expression.
3246 /// Subclasses may override this routine to provide different behavior.
3248 SourceLocation LAngleLoc,
3249 TypeSourceInfo *TInfo,
3250 SourceLocation RAngleLoc,
3251 SourceLocation LParenLoc,
3252 Expr *SubExpr,
3253 SourceLocation RParenLoc) {
3254 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3255 TInfo, SubExpr,
3256 SourceRange(LAngleLoc, RAngleLoc),
3257 SourceRange(LParenLoc, RParenLoc));
3258 }
3259
3260 /// Build a new C++ reinterpret_cast expression.
3261 ///
3262 /// By default, performs semantic analysis to build the new expression.
3263 /// Subclasses may override this routine to provide different behavior.
3265 SourceLocation LAngleLoc,
3266 TypeSourceInfo *TInfo,
3267 SourceLocation RAngleLoc,
3268 SourceLocation LParenLoc,
3269 Expr *SubExpr,
3270 SourceLocation RParenLoc) {
3271 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3272 TInfo, SubExpr,
3273 SourceRange(LAngleLoc, RAngleLoc),
3274 SourceRange(LParenLoc, RParenLoc));
3275 }
3276
3277 /// Build a new C++ const_cast expression.
3278 ///
3279 /// By default, performs semantic analysis to build the new expression.
3280 /// Subclasses may override this routine to provide different behavior.
3282 SourceLocation LAngleLoc,
3283 TypeSourceInfo *TInfo,
3284 SourceLocation RAngleLoc,
3285 SourceLocation LParenLoc,
3286 Expr *SubExpr,
3287 SourceLocation RParenLoc) {
3288 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3289 TInfo, SubExpr,
3290 SourceRange(LAngleLoc, RAngleLoc),
3291 SourceRange(LParenLoc, RParenLoc));
3292 }
3293
3296 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3297 SourceLocation LParenLoc, Expr *SubExpr,
3298 SourceLocation RParenLoc) {
3299 return getSema().BuildCXXNamedCast(
3300 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3301 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3302 }
3303
3304 /// Build a new C++ functional-style cast expression.
3305 ///
3306 /// By default, performs semantic analysis to build the new expression.
3307 /// Subclasses may override this routine to provide different behavior.
3309 SourceLocation LParenLoc,
3310 Expr *Sub,
3311 SourceLocation RParenLoc,
3312 bool ListInitialization) {
3313 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3314 // CXXParenListInitExpr. Pass its expanded arguments so that the
3315 // CXXParenListInitExpr can be rebuilt.
3316 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3318 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3319 RParenLoc, ListInitialization);
3320 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3321 MultiExprArg(&Sub, 1), RParenLoc,
3322 ListInitialization);
3323 }
3324
3325 /// Build a new C++ __builtin_bit_cast expression.
3326 ///
3327 /// By default, performs semantic analysis to build the new expression.
3328 /// Subclasses may override this routine to provide different behavior.
3330 TypeSourceInfo *TSI, Expr *Sub,
3331 SourceLocation RParenLoc) {
3332 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3333 }
3334
3335 /// Build a new C++ typeid(type) expression.
3336 ///
3337 /// By default, performs semantic analysis to build the new expression.
3338 /// Subclasses may override this routine to provide different behavior.
3340 SourceLocation TypeidLoc,
3341 TypeSourceInfo *Operand,
3342 SourceLocation RParenLoc) {
3343 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3344 RParenLoc);
3345 }
3346
3347
3348 /// Build a new C++ typeid(expr) expression.
3349 ///
3350 /// By default, performs semantic analysis to build the new expression.
3351 /// Subclasses may override this routine to provide different behavior.
3353 SourceLocation TypeidLoc,
3354 Expr *Operand,
3355 SourceLocation RParenLoc) {
3356 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3357 RParenLoc);
3358 }
3359
3360 /// Build a new C++ __uuidof(type) expression.
3361 ///
3362 /// By default, performs semantic analysis to build the new expression.
3363 /// Subclasses may override this routine to provide different behavior.
3365 TypeSourceInfo *Operand,
3366 SourceLocation RParenLoc) {
3367 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3368 }
3369
3370 /// Build a new C++ __uuidof(expr) expression.
3371 ///
3372 /// By default, performs semantic analysis to build the new expression.
3373 /// Subclasses may override this routine to provide different behavior.
3375 Expr *Operand, SourceLocation RParenLoc) {
3376 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3377 }
3378
3379 /// Build a new C++ "this" expression.
3380 ///
3381 /// By default, performs semantic analysis to build a new "this" expression.
3382 /// Subclasses may override this routine to provide different behavior.
3384 QualType ThisType,
3385 bool isImplicit) {
3386 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3387 return ExprError();
3388 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3389 }
3390
3391 /// Build a new C++ throw expression.
3392 ///
3393 /// By default, performs semantic analysis to build the new expression.
3394 /// Subclasses may override this routine to provide different behavior.
3396 bool IsThrownVariableInScope) {
3397 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3398 }
3399
3400 /// Build a new C++ default-argument expression.
3401 ///
3402 /// By default, builds a new default-argument expression, which does not
3403 /// require any semantic analysis. Subclasses may override this routine to
3404 /// provide different behavior.
3406 Expr *RewrittenExpr) {
3407 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3408 RewrittenExpr, getSema().CurContext);
3409 }
3410
3411 /// Build a new C++11 default-initialization expression.
3412 ///
3413 /// By default, builds a new default field initialization expression, which
3414 /// does not require any semantic analysis. Subclasses may override this
3415 /// routine to provide different behavior.
3417 FieldDecl *Field) {
3418 return getSema().BuildCXXDefaultInitExpr(Loc, Field);
3419 }
3420
3421 /// Build a new C++ zero-initialization expression.
3422 ///
3423 /// By default, performs semantic analysis to build the new expression.
3424 /// Subclasses may override this routine to provide different behavior.
3426 SourceLocation LParenLoc,
3427 SourceLocation RParenLoc) {
3428 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3429 /*ListInitialization=*/false);
3430 }
3431
3432 /// Build a new C++ "new" expression.
3433 ///
3434 /// By default, performs semantic analysis to build the new expression.
3435 /// Subclasses may override this routine to provide different behavior.
3437 SourceLocation PlacementLParen,
3438 MultiExprArg PlacementArgs,
3439 SourceLocation PlacementRParen,
3440 SourceRange TypeIdParens, QualType AllocatedType,
3441 TypeSourceInfo *AllocatedTypeInfo,
3442 std::optional<Expr *> ArraySize,
3443 SourceRange DirectInitRange, Expr *Initializer) {
3444 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3445 PlacementLParen,
3446 PlacementArgs,
3447 PlacementRParen,
3448 TypeIdParens,
3449 AllocatedType,
3450 AllocatedTypeInfo,
3451 ArraySize,
3452 DirectInitRange,
3453 Initializer);
3454 }
3455
3456 /// Build a new C++ "delete" expression.
3457 ///
3458 /// By default, performs semantic analysis to build the new expression.
3459 /// Subclasses may override this routine to provide different behavior.
3461 bool IsGlobalDelete,
3462 bool IsArrayForm,
3463 Expr *Operand) {
3464 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3465 Operand);
3466 }
3467
3468 /// Build a new type trait expression.
3469 ///
3470 /// By default, performs semantic analysis to build the new expression.
3471 /// Subclasses may override this routine to provide different behavior.
3473 SourceLocation StartLoc,
3475 SourceLocation RParenLoc) {
3476 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3477 }
3478
3479 /// Build a new array type trait expression.
3480 ///
3481 /// By default, performs semantic analysis to build the new expression.
3482 /// Subclasses may override this routine to provide different behavior.
3484 SourceLocation StartLoc,
3485 TypeSourceInfo *TSInfo,
3486 Expr *DimExpr,
3487 SourceLocation RParenLoc) {
3488 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3489 }
3490
3491 /// Build a new expression trait expression.
3492 ///
3493 /// By default, performs semantic analysis to build the new expression.
3494 /// Subclasses may override this routine to provide different behavior.
3496 SourceLocation StartLoc,
3497 Expr *Queried,
3498 SourceLocation RParenLoc) {
3499 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3500 }
3501
3502 /// Build a new (previously unresolved) declaration reference
3503 /// expression.
3504 ///
3505 /// By default, performs semantic analysis to build the new expression.
3506 /// Subclasses may override this routine to provide different behavior.
3508 NestedNameSpecifierLoc QualifierLoc,
3509 SourceLocation TemplateKWLoc,
3510 const DeclarationNameInfo &NameInfo,
3511 const TemplateArgumentListInfo *TemplateArgs,
3512 bool IsAddressOfOperand,
3513 TypeSourceInfo **RecoveryTSI) {
3514 CXXScopeSpec SS;
3515 SS.Adopt(QualifierLoc);
3516
3517 if (TemplateArgs || TemplateKWLoc.isValid())
3519 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3520
3522 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3523 }
3524
3525 /// Build a new template-id expression.
3526 ///
3527 /// By default, performs semantic analysis to build the new expression.
3528 /// Subclasses may override this routine to provide different behavior.
3530 SourceLocation TemplateKWLoc,
3531 LookupResult &R,
3532 bool RequiresADL,
3533 const TemplateArgumentListInfo *TemplateArgs) {
3534 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3535 TemplateArgs);
3536 }
3537
3538 /// Build a new object-construction expression.
3539 ///
3540 /// By default, performs semantic analysis to build the new expression.
3541 /// Subclasses may override this routine to provide different behavior.
3544 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3545 bool ListInitialization, bool StdInitListInitialization,
3546 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3547 SourceRange ParenRange) {
3548 // Reconstruct the constructor we originally found, which might be
3549 // different if this is a call to an inherited constructor.
3550 CXXConstructorDecl *FoundCtor = Constructor;
3551 if (Constructor->isInheritingConstructor())
3552 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3553
3554 SmallVector<Expr *, 8> ConvertedArgs;
3555 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3556 ConvertedArgs))
3557 return ExprError();
3558
3559 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3560 IsElidable,
3561 ConvertedArgs,
3562 HadMultipleCandidates,
3563 ListInitialization,
3564 StdInitListInitialization,
3565 RequiresZeroInit, ConstructKind,
3566 ParenRange);
3567 }
3568
3569 /// Build a new implicit construction via inherited constructor
3570 /// expression.
3572 CXXConstructorDecl *Constructor,
3573 bool ConstructsVBase,
3574 bool InheritedFromVBase) {
3576 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3577 }
3578
3579 /// Build a new object-construction expression.
3580 ///
3581 /// By default, performs semantic analysis to build the new expression.
3582 /// Subclasses may override this routine to provide different behavior.
3584 SourceLocation LParenOrBraceLoc,
3585 MultiExprArg Args,
3586 SourceLocation RParenOrBraceLoc,
3587 bool ListInitialization) {
3589 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3590 }
3591
3592 /// Build a new object-construction expression.
3593 ///
3594 /// By default, performs semantic analysis to build the new expression.
3595 /// Subclasses may override this routine to provide different behavior.
3597 SourceLocation LParenLoc,
3598 MultiExprArg Args,
3599 SourceLocation RParenLoc,
3600 bool ListInitialization) {
3601 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3602 RParenLoc, ListInitialization);
3603 }
3604
3605 /// Build a new member reference expression.
3606 ///
3607 /// By default, performs semantic analysis to build the new expression.
3608 /// Subclasses may override this routine to provide different behavior.
3610 QualType BaseType,
3611 bool IsArrow,
3612 SourceLocation OperatorLoc,
3613 NestedNameSpecifierLoc QualifierLoc,
3614 SourceLocation TemplateKWLoc,
3615 NamedDecl *FirstQualifierInScope,
3616 const DeclarationNameInfo &MemberNameInfo,
3617 const TemplateArgumentListInfo *TemplateArgs) {
3618 CXXScopeSpec SS;
3619 SS.Adopt(QualifierLoc);
3620
3621 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3622 OperatorLoc, IsArrow,
3623 SS, TemplateKWLoc,
3624 FirstQualifierInScope,
3625 MemberNameInfo,
3626 TemplateArgs, /*S*/nullptr);
3627 }
3628
3629 /// Build a new member reference expression.
3630 ///
3631 /// By default, performs semantic analysis to build the new expression.
3632 /// Subclasses may override this routine to provide different behavior.
3634 SourceLocation OperatorLoc,
3635 bool IsArrow,
3636 NestedNameSpecifierLoc QualifierLoc,
3637 SourceLocation TemplateKWLoc,
3638 NamedDecl *FirstQualifierInScope,
3639 LookupResult &R,
3640 const TemplateArgumentListInfo *TemplateArgs) {
3641 CXXScopeSpec SS;
3642 SS.Adopt(QualifierLoc);
3643
3644 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3645 OperatorLoc, IsArrow,
3646 SS, TemplateKWLoc,
3647 FirstQualifierInScope,
3648 R, TemplateArgs, /*S*/nullptr);
3649 }
3650
3651 /// Build a new noexcept expression.
3652 ///
3653 /// By default, performs semantic analysis to build the new expression.
3654 /// Subclasses may override this routine to provide different behavior.
3656 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3657 }
3658
3659 /// Build a new expression to compute the length of a parameter pack.
3661 SourceLocation PackLoc,
3662 SourceLocation RParenLoc,
3663 std::optional<unsigned> Length,
3664 ArrayRef<TemplateArgument> PartialArgs) {
3665 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3666 RParenLoc, Length, PartialArgs);
3667 }
3668
3670 SourceLocation RSquareLoc,
3671 Expr *PackIdExpression, Expr *IndexExpr,
3672 ArrayRef<Expr *> ExpandedExprs,
3673 bool FullySubstituted = false) {
3674 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3675 IndexExpr, RSquareLoc, ExpandedExprs,
3676 FullySubstituted);
3677 }
3678
3679 /// Build a new expression representing a call to a source location
3680 /// builtin.
3681 ///
3682 /// By default, performs semantic analysis to build the new expression.
3683 /// Subclasses may override this routine to provide different behavior.
3685 SourceLocation BuiltinLoc,
3686 SourceLocation RPLoc,
3687 DeclContext *ParentContext) {
3688 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3689 ParentContext);
3690 }
3691
3692 /// Build a new Objective-C boxed expression.
3693 ///
3694 /// By default, performs semantic analysis to build the new expression.
3695 /// Subclasses may override this routine to provide different behavior.
3697 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3698 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3700 CXXScopeSpec SS;
3701 SS.Adopt(NNS);
3702 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3703 ConceptNameInfo,
3704 FoundDecl,
3705 NamedConcept, TALI);
3706 if (Result.isInvalid())
3707 return ExprError();
3708 return Result;
3709 }
3710
3711 /// \brief Build a new requires expression.
3712 ///
3713 /// By default, performs semantic analysis to build the new expression.
3714 /// Subclasses may override this routine to provide different behavior.
3717 SourceLocation LParenLoc,
3718 ArrayRef<ParmVarDecl *> LocalParameters,
3719 SourceLocation RParenLoc,
3721 SourceLocation ClosingBraceLoc) {
3722 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3723 LocalParameters, RParenLoc, Requirements,
3724 ClosingBraceLoc);
3725 }
3726
3730 return SemaRef.BuildTypeRequirement(SubstDiag);
3731 }
3732
3735 }
3736
3739 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3740 SourceLocation NoexceptLoc,
3742 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3743 std::move(Ret));
3744 }
3745
3747 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3749 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3750 std::move(Ret));
3751 }
3752
3754 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3755 const ASTConstraintSatisfaction &Satisfaction) {
3756 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3757 Satisfaction);
3758 }
3759
3761 return SemaRef.BuildNestedRequirement(Constraint);
3762 }
3763
3764 /// \brief Build a new Objective-C boxed expression.
3765 ///
3766 /// By default, performs semantic analysis to build the new expression.
3767 /// Subclasses may override this routine to provide different behavior.
3769 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3770 }
3771
3772 /// Build a new Objective-C array literal.
3773 ///
3774 /// By default, performs semantic analysis to build the new expression.
3775 /// Subclasses may override this routine to provide different behavior.
3777 Expr **Elements, unsigned NumElements) {
3779 Range, MultiExprArg(Elements, NumElements));
3780 }
3781
3783 Expr *Base, Expr *Key,
3784 ObjCMethodDecl *getterMethod,
3785 ObjCMethodDecl *setterMethod) {
3787 RB, Base, Key, getterMethod, setterMethod);
3788 }
3789
3790 /// Build a new Objective-C dictionary literal.
3791 ///
3792 /// By default, performs semantic analysis to build the new expression.
3793 /// Subclasses may override this routine to provide different behavior.
3796 return getSema().ObjC().BuildObjCDictionaryLiteral(Range, Elements);
3797 }
3798
3799 /// Build a new Objective-C \@encode expression.
3800 ///
3801 /// By default, performs semantic analysis to build the new expression.
3802 /// Subclasses may override this routine to provide different behavior.
3804 TypeSourceInfo *EncodeTypeInfo,
3805 SourceLocation RParenLoc) {
3806 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3807 RParenLoc);
3808 }
3809
3810 /// Build a new Objective-C class message.
3812 Selector Sel,
3813 ArrayRef<SourceLocation> SelectorLocs,
3814 ObjCMethodDecl *Method,
3815 SourceLocation LBracLoc,
3816 MultiExprArg Args,
3817 SourceLocation RBracLoc) {
3819 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3820 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3821 RBracLoc, Args);
3822 }
3823
3824 /// Build a new Objective-C instance message.
3826 Selector Sel,
3827 ArrayRef<SourceLocation> SelectorLocs,
3828 ObjCMethodDecl *Method,
3829 SourceLocation LBracLoc,
3830 MultiExprArg Args,
3831 SourceLocation RBracLoc) {
3832 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3833 /*SuperLoc=*/SourceLocation(),
3834 Sel, Method, LBracLoc,
3835 SelectorLocs, RBracLoc, Args);
3836 }
3837
3838 /// Build a new Objective-C instance/class message to 'super'.
3840 Selector Sel,
3841 ArrayRef<SourceLocation> SelectorLocs,
3842 QualType SuperType,
3843 ObjCMethodDecl *Method,
3844 SourceLocation LBracLoc,
3845 MultiExprArg Args,
3846 SourceLocation RBracLoc) {
3847 return Method->isInstanceMethod()
3849 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3850 SelectorLocs, RBracLoc, Args)
3851 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3852 Sel, Method, LBracLoc,
3853 SelectorLocs, RBracLoc, Args);
3854 }
3855
3856 /// Build a new Objective-C ivar reference expression.
3857 ///
3858 /// By default, performs semantic analysis to build the new expression.
3859 /// Subclasses may override this routine to provide different behavior.
3861 SourceLocation IvarLoc,
3862 bool IsArrow, bool IsFreeIvar) {
3863 CXXScopeSpec SS;
3864 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3866 BaseArg, BaseArg->getType(),
3867 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3868 /*FirstQualifierInScope=*/nullptr, NameInfo,
3869 /*TemplateArgs=*/nullptr,
3870 /*S=*/nullptr);
3871 if (IsFreeIvar && Result.isUsable())
3872 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3873 return Result;
3874 }
3875
3876 /// Build a new Objective-C property reference expression.
3877 ///
3878 /// By default, performs semantic analysis to build the new expression.
3879 /// Subclasses may override this routine to provide different behavior.
3882 SourceLocation PropertyLoc) {
3883 CXXScopeSpec SS;
3884 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3885 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3886 /*FIXME:*/PropertyLoc,
3887 /*IsArrow=*/false,
3888 SS, SourceLocation(),
3889 /*FirstQualifierInScope=*/nullptr,
3890 NameInfo,
3891 /*TemplateArgs=*/nullptr,
3892 /*S=*/nullptr);
3893 }
3894
3895 /// Build a new Objective-C property reference expression.
3896 ///
3897 /// By default, performs semantic analysis to build the new expression.
3898 /// Subclasses may override this routine to provide different behavior.
3900 ObjCMethodDecl *Getter,
3901 ObjCMethodDecl *Setter,
3902 SourceLocation PropertyLoc) {
3903 // Since these expressions can only be value-dependent, we do not
3904 // need to perform semantic analysis again.
3905 return Owned(
3906 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
3908 PropertyLoc, Base));
3909 }
3910
3911 /// Build a new Objective-C "isa" expression.
3912 ///
3913 /// By default, performs semantic analysis to build the new expression.
3914 /// Subclasses may override this routine to provide different behavior.
3916 SourceLocation OpLoc, bool IsArrow) {
3917 CXXScopeSpec SS;
3918 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
3919 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3920 OpLoc, IsArrow,
3921 SS, SourceLocation(),
3922 /*FirstQualifierInScope=*/nullptr,
3923 NameInfo,
3924 /*TemplateArgs=*/nullptr,
3925 /*S=*/nullptr);
3926 }
3927
3928 /// Build a new shuffle vector expression.
3929 ///
3930 /// By default, performs semantic analysis to build the new expression.
3931 /// Subclasses may override this routine to provide different behavior.
3933 MultiExprArg SubExprs,
3934 SourceLocation RParenLoc) {
3935 // Find the declaration for __builtin_shufflevector
3936 const IdentifierInfo &Name
3937 = SemaRef.Context.Idents.get("__builtin_shufflevector");
3939 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
3940 assert(!Lookup.empty() && "No __builtin_shufflevector?");
3941
3942 // Build a reference to the __builtin_shufflevector builtin
3943 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
3944 Expr *Callee = new (SemaRef.Context)
3945 DeclRefExpr(SemaRef.Context, Builtin, false,
3946 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
3947 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
3948 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
3949 CK_BuiltinFnToFnPtr).get();
3950
3951 // Build the CallExpr
3952 ExprResult TheCall = CallExpr::Create(
3953 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
3954 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
3956
3957 // Type-check the __builtin_shufflevector expression.
3958 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
3959 }
3960
3961 /// Build a new convert vector expression.
3963 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
3964 SourceLocation RParenLoc) {
3965 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
3966 }
3967
3968 /// Build a new template argument pack expansion.
3969 ///
3970 /// By default, performs semantic analysis to build a new pack expansion
3971 /// for a template argument. Subclasses may override this routine to provide
3972 /// different behavior.
3975 std::optional<unsigned> NumExpansions) {
3976 switch (Pattern.getArgument().getKind()) {
3980 EllipsisLoc, NumExpansions);
3981 if (Result.isInvalid())
3982 return TemplateArgumentLoc();
3983
3984 return TemplateArgumentLoc(Result.get(), Result.get());
3985 }
3986
3988 return TemplateArgumentLoc(
3991 NumExpansions),
3992 Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(),
3993 EllipsisLoc);
3994
4002 llvm_unreachable("Pack expansion pattern has no parameter packs");
4003
4005 if (TypeSourceInfo *Expansion
4006 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4007 EllipsisLoc,
4008 NumExpansions))
4009 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4010 Expansion);
4011 break;
4012 }
4013
4014 return TemplateArgumentLoc();
4015 }
4016
4017 /// Build a new expression pack expansion.
4018 ///
4019 /// By default, performs semantic analysis to build a new pack expansion
4020 /// for an expression. Subclasses may override this routine to provide
4021 /// different behavior.
4023 std::optional<unsigned> NumExpansions) {
4024 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4025 }
4026
4027 /// Build a new C++1z fold-expression.
4028 ///
4029 /// By default, performs semantic analysis in order to build a new fold
4030 /// expression.
4032 SourceLocation LParenLoc, Expr *LHS,
4033 BinaryOperatorKind Operator,
4034 SourceLocation EllipsisLoc, Expr *RHS,
4035 SourceLocation RParenLoc,
4036 std::optional<unsigned> NumExpansions) {
4037 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4038 EllipsisLoc, RHS, RParenLoc,
4039 NumExpansions);
4040 }
4041
4043 LambdaScopeInfo *LSI) {
4044 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4045 if (Expr *Init = PVD->getInit())
4047 Init->containsUnexpandedParameterPack();
4048 else if (PVD->hasUninstantiatedDefaultArg())
4050 PVD->getUninstantiatedDefaultArg()
4051 ->containsUnexpandedParameterPack();
4052 }
4053 return getSema().BuildLambdaExpr(StartLoc, EndLoc, LSI);
4054 }
4055
4056 /// Build an empty C++1z fold-expression with the given operator.
4057 ///
4058 /// By default, produces the fallback value for the fold-expression, or
4059 /// produce an error if there is no fallback value.
4061 BinaryOperatorKind Operator) {
4062 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4063 }
4064
4065 /// Build a new atomic operation expression.
4066 ///
4067 /// By default, performs semantic analysis to build the new expression.
4068 /// Subclasses may override this routine to provide different behavior.
4071 SourceLocation RParenLoc) {
4072 // Use this for all of the locations, since we don't know the difference
4073 // between the call and the expr at this point.
4074 SourceRange Range{BuiltinLoc, RParenLoc};
4075 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4077 }
4078
4080 ArrayRef<Expr *> SubExprs, QualType Type) {
4081 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4082 }
4083
4085 SourceLocation BeginLoc,
4086 SourceLocation DirLoc,
4087 SourceLocation EndLoc,
4089 StmtResult StrBlock) {
4091 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4092 SourceLocation{}, EndLoc, Clauses, StrBlock);
4093 }
4094
4096 SourceLocation DirLoc,
4097 SourceLocation EndLoc,
4099 StmtResult Loop) {
4101 OpenACCDirectiveKind::Loop, BeginLoc, DirLoc, SourceLocation{},
4102 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, Loop);
4103 }
4104
4106 SourceLocation BeginLoc,
4107 SourceLocation DirLoc,
4108 SourceLocation EndLoc,
4110 StmtResult Loop) {
4112 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4113 SourceLocation{}, EndLoc, Clauses, Loop);
4114 }
4115
4117 SourceLocation DirLoc,
4118 SourceLocation EndLoc,
4120 StmtResult StrBlock) {
4122 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4123 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4124 }
4125
4128 SourceLocation DirLoc, SourceLocation EndLoc,
4129 ArrayRef<OpenACCClause *> Clauses) {
4132 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4133 }
4134
4137 SourceLocation DirLoc, SourceLocation EndLoc,
4138 ArrayRef<OpenACCClause *> Clauses) {
4141 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4142 }
4143
4145 SourceLocation DirLoc,
4146 SourceLocation EndLoc,
4148 StmtResult StrBlock) {
4151 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, StrBlock);
4152 }
4153
4155 SourceLocation DirLoc,
4156 SourceLocation EndLoc,
4157 ArrayRef<OpenACCClause *> Clauses) {
4159 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4160 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4161 }
4162
4165 SourceLocation DirLoc, SourceLocation EndLoc,
4166 ArrayRef<OpenACCClause *> Clauses) {
4169 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4170 }
4171
4173 SourceLocation DirLoc,
4174 SourceLocation EndLoc,
4175 ArrayRef<OpenACCClause *> Clauses) {
4177 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4178 SourceLocation{}, {}, SourceLocation{}, EndLoc, Clauses, {});
4179 }
4180
4182 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4183 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4184 SourceLocation RParenLoc, SourceLocation EndLoc,
4185 ArrayRef<OpenACCClause *> Clauses) {
4187 Exprs.push_back(DevNumExpr);
4188 Exprs.insert(Exprs.end(), QueueIdExprs.begin(), QueueIdExprs.end());
4190 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4191 Exprs, RParenLoc, EndLoc, Clauses, {});
4192 }
4193
4195 return getSema().OpenACC().ActOnOpenACCAsteriskSizeExpr(AsteriskLoc);
4196 }
4197
4198private:
4199 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
4200 QualType ObjectType,
4201 NamedDecl *FirstQualifierInScope,
4202 CXXScopeSpec &SS);
4203
4204 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4205 QualType ObjectType,
4206 NamedDecl *FirstQualifierInScope,
4207 CXXScopeSpec &SS);
4208
4209 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
4210 NamedDecl *FirstQualifierInScope,
4211 CXXScopeSpec &SS);
4212
4213 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4215 bool DeducibleTSTContext);
4216
4218 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4220
4222 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4223 OpenACCDirectiveKind DirKind,
4224 const OpenACCClause *OldClause);
4225};
4226
4227template <typename Derived>
4229 if (!S)
4230 return S;
4231
4232 switch (S->getStmtClass()) {
4233 case Stmt::NoStmtClass: break;
4234
4235 // Transform individual statement nodes
4236 // Pass SDK into statements that can produce a value
4237#define STMT(Node, Parent) \
4238 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4239#define VALUESTMT(Node, Parent) \
4240 case Stmt::Node##Class: \
4241 return getDerived().Transform##Node(cast<Node>(S), SDK);
4242#define ABSTRACT_STMT(Node)
4243#define EXPR(Node, Parent)
4244#include "clang/AST/StmtNodes.inc"
4245
4246 // Transform expressions by calling TransformExpr.
4247#define STMT(Node, Parent)
4248#define ABSTRACT_STMT(Stmt)
4249#define EXPR(Node, Parent) case Stmt::Node##Class:
4250#include "clang/AST/StmtNodes.inc"
4251 {
4252 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4253
4254 if (SDK == SDK_StmtExprResult)
4255 E = getSema().ActOnStmtExprResult(E);
4256 return getSema().ActOnExprStmt(E, SDK == SDK_Discarded);
4257 }
4258 }
4259
4260 return S;
4261}
4262
4263template<typename Derived>
4265 if (!S)
4266 return S;
4267
4268 switch (S->getClauseKind()) {
4269 default: break;
4270 // Transform individual clause nodes
4271#define GEN_CLANG_CLAUSE_CLASS
4272#define CLAUSE_CLASS(Enum, Str, Class) \
4273 case Enum: \
4274 return getDerived().Transform##Class(cast<Class>(S));
4275#include "llvm/Frontend/OpenMP/OMP.inc"
4276 }
4277
4278 return S;
4279}
4280
4281
4282template<typename Derived>
4284 if (!E)
4285 return E;
4286
4287 switch (E->getStmtClass()) {
4288 case Stmt::NoStmtClass: break;
4289#define STMT(Node, Parent) case Stmt::Node##Class: break;
4290#define ABSTRACT_STMT(Stmt)
4291#define EXPR(Node, Parent) \
4292 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4293#include "clang/AST/StmtNodes.inc"
4294 }
4295
4296 return E;
4297}
4298
4299template<typename Derived>
4301 bool NotCopyInit) {
4302 // Initializers are instantiated like expressions, except that various outer
4303 // layers are stripped.
4304 if (!Init)
4305 return Init;
4306
4307 if (auto *FE = dyn_cast<FullExpr>(Init))
4308 Init = FE->getSubExpr();
4309
4310 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4311 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4312 Init = OVE->getSourceExpr();
4313 }
4314
4315 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4316 Init = MTE->getSubExpr();
4317
4318 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4319 Init = Binder->getSubExpr();
4320
4321 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4322 Init = ICE->getSubExprAsWritten();
4323
4324 if (CXXStdInitializerListExpr *ILE =
4325 dyn_cast<CXXStdInitializerListExpr>(Init))
4326 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4327
4328 // If this is copy-initialization, we only need to reconstruct
4329 // InitListExprs. Other forms of copy-initialization will be a no-op if
4330 // the initializer is already the right type.
4331 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4332 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4333 return getDerived().TransformExpr(Init);
4334
4335 // Revert value-initialization back to empty parens.
4336 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4337 SourceRange Parens = VIE->getSourceRange();
4338 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4339 Parens.getEnd());
4340 }
4341
4342 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4343 if (isa<ImplicitValueInitExpr>(Init))
4344 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4345 SourceLocation());
4346
4347 // Revert initialization by constructor back to a parenthesized or braced list
4348 // of expressions. Any other form of initializer can just be reused directly.
4349 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4350 return getDerived().TransformExpr(Init);
4351
4352 // If the initialization implicitly converted an initializer list to a
4353 // std::initializer_list object, unwrap the std::initializer_list too.
4354 if (Construct && Construct->isStdInitListInitialization())
4355 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4356
4357 // Enter a list-init context if this was list initialization.
4360 Construct->isListInitialization());
4361
4362 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4363 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4364 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4365 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4366 SmallVector<Expr*, 8> NewArgs;
4367 bool ArgChanged = false;
4368 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4369 /*IsCall*/true, NewArgs, &ArgChanged))
4370 return ExprError();
4371
4372 // If this was list initialization, revert to syntactic list form.
4373 if (Construct->isListInitialization())
4374 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4375 Construct->getEndLoc());
4376
4377 // Build a ParenListExpr to represent anything else.
4379 if (Parens.isInvalid()) {
4380 // This was a variable declaration's initialization for which no initializer
4381 // was specified.
4382 assert(NewArgs.empty() &&
4383 "no parens or braces but have direct init with arguments?");
4384 return ExprEmpty();
4385 }
4386 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4387 Parens.getEnd());
4388}
4389
4390template<typename Derived>
4392 unsigned NumInputs,
4393 bool IsCall,
4394 SmallVectorImpl<Expr *> &Outputs,
4395 bool *ArgChanged) {
4396 for (unsigned I = 0; I != NumInputs; ++I) {
4397 // If requested, drop call arguments that need to be dropped.
4398 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4399 if (ArgChanged)
4400 *ArgChanged = true;
4401
4402 break;
4403 }
4404
4405 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4406 Expr *Pattern = Expansion->getPattern();
4407
4409 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4410 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4411
4412 // Determine whether the set of unexpanded parameter packs can and should
4413 // be expanded.
4414 bool Expand = true;
4415 bool RetainExpansion = false;
4416 std::optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
4417 std::optional<unsigned> NumExpansions = OrigNumExpansions;
4418 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
4419 Pattern->getSourceRange(),
4420 Unexpanded,
4421 Expand, RetainExpansion,
4422 NumExpansions))
4423 return true;
4424
4425 if (!Expand) {
4426 // The transform has determined that we should perform a simple
4427 // transformation on the pack expansion, producing another pack
4428 // expansion.
4429 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4430 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4431 if (OutPattern.isInvalid())
4432 return true;
4433
4434 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4435 Expansion->getEllipsisLoc(),
4436 NumExpansions);
4437 if (Out.isInvalid())
4438 return true;
4439
4440 if (ArgChanged)
4441 *ArgChanged = true;
4442 Outputs.push_back(Out.get());
4443 continue;
4444 }
4445
4446 // Record right away that the argument was changed. This needs
4447 // to happen even if the array expands to nothing.
4448 if (ArgChanged) *ArgChanged = true;
4449
4450 // The transform has determined that we should perform an elementwise
4451 // expansion of the pattern. Do so.
4452 for (unsigned I = 0; I != *NumExpansions; ++I) {
4453 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4454 ExprResult Out = getDerived().TransformExpr(Pattern);
4455 if (Out.isInvalid())
4456 return true;
4457
4458 if (Out.get()->containsUnexpandedParameterPack()) {
4459 Out = getDerived().RebuildPackExpansion(
4460 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4461 if (Out.isInvalid())
4462 return true;
4463 }
4464
4465 Outputs.push_back(Out.get());
4466 }
4467
4468 // If we're supposed to retain a pack expansion, do so by temporarily
4469 // forgetting the partially-substituted parameter pack.
4470 if (RetainExpansion) {
4471 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4472
4473 ExprResult Out = getDerived().TransformExpr(Pattern);
4474 if (Out.isInvalid())
4475 return true;
4476
4477 Out = getDerived().RebuildPackExpansion(
4478 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4479 if (Out.isInvalid())
4480 return true;
4481
4482 Outputs.push_back(Out.get());
4483 }
4484
4485 continue;
4486 }
4487
4489 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4490 : getDerived().TransformExpr(Inputs[I]);
4491 if (Result.isInvalid())
4492 return true;
4493
4494 if (Result.get() != Inputs[I] && ArgChanged)
4495 *ArgChanged = true;
4496
4497 Outputs.push_back(Result.get());
4498 }
4499
4500 return false;
4501}
4502
4503template <typename Derived>
4506 if (Var) {
4507 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4508 getDerived().TransformDefinition(Var->getLocation(), Var));
4509
4510 if (!ConditionVar)
4511 return Sema::ConditionError();
4512
4513 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4514 }
4515
4516 if (Expr) {
4517 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4518
4519 if (CondExpr.isInvalid())
4520 return Sema::ConditionError();
4521
4522 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4523 /*MissingOK=*/true);
4524 }
4525
4526 return Sema::ConditionResult();
4527}
4528
4529template <typename Derived>
4531 NestedNameSpecifierLoc NNS, QualType ObjectType,
4532 NamedDecl *FirstQualifierInScope) {
4534
4535 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4536 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4537 Qualifier = Qualifier.getPrefix())
4538 Qualifiers.push_back(Qualifier);
4539 };
4540 insertNNS(NNS);
4541
4542 CXXScopeSpec SS;
4543 while (!Qualifiers.empty()) {
4544 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4546
4547 switch (QNNS->getKind()) {
4551 ObjectType);
4552 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false,
4553 SS, FirstQualifierInScope, false))
4554 return NestedNameSpecifierLoc();
4555 break;
4556 }
4557
4559 NamespaceDecl *NS =
4560 cast_or_null<NamespaceDecl>(getDerived().TransformDecl(
4561 Q.getLocalBeginLoc(), QNNS->getAsNamespace()));
4562 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4563 break;
4564 }
4565
4567 NamespaceAliasDecl *Alias =
4568 cast_or_null<NamespaceAliasDecl>(getDerived().TransformDecl(
4570 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
4571 Q.getLocalEndLoc());
4572 break;
4573 }
4574
4576 // There is no meaningful transformation that one could perform on the
4577 // global scope.
4578 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4579 break;
4580
4582 CXXRecordDecl *RD =
4583 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
4584 SourceLocation(), QNNS->getAsRecordDecl()));
4585 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
4586 break;
4587 }
4588
4591 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
4592 FirstQualifierInScope, SS);
4593
4594 if (!TL)
4595 return NestedNameSpecifierLoc();
4596
4597 QualType T = TL.getType();
4598 if (T->isDependentType() || T->isRecordType() ||
4599 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4600 if (T->isEnumeralType())
4601 SemaRef.Diag(TL.getBeginLoc(),
4602 diag::warn_cxx98_compat_enum_nested_name_spec);
4603
4604 if (const auto ETL = TL.getAs<ElaboratedTypeLoc>()) {
4605 SS.Adopt(ETL.getQualifierLoc());
4606 TL = ETL.getNamedTypeLoc();
4607 }
4608
4609 SS.Extend(SemaRef.Context, TL.getTemplateKeywordLoc(), TL,
4610 Q.getLocalEndLoc());
4611 break;
4612 }
4613 // If the nested-name-specifier is an invalid type def, don't emit an
4614 // error because a previous error should have already been emitted.
4616 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
4617 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4618 << T << SS.getRange();
4619 }
4620 return NestedNameSpecifierLoc();
4621 }
4622 }
4623
4624 // The qualifier-in-scope and object type only apply to the leftmost entity.
4625 FirstQualifierInScope = nullptr;
4626 ObjectType = QualType();
4627 }
4628
4629 // Don't rebuild the nested-name-specifier if we don't have to.
4630 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4631 !getDerived().AlwaysRebuild())
4632 return NNS;
4633
4634 // If we can re-use the source-location data from the original
4635 // nested-name-specifier, do so.
4636 if (SS.location_size() == NNS.getDataLength() &&
4637 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4639
4640 // Allocate new nested-name-specifier location information.
4641 return SS.getWithLocInContext(SemaRef.Context);
4642}
4643
4644template<typename Derived>
4648 DeclarationName Name = NameInfo.getName();
4649 if (!Name)
4650 return DeclarationNameInfo();
4651
4652 switch (Name.getNameKind()) {
4660 return NameInfo;
4661
4663 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4664 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4665 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4666 if (!NewTemplate)
4667 return DeclarationNameInfo();
4668
4669 DeclarationNameInfo NewNameInfo(NameInfo);
4670 NewNameInfo.setName(
4672 return NewNameInfo;
4673 }
4674
4678 TypeSourceInfo *NewTInfo;
4679 CanQualType NewCanTy;
4680 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4681 NewTInfo = getDerived().TransformType(OldTInfo);
4682 if (!NewTInfo)
4683 return DeclarationNameInfo();
4684 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4685 }
4686 else {
4687 NewTInfo = nullptr;
4688 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4689 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4690 if (NewT.isNull())
4691 return DeclarationNameInfo();
4692 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4693 }
4694
4695 DeclarationName NewName
4696 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4697 NewCanTy);
4698 DeclarationNameInfo NewNameInfo(NameInfo);
4699 NewNameInfo.setName(NewName);
4700 NewNameInfo.setNamedTypeInfo(NewTInfo);
4701 return NewNameInfo;
4702 }
4703 }
4704
4705 llvm_unreachable("Unknown name kind.");
4706}
4707
4708template<typename Derived>
4711 TemplateName Name,
4712 SourceLocation NameLoc,
4713 QualType ObjectType,
4714 NamedDecl *FirstQualifierInScope,
4715 bool AllowInjectedClassName) {
4716 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
4717 TemplateDecl *Template = QTN->getUnderlyingTemplate().getAsTemplateDecl();
4718 assert(Template && "qualified template name must refer to a template");
4719
4720 TemplateDecl *TransTemplate
4721 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4722 Template));
4723 if (!TransTemplate)
4724 return TemplateName();
4725
4726 if (!getDerived().AlwaysRebuild() &&
4727 SS.getScopeRep() == QTN->getQualifier() &&
4728 TransTemplate == Template)
4729 return Name;
4730
4731 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4732 TransTemplate);
4733 }
4734
4735 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
4736 if (SS.getScopeRep()) {
4737 // These apply to the scope specifier, not the template.
4738 ObjectType = QualType();
4739 FirstQualifierInScope = nullptr;
4740 }
4741
4742 if (!getDerived().AlwaysRebuild() &&
4743 SS.getScopeRep() == DTN->getQualifier() &&
4744 ObjectType.isNull())
4745 return Name;
4746
4747 // FIXME: Preserve the location of the "template" keyword.
4748 SourceLocation TemplateKWLoc = NameLoc;
4749
4750 if (DTN->isIdentifier()) {
4751 return getDerived().RebuildTemplateName(SS,
4752 TemplateKWLoc,
4753 *DTN->getIdentifier(),
4754 NameLoc,
4755 ObjectType,
4756 FirstQualifierInScope,
4757 AllowInjectedClassName);
4758 }
4759
4760 return getDerived().RebuildTemplateName(SS, TemplateKWLoc,
4761 DTN->getOperator(), NameLoc,
4762 ObjectType, AllowInjectedClassName);
4763 }
4764
4765 // FIXME: Try to preserve more of the TemplateName.
4766 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
4767 TemplateDecl *TransTemplate
4768 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
4769 Template));
4770 if (!TransTemplate)
4771 return TemplateName();
4772
4773 return getDerived().RebuildTemplateName(SS, /*TemplateKeyword=*/false,
4774 TransTemplate);
4775 }
4776
4778 = Name.getAsSubstTemplateTemplateParmPack()) {
4779 return getDerived().RebuildTemplateName(
4780 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4781 SubstPack->getIndex(), SubstPack->getFinal());
4782 }
4783
4784 // These should be getting filtered out before they reach the AST.
4785 llvm_unreachable("overloaded function decl survived to here");
4786}
4787
4788template<typename Derived>
4790 const TemplateArgument &Arg,
4791 TemplateArgumentLoc &Output) {
4792 Output = getSema().getTrivialTemplateArgumentLoc(
4793 Arg, QualType(), getDerived().getBaseLocation());
4794}
4795
4796template <typename Derived>
4798 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
4799 bool Uneval) {
4800 const TemplateArgument &Arg = Input.getArgument();
4801 switch (Arg.getKind()) {
4804 llvm_unreachable("Unexpected TemplateArgument");
4805
4810 // Transform a resolved template argument straight to a resolved template
4811 // argument. We get here when substituting into an already-substituted
4812 // template type argument during concept satisfaction checking.
4814 QualType NewT = getDerived().TransformType(T);
4815 if (NewT.isNull())
4816 return true;
4817
4819 ? Arg.getAsDecl()
4820 : nullptr;
4821 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
4822 getDerived().getBaseLocation(), D))
4823 : nullptr;
4824 if (D && !NewD)
4825 return true;
4826
4827 if (NewT == T && D == NewD)
4828 Output = Input;
4829 else if (Arg.getKind() == TemplateArgument::Integral)
4830 Output = TemplateArgumentLoc(
4831 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
4833 else if (Arg.getKind() == TemplateArgument::NullPtr)
4834 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
4836 else if (Arg.getKind() == TemplateArgument::Declaration)
4837 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
4840 Output = TemplateArgumentLoc(
4841 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
4843 else
4844 llvm_unreachable("unexpected template argument kind");
4845
4846 return false;
4847 }
4848
4850 TypeSourceInfo *DI = Input.getTypeSourceInfo();
4851 if (!DI)
4852 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
4853
4854 DI = getDerived().TransformType(DI);
4855 if (!DI)
4856 return true;
4857
4858 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
4859 return false;
4860 }
4861
4863 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
4864 if (QualifierLoc) {
4865 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
4866 if (!QualifierLoc)
4867 return true;
4868 }
4869
4870 CXXScopeSpec SS;
4871 SS.Adopt(QualifierLoc);
4872 TemplateName Template = getDerived().TransformTemplateName(
4873 SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
4874 if (Template.isNull())
4875 return true;
4876
4877 Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template),
4878 QualifierLoc, Input.getTemplateNameLoc());
4879 return false;
4880 }
4881
4883 llvm_unreachable("Caller should expand pack expansions");
4884
4886 // Template argument expressions are constant expressions.
4888 getSema(),
4891 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
4893
4894 Expr *InputExpr = Input.getSourceExpression();
4895 if (!InputExpr)
4896 InputExpr = Input.getArgument().getAsExpr();
4897
4898 ExprResult E = getDerived().TransformExpr(InputExpr);
4899 E = SemaRef.ActOnConstantExpression(E);
4900 if (E.isInvalid())
4901 return true;
4902 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
4903 return false;
4904 }
4905 }
4906
4907 // Work around bogus GCC warning
4908 return true;
4909}
4910
4911/// Iterator adaptor that invents template argument location information
4912/// for each of the template arguments in its underlying iterator.
4913template<typename Derived, typename InputIterator>
4916 InputIterator Iter;
4917
4918public:
4921 typedef typename std::iterator_traits<InputIterator>::difference_type
4923 typedef std::input_iterator_tag iterator_category;
4924
4925 class pointer {
4927
4928 public:
4929 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4930
4931 const TemplateArgumentLoc *operator->() const { return &Arg; }
4932 };
4933
4935 InputIterator Iter)
4936 : Self(Self), Iter(Iter) { }
4937
4939 ++Iter;
4940 return *this;
4941 }
4942
4945 ++(*this);
4946 return Old;
4947 }
4948
4951 Self.InventTemplateArgumentLoc(*Iter, Result);
4952 return Result;
4953 }
4954
4955 pointer operator->() const { return pointer(**this); }
4956
4959 return X.Iter == Y.Iter;
4960 }
4961
4964 return X.Iter != Y.Iter;
4965 }
4966};
4967
4968template<typename Derived>
4969template<typename InputIterator>
4971 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
4972 bool Uneval) {
4973 for (; First != Last; ++First) {
4976
4977 if (In.getArgument().getKind() == TemplateArgument::Pack) {
4978 // Unpack argument packs, which we translate them into separate
4979 // arguments.
4980 // FIXME: We could do much better if we could guarantee that the
4981 // TemplateArgumentLocInfo for the pack expansion would be usable for
4982 // all of the template arguments in the argument pack.
4983 typedef TemplateArgumentLocInventIterator<Derived,
4985 PackLocIterator;
4986 if (TransformTemplateArguments(PackLocIterator(*this,
4987 In.getArgument().pack_begin()),
4988 PackLocIterator(*this,
4989 In.getArgument().pack_end()),
4990 Outputs, Uneval))
4991 return true;
4992
4993 continue;
4994 }
4995
4996 if (In.getArgument().isPackExpansion()) {
4997 // We have a pack expansion, for which we will be substituting into
4998 // the pattern.
4999 SourceLocation Ellipsis;
5000 std::optional<unsigned> OrigNumExpansions;
5001 TemplateArgumentLoc Pattern
5002 = getSema().getTemplateArgumentPackExpansionPattern(
5003 In, Ellipsis, OrigNumExpansions);
5004
5006 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5007 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5008
5009 // Determine whether the set of unexpanded parameter packs can and should
5010 // be expanded.
5011 bool Expand = true;
5012 bool RetainExpansion = false;
5013 std::optional<unsigned> NumExpansions = OrigNumExpansions;
5014 if (getDerived().TryExpandParameterPacks(Ellipsis,
5015 Pattern.getSourceRange(),
5016 Unexpanded,
5017 Expand,
5018 RetainExpansion,
5019 NumExpansions))
5020 return true;
5021
5022 if (!Expand) {
5023 // The transform has determined that we should perform a simple
5024 // transformation on the pack expansion, producing another pack
5025 // expansion.
5026 TemplateArgumentLoc OutPattern;
5027 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5028 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5029 return true;
5030
5031 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
5032 NumExpansions);
5033 if (Out.getArgument().isNull())
5034 return true;
5035
5036 Outputs.addArgument(Out);
5037 continue;
5038 }
5039
5040 // The transform has determined that we should perform an elementwise
5041 // expansion of the pattern. Do so.
5042 for (unsigned I = 0; I != *NumExpansions; ++I) {
5043 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
5044
5045 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5046 return true;
5047
5048 if (Out.getArgument().containsUnexpandedParameterPack()) {
5049 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5050 OrigNumExpansions);
5051 if (Out.getArgument().isNull())
5052 return true;
5053 }
5054
5055 Outputs.addArgument(Out);
5056 }
5057
5058 // If we're supposed to retain a pack expansion, do so by temporarily
5059 // forgetting the partially-substituted parameter pack.
5060 if (RetainExpansion) {
5061 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5062
5063 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
5064 return true;
5065
5066 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
5067 OrigNumExpansions);
5068 if (Out.getArgument().isNull())
5069 return true;
5070
5071 Outputs.addArgument(Out);
5072 }
5073
5074 continue;
5075 }
5076
5077 // The simple case:
5078 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5079 return true;
5080
5081 Outputs.addArgument(Out);
5082 }
5083
5084 return false;
5085
5086}
5087
5088//===----------------------------------------------------------------------===//
5089// Type transformation
5090//===----------------------------------------------------------------------===//
5091
5092template<typename Derived>
5094 if (getDerived().AlreadyTransformed(T))
5095 return T;
5096
5097 // Temporary workaround. All of these transformations should
5098 // eventually turn into transformations on TypeLocs.
5099 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5100 getDerived().getBaseLocation());
5101
5102 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
5103
5104 if (!NewDI)
5105 return QualType();
5106
5107 return NewDI->getType();
5108}
5109
5110template<typename Derived>
5112 // Refine the base location to the type's location.
5113 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5114 getDerived().getBaseEntity());
5115 if (getDerived().AlreadyTransformed(DI->getType()))
5116 return DI;
5117
5118 TypeLocBuilder TLB;
5119
5120 TypeLoc TL = DI->getTypeLoc();
5121 TLB.reserve(TL.getFullDataSize());
5122
5123 QualType Result = getDerived().TransformType(TLB, TL);
5124 if (Result.isNull())
5125 return nullptr;
5126
5127 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5128}
5129
5130template<typename Derived>
5133 switch (T.getTypeLocClass()) {
5134#define ABSTRACT_TYPELOC(CLASS, PARENT)
5135#define TYPELOC(CLASS, PARENT) \
5136 case TypeLoc::CLASS: \
5137 return getDerived().Transform##CLASS##Type(TLB, \
5138 T.castAs<CLASS##TypeLoc>());
5139#include "clang/AST/TypeLocNodes.def"
5140 }
5141
5142 llvm_unreachable("unhandled type loc!");
5143}
5144
5145template<typename Derived>
5147 if (!isa<DependentNameType>(T))
5148 return TransformType(T);
5149
5150 if (getDerived().AlreadyTransformed(T))
5151 return T;
5152 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
5153 getDerived().getBaseLocation());
5154 TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI);
5155 return NewDI ? NewDI->getType() : QualType();
5156}
5157
5158template<typename Derived>
5161 if (!isa<DependentNameType>(DI->getType()))
5162 return TransformType(DI);
5163
5164 // Refine the base location to the type's location.
5165 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
5166 getDerived().getBaseEntity());
5167 if (getDerived().AlreadyTransformed(DI->getType()))
5168 return DI;
5169
5170 TypeLocBuilder TLB;
5171
5172 TypeLoc TL = DI->getTypeLoc();
5173 TLB.reserve(TL.getFullDataSize());
5174
5175 auto QTL = TL.getAs<QualifiedTypeLoc>();
5176 if (QTL)
5177 TL = QTL.getUnqualifiedLoc();
5178
5179 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5180
5181 QualType Result = getDerived().TransformDependentNameType(
5182 TLB, DNTL, /*DeducedTSTContext*/true);
5183 if (Result.isNull())
5184 return nullptr;
5185
5186 if (QTL) {
5187 Result = getDerived().RebuildQualifiedType(Result, QTL);
5188 if (Result.isNull())
5189 return nullptr;
5191 }
5192
5193 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5194}
5195
5196template<typename Derived>
5201 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5202 auto SuppressObjCLifetime =
5203 T.getType().getLocalQualifiers().hasObjCLifetime();
5204 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5205 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5206 SuppressObjCLifetime);
5207 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5208 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5209 TLB, STTP, SuppressObjCLifetime);
5210 } else {
5211 Result = getDerived().TransformType(TLB, UnqualTL);
5212 }
5213
5214 if (Result.isNull())
5215 return QualType();
5216
5217 Result = getDerived().RebuildQualifiedType(Result, T);
5218
5219 if (Result.isNull())
5220 return QualType();
5221
5222 // RebuildQualifiedType might have updated the type, but not in a way
5223 // that invalidates the TypeLoc. (There's no location information for
5224 // qualifiers.)
5226
5227 return Result;
5228}
5229
5230template <typename Derived>
5232 QualifiedTypeLoc TL) {
5233
5235 Qualifiers Quals = TL.getType().getLocalQualifiers();
5236
5237 if ((T.getAddressSpace() != LangAS::Default &&
5238 Quals.getAddressSpace() != LangAS::Default) &&
5239 T.getAddressSpace() != Quals.getAddressSpace()) {
5240 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5241 << TL.getType() << T;
5242 return QualType();
5243 }
5244
5245 // C++ [dcl.fct]p7:
5246 // [When] adding cv-qualifications on top of the function type [...] the
5247 // cv-qualifiers are ignored.
5248 if (T->isFunctionType()) {
5250 Quals.getAddressSpace());
5251 return T;
5252 }
5253
5254 // C++ [dcl.ref]p1:
5255 // when the cv-qualifiers are introduced through the use of a typedef-name
5256 // or decltype-specifier [...] the cv-qualifiers are ignored.
5257 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5258 // applied to a reference type.
5259 if (T->isReferenceType()) {
5260 // The only qualifier that applies to a reference type is restrict.
5261 if (!Quals.hasRestrict())
5262 return T;
5264 }
5265
5266 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5267 // resulting type.
5268 if (Quals.hasObjCLifetime()) {
5269 if (!T->isObjCLifetimeType() && !T->isDependentType())
5270 Quals.removeObjCLifetime();
5271 else if (T.getObjCLifetime()) {
5272 // Objective-C ARC:
5273 // A lifetime qualifier applied to a substituted template parameter
5274 // overrides the lifetime qualifier from the template argument.
5275 const AutoType *AutoTy;
5276 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5277 // 'auto' types behave the same way as template parameters.
5278 QualType Deduced = AutoTy->getDeducedType();
5279 Qualifiers Qs = Deduced.getQualifiers();
5280 Qs.removeObjCLifetime();
5281 Deduced =
5282 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5283 T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(),
5284 AutoTy->isDependentType(),
5285 /*isPack=*/false,
5286 AutoTy->getTypeConstraintConcept(),
5287 AutoTy->getTypeConstraintArguments());
5288 } else {
5289 // Otherwise, complain about the addition of a qualifier to an
5290 // already-qualified type.
5291 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5292 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5293 Quals.removeObjCLifetime();
5294 }
5295 }
5296 }
5297
5298 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5299}
5300
5301template<typename Derived>
5302TypeLoc
5304 QualType ObjectType,
5305 NamedDecl *UnqualLookup,
5306 CXXScopeSpec &SS) {
5307 if (getDerived().AlreadyTransformed(TL.getType()))
5308 return TL;
5309
5310 TypeSourceInfo *TSI =
5311 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
5312 if (TSI)
5313 return TSI->getTypeLoc();
5314 return TypeLoc();
5315}
5316
5317template<typename Derived>
5318TypeSourceInfo *
5319TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
5320 QualType ObjectType,
5321 NamedDecl *UnqualLookup,
5322 CXXScopeSpec &SS) {
5323 if (getDerived().AlreadyTransformed(TSInfo->getType()))
5324 return TSInfo;
5325
5326 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
5327 UnqualLookup, SS);
5328}
5329
5330template <typename Derived>
5331TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
5332 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
5333 CXXScopeSpec &SS) {
5334 QualType T = TL.getType();
5335 assert(!getDerived().AlreadyTransformed(T));
5336
5337 TypeLocBuilder TLB;
5338 QualType Result;
5339
5340 if (isa<TemplateSpecializationType>(T)) {
5341 TemplateSpecializationTypeLoc SpecTL =
5342 TL.castAs<TemplateSpecializationTypeLoc>();
5343
5344 TemplateName Template = getDerived().TransformTemplateName(
5345 SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(),
5346 ObjectType, UnqualLookup, /*AllowInjectedClassName*/true);
5347 if (Template.isNull())
5348 return nullptr;
5349
5350 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
5351 Template);
5352 } else if (isa<DependentTemplateSpecializationType>(T)) {
5353 DependentTemplateSpecializationTypeLoc SpecTL =
5354 TL.castAs<DependentTemplateSpecializationTypeLoc>();
5355
5356 TemplateName Template
5357 = getDerived().RebuildTemplateName(SS,
5358 SpecTL.getTemplateKeywordLoc(),
5359 *SpecTL.getTypePtr()->getIdentifier(),
5360 SpecTL.getTemplateNameLoc(),
5361 ObjectType, UnqualLookup,
5362 /*AllowInjectedClassName*/true);
5363 if (Template.isNull())
5364 return nullptr;
5365
5366 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
5367 SpecTL,
5368 Template,
5369 SS);
5370 } else {
5371 // Nothing special needs to be done for these.
5372 Result = getDerived().TransformType(TLB, TL);
5373 }
5374
5375 if (Result.isNull())
5376 return nullptr;
5377
5378 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5379}
5380
5381template <class TyLoc> static inline
5383 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5384 NewT.setNameLoc(T.getNameLoc());
5385 return T.getType();
5386}
5387
5388template<typename Derived>
5389QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5390 BuiltinTypeLoc T) {
5391 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5392 NewT.setBuiltinLoc(T.getBuiltinLoc());
5393 if (T.needsExtraLocalData())
5394 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5395 return T.getType();
5396}
5397
5398template<typename Derived>
5399QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
5400 ComplexTypeLoc T) {
5401 // FIXME: recurse?
5402 return TransformTypeSpecType(TLB, T);
5403}
5404
5405template <typename Derived>
5406QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
5407 AdjustedTypeLoc TL) {
5408 // Adjustments applied during transformation are handled elsewhere.
5409 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5410}
5411
5412template<typename Derived>
5413QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
5414 DecayedTypeLoc TL) {
5415 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5416 if (OriginalType.isNull())
5417 return QualType();
5418
5419 QualType Result = TL.getType();
5420 if (getDerived().AlwaysRebuild() ||
5421 OriginalType != TL.getOriginalLoc().getType())
5422 Result = SemaRef.Context.getDecayedType(OriginalType);
5423 TLB.push<DecayedTypeLoc>(Result);
5424 // Nothing to set for DecayedTypeLoc.
5425 return Result;
5426}
5427
5428template <typename Derived>
5429QualType
5430TreeTransform<Derived>::TransformArrayParameterType(TypeLocBuilder &TLB,
5431 ArrayParameterTypeLoc TL) {
5432 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5433 if (OriginalType.isNull())
5434 return QualType();
5435
5436 QualType Result = TL.getType();
5437 if (getDerived().AlwaysRebuild() ||
5438 OriginalType != TL.getElementLoc().getType())
5439 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5440 TLB.push<ArrayParameterTypeLoc>(Result);
5441 // Nothing to set for ArrayParameterTypeLoc.
5442 return Result;
5443}
5444
5445template<typename Derived>
5446QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
5447 PointerTypeLoc TL) {
5448 QualType PointeeType
5449 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5450 if (PointeeType.isNull())
5451 return QualType();
5452
5453 QualType Result = TL.getType();
5454 if (PointeeType->getAs<ObjCObjectType>()) {
5455 // A dependent pointer type 'T *' has is being transformed such
5456 // that an Objective-C class type is being replaced for 'T'. The
5457 // resulting pointer type is an ObjCObjectPointerType, not a
5458 // PointerType.
5459 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5460
5461 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5462 NewT.setStarLoc(TL.getStarLoc());
5463 return Result;
5464 }
5465
5466 if (getDerived().AlwaysRebuild() ||
5467 PointeeType != TL.getPointeeLoc().getType()) {
5468 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5469 if (Result.isNull())
5470 return QualType();
5471 }
5472
5473 // Objective-C ARC can add lifetime qualifiers to the type that we're
5474 // pointing to.
5475 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5476
5477 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5478 NewT.setSigilLoc(TL.getSigilLoc());
5479 return Result;
5480}
5481
5482template<typename Derived>
5483QualType
5484TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
5485 BlockPointerTypeLoc TL) {
5486 QualType PointeeType
5487 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5488 if (PointeeType.isNull())
5489 return QualType();
5490
5491 QualType Result = TL.getType();
5492 if (getDerived().AlwaysRebuild() ||
5493 PointeeType != TL.getPointeeLoc().getType()) {
5494 Result = getDerived().RebuildBlockPointerType(PointeeType,
5495 TL.getSigilLoc());
5496 if (Result.isNull())
5497 return QualType();
5498 }
5499
5500 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
5501 NewT.setSigilLoc(TL.getSigilLoc());
5502 return Result;
5503}
5504
5505/// Transforms a reference type. Note that somewhat paradoxically we
5506/// don't care whether the type itself is an l-value type or an r-value
5507/// type; we only care if the type was *written* as an l-value type
5508/// or an r-value type.
5509template<typename Derived>
5510QualType
5512 ReferenceTypeLoc TL) {
5513 const ReferenceType *T = TL.getTypePtr();
5514
5515 // Note that this works with the pointee-as-written.
5516 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5517 if (PointeeType.isNull())
5518 return QualType();
5519
5520 QualType Result = TL.getType();
5521 if (getDerived().AlwaysRebuild() ||
5522 PointeeType != T->getPointeeTypeAsWritten()) {
5523 Result = getDerived().RebuildReferenceType(PointeeType,
5524 T->isSpelledAsLValue(),
5525 TL.getSigilLoc());
5526 if (Result.isNull())
5527 return QualType();
5528 }
5529
5530 // Objective-C ARC can add lifetime qualifiers to the type that we're
5531 // referring to.
5534
5535 // r-value references can be rebuilt as l-value references.
5536 ReferenceTypeLoc NewTL;
5537 if (isa<LValueReferenceType>(Result))
5538 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5539 else
5540 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5541 NewTL.setSigilLoc(TL.getSigilLoc());
5542
5543 return Result;
5544}
5545
5546template<typename Derived>
5550 return TransformReferenceType(TLB, TL);
5551}
5552
5553template<typename Derived>
5554QualType
5555TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5556 RValueReferenceTypeLoc TL) {
5557 return TransformReferenceType(TLB, TL);
5558}
5559
5560template<typename Derived>
5561QualType
5562TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
5563 MemberPointerTypeLoc TL) {
5564 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5565 if (PointeeType.isNull())
5566 return QualType();
5567
5568 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
5569 TypeSourceInfo *NewClsTInfo = nullptr;
5570 if (OldClsTInfo) {
5571 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
5572 if (!NewClsTInfo)
5573 return QualType();
5574 }
5575
5576 const MemberPointerType *T = TL.getTypePtr();
5577 QualType OldClsType = QualType(T->getClass(), 0);
5578 QualType NewClsType;
5579 if (NewClsTInfo)
5580 NewClsType = NewClsTInfo->getType();
5581 else {
5582 NewClsType = getDerived().TransformType(OldClsType);
5583 if (NewClsType.isNull())
5584 return QualType();
5585 }
5586
5587 QualType Result = TL.getType();
5588 if (getDerived().AlwaysRebuild() ||
5589 PointeeType != T->getPointeeType() ||
5590 NewClsType != OldClsType) {
5591 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
5592 TL.getStarLoc());
5593 if (Result.isNull())
5594 return QualType();
5595 }
5596
5597 // If we had to adjust the pointee type when building a member pointer, make
5598 // sure to push TypeLoc info for it.
5599 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5600 if (MPT && PointeeType != MPT->getPointeeType()) {
5601 assert(isa<AdjustedType>(MPT->getPointeeType()));
5602 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5603 }
5604
5605 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
5606 NewTL.setSigilLoc(TL.getSigilLoc());
5607 NewTL.setClassTInfo(NewClsTInfo);
5608
5609 return Result;
5610}
5611
5612template<typename Derived>
5613QualType
5614TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
5615 ConstantArrayTypeLoc TL) {
5616 const ConstantArrayType *T = TL.getTypePtr();
5617 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5618 if (ElementType.isNull())
5619 return QualType();
5620
5621 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5622 Expr *OldSize = TL.getSizeExpr();
5623 if (!OldSize)
5624 OldSize = const_cast<Expr*>(T->getSizeExpr());
5625 Expr *NewSize = nullptr;
5626 if (OldSize) {
5627 EnterExpressionEvaluationContext Unevaluated(
5629 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5630 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5631 }
5632
5633 QualType Result = TL.getType();
5634 if (getDerived().AlwaysRebuild() ||
5635 ElementType != T->getElementType() ||
5636 (T->getSizeExpr() && NewSize != OldSize)) {
5637 Result = getDerived().RebuildConstantArrayType(ElementType,
5638 T->getSizeModifier(),
5639 T->getSize(), NewSize,
5640 T->getIndexTypeCVRQualifiers(),
5641 TL.getBracketsRange());
5642 if (Result.isNull())
5643 return QualType();
5644 }
5645
5646 // We might have either a ConstantArrayType or a VariableArrayType now:
5647 // a ConstantArrayType is allowed to have an element type which is a
5648 // VariableArrayType if the type is dependent. Fortunately, all array
5649 // types have the same location layout.
5650 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5651 NewTL.setLBracketLoc(TL.getLBracketLoc());
5652 NewTL.setRBracketLoc(TL.getRBracketLoc());
5653 NewTL.setSizeExpr(NewSize);
5654
5655 return Result;
5656}
5657
5658template<typename Derived>
5659QualType TreeTransform<Derived>::TransformIncompleteArrayType(
5660 TypeLocBuilder &TLB,
5661 IncompleteArrayTypeLoc TL) {
5662 const IncompleteArrayType *T = TL.getTypePtr();
5663 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5664 if (ElementType.isNull())
5665 return QualType();
5666
5667 QualType Result = TL.getType();
5668 if (getDerived().AlwaysRebuild() ||
5669 ElementType != T->getElementType()) {
5670 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5671 T->getSizeModifier(),
5672 T->getIndexTypeCVRQualifiers(),
5673 TL.getBracketsRange());
5674 if (Result.isNull())
5675 return QualType();
5676 }
5677
5678 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
5679 NewTL.setLBracketLoc(TL.getLBracketLoc());
5680 NewTL.setRBracketLoc(TL.getRBracketLoc());
5681 NewTL.setSizeExpr(nullptr);
5682
5683 return Result;
5684}
5685
5686template<typename Derived>
5687QualType
5688TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
5689 VariableArrayTypeLoc TL) {
5690 const VariableArrayType *T = TL.getTypePtr();
5691 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5692 if (ElementType.isNull())
5693 return QualType();
5694
5695 ExprResult SizeResult;
5696 {
5697 EnterExpressionEvaluationContext Context(
5699 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5700 }
5701 if (SizeResult.isInvalid())
5702 return QualType();
5703 SizeResult =
5704 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5705 if (SizeResult.isInvalid())
5706 return QualType();
5707
5708 Expr *Size = SizeResult.get();
5709
5710 QualType Result = TL.getType();
5711 if (getDerived().AlwaysRebuild() ||
5712 ElementType != T->getElementType() ||
5713 Size != T->getSizeExpr()) {
5714 Result = getDerived().RebuildVariableArrayType(ElementType,
5715 T->getSizeModifier(),
5716 Size,
5717 T->getIndexTypeCVRQualifiers(),
5718 TL.getBracketsRange());
5719 if (Result.isNull())
5720 return QualType();
5721 }
5722
5723 // We might have constant size array now, but fortunately it has the same
5724 // location layout.
5725 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5726 NewTL.setLBracketLoc(TL.getLBracketLoc());
5727 NewTL.setRBracketLoc(TL.getRBracketLoc());
5728 NewTL.setSizeExpr(Size);
5729
5730 return Result;
5731}
5732
5733template<typename Derived>
5734QualType
5735TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
5736 DependentSizedArrayTypeLoc TL) {
5737 const DependentSizedArrayType *T = TL.getTypePtr();
5738 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5739 if (ElementType.isNull())
5740 return QualType();
5741
5742 // Array bounds are constant expressions.
5743 EnterExpressionEvaluationContext Unevaluated(
5745
5746 // If we have a VLA then it won't be a constant.
5747 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
5748
5749 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5750 Expr *origSize = TL.getSizeExpr();
5751 if (!origSize) origSize = T->getSizeExpr();
5752
5753 ExprResult sizeResult
5754 = getDerived().TransformExpr(origSize);
5755 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
5756 if (sizeResult.isInvalid())
5757 return QualType();
5758
5759 Expr *size = sizeResult.get();
5760
5761 QualType Result = TL.getType();
5762 if (getDerived().AlwaysRebuild() ||
5763 ElementType != T->getElementType() ||
5764 size != origSize) {
5765 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
5766 T->getSizeModifier(),
5767 size,
5768 T->getIndexTypeCVRQualifiers(),
5769 TL.getBracketsRange());
5770 if (Result.isNull())
5771 return QualType();
5772 }
5773
5774 // We might have any sort of array type now, but fortunately they
5775 // all have the same location layout.
5776 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5777 NewTL.setLBracketLoc(TL.getLBracketLoc());
5778 NewTL.setRBracketLoc(TL.getRBracketLoc());
5779 NewTL.setSizeExpr(size);
5780
5781 return Result;
5782}
5783
5784template <typename Derived>
5785QualType TreeTransform<Derived>::TransformDependentVectorType(
5786 TypeLocBuilder &TLB, DependentVectorTypeLoc TL) {
5787 const DependentVectorType *T = TL.getTypePtr();
5788 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5789 if (ElementType.isNull())
5790 return QualType();
5791
5792 EnterExpressionEvaluationContext Unevaluated(
5794
5795 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5796 Size = SemaRef.ActOnConstantExpression(Size);
5797 if (Size.isInvalid())
5798 return QualType();
5799
5800 QualType Result = TL.getType();
5801 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5802 Size.get() != T->getSizeExpr()) {
5803 Result = getDerived().RebuildDependentVectorType(
5804 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
5805 if (Result.isNull())
5806 return QualType();
5807 }
5808
5809 // Result might be dependent or not.
5810 if (isa<DependentVectorType>(Result)) {
5811 DependentVectorTypeLoc NewTL =
5812 TLB.push<DependentVectorTypeLoc>(Result);
5813 NewTL.setNameLoc(TL.getNameLoc());
5814 } else {
5815 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
5816 NewTL.setNameLoc(TL.getNameLoc());
5817 }
5818
5819 return Result;
5820}
5821
5822template<typename Derived>
5823QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
5824 TypeLocBuilder &TLB,
5825 DependentSizedExtVectorTypeLoc TL) {
5826 const DependentSizedExtVectorType *T = TL.getTypePtr();
5827
5828 // FIXME: ext vector locs should be nested
5829 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5830 if (ElementType.isNull())
5831 return QualType();
5832
5833 // Vector sizes are constant expressions.
5834 EnterExpressionEvaluationContext Unevaluated(
5836
5837 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
5838 Size = SemaRef.ActOnConstantExpression(Size);
5839 if (Size.isInvalid())
5840 return QualType();
5841
5842 QualType Result = TL.getType();
5843 if (getDerived().AlwaysRebuild() ||
5844 ElementType != T->getElementType() ||
5845 Size.get() != T->getSizeExpr()) {
5846 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
5847 Size.get(),
5848 T->getAttributeLoc());
5849 if (Result.isNull())
5850 return QualType();
5851 }
5852
5853 // Result might be dependent or not.
5854 if (isa<DependentSizedExtVectorType>(Result)) {
5855 DependentSizedExtVectorTypeLoc NewTL
5856 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
5857 NewTL.setNameLoc(TL.getNameLoc());
5858 } else {
5859 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
5860 NewTL.setNameLoc(TL.getNameLoc());
5861 }
5862
5863 return Result;
5864}
5865
5866template <typename Derived>
5867QualType
5868TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB,
5869 ConstantMatrixTypeLoc TL) {
5870 const ConstantMatrixType *T = TL.getTypePtr();
5871 QualType ElementType = getDerived().TransformType(T->getElementType());
5872 if (ElementType.isNull())
5873 return QualType();
5874
5875 QualType Result = TL.getType();
5876 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
5877 Result = getDerived().RebuildConstantMatrixType(
5878 ElementType, T->getNumRows(), T->getNumColumns());
5879 if (Result.isNull())
5880 return QualType();
5881 }
5882
5883 ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result);
5884 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5885 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5886 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
5887 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
5888
5889 return Result;
5890}
5891
5892template <typename Derived>
5893QualType TreeTransform<Derived>::TransformDependentSizedMatrixType(
5894 TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) {
5895 const DependentSizedMatrixType *T = TL.getTypePtr();
5896
5897 QualType ElementType = getDerived().TransformType(T->getElementType());
5898 if (ElementType.isNull()) {
5899 return QualType();
5900 }
5901
5902 // Matrix dimensions are constant expressions.
5903 EnterExpressionEvaluationContext Unevaluated(
5905
5906 Expr *origRows = TL.getAttrRowOperand();
5907 if (!origRows)
5908 origRows = T->getRowExpr();
5909 Expr *origColumns = TL.getAttrColumnOperand();
5910 if (!origColumns)
5911 origColumns = T->getColumnExpr();
5912
5913 ExprResult rowResult = getDerived().TransformExpr(origRows);
5914 rowResult = SemaRef.ActOnConstantExpression(rowResult);
5915 if (rowResult.isInvalid())
5916 return QualType();
5917
5918 ExprResult columnResult = getDerived().TransformExpr(origColumns);
5919 columnResult = SemaRef.ActOnConstantExpression(columnResult);
5920 if (columnResult.isInvalid())
5921 return QualType();
5922
5923 Expr *rows = rowResult.get();
5924 Expr *columns = columnResult.get();
5925
5926 QualType Result = TL.getType();
5927 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
5928 rows != origRows || columns != origColumns) {
5929 Result = getDerived().RebuildDependentSizedMatrixType(
5930 ElementType, rows, columns, T->getAttributeLoc());
5931
5932 if (Result.isNull())
5933 return QualType();
5934 }
5935
5936 // We might have any sort of matrix type now, but fortunately they
5937 // all have the same location layout.
5938 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
5939 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5940 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5941 NewTL.setAttrRowOperand(rows);
5942 NewTL.setAttrColumnOperand(columns);
5943 return Result;
5944}
5945
5946template <typename Derived>
5947QualType TreeTransform<Derived>::TransformDependentAddressSpaceType(
5948 TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) {
5949 const DependentAddressSpaceType *T = TL.getTypePtr();
5950
5951 QualType pointeeType =
5952 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
5953
5954 if (pointeeType.isNull())
5955 return QualType();
5956
5957 // Address spaces are constant expressions.
5958 EnterExpressionEvaluationContext Unevaluated(
5960
5961 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
5962 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
5963 if (AddrSpace.isInvalid())
5964 return QualType();
5965
5966 QualType Result = TL.getType();
5967 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
5968 AddrSpace.get() != T->getAddrSpaceExpr()) {
5969 Result = getDerived().RebuildDependentAddressSpaceType(
5970 pointeeType, AddrSpace.get(), T->getAttributeLoc());
5971 if (Result.isNull())
5972 return QualType();
5973 }
5974
5975 // Result might be dependent or not.
5976 if (isa<DependentAddressSpaceType>(Result)) {
5977 DependentAddressSpaceTypeLoc NewTL =
5978 TLB.push<DependentAddressSpaceTypeLoc>(Result);
5979
5980 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5981 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
5982 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
5983
5984 } else {
5985 TLB.TypeWasModifiedSafely(Result);
5986 }
5987
5988 return Result;
5989}
5990
5991template <typename Derived>
5992QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
5993 VectorTypeLoc TL) {
5994 const VectorType *T = TL.getTypePtr();
5995 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5996 if (ElementType.isNull())
5997 return QualType();
5998
5999 QualType Result = TL.getType();
6000 if (getDerived().AlwaysRebuild() ||
6001 ElementType != T->getElementType()) {
6002 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6003 T->getVectorKind());
6004 if (Result.isNull())
6005 return QualType();
6006 }
6007
6008 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6009 NewTL.setNameLoc(TL.getNameLoc());
6010
6011 return Result;
6012}
6013
6014template<typename Derived>
6015QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
6016 ExtVectorTypeLoc TL) {
6017 const VectorType *T = TL.getTypePtr();
6018 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6019 if (ElementType.isNull())
6020 return QualType();
6021
6022 QualType Result = TL.getType();
6023 if (getDerived().AlwaysRebuild() ||
6024 ElementType != T->getElementType()) {
6025 Result = getDerived().RebuildExtVectorType(ElementType,
6026 T->getNumElements(),
6027 /*FIXME*/ SourceLocation());
6028 if (Result.isNull())
6029 return QualType();
6030 }
6031
6032 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6033 NewTL.setNameLoc(TL.getNameLoc());
6034
6035 return Result;
6036}
6037
6038template <typename Derived>
6040 ParmVarDecl *OldParm, int indexAdjustment,
6041 std::optional<unsigned> NumExpansions, bool ExpectParameterPack) {
6042 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
6043 TypeSourceInfo *NewDI = nullptr;
6044
6045 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
6046 // If we're substituting into a pack expansion type and we know the
6047 // length we want to expand to, just substitute for the pattern.
6048 TypeLoc OldTL = OldDI->getTypeLoc();
6049 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6050
6051 TypeLocBuilder TLB;
6052 TypeLoc NewTL = OldDI->getTypeLoc();
6053 TLB.reserve(NewTL.getFullDataSize());
6054
6055 QualType Result = getDerived().TransformType(TLB,
6056 OldExpansionTL.getPatternLoc());
6057 if (Result.isNull())
6058 return nullptr;
6059
6060 Result = RebuildPackExpansionType(Result,
6061 OldExpansionTL.getPatternLoc().getSourceRange(),
6062 OldExpansionTL.getEllipsisLoc(),
6063 NumExpansions);
6064 if (Result.isNull())
6065 return nullptr;
6066
6067 PackExpansionTypeLoc NewExpansionTL
6068 = TLB.push<PackExpansionTypeLoc>(Result);
6069 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6070 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6071 } else
6072 NewDI = getDerived().TransformType(OldDI);
6073 if (!NewDI)
6074 return nullptr;
6075
6076 if (NewDI == OldDI && indexAdjustment == 0)
6077 return OldParm;
6078
6079 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
6080 OldParm->getDeclContext(),
6081 OldParm->getInnerLocStart(),
6082 OldParm->getLocation(),
6083 OldParm->getIdentifier(),
6084 NewDI->getType(),
6085 NewDI,
6086 OldParm->getStorageClass(),
6087 /* DefArg */ nullptr);
6088 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6089 OldParm->getFunctionScopeIndex() + indexAdjustment);
6090 transformedLocalDecl(OldParm, {newParm});
6091 return newParm;
6092}
6093
6094template <typename Derived>
6097 const QualType *ParamTypes,
6098 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6099 SmallVectorImpl<QualType> &OutParamTypes,
6102 unsigned *LastParamTransformed) {
6103 int indexAdjustment = 0;
6104
6105 unsigned NumParams = Params.size();
6106 for (unsigned i = 0; i != NumParams; ++i) {
6107 if (LastParamTransformed)
6108 *LastParamTransformed = i;
6109 if (ParmVarDecl *OldParm = Params[i]) {
6110 assert(OldParm->getFunctionScopeIndex() == i);
6111
6112 std::optional<unsigned> NumExpansions;
6113 ParmVarDecl *NewParm = nullptr;
6114 if (OldParm->isParameterPack()) {
6115 // We have a function parameter pack that may need to be expanded.
6117
6118 // Find the parameter packs that could be expanded.
6119 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6121 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6122 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6123
6124 // Determine whether we should expand the parameter packs.
6125 bool ShouldExpand = false;
6126 bool RetainExpansion = false;
6127 std::optional<unsigned> OrigNumExpansions;
6128 if (Unexpanded.size() > 0) {
6129 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6130 NumExpansions = OrigNumExpansions;
6131 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
6132 Pattern.getSourceRange(),
6133 Unexpanded,
6134 ShouldExpand,
6135 RetainExpansion,
6136 NumExpansions)) {
6137 return true;
6138 }
6139 } else {
6140#ifndef NDEBUG
6141 const AutoType *AT =
6142 Pattern.getType().getTypePtr()->getContainedAutoType();
6143 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6144 "Could not find parameter packs or undeduced auto type!");
6145#endif
6146 }
6147
6148 if (ShouldExpand) {
6149 // Expand the function parameter pack into multiple, separate
6150 // parameters.
6151 getDerived().ExpandingFunctionParameterPack(OldParm);
6152 for (unsigned I = 0; I != *NumExpansions; ++I) {
6153 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6154 ParmVarDecl *NewParm
6155 = getDerived().TransformFunctionTypeParam(OldParm,
6156 indexAdjustment++,
6157 OrigNumExpansions,
6158 /*ExpectParameterPack=*/false);
6159 if (!NewParm)
6160 return true;
6161
6162 if (ParamInfos)
6163 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6164 OutParamTypes.push_back(NewParm->getType());
6165 if (PVars)
6166 PVars->push_back(NewParm);
6167 }
6168
6169 // If we're supposed to retain a pack expansion, do so by temporarily
6170 // forgetting the partially-substituted parameter pack.
6171 if (RetainExpansion) {
6172 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6173 ParmVarDecl *NewParm
6174 = getDerived().TransformFunctionTypeParam(OldParm,
6175 indexAdjustment++,
6176 OrigNumExpansions,
6177 /*ExpectParameterPack=*/false);
6178 if (!NewParm)
6179 return true;
6180
6181 if (ParamInfos)
6182 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6183 OutParamTypes.push_back(NewParm->getType());
6184 if (PVars)
6185 PVars->push_back(NewParm);
6186 }
6187
6188 // The next parameter should have the same adjustment as the
6189 // last thing we pushed, but we post-incremented indexAdjustment
6190 // on every push. Also, if we push nothing, the adjustment should
6191 // go down by one.
6192 indexAdjustment--;
6193
6194 // We're done with the pack expansion.
6195 continue;
6196 }
6197
6198 // We'll substitute the parameter now without expanding the pack
6199 // expansion.
6200 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6201 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6202 indexAdjustment,
6203 NumExpansions,
6204 /*ExpectParameterPack=*/true);
6205 assert(NewParm->isParameterPack() &&
6206 "Parameter pack no longer a parameter pack after "
6207 "transformation.");
6208 } else {
6209 NewParm = getDerived().TransformFunctionTypeParam(
6210 OldParm, indexAdjustment, std::nullopt,
6211 /*ExpectParameterPack=*/false);
6212 }
6213
6214 if (!NewParm)
6215 return true;
6216
6217 if (ParamInfos)
6218 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6219 OutParamTypes.push_back(NewParm->getType());
6220 if (PVars)
6221 PVars->push_back(NewParm);
6222 continue;
6223 }
6224
6225 // Deal with the possibility that we don't have a parameter
6226 // declaration for this parameter.
6227 assert(ParamTypes);
6228 QualType OldType = ParamTypes[i];
6229 bool IsPackExpansion = false;
6230 std::optional<unsigned> NumExpansions;
6231 QualType NewType;
6232 if (const PackExpansionType *Expansion
6233 = dyn_cast<PackExpansionType>(OldType)) {
6234 // We have a function parameter pack that may need to be expanded.
6235 QualType Pattern = Expansion->getPattern();
6237 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6238
6239 // Determine whether we should expand the parameter packs.
6240 bool ShouldExpand = false;
6241 bool RetainExpansion = false;
6242 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
6243 Unexpanded,
6244 ShouldExpand,
6245 RetainExpansion,
6246 NumExpansions)) {
6247 return true;
6248 }
6249
6250 if (ShouldExpand) {
6251 // Expand the function parameter pack into multiple, separate
6252 // parameters.
6253 for (unsigned I = 0; I != *NumExpansions; ++I) {
6254 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6255 QualType NewType = getDerived().TransformType(Pattern);
6256 if (NewType.isNull())
6257 return true;
6258
6259 if (NewType->containsUnexpandedParameterPack()) {
6260 NewType = getSema().getASTContext().getPackExpansionType(
6261 NewType, std::nullopt);
6262
6263 if (NewType.isNull())
6264 return true;
6265 }
6266
6267 if (ParamInfos)
6268 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6269 OutParamTypes.push_back(NewType);
6270 if (PVars)
6271 PVars->push_back(nullptr);
6272 }
6273
6274 // We're done with the pack expansion.
6275 continue;
6276 }
6277
6278 // If we're supposed to retain a pack expansion, do so by temporarily
6279 // forgetting the partially-substituted parameter pack.
6280 if (RetainExpansion) {
6281 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6282 QualType NewType = getDerived().TransformType(Pattern);
6283 if (NewType.isNull())
6284 return true;
6285
6286 if (ParamInfos)
6287 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6288 OutParamTypes.push_back(NewType);
6289 if (PVars)
6290 PVars->push_back(nullptr);
6291 }
6292
6293 // We'll substitute the parameter now without expanding the pack
6294 // expansion.
6295 OldType = Expansion->getPattern();
6296 IsPackExpansion = true;
6297 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6298 NewType = getDerived().TransformType(OldType);
6299 } else {
6300 NewType = getDerived().TransformType(OldType);
6301 }
6302
6303 if (NewType.isNull())
6304 return true;
6305
6306 if (IsPackExpansion)
6307 NewType = getSema().Context.getPackExpansionType(NewType,
6308 NumExpansions);
6309
6310 if (ParamInfos)
6311 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6312 OutParamTypes.push_back(NewType);
6313 if (PVars)
6314 PVars->push_back(nullptr);
6315 }
6316
6317#ifndef NDEBUG
6318 if (PVars) {
6319 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6320 if (ParmVarDecl *parm = (*PVars)[i])
6321 assert(parm->getFunctionScopeIndex() == i);
6322 }
6323#endif
6324
6325 return false;
6326}
6327
6328template<typename Derived>
6332 SmallVector<QualType, 4> ExceptionStorage;
6333 return getDerived().TransformFunctionProtoType(
6334 TLB, TL, nullptr, Qualifiers(),
6335 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6336 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6337 ExceptionStorage, Changed);
6338 });
6339}
6340
6341template<typename Derived> template<typename Fn>
6343 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6344 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6345
6346 // Transform the parameters and return type.
6347 //
6348 // We are required to instantiate the params and return type in source order.
6349 // When the function has a trailing return type, we instantiate the
6350 // parameters before the return type, since the return type can then refer
6351 // to the parameters themselves (via decltype, sizeof, etc.).
6352 //
6353 SmallVector<QualType, 4> ParamTypes;
6355 Sema::ExtParameterInfoBuilder ExtParamInfos;
6356 const FunctionProtoType *T = TL.getTypePtr();
6357
6358 QualType ResultType;
6359
6360 if (T->hasTrailingReturn()) {
6361 if (getDerived().TransformFunctionTypeParams(
6362 TL.getBeginLoc(), TL.getParams(),
6365 ParamTypes, &ParamDecls, ExtParamInfos))
6366 return QualType();
6367
6368 {
6369 // C++11 [expr.prim.general]p3:
6370 // If a declaration declares a member function or member function
6371 // template of a class X, the expression this is a prvalue of type
6372 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6373 // and the end of the function-definition, member-declarator, or
6374 // declarator.
6375 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6376 Sema::CXXThisScopeRAII ThisScope(
6377 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6378
6379 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6380 if (ResultType.isNull())
6381 return QualType();
6382 }
6383 }
6384 else {
6385 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6386 if (ResultType.isNull())
6387 return QualType();
6388
6389 if (getDerived().TransformFunctionTypeParams(
6390 TL.getBeginLoc(), TL.getParams(),
6393 ParamTypes, &ParamDecls, ExtParamInfos))
6394 return QualType();
6395 }
6396
6398
6399 bool EPIChanged = false;
6400 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6401 return QualType();
6402
6403 // Handle extended parameter information.
6404 if (auto NewExtParamInfos =
6405 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6406 if (!EPI.ExtParameterInfos ||
6408 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6409 EPIChanged = true;
6410 }
6411 EPI.ExtParameterInfos = NewExtParamInfos;
6412 } else if (EPI.ExtParameterInfos) {
6413 EPIChanged = true;
6414 EPI.ExtParameterInfos = nullptr;
6415 }
6416
6417 // Transform any function effects with unevaluated conditions.
6418 // Hold this set in a local for the rest of this function, since EPI
6419 // may need to hold a FunctionEffectsRef pointing into it.
6420 std::optional<FunctionEffectSet> NewFX;
6421 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6422 NewFX.emplace();
6425
6426 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6427 FunctionEffectWithCondition NewEC = PrevEC;
6428 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6429 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6430 if (NewExpr.isInvalid())
6431 return QualType();
6432 std::optional<FunctionEffectMode> Mode =
6433 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6434 if (!Mode)
6435 return QualType();
6436
6437 // The condition expression has been transformed, and re-evaluated.
6438 // It may or may not have become constant.
6439 switch (*Mode) {
6441 NewEC.Cond = {};
6442 break;
6444 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6445 NewEC.Cond = {};
6446 break;
6448 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6449 break;
6451 llvm_unreachable(
6452 "FunctionEffectMode::None shouldn't be possible here");
6453 }
6454 }
6455 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6456 TL.getBeginLoc())) {
6458 NewFX->insert(NewEC, Errs);
6459 assert(Errs.empty());
6460 }
6461 }
6462 EPI.FunctionEffects = *NewFX;
6463 EPIChanged = true;
6464 }
6465
6466 QualType Result = TL.getType();
6467 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6468 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6469 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6470 if (Result.isNull())
6471 return QualType();
6472 }
6473
6476 NewTL.setLParenLoc(TL.getLParenLoc());
6477 NewTL.setRParenLoc(TL.getRParenLoc());
6480 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6481 NewTL.setParam(i, ParamDecls[i]);
6482
6483 return Result;
6484}
6485
6486template<typename Derived>
6489 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6490 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6491
6492 // Instantiate a dynamic noexcept expression, if any.
6493 if (isComputedNoexcept(ESI.Type)) {
6494 // Update this scrope because ContextDecl in Sema will be used in
6495 // TransformExpr.
6496 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6497 Sema::CXXThisScopeRAII ThisScope(
6498 SemaRef, Method ? Method->getParent() : nullptr,
6499 Method ? Method->getMethodQualifiers() : Qualifiers{},
6500 Method != nullptr);
6503 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6504 if (NoexceptExpr.isInvalid())
6505 return true;
6506
6508 NoexceptExpr =
6509 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6510 if (NoexceptExpr.isInvalid())
6511 return true;
6512
6513 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6514 Changed = true;
6515 ESI.NoexceptExpr = NoexceptExpr.get();
6516 ESI.Type = EST;
6517 }
6518
6519 if (ESI.Type != EST_Dynamic)
6520 return false;
6521
6522 // Instantiate a dynamic exception specification's type.
6523 for (QualType T : ESI.Exceptions) {
6524 if (const PackExpansionType *PackExpansion =
6526 Changed = true;
6527
6528 // We have a pack expansion. Instantiate it.
6530 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6531 Unexpanded);
6532 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6533
6534 // Determine whether the set of unexpanded parameter packs can and
6535 // should
6536 // be expanded.
6537 bool Expand = false;
6538 bool RetainExpansion = false;
6539 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
6540 // FIXME: Track the location of the ellipsis (and track source location
6541 // information for the types in the exception specification in general).
6542 if (getDerived().TryExpandParameterPacks(
6543 Loc, SourceRange(), Unexpanded, Expand,
6544 RetainExpansion, NumExpansions))
6545 return true;
6546
6547 if (!Expand) {
6548 // We can't expand this pack expansion into separate arguments yet;
6549 // just substitute into the pattern and create a new pack expansion
6550 // type.
6551 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6552 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6553 if (U.isNull())
6554 return true;
6555
6556 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6557 Exceptions.push_back(U);
6558 continue;
6559 }
6560
6561 // Substitute into the pack expansion pattern for each slice of the
6562 // pack.
6563 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6564 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
6565
6566 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6567 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6568 return true;
6569
6570 Exceptions.push_back(U);
6571 }
6572 } else {
6573 QualType U = getDerived().TransformType(T);
6574 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6575 return true;
6576 if (T != U)
6577 Changed = true;
6578
6579 Exceptions.push_back(U);
6580 }
6581 }
6582
6583 ESI.Exceptions = Exceptions;
6584 if (ESI.Exceptions.empty())
6585 ESI.Type = EST_DynamicNone;
6586 return false;
6587}
6588
6589template<typename Derived>
6591 TypeLocBuilder &TLB,
6593 const FunctionNoProtoType *T = TL.getTypePtr();
6594 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6595 if (ResultType.isNull())
6596 return QualType();
6597
6598 QualType Result = TL.getType();
6599 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6600 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6601
6604 NewTL.setLParenLoc(TL.getLParenLoc());
6605 NewTL.setRParenLoc(TL.getRParenLoc());
6607
6608 return Result;
6609}
6610
6611template <typename Derived>
6612QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6613 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6614 const UnresolvedUsingType *T = TL.getTypePtr();
6615 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6616 if (!D)
6617 return QualType();
6618
6619 QualType Result = TL.getType();
6620 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
6621 Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D);
6622 if (Result.isNull())
6623 return QualType();
6624 }
6625
6626 // We might get an arbitrary type spec type back. We should at
6627 // least always get a type spec type, though.
6628 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
6629 NewTL.setNameLoc(TL.getNameLoc());
6630
6631 return Result;
6632}
6633
6634template <typename Derived>
6635QualType TreeTransform<Derived>::TransformUsingType(TypeLocBuilder &TLB,
6636 UsingTypeLoc TL) {
6637 const UsingType *T = TL.getTypePtr();
6638
6639 auto *Found = cast_or_null<UsingShadowDecl>(getDerived().TransformDecl(
6640 TL.getLocalSourceRange().getBegin(), T->getFoundDecl()));
6641 if (!Found)
6642 return QualType();
6643
6644 QualType Underlying = getDerived().TransformType(T->desugar());
6645 if (Underlying.isNull())
6646 return QualType();
6647
6648 QualType Result = TL.getType();
6649 if (getDerived().AlwaysRebuild() || Found != T->getFoundDecl() ||
6650 Underlying != T->getUnderlyingType()) {
6651 Result = getDerived().RebuildUsingType(Found, Underlying);
6652 if (Result.isNull())
6653 return QualType();
6654 }
6655
6656 TLB.pushTypeSpec(Result).setNameLoc(TL.getNameLoc());
6657 return Result;
6658}
6659
6660template<typename Derived>
6661QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
6662 TypedefTypeLoc TL) {
6663 const TypedefType *T = TL.getTypePtr();
6664 TypedefNameDecl *Typedef
6665 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6666 T->getDecl()));
6667 if (!Typedef)
6668 return QualType();
6669
6670 QualType Result = TL.getType();
6671 if (getDerived().AlwaysRebuild() ||
6672 Typedef != T->getDecl()) {
6673 Result = getDerived().RebuildTypedefType(Typedef);
6674 if (Result.isNull())
6675 return QualType();
6676 }
6677
6678 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
6679 NewTL.setNameLoc(TL.getNameLoc());
6680
6681 return Result;
6682}
6683
6684template<typename Derived>
6685QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
6686 TypeOfExprTypeLoc TL) {
6687 // typeof expressions are not potentially evaluated contexts
6688 EnterExpressionEvaluationContext Unevaluated(
6691
6692 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
6693 if (E.isInvalid())
6694 return QualType();
6695
6696 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
6697 if (E.isInvalid())
6698 return QualType();
6699
6700 QualType Result = TL.getType();
6701 TypeOfKind Kind = Result->castAs<TypeOfExprType>()->getKind();
6702 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
6703 Result =
6704 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
6705 if (Result.isNull())
6706 return QualType();
6707 }
6708
6709 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
6710 NewTL.setTypeofLoc(TL.getTypeofLoc());
6711 NewTL.setLParenLoc(TL.getLParenLoc());
6712 NewTL.setRParenLoc(TL.getRParenLoc());
6713
6714 return Result;
6715}
6716
6717template<typename Derived>
6718QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
6719 TypeOfTypeLoc TL) {
6720 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
6721 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
6722 if (!New_Under_TI)
6723 return QualType();
6724
6725 QualType Result = TL.getType();
6726 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
6727 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
6728 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
6729 if (Result.isNull())
6730 return QualType();
6731 }
6732
6733 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
6734 NewTL.setTypeofLoc(TL.getTypeofLoc());
6735 NewTL.setLParenLoc(TL.getLParenLoc());
6736 NewTL.setRParenLoc(TL.getRParenLoc());
6737 NewTL.setUnmodifiedTInfo(New_Under_TI);
6738
6739 return Result;
6740}
6741
6742template<typename Derived>
6743QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
6744 DecltypeTypeLoc TL) {
6745 const DecltypeType *T = TL.getTypePtr();
6746
6747 // decltype expressions are not potentially evaluated contexts
6748 EnterExpressionEvaluationContext Unevaluated(
6751
6752 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
6753 if (E.isInvalid())
6754 return QualType();
6755
6756 E = getSema().ActOnDecltypeExpression(E.get());
6757 if (E.isInvalid())
6758 return QualType();
6759
6760 QualType Result = TL.getType();
6761 if (getDerived().AlwaysRebuild() ||
6762 E.get() != T->getUnderlyingExpr()) {
6763 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
6764 if (Result.isNull())
6765 return QualType();
6766 }
6767 else E.get();
6768
6769 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
6770 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
6771 NewTL.setRParenLoc(TL.getRParenLoc());
6772 return Result;
6773}
6774
6775template <typename Derived>
6776QualType
6777TreeTransform<Derived>::TransformPackIndexingType(TypeLocBuilder &TLB,
6778 PackIndexingTypeLoc TL) {
6779 // Transform the index
6780 ExprResult IndexExpr;
6781 {
6782 EnterExpressionEvaluationContext ConstantContext(
6784
6785 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
6786 if (IndexExpr.isInvalid())
6787 return QualType();
6788 }
6789 QualType Pattern = TL.getPattern();
6790
6791 const PackIndexingType *PIT = TL.getTypePtr();
6792 SmallVector<QualType, 5> SubtitutedTypes;
6793 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
6794
6795 bool NotYetExpanded = Types.empty();
6796 bool FullySubstituted = true;
6797
6798 if (Types.empty() && !PIT->expandsToEmptyPack())
6799 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
6800
6801 for (QualType T : Types) {
6803 QualType Transformed = getDerived().TransformType(T);
6804 if (Transformed.isNull())
6805 return QualType();
6806 SubtitutedTypes.push_back(Transformed);
6807 continue;
6808 }
6809
6811 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
6812 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6813 // Determine whether the set of unexpanded parameter packs can and should
6814 // be expanded.
6815 bool ShouldExpand = true;
6816 bool RetainExpansion = false;
6817 std::optional<unsigned> OrigNumExpansions;
6818 std::optional<unsigned> NumExpansions = OrigNumExpansions;
6819 if (getDerived().TryExpandParameterPacks(TL.getEllipsisLoc(), SourceRange(),
6820 Unexpanded, ShouldExpand,
6821 RetainExpansion, NumExpansions))
6822 return QualType();
6823 if (!ShouldExpand) {
6824 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6825 // FIXME: should we keep TypeLoc for individual expansions in
6826 // PackIndexingTypeLoc?
6827 TypeSourceInfo *TI =
6828 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
6829 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
6830 if (Pack.isNull())
6831 return QualType();
6832 if (NotYetExpanded) {
6833 FullySubstituted = false;
6834 QualType Out = getDerived().RebuildPackIndexingType(
6835 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6836 FullySubstituted);
6837 if (Out.isNull())
6838 return QualType();
6839
6840 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6841 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6842 return Out;
6843 }
6844 SubtitutedTypes.push_back(Pack);
6845 continue;
6846 }
6847 for (unsigned I = 0; I != *NumExpansions; ++I) {
6848 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
6849 QualType Out = getDerived().TransformType(T);
6850 if (Out.isNull())
6851 return QualType();
6852 SubtitutedTypes.push_back(Out);
6853 FullySubstituted &= !Out->containsUnexpandedParameterPack();
6854 }
6855 // If we're supposed to retain a pack expansion, do so by temporarily
6856 // forgetting the partially-substituted parameter pack.
6857 if (RetainExpansion) {
6858 FullySubstituted = false;
6859 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6860 QualType Out = getDerived().TransformType(T);
6861 if (Out.isNull())
6862 return QualType();
6863 SubtitutedTypes.push_back(Out);
6864 }
6865 }
6866
6867 // A pack indexing type can appear in a larger pack expansion,
6868 // e.g. `Pack...[pack_of_indexes]...`
6869 // so we need to temporarily disable substitution of pack elements
6870 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
6871 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
6872
6873 QualType Out = getDerived().RebuildPackIndexingType(
6874 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
6875 FullySubstituted, SubtitutedTypes);
6876 if (Out.isNull())
6877 return Out;
6878
6879 PackIndexingTypeLoc Loc = TLB.push<PackIndexingTypeLoc>(Out);
6880 Loc.setEllipsisLoc(TL.getEllipsisLoc());
6881 return Out;
6882}
6883
6884template<typename Derived>
6885QualType TreeTransform<Derived>::TransformUnaryTransformType(
6886 TypeLocBuilder &TLB,
6887 UnaryTransformTypeLoc TL) {
6888 QualType Result = TL.getType();
6889 if (Result->isDependentType()) {
6890 const UnaryTransformType *T = TL.getTypePtr();
6891
6892 TypeSourceInfo *NewBaseTSI =
6893 getDerived().TransformType(TL.getUnderlyingTInfo());
6894 if (!NewBaseTSI)
6895 return QualType();
6896 QualType NewBase = NewBaseTSI->getType();
6897
6898 Result = getDerived().RebuildUnaryTransformType(NewBase,
6899 T->getUTTKind(),
6900 TL.getKWLoc());
6901 if (Result.isNull())
6902 return QualType();
6903 }
6904
6905 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
6906 NewTL.setKWLoc(TL.getKWLoc());
6907 NewTL.setParensRange(TL.getParensRange());
6908 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
6909 return Result;
6910}
6911
6912template<typename Derived>
6913QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType(
6914 TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) {
6915 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
6916
6917 CXXScopeSpec SS;
6918 TemplateName TemplateName = getDerived().TransformTemplateName(
6919 SS, T->getTemplateName(), TL.getTemplateNameLoc());
6920 if (TemplateName.isNull())
6921 return QualType();
6922
6923 QualType OldDeduced = T->getDeducedType();
6924 QualType NewDeduced;
6925 if (!OldDeduced.isNull()) {
6926 NewDeduced = getDerived().TransformType(OldDeduced);
6927 if (NewDeduced.isNull())
6928 return QualType();
6929 }
6930
6931 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
6932 TemplateName, NewDeduced);
6933 if (Result.isNull())
6934 return QualType();
6935
6936 DeducedTemplateSpecializationTypeLoc NewTL =
6937 TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
6938 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
6939
6940 return Result;
6941}
6942
6943template<typename Derived>
6944QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
6945 RecordTypeLoc TL) {
6946 const RecordType *T = TL.getTypePtr();
6947 RecordDecl *Record
6948 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6949 T->getDecl()));
6950 if (!Record)
6951 return QualType();
6952
6953 QualType Result = TL.getType();
6954 if (getDerived().AlwaysRebuild() ||
6955 Record != T->getDecl()) {
6956 Result = getDerived().RebuildRecordType(Record);
6957 if (Result.isNull())
6958 return QualType();
6959 }
6960
6961 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
6962 NewTL.setNameLoc(TL.getNameLoc());
6963
6964 return Result;
6965}
6966
6967template<typename Derived>
6968QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
6969 EnumTypeLoc TL) {
6970 const EnumType *T = TL.getTypePtr();
6971 EnumDecl *Enum
6972 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
6973 T->getDecl()));
6974 if (!Enum)
6975 return QualType();
6976
6977 QualType Result = TL.getType();
6978 if (getDerived().AlwaysRebuild() ||
6979 Enum != T->getDecl()) {
6980 Result = getDerived().RebuildEnumType(Enum);
6981 if (Result.isNull())
6982 return QualType();
6983 }
6984
6985 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
6986 NewTL.setNameLoc(TL.getNameLoc());
6987
6988 return Result;
6989}
6990
6991template<typename Derived>
6992QualType TreeTransform<Derived>::TransformInjectedClassNameType(
6993 TypeLocBuilder &TLB,
6994 InjectedClassNameTypeLoc TL) {
6995 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
6996 TL.getTypePtr()->getDecl());
6997 if (!D) return QualType();
6998
6999 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
7000 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
7001 return T;
7002}
7003
7004template<typename Derived>
7006 TypeLocBuilder &TLB,
7008 return getDerived().TransformTemplateTypeParmType(
7009 TLB, TL,
7010 /*SuppressObjCLifetime=*/false);
7011}
7012
7013template <typename Derived>
7015 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7016 return TransformTypeSpecType(TLB, TL);
7017}
7018
7019template<typename Derived>
7020QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7021 TypeLocBuilder &TLB,
7022 SubstTemplateTypeParmTypeLoc TL) {
7023 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7024
7025 Decl *NewReplaced =
7026 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7027
7028 // Substitute into the replacement type, which itself might involve something
7029 // that needs to be transformed. This only tends to occur with default
7030 // template arguments of template template parameters.
7031 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7032 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7033 if (Replacement.isNull())
7034 return QualType();
7035
7036 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7037 Replacement, NewReplaced, T->getIndex(), T->getPackIndex());
7038
7039 // Propagate type-source information.
7040 SubstTemplateTypeParmTypeLoc NewTL
7041 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7042 NewTL.setNameLoc(TL.getNameLoc());
7043 return Result;
7044
7045}
7046
7047template<typename Derived>
7049 TypeLocBuilder &TLB,
7051 return getDerived().TransformSubstTemplateTypeParmPackType(
7052 TLB, TL, /*SuppressObjCLifetime=*/false);
7053}
7054
7055template <typename Derived>
7058 return TransformTypeSpecType(TLB, TL);
7059}
7060
7061template<typename Derived>
7063 TypeLocBuilder &TLB,
7066
7067 // The nested-name-specifier never matters in a TemplateSpecializationType,
7068 // because we can't have a dependent nested-name-specifier anyway.
7069 CXXScopeSpec SS;
7070 TemplateName Template
7071 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
7072 TL.getTemplateNameLoc());
7073 if (Template.isNull())
7074 return QualType();
7075
7076 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
7077}
7078
7079template<typename Derived>
7081 AtomicTypeLoc TL) {
7082 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7083 if (ValueType.isNull())
7084 return QualType();
7085
7086 QualType Result = TL.getType();
7087 if (getDerived().AlwaysRebuild() ||
7088 ValueType != TL.getValueLoc().getType()) {
7089 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7090 if (Result.isNull())
7091 return QualType();
7092 }
7093
7094 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7095 NewTL.setKWLoc(TL.getKWLoc());
7096 NewTL.setLParenLoc(TL.getLParenLoc());
7097 NewTL.setRParenLoc(TL.getRParenLoc());
7098
7099 return Result;
7100}
7101
7102template <typename Derived>
7103QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB,
7104 PipeTypeLoc TL) {
7105 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7106 if (ValueType.isNull())
7107 return QualType();
7108
7109 QualType Result = TL.getType();
7110 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7111 const PipeType *PT = Result->castAs<PipeType>();
7112 bool isReadPipe = PT->isReadOnly();
7113 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7114 if (Result.isNull())
7115 return QualType();
7116 }
7117
7118 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7119 NewTL.setKWLoc(TL.getKWLoc());
7120
7121 return Result;
7122}
7123
7124template <typename Derived>
7125QualType TreeTransform<Derived>::TransformBitIntType(TypeLocBuilder &TLB,
7126 BitIntTypeLoc TL) {
7127 const BitIntType *EIT = TL.getTypePtr();
7128 QualType Result = TL.getType();
7129
7130 if (getDerived().AlwaysRebuild()) {
7131 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7132 EIT->getNumBits(), TL.getNameLoc());
7133 if (Result.isNull())
7134 return QualType();
7135 }
7136
7137 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7138 NewTL.setNameLoc(TL.getNameLoc());
7139 return Result;
7140}
7141
7142template <typename Derived>
7143QualType TreeTransform<Derived>::TransformDependentBitIntType(
7144 TypeLocBuilder &TLB, DependentBitIntTypeLoc TL) {
7145 const DependentBitIntType *EIT = TL.getTypePtr();
7146
7147 EnterExpressionEvaluationContext Unevaluated(
7149 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7150 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7151
7152 if (BitsExpr.isInvalid())
7153 return QualType();
7154
7155 QualType Result = TL.getType();
7156
7157 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7158 Result = getDerived().RebuildDependentBitIntType(
7159 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7160
7161 if (Result.isNull())
7162 return QualType();
7163 }
7164
7165 if (isa<DependentBitIntType>(Result)) {
7166 DependentBitIntTypeLoc NewTL = TLB.push<DependentBitIntTypeLoc>(Result);
7167 NewTL.setNameLoc(TL.getNameLoc());
7168 } else {
7169 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7170 NewTL.setNameLoc(TL.getNameLoc());
7171 }
7172 return Result;
7173}
7174
7175 /// Simple iterator that traverses the template arguments in a
7176 /// container that provides a \c getArgLoc() member function.
7177 ///
7178 /// This iterator is intended to be used with the iterator form of
7179 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7180 template<typename ArgLocContainer>
7182 ArgLocContainer *Container;
7183 unsigned Index;
7184
7185 public:
7188 typedef int difference_type;
7189 typedef std::input_iterator_tag iterator_category;
7190
7191 class pointer {
7193
7194 public:
7195 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7196
7198 return &Arg;
7199 }
7200 };
7201
7202
7204
7205 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7206 unsigned Index)
7207 : Container(&Container), Index(Index) { }
7208
7210 ++Index;
7211 return *this;
7212 }
7213
7216 ++(*this);
7217 return Old;
7218 }
7219
7221 return Container->getArgLoc(Index);
7222 }
7223
7225 return pointer(Container->getArgLoc(Index));
7226 }
7227
7230 return X.Container == Y.Container && X.Index == Y.Index;
7231 }
7232
7235 return !(X == Y);
7236 }
7237 };
7238
7239template<typename Derived>
7240QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7241 AutoTypeLoc TL) {
7242 const AutoType *T = TL.getTypePtr();
7243 QualType OldDeduced = T->getDeducedType();
7244 QualType NewDeduced;
7245 if (!OldDeduced.isNull()) {
7246 NewDeduced = getDerived().TransformType(OldDeduced);
7247 if (NewDeduced.isNull())
7248 return QualType();
7249 }
7250
7251 ConceptDecl *NewCD = nullptr;
7252 TemplateArgumentListInfo NewTemplateArgs;
7253 NestedNameSpecifierLoc NewNestedNameSpec;
7254 if (T->isConstrained()) {
7255 assert(TL.getConceptReference());
7256 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7257 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7258
7259 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7260 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7261 typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator;
7262 if (getDerived().TransformTemplateArguments(
7263 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7264 NewTemplateArgs))
7265 return QualType();
7266
7267 if (TL.getNestedNameSpecifierLoc()) {
7268 NewNestedNameSpec
7269 = getDerived().TransformNestedNameSpecifierLoc(
7270 TL.getNestedNameSpecifierLoc());
7271 if (!NewNestedNameSpec)
7272 return QualType();
7273 }
7274 }
7275
7276 QualType Result = TL.getType();
7277 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7278 T->isDependentType() || T->isConstrained()) {
7279 // FIXME: Maybe don't rebuild if all template arguments are the same.
7281 NewArgList.reserve(NewTemplateArgs.size());
7282 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7283 NewArgList.push_back(ArgLoc.getArgument());
7284 Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD,
7285 NewArgList);
7286 if (Result.isNull())
7287 return QualType();
7288 }
7289
7290 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7291 NewTL.setNameLoc(TL.getNameLoc());
7292 NewTL.setRParenLoc(TL.getRParenLoc());
7293 NewTL.setConceptReference(nullptr);
7294
7295 if (T->isConstrained()) {
7296 DeclarationNameInfo DNI = DeclarationNameInfo(
7297 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7298 TL.getConceptNameLoc(),
7299 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7300 auto *CR = ConceptReference::Create(
7301 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7302 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7303 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7304 NewTL.setConceptReference(CR);
7305 }
7306
7307 return Result;
7308}
7309
7310template <typename Derived>
7312 TypeLocBuilder &TLB,
7313 TemplateSpecializationTypeLoc TL,
7314 TemplateName Template) {
7315 TemplateArgumentListInfo NewTemplateArgs;
7316 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7317 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7318 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
7319 ArgIterator;
7320 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7321 ArgIterator(TL, TL.getNumArgs()),
7322 NewTemplateArgs))
7323 return QualType();
7324
7325 // FIXME: maybe don't rebuild if all the template arguments are the same.
7326
7327 QualType Result =
7328 getDerived().RebuildTemplateSpecializationType(Template,
7329 TL.getTemplateNameLoc(),
7330 NewTemplateArgs);
7331
7332 if (!Result.isNull()) {
7333 // Specializations of template template parameters are represented as
7334 // TemplateSpecializationTypes, and substitution of type alias templates
7335 // within a dependent context can transform them into
7336 // DependentTemplateSpecializationTypes.
7337 if (isa<DependentTemplateSpecializationType>(Result)) {
7338 DependentTemplateSpecializationTypeLoc NewTL
7339 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
7340 NewTL.setElaboratedKeywordLoc(SourceLocation());
7341 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
7342 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7343 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7344 NewTL.setLAngleLoc(TL.getLAngleLoc());
7345 NewTL.setRAngleLoc(TL.getRAngleLoc());
7346 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7347 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7348 return Result;
7349 }
7350
7351 TemplateSpecializationTypeLoc NewTL
7352 = TLB.push<TemplateSpecializationTypeLoc>(Result);
7353 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
7354 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7355 NewTL.setLAngleLoc(TL.getLAngleLoc());
7356 NewTL.setRAngleLoc(TL.getRAngleLoc());
7357 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7358 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7359 }
7360
7361 return Result;
7362}
7363
7364template <typename Derived>
7366 TypeLocBuilder &TLB,
7368 TemplateName Template,
7369 CXXScopeSpec &SS) {
7370 TemplateArgumentListInfo NewTemplateArgs;
7371 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7372 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7375 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7376 ArgIterator(TL, TL.getNumArgs()),
7377 NewTemplateArgs))
7378 return QualType();
7379
7380 // FIXME: maybe don't rebuild if all the template arguments are the same.
7381
7382 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
7383 QualType Result = getSema().Context.getDependentTemplateSpecializationType(
7384 TL.getTypePtr()->getKeyword(), DTN->getQualifier(),
7385 DTN->getIdentifier(), NewTemplateArgs.arguments());
7386
7390 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
7393 NewTL.setLAngleLoc(TL.getLAngleLoc());
7394 NewTL.setRAngleLoc(TL.getRAngleLoc());
7395 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7396 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7397 return Result;
7398 }
7399
7401 = getDerived().RebuildTemplateSpecializationType(Template,
7402 TL.getTemplateNameLoc(),
7403 NewTemplateArgs);
7404
7405 if (!Result.isNull()) {
7406 /// FIXME: Wrap this in an elaborated-type-specifier?
7411 NewTL.setLAngleLoc(TL.getLAngleLoc());
7412 NewTL.setRAngleLoc(TL.getRAngleLoc());
7413 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
7414 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
7415 }
7416
7417 return Result;
7418}
7419
7420template<typename Derived>
7423 ElaboratedTypeLoc TL) {
7424 const ElaboratedType *T = TL.getTypePtr();
7425
7426 NestedNameSpecifierLoc QualifierLoc;
7427 // NOTE: the qualifier in an ElaboratedType is optional.
7428 if (TL.getQualifierLoc()) {
7429 QualifierLoc
7430 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7431 if (!QualifierLoc)
7432 return QualType();
7433 }
7434
7435 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
7436 if (NamedT.isNull())
7437 return QualType();
7438
7439 // C++0x [dcl.type.elab]p2:
7440 // If the identifier resolves to a typedef-name or the simple-template-id
7441 // resolves to an alias template specialization, the
7442 // elaborated-type-specifier is ill-formed.
7443 if (T->getKeyword() != ElaboratedTypeKeyword::None &&
7444 T->getKeyword() != ElaboratedTypeKeyword::Typename) {
7445 if (const TemplateSpecializationType *TST =
7446 NamedT->getAs<TemplateSpecializationType>()) {
7447 TemplateName Template = TST->getTemplateName();
7448 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
7449 Template.getAsTemplateDecl())) {
7450 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
7451 diag::err_tag_reference_non_tag)
7453 << llvm::to_underlying(
7455 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
7456 }
7457 }
7458 }
7459
7460 QualType Result = TL.getType();
7461 if (getDerived().AlwaysRebuild() ||
7462 QualifierLoc != TL.getQualifierLoc() ||
7463 NamedT != T->getNamedType()) {
7464 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
7465 T->getKeyword(),
7466 QualifierLoc, NamedT);
7467 if (Result.isNull())
7468 return QualType();
7469 }
7470
7471 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7472 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7473 NewTL.setQualifierLoc(QualifierLoc);
7474 return Result;
7475}
7476
7477template <typename Derived>
7478QualType TreeTransform<Derived>::TransformAttributedType(TypeLocBuilder &TLB,
7479 AttributedTypeLoc TL) {
7480 const AttributedType *oldType = TL.getTypePtr();
7481 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7482 if (modifiedType.isNull())
7483 return QualType();
7484
7485 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7486 const Attr *oldAttr = TL.getAttr();
7487 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7488 if (oldAttr && !newAttr)
7489 return QualType();
7490
7491 QualType result = TL.getType();
7492
7493 // FIXME: dependent operand expressions?
7494 if (getDerived().AlwaysRebuild() ||
7495 modifiedType != oldType->getModifiedType()) {
7496 // If the equivalent type is equal to the modified type, we don't want to
7497 // transform it as well because:
7498 //
7499 // 1. The transformation would yield the same result and is therefore
7500 // superfluous, and
7501 //
7502 // 2. Transforming the same type twice can cause problems, e.g. if it
7503 // is a FunctionProtoType, we may end up instantiating the function
7504 // parameters twice, which causes an assertion since the parameters
7505 // are already bound to their counterparts in the template for this
7506 // instantiation.
7507 //
7508 QualType equivalentType = modifiedType;
7509 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7510 TypeLocBuilder AuxiliaryTLB;
7511 AuxiliaryTLB.reserve(TL.getFullDataSize());
7512 equivalentType =
7513 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7514 if (equivalentType.isNull())
7515 return QualType();
7516 }
7517
7518 // Check whether we can add nullability; it is only represented as
7519 // type sugar, and therefore cannot be diagnosed in any other way.
7520 if (auto nullability = oldType->getImmediateNullability()) {
7521 if (!modifiedType->canHaveNullability()) {
7522 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7523 : TL.getModifiedLoc().getBeginLoc()),
7524 diag::err_nullability_nonpointer)
7525 << DiagNullabilityKind(*nullability, false) << modifiedType;
7526 return QualType();
7527 }
7528 }
7529
7530 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7531 modifiedType,
7532 equivalentType,
7533 TL.getAttr());
7534 }
7535
7536 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7537 newTL.setAttr(newAttr);
7538 return result;
7539}
7540
7541template <typename Derived>
7542QualType TreeTransform<Derived>::TransformCountAttributedType(
7543 TypeLocBuilder &TLB, CountAttributedTypeLoc TL) {
7544 const CountAttributedType *OldTy = TL.getTypePtr();
7545 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7546 if (InnerTy.isNull())
7547 return QualType();
7548
7549 Expr *OldCount = TL.getCountExpr();
7550 Expr *NewCount = nullptr;
7551 if (OldCount) {
7552 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7553 if (CountResult.isInvalid())
7554 return QualType();
7555 NewCount = CountResult.get();
7556 }
7557
7558 QualType Result = TL.getType();
7559 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7560 OldCount != NewCount) {
7561 // Currently, CountAttributedType can only wrap incomplete array types.
7563 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7564 }
7565
7566 TLB.push<CountAttributedTypeLoc>(Result);
7567 return Result;
7568}
7569
7570template <typename Derived>
7571QualType TreeTransform<Derived>::TransformBTFTagAttributedType(
7572 TypeLocBuilder &TLB, BTFTagAttributedTypeLoc TL) {
7573 // The BTFTagAttributedType is available for C only.
7574 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7575}
7576
7577template <typename Derived>
7578QualType TreeTransform<Derived>::TransformHLSLAttributedResourceType(
7579 TypeLocBuilder &TLB, HLSLAttributedResourceTypeLoc TL) {
7580
7581 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7582
7583 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7584 if (WrappedTy.isNull())
7585 return QualType();
7586
7587 QualType ContainedTy = QualType();
7588 QualType OldContainedTy = oldType->getContainedType();
7589 if (!OldContainedTy.isNull()) {
7590 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7591 if (!oldContainedTSI)
7592 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7593 OldContainedTy, SourceLocation());
7594 TypeSourceInfo *ContainedTSI = getDerived().TransformType(oldContainedTSI);
7595 if (!ContainedTSI)
7596 return QualType();
7597 ContainedTy = ContainedTSI->getType();
7598 }
7599
7600 QualType Result = TL.getType();
7601 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7602 ContainedTy != oldType->getContainedType()) {
7604 WrappedTy, ContainedTy, oldType->getAttrs());
7605 }
7606
7607 TLB.push<HLSLAttributedResourceTypeLoc>(Result);
7608 return Result;
7609}
7610
7611template<typename Derived>
7612QualType
7613TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
7614 ParenTypeLoc TL) {
7615 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7616 if (Inner.isNull())
7617 return QualType();
7618
7619 QualType Result = TL.getType();
7620 if (getDerived().AlwaysRebuild() ||
7621 Inner != TL.getInnerLoc().getType()) {
7622 Result = getDerived().RebuildParenType(Inner);
7623 if (Result.isNull())
7624 return QualType();
7625 }
7626
7627 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7628 NewTL.setLParenLoc(TL.getLParenLoc());
7629 NewTL.setRParenLoc(TL.getRParenLoc());
7630 return Result;
7631}
7632
7633template <typename Derived>
7634QualType
7635TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB,
7636 MacroQualifiedTypeLoc TL) {
7637 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7638 if (Inner.isNull())
7639 return QualType();
7640
7641 QualType Result = TL.getType();
7642 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7643 Result =
7644 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7645 if (Result.isNull())
7646 return QualType();
7647 }
7648
7649 MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result);
7650 NewTL.setExpansionLoc(TL.getExpansionLoc());
7651 return Result;
7652}
7653
7654template<typename Derived>
7655QualType TreeTransform<Derived>::TransformDependentNameType(
7656 TypeLocBuilder &TLB, DependentNameTypeLoc TL) {
7657 return TransformDependentNameType(TLB, TL, false);
7658}
7659
7660template<typename Derived>
7661QualType TreeTransform<Derived>::TransformDependentNameType(
7662 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) {
7663 const DependentNameType *T = TL.getTypePtr();
7664
7665 NestedNameSpecifierLoc QualifierLoc
7666 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7667 if (!QualifierLoc)
7668 return QualType();
7669
7670 QualType Result
7671 = getDerived().RebuildDependentNameType(T->getKeyword(),
7672 TL.getElaboratedKeywordLoc(),
7673 QualifierLoc,
7674 T->getIdentifier(),
7675 TL.getNameLoc(),
7676 DeducedTSTContext);
7677 if (Result.isNull())
7678 return QualType();
7679
7680 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
7681 QualType NamedT = ElabT->getNamedType();
7682 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
7683
7684 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
7685 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7686 NewTL.setQualifierLoc(QualifierLoc);
7687 } else {
7688 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
7689 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7690 NewTL.setQualifierLoc(QualifierLoc);
7691 NewTL.setNameLoc(TL.getNameLoc());
7692 }
7693 return Result;
7694}
7695
7696template<typename Derived>
7699 DependentTemplateSpecializationTypeLoc TL) {
7700 NestedNameSpecifierLoc QualifierLoc;
7701 if (TL.getQualifierLoc()) {
7702 QualifierLoc
7703 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
7704 if (!QualifierLoc)
7705 return QualType();
7706 }
7707
7708 return getDerived()
7709 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
7710}
7711
7712template<typename Derived>
7716 NestedNameSpecifierLoc QualifierLoc) {
7718
7719 TemplateArgumentListInfo NewTemplateArgs;
7720 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7721 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7722
7725 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7726 ArgIterator(TL, TL.getNumArgs()),
7727 NewTemplateArgs))
7728 return QualType();
7729
7730 QualType Result = getDerived().RebuildDependentTemplateSpecializationType(
7731 T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(),
7732 T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs,
7733 /*AllowInjectedClassName*/ false);
7734 if (Result.isNull())
7735 return QualType();
7736
7737 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
7738 QualType NamedT = ElabT->getNamedType();
7739
7740 // Copy information relevant to the template specialization.
7742 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
7745 NamedTL.setLAngleLoc(TL.getLAngleLoc());
7746 NamedTL.setRAngleLoc(TL.getRAngleLoc());
7747 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7748 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7749
7750 // Copy information relevant to the elaborated type.
7753 NewTL.setQualifierLoc(QualifierLoc);
7754 } else if (isa<DependentTemplateSpecializationType>(Result)) {
7758 SpecTL.setQualifierLoc(QualifierLoc);
7761 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7762 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7763 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7764 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7765 } else {
7770 SpecTL.setLAngleLoc(TL.getLAngleLoc());
7771 SpecTL.setRAngleLoc(TL.getRAngleLoc());
7772 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
7773 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
7774 }
7775 return Result;
7776}
7777
7778template<typename Derived>
7781 QualType Pattern
7782 = getDerived().TransformType(TLB, TL.getPatternLoc());
7783 if (Pattern.isNull())
7784 return QualType();
7785
7786 QualType Result = TL.getType();
7787 if (getDerived().AlwaysRebuild() ||
7788 Pattern != TL.getPatternLoc().getType()) {
7789 Result = getDerived().RebuildPackExpansionType(Pattern,
7791 TL.getEllipsisLoc(),
7793 if (Result.isNull())
7794 return QualType();
7795 }
7796
7797 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
7798 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7799 return Result;
7800}
7801
7802template<typename Derived>
7803QualType
7804TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
7805 ObjCInterfaceTypeLoc TL) {
7806 // ObjCInterfaceType is never dependent.
7807 TLB.pushFullCopy(TL);
7808 return TL.getType();
7809}
7810
7811template<typename Derived>
7812QualType
7813TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB,
7814 ObjCTypeParamTypeLoc TL) {
7815 const ObjCTypeParamType *T = TL.getTypePtr();
7816 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7817 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7818 if (!OTP)
7819 return QualType();
7820
7821 QualType Result = TL.getType();
7822 if (getDerived().AlwaysRebuild() ||
7823 OTP != T->getDecl()) {
7824 Result = getDerived().RebuildObjCTypeParamType(
7825 OTP, TL.getProtocolLAngleLoc(),
7826 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7827 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7828 if (Result.isNull())
7829 return QualType();
7830 }
7831
7832 ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result);
7833 if (TL.getNumProtocols()) {
7834 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7835 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7836 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
7837 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7838 }
7839 return Result;
7840}
7841
7842template<typename Derived>
7843QualType
7844TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
7845 ObjCObjectTypeLoc TL) {
7846 // Transform base type.
7847 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
7848 if (BaseType.isNull())
7849 return QualType();
7850
7851 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
7852
7853 // Transform type arguments.
7854 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
7855 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
7856 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
7857 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
7858 QualType TypeArg = TypeArgInfo->getType();
7859 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
7860 AnyChanged = true;
7861
7862 // We have a pack expansion. Instantiate it.
7863 const auto *PackExpansion = PackExpansionLoc.getType()
7864 ->castAs<PackExpansionType>();
7866 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
7867 Unexpanded);
7868 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7869
7870 // Determine whether the set of unexpanded parameter packs can
7871 // and should be expanded.
7872 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
7873 bool Expand = false;
7874 bool RetainExpansion = false;
7875 std::optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
7876 if (getDerived().TryExpandParameterPacks(
7877 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
7878 Unexpanded, Expand, RetainExpansion, NumExpansions))
7879 return QualType();
7880
7881 if (!Expand) {
7882 // We can't expand this pack expansion into separate arguments yet;
7883 // just substitute into the pattern and create a new pack expansion
7884 // type.
7885 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
7886
7887 TypeLocBuilder TypeArgBuilder;
7888 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7889 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
7890 PatternLoc);
7891 if (NewPatternType.isNull())
7892 return QualType();
7893
7894 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
7895 NewPatternType, NumExpansions);
7896 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
7897 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
7898 NewTypeArgInfos.push_back(
7899 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
7900 continue;
7901 }
7902
7903 // Substitute into the pack expansion pattern for each slice of the
7904 // pack.
7905 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
7906 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
7907
7908 TypeLocBuilder TypeArgBuilder;
7909 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
7910
7911 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
7912 PatternLoc);
7913 if (NewTypeArg.isNull())
7914 return QualType();
7915
7916 NewTypeArgInfos.push_back(
7917 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7918 }
7919
7920 continue;
7921 }
7922
7923 TypeLocBuilder TypeArgBuilder;
7924 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
7925 QualType NewTypeArg =
7926 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
7927 if (NewTypeArg.isNull())
7928 return QualType();
7929
7930 // If nothing changed, just keep the old TypeSourceInfo.
7931 if (NewTypeArg == TypeArg) {
7932 NewTypeArgInfos.push_back(TypeArgInfo);
7933 continue;
7934 }
7935
7936 NewTypeArgInfos.push_back(
7937 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
7938 AnyChanged = true;
7939 }
7940
7941 QualType Result = TL.getType();
7942 if (getDerived().AlwaysRebuild() || AnyChanged) {
7943 // Rebuild the type.
7944 Result = getDerived().RebuildObjCObjectType(
7945 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
7946 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
7947 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7948 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7949
7950 if (Result.isNull())
7951 return QualType();
7952 }
7953
7954 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
7955 NewT.setHasBaseTypeAsWritten(true);
7956 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
7957 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
7958 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
7959 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
7960 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
7961 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
7962 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
7963 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
7964 return Result;
7965}
7966
7967template<typename Derived>
7968QualType
7969TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
7970 ObjCObjectPointerTypeLoc TL) {
7971 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
7972 if (PointeeType.isNull())
7973 return QualType();
7974
7975 QualType Result = TL.getType();
7976 if (getDerived().AlwaysRebuild() ||
7977 PointeeType != TL.getPointeeLoc().getType()) {
7978 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
7979 TL.getStarLoc());
7980 if (Result.isNull())
7981 return QualType();
7982 }
7983
7984 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
7985 NewT.setStarLoc(TL.getStarLoc());
7986 return Result;
7987}
7988
7989//===----------------------------------------------------------------------===//
7990// Statement transformation
7991//===----------------------------------------------------------------------===//
7992template<typename Derived>
7994TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
7995 return S;
7996}
7997
7998template<typename Derived>
8001 return getDerived().TransformCompoundStmt(S, false);
8002}
8003
8004template<typename Derived>
8007 bool IsStmtExpr) {
8008 Sema::CompoundScopeRAII CompoundScope(getSema());
8009 Sema::FPFeaturesStateRAII FPSave(getSema());
8010 if (S->hasStoredFPFeatures())
8011 getSema().resetFPOptions(
8012 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8013
8014 const Stmt *ExprResult = S->getStmtExprResult();
8015 bool SubStmtInvalid = false;
8016 bool SubStmtChanged = false;
8017 SmallVector<Stmt*, 8> Statements;
8018 for (auto *B : S->body()) {
8019 StmtResult Result = getDerived().TransformStmt(
8020 B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded);
8021
8022 if (Result.isInvalid()) {
8023 // Immediately fail if this was a DeclStmt, since it's very
8024 // likely that this will cause problems for future statements.
8025 if (isa<DeclStmt>(B))
8026 return StmtError();
8027
8028 // Otherwise, just keep processing substatements and fail later.
8029 SubStmtInvalid = true;
8030 continue;
8031 }
8032
8033 SubStmtChanged = SubStmtChanged || Result.get() != B;
8034 Statements.push_back(Result.getAs<Stmt>());
8035 }
8036
8037 if (SubStmtInvalid)
8038 return StmtError();
8039
8040 if (!getDerived().AlwaysRebuild() &&
8041 !SubStmtChanged)
8042 return S;
8043
8044 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8045 Statements,
8046 S->getRBracLoc(),
8047 IsStmtExpr);
8048}
8049
8050template<typename Derived>
8052TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
8053 ExprResult LHS, RHS;
8054 {
8055 EnterExpressionEvaluationContext Unevaluated(
8057
8058 // Transform the left-hand case value.
8059 LHS = getDerived().TransformExpr(S->getLHS());
8060 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8061 if (LHS.isInvalid())
8062 return StmtError();
8063
8064 // Transform the right-hand case value (for the GNU case-range extension).
8065 RHS = getDerived().TransformExpr(S->getRHS());
8066 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8067 if (RHS.isInvalid())
8068 return StmtError();
8069 }
8070
8071 // Build the case statement.
8072 // Case statements are always rebuilt so that they will attached to their
8073 // transformed switch statement.
8074 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8075 LHS.get(),
8076 S->getEllipsisLoc(),
8077 RHS.get(),
8078 S->getColonLoc());
8079 if (Case.isInvalid())
8080 return StmtError();
8081
8082 // Transform the statement following the case
8083 StmtResult SubStmt =
8084 getDerived().TransformStmt(S->getSubStmt());
8085 if (SubStmt.isInvalid())
8086 return StmtError();
8087
8088 // Attach the body to the case statement
8089 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8090}
8091
8092template <typename Derived>
8093StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
8094 // Transform the statement following the default case
8095 StmtResult SubStmt =
8096 getDerived().TransformStmt(S->getSubStmt());
8097 if (SubStmt.isInvalid())
8098 return StmtError();
8099
8100 // Default statements are always rebuilt
8101 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8102 SubStmt.get());
8103}
8104
8105template<typename Derived>
8107TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) {
8108 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8109 if (SubStmt.isInvalid())
8110 return StmtError();
8111
8112 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8113 S->getDecl());
8114 if (!LD)
8115 return StmtError();
8116
8117 // If we're transforming "in-place" (we're not creating new local
8118 // declarations), assume we're replacing the old label statement
8119 // and clear out the reference to it.
8120 if (LD == S->getDecl())
8121 S->getDecl()->setStmt(nullptr);
8122
8123 // FIXME: Pass the real colon location in.
8124 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8125 cast<LabelDecl>(LD), SourceLocation(),
8126 SubStmt.get());
8127}
8128
8129template <typename Derived>
8131 if (!R)
8132 return R;
8133
8134 switch (R->getKind()) {
8135// Transform attributes by calling TransformXXXAttr.
8136#define ATTR(X) \
8137 case attr::X: \
8138 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8139#include "clang/Basic/AttrList.inc"
8140 }
8141 return R;
8142}
8143
8144template <typename Derived>
8146 const Stmt *InstS,
8147 const Attr *R) {
8148 if (!R)
8149 return R;
8150
8151 switch (R->getKind()) {
8152// Transform attributes by calling TransformStmtXXXAttr.
8153#define ATTR(X) \
8154 case attr::X: \
8155 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8156#include "clang/Basic/AttrList.inc"
8157 }
8158 return TransformAttr(R);
8159}
8160
8161template <typename Derived>
8164 StmtDiscardKind SDK) {
8165 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8166 if (SubStmt.isInvalid())
8167 return StmtError();
8168
8169 bool AttrsChanged = false;
8171
8172 // Visit attributes and keep track if any are transformed.
8173 for (const auto *I : S->getAttrs()) {
8174 const Attr *R =
8175 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8176 AttrsChanged |= (I != R);
8177 if (R)
8178 Attrs.push_back(R);
8179 }
8180
8181 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8182 return S;
8183
8184 // If transforming the attributes failed for all of the attributes in the
8185 // statement, don't make an AttributedStmt without attributes.
8186 if (Attrs.empty())
8187 return SubStmt;
8188
8189 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8190 SubStmt.get());
8191}
8192
8193template<typename Derived>
8195TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
8196 // Transform the initialization statement
8197 StmtResult Init = getDerived().TransformStmt(S->getInit());
8198 if (Init.isInvalid())
8199 return StmtError();
8200
8201 Sema::ConditionResult Cond;
8202 if (!S->isConsteval()) {
8203 // Transform the condition
8204 Cond = getDerived().TransformCondition(
8205 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8206 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8208 if (Cond.isInvalid())
8209 return StmtError();
8210 }
8211
8212 // If this is a constexpr if, determine which arm we should instantiate.
8213 std::optional<bool> ConstexprConditionValue;
8214 if (S->isConstexpr())
8215 ConstexprConditionValue = Cond.getKnownValue();
8216
8217 // Transform the "then" branch.
8218 StmtResult Then;
8219 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8220 EnterExpressionEvaluationContext Ctx(
8223 S->isNonNegatedConsteval());
8224
8225 Then = getDerived().TransformStmt(S->getThen());
8226 if (Then.isInvalid())
8227 return StmtError();
8228 } else {
8229 // Discarded branch is replaced with empty CompoundStmt so we can keep
8230 // proper source location for start and end of original branch, so
8231 // subsequent transformations like CoverageMapping work properly
8232 Then = new (getSema().Context)
8233 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8234 }
8235
8236 // Transform the "else" branch.
8237 StmtResult Else;
8238 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8239 EnterExpressionEvaluationContext Ctx(
8242 S->isNegatedConsteval());
8243
8244 Else = getDerived().TransformStmt(S->getElse());
8245 if (Else.isInvalid())
8246 return StmtError();
8247 } else if (S->getElse() && ConstexprConditionValue &&
8248 *ConstexprConditionValue) {
8249 // Same thing here as with <then> branch, we are discarding it, we can't
8250 // replace it with NULL nor NullStmt as we need to keep for source location
8251 // range, for CoverageMapping
8252 Else = new (getSema().Context)
8253 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8254 }
8255
8256 if (!getDerived().AlwaysRebuild() &&
8257 Init.get() == S->getInit() &&
8258 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8259 Then.get() == S->getThen() &&
8260 Else.get() == S->getElse())
8261 return S;
8262
8263 return getDerived().RebuildIfStmt(
8264 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8265 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8266}
8267
8268template<typename Derived>
8270TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
8271 // Transform the initialization statement
8272 StmtResult Init = getDerived().TransformStmt(S->getInit());
8273 if (Init.isInvalid())
8274 return StmtError();
8275
8276 // Transform the condition.
8277 Sema::ConditionResult Cond = getDerived().TransformCondition(
8278 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8280 if (Cond.isInvalid())
8281 return StmtError();
8282
8283 // Rebuild the switch statement.
8285 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8286 Init.get(), Cond, S->getRParenLoc());
8287 if (Switch.isInvalid())
8288 return StmtError();
8289
8290 // Transform the body of the switch statement.
8291 StmtResult Body = getDerived().TransformStmt(S->getBody());
8292 if (Body.isInvalid())
8293 return StmtError();
8294
8295 // Complete the switch statement.
8296 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8297 Body.get());
8298}
8299
8300template<typename Derived>
8302TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
8303 // Transform the condition
8304 Sema::ConditionResult Cond = getDerived().TransformCondition(
8305 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8307 if (Cond.isInvalid())
8308 return StmtError();
8309
8310 // OpenACC Restricts a while-loop inside of certain construct/clause
8311 // combinations, so diagnose that here in OpenACC mode.
8312 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8313 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8314
8315 // Transform the body
8316 StmtResult Body = getDerived().TransformStmt(S->getBody());
8317 if (Body.isInvalid())
8318 return StmtError();
8319
8320 if (!getDerived().AlwaysRebuild() &&
8321 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8322 Body.get() == S->getBody())
8323 return Owned(S);
8324
8325 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8326 Cond, S->getRParenLoc(), Body.get());
8327}
8328
8329template<typename Derived>
8331TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
8332 // OpenACC Restricts a do-loop inside of certain construct/clause
8333 // combinations, so diagnose that here in OpenACC mode.
8334 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8335 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8336
8337 // Transform the body
8338 StmtResult Body = getDerived().TransformStmt(S->getBody());
8339 if (Body.isInvalid())
8340 return StmtError();
8341
8342 // Transform the condition
8343 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8344 if (Cond.isInvalid())
8345 return StmtError();
8346
8347 if (!getDerived().AlwaysRebuild() &&
8348 Cond.get() == S->getCond() &&
8349 Body.get() == S->getBody())
8350 return S;
8351
8352 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8353 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8354 S->getRParenLoc());
8355}
8356
8357template<typename Derived>
8359TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
8360 if (getSema().getLangOpts().OpenMP)
8361 getSema().OpenMP().startOpenMPLoop();
8362
8363 // Transform the initialization statement
8364 StmtResult Init = getDerived().TransformStmt(S->getInit());
8365 if (Init.isInvalid())
8366 return StmtError();
8367
8368 // In OpenMP loop region loop control variable must be captured and be
8369 // private. Perform analysis of first part (if any).
8370 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8371 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8372 Init.get());
8373
8374 // Transform the condition
8375 Sema::ConditionResult Cond = getDerived().TransformCondition(
8376 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8378 if (Cond.isInvalid())
8379 return StmtError();
8380
8381 // Transform the increment
8382 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8383 if (Inc.isInvalid())
8384 return StmtError();
8385
8386 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8387 if (S->getInc() && !FullInc.get())
8388 return StmtError();
8389
8390 // OpenACC Restricts a for-loop inside of certain construct/clause
8391 // combinations, so diagnose that here in OpenACC mode.
8392 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
8393 SemaRef.OpenACC().ActOnForStmtBegin(
8394 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8395 Cond.get().second, S->getInc(), Inc.get());
8396
8397 // Transform the body
8398 StmtResult Body = getDerived().TransformStmt(S->getBody());
8399 if (Body.isInvalid())
8400 return StmtError();
8401
8402 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8403
8404 if (!getDerived().AlwaysRebuild() &&
8405 Init.get() == S->getInit() &&
8406 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8407 Inc.get() == S->getInc() &&
8408 Body.get() == S->getBody())
8409 return S;
8410
8411 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8412 Init.get(), Cond, FullInc,
8413 S->getRParenLoc(), Body.get());
8414}
8415
8416template<typename Derived>
8418TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
8419 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8420 S->getLabel());
8421 if (!LD)
8422 return StmtError();
8423
8424 // Goto statements must always be rebuilt, to resolve the label.
8425 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8426 cast<LabelDecl>(LD));
8427}
8428
8429template<typename Derived>
8431TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
8432 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8433 if (Target.isInvalid())
8434 return StmtError();
8435 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8436
8437 if (!getDerived().AlwaysRebuild() &&
8438 Target.get() == S->getTarget())
8439 return S;
8440
8441 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8442 Target.get());
8443}
8444
8445template<typename Derived>
8447TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
8448 return S;
8449}
8450
8451template<typename Derived>
8453TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
8454 return S;
8455}
8456
8457template<typename Derived>
8459TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
8460 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8461 /*NotCopyInit*/false);
8462 if (Result.isInvalid())
8463 return StmtError();
8464
8465 // FIXME: We always rebuild the return statement because there is no way
8466 // to tell whether the return type of the function has changed.
8467 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8468}
8469
8470template<typename Derived>
8472TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
8473 bool DeclChanged = false;
8475 LambdaScopeInfo *LSI = getSema().getCurLambda();
8476 for (auto *D : S->decls()) {
8477 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8478 if (!Transformed)
8479 return StmtError();
8480
8481 if (Transformed != D)
8482 DeclChanged = true;
8483
8484 if (LSI) {
8485 if (auto *TD = dyn_cast<TypeDecl>(Transformed))
8486 LSI->ContainsUnexpandedParameterPack |=
8487 getSema()
8488 .getASTContext()
8489 .getTypeDeclType(TD)
8490 .getCanonicalType()
8491 ->containsUnexpandedParameterPack();
8492
8493 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8494 LSI->ContainsUnexpandedParameterPack |=
8495 VD->getType()->containsUnexpandedParameterPack();
8496 }
8497
8498 Decls.push_back(Transformed);
8499 }
8500
8501 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8502 return S;
8503
8504 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8505}
8506
8507template<typename Derived>
8509TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
8510
8511 SmallVector<Expr*, 8> Constraints;
8514
8515 ExprResult AsmString;
8516 SmallVector<Expr*, 8> Clobbers;
8517
8518 bool ExprsChanged = false;
8519
8520 // Go through the outputs.
8521 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8522 Names.push_back(S->getOutputIdentifier(I));
8523
8524 // No need to transform the constraint literal.
8525 Constraints.push_back(S->getOutputConstraintLiteral(I));
8526
8527 // Transform the output expr.
8528 Expr *OutputExpr = S->getOutputExpr(I);
8529 ExprResult Result = getDerived().TransformExpr(OutputExpr);
8530 if (Result.isInvalid())
8531 return StmtError();
8532
8533 ExprsChanged |= Result.get() != OutputExpr;
8534
8535 Exprs.push_back(Result.get());
8536 }
8537
8538 // Go through the inputs.
8539 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8540 Names.push_back(S->getInputIdentifier(I));
8541
8542 // No need to transform the constraint literal.
8543 Constraints.push_back(S->getInputConstraintLiteral(I));
8544
8545 // Transform the input expr.
8546 Expr *InputExpr = S->getInputExpr(I);
8547 ExprResult Result = getDerived().TransformExpr(InputExpr);
8548 if (Result.isInvalid())
8549 return StmtError();
8550
8551 ExprsChanged |= Result.get() != InputExpr;
8552
8553 Exprs.push_back(Result.get());
8554 }
8555
8556 // Go through the Labels.
8557 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8558 Names.push_back(S->getLabelIdentifier(I));
8559
8560 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8561 if (Result.isInvalid())
8562 return StmtError();
8563 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8564 Exprs.push_back(Result.get());
8565 }
8566 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8567 return S;
8568
8569 // Go through the clobbers.
8570 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
8571 Clobbers.push_back(S->getClobberStringLiteral(I));
8572
8573 // No need to transform the asm string literal.
8574 AsmString = S->getAsmString();
8575 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8576 S->isVolatile(), S->getNumOutputs(),
8577 S->getNumInputs(), Names.data(),
8578 Constraints, Exprs, AsmString.get(),
8579 Clobbers, S->getNumLabels(),
8580 S->getRParenLoc());
8581}
8582
8583template<typename Derived>
8585TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
8586 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8587
8588 bool HadError = false, HadChange = false;
8589
8590 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8591 SmallVector<Expr*, 8> TransformedExprs;
8592 TransformedExprs.reserve(SrcExprs.size());
8593 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8594 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8595 if (!Result.isUsable()) {
8596 HadError = true;
8597 } else {
8598 HadChange |= (Result.get() != SrcExprs[i]);
8599 TransformedExprs.push_back(Result.get());
8600 }
8601 }
8602
8603 if (HadError) return StmtError();
8604 if (!HadChange && !getDerived().AlwaysRebuild())
8605 return Owned(S);
8606
8607 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8608 AsmToks, S->getAsmString(),
8609 S->getNumOutputs(), S->getNumInputs(),
8610 S->getAllConstraints(), S->getClobbers(),
8611 TransformedExprs, S->getEndLoc());
8612}
8613
8614// C++ Coroutines
8615template<typename Derived>
8617TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) {
8618 auto *ScopeInfo = SemaRef.getCurFunction();
8619 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8620 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8621 ScopeInfo->NeedsCoroutineSuspends &&
8622 ScopeInfo->CoroutineSuspends.first == nullptr &&
8623 ScopeInfo->CoroutineSuspends.second == nullptr &&
8624 "expected clean scope info");
8625
8626 // Set that we have (possibly-invalid) suspend points before we do anything
8627 // that may fail.
8628 ScopeInfo->setNeedsCoroutineSuspends(false);
8629
8630 // We re-build the coroutine promise object (and the coroutine parameters its
8631 // type and constructor depend on) based on the types used in our current
8632 // function. We must do so, and set it on the current FunctionScopeInfo,
8633 // before attempting to transform the other parts of the coroutine body
8634 // statement, such as the implicit suspend statements (because those
8635 // statements reference the FunctionScopeInfo::CoroutinePromise).
8636 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8637 return StmtError();
8638 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8639 if (!Promise)
8640 return StmtError();
8641 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8642 ScopeInfo->CoroutinePromise = Promise;
8643
8644 // Transform the implicit coroutine statements constructed using dependent
8645 // types during the previous parse: initial and final suspensions, the return
8646 // object, and others. We also transform the coroutine function's body.
8647 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8648 if (InitSuspend.isInvalid())
8649 return StmtError();
8650 StmtResult FinalSuspend =
8651 getDerived().TransformStmt(S->getFinalSuspendStmt());
8652 if (FinalSuspend.isInvalid() ||
8653 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8654 return StmtError();
8655 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8656 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8657
8658 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8659 if (BodyRes.isInvalid())
8660 return StmtError();
8661
8662 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8663 if (Builder.isInvalid())
8664 return StmtError();
8665
8666 Expr *ReturnObject = S->getReturnValueInit();
8667 assert(ReturnObject && "the return object is expected to be valid");
8668 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8669 /*NoCopyInit*/ false);
8670 if (Res.isInvalid())
8671 return StmtError();
8672 Builder.ReturnValue = Res.get();
8673
8674 // If during the previous parse the coroutine still had a dependent promise
8675 // statement, we may need to build some implicit coroutine statements
8676 // (such as exception and fallthrough handlers) for the first time.
8677 if (S->hasDependentPromiseType()) {
8678 // We can only build these statements, however, if the current promise type
8679 // is not dependent.
8680 if (!Promise->getType()->isDependentType()) {
8681 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8682 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8683 "these nodes should not have been built yet");
8684 if (!Builder.buildDependentStatements())
8685 return StmtError();
8686 }
8687 } else {
8688 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8689 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8690 if (Res.isInvalid())
8691 return StmtError();
8692 Builder.OnFallthrough = Res.get();
8693 }
8694
8695 if (auto *OnException = S->getExceptionHandler()) {
8696 StmtResult Res = getDerived().TransformStmt(OnException);
8697 if (Res.isInvalid())
8698 return StmtError();
8699 Builder.OnException = Res.get();
8700 }
8701
8702 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8703 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8704 if (Res.isInvalid())
8705 return StmtError();
8706 Builder.ReturnStmtOnAllocFailure = Res.get();
8707 }
8708
8709 // Transform any additional statements we may have already built
8710 assert(S->getAllocate() && S->getDeallocate() &&
8711 "allocation and deallocation calls must already be built");
8712 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8713 if (AllocRes.isInvalid())
8714 return StmtError();
8715 Builder.Allocate = AllocRes.get();
8716
8717 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8718 if (DeallocRes.isInvalid())
8719 return StmtError();
8720 Builder.Deallocate = DeallocRes.get();
8721
8722 if (auto *ResultDecl = S->getResultDecl()) {
8723 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8724 if (Res.isInvalid())
8725 return StmtError();
8726 Builder.ResultDecl = Res.get();
8727 }
8728
8729 if (auto *ReturnStmt = S->getReturnStmt()) {
8730 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8731 if (Res.isInvalid())
8732 return StmtError();
8733 Builder.ReturnStmt = Res.get();
8734 }
8735 }
8736
8737 return getDerived().RebuildCoroutineBodyStmt(Builder);
8738}
8739
8740template<typename Derived>
8742TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) {
8743 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8744 /*NotCopyInit*/false);
8745 if (Result.isInvalid())
8746 return StmtError();
8747
8748 // Always rebuild; we don't know if this needs to be injected into a new
8749 // context or if the promise type has changed.
8750 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8751 S->isImplicit());
8752}
8753
8754template <typename Derived>
8755ExprResult TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) {
8756 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8757 /*NotCopyInit*/ false);
8758 if (Operand.isInvalid())
8759 return ExprError();
8760
8761 // Rebuild the common-expr from the operand rather than transforming it
8762 // separately.
8763
8764 // FIXME: getCurScope() should not be used during template instantiation.
8765 // We should pick up the set of unqualified lookup results for operator
8766 // co_await during the initial parse.
8767 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8768 getSema().getCurScope(), E->getKeywordLoc());
8769
8770 // Always rebuild; we don't know if this needs to be injected into a new
8771 // context or if the promise type has changed.
8772 return getDerived().RebuildCoawaitExpr(
8773 E->getKeywordLoc(), Operand.get(),
8774 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8775}
8776
8777template <typename Derived>
8779TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) {
8780 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
8781 /*NotCopyInit*/ false);
8782 if (OperandResult.isInvalid())
8783 return ExprError();
8784
8785 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
8786 E->getOperatorCoawaitLookup());
8787
8788 if (LookupResult.isInvalid())
8789 return ExprError();
8790
8791 // Always rebuild; we don't know if this needs to be injected into a new
8792 // context or if the promise type has changed.
8793 return getDerived().RebuildDependentCoawaitExpr(
8794 E->getKeywordLoc(), OperandResult.get(),
8795 cast<UnresolvedLookupExpr>(LookupResult.get()));
8796}
8797
8798template<typename Derived>
8800TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) {
8801 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
8802 /*NotCopyInit*/false);
8803 if (Result.isInvalid())
8804 return ExprError();
8805
8806 // Always rebuild; we don't know if this needs to be injected into a new
8807 // context or if the promise type has changed.
8808 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
8809}
8810
8811// Objective-C Statements.
8812
8813template<typename Derived>
8815TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
8816 // Transform the body of the @try.
8817 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
8818 if (TryBody.isInvalid())
8819 return StmtError();
8820
8821 // Transform the @catch statements (if present).
8822 bool AnyCatchChanged = false;
8823 SmallVector<Stmt*, 8> CatchStmts;
8824 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
8825 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
8826 if (Catch.isInvalid())
8827 return StmtError();
8828 if (Catch.get() != S->getCatchStmt(I))
8829 AnyCatchChanged = true;
8830 CatchStmts.push_back(Catch.get());
8831 }
8832
8833 // Transform the @finally statement (if present).
8834 StmtResult Finally;
8835 if (S->getFinallyStmt()) {
8836 Finally = getDerived().TransformStmt(S->getFinallyStmt());
8837 if (Finally.isInvalid())
8838 return StmtError();
8839 }
8840
8841 // If nothing changed, just retain this statement.
8842 if (!getDerived().AlwaysRebuild() &&
8843 TryBody.get() == S->getTryBody() &&
8844 !AnyCatchChanged &&
8845 Finally.get() == S->getFinallyStmt())
8846 return S;
8847
8848 // Build a new statement.
8849 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
8850 CatchStmts, Finally.get());
8851}
8852
8853template<typename Derived>
8855TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
8856 // Transform the @catch parameter, if there is one.
8857 VarDecl *Var = nullptr;
8858 if (VarDecl *FromVar = S->getCatchParamDecl()) {
8859 TypeSourceInfo *TSInfo = nullptr;
8860 if (FromVar->getTypeSourceInfo()) {
8861 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
8862 if (!TSInfo)
8863 return StmtError();
8864 }
8865
8866 QualType T;
8867 if (TSInfo)
8868 T = TSInfo->getType();
8869 else {
8870 T = getDerived().TransformType(FromVar->getType());
8871 if (T.isNull())
8872 return StmtError();
8873 }
8874
8875 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
8876 if (!Var)
8877 return StmtError();
8878 }
8879
8880 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
8881 if (Body.isInvalid())
8882 return StmtError();
8883
8884 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
8885 S->getRParenLoc(),
8886 Var, Body.get());
8887}
8888
8889template<typename Derived>
8891TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
8892 // Transform the body.
8893 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
8894 if (Body.isInvalid())
8895 return StmtError();
8896
8897 // If nothing changed, just retain this statement.
8898 if (!getDerived().AlwaysRebuild() &&
8899 Body.get() == S->getFinallyBody())
8900 return S;
8901
8902 // Build a new statement.
8903 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
8904 Body.get());
8905}
8906
8907template<typename Derived>
8909TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
8911 if (S->getThrowExpr()) {
8912 Operand = getDerived().TransformExpr(S->getThrowExpr());
8913 if (Operand.isInvalid())
8914 return StmtError();
8915 }
8916
8917 if (!getDerived().AlwaysRebuild() &&
8918 Operand.get() == S->getThrowExpr())
8919 return S;
8920
8921 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
8922}
8923
8924template<typename Derived>
8926TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
8927 ObjCAtSynchronizedStmt *S) {
8928 // Transform the object we are locking.
8929 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
8930 if (Object.isInvalid())
8931 return StmtError();
8932 Object =
8933 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
8934 Object.get());
8935 if (Object.isInvalid())
8936 return StmtError();
8937
8938 // Transform the body.
8939 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
8940 if (Body.isInvalid())
8941 return StmtError();
8942
8943 // If nothing change, just retain the current statement.
8944 if (!getDerived().AlwaysRebuild() &&
8945 Object.get() == S->getSynchExpr() &&
8946 Body.get() == S->getSynchBody())
8947 return S;
8948
8949 // Build a new statement.
8950 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
8951 Object.get(), Body.get());
8952}
8953
8954template<typename Derived>
8956TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
8957 ObjCAutoreleasePoolStmt *S) {
8958 // Transform the body.
8959 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
8960 if (Body.isInvalid())
8961 return StmtError();
8962
8963 // If nothing changed, just retain this statement.
8964 if (!getDerived().AlwaysRebuild() &&
8965 Body.get() == S->getSubStmt())
8966 return S;
8967
8968 // Build a new statement.
8969 return getDerived().RebuildObjCAutoreleasePoolStmt(
8970 S->getAtLoc(), Body.get());
8971}
8972
8973template<typename Derived>
8975TreeTransform<Derived>::TransformObjCForCollectionStmt(
8976 ObjCForCollectionStmt *S) {
8977 // Transform the element statement.
8978 StmtResult Element =
8979 getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded);
8980 if (Element.isInvalid())
8981 return StmtError();
8982
8983 // Transform the collection expression.
8984 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
8985 if (Collection.isInvalid())
8986 return StmtError();
8987
8988 // Transform the body.
8989 StmtResult Body = getDerived().TransformStmt(S->getBody());
8990 if (Body.isInvalid())
8991 return StmtError();
8992
8993 // If nothing changed, just retain this statement.
8994 if (!getDerived().AlwaysRebuild() &&
8995 Element.get() == S->getElement() &&
8996 Collection.get() == S->getCollection() &&
8997 Body.get() == S->getBody())
8998 return S;
8999
9000 // Build a new statement.
9001 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9002 Element.get(),
9003 Collection.get(),
9004 S->getRParenLoc(),
9005 Body.get());
9006}
9007
9008template <typename Derived>
9009StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
9010 // Transform the exception declaration, if any.
9011 VarDecl *Var = nullptr;
9012 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9013 TypeSourceInfo *T =
9014 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9015 if (!T)
9016 return StmtError();
9017
9018 Var = getDerived().RebuildExceptionDecl(
9019 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9020 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9021 if (!Var || Var->isInvalidDecl())
9022 return StmtError();
9023 }
9024
9025 // Transform the actual exception handler.
9026 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9027 if (Handler.isInvalid())
9028 return StmtError();
9029
9030 if (!getDerived().AlwaysRebuild() && !Var &&
9031 Handler.get() == S->getHandlerBlock())
9032 return S;
9033
9034 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9035}
9036
9037template <typename Derived>
9038StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
9039 // Transform the try block itself.
9040 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9041 if (TryBlock.isInvalid())
9042 return StmtError();
9043
9044 // Transform the handlers.
9045 bool HandlerChanged = false;
9046 SmallVector<Stmt *, 8> Handlers;
9047 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9048 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9049 if (Handler.isInvalid())
9050 return StmtError();
9051
9052 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9053 Handlers.push_back(Handler.getAs<Stmt>());
9054 }
9055
9056 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9057 !HandlerChanged)
9058 return S;
9059
9060 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9061 Handlers);
9062}
9063
9064template<typename Derived>
9066TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
9067 EnterExpressionEvaluationContext ForRangeInitContext(
9069 /*LambdaContextDecl=*/nullptr,
9071 getSema().getLangOpts().CPlusPlus23);
9072
9073 // P2718R0 - Lifetime extension in range-based for loops.
9074 if (getSema().getLangOpts().CPlusPlus23) {
9075 auto &LastRecord = getSema().currentEvaluationContext();
9076 LastRecord.InLifetimeExtendingContext = true;
9077 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9078 }
9080 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9081 if (Init.isInvalid())
9082 return StmtError();
9083
9084 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9085 if (Range.isInvalid())
9086 return StmtError();
9087
9088 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9089 assert(getSema().getLangOpts().CPlusPlus23 ||
9090 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9091 auto ForRangeLifetimeExtendTemps =
9092 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9093
9094 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9095 if (Begin.isInvalid())
9096 return StmtError();
9097 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9098 if (End.isInvalid())
9099 return StmtError();
9100
9101 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9102 if (Cond.isInvalid())
9103 return StmtError();
9104 if (Cond.get())
9105 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9106 if (Cond.isInvalid())
9107 return StmtError();
9108 if (Cond.get())
9109 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9110
9111 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9112 if (Inc.isInvalid())
9113 return StmtError();
9114 if (Inc.get())
9115 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9116
9117 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9118 if (LoopVar.isInvalid())
9119 return StmtError();
9120
9121 StmtResult NewStmt = S;
9122 if (getDerived().AlwaysRebuild() ||
9123 Init.get() != S->getInit() ||
9124 Range.get() != S->getRangeStmt() ||
9125 Begin.get() != S->getBeginStmt() ||
9126 End.get() != S->getEndStmt() ||
9127 Cond.get() != S->getCond() ||
9128 Inc.get() != S->getInc() ||
9129 LoopVar.get() != S->getLoopVarStmt()) {
9130 NewStmt = getDerived().RebuildCXXForRangeStmt(
9131 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9132 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9133 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9134 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9135 // Might not have attached any initializer to the loop variable.
9136 getSema().ActOnInitializerError(
9137 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9138 return StmtError();
9139 }
9140 }
9141
9142 // OpenACC Restricts a while-loop inside of certain construct/clause
9143 // combinations, so diagnose that here in OpenACC mode.
9144 SemaOpenACC::LoopInConstructRAII LCR{SemaRef.OpenACC()};
9145 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9146
9147 StmtResult Body = getDerived().TransformStmt(S->getBody());
9148 if (Body.isInvalid())
9149 return StmtError();
9150
9151 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9152
9153 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9154 // it now so we have a new statement to attach the body to.
9155 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9156 NewStmt = getDerived().RebuildCXXForRangeStmt(
9157 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9158 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9159 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9160 if (NewStmt.isInvalid())
9161 return StmtError();
9162 }
9163
9164 if (NewStmt.get() == S)
9165 return S;
9166
9167 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9168}
9169
9170template<typename Derived>
9172TreeTransform<Derived>::TransformMSDependentExistsStmt(
9173 MSDependentExistsStmt *S) {
9174 // Transform the nested-name-specifier, if any.
9175 NestedNameSpecifierLoc QualifierLoc;
9176 if (S->getQualifierLoc()) {
9177 QualifierLoc
9178 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9179 if (!QualifierLoc)
9180 return StmtError();
9181 }
9182
9183 // Transform the declaration name.
9184 DeclarationNameInfo NameInfo = S->getNameInfo();
9185 if (NameInfo.getName()) {
9186 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9187 if (!NameInfo.getName())
9188 return StmtError();
9189 }
9190
9191 // Check whether anything changed.
9192 if (!getDerived().AlwaysRebuild() &&
9193 QualifierLoc == S->getQualifierLoc() &&
9194 NameInfo.getName() == S->getNameInfo().getName())
9195 return S;
9196
9197 // Determine whether this name exists, if we can.
9198 CXXScopeSpec SS;
9199 SS.Adopt(QualifierLoc);
9200 bool Dependent = false;
9201 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9202 case Sema::IER_Exists:
9203 if (S->isIfExists())
9204 break;
9205
9206 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9207
9209 if (S->isIfNotExists())
9210 break;
9211
9212 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9213
9215 Dependent = true;
9216 break;
9217
9218 case Sema::IER_Error:
9219 return StmtError();
9220 }
9221
9222 // We need to continue with the instantiation, so do so now.
9223 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9224 if (SubStmt.isInvalid())
9225 return StmtError();
9226
9227 // If we have resolved the name, just transform to the substatement.
9228 if (!Dependent)
9229 return SubStmt;
9230
9231 // The name is still dependent, so build a dependent expression again.
9232 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9233 S->isIfExists(),
9234 QualifierLoc,
9235 NameInfo,
9236 SubStmt.get());
9237}
9238
9239template<typename Derived>
9241TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
9242 NestedNameSpecifierLoc QualifierLoc;
9243 if (E->getQualifierLoc()) {
9244 QualifierLoc
9245 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9246 if (!QualifierLoc)
9247 return ExprError();
9248 }
9249
9250 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9251 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9252 if (!PD)
9253 return ExprError();
9254
9255 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9256 if (Base.isInvalid())
9257 return ExprError();
9258
9259 return new (SemaRef.getASTContext())
9260 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9262 QualifierLoc, E->getMemberLoc());
9263}
9264
9265template <typename Derived>
9266ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr(
9267 MSPropertySubscriptExpr *E) {
9268 auto BaseRes = getDerived().TransformExpr(E->getBase());
9269 if (BaseRes.isInvalid())
9270 return ExprError();
9271 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9272 if (IdxRes.isInvalid())
9273 return ExprError();
9274
9275 if (!getDerived().AlwaysRebuild() &&
9276 BaseRes.get() == E->getBase() &&
9277 IdxRes.get() == E->getIdx())
9278 return E;
9279
9280 return getDerived().RebuildArraySubscriptExpr(
9281 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9282}
9283
9284template <typename Derived>
9285StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
9286 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9287 if (TryBlock.isInvalid())
9288 return StmtError();
9289
9290 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9291 if (Handler.isInvalid())
9292 return StmtError();
9293
9294 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9295 Handler.get() == S->getHandler())
9296 return S;
9297
9298 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9299 TryBlock.get(), Handler.get());
9300}
9301
9302template <typename Derived>
9303StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
9304 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9305 if (Block.isInvalid())
9306 return StmtError();
9307
9308 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9309}
9310
9311template <typename Derived>
9312StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
9313 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9314 if (FilterExpr.isInvalid())
9315 return StmtError();
9316
9317 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9318 if (Block.isInvalid())
9319 return StmtError();
9320
9321 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9322 Block.get());
9323}
9324
9325template <typename Derived>
9327 if (isa<SEHFinallyStmt>(Handler))
9328 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9329 else
9330 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9331}
9332
9333template<typename Derived>
9336 return S;
9337}
9338
9339//===----------------------------------------------------------------------===//
9340// OpenMP directive transformation
9341//===----------------------------------------------------------------------===//
9342
9343template <typename Derived>
9345TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9346 // OMPCanonicalLoops are eliminated during transformation, since they will be
9347 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9348 // after transformation.
9349 return getDerived().TransformStmt(L->getLoopStmt());
9350}
9351
9352template <typename Derived>
9355
9356 // Transform the clauses
9358 ArrayRef<OMPClause *> Clauses = D->clauses();
9359 TClauses.reserve(Clauses.size());
9360 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9361 I != E; ++I) {
9362 if (*I) {
9363 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9364 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9365 getDerived().getSema().OpenMP().EndOpenMPClause();
9366 if (Clause)
9367 TClauses.push_back(Clause);
9368 } else {
9369 TClauses.push_back(nullptr);
9370 }
9371 }
9372 StmtResult AssociatedStmt;
9373 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9374 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9375 D->getDirectiveKind(),
9376 /*CurScope=*/nullptr);
9377 StmtResult Body;
9378 {
9379 Sema::CompoundScopeRAII CompoundScope(getSema());
9380 Stmt *CS;
9381 if (D->getDirectiveKind() == OMPD_atomic ||
9382 D->getDirectiveKind() == OMPD_critical ||
9383 D->getDirectiveKind() == OMPD_section ||
9384 D->getDirectiveKind() == OMPD_master)
9385 CS = D->getAssociatedStmt();
9386 else
9387 CS = D->getRawStmt();
9388 Body = getDerived().TransformStmt(CS);
9389 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9390 getSema().getLangOpts().OpenMPIRBuilder)
9391 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9392 }
9393 AssociatedStmt =
9394 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9395 if (AssociatedStmt.isInvalid()) {
9396 return StmtError();
9397 }
9398 }
9399 if (TClauses.size() != Clauses.size()) {
9400 return StmtError();
9401 }
9402
9403 // Transform directive name for 'omp critical' directive.
9404 DeclarationNameInfo DirName;
9405 if (D->getDirectiveKind() == OMPD_critical) {
9406 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9407 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9408 }
9409 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9410 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9411 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9412 } else if (D->getDirectiveKind() == OMPD_cancel) {
9413 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9414 }
9415
9416 return getDerived().RebuildOMPExecutableDirective(
9417 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9418 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9419}
9420
9421/// This is mostly the same as above, but allows 'informational' class
9422/// directives when rebuilding the stmt. It still takes an
9423/// OMPExecutableDirective-type argument because we're reusing that as the
9424/// superclass for the 'assume' directive at present, instead of defining a
9425/// mostly-identical OMPInformationalDirective parent class.
9426template <typename Derived>
9429
9430 // Transform the clauses
9432 ArrayRef<OMPClause *> Clauses = D->clauses();
9433 TClauses.reserve(Clauses.size());
9434 for (OMPClause *C : Clauses) {
9435 if (C) {
9436 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9437 OMPClause *Clause = getDerived().TransformOMPClause(C);
9438 getDerived().getSema().OpenMP().EndOpenMPClause();
9439 if (Clause)
9440 TClauses.push_back(Clause);
9441 } else {
9442 TClauses.push_back(nullptr);
9443 }
9444 }
9445 StmtResult AssociatedStmt;
9446 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9447 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9448 D->getDirectiveKind(),
9449 /*CurScope=*/nullptr);
9450 StmtResult Body;
9451 {
9452 Sema::CompoundScopeRAII CompoundScope(getSema());
9453 assert(D->getDirectiveKind() == OMPD_assume &&
9454 "Unexpected informational directive");
9455 Stmt *CS = D->getAssociatedStmt();
9456 Body = getDerived().TransformStmt(CS);
9457 }
9458 AssociatedStmt =
9459 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9460 if (AssociatedStmt.isInvalid())
9461 return StmtError();
9462 }
9463 if (TClauses.size() != Clauses.size())
9464 return StmtError();
9465
9466 DeclarationNameInfo DirName;
9467
9468 return getDerived().RebuildOMPInformationalDirective(
9469 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9470 D->getBeginLoc(), D->getEndLoc());
9471}
9472
9473template <typename Derived>
9476 // TODO: Fix This
9477 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9478 << getOpenMPDirectiveName(D->getDirectiveKind());
9479 return StmtError();
9480}
9481
9482template <typename Derived>
9484TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9485 DeclarationNameInfo DirName;
9486 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9487 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9488 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9489 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9490 return Res;
9491}
9492
9493template <typename Derived>
9495TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
9496 DeclarationNameInfo DirName;
9497 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9498 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9499 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9500 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9501 return Res;
9502}
9503
9504template <typename Derived>
9506TreeTransform<Derived>::TransformOMPTileDirective(OMPTileDirective *D) {
9507 DeclarationNameInfo DirName;
9508 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9509 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9510 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9511 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9512 return Res;
9513}
9514
9515template <typename Derived>
9517TreeTransform<Derived>::TransformOMPUnrollDirective(OMPUnrollDirective *D) {
9518 DeclarationNameInfo DirName;
9519 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9520 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9521 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9522 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9523 return Res;
9524}
9525
9526template <typename Derived>
9528TreeTransform<Derived>::TransformOMPReverseDirective(OMPReverseDirective *D) {
9529 DeclarationNameInfo DirName;
9530 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9531 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9532 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9533 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9534 return Res;
9535}
9536
9537template <typename Derived>
9538StmtResult TreeTransform<Derived>::TransformOMPInterchangeDirective(
9539 OMPInterchangeDirective *D) {
9540 DeclarationNameInfo DirName;
9541 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9542 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9543 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9544 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9545 return Res;
9546}
9547
9548template <typename Derived>
9550TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
9551 DeclarationNameInfo DirName;
9552 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9553 OMPD_for, DirName, nullptr, D->getBeginLoc());
9554 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9555 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9556 return Res;
9557}
9558
9559template <typename Derived>
9561TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
9562 DeclarationNameInfo DirName;
9563 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9564 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
9565 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9566 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9567 return Res;
9568}
9569
9570template <typename Derived>
9572TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
9573 DeclarationNameInfo DirName;
9574 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9575 OMPD_sections, DirName, nullptr, D->getBeginLoc());
9576 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9577 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9578 return Res;
9579}
9580
9581template <typename Derived>
9583TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
9584 DeclarationNameInfo DirName;
9585 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9586 OMPD_section, DirName, nullptr, D->getBeginLoc());
9587 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9588 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9589 return Res;
9590}
9591
9592template <typename Derived>
9594TreeTransform<Derived>::TransformOMPScopeDirective(OMPScopeDirective *D) {
9595 DeclarationNameInfo DirName;
9596 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9597 OMPD_scope, DirName, nullptr, D->getBeginLoc());
9598 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9599 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9600 return Res;
9601}
9602
9603template <typename Derived>
9605TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
9606 DeclarationNameInfo DirName;
9607 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9608 OMPD_single, DirName, nullptr, D->getBeginLoc());
9609 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9610 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9611 return Res;
9612}
9613
9614template <typename Derived>
9616TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
9617 DeclarationNameInfo DirName;
9618 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9619 OMPD_master, DirName, nullptr, D->getBeginLoc());
9620 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9621 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9622 return Res;
9623}
9624
9625template <typename Derived>
9627TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
9628 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9629 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
9630 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9631 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9632 return Res;
9633}
9634
9635template <typename Derived>
9636StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
9637 OMPParallelForDirective *D) {
9638 DeclarationNameInfo DirName;
9639 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9640 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
9641 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9642 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9643 return Res;
9644}
9645
9646template <typename Derived>
9647StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
9648 OMPParallelForSimdDirective *D) {
9649 DeclarationNameInfo DirName;
9650 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9651 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
9652 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9653 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9654 return Res;
9655}
9656
9657template <typename Derived>
9658StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective(
9659 OMPParallelMasterDirective *D) {
9660 DeclarationNameInfo DirName;
9661 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9662 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
9663 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9664 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9665 return Res;
9666}
9667
9668template <typename Derived>
9669StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedDirective(
9670 OMPParallelMaskedDirective *D) {
9671 DeclarationNameInfo DirName;
9672 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9673 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
9674 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9675 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9676 return Res;
9677}
9678
9679template <typename Derived>
9680StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
9681 OMPParallelSectionsDirective *D) {
9682 DeclarationNameInfo DirName;
9683 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9684 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
9685 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9686 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9687 return Res;
9688}
9689
9690template <typename Derived>
9692TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
9693 DeclarationNameInfo DirName;
9694 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9695 OMPD_task, DirName, nullptr, D->getBeginLoc());
9696 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9697 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9698 return Res;
9699}
9700
9701template <typename Derived>
9702StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
9703 OMPTaskyieldDirective *D) {
9704 DeclarationNameInfo DirName;
9705 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9706 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
9707 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9708 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9709 return Res;
9710}
9711
9712template <typename Derived>
9714TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
9715 DeclarationNameInfo DirName;
9716 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9717 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
9718 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9719 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9720 return Res;
9721}
9722
9723template <typename Derived>
9725TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
9726 DeclarationNameInfo DirName;
9727 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9728 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
9729 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9730 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9731 return Res;
9732}
9733
9734template <typename Derived>
9736TreeTransform<Derived>::TransformOMPAssumeDirective(OMPAssumeDirective *D) {
9737 DeclarationNameInfo DirName;
9738 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9739 OMPD_assume, DirName, nullptr, D->getBeginLoc());
9740 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
9741 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9742 return Res;
9743}
9744
9745template <typename Derived>
9747TreeTransform<Derived>::TransformOMPErrorDirective(OMPErrorDirective *D) {
9748 DeclarationNameInfo DirName;
9749 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9750 OMPD_error, DirName, nullptr, D->getBeginLoc());
9751 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9752 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9753 return Res;
9754}
9755
9756template <typename Derived>
9757StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
9758 OMPTaskgroupDirective *D) {
9759 DeclarationNameInfo DirName;
9760 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9761 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
9762 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9763 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9764 return Res;
9765}
9766
9767template <typename Derived>
9769TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
9770 DeclarationNameInfo DirName;
9771 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9772 OMPD_flush, DirName, nullptr, D->getBeginLoc());
9773 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9774 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9775 return Res;
9776}
9777
9778template <typename Derived>
9780TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) {
9781 DeclarationNameInfo DirName;
9782 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9783 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
9784 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9785 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9786 return Res;
9787}
9788
9789template <typename Derived>
9791TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) {
9792 DeclarationNameInfo DirName;
9793 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9794 OMPD_scan, DirName, nullptr, D->getBeginLoc());
9795 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9796 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9797 return Res;
9798}
9799
9800template <typename Derived>
9802TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
9803 DeclarationNameInfo DirName;
9804 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9805 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
9806 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9807 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9808 return Res;
9809}
9810
9811template <typename Derived>
9813TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
9814 DeclarationNameInfo DirName;
9815 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9816 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
9817 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9818 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9819 return Res;
9820}
9821
9822template <typename Derived>
9824TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
9825 DeclarationNameInfo DirName;
9826 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9827 OMPD_target, DirName, nullptr, D->getBeginLoc());
9828 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9829 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9830 return Res;
9831}
9832
9833template <typename Derived>
9834StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
9835 OMPTargetDataDirective *D) {
9836 DeclarationNameInfo DirName;
9837 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9838 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
9839 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9840 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9841 return Res;
9842}
9843
9844template <typename Derived>
9845StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective(
9846 OMPTargetEnterDataDirective *D) {
9847 DeclarationNameInfo DirName;
9848 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9849 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
9850 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9851 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9852 return Res;
9853}
9854
9855template <typename Derived>
9856StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective(
9857 OMPTargetExitDataDirective *D) {
9858 DeclarationNameInfo DirName;
9859 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9860 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
9861 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9862 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9863 return Res;
9864}
9865
9866template <typename Derived>
9867StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective(
9868 OMPTargetParallelDirective *D) {
9869 DeclarationNameInfo DirName;
9870 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9871 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
9872 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9873 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9874 return Res;
9875}
9876
9877template <typename Derived>
9878StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective(
9879 OMPTargetParallelForDirective *D) {
9880 DeclarationNameInfo DirName;
9881 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9882 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
9883 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9884 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9885 return Res;
9886}
9887
9888template <typename Derived>
9889StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective(
9890 OMPTargetUpdateDirective *D) {
9891 DeclarationNameInfo DirName;
9892 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9893 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
9894 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9895 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9896 return Res;
9897}
9898
9899template <typename Derived>
9901TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
9902 DeclarationNameInfo DirName;
9903 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9904 OMPD_teams, DirName, nullptr, D->getBeginLoc());
9905 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9906 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9907 return Res;
9908}
9909
9910template <typename Derived>
9911StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
9912 OMPCancellationPointDirective *D) {
9913 DeclarationNameInfo DirName;
9914 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9915 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
9916 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9917 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9918 return Res;
9919}
9920
9921template <typename Derived>
9923TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
9924 DeclarationNameInfo DirName;
9925 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9926 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
9927 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9928 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9929 return Res;
9930}
9931
9932template <typename Derived>
9934TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) {
9935 DeclarationNameInfo DirName;
9936 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9937 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
9938 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9939 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9940 return Res;
9941}
9942
9943template <typename Derived>
9944StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective(
9945 OMPTaskLoopSimdDirective *D) {
9946 DeclarationNameInfo DirName;
9947 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9948 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9949 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9950 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9951 return Res;
9952}
9953
9954template <typename Derived>
9955StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective(
9956 OMPMasterTaskLoopDirective *D) {
9957 DeclarationNameInfo DirName;
9958 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9959 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
9960 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9961 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9962 return Res;
9963}
9964
9965template <typename Derived>
9966StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopDirective(
9967 OMPMaskedTaskLoopDirective *D) {
9968 DeclarationNameInfo DirName;
9969 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9970 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
9971 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9972 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9973 return Res;
9974}
9975
9976template <typename Derived>
9977StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective(
9978 OMPMasterTaskLoopSimdDirective *D) {
9979 DeclarationNameInfo DirName;
9980 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9981 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9982 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9983 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9984 return Res;
9985}
9986
9987template <typename Derived>
9988StmtResult TreeTransform<Derived>::TransformOMPMaskedTaskLoopSimdDirective(
9989 OMPMaskedTaskLoopSimdDirective *D) {
9990 DeclarationNameInfo DirName;
9991 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9992 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
9993 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9994 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9995 return Res;
9996}
9997
9998template <typename Derived>
9999StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective(
10000 OMPParallelMasterTaskLoopDirective *D) {
10001 DeclarationNameInfo DirName;
10002 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10003 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10004 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10005 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10006 return Res;
10007}
10008
10009template <typename Derived>
10010StmtResult TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopDirective(
10011 OMPParallelMaskedTaskLoopDirective *D) {
10012 DeclarationNameInfo DirName;
10013 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10014 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10015 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10016 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10017 return Res;
10018}
10019
10020template <typename Derived>
10022TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective(
10023 OMPParallelMasterTaskLoopSimdDirective *D) {
10024 DeclarationNameInfo DirName;
10025 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10026 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10027 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10028 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10029 return Res;
10030}
10031
10032template <typename Derived>
10034TreeTransform<Derived>::TransformOMPParallelMaskedTaskLoopSimdDirective(
10035 OMPParallelMaskedTaskLoopSimdDirective *D) {
10036 DeclarationNameInfo DirName;
10037 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10038 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10039 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10040 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10041 return Res;
10042}
10043
10044template <typename Derived>
10045StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective(
10046 OMPDistributeDirective *D) {
10047 DeclarationNameInfo DirName;
10048 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10049 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10050 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10051 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10052 return Res;
10053}
10054
10055template <typename Derived>
10056StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective(
10057 OMPDistributeParallelForDirective *D) {
10058 DeclarationNameInfo DirName;
10059 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10060 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10061 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10062 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10063 return Res;
10064}
10065
10066template <typename Derived>
10068TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective(
10069 OMPDistributeParallelForSimdDirective *D) {
10070 DeclarationNameInfo DirName;
10071 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10072 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10073 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10074 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10075 return Res;
10076}
10077
10078template <typename Derived>
10079StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective(
10080 OMPDistributeSimdDirective *D) {
10081 DeclarationNameInfo DirName;
10082 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10083 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10084 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10085 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10086 return Res;
10087}
10088
10089template <typename Derived>
10090StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective(
10091 OMPTargetParallelForSimdDirective *D) {
10092 DeclarationNameInfo DirName;
10093 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10094 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10095 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10096 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10097 return Res;
10098}
10099
10100template <typename Derived>
10101StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective(
10102 OMPTargetSimdDirective *D) {
10103 DeclarationNameInfo DirName;
10104 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10105 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10106 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10107 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10108 return Res;
10109}
10110
10111template <typename Derived>
10112StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective(
10113 OMPTeamsDistributeDirective *D) {
10114 DeclarationNameInfo DirName;
10115 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10116 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10117 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10118 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10119 return Res;
10120}
10121
10122template <typename Derived>
10123StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective(
10124 OMPTeamsDistributeSimdDirective *D) {
10125 DeclarationNameInfo DirName;
10126 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10127 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10128 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10129 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10130 return Res;
10131}
10132
10133template <typename Derived>
10134StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective(
10135 OMPTeamsDistributeParallelForSimdDirective *D) {
10136 DeclarationNameInfo DirName;
10137 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10138 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10139 D->getBeginLoc());
10140 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10141 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10142 return Res;
10143}
10144
10145template <typename Derived>
10146StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective(
10147 OMPTeamsDistributeParallelForDirective *D) {
10148 DeclarationNameInfo DirName;
10149 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10150 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10151 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10152 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10153 return Res;
10154}
10155
10156template <typename Derived>
10157StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective(
10158 OMPTargetTeamsDirective *D) {
10159 DeclarationNameInfo DirName;
10160 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10161 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10162 auto Res = getDerived().TransformOMPExecutableDirective(D);
10163 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10164 return Res;
10165}
10166
10167template <typename Derived>
10168StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective(
10169 OMPTargetTeamsDistributeDirective *D) {
10170 DeclarationNameInfo DirName;
10171 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10172 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10173 auto Res = getDerived().TransformOMPExecutableDirective(D);
10174 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10175 return Res;
10176}
10177
10178template <typename Derived>
10180TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective(
10181 OMPTargetTeamsDistributeParallelForDirective *D) {
10182 DeclarationNameInfo DirName;
10183 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10184 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10185 D->getBeginLoc());
10186 auto Res = getDerived().TransformOMPExecutableDirective(D);
10187 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10188 return Res;
10189}
10190
10191template <typename Derived>
10192StmtResult TreeTransform<Derived>::
10193 TransformOMPTargetTeamsDistributeParallelForSimdDirective(
10194 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10195 DeclarationNameInfo DirName;
10196 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10197 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10198 D->getBeginLoc());
10199 auto Res = getDerived().TransformOMPExecutableDirective(D);
10200 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10201 return Res;
10202}
10203
10204template <typename Derived>
10206TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective(
10207 OMPTargetTeamsDistributeSimdDirective *D) {
10208 DeclarationNameInfo DirName;
10209 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10210 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10211 auto Res = getDerived().TransformOMPExecutableDirective(D);
10212 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10213 return Res;
10214}
10215
10216template <typename Derived>
10218TreeTransform<Derived>::TransformOMPInteropDirective(OMPInteropDirective *D) {
10219 DeclarationNameInfo DirName;
10220 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10221 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10222 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10223 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10224 return Res;
10225}
10226
10227template <typename Derived>
10229TreeTransform<Derived>::TransformOMPDispatchDirective(OMPDispatchDirective *D) {
10230 DeclarationNameInfo DirName;
10231 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10232 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10233 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10234 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10235 return Res;
10236}
10237
10238template <typename Derived>
10240TreeTransform<Derived>::TransformOMPMaskedDirective(OMPMaskedDirective *D) {
10241 DeclarationNameInfo DirName;
10242 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10243 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10244 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10245 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10246 return Res;
10247}
10248
10249template <typename Derived>
10250StmtResult TreeTransform<Derived>::TransformOMPGenericLoopDirective(
10251 OMPGenericLoopDirective *D) {
10252 DeclarationNameInfo DirName;
10253 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10254 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10255 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10256 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10257 return Res;
10258}
10259
10260template <typename Derived>
10261StmtResult TreeTransform<Derived>::TransformOMPTeamsGenericLoopDirective(
10262 OMPTeamsGenericLoopDirective *D) {
10263 DeclarationNameInfo DirName;
10264 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10265 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10266 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10267 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10268 return Res;
10269}
10270
10271template <typename Derived>
10272StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsGenericLoopDirective(
10273 OMPTargetTeamsGenericLoopDirective *D) {
10274 DeclarationNameInfo DirName;
10275 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10276 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10277 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10278 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10279 return Res;
10280}
10281
10282template <typename Derived>
10283StmtResult TreeTransform<Derived>::TransformOMPParallelGenericLoopDirective(
10284 OMPParallelGenericLoopDirective *D) {
10285 DeclarationNameInfo DirName;
10286 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10287 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10288 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10289 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10290 return Res;
10291}
10292
10293template <typename Derived>
10295TreeTransform<Derived>::TransformOMPTargetParallelGenericLoopDirective(
10296 OMPTargetParallelGenericLoopDirective *D) {
10297 DeclarationNameInfo DirName;
10298 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10299 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10300 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10301 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10302 return Res;
10303}
10304
10305//===----------------------------------------------------------------------===//
10306// OpenMP clause transformation
10307//===----------------------------------------------------------------------===//
10308template <typename Derived>
10309OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
10310 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10311 if (Cond.isInvalid())
10312 return nullptr;
10313 return getDerived().RebuildOMPIfClause(
10314 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10315 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10316}
10317
10318template <typename Derived>
10319OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
10320 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10321 if (Cond.isInvalid())
10322 return nullptr;
10323 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10324 C->getLParenLoc(), C->getEndLoc());
10325}
10326
10327template <typename Derived>
10328OMPClause *
10329TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
10330 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10331 if (NumThreads.isInvalid())
10332 return nullptr;
10333 return getDerived().RebuildOMPNumThreadsClause(
10334 NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10335}
10336
10337template <typename Derived>
10338OMPClause *
10339TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
10340 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10341 if (E.isInvalid())
10342 return nullptr;
10343 return getDerived().RebuildOMPSafelenClause(
10344 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10345}
10346
10347template <typename Derived>
10348OMPClause *
10349TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) {
10350 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10351 if (E.isInvalid())
10352 return nullptr;
10353 return getDerived().RebuildOMPAllocatorClause(
10354 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10355}
10356
10357template <typename Derived>
10358OMPClause *
10359TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
10360 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10361 if (E.isInvalid())
10362 return nullptr;
10363 return getDerived().RebuildOMPSimdlenClause(
10364 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10365}
10366
10367template <typename Derived>
10368OMPClause *TreeTransform<Derived>::TransformOMPSizesClause(OMPSizesClause *C) {
10369 SmallVector<Expr *, 4> TransformedSizes;
10370 TransformedSizes.reserve(C->getNumSizes());
10371 bool Changed = false;
10372 for (Expr *E : C->getSizesRefs()) {
10373 if (!E) {
10374 TransformedSizes.push_back(nullptr);
10375 continue;
10376 }
10377
10378 ExprResult T = getDerived().TransformExpr(E);
10379 if (T.isInvalid())
10380 return nullptr;
10381 if (E != T.get())
10382 Changed = true;
10383 TransformedSizes.push_back(T.get());
10384 }
10385
10386 if (!Changed && !getDerived().AlwaysRebuild())
10387 return C;
10388 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10389 C->getLParenLoc(), C->getEndLoc());
10390}
10391
10392template <typename Derived>
10393OMPClause *
10394TreeTransform<Derived>::TransformOMPPermutationClause(OMPPermutationClause *C) {
10395 SmallVector<Expr *> TransformedArgs;
10396 TransformedArgs.reserve(C->getNumLoops());
10397 bool Changed = false;
10398 for (Expr *E : C->getArgsRefs()) {
10399 if (!E) {
10400 TransformedArgs.push_back(nullptr);
10401 continue;
10402 }
10403
10404 ExprResult T = getDerived().TransformExpr(E);
10405 if (T.isInvalid())
10406 return nullptr;
10407 if (E != T.get())
10408 Changed = true;
10409 TransformedArgs.push_back(T.get());
10410 }
10411
10412 if (!Changed && !getDerived().AlwaysRebuild())
10413 return C;
10414 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10415 C->getLParenLoc(), C->getEndLoc());
10416}
10417
10418template <typename Derived>
10419OMPClause *TreeTransform<Derived>::TransformOMPFullClause(OMPFullClause *C) {
10420 if (!getDerived().AlwaysRebuild())
10421 return C;
10422 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10423}
10424
10425template <typename Derived>
10426OMPClause *
10427TreeTransform<Derived>::TransformOMPPartialClause(OMPPartialClause *C) {
10428 ExprResult T = getDerived().TransformExpr(C->getFactor());
10429 if (T.isInvalid())
10430 return nullptr;
10431 Expr *Factor = T.get();
10432 bool Changed = Factor != C->getFactor();
10433
10434 if (!Changed && !getDerived().AlwaysRebuild())
10435 return C;
10436 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10437 C->getEndLoc());
10438}
10439
10440template <typename Derived>
10441OMPClause *
10442TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
10443 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10444 if (E.isInvalid())
10445 return nullptr;
10446 return getDerived().RebuildOMPCollapseClause(
10447 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10448}
10449
10450template <typename Derived>
10451OMPClause *
10452TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
10453 return getDerived().RebuildOMPDefaultClause(
10454 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(),
10455 C->getLParenLoc(), C->getEndLoc());
10456}
10457
10458template <typename Derived>
10459OMPClause *
10460TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
10461 return getDerived().RebuildOMPProcBindClause(
10462 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10463 C->getLParenLoc(), C->getEndLoc());
10464}
10465
10466template <typename Derived>
10467OMPClause *
10468TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
10469 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10470 if (E.isInvalid())
10471 return nullptr;
10472 return getDerived().RebuildOMPScheduleClause(
10473 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
10474 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
10475 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
10476 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
10477}
10478
10479template <typename Derived>
10480OMPClause *
10481TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
10482 ExprResult E;
10483 if (auto *Num = C->getNumForLoops()) {
10484 E = getDerived().TransformExpr(Num);
10485 if (E.isInvalid())
10486 return nullptr;
10487 }
10488 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
10489 C->getLParenLoc(), E.get());
10490}
10491
10492template <typename Derived>
10493OMPClause *
10494TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) {
10495 ExprResult E;
10496 if (Expr *Evt = C->getEventHandler()) {
10497 E = getDerived().TransformExpr(Evt);
10498 if (E.isInvalid())
10499 return nullptr;
10500 }
10501 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
10502 C->getLParenLoc(), C->getEndLoc());
10503}
10504
10505template <typename Derived>
10506OMPClause *
10507TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
10508 // No need to rebuild this clause, no template-dependent parameters.
10509 return C;
10510}
10511
10512template <typename Derived>
10513OMPClause *
10514TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
10515 // No need to rebuild this clause, no template-dependent parameters.
10516 return C;
10517}
10518
10519template <typename Derived>
10520OMPClause *
10521TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
10522 // No need to rebuild this clause, no template-dependent parameters.
10523 return C;
10524}
10525
10526template <typename Derived>
10527OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
10528 // No need to rebuild this clause, no template-dependent parameters.
10529 return C;
10530}
10531
10532template <typename Derived>
10533OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
10534 // No need to rebuild this clause, no template-dependent parameters.
10535 return C;
10536}
10537
10538template <typename Derived>
10539OMPClause *
10540TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
10541 // No need to rebuild this clause, no template-dependent parameters.
10542 return C;
10543}
10544
10545template <typename Derived>
10546OMPClause *
10547TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
10548 // No need to rebuild this clause, no template-dependent parameters.
10549 return C;
10550}
10551
10552template <typename Derived>
10553OMPClause *
10554TreeTransform<Derived>::TransformOMPCompareClause(OMPCompareClause *C) {
10555 // No need to rebuild this clause, no template-dependent parameters.
10556 return C;
10557}
10558
10559template <typename Derived>
10560OMPClause *TreeTransform<Derived>::TransformOMPFailClause(OMPFailClause *C) {
10561 // No need to rebuild this clause, no template-dependent parameters.
10562 return C;
10563}
10564
10565template <typename Derived>
10566OMPClause *
10567TreeTransform<Derived>::TransformOMPAbsentClause(OMPAbsentClause *C) {
10568 return C;
10569}
10570
10571template <typename Derived>
10572OMPClause *TreeTransform<Derived>::TransformOMPHoldsClause(OMPHoldsClause *C) {
10573 ExprResult E = getDerived().TransformExpr(C->getExpr());
10574 if (E.isInvalid())
10575 return nullptr;
10576 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
10577 C->getLParenLoc(), C->getEndLoc());
10578}
10579
10580template <typename Derived>
10581OMPClause *
10582TreeTransform<Derived>::TransformOMPContainsClause(OMPContainsClause *C) {
10583 return C;
10584}
10585
10586template <typename Derived>
10587OMPClause *
10588TreeTransform<Derived>::TransformOMPNoOpenMPClause(OMPNoOpenMPClause *C) {
10589 return C;
10590}
10591template <typename Derived>
10592OMPClause *TreeTransform<Derived>::TransformOMPNoOpenMPRoutinesClause(
10593 OMPNoOpenMPRoutinesClause *C) {
10594 return C;
10595}
10596template <typename Derived>
10597OMPClause *TreeTransform<Derived>::TransformOMPNoParallelismClause(
10598 OMPNoParallelismClause *C) {
10599 return C;
10600}
10601
10602template <typename Derived>
10603OMPClause *
10604TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
10605 // No need to rebuild this clause, no template-dependent parameters.
10606 return C;
10607}
10608
10609template <typename Derived>
10610OMPClause *
10611TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) {
10612 // No need to rebuild this clause, no template-dependent parameters.
10613 return C;
10614}
10615
10616template <typename Derived>
10617OMPClause *
10618TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) {
10619 // No need to rebuild this clause, no template-dependent parameters.
10620 return C;
10621}
10622
10623template <typename Derived>
10624OMPClause *
10625TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) {
10626 // No need to rebuild this clause, no template-dependent parameters.
10627 return C;
10628}
10629
10630template <typename Derived>
10631OMPClause *
10632TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) {
10633 // No need to rebuild this clause, no template-dependent parameters.
10634 return C;
10635}
10636
10637template <typename Derived>
10638OMPClause *TreeTransform<Derived>::TransformOMPWeakClause(OMPWeakClause *C) {
10639 // No need to rebuild this clause, no template-dependent parameters.
10640 return C;
10641}
10642
10643template <typename Derived>
10644OMPClause *
10645TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
10646 // No need to rebuild this clause, no template-dependent parameters.
10647 return C;
10648}
10649
10650template <typename Derived>
10651OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
10652 // No need to rebuild this clause, no template-dependent parameters.
10653 return C;
10654}
10655
10656template <typename Derived>
10657OMPClause *
10658TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) {
10659 // No need to rebuild this clause, no template-dependent parameters.
10660 return C;
10661}
10662
10663template <typename Derived>
10664OMPClause *TreeTransform<Derived>::TransformOMPInitClause(OMPInitClause *C) {
10665 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
10666 if (IVR.isInvalid())
10667 return nullptr;
10668
10669 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
10670 InteropInfo.PreferTypes.reserve(C->varlist_size() - 1);
10671 for (Expr *E : llvm::drop_begin(C->varlist())) {
10672 ExprResult ER = getDerived().TransformExpr(cast<Expr>(E));
10673 if (ER.isInvalid())
10674 return nullptr;
10675 InteropInfo.PreferTypes.push_back(ER.get());
10676 }
10677 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
10678 C->getBeginLoc(), C->getLParenLoc(),
10679 C->getVarLoc(), C->getEndLoc());
10680}
10681
10682template <typename Derived>
10683OMPClause *TreeTransform<Derived>::TransformOMPUseClause(OMPUseClause *C) {
10684 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
10685 if (ER.isInvalid())
10686 return nullptr;
10687 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
10688 C->getLParenLoc(), C->getVarLoc(),
10689 C->getEndLoc());
10690}
10691
10692template <typename Derived>
10693OMPClause *
10694TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) {
10695 ExprResult ER;
10696 if (Expr *IV = C->getInteropVar()) {
10697 ER = getDerived().TransformExpr(IV);
10698 if (ER.isInvalid())
10699 return nullptr;
10700 }
10701 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
10702 C->getLParenLoc(), C->getVarLoc(),
10703 C->getEndLoc());
10704}
10705
10706template <typename Derived>
10707OMPClause *
10708TreeTransform<Derived>::TransformOMPNovariantsClause(OMPNovariantsClause *C) {
10709 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10710 if (Cond.isInvalid())
10711 return nullptr;
10712 return getDerived().RebuildOMPNovariantsClause(
10713 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10714}
10715
10716template <typename Derived>
10717OMPClause *
10718TreeTransform<Derived>::TransformOMPNocontextClause(OMPNocontextClause *C) {
10719 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10720 if (Cond.isInvalid())
10721 return nullptr;
10722 return getDerived().RebuildOMPNocontextClause(
10723 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10724}
10725
10726template <typename Derived>
10727OMPClause *
10728TreeTransform<Derived>::TransformOMPFilterClause(OMPFilterClause *C) {
10729 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
10730 if (ThreadID.isInvalid())
10731 return nullptr;
10732 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
10733 C->getLParenLoc(), C->getEndLoc());
10734}
10735
10736template <typename Derived>
10737OMPClause *TreeTransform<Derived>::TransformOMPAlignClause(OMPAlignClause *C) {
10738 ExprResult E = getDerived().TransformExpr(C->getAlignment());
10739 if (E.isInvalid())
10740 return nullptr;
10741 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
10742 C->getLParenLoc(), C->getEndLoc());
10743}
10744
10745template <typename Derived>
10746OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause(
10747 OMPUnifiedAddressClause *C) {
10748 llvm_unreachable("unified_address clause cannot appear in dependent context");
10749}
10750
10751template <typename Derived>
10752OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause(
10753 OMPUnifiedSharedMemoryClause *C) {
10754 llvm_unreachable(
10755 "unified_shared_memory clause cannot appear in dependent context");
10756}
10757
10758template <typename Derived>
10759OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause(
10760 OMPReverseOffloadClause *C) {
10761 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
10762}
10763
10764template <typename Derived>
10765OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause(
10766 OMPDynamicAllocatorsClause *C) {
10767 llvm_unreachable(
10768 "dynamic_allocators clause cannot appear in dependent context");
10769}
10770
10771template <typename Derived>
10772OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause(
10773 OMPAtomicDefaultMemOrderClause *C) {
10774 llvm_unreachable(
10775 "atomic_default_mem_order clause cannot appear in dependent context");
10776}
10777
10778template <typename Derived>
10779OMPClause *TreeTransform<Derived>::TransformOMPAtClause(OMPAtClause *C) {
10780 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
10781 C->getBeginLoc(), C->getLParenLoc(),
10782 C->getEndLoc());
10783}
10784
10785template <typename Derived>
10786OMPClause *
10787TreeTransform<Derived>::TransformOMPSeverityClause(OMPSeverityClause *C) {
10788 return getDerived().RebuildOMPSeverityClause(
10789 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
10790 C->getLParenLoc(), C->getEndLoc());
10791}
10792
10793template <typename Derived>
10794OMPClause *
10795TreeTransform<Derived>::TransformOMPMessageClause(OMPMessageClause *C) {
10796 ExprResult E = getDerived().TransformExpr(C->getMessageString());
10797 if (E.isInvalid())
10798 return nullptr;
10799 return getDerived().RebuildOMPMessageClause(
10800 C->getMessageString(), C->getBeginLoc(), C->getLParenLoc(),
10801 C->getEndLoc());
10802}
10803
10804template <typename Derived>
10805OMPClause *
10806TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
10808 Vars.reserve(C->varlist_size());
10809 for (auto *VE : C->varlist()) {
10810 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10811 if (EVar.isInvalid())
10812 return nullptr;
10813 Vars.push_back(EVar.get());
10814 }
10815 return getDerived().RebuildOMPPrivateClause(
10816 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10817}
10818
10819template <typename Derived>
10820OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
10821 OMPFirstprivateClause *C) {
10823 Vars.reserve(C->varlist_size());
10824 for (auto *VE : C->varlist()) {
10825 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10826 if (EVar.isInvalid())
10827 return nullptr;
10828 Vars.push_back(EVar.get());
10829 }
10830 return getDerived().RebuildOMPFirstprivateClause(
10831 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10832}
10833
10834template <typename Derived>
10835OMPClause *
10836TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
10838 Vars.reserve(C->varlist_size());
10839 for (auto *VE : C->varlist()) {
10840 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10841 if (EVar.isInvalid())
10842 return nullptr;
10843 Vars.push_back(EVar.get());
10844 }
10845 return getDerived().RebuildOMPLastprivateClause(
10846 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
10847 C->getLParenLoc(), C->getEndLoc());
10848}
10849
10850template <typename Derived>
10851OMPClause *
10852TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
10854 Vars.reserve(C->varlist_size());
10855 for (auto *VE : C->varlist()) {
10856 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10857 if (EVar.isInvalid())
10858 return nullptr;
10859 Vars.push_back(EVar.get());
10860 }
10861 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
10862 C->getLParenLoc(), C->getEndLoc());
10863}
10864
10865template <typename Derived>
10866OMPClause *
10867TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
10869 Vars.reserve(C->varlist_size());
10870 for (auto *VE : C->varlist()) {
10871 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10872 if (EVar.isInvalid())
10873 return nullptr;
10874 Vars.push_back(EVar.get());
10875 }
10876 CXXScopeSpec ReductionIdScopeSpec;
10877 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10878
10879 DeclarationNameInfo NameInfo = C->getNameInfo();
10880 if (NameInfo.getName()) {
10881 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10882 if (!NameInfo.getName())
10883 return nullptr;
10884 }
10885 // Build a list of all UDR decls with the same names ranged by the Scopes.
10886 // The Scope boundary is a duplication of the previous decl.
10887 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10888 for (auto *E : C->reduction_ops()) {
10889 // Transform all the decls.
10890 if (E) {
10891 auto *ULE = cast<UnresolvedLookupExpr>(E);
10892 UnresolvedSet<8> Decls;
10893 for (auto *D : ULE->decls()) {
10894 NamedDecl *InstD =
10895 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10896 Decls.addDecl(InstD, InstD->getAccess());
10897 }
10898 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10899 SemaRef.Context, /*NamingClass=*/nullptr,
10900 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10901 /*ADL=*/true, Decls.begin(), Decls.end(),
10902 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10903 } else
10904 UnresolvedReductions.push_back(nullptr);
10905 }
10906 return getDerived().RebuildOMPReductionClause(
10907 Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(),
10908 C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
10909 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10910}
10911
10912template <typename Derived>
10913OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause(
10914 OMPTaskReductionClause *C) {
10916 Vars.reserve(C->varlist_size());
10917 for (auto *VE : C->varlist()) {
10918 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10919 if (EVar.isInvalid())
10920 return nullptr;
10921 Vars.push_back(EVar.get());
10922 }
10923 CXXScopeSpec ReductionIdScopeSpec;
10924 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10925
10926 DeclarationNameInfo NameInfo = C->getNameInfo();
10927 if (NameInfo.getName()) {
10928 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10929 if (!NameInfo.getName())
10930 return nullptr;
10931 }
10932 // Build a list of all UDR decls with the same names ranged by the Scopes.
10933 // The Scope boundary is a duplication of the previous decl.
10934 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10935 for (auto *E : C->reduction_ops()) {
10936 // Transform all the decls.
10937 if (E) {
10938 auto *ULE = cast<UnresolvedLookupExpr>(E);
10939 UnresolvedSet<8> Decls;
10940 for (auto *D : ULE->decls()) {
10941 NamedDecl *InstD =
10942 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10943 Decls.addDecl(InstD, InstD->getAccess());
10944 }
10945 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10946 SemaRef.Context, /*NamingClass=*/nullptr,
10947 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10948 /*ADL=*/true, Decls.begin(), Decls.end(),
10949 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10950 } else
10951 UnresolvedReductions.push_back(nullptr);
10952 }
10953 return getDerived().RebuildOMPTaskReductionClause(
10954 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
10955 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
10956}
10957
10958template <typename Derived>
10959OMPClause *
10960TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) {
10962 Vars.reserve(C->varlist_size());
10963 for (auto *VE : C->varlist()) {
10964 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
10965 if (EVar.isInvalid())
10966 return nullptr;
10967 Vars.push_back(EVar.get());
10968 }
10969 CXXScopeSpec ReductionIdScopeSpec;
10970 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
10971
10972 DeclarationNameInfo NameInfo = C->getNameInfo();
10973 if (NameInfo.getName()) {
10974 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
10975 if (!NameInfo.getName())
10976 return nullptr;
10977 }
10978 // Build a list of all UDR decls with the same names ranged by the Scopes.
10979 // The Scope boundary is a duplication of the previous decl.
10980 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
10981 for (auto *E : C->reduction_ops()) {
10982 // Transform all the decls.
10983 if (E) {
10984 auto *ULE = cast<UnresolvedLookupExpr>(E);
10985 UnresolvedSet<8> Decls;
10986 for (auto *D : ULE->decls()) {
10987 NamedDecl *InstD =
10988 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
10989 Decls.addDecl(InstD, InstD->getAccess());
10990 }
10991 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
10992 SemaRef.Context, /*NamingClass=*/nullptr,
10993 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
10994 /*ADL=*/true, Decls.begin(), Decls.end(),
10995 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
10996 } else
10997 UnresolvedReductions.push_back(nullptr);
10998 }
10999 return getDerived().RebuildOMPInReductionClause(
11000 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11001 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11002}
11003
11004template <typename Derived>
11005OMPClause *
11006TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
11008 Vars.reserve(C->varlist_size());
11009 for (auto *VE : C->varlist()) {
11010 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11011 if (EVar.isInvalid())
11012 return nullptr;
11013 Vars.push_back(EVar.get());
11014 }
11015 ExprResult Step = getDerived().TransformExpr(C->getStep());
11016 if (Step.isInvalid())
11017 return nullptr;
11018 return getDerived().RebuildOMPLinearClause(
11019 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11020 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11021 C->getEndLoc());
11022}
11023
11024template <typename Derived>
11025OMPClause *
11026TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
11028 Vars.reserve(C->varlist_size());
11029 for (auto *VE : C->varlist()) {
11030 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11031 if (EVar.isInvalid())
11032 return nullptr;
11033 Vars.push_back(EVar.get());
11034 }
11035 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11036 if (Alignment.isInvalid())
11037 return nullptr;
11038 return getDerived().RebuildOMPAlignedClause(
11039 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11040 C->getColonLoc(), C->getEndLoc());
11041}
11042
11043template <typename Derived>
11044OMPClause *
11045TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
11047 Vars.reserve(C->varlist_size());
11048 for (auto *VE : C->varlist()) {
11049 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11050 if (EVar.isInvalid())
11051 return nullptr;
11052 Vars.push_back(EVar.get());
11053 }
11054 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11055 C->getLParenLoc(), C->getEndLoc());
11056}
11057
11058template <typename Derived>
11059OMPClause *
11060TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
11062 Vars.reserve(C->varlist_size());
11063 for (auto *VE : C->varlist()) {
11064 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11065 if (EVar.isInvalid())
11066 return nullptr;
11067 Vars.push_back(EVar.get());
11068 }
11069 return getDerived().RebuildOMPCopyprivateClause(
11070 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11071}
11072
11073template <typename Derived>
11074OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
11076 Vars.reserve(C->varlist_size());
11077 for (auto *VE : C->varlist()) {
11078 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11079 if (EVar.isInvalid())
11080 return nullptr;
11081 Vars.push_back(EVar.get());
11082 }
11083 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11084 C->getLParenLoc(), C->getEndLoc());
11085}
11086
11087template <typename Derived>
11088OMPClause *
11089TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) {
11090 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11091 if (E.isInvalid())
11092 return nullptr;
11093 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11094 C->getLParenLoc(), C->getEndLoc());
11095}
11096
11097template <typename Derived>
11098OMPClause *
11099TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
11101 Expr *DepModifier = C->getModifier();
11102 if (DepModifier) {
11103 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11104 if (DepModRes.isInvalid())
11105 return nullptr;
11106 DepModifier = DepModRes.get();
11107 }
11108 Vars.reserve(C->varlist_size());
11109 for (auto *VE : C->varlist()) {
11110 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11111 if (EVar.isInvalid())
11112 return nullptr;
11113 Vars.push_back(EVar.get());
11114 }
11115 return getDerived().RebuildOMPDependClause(
11116 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11117 C->getOmpAllMemoryLoc()},
11118 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11119}
11120
11121template <typename Derived>
11122OMPClause *
11123TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
11124 ExprResult E = getDerived().TransformExpr(C->getDevice());
11125 if (E.isInvalid())
11126 return nullptr;
11127 return getDerived().RebuildOMPDeviceClause(
11128 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11129 C->getModifierLoc(), C->getEndLoc());
11130}
11131
11132template <typename Derived, class T>
11135 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11136 DeclarationNameInfo &MapperIdInfo,
11137 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11138 // Transform expressions in the list.
11139 Vars.reserve(C->varlist_size());
11140 for (auto *VE : C->varlist()) {
11141 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11142 if (EVar.isInvalid())
11143 return true;
11144 Vars.push_back(EVar.get());
11145 }
11146 // Transform mapper scope specifier and identifier.
11147 NestedNameSpecifierLoc QualifierLoc;
11148 if (C->getMapperQualifierLoc()) {
11149 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11150 C->getMapperQualifierLoc());
11151 if (!QualifierLoc)
11152 return true;
11153 }
11154 MapperIdScopeSpec.Adopt(QualifierLoc);
11155 MapperIdInfo = C->getMapperIdInfo();
11156 if (MapperIdInfo.getName()) {
11157 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11158 if (!MapperIdInfo.getName())
11159 return true;
11160 }
11161 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11162 // the previous user-defined mapper lookup in dependent environment.
11163 for (auto *E : C->mapperlists()) {
11164 // Transform all the decls.
11165 if (E) {
11166 auto *ULE = cast<UnresolvedLookupExpr>(E);
11167 UnresolvedSet<8> Decls;
11168 for (auto *D : ULE->decls()) {
11169 NamedDecl *InstD =
11170 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11171 Decls.addDecl(InstD, InstD->getAccess());
11172 }
11173 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11174 TT.getSema().Context, /*NamingClass=*/nullptr,
11175 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11176 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11177 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11178 } else {
11179 UnresolvedMappers.push_back(nullptr);
11180 }
11181 }
11182 return false;
11183}
11184
11185template <typename Derived>
11186OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11187 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11189 Expr *IteratorModifier = C->getIteratorModifier();
11190 if (IteratorModifier) {
11191 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11192 if (MapModRes.isInvalid())
11193 return nullptr;
11194 IteratorModifier = MapModRes.get();
11195 }
11196 CXXScopeSpec MapperIdScopeSpec;
11197 DeclarationNameInfo MapperIdInfo;
11198 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11199 if (transformOMPMappableExprListClause<Derived, OMPMapClause>(
11200 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11201 return nullptr;
11202 return getDerived().RebuildOMPMapClause(
11203 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11204 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11205 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11206}
11207
11208template <typename Derived>
11209OMPClause *
11210TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) {
11211 Expr *Allocator = C->getAllocator();
11212 if (Allocator) {
11213 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11214 if (AllocatorRes.isInvalid())
11215 return nullptr;
11216 Allocator = AllocatorRes.get();
11217 }
11219 Vars.reserve(C->varlist_size());
11220 for (auto *VE : C->varlist()) {
11221 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11222 if (EVar.isInvalid())
11223 return nullptr;
11224 Vars.push_back(EVar.get());
11225 }
11226 return getDerived().RebuildOMPAllocateClause(
11227 Allocator, C->getAllocatorModifier(), Vars, C->getBeginLoc(),
11228 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11229}
11230
11231template <typename Derived>
11232OMPClause *
11233TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) {
11235 Vars.reserve(C->varlist_size());
11236 for (auto *VE : C->varlist()) {
11237 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11238 if (EVar.isInvalid())
11239 return nullptr;
11240 Vars.push_back(EVar.get());
11241 }
11242 return getDerived().RebuildOMPNumTeamsClause(
11243 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11244}
11245
11246template <typename Derived>
11247OMPClause *
11248TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) {
11250 Vars.reserve(C->varlist_size());
11251 for (auto *VE : C->varlist()) {
11252 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11253 if (EVar.isInvalid())
11254 return nullptr;
11255 Vars.push_back(EVar.get());
11256 }
11257 return getDerived().RebuildOMPThreadLimitClause(
11258 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11259}
11260
11261template <typename Derived>
11262OMPClause *
11263TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) {
11264 ExprResult E = getDerived().TransformExpr(C->getPriority());
11265 if (E.isInvalid())
11266 return nullptr;
11267 return getDerived().RebuildOMPPriorityClause(
11268 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11269}
11270
11271template <typename Derived>
11272OMPClause *
11273TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) {
11274 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11275 if (E.isInvalid())
11276 return nullptr;
11277 return getDerived().RebuildOMPGrainsizeClause(
11278 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11279 C->getModifierLoc(), C->getEndLoc());
11280}
11281
11282template <typename Derived>
11283OMPClause *
11284TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) {
11285 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11286 if (E.isInvalid())
11287 return nullptr;
11288 return getDerived().RebuildOMPNumTasksClause(
11289 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11290 C->getModifierLoc(), C->getEndLoc());
11291}
11292
11293template <typename Derived>
11294OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) {
11295 ExprResult E = getDerived().TransformExpr(C->getHint());
11296 if (E.isInvalid())
11297 return nullptr;
11298 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11299 C->getLParenLoc(), C->getEndLoc());
11300}
11301
11302template <typename Derived>
11303OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause(
11304 OMPDistScheduleClause *C) {
11305 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11306 if (E.isInvalid())
11307 return nullptr;
11308 return getDerived().RebuildOMPDistScheduleClause(
11309 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11310 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11311}
11312
11313template <typename Derived>
11314OMPClause *
11315TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) {
11316 // Rebuild Defaultmap Clause since we need to invoke the checking of
11317 // defaultmap(none:variable-category) after template initialization.
11318 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11319 C->getDefaultmapKind(),
11320 C->getBeginLoc(),
11321 C->getLParenLoc(),
11322 C->getDefaultmapModifierLoc(),
11323 C->getDefaultmapKindLoc(),
11324 C->getEndLoc());
11325}
11326
11327template <typename Derived>
11328OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) {
11329 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11331 CXXScopeSpec MapperIdScopeSpec;
11332 DeclarationNameInfo MapperIdInfo;
11333 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11334 if (transformOMPMappableExprListClause<Derived, OMPToClause>(
11335 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11336 return nullptr;
11337 return getDerived().RebuildOMPToClause(
11338 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11339 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11340}
11341
11342template <typename Derived>
11343OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) {
11344 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11346 CXXScopeSpec MapperIdScopeSpec;
11347 DeclarationNameInfo MapperIdInfo;
11348 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11349 if (transformOMPMappableExprListClause<Derived, OMPFromClause>(
11350 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11351 return nullptr;
11352 return getDerived().RebuildOMPFromClause(
11353 C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec,
11354 MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11355}
11356
11357template <typename Derived>
11358OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause(
11359 OMPUseDevicePtrClause *C) {
11361 Vars.reserve(C->varlist_size());
11362 for (auto *VE : C->varlist()) {
11363 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11364 if (EVar.isInvalid())
11365 return nullptr;
11366 Vars.push_back(EVar.get());
11367 }
11368 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11369 return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs);
11370}
11371
11372template <typename Derived>
11373OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause(
11374 OMPUseDeviceAddrClause *C) {
11376 Vars.reserve(C->varlist_size());
11377 for (auto *VE : C->varlist()) {
11378 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11379 if (EVar.isInvalid())
11380 return nullptr;
11381 Vars.push_back(EVar.get());
11382 }
11383 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11384 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11385}
11386
11387template <typename Derived>
11388OMPClause *
11389TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) {
11391 Vars.reserve(C->varlist_size());
11392 for (auto *VE : C->varlist()) {
11393 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11394 if (EVar.isInvalid())
11395 return nullptr;
11396 Vars.push_back(EVar.get());
11397 }
11398 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11399 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11400}
11401
11402template <typename Derived>
11403OMPClause *TreeTransform<Derived>::TransformOMPHasDeviceAddrClause(
11404 OMPHasDeviceAddrClause *C) {
11406 Vars.reserve(C->varlist_size());
11407 for (auto *VE : C->varlist()) {
11408 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11409 if (EVar.isInvalid())
11410 return nullptr;
11411 Vars.push_back(EVar.get());
11412 }
11413 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11414 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
11415}
11416
11417template <typename Derived>
11418OMPClause *
11419TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) {
11421 Vars.reserve(C->varlist_size());
11422 for (auto *VE : C->varlist()) {
11423 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11424 if (EVar.isInvalid())
11425 return nullptr;
11426 Vars.push_back(EVar.get());
11427 }
11428 return getDerived().RebuildOMPNontemporalClause(
11429 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11430}
11431
11432template <typename Derived>
11433OMPClause *
11434TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) {
11436 Vars.reserve(C->varlist_size());
11437 for (auto *VE : C->varlist()) {
11438 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11439 if (EVar.isInvalid())
11440 return nullptr;
11441 Vars.push_back(EVar.get());
11442 }
11443 return getDerived().RebuildOMPInclusiveClause(
11444 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11445}
11446
11447template <typename Derived>
11448OMPClause *
11449TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) {
11451 Vars.reserve(C->varlist_size());
11452 for (auto *VE : C->varlist()) {
11453 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11454 if (EVar.isInvalid())
11455 return nullptr;
11456 Vars.push_back(EVar.get());
11457 }
11458 return getDerived().RebuildOMPExclusiveClause(
11459 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11460}
11461
11462template <typename Derived>
11463OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause(
11464 OMPUsesAllocatorsClause *C) {
11466 Data.reserve(C->getNumberOfAllocators());
11467 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
11468 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
11469 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
11470 if (Allocator.isInvalid())
11471 continue;
11472 ExprResult AllocatorTraits;
11473 if (Expr *AT = D.AllocatorTraits) {
11474 AllocatorTraits = getDerived().TransformExpr(AT);
11475 if (AllocatorTraits.isInvalid())
11476 continue;
11477 }
11478 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
11479 NewD.Allocator = Allocator.get();
11480 NewD.AllocatorTraits = AllocatorTraits.get();
11481 NewD.LParenLoc = D.LParenLoc;
11482 NewD.RParenLoc = D.RParenLoc;
11483 }
11484 return getDerived().RebuildOMPUsesAllocatorsClause(
11485 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11486}
11487
11488template <typename Derived>
11489OMPClause *
11490TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) {
11491 SmallVector<Expr *, 4> Locators;
11492 Locators.reserve(C->varlist_size());
11493 ExprResult ModifierRes;
11494 if (Expr *Modifier = C->getModifier()) {
11495 ModifierRes = getDerived().TransformExpr(Modifier);
11496 if (ModifierRes.isInvalid())
11497 return nullptr;
11498 }
11499 for (Expr *E : C->varlist()) {
11500 ExprResult Locator = getDerived().TransformExpr(E);
11501 if (Locator.isInvalid())
11502 continue;
11503 Locators.push_back(Locator.get());
11504 }
11505 return getDerived().RebuildOMPAffinityClause(
11506 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
11507 ModifierRes.get(), Locators);
11508}
11509
11510template <typename Derived>
11511OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) {
11512 return getDerived().RebuildOMPOrderClause(
11513 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
11514 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
11515}
11516
11517template <typename Derived>
11518OMPClause *TreeTransform<Derived>::TransformOMPBindClause(OMPBindClause *C) {
11519 return getDerived().RebuildOMPBindClause(
11520 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
11521 C->getLParenLoc(), C->getEndLoc());
11522}
11523
11524template <typename Derived>
11525OMPClause *TreeTransform<Derived>::TransformOMPXDynCGroupMemClause(
11526 OMPXDynCGroupMemClause *C) {
11527 ExprResult Size = getDerived().TransformExpr(C->getSize());
11528 if (Size.isInvalid())
11529 return nullptr;
11530 return getDerived().RebuildOMPXDynCGroupMemClause(
11531 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11532}
11533
11534template <typename Derived>
11535OMPClause *
11536TreeTransform<Derived>::TransformOMPDoacrossClause(OMPDoacrossClause *C) {
11538 Vars.reserve(C->varlist_size());
11539 for (auto *VE : C->varlist()) {
11540 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11541 if (EVar.isInvalid())
11542 return nullptr;
11543 Vars.push_back(EVar.get());
11544 }
11545 return getDerived().RebuildOMPDoacrossClause(
11546 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
11547 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11548}
11549
11550template <typename Derived>
11551OMPClause *
11552TreeTransform<Derived>::TransformOMPXAttributeClause(OMPXAttributeClause *C) {
11554 for (auto *A : C->getAttrs())
11555 NewAttrs.push_back(getDerived().TransformAttr(A));
11556 return getDerived().RebuildOMPXAttributeClause(
11557 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11558}
11559
11560template <typename Derived>
11561OMPClause *TreeTransform<Derived>::TransformOMPXBareClause(OMPXBareClause *C) {
11562 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
11563}
11564
11565//===----------------------------------------------------------------------===//
11566// OpenACC transformation
11567//===----------------------------------------------------------------------===//
11568namespace {
11569template <typename Derived>
11570class OpenACCClauseTransform final
11571 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
11572 TreeTransform<Derived> &Self;
11573 ArrayRef<const OpenACCClause *> ExistingClauses;
11574 SemaOpenACC::OpenACCParsedClause &ParsedClause;
11575 OpenACCClause *NewClause = nullptr;
11576
11577 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
11578 llvm::SmallVector<Expr *> InstantiatedVarList;
11579 for (Expr *CurVar : VarList) {
11580 ExprResult Res = Self.TransformExpr(CurVar);
11581
11582 if (!Res.isUsable())
11583 continue;
11584
11585 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getClauseKind(),
11586 Res.get());
11587
11588 if (Res.isUsable())
11589 InstantiatedVarList.push_back(Res.get());
11590 }
11591
11592 return InstantiatedVarList;
11593 }
11594
11595public:
11596 OpenACCClauseTransform(TreeTransform<Derived> &Self,
11597 ArrayRef<const OpenACCClause *> ExistingClauses,
11598 SemaOpenACC::OpenACCParsedClause &PC)
11599 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
11600
11601 OpenACCClause *CreatedClause() const { return NewClause; }
11602
11603#define VISIT_CLAUSE(CLAUSE_NAME) \
11604 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
11605#include "clang/Basic/OpenACCClauses.def"
11606};
11607
11608template <typename Derived>
11609void OpenACCClauseTransform<Derived>::VisitDefaultClause(
11610 const OpenACCDefaultClause &C) {
11611 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
11612
11613 NewClause = OpenACCDefaultClause::Create(
11614 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
11615 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11616 ParsedClause.getEndLoc());
11617}
11618
11619template <typename Derived>
11620void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
11621 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11622 assert(Cond && "If constructed with invalid Condition");
11623 Sema::ConditionResult Res = Self.TransformCondition(
11624 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
11625
11626 if (Res.isInvalid() || !Res.get().second)
11627 return;
11628
11629 ParsedClause.setConditionDetails(Res.get().second);
11630
11631 NewClause = OpenACCIfClause::Create(
11632 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11633 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11634 ParsedClause.getEndLoc());
11635}
11636
11637template <typename Derived>
11638void OpenACCClauseTransform<Derived>::VisitSelfClause(
11639 const OpenACCSelfClause &C) {
11640
11641 if (C.hasConditionExpr()) {
11642 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
11643 Sema::ConditionResult Res =
11644 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
11646
11647 if (Res.isInvalid() || !Res.get().second)
11648 return;
11649
11650 ParsedClause.setConditionDetails(Res.get().second);
11651 }
11652
11653 NewClause = OpenACCSelfClause::Create(
11654 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11655 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
11656 ParsedClause.getEndLoc());
11657}
11658
11659template <typename Derived>
11660void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
11661 const OpenACCNumGangsClause &C) {
11662 llvm::SmallVector<Expr *> InstantiatedIntExprs;
11663
11664 for (Expr *CurIntExpr : C.getIntExprs()) {
11665 ExprResult Res = Self.TransformExpr(CurIntExpr);
11666
11667 if (!Res.isUsable())
11668 return;
11669
11670 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11671 C.getClauseKind(),
11672 C.getBeginLoc(), Res.get());
11673 if (!Res.isUsable())
11674 return;
11675
11676 InstantiatedIntExprs.push_back(Res.get());
11677 }
11678
11679 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
11681 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11682 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
11683 ParsedClause.getEndLoc());
11684}
11685
11686template <typename Derived>
11687void OpenACCClauseTransform<Derived>::VisitPrivateClause(
11688 const OpenACCPrivateClause &C) {
11689 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11690 /*IsReadOnly=*/false, /*IsZero=*/false);
11691
11692 NewClause = OpenACCPrivateClause::Create(
11693 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11694 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11695 ParsedClause.getEndLoc());
11696}
11697
11698template <typename Derived>
11699void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
11700 const OpenACCFirstPrivateClause &C) {
11701 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11702 /*IsReadOnly=*/false, /*IsZero=*/false);
11703
11705 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11706 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11707 ParsedClause.getEndLoc());
11708}
11709
11710template <typename Derived>
11711void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
11712 const OpenACCNoCreateClause &C) {
11713 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11714 /*IsReadOnly=*/false, /*IsZero=*/false);
11715
11717 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11718 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11719 ParsedClause.getEndLoc());
11720}
11721
11722template <typename Derived>
11723void OpenACCClauseTransform<Derived>::VisitPresentClause(
11724 const OpenACCPresentClause &C) {
11725 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11726 /*IsReadOnly=*/false, /*IsZero=*/false);
11727
11728 NewClause = OpenACCPresentClause::Create(
11729 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11730 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11731 ParsedClause.getEndLoc());
11732}
11733
11734template <typename Derived>
11735void OpenACCClauseTransform<Derived>::VisitCopyClause(
11736 const OpenACCCopyClause &C) {
11737 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11738 /*IsReadOnly=*/false, /*IsZero=*/false);
11739
11740 NewClause = OpenACCCopyClause::Create(
11741 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11742 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11743 ParsedClause.getVarList(), ParsedClause.getEndLoc());
11744}
11745
11746template <typename Derived>
11747void OpenACCClauseTransform<Derived>::VisitCopyInClause(
11748 const OpenACCCopyInClause &C) {
11749 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()), C.isReadOnly(),
11750 /*IsZero=*/false);
11751
11752 NewClause = OpenACCCopyInClause::Create(
11753 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11754 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11755 ParsedClause.isReadOnly(), ParsedClause.getVarList(),
11756 ParsedClause.getEndLoc());
11757}
11758
11759template <typename Derived>
11760void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
11761 const OpenACCCopyOutClause &C) {
11762 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11763 /*IsReadOnly=*/false, C.isZero());
11764
11765 NewClause = OpenACCCopyOutClause::Create(
11766 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11767 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11768 ParsedClause.isZero(), ParsedClause.getVarList(),
11769 ParsedClause.getEndLoc());
11770}
11771
11772template <typename Derived>
11773void OpenACCClauseTransform<Derived>::VisitCreateClause(
11774 const OpenACCCreateClause &C) {
11775 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11776 /*IsReadOnly=*/false, C.isZero());
11777
11778 NewClause = OpenACCCreateClause::Create(
11779 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
11780 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
11781 ParsedClause.isZero(), ParsedClause.getVarList(),
11782 ParsedClause.getEndLoc());
11783}
11784template <typename Derived>
11785void OpenACCClauseTransform<Derived>::VisitAttachClause(
11786 const OpenACCAttachClause &C) {
11787 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11788
11789 // Ensure each var is a pointer type.
11790 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11791 return Self.getSema().OpenACC().CheckVarIsPointerType(
11792 OpenACCClauseKind::Attach, E);
11793 }), VarList.end());
11794
11795 ParsedClause.setVarListDetails(VarList,
11796 /*IsReadOnly=*/false, /*IsZero=*/false);
11797 NewClause = OpenACCAttachClause::Create(
11798 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11799 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11800 ParsedClause.getEndLoc());
11801}
11802
11803template <typename Derived>
11804void OpenACCClauseTransform<Derived>::VisitDetachClause(
11805 const OpenACCDetachClause &C) {
11806 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11807
11808 // Ensure each var is a pointer type.
11809 VarList.erase(
11810 std::remove_if(VarList.begin(), VarList.end(),
11811 [&](Expr *E) {
11812 return Self.getSema().OpenACC().CheckVarIsPointerType(
11813 OpenACCClauseKind::Detach, E);
11814 }),
11815 VarList.end());
11816
11817 ParsedClause.setVarListDetails(VarList,
11818 /*IsReadOnly=*/false, /*IsZero=*/false);
11819 NewClause = OpenACCDetachClause::Create(
11820 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11821 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11822 ParsedClause.getEndLoc());
11823}
11824
11825template <typename Derived>
11826void OpenACCClauseTransform<Derived>::VisitDeleteClause(
11827 const OpenACCDeleteClause &C) {
11828 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11829 /*IsReadOnly=*/false, /*IsZero=*/false);
11830 NewClause = OpenACCDeleteClause::Create(
11831 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11832 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11833 ParsedClause.getEndLoc());
11834}
11835
11836template <typename Derived>
11837void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
11838 const OpenACCUseDeviceClause &C) {
11839 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
11840 /*IsReadOnly=*/false, /*IsZero=*/false);
11842 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11843 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11844 ParsedClause.getEndLoc());
11845}
11846
11847template <typename Derived>
11848void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
11849 const OpenACCDevicePtrClause &C) {
11850 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
11851
11852 // Ensure each var is a pointer type.
11853 VarList.erase(std::remove_if(VarList.begin(), VarList.end(), [&](Expr *E) {
11854 return Self.getSema().OpenACC().CheckVarIsPointerType(
11855 OpenACCClauseKind::DevicePtr, E);
11856 }), VarList.end());
11857
11858 ParsedClause.setVarListDetails(VarList,
11859 /*IsReadOnly=*/false, /*IsZero=*/false);
11861 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11862 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
11863 ParsedClause.getEndLoc());
11864}
11865
11866template <typename Derived>
11867void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
11868 const OpenACCNumWorkersClause &C) {
11869 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11870 assert(IntExpr && "num_workers clause constructed with invalid int expr");
11871
11872 ExprResult Res = Self.TransformExpr(IntExpr);
11873 if (!Res.isUsable())
11874 return;
11875
11876 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11877 C.getClauseKind(),
11878 C.getBeginLoc(), Res.get());
11879 if (!Res.isUsable())
11880 return;
11881
11882 ParsedClause.setIntExprDetails(Res.get());
11884 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11885 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11886 ParsedClause.getEndLoc());
11887}
11888
11889template <typename Derived>
11890void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
11891 const OpenACCDeviceNumClause &C) {
11892 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11893 assert(IntExpr && "device_num clause constructed with invalid int expr");
11894
11895 ExprResult Res = Self.TransformExpr(IntExpr);
11896 if (!Res.isUsable())
11897 return;
11898
11899 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11900 C.getClauseKind(),
11901 C.getBeginLoc(), Res.get());
11902 if (!Res.isUsable())
11903 return;
11904
11905 ParsedClause.setIntExprDetails(Res.get());
11907 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11908 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11909 ParsedClause.getEndLoc());
11910}
11911
11912template <typename Derived>
11913void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
11914 const OpenACCDefaultAsyncClause &C) {
11915 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11916 assert(IntExpr && "default_async clause constructed with invalid int expr");
11917
11918 ExprResult Res = Self.TransformExpr(IntExpr);
11919 if (!Res.isUsable())
11920 return;
11921
11922 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11923 C.getClauseKind(),
11924 C.getBeginLoc(), Res.get());
11925 if (!Res.isUsable())
11926 return;
11927
11928 ParsedClause.setIntExprDetails(Res.get());
11930 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11931 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11932 ParsedClause.getEndLoc());
11933}
11934
11935template <typename Derived>
11936void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
11937 const OpenACCVectorLengthClause &C) {
11938 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
11939 assert(IntExpr && "vector_length clause constructed with invalid int expr");
11940
11941 ExprResult Res = Self.TransformExpr(IntExpr);
11942 if (!Res.isUsable())
11943 return;
11944
11945 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11946 C.getClauseKind(),
11947 C.getBeginLoc(), Res.get());
11948 if (!Res.isUsable())
11949 return;
11950
11951 ParsedClause.setIntExprDetails(Res.get());
11953 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11954 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
11955 ParsedClause.getEndLoc());
11956}
11957
11958template <typename Derived>
11959void OpenACCClauseTransform<Derived>::VisitAsyncClause(
11960 const OpenACCAsyncClause &C) {
11961 if (C.hasIntExpr()) {
11962 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
11963 if (!Res.isUsable())
11964 return;
11965
11966 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11967 C.getClauseKind(),
11968 C.getBeginLoc(), Res.get());
11969 if (!Res.isUsable())
11970 return;
11971 ParsedClause.setIntExprDetails(Res.get());
11972 }
11973
11974 NewClause = OpenACCAsyncClause::Create(
11975 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
11976 ParsedClause.getLParenLoc(),
11977 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
11978 : nullptr,
11979 ParsedClause.getEndLoc());
11980}
11981
11982template <typename Derived>
11983void OpenACCClauseTransform<Derived>::VisitWorkerClause(
11984 const OpenACCWorkerClause &C) {
11985 if (C.hasIntExpr()) {
11986 // restrictions on this expression are all "does it exist in certain
11987 // situations" that are not possible to be dependent, so the only check we
11988 // have is that it transforms, and is an int expression.
11989 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
11990 if (!Res.isUsable())
11991 return;
11992
11993 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
11994 C.getClauseKind(),
11995 C.getBeginLoc(), Res.get());
11996 if (!Res.isUsable())
11997 return;
11998 ParsedClause.setIntExprDetails(Res.get());
11999 }
12000
12001 NewClause = OpenACCWorkerClause::Create(
12002 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12003 ParsedClause.getLParenLoc(),
12004 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12005 : nullptr,
12006 ParsedClause.getEndLoc());
12007}
12008
12009template <typename Derived>
12010void OpenACCClauseTransform<Derived>::VisitVectorClause(
12011 const OpenACCVectorClause &C) {
12012 if (C.hasIntExpr()) {
12013 // restrictions on this expression are all "does it exist in certain
12014 // situations" that are not possible to be dependent, so the only check we
12015 // have is that it transforms, and is an int expression.
12016 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12017 if (!Res.isUsable())
12018 return;
12019
12020 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12021 C.getClauseKind(),
12022 C.getBeginLoc(), Res.get());
12023 if (!Res.isUsable())
12024 return;
12025 ParsedClause.setIntExprDetails(Res.get());
12026 }
12027
12028 NewClause = OpenACCVectorClause::Create(
12029 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12030 ParsedClause.getLParenLoc(),
12031 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12032 : nullptr,
12033 ParsedClause.getEndLoc());
12034}
12035
12036template <typename Derived>
12037void OpenACCClauseTransform<Derived>::VisitWaitClause(
12038 const OpenACCWaitClause &C) {
12039 if (!C.getLParenLoc().isInvalid()) {
12040 Expr *DevNumExpr = nullptr;
12041 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12042
12043 // Instantiate devnum expr if it exists.
12044 if (C.getDevNumExpr()) {
12045 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12046 if (!Res.isUsable())
12047 return;
12048 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12049 C.getClauseKind(),
12050 C.getBeginLoc(), Res.get());
12051 if (!Res.isUsable())
12052 return;
12053
12054 DevNumExpr = Res.get();
12055 }
12056
12057 // Instantiate queue ids.
12058 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12059 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12060 if (!Res.isUsable())
12061 return;
12062 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12063 C.getClauseKind(),
12064 C.getBeginLoc(), Res.get());
12065 if (!Res.isUsable())
12066 return;
12067
12068 InstantiatedQueueIdExprs.push_back(Res.get());
12069 }
12070
12071 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12072 std::move(InstantiatedQueueIdExprs));
12073 }
12074
12075 NewClause = OpenACCWaitClause::Create(
12076 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12077 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12078 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12079 ParsedClause.getEndLoc());
12080}
12081
12082template <typename Derived>
12083void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12084 const OpenACCDeviceTypeClause &C) {
12085 // Nothing to transform here, just create a new version of 'C'.
12087 Self.getSema().getASTContext(), C.getClauseKind(),
12088 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12089 C.getArchitectures(), ParsedClause.getEndLoc());
12090}
12091
12092template <typename Derived>
12093void OpenACCClauseTransform<Derived>::VisitAutoClause(
12094 const OpenACCAutoClause &C) {
12095 // Nothing to do, so just create a new node.
12096 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12097 ParsedClause.getBeginLoc(),
12098 ParsedClause.getEndLoc());
12099}
12100
12101template <typename Derived>
12102void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12103 const OpenACCIndependentClause &C) {
12104 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12105 ParsedClause.getBeginLoc(),
12106 ParsedClause.getEndLoc());
12107}
12108
12109template <typename Derived>
12110void OpenACCClauseTransform<Derived>::VisitSeqClause(
12111 const OpenACCSeqClause &C) {
12112 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12113 ParsedClause.getBeginLoc(),
12114 ParsedClause.getEndLoc());
12115}
12116template <typename Derived>
12117void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12118 const OpenACCFinalizeClause &C) {
12119 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12120 ParsedClause.getBeginLoc(),
12121 ParsedClause.getEndLoc());
12122}
12123
12124template <typename Derived>
12125void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12126 const OpenACCIfPresentClause &C) {
12127 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12128 ParsedClause.getBeginLoc(),
12129 ParsedClause.getEndLoc());
12130}
12131
12132template <typename Derived>
12133void OpenACCClauseTransform<Derived>::VisitReductionClause(
12134 const OpenACCReductionClause &C) {
12135 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12136 SmallVector<Expr *> ValidVars;
12137
12138 for (Expr *Var : TransformedVars) {
12139 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12140 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12141 if (Res.isUsable())
12142 ValidVars.push_back(Res.get());
12143 }
12144
12145 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12146 ExistingClauses, ParsedClause.getDirectiveKind(),
12147 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12148 C.getReductionOp(), ValidVars, ParsedClause.getEndLoc());
12149}
12150
12151template <typename Derived>
12152void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12153 const OpenACCCollapseClause &C) {
12154 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12155 assert(LoopCount && "collapse clause constructed with invalid loop count");
12156
12157 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12158
12159 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12161 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12162
12163 NewLoopCount =
12164 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12165
12166 if (!NewLoopCount.isUsable())
12167 return;
12168
12169 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12171 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12172 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12173 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12174}
12175
12176template <typename Derived>
12177void OpenACCClauseTransform<Derived>::VisitTileClause(
12178 const OpenACCTileClause &C) {
12179
12180 llvm::SmallVector<Expr *> TransformedExprs;
12181
12182 for (Expr *E : C.getSizeExprs()) {
12183 ExprResult NewSizeExpr = Self.TransformExpr(E);
12184
12185 if (!NewSizeExpr.isUsable())
12186 return;
12187
12188 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12190 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12191
12192 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12193
12194 if (!NewSizeExpr.isUsable())
12195 return;
12196 TransformedExprs.push_back(NewSizeExpr.get());
12197 }
12198
12199 ParsedClause.setIntExprDetails(TransformedExprs);
12200 NewClause = OpenACCTileClause::Create(
12201 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12202 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12203 ParsedClause.getEndLoc());
12204}
12205template <typename Derived>
12206void OpenACCClauseTransform<Derived>::VisitGangClause(
12207 const OpenACCGangClause &C) {
12208 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12209 llvm::SmallVector<Expr *> TransformedIntExprs;
12210
12211 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12212 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12213 if (!ER.isUsable())
12214 continue;
12215
12216 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12217 ParsedClause.getDirectiveKind(),
12218 C.getExpr(I).first, ER.get());
12219 if (!ER.isUsable())
12220 continue;
12221 TransformedGangKinds.push_back(C.getExpr(I).first);
12222 TransformedIntExprs.push_back(ER.get());
12223 }
12224
12225 NewClause = Self.getSema().OpenACC().CheckGangClause(
12226 ParsedClause.getDirectiveKind(), ExistingClauses,
12227 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12228 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12229}
12230} // namespace
12231template <typename Derived>
12232OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12233 ArrayRef<const OpenACCClause *> ExistingClauses,
12234 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12235
12236 SemaOpenACC::OpenACCParsedClause ParsedClause(
12237 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12238 ParsedClause.setEndLoc(OldClause->getEndLoc());
12239
12240 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12241 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12242
12243 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12244 ParsedClause};
12245 Transform.Visit(OldClause);
12246
12247 return Transform.CreatedClause();
12248}
12249
12250template <typename Derived>
12252TreeTransform<Derived>::TransformOpenACCClauseList(
12254 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12255 for (const auto *Clause : OldClauses) {
12256 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12257 TransformedClauses, DirKind, Clause))
12258 TransformedClauses.push_back(TransformedClause);
12259 }
12260 return TransformedClauses;
12261}
12262
12263template <typename Derived>
12264StmtResult TreeTransform<Derived>::TransformOpenACCComputeConstruct(
12265 OpenACCComputeConstruct *C) {
12266 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12267
12268 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12269 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12270 C->clauses());
12271
12272 if (getSema().OpenACC().ActOnStartStmtDirective(
12273 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12274 return StmtError();
12275
12276 // Transform Structured Block.
12277 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12278 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12279 C->clauses(), TransformedClauses);
12280 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12281 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12282 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12283
12284 return getDerived().RebuildOpenACCComputeConstruct(
12285 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12286 C->getEndLoc(), TransformedClauses, StrBlock);
12287}
12288
12289template <typename Derived>
12291TreeTransform<Derived>::TransformOpenACCLoopConstruct(OpenACCLoopConstruct *C) {
12292
12293 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12294
12295 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12296 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12297 C->clauses());
12298
12299 if (getSema().OpenACC().ActOnStartStmtDirective(
12300 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12301 return StmtError();
12302
12303 // Transform Loop.
12304 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12305 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12306 C->clauses(), TransformedClauses);
12307 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12308 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12309 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12310
12311 return getDerived().RebuildOpenACCLoopConstruct(
12312 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12313 TransformedClauses, Loop);
12314}
12315
12316template <typename Derived>
12317StmtResult TreeTransform<Derived>::TransformOpenACCCombinedConstruct(
12318 OpenACCCombinedConstruct *C) {
12319 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12320
12321 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12322 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12323 C->clauses());
12324
12325 if (getSema().OpenACC().ActOnStartStmtDirective(
12326 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12327 return StmtError();
12328
12329 // Transform Loop.
12330 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12331 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12332 C->clauses(), TransformedClauses);
12333 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
12334 Loop = getSema().OpenACC().ActOnAssociatedStmt(
12335 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
12336
12337 return getDerived().RebuildOpenACCCombinedConstruct(
12338 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
12339 C->getEndLoc(), TransformedClauses, Loop);
12340}
12341
12342template <typename Derived>
12344TreeTransform<Derived>::TransformOpenACCDataConstruct(OpenACCDataConstruct *C) {
12345 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12346
12347 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12348 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12349 C->clauses());
12350 if (getSema().OpenACC().ActOnStartStmtDirective(
12351 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12352 return StmtError();
12353
12354 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12355 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12356 C->clauses(), TransformedClauses);
12357 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12358 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12359 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12360
12361 return getDerived().RebuildOpenACCDataConstruct(
12362 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12363 TransformedClauses, StrBlock);
12364}
12365
12366template <typename Derived>
12367StmtResult TreeTransform<Derived>::TransformOpenACCEnterDataConstruct(
12368 OpenACCEnterDataConstruct *C) {
12369 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12370
12371 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12372 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12373 C->clauses());
12374 if (getSema().OpenACC().ActOnStartStmtDirective(
12375 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12376 return StmtError();
12377
12378 return getDerived().RebuildOpenACCEnterDataConstruct(
12379 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12380 TransformedClauses);
12381}
12382
12383template <typename Derived>
12384StmtResult TreeTransform<Derived>::TransformOpenACCExitDataConstruct(
12385 OpenACCExitDataConstruct *C) {
12386 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12387
12388 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12389 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12390 C->clauses());
12391 if (getSema().OpenACC().ActOnStartStmtDirective(
12392 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12393 return StmtError();
12394
12395 return getDerived().RebuildOpenACCExitDataConstruct(
12396 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12397 TransformedClauses);
12398}
12399
12400template <typename Derived>
12401StmtResult TreeTransform<Derived>::TransformOpenACCHostDataConstruct(
12402 OpenACCHostDataConstruct *C) {
12403 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12404
12405 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12406 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12407 C->clauses());
12408 if (getSema().OpenACC().ActOnStartStmtDirective(
12409 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12410 return StmtError();
12411
12412 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
12413 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
12414 C->clauses(), TransformedClauses);
12415 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
12416 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
12417 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
12418
12419 return getDerived().RebuildOpenACCHostDataConstruct(
12420 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12421 TransformedClauses, StrBlock);
12422}
12423
12424template <typename Derived>
12426TreeTransform<Derived>::TransformOpenACCInitConstruct(OpenACCInitConstruct *C) {
12427 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12428
12429 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12430 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12431 C->clauses());
12432 if (getSema().OpenACC().ActOnStartStmtDirective(
12433 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12434 return StmtError();
12435
12436 return getDerived().RebuildOpenACCInitConstruct(
12437 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12438 TransformedClauses);
12439}
12440
12441template <typename Derived>
12442StmtResult TreeTransform<Derived>::TransformOpenACCShutdownConstruct(
12443 OpenACCShutdownConstruct *C) {
12444 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12445
12446 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12447 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12448 C->clauses());
12449 if (getSema().OpenACC().ActOnStartStmtDirective(
12450 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12451 return StmtError();
12452
12453 return getDerived().RebuildOpenACCShutdownConstruct(
12454 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12455 TransformedClauses);
12456}
12457template <typename Derived>
12459TreeTransform<Derived>::TransformOpenACCSetConstruct(OpenACCSetConstruct *C) {
12460 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12461
12462 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12463 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12464 C->clauses());
12465 if (getSema().OpenACC().ActOnStartStmtDirective(
12466 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12467 return StmtError();
12468
12469 return getDerived().RebuildOpenACCSetConstruct(
12470 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
12471 TransformedClauses);
12472}
12473
12474template <typename Derived>
12476TreeTransform<Derived>::TransformOpenACCWaitConstruct(OpenACCWaitConstruct *C) {
12477 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
12478
12479 ExprResult DevNumExpr;
12480 if (C->hasDevNumExpr()) {
12481 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
12482
12483 if (DevNumExpr.isUsable())
12484 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
12486 C->getBeginLoc(), DevNumExpr.get());
12487 }
12488
12489 llvm::SmallVector<Expr *> QueueIdExprs;
12490
12491 for (Expr *QE : C->getQueueIdExprs()) {
12492 assert(QE && "Null queue id expr?");
12493 ExprResult NewEQ = getDerived().TransformExpr(QE);
12494
12495 if (!NewEQ.isUsable())
12496 break;
12497 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
12499 C->getBeginLoc(), NewEQ.get());
12500 if (NewEQ.isUsable())
12501 QueueIdExprs.push_back(NewEQ.get());
12502 }
12503
12504 llvm::SmallVector<OpenACCClause *> TransformedClauses =
12505 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
12506 C->clauses());
12507
12508 if (getSema().OpenACC().ActOnStartStmtDirective(
12509 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
12510 return StmtError();
12511
12512 return getDerived().RebuildOpenACCWaitConstruct(
12513 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
12514 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
12515 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
12516}
12517
12518template <typename Derived>
12519ExprResult TreeTransform<Derived>::TransformOpenACCAsteriskSizeExpr(
12520 OpenACCAsteriskSizeExpr *E) {
12521 if (getDerived().AlwaysRebuild())
12522 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
12523 // Nothing can ever change, so there is never anything to transform.
12524 return E;
12525}
12526
12527//===----------------------------------------------------------------------===//
12528// Expression transformation
12529//===----------------------------------------------------------------------===//
12530template<typename Derived>
12532TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) {
12533 return TransformExpr(E->getSubExpr());
12534}
12535
12536template <typename Derived>
12537ExprResult TreeTransform<Derived>::TransformSYCLUniqueStableNameExpr(
12538 SYCLUniqueStableNameExpr *E) {
12539 if (!E->isTypeDependent())
12540 return E;
12541
12542 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
12543
12544 if (!NewT)
12545 return ExprError();
12546
12547 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
12548 return E;
12549
12550 return getDerived().RebuildSYCLUniqueStableNameExpr(
12551 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
12552}
12553
12554template<typename Derived>
12556TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
12557 if (!E->isTypeDependent())
12558 return E;
12559
12560 return getDerived().RebuildPredefinedExpr(E->getLocation(),
12561 E->getIdentKind());
12562}
12563
12564template<typename Derived>
12566TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
12567 NestedNameSpecifierLoc QualifierLoc;
12568 if (E->getQualifierLoc()) {
12569 QualifierLoc
12570 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
12571 if (!QualifierLoc)
12572 return ExprError();
12573 }
12574
12575 ValueDecl *ND
12576 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
12577 E->getDecl()));
12578 if (!ND)
12579 return ExprError();
12580
12581 NamedDecl *Found = ND;
12582 if (E->getFoundDecl() != E->getDecl()) {
12583 Found = cast_or_null<NamedDecl>(
12584 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
12585 if (!Found)
12586 return ExprError();
12587 }
12588
12589 DeclarationNameInfo NameInfo = E->getNameInfo();
12590 if (NameInfo.getName()) {
12591 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
12592 if (!NameInfo.getName())
12593 return ExprError();
12594 }
12595
12596 if (!getDerived().AlwaysRebuild() &&
12597 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
12598 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
12599 Found == E->getFoundDecl() &&
12600 NameInfo.getName() == E->getDecl()->getDeclName() &&
12601 !E->hasExplicitTemplateArgs()) {
12602
12603 // Mark it referenced in the new context regardless.
12604 // FIXME: this is a bit instantiation-specific.
12605 SemaRef.MarkDeclRefReferenced(E);
12606
12607 return E;
12608 }
12609
12610 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
12611 if (E->hasExplicitTemplateArgs()) {
12612 TemplateArgs = &TransArgs;
12613 TransArgs.setLAngleLoc(E->getLAngleLoc());
12614 TransArgs.setRAngleLoc(E->getRAngleLoc());
12615 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
12616 E->getNumTemplateArgs(),
12617 TransArgs))
12618 return ExprError();
12619 }
12620
12621 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
12622 Found, TemplateArgs);
12623}
12624
12625template<typename Derived>
12627TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
12628 return E;
12629}
12630
12631template <typename Derived>
12632ExprResult TreeTransform<Derived>::TransformFixedPointLiteral(
12633 FixedPointLiteral *E) {
12634 return E;
12635}
12636
12637template<typename Derived>
12639TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
12640 return E;
12641}
12642
12643template<typename Derived>
12645TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
12646 return E;
12647}
12648
12649template<typename Derived>
12651TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
12652 return E;
12653}
12654
12655template<typename Derived>
12657TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
12658 return E;
12659}
12660
12661template<typename Derived>
12663TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
12664 return getDerived().TransformCallExpr(E);
12665}
12666
12667template<typename Derived>
12669TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
12670 ExprResult ControllingExpr;
12671 TypeSourceInfo *ControllingType = nullptr;
12672 if (E->isExprPredicate())
12673 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
12674 else
12675 ControllingType = getDerived().TransformType(E->getControllingType());
12676
12677 if (ControllingExpr.isInvalid() && !ControllingType)
12678 return ExprError();
12679
12680 SmallVector<Expr *, 4> AssocExprs;
12682 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
12683 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
12684 if (TSI) {
12685 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
12686 if (!AssocType)
12687 return ExprError();
12688 AssocTypes.push_back(AssocType);
12689 } else {
12690 AssocTypes.push_back(nullptr);
12691 }
12692
12693 ExprResult AssocExpr =
12694 getDerived().TransformExpr(Assoc.getAssociationExpr());
12695 if (AssocExpr.isInvalid())
12696 return ExprError();
12697 AssocExprs.push_back(AssocExpr.get());
12698 }
12699
12700 if (!ControllingType)
12701 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
12702 E->getDefaultLoc(),
12703 E->getRParenLoc(),
12704 ControllingExpr.get(),
12705 AssocTypes,
12706 AssocExprs);
12707 return getDerived().RebuildGenericSelectionExpr(
12708 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
12709 ControllingType, AssocTypes, AssocExprs);
12710}
12711
12712template<typename Derived>
12714TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
12715 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
12716 if (SubExpr.isInvalid())
12717 return ExprError();
12718
12719 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
12720 return E;
12721
12722 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
12723 E->getRParen());
12724}
12725
12726/// The operand of a unary address-of operator has special rules: it's
12727/// allowed to refer to a non-static member of a class even if there's no 'this'
12728/// object available.
12729template<typename Derived>
12732 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
12733 return getDerived().TransformDependentScopeDeclRefExpr(
12734 DRE, /*IsAddressOfOperand=*/true, nullptr);
12735 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
12736 return getDerived().TransformUnresolvedLookupExpr(
12737 ULE, /*IsAddressOfOperand=*/true);
12738 else
12739 return getDerived().TransformExpr(E);
12740}
12741
12742template<typename Derived>
12745 ExprResult SubExpr;
12746 if (E->getOpcode() == UO_AddrOf)
12747 SubExpr = TransformAddressOfOperand(E->getSubExpr());
12748 else
12749 SubExpr = TransformExpr(E->getSubExpr());
12750 if (SubExpr.isInvalid())
12751 return ExprError();
12752
12753 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
12754 return E;
12755
12756 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
12757 E->getOpcode(),
12758 SubExpr.get());
12759}
12760
12761template<typename Derived>
12763TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
12764 // Transform the type.
12765 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
12766 if (!Type)
12767 return ExprError();
12768
12769 // Transform all of the components into components similar to what the
12770 // parser uses.
12771 // FIXME: It would be slightly more efficient in the non-dependent case to
12772 // just map FieldDecls, rather than requiring the rebuilder to look for
12773 // the fields again. However, __builtin_offsetof is rare enough in
12774 // template code that we don't care.
12775 bool ExprChanged = false;
12776 typedef Sema::OffsetOfComponent Component;
12777 SmallVector<Component, 4> Components;
12778 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
12779 const OffsetOfNode &ON = E->getComponent(I);
12780 Component Comp;
12781 Comp.isBrackets = true;
12782 Comp.LocStart = ON.getSourceRange().getBegin();
12783 Comp.LocEnd = ON.getSourceRange().getEnd();
12784 switch (ON.getKind()) {
12785 case OffsetOfNode::Array: {
12786 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
12787 ExprResult Index = getDerived().TransformExpr(FromIndex);
12788 if (Index.isInvalid())
12789 return ExprError();
12790
12791 ExprChanged = ExprChanged || Index.get() != FromIndex;
12792 Comp.isBrackets = true;
12793 Comp.U.E = Index.get();
12794 break;
12795 }
12796
12799 Comp.isBrackets = false;
12800 Comp.U.IdentInfo = ON.getFieldName();
12801 if (!Comp.U.IdentInfo)
12802 continue;
12803
12804 break;
12805
12806 case OffsetOfNode::Base:
12807 // Will be recomputed during the rebuild.
12808 continue;
12809 }
12810
12811 Components.push_back(Comp);
12812 }
12813
12814 // If nothing changed, retain the existing expression.
12815 if (!getDerived().AlwaysRebuild() &&
12816 Type == E->getTypeSourceInfo() &&
12817 !ExprChanged)
12818 return E;
12819
12820 // Build a new offsetof expression.
12821 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
12822 Components, E->getRParenLoc());
12823}
12824
12825template<typename Derived>
12827TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
12828 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
12829 "opaque value expression requires transformation");
12830 return E;
12831}
12832
12833template<typename Derived>
12835TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
12836 return E;
12837}
12838
12839template <typename Derived>
12840ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) {
12842 bool Changed = false;
12843 for (Expr *C : E->subExpressions()) {
12844 ExprResult NewC = getDerived().TransformExpr(C);
12845 if (NewC.isInvalid())
12846 return ExprError();
12847 Children.push_back(NewC.get());
12848
12849 Changed |= NewC.get() != C;
12850 }
12851 if (!getDerived().AlwaysRebuild() && !Changed)
12852 return E;
12853 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
12854 Children, E->getType());
12855}
12856
12857template<typename Derived>
12859TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
12860 // Rebuild the syntactic form. The original syntactic form has
12861 // opaque-value expressions in it, so strip those away and rebuild
12862 // the result. This is a really awful way of doing this, but the
12863 // better solution (rebuilding the semantic expressions and
12864 // rebinding OVEs as necessary) doesn't work; we'd need
12865 // TreeTransform to not strip away implicit conversions.
12866 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
12867 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
12868 if (result.isInvalid()) return ExprError();
12869
12870 // If that gives us a pseudo-object result back, the pseudo-object
12871 // expression must have been an lvalue-to-rvalue conversion which we
12872 // should reapply.
12873 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
12874 result = SemaRef.PseudoObject().checkRValue(result.get());
12875
12876 return result;
12877}
12878
12879template<typename Derived>
12881TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
12882 UnaryExprOrTypeTraitExpr *E) {
12883 if (E->isArgumentType()) {
12884 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
12885
12886 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
12887 if (!NewT)
12888 return ExprError();
12889
12890 if (!getDerived().AlwaysRebuild() && OldT == NewT)
12891 return E;
12892
12893 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
12894 E->getKind(),
12895 E->getSourceRange());
12896 }
12897
12898 // C++0x [expr.sizeof]p1:
12899 // The operand is either an expression, which is an unevaluated operand
12900 // [...]
12901 EnterExpressionEvaluationContext Unevaluated(
12904
12905 // Try to recover if we have something like sizeof(T::X) where X is a type.
12906 // Notably, there must be *exactly* one set of parens if X is a type.
12907 TypeSourceInfo *RecoveryTSI = nullptr;
12908 ExprResult SubExpr;
12909 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
12910 if (auto *DRE =
12911 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
12912 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
12913 PE, DRE, false, &RecoveryTSI);
12914 else
12915 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
12916
12917 if (RecoveryTSI) {
12918 return getDerived().RebuildUnaryExprOrTypeTrait(
12919 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
12920 } else if (SubExpr.isInvalid())
12921 return ExprError();
12922
12923 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
12924 return E;
12925
12926 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
12927 E->getOperatorLoc(),
12928 E->getKind(),
12929 E->getSourceRange());
12930}
12931
12932template<typename Derived>
12934TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
12935 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
12936 if (LHS.isInvalid())
12937 return ExprError();
12938
12939 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
12940 if (RHS.isInvalid())
12941 return ExprError();
12942
12943
12944 if (!getDerived().AlwaysRebuild() &&
12945 LHS.get() == E->getLHS() &&
12946 RHS.get() == E->getRHS())
12947 return E;
12948
12949 return getDerived().RebuildArraySubscriptExpr(
12950 LHS.get(),
12951 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
12952}
12953
12954template <typename Derived>
12956TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) {
12957 ExprResult Base = getDerived().TransformExpr(E->getBase());
12958 if (Base.isInvalid())
12959 return ExprError();
12960
12961 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
12962 if (RowIdx.isInvalid())
12963 return ExprError();
12964
12965 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
12966 if (ColumnIdx.isInvalid())
12967 return ExprError();
12968
12969 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
12970 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
12971 return E;
12972
12973 return getDerived().RebuildMatrixSubscriptExpr(
12974 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
12975}
12976
12977template <typename Derived>
12979TreeTransform<Derived>::TransformArraySectionExpr(ArraySectionExpr *E) {
12980 ExprResult Base = getDerived().TransformExpr(E->getBase());
12981 if (Base.isInvalid())
12982 return ExprError();
12983
12984 ExprResult LowerBound;
12985 if (E->getLowerBound()) {
12986 LowerBound = getDerived().TransformExpr(E->getLowerBound());
12987 if (LowerBound.isInvalid())
12988 return ExprError();
12989 }
12990
12991 ExprResult Length;
12992 if (E->getLength()) {
12993 Length = getDerived().TransformExpr(E->getLength());
12994 if (Length.isInvalid())
12995 return ExprError();
12996 }
12997
12998 ExprResult Stride;
12999 if (E->isOMPArraySection()) {
13000 if (Expr *Str = E->getStride()) {
13001 Stride = getDerived().TransformExpr(Str);
13002 if (Stride.isInvalid())
13003 return ExprError();
13004 }
13005 }
13006
13007 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13008 LowerBound.get() == E->getLowerBound() &&
13009 Length.get() == E->getLength() &&
13010 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13011 return E;
13012
13013 return getDerived().RebuildArraySectionExpr(
13014 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13015 LowerBound.get(), E->getColonLocFirst(),
13016 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13017 Length.get(), Stride.get(), E->getRBracketLoc());
13018}
13019
13020template <typename Derived>
13022TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) {
13023 ExprResult Base = getDerived().TransformExpr(E->getBase());
13024 if (Base.isInvalid())
13025 return ExprError();
13026
13028 bool ErrorFound = false;
13029 for (Expr *Dim : E->getDimensions()) {
13030 ExprResult DimRes = getDerived().TransformExpr(Dim);
13031 if (DimRes.isInvalid()) {
13032 ErrorFound = true;
13033 continue;
13034 }
13035 Dims.push_back(DimRes.get());
13036 }
13037
13038 if (ErrorFound)
13039 return ExprError();
13040 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13041 E->getRParenLoc(), Dims,
13042 E->getBracketsRanges());
13043}
13044
13045template <typename Derived>
13047TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) {
13048 unsigned NumIterators = E->numOfIterators();
13050
13051 bool ErrorFound = false;
13052 bool NeedToRebuild = getDerived().AlwaysRebuild();
13053 for (unsigned I = 0; I < NumIterators; ++I) {
13054 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13055 Data[I].DeclIdent = D->getIdentifier();
13056 Data[I].DeclIdentLoc = D->getLocation();
13057 if (D->getLocation() == D->getBeginLoc()) {
13058 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13059 "Implicit type must be int.");
13060 } else {
13061 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13062 QualType DeclTy = getDerived().TransformType(D->getType());
13063 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13064 }
13065 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13066 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13067 ExprResult End = getDerived().TransformExpr(Range.End);
13068 ExprResult Step = getDerived().TransformExpr(Range.Step);
13069 ErrorFound = ErrorFound ||
13070 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13071 !Data[I].Type.get().isNull())) ||
13072 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13073 if (ErrorFound)
13074 continue;
13075 Data[I].Range.Begin = Begin.get();
13076 Data[I].Range.End = End.get();
13077 Data[I].Range.Step = Step.get();
13078 Data[I].AssignLoc = E->getAssignLoc(I);
13079 Data[I].ColonLoc = E->getColonLoc(I);
13080 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13081 NeedToRebuild =
13082 NeedToRebuild ||
13083 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13084 D->getType().getTypePtrOrNull()) ||
13085 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13086 Range.Step != Data[I].Range.Step;
13087 }
13088 if (ErrorFound)
13089 return ExprError();
13090 if (!NeedToRebuild)
13091 return E;
13092
13093 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13094 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13095 if (!Res.isUsable())
13096 return Res;
13097 auto *IE = cast<OMPIteratorExpr>(Res.get());
13098 for (unsigned I = 0; I < NumIterators; ++I)
13099 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13100 IE->getIteratorDecl(I));
13101 return Res;
13102}
13103
13104template<typename Derived>
13106TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
13107 // Transform the callee.
13108 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13109 if (Callee.isInvalid())
13110 return ExprError();
13111
13112 // Transform arguments.
13113 bool ArgChanged = false;
13115 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13116 &ArgChanged))
13117 return ExprError();
13118
13119 if (!getDerived().AlwaysRebuild() &&
13120 Callee.get() == E->getCallee() &&
13121 !ArgChanged)
13122 return SemaRef.MaybeBindToTemporary(E);
13123
13124 // FIXME: Wrong source location information for the '('.
13125 SourceLocation FakeLParenLoc
13126 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13127
13128 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13129 if (E->hasStoredFPFeatures()) {
13130 FPOptionsOverride NewOverrides = E->getFPFeatures();
13131 getSema().CurFPFeatures =
13132 NewOverrides.applyOverrides(getSema().getLangOpts());
13133 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13134 }
13135
13136 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13137 Args,
13138 E->getRParenLoc());
13139}
13140
13141template<typename Derived>
13143TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
13144 ExprResult Base = getDerived().TransformExpr(E->getBase());
13145 if (Base.isInvalid())
13146 return ExprError();
13147
13148 NestedNameSpecifierLoc QualifierLoc;
13149 if (E->hasQualifier()) {
13150 QualifierLoc
13151 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13152
13153 if (!QualifierLoc)
13154 return ExprError();
13155 }
13156 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
13157
13158 ValueDecl *Member
13159 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
13160 E->getMemberDecl()));
13161 if (!Member)
13162 return ExprError();
13163
13164 NamedDecl *FoundDecl = E->getFoundDecl();
13165 if (FoundDecl == E->getMemberDecl()) {
13166 FoundDecl = Member;
13167 } else {
13168 FoundDecl = cast_or_null<NamedDecl>(
13169 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
13170 if (!FoundDecl)
13171 return ExprError();
13172 }
13173
13174 if (!getDerived().AlwaysRebuild() &&
13175 Base.get() == E->getBase() &&
13176 QualifierLoc == E->getQualifierLoc() &&
13177 Member == E->getMemberDecl() &&
13178 FoundDecl == E->getFoundDecl() &&
13179 !E->hasExplicitTemplateArgs()) {
13180
13181 // Skip for member expression of (this->f), rebuilt thisi->f is needed
13182 // for Openmp where the field need to be privatizized in the case.
13183 if (!(isa<CXXThisExpr>(E->getBase()) &&
13184 getSema().OpenMP().isOpenMPRebuildMemberExpr(
13185 cast<ValueDecl>(Member)))) {
13186 // Mark it referenced in the new context regardless.
13187 // FIXME: this is a bit instantiation-specific.
13188 SemaRef.MarkMemberReferenced(E);
13189 return E;
13190 }
13191 }
13192
13193 TemplateArgumentListInfo TransArgs;
13194 if (E->hasExplicitTemplateArgs()) {
13195 TransArgs.setLAngleLoc(E->getLAngleLoc());
13196 TransArgs.setRAngleLoc(E->getRAngleLoc());
13197 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13198 E->getNumTemplateArgs(),
13199 TransArgs))
13200 return ExprError();
13201 }
13202
13203 // FIXME: Bogus source location for the operator
13204 SourceLocation FakeOperatorLoc =
13205 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
13206
13207 // FIXME: to do this check properly, we will need to preserve the
13208 // first-qualifier-in-scope here, just in case we had a dependent
13209 // base (and therefore couldn't do the check) and a
13210 // nested-name-qualifier (and therefore could do the lookup).
13211 NamedDecl *FirstQualifierInScope = nullptr;
13212 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
13213 if (MemberNameInfo.getName()) {
13214 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
13215 if (!MemberNameInfo.getName())
13216 return ExprError();
13217 }
13218
13219 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
13220 E->isArrow(),
13221 QualifierLoc,
13222 TemplateKWLoc,
13223 MemberNameInfo,
13224 Member,
13225 FoundDecl,
13226 (E->hasExplicitTemplateArgs()
13227 ? &TransArgs : nullptr),
13228 FirstQualifierInScope);
13229}
13230
13231template<typename Derived>
13233TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
13234 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13235 if (LHS.isInvalid())
13236 return ExprError();
13237
13238 ExprResult RHS =
13239 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
13240 if (RHS.isInvalid())
13241 return ExprError();
13242
13243 if (!getDerived().AlwaysRebuild() &&
13244 LHS.get() == E->getLHS() &&
13245 RHS.get() == E->getRHS())
13246 return E;
13247
13248 if (E->isCompoundAssignmentOp())
13249 // FPFeatures has already been established from trailing storage
13250 return getDerived().RebuildBinaryOperator(
13251 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
13252 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13253 FPOptionsOverride NewOverrides(E->getFPFeatures());
13254 getSema().CurFPFeatures =
13255 NewOverrides.applyOverrides(getSema().getLangOpts());
13256 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13257 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
13258 LHS.get(), RHS.get());
13259}
13260
13261template <typename Derived>
13262ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator(
13263 CXXRewrittenBinaryOperator *E) {
13264 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
13265
13266 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
13267 if (LHS.isInvalid())
13268 return ExprError();
13269
13270 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
13271 if (RHS.isInvalid())
13272 return ExprError();
13273
13274 // Extract the already-resolved callee declarations so that we can restrict
13275 // ourselves to using them as the unqualified lookup results when rebuilding.
13276 UnresolvedSet<2> UnqualLookups;
13277 bool ChangedAnyLookups = false;
13278 Expr *PossibleBinOps[] = {E->getSemanticForm(),
13279 const_cast<Expr *>(Decomp.InnerBinOp)};
13280 for (Expr *PossibleBinOp : PossibleBinOps) {
13281 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
13282 if (!Op)
13283 continue;
13284 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
13285 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
13286 continue;
13287
13288 // Transform the callee in case we built a call to a local extern
13289 // declaration.
13290 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
13291 E->getOperatorLoc(), Callee->getFoundDecl()));
13292 if (!Found)
13293 return ExprError();
13294 if (Found != Callee->getFoundDecl())
13295 ChangedAnyLookups = true;
13296 UnqualLookups.addDecl(Found);
13297 }
13298
13299 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
13300 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
13301 // Mark all functions used in the rewrite as referenced. Note that when
13302 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
13303 // function calls, and/or there might be a user-defined conversion sequence
13304 // applied to the operands of the <.
13305 // FIXME: this is a bit instantiation-specific.
13306 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
13307 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
13308 return E;
13309 }
13310
13311 return getDerived().RebuildCXXRewrittenBinaryOperator(
13312 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
13313}
13314
13315template<typename Derived>
13317TreeTransform<Derived>::TransformCompoundAssignOperator(
13318 CompoundAssignOperator *E) {
13319 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13320 FPOptionsOverride NewOverrides(E->getFPFeatures());
13321 getSema().CurFPFeatures =
13322 NewOverrides.applyOverrides(getSema().getLangOpts());
13323 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13324 return getDerived().TransformBinaryOperator(E);
13325}
13326
13327template<typename Derived>
13328ExprResult TreeTransform<Derived>::
13329TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
13330 // Just rebuild the common and RHS expressions and see whether we
13331 // get any changes.
13332
13333 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
13334 if (commonExpr.isInvalid())
13335 return ExprError();
13336
13337 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
13338 if (rhs.isInvalid())
13339 return ExprError();
13340
13341 if (!getDerived().AlwaysRebuild() &&
13342 commonExpr.get() == e->getCommon() &&
13343 rhs.get() == e->getFalseExpr())
13344 return e;
13345
13346 return getDerived().RebuildConditionalOperator(commonExpr.get(),
13347 e->getQuestionLoc(),
13348 nullptr,
13349 e->getColonLoc(),
13350 rhs.get());
13351}
13352
13353template<typename Derived>
13355TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
13356 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13357 if (Cond.isInvalid())
13358 return ExprError();
13359
13360 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13361 if (LHS.isInvalid())
13362 return ExprError();
13363
13364 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13365 if (RHS.isInvalid())
13366 return ExprError();
13367
13368 if (!getDerived().AlwaysRebuild() &&
13369 Cond.get() == E->getCond() &&
13370 LHS.get() == E->getLHS() &&
13371 RHS.get() == E->getRHS())
13372 return E;
13373
13374 return getDerived().RebuildConditionalOperator(Cond.get(),
13375 E->getQuestionLoc(),
13376 LHS.get(),
13377 E->getColonLoc(),
13378 RHS.get());
13379}
13380
13381template<typename Derived>
13383TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
13384 // Implicit casts are eliminated during transformation, since they
13385 // will be recomputed by semantic analysis after transformation.
13386 return getDerived().TransformExpr(E->getSubExprAsWritten());
13387}
13388
13389template<typename Derived>
13391TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
13392 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13393 if (!Type)
13394 return ExprError();
13395
13396 ExprResult SubExpr
13397 = getDerived().TransformExpr(E->getSubExprAsWritten());
13398 if (SubExpr.isInvalid())
13399 return ExprError();
13400
13401 if (!getDerived().AlwaysRebuild() &&
13402 Type == E->getTypeInfoAsWritten() &&
13403 SubExpr.get() == E->getSubExpr())
13404 return E;
13405
13406 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
13407 Type,
13408 E->getRParenLoc(),
13409 SubExpr.get());
13410}
13411
13412template<typename Derived>
13414TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
13415 TypeSourceInfo *OldT = E->getTypeSourceInfo();
13416 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13417 if (!NewT)
13418 return ExprError();
13419
13420 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
13421 if (Init.isInvalid())
13422 return ExprError();
13423
13424 if (!getDerived().AlwaysRebuild() &&
13425 OldT == NewT &&
13426 Init.get() == E->getInitializer())
13427 return SemaRef.MaybeBindToTemporary(E);
13428
13429 // Note: the expression type doesn't necessarily match the
13430 // type-as-written, but that's okay, because it should always be
13431 // derivable from the initializer.
13432
13433 return getDerived().RebuildCompoundLiteralExpr(
13434 E->getLParenLoc(), NewT,
13435 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
13436}
13437
13438template<typename Derived>
13440TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
13441 ExprResult Base = getDerived().TransformExpr(E->getBase());
13442 if (Base.isInvalid())
13443 return ExprError();
13444
13445 if (!getDerived().AlwaysRebuild() &&
13446 Base.get() == E->getBase())
13447 return E;
13448
13449 // FIXME: Bad source location
13450 SourceLocation FakeOperatorLoc =
13451 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
13452 return getDerived().RebuildExtVectorElementExpr(
13453 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
13454 E->getAccessor());
13455}
13456
13457template<typename Derived>
13459TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
13460 if (InitListExpr *Syntactic = E->getSyntacticForm())
13461 E = Syntactic;
13462
13463 bool InitChanged = false;
13464
13465 EnterExpressionEvaluationContext Context(
13467
13469 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
13470 Inits, &InitChanged))
13471 return ExprError();
13472
13473 if (!getDerived().AlwaysRebuild() && !InitChanged) {
13474 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
13475 // in some cases. We can't reuse it in general, because the syntactic and
13476 // semantic forms are linked, and we can't know that semantic form will
13477 // match even if the syntactic form does.
13478 }
13479
13480 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
13481 E->getRBraceLoc());
13482}
13483
13484template<typename Derived>
13486TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
13487 Designation Desig;
13488
13489 // transform the initializer value
13490 ExprResult Init = getDerived().TransformExpr(E->getInit());
13491 if (Init.isInvalid())
13492 return ExprError();
13493
13494 // transform the designators.
13495 SmallVector<Expr*, 4> ArrayExprs;
13496 bool ExprChanged = false;
13497 for (const DesignatedInitExpr::Designator &D : E->designators()) {
13498 if (D.isFieldDesignator()) {
13499 if (D.getFieldDecl()) {
13500 FieldDecl *Field = cast_or_null<FieldDecl>(
13501 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
13502 if (Field != D.getFieldDecl())
13503 // Rebuild the expression when the transformed FieldDecl is
13504 // different to the already assigned FieldDecl.
13505 ExprChanged = true;
13506 if (Field->isAnonymousStructOrUnion())
13507 continue;
13508 } else {
13509 // Ensure that the designator expression is rebuilt when there isn't
13510 // a resolved FieldDecl in the designator as we don't want to assign
13511 // a FieldDecl to a pattern designator that will be instantiated again.
13512 ExprChanged = true;
13513 }
13514 Desig.AddDesignator(Designator::CreateFieldDesignator(
13515 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
13516 continue;
13517 }
13518
13519 if (D.isArrayDesignator()) {
13520 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
13521 if (Index.isInvalid())
13522 return ExprError();
13523
13524 Desig.AddDesignator(
13525 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
13526
13527 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D);
13528 ArrayExprs.push_back(Index.get());
13529 continue;
13530 }
13531
13532 assert(D.isArrayRangeDesignator() && "New kind of designator?");
13533 ExprResult Start
13534 = getDerived().TransformExpr(E->getArrayRangeStart(D));
13535 if (Start.isInvalid())
13536 return ExprError();
13537
13538 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
13539 if (End.isInvalid())
13540 return ExprError();
13541
13542 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
13543 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
13544
13545 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
13546 End.get() != E->getArrayRangeEnd(D);
13547
13548 ArrayExprs.push_back(Start.get());
13549 ArrayExprs.push_back(End.get());
13550 }
13551
13552 if (!getDerived().AlwaysRebuild() &&
13553 Init.get() == E->getInit() &&
13554 !ExprChanged)
13555 return E;
13556
13557 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
13558 E->getEqualOrColonLoc(),
13559 E->usesGNUSyntax(), Init.get());
13560}
13561
13562// Seems that if TransformInitListExpr() only works on the syntactic form of an
13563// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
13564template<typename Derived>
13566TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
13567 DesignatedInitUpdateExpr *E) {
13568 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
13569 "initializer");
13570 return ExprError();
13571}
13572
13573template<typename Derived>
13575TreeTransform<Derived>::TransformNoInitExpr(
13576 NoInitExpr *E) {
13577 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
13578 return ExprError();
13579}
13580
13581template<typename Derived>
13583TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) {
13584 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
13585 return ExprError();
13586}
13587
13588template<typename Derived>
13590TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) {
13591 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
13592 return ExprError();
13593}
13594
13595template<typename Derived>
13597TreeTransform<Derived>::TransformImplicitValueInitExpr(
13598 ImplicitValueInitExpr *E) {
13599 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
13600
13601 // FIXME: Will we ever have proper type location here? Will we actually
13602 // need to transform the type?
13603 QualType T = getDerived().TransformType(E->getType());
13604 if (T.isNull())
13605 return ExprError();
13606
13607 if (!getDerived().AlwaysRebuild() &&
13608 T == E->getType())
13609 return E;
13610
13611 return getDerived().RebuildImplicitValueInitExpr(T);
13612}
13613
13614template<typename Derived>
13616TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
13617 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
13618 if (!TInfo)
13619 return ExprError();
13620
13621 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13622 if (SubExpr.isInvalid())
13623 return ExprError();
13624
13625 if (!getDerived().AlwaysRebuild() &&
13626 TInfo == E->getWrittenTypeInfo() &&
13627 SubExpr.get() == E->getSubExpr())
13628 return E;
13629
13630 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
13631 TInfo, E->getRParenLoc());
13632}
13633
13634template<typename Derived>
13636TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
13637 bool ArgumentChanged = false;
13639 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
13640 &ArgumentChanged))
13641 return ExprError();
13642
13643 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
13644 Inits,
13645 E->getRParenLoc());
13646}
13647
13648/// Transform an address-of-label expression.
13649///
13650/// By default, the transformation of an address-of-label expression always
13651/// rebuilds the expression, so that the label identifier can be resolved to
13652/// the corresponding label statement by semantic analysis.
13653template<typename Derived>
13655TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
13656 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
13657 E->getLabel());
13658 if (!LD)
13659 return ExprError();
13660
13661 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
13662 cast<LabelDecl>(LD));
13663}
13664
13665template<typename Derived>
13667TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
13668 SemaRef.ActOnStartStmtExpr();
13669 StmtResult SubStmt
13670 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
13671 if (SubStmt.isInvalid()) {
13672 SemaRef.ActOnStmtExprError();
13673 return ExprError();
13674 }
13675
13676 unsigned OldDepth = E->getTemplateDepth();
13677 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
13678
13679 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
13680 SubStmt.get() == E->getSubStmt()) {
13681 // Calling this an 'error' is unintuitive, but it does the right thing.
13682 SemaRef.ActOnStmtExprError();
13683 return SemaRef.MaybeBindToTemporary(E);
13684 }
13685
13686 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
13687 E->getRParenLoc(), NewDepth);
13688}
13689
13690template<typename Derived>
13692TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
13693 ExprResult Cond = getDerived().TransformExpr(E->getCond());
13694 if (Cond.isInvalid())
13695 return ExprError();
13696
13697 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13698 if (LHS.isInvalid())
13699 return ExprError();
13700
13701 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13702 if (RHS.isInvalid())
13703 return ExprError();
13704
13705 if (!getDerived().AlwaysRebuild() &&
13706 Cond.get() == E->getCond() &&
13707 LHS.get() == E->getLHS() &&
13708 RHS.get() == E->getRHS())
13709 return E;
13710
13711 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
13712 Cond.get(), LHS.get(), RHS.get(),
13713 E->getRParenLoc());
13714}
13715
13716template<typename Derived>
13718TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
13719 return E;
13720}
13721
13722template<typename Derived>
13724TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
13725 switch (E->getOperator()) {
13726 case OO_New:
13727 case OO_Delete:
13728 case OO_Array_New:
13729 case OO_Array_Delete:
13730 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
13731
13732 case OO_Subscript:
13733 case OO_Call: {
13734 // This is a call to an object's operator().
13735 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
13736
13737 // Transform the object itself.
13738 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
13739 if (Object.isInvalid())
13740 return ExprError();
13741
13742 // FIXME: Poor location information
13743 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
13744 static_cast<Expr *>(Object.get())->getEndLoc());
13745
13746 // Transform the call arguments.
13748 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
13749 Args))
13750 return ExprError();
13751
13752 if (E->getOperator() == OO_Subscript)
13753 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
13754 Args, E->getEndLoc());
13755
13756 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
13757 E->getEndLoc());
13758 }
13759
13760#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
13761 case OO_##Name: \
13762 break;
13763
13764#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
13765#include "clang/Basic/OperatorKinds.def"
13766
13767 case OO_Conditional:
13768 llvm_unreachable("conditional operator is not actually overloadable");
13769
13770 case OO_None:
13772 llvm_unreachable("not an overloaded operator?");
13773 }
13774
13776 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
13777 First = getDerived().TransformAddressOfOperand(E->getArg(0));
13778 else
13779 First = getDerived().TransformExpr(E->getArg(0));
13780 if (First.isInvalid())
13781 return ExprError();
13782
13783 ExprResult Second;
13784 if (E->getNumArgs() == 2) {
13785 Second =
13786 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
13787 if (Second.isInvalid())
13788 return ExprError();
13789 }
13790
13791 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13792 FPOptionsOverride NewOverrides(E->getFPFeatures());
13793 getSema().CurFPFeatures =
13794 NewOverrides.applyOverrides(getSema().getLangOpts());
13795 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13796
13797 Expr *Callee = E->getCallee();
13798 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
13799 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
13801 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
13802 return ExprError();
13803
13804 return getDerived().RebuildCXXOperatorCallExpr(
13805 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
13806 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
13807 }
13808
13809 UnresolvedSet<1> Functions;
13810 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
13811 Callee = ICE->getSubExprAsWritten();
13812 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
13813 ValueDecl *VD = cast_or_null<ValueDecl>(
13814 getDerived().TransformDecl(DR->getLocation(), DR));
13815 if (!VD)
13816 return ExprError();
13817
13818 if (!isa<CXXMethodDecl>(VD))
13819 Functions.addDecl(VD);
13820
13821 return getDerived().RebuildCXXOperatorCallExpr(
13822 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
13823 /*RequiresADL=*/false, Functions, First.get(), Second.get());
13824}
13825
13826template<typename Derived>
13828TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
13829 return getDerived().TransformCallExpr(E);
13830}
13831
13832template <typename Derived>
13833ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) {
13834 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
13835 getSema().CurContext != E->getParentContext();
13836
13837 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
13838 return E;
13839
13840 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
13841 E->getBeginLoc(), E->getEndLoc(),
13842 getSema().CurContext);
13843}
13844
13845template <typename Derived>
13846ExprResult TreeTransform<Derived>::TransformEmbedExpr(EmbedExpr *E) {
13847 return E;
13848}
13849
13850template<typename Derived>
13852TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
13853 // Transform the callee.
13854 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13855 if (Callee.isInvalid())
13856 return ExprError();
13857
13858 // Transform exec config.
13859 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
13860 if (EC.isInvalid())
13861 return ExprError();
13862
13863 // Transform arguments.
13864 bool ArgChanged = false;
13866 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13867 &ArgChanged))
13868 return ExprError();
13869
13870 if (!getDerived().AlwaysRebuild() &&
13871 Callee.get() == E->getCallee() &&
13872 !ArgChanged)
13873 return SemaRef.MaybeBindToTemporary(E);
13874
13875 // FIXME: Wrong source location information for the '('.
13876 SourceLocation FakeLParenLoc
13877 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13878 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13879 Args,
13880 E->getRParenLoc(), EC.get());
13881}
13882
13883template<typename Derived>
13886 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
13887 if (!Type)
13888 return ExprError();
13889
13890 ExprResult SubExpr
13891 = getDerived().TransformExpr(E->getSubExprAsWritten());
13892 if (SubExpr.isInvalid())
13893 return ExprError();
13894
13895 if (!getDerived().AlwaysRebuild() &&
13896 Type == E->getTypeInfoAsWritten() &&
13897 SubExpr.get() == E->getSubExpr())
13898 return E;
13899 return getDerived().RebuildCXXNamedCastExpr(
13900 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
13901 Type, E->getAngleBrackets().getEnd(),
13902 // FIXME. this should be '(' location
13903 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
13904}
13905
13906template<typename Derived>
13909 TypeSourceInfo *TSI =
13910 getDerived().TransformType(BCE->getTypeInfoAsWritten());
13911 if (!TSI)
13912 return ExprError();
13913
13914 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
13915 if (Sub.isInvalid())
13916 return ExprError();
13917
13918 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
13919 Sub.get(), BCE->getEndLoc());
13920}
13921
13922template<typename Derived>
13924TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
13925 return getDerived().TransformCXXNamedCastExpr(E);
13926}
13927
13928template<typename Derived>
13930TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
13931 return getDerived().TransformCXXNamedCastExpr(E);
13932}
13933
13934template<typename Derived>
13936TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
13937 CXXReinterpretCastExpr *E) {
13938 return getDerived().TransformCXXNamedCastExpr(E);
13939}
13940
13941template<typename Derived>
13943TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
13944 return getDerived().TransformCXXNamedCastExpr(E);
13945}
13946
13947template<typename Derived>
13949TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) {
13950 return getDerived().TransformCXXNamedCastExpr(E);
13951}
13952
13953template<typename Derived>
13955TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
13956 CXXFunctionalCastExpr *E) {
13957 TypeSourceInfo *Type =
13958 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
13959 if (!Type)
13960 return ExprError();
13961
13962 ExprResult SubExpr
13963 = getDerived().TransformExpr(E->getSubExprAsWritten());
13964 if (SubExpr.isInvalid())
13965 return ExprError();
13966
13967 if (!getDerived().AlwaysRebuild() &&
13968 Type == E->getTypeInfoAsWritten() &&
13969 SubExpr.get() == E->getSubExpr())
13970 return E;
13971
13972 return getDerived().RebuildCXXFunctionalCastExpr(Type,
13973 E->getLParenLoc(),
13974 SubExpr.get(),
13975 E->getRParenLoc(),
13976 E->isListInitialization());
13977}
13978
13979template<typename Derived>
13981TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
13982 if (E->isTypeOperand()) {
13983 TypeSourceInfo *TInfo
13984 = getDerived().TransformType(E->getTypeOperandSourceInfo());
13985 if (!TInfo)
13986 return ExprError();
13987
13988 if (!getDerived().AlwaysRebuild() &&
13989 TInfo == E->getTypeOperandSourceInfo())
13990 return E;
13991
13992 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
13993 TInfo, E->getEndLoc());
13994 }
13995
13996 // Typeid's operand is an unevaluated context, unless it's a polymorphic
13997 // type. We must not unilaterally enter unevaluated context here, as then
13998 // semantic processing can re-transform an already transformed operand.
13999 Expr *Op = E->getExprOperand();
14001 if (E->isGLValue())
14002 if (auto *RecordT = Op->getType()->getAs<RecordType>())
14003 if (cast<CXXRecordDecl>(RecordT->getDecl())->isPolymorphic())
14004 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14005
14006 EnterExpressionEvaluationContext Unevaluated(SemaRef, EvalCtx,
14008
14009 ExprResult SubExpr = getDerived().TransformExpr(Op);
14010 if (SubExpr.isInvalid())
14011 return ExprError();
14012
14013 if (!getDerived().AlwaysRebuild() &&
14014 SubExpr.get() == E->getExprOperand())
14015 return E;
14016
14017 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14018 SubExpr.get(), E->getEndLoc());
14019}
14020
14021template<typename Derived>
14023TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
14024 if (E->isTypeOperand()) {
14025 TypeSourceInfo *TInfo
14026 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14027 if (!TInfo)
14028 return ExprError();
14029
14030 if (!getDerived().AlwaysRebuild() &&
14031 TInfo == E->getTypeOperandSourceInfo())
14032 return E;
14033
14034 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14035 TInfo, E->getEndLoc());
14036 }
14037
14038 EnterExpressionEvaluationContext Unevaluated(
14040
14041 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14042 if (SubExpr.isInvalid())
14043 return ExprError();
14044
14045 if (!getDerived().AlwaysRebuild() &&
14046 SubExpr.get() == E->getExprOperand())
14047 return E;
14048
14049 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14050 SubExpr.get(), E->getEndLoc());
14051}
14052
14053template<typename Derived>
14055TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
14056 return E;
14057}
14058
14059template<typename Derived>
14061TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
14062 CXXNullPtrLiteralExpr *E) {
14063 return E;
14064}
14065
14066template<typename Derived>
14068TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
14069
14070 // In lambdas, the qualifiers of the type depends of where in
14071 // the call operator `this` appear, and we do not have a good way to
14072 // rebuild this information, so we transform the type.
14073 //
14074 // In other contexts, the type of `this` may be overrided
14075 // for type deduction, so we need to recompute it.
14076 //
14077 // Always recompute the type if we're in the body of a lambda, and
14078 // 'this' is dependent on a lambda's explicit object parameter.
14079 QualType T = [&]() {
14080 auto &S = getSema();
14081 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14082 return S.getCurrentThisType();
14083 if (S.getCurLambda())
14084 return getDerived().TransformType(E->getType());
14085 return S.getCurrentThisType();
14086 }();
14087
14088 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
14089 // Mark it referenced in the new context regardless.
14090 // FIXME: this is a bit instantiation-specific.
14091 getSema().MarkThisReferenced(E);
14092 return E;
14093 }
14094
14095 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14096}
14097
14098template<typename Derived>
14100TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
14101 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14102 if (SubExpr.isInvalid())
14103 return ExprError();
14104
14105 if (!getDerived().AlwaysRebuild() &&
14106 SubExpr.get() == E->getSubExpr())
14107 return E;
14108
14109 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
14110 E->isThrownVariableInScope());
14111}
14112
14113template<typename Derived>
14115TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
14116 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
14117 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
14118 if (!Param)
14119 return ExprError();
14120
14121 ExprResult InitRes;
14122 if (E->hasRewrittenInit()) {
14123 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
14124 if (InitRes.isInvalid())
14125 return ExprError();
14126 }
14127
14128 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
14129 E->getUsedContext() == SemaRef.CurContext &&
14130 InitRes.get() == E->getRewrittenExpr())
14131 return E;
14132
14133 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
14134 InitRes.get());
14135}
14136
14137template<typename Derived>
14139TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
14140 FieldDecl *Field = cast_or_null<FieldDecl>(
14141 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
14142 if (!Field)
14143 return ExprError();
14144
14145 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
14146 E->getUsedContext() == SemaRef.CurContext)
14147 return E;
14148
14149 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
14150}
14151
14152template<typename Derived>
14154TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
14155 CXXScalarValueInitExpr *E) {
14156 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
14157 if (!T)
14158 return ExprError();
14159
14160 if (!getDerived().AlwaysRebuild() &&
14161 T == E->getTypeSourceInfo())
14162 return E;
14163
14164 return getDerived().RebuildCXXScalarValueInitExpr(T,
14165 /*FIXME:*/T->getTypeLoc().getEndLoc(),
14166 E->getRParenLoc());
14167}
14168
14169template<typename Derived>
14171TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
14172 // Transform the type that we're allocating
14173 TypeSourceInfo *AllocTypeInfo =
14174 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
14175 if (!AllocTypeInfo)
14176 return ExprError();
14177
14178 // Transform the size of the array we're allocating (if any).
14179 std::optional<Expr *> ArraySize;
14180 if (E->isArray()) {
14181 ExprResult NewArraySize;
14182 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
14183 NewArraySize = getDerived().TransformExpr(*OldArraySize);
14184 if (NewArraySize.isInvalid())
14185 return ExprError();
14186 }
14187 ArraySize = NewArraySize.get();
14188 }
14189
14190 // Transform the placement arguments (if any).
14191 bool ArgumentChanged = false;
14192 SmallVector<Expr*, 8> PlacementArgs;
14193 if (getDerived().TransformExprs(E->getPlacementArgs(),
14194 E->getNumPlacementArgs(), true,
14195 PlacementArgs, &ArgumentChanged))
14196 return ExprError();
14197
14198 // Transform the initializer (if any).
14199 Expr *OldInit = E->getInitializer();
14200 ExprResult NewInit;
14201 if (OldInit)
14202 NewInit = getDerived().TransformInitializer(OldInit, true);
14203 if (NewInit.isInvalid())
14204 return ExprError();
14205
14206 // Transform new operator and delete operator.
14207 FunctionDecl *OperatorNew = nullptr;
14208 if (E->getOperatorNew()) {
14209 OperatorNew = cast_or_null<FunctionDecl>(
14210 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
14211 if (!OperatorNew)
14212 return ExprError();
14213 }
14214
14215 FunctionDecl *OperatorDelete = nullptr;
14216 if (E->getOperatorDelete()) {
14217 OperatorDelete = cast_or_null<FunctionDecl>(
14218 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14219 if (!OperatorDelete)
14220 return ExprError();
14221 }
14222
14223 if (!getDerived().AlwaysRebuild() &&
14224 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
14225 ArraySize == E->getArraySize() &&
14226 NewInit.get() == OldInit &&
14227 OperatorNew == E->getOperatorNew() &&
14228 OperatorDelete == E->getOperatorDelete() &&
14229 !ArgumentChanged) {
14230 // Mark any declarations we need as referenced.
14231 // FIXME: instantiation-specific.
14232 if (OperatorNew)
14233 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
14234 if (OperatorDelete)
14235 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14236
14237 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
14238 QualType ElementType
14239 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
14240 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
14241 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
14242 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
14244 }
14245 }
14246 }
14247
14248 return E;
14249 }
14250
14251 QualType AllocType = AllocTypeInfo->getType();
14252 if (!ArraySize) {
14253 // If no array size was specified, but the new expression was
14254 // instantiated with an array type (e.g., "new T" where T is
14255 // instantiated with "int[4]"), extract the outer bound from the
14256 // array type as our array size. We do this with constant and
14257 // dependently-sized array types.
14258 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
14259 if (!ArrayT) {
14260 // Do nothing
14261 } else if (const ConstantArrayType *ConsArrayT
14262 = dyn_cast<ConstantArrayType>(ArrayT)) {
14263 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
14264 SemaRef.Context.getSizeType(),
14265 /*FIXME:*/ E->getBeginLoc());
14266 AllocType = ConsArrayT->getElementType();
14267 } else if (const DependentSizedArrayType *DepArrayT
14268 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
14269 if (DepArrayT->getSizeExpr()) {
14270 ArraySize = DepArrayT->getSizeExpr();
14271 AllocType = DepArrayT->getElementType();
14272 }
14273 }
14274 }
14275
14276 return getDerived().RebuildCXXNewExpr(
14277 E->getBeginLoc(), E->isGlobalNew(),
14278 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
14279 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
14280 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
14281}
14282
14283template<typename Derived>
14285TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
14286 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
14287 if (Operand.isInvalid())
14288 return ExprError();
14289
14290 // Transform the delete operator, if known.
14291 FunctionDecl *OperatorDelete = nullptr;
14292 if (E->getOperatorDelete()) {
14293 OperatorDelete = cast_or_null<FunctionDecl>(
14294 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
14295 if (!OperatorDelete)
14296 return ExprError();
14297 }
14298
14299 if (!getDerived().AlwaysRebuild() &&
14300 Operand.get() == E->getArgument() &&
14301 OperatorDelete == E->getOperatorDelete()) {
14302 // Mark any declarations we need as referenced.
14303 // FIXME: instantiation-specific.
14304 if (OperatorDelete)
14305 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
14306
14307 if (!E->getArgument()->isTypeDependent()) {
14308 QualType Destroyed = SemaRef.Context.getBaseElementType(
14309 E->getDestroyedType());
14310 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
14311 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
14313 SemaRef.LookupDestructor(Record));
14314 }
14315 }
14316
14317 return E;
14318 }
14319
14320 return getDerived().RebuildCXXDeleteExpr(
14321 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
14322}
14323
14324template<typename Derived>
14326TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
14327 CXXPseudoDestructorExpr *E) {
14328 ExprResult Base = getDerived().TransformExpr(E->getBase());
14329 if (Base.isInvalid())
14330 return ExprError();
14331
14332 ParsedType ObjectTypePtr;
14333 bool MayBePseudoDestructor = false;
14334 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
14335 E->getOperatorLoc(),
14336 E->isArrow()? tok::arrow : tok::period,
14337 ObjectTypePtr,
14338 MayBePseudoDestructor);
14339 if (Base.isInvalid())
14340 return ExprError();
14341
14342 QualType ObjectType = ObjectTypePtr.get();
14343 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
14344 if (QualifierLoc) {
14345 QualifierLoc
14346 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
14347 if (!QualifierLoc)
14348 return ExprError();
14349 }
14350 CXXScopeSpec SS;
14351 SS.Adopt(QualifierLoc);
14352
14353 PseudoDestructorTypeStorage Destroyed;
14354 if (E->getDestroyedTypeInfo()) {
14355 TypeSourceInfo *DestroyedTypeInfo
14356 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
14357 ObjectType, nullptr, SS);
14358 if (!DestroyedTypeInfo)
14359 return ExprError();
14360 Destroyed = DestroyedTypeInfo;
14361 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
14362 // We aren't likely to be able to resolve the identifier down to a type
14363 // now anyway, so just retain the identifier.
14364 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
14365 E->getDestroyedTypeLoc());
14366 } else {
14367 // Look for a destructor known with the given name.
14368 ParsedType T = SemaRef.getDestructorName(
14369 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
14370 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
14371 if (!T)
14372 return ExprError();
14373
14374 Destroyed
14376 E->getDestroyedTypeLoc());
14377 }
14378
14379 TypeSourceInfo *ScopeTypeInfo = nullptr;
14380 if (E->getScopeTypeInfo()) {
14381 CXXScopeSpec EmptySS;
14382 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
14383 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
14384 if (!ScopeTypeInfo)
14385 return ExprError();
14386 }
14387
14388 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
14389 E->getOperatorLoc(),
14390 E->isArrow(),
14391 SS,
14392 ScopeTypeInfo,
14393 E->getColonColonLoc(),
14394 E->getTildeLoc(),
14395 Destroyed);
14396}
14397
14398template <typename Derived>
14400 bool RequiresADL,
14401 LookupResult &R) {
14402 // Transform all the decls.
14403 bool AllEmptyPacks = true;
14404 for (auto *OldD : Old->decls()) {
14405 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
14406 if (!InstD) {
14407 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
14408 // This can happen because of dependent hiding.
14409 if (isa<UsingShadowDecl>(OldD))
14410 continue;
14411 else {
14412 R.clear();
14413 return true;
14414 }
14415 }
14416
14417 // Expand using pack declarations.
14418 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
14419 ArrayRef<NamedDecl*> Decls = SingleDecl;
14420 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
14421 Decls = UPD->expansions();
14422
14423 // Expand using declarations.
14424 for (auto *D : Decls) {
14425 if (auto *UD = dyn_cast<UsingDecl>(D)) {
14426 for (auto *SD : UD->shadows())
14427 R.addDecl(SD);
14428 } else {
14429 R.addDecl(D);
14430 }
14431 }
14432
14433 AllEmptyPacks &= Decls.empty();
14434 }
14435
14436 // C++ [temp.res]/8.4.2:
14437 // The program is ill-formed, no diagnostic required, if [...] lookup for
14438 // a name in the template definition found a using-declaration, but the
14439 // lookup in the corresponding scope in the instantiation odoes not find
14440 // any declarations because the using-declaration was a pack expansion and
14441 // the corresponding pack is empty
14442 if (AllEmptyPacks && !RequiresADL) {
14443 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
14444 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
14445 return true;
14446 }
14447
14448 // Resolve a kind, but don't do any further analysis. If it's
14449 // ambiguous, the callee needs to deal with it.
14450 R.resolveKind();
14451
14452 if (Old->hasTemplateKeyword() && !R.empty()) {
14454 getSema().FilterAcceptableTemplateNames(R,
14455 /*AllowFunctionTemplates=*/true,
14456 /*AllowDependent=*/true);
14457 if (R.empty()) {
14458 // If a 'template' keyword was used, a lookup that finds only non-template
14459 // names is an error.
14460 getSema().Diag(R.getNameLoc(),
14461 diag::err_template_kw_refers_to_non_template)
14463 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
14464 getSema().Diag(FoundDecl->getLocation(),
14465 diag::note_template_kw_refers_to_non_template)
14466 << R.getLookupName();
14467 return true;
14468 }
14469 }
14470
14471 return false;
14472}
14473
14474template <typename Derived>
14476 UnresolvedLookupExpr *Old) {
14477 return TransformUnresolvedLookupExpr(Old, /*IsAddressOfOperand=*/false);
14478}
14479
14480template <typename Derived>
14483 bool IsAddressOfOperand) {
14484 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
14486
14487 // Transform the declaration set.
14488 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
14489 return ExprError();
14490
14491 // Rebuild the nested-name qualifier, if present.
14492 CXXScopeSpec SS;
14493 if (Old->getQualifierLoc()) {
14494 NestedNameSpecifierLoc QualifierLoc
14495 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
14496 if (!QualifierLoc)
14497 return ExprError();
14498
14499 SS.Adopt(QualifierLoc);
14500 }
14501
14502 if (Old->getNamingClass()) {
14503 CXXRecordDecl *NamingClass
14504 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
14505 Old->getNameLoc(),
14506 Old->getNamingClass()));
14507 if (!NamingClass) {
14508 R.clear();
14509 return ExprError();
14510 }
14511
14512 R.setNamingClass(NamingClass);
14513 }
14514
14515 // Rebuild the template arguments, if any.
14516 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
14517 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
14518 if (Old->hasExplicitTemplateArgs() &&
14519 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14520 Old->getNumTemplateArgs(),
14521 TransArgs)) {
14522 R.clear();
14523 return ExprError();
14524 }
14525
14526 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
14527 // a non-static data member is named in an unevaluated operand, or when
14528 // a member is named in a dependent class scope function template explicit
14529 // specialization that is neither declared static nor with an explicit object
14530 // parameter.
14531 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
14532 return SemaRef.BuildPossibleImplicitMemberExpr(
14533 SS, TemplateKWLoc, R,
14534 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
14535 /*S=*/nullptr);
14536
14537 // If we have neither explicit template arguments, nor the template keyword,
14538 // it's a normal declaration name or member reference.
14539 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
14540 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
14541
14542 // If we have template arguments, then rebuild the template-id expression.
14543 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
14544 Old->requiresADL(), &TransArgs);
14545}
14546
14547template<typename Derived>
14549TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
14550 bool ArgChanged = false;
14552 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
14553 TypeSourceInfo *From = E->getArg(I);
14554 TypeLoc FromTL = From->getTypeLoc();
14555 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
14556 TypeLocBuilder TLB;
14557 TLB.reserve(FromTL.getFullDataSize());
14558 QualType To = getDerived().TransformType(TLB, FromTL);
14559 if (To.isNull())
14560 return ExprError();
14561
14562 if (To == From->getType())
14563 Args.push_back(From);
14564 else {
14565 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14566 ArgChanged = true;
14567 }
14568 continue;
14569 }
14570
14571 ArgChanged = true;
14572
14573 // We have a pack expansion. Instantiate it.
14574 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
14575 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
14577 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
14578
14579 // Determine whether the set of unexpanded parameter packs can and should
14580 // be expanded.
14581 bool Expand = true;
14582 bool RetainExpansion = false;
14583 std::optional<unsigned> OrigNumExpansions =
14584 ExpansionTL.getTypePtr()->getNumExpansions();
14585 std::optional<unsigned> NumExpansions = OrigNumExpansions;
14586 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
14587 PatternTL.getSourceRange(),
14588 Unexpanded,
14589 Expand, RetainExpansion,
14590 NumExpansions))
14591 return ExprError();
14592
14593 if (!Expand) {
14594 // The transform has determined that we should perform a simple
14595 // transformation on the pack expansion, producing another pack
14596 // expansion.
14597 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
14598
14599 TypeLocBuilder TLB;
14600 TLB.reserve(From->getTypeLoc().getFullDataSize());
14601
14602 QualType To = getDerived().TransformType(TLB, PatternTL);
14603 if (To.isNull())
14604 return ExprError();
14605
14606 To = getDerived().RebuildPackExpansionType(To,
14607 PatternTL.getSourceRange(),
14608 ExpansionTL.getEllipsisLoc(),
14609 NumExpansions);
14610 if (To.isNull())
14611 return ExprError();
14612
14613 PackExpansionTypeLoc ToExpansionTL
14614 = TLB.push<PackExpansionTypeLoc>(To);
14615 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14616 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14617 continue;
14618 }
14619
14620 // Expand the pack expansion by substituting for each argument in the
14621 // pack(s).
14622 for (unsigned I = 0; I != *NumExpansions; ++I) {
14623 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
14624 TypeLocBuilder TLB;
14625 TLB.reserve(PatternTL.getFullDataSize());
14626 QualType To = getDerived().TransformType(TLB, PatternTL);
14627 if (To.isNull())
14628 return ExprError();
14629
14630 if (To->containsUnexpandedParameterPack()) {
14631 To = getDerived().RebuildPackExpansionType(To,
14632 PatternTL.getSourceRange(),
14633 ExpansionTL.getEllipsisLoc(),
14634 NumExpansions);
14635 if (To.isNull())
14636 return ExprError();
14637
14638 PackExpansionTypeLoc ToExpansionTL
14639 = TLB.push<PackExpansionTypeLoc>(To);
14640 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14641 }
14642
14643 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14644 }
14645
14646 if (!RetainExpansion)
14647 continue;
14648
14649 // If we're supposed to retain a pack expansion, do so by temporarily
14650 // forgetting the partially-substituted parameter pack.
14651 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
14652
14653 TypeLocBuilder TLB;
14654 TLB.reserve(From->getTypeLoc().getFullDataSize());
14655
14656 QualType To = getDerived().TransformType(TLB, PatternTL);
14657 if (To.isNull())
14658 return ExprError();
14659
14660 To = getDerived().RebuildPackExpansionType(To,
14661 PatternTL.getSourceRange(),
14662 ExpansionTL.getEllipsisLoc(),
14663 NumExpansions);
14664 if (To.isNull())
14665 return ExprError();
14666
14667 PackExpansionTypeLoc ToExpansionTL
14668 = TLB.push<PackExpansionTypeLoc>(To);
14669 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
14670 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
14671 }
14672
14673 if (!getDerived().AlwaysRebuild() && !ArgChanged)
14674 return E;
14675
14676 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
14677 E->getEndLoc());
14678}
14679
14680template<typename Derived>
14682TreeTransform<Derived>::TransformConceptSpecializationExpr(
14683 ConceptSpecializationExpr *E) {
14684 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
14685 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
14686 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
14687 Old->NumTemplateArgs, TransArgs))
14688 return ExprError();
14689
14690 return getDerived().RebuildConceptSpecializationExpr(
14691 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
14692 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
14693 &TransArgs);
14694}
14695
14696template<typename Derived>
14698TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) {
14699 SmallVector<ParmVarDecl*, 4> TransParams;
14700 SmallVector<QualType, 4> TransParamTypes;
14701 Sema::ExtParameterInfoBuilder ExtParamInfos;
14702
14703 // C++2a [expr.prim.req]p2
14704 // Expressions appearing within a requirement-body are unevaluated operands.
14705 EnterExpressionEvaluationContext Ctx(
14708
14709 RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create(
14710 getSema().Context, getSema().CurContext,
14711 E->getBody()->getBeginLoc());
14712
14713 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
14714
14715 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
14716 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
14717 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
14718
14719 for (ParmVarDecl *Param : TransParams)
14720 if (Param)
14721 Param->setDeclContext(Body);
14722
14723 // On failure to transform, TransformRequiresTypeParams returns an expression
14724 // in the event that the transformation of the type params failed in some way.
14725 // It is expected that this will result in a 'not satisfied' Requires clause
14726 // when instantiating.
14727 if (!TypeParamResult.isUnset())
14728 return TypeParamResult;
14729
14731 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
14732 TransReqs))
14733 return ExprError();
14734
14735 for (concepts::Requirement *Req : TransReqs) {
14736 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
14737 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
14738 ER->getReturnTypeRequirement()
14739 .getTypeConstraintTemplateParameterList()->getParam(0)
14740 ->setDeclContext(Body);
14741 }
14742 }
14743 }
14744
14745 return getDerived().RebuildRequiresExpr(
14746 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
14747 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
14748}
14749
14750template<typename Derived>
14754 for (concepts::Requirement *Req : Reqs) {
14755 concepts::Requirement *TransReq = nullptr;
14756 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
14757 TransReq = getDerived().TransformTypeRequirement(TypeReq);
14758 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
14759 TransReq = getDerived().TransformExprRequirement(ExprReq);
14760 else
14761 TransReq = getDerived().TransformNestedRequirement(
14762 cast<concepts::NestedRequirement>(Req));
14763 if (!TransReq)
14764 return true;
14765 Transformed.push_back(TransReq);
14766 }
14767 return false;
14768}
14769
14770template<typename Derived>
14774 if (Req->isSubstitutionFailure()) {
14775 if (getDerived().AlwaysRebuild())
14776 return getDerived().RebuildTypeRequirement(
14778 return Req;
14779 }
14780 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
14781 if (!TransType)
14782 return nullptr;
14783 return getDerived().RebuildTypeRequirement(TransType);
14784}
14785
14786template<typename Derived>
14789 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
14790 if (Req->isExprSubstitutionFailure())
14791 TransExpr = Req->getExprSubstitutionDiagnostic();
14792 else {
14793 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
14794 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
14795 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
14796 if (TransExprRes.isInvalid())
14797 return nullptr;
14798 TransExpr = TransExprRes.get();
14799 }
14800
14801 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
14802 const auto &RetReq = Req->getReturnTypeRequirement();
14803 if (RetReq.isEmpty())
14804 TransRetReq.emplace();
14805 else if (RetReq.isSubstitutionFailure())
14806 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
14807 else if (RetReq.isTypeConstraint()) {
14808 TemplateParameterList *OrigTPL =
14809 RetReq.getTypeConstraintTemplateParameterList();
14811 getDerived().TransformTemplateParameterList(OrigTPL);
14812 if (!TPL)
14813 return nullptr;
14814 TransRetReq.emplace(TPL);
14815 }
14816 assert(TransRetReq && "All code paths leading here must set TransRetReq");
14817 if (Expr *E = TransExpr.dyn_cast<Expr *>())
14818 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
14819 Req->getNoexceptLoc(),
14820 std::move(*TransRetReq));
14821 return getDerived().RebuildExprRequirement(
14822 cast<concepts::Requirement::SubstitutionDiagnostic *>(TransExpr),
14823 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
14824}
14825
14826template<typename Derived>
14830 if (Req->hasInvalidConstraint()) {
14831 if (getDerived().AlwaysRebuild())
14832 return getDerived().RebuildNestedRequirement(
14834 return Req;
14835 }
14836 ExprResult TransConstraint =
14837 getDerived().TransformExpr(Req->getConstraintExpr());
14838 if (TransConstraint.isInvalid())
14839 return nullptr;
14840 return getDerived().RebuildNestedRequirement(TransConstraint.get());
14841}
14842
14843template<typename Derived>
14846 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
14847 if (!T)
14848 return ExprError();
14849
14850 if (!getDerived().AlwaysRebuild() &&
14851 T == E->getQueriedTypeSourceInfo())
14852 return E;
14853
14854 ExprResult SubExpr;
14855 {
14858 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
14859 if (SubExpr.isInvalid())
14860 return ExprError();
14861
14862 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
14863 return E;
14864 }
14865
14866 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
14867 SubExpr.get(), E->getEndLoc());
14868}
14869
14870template<typename Derived>
14872TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
14873 ExprResult SubExpr;
14874 {
14875 EnterExpressionEvaluationContext Unevaluated(
14877 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
14878 if (SubExpr.isInvalid())
14879 return ExprError();
14880
14881 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
14882 return E;
14883 }
14884
14885 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
14886 SubExpr.get(), E->getEndLoc());
14887}
14888
14889template <typename Derived>
14891 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
14892 TypeSourceInfo **RecoveryTSI) {
14893 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
14894 DRE, AddrTaken, RecoveryTSI);
14895
14896 // Propagate both errors and recovered types, which return ExprEmpty.
14897 if (!NewDRE.isUsable())
14898 return NewDRE;
14899
14900 // We got an expr, wrap it up in parens.
14901 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
14902 return PE;
14903 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
14904 PE->getRParen());
14905}
14906
14907template <typename Derived>
14910 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
14911 nullptr);
14912}
14913
14914template <typename Derived>
14916 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
14917 TypeSourceInfo **RecoveryTSI) {
14918 assert(E->getQualifierLoc());
14919 NestedNameSpecifierLoc QualifierLoc =
14920 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
14921 if (!QualifierLoc)
14922 return ExprError();
14923 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14924
14925 // TODO: If this is a conversion-function-id, verify that the
14926 // destination type name (if present) resolves the same way after
14927 // instantiation as it did in the local scope.
14928
14929 DeclarationNameInfo NameInfo =
14930 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
14931 if (!NameInfo.getName())
14932 return ExprError();
14933
14934 if (!E->hasExplicitTemplateArgs()) {
14935 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
14936 // Note: it is sufficient to compare the Name component of NameInfo:
14937 // if name has not changed, DNLoc has not changed either.
14938 NameInfo.getName() == E->getDeclName())
14939 return E;
14940
14941 return getDerived().RebuildDependentScopeDeclRefExpr(
14942 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
14943 IsAddressOfOperand, RecoveryTSI);
14944 }
14945
14946 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
14947 if (getDerived().TransformTemplateArguments(
14948 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
14949 return ExprError();
14950
14951 return getDerived().RebuildDependentScopeDeclRefExpr(
14952 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
14953 RecoveryTSI);
14954}
14955
14956template<typename Derived>
14958TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
14959 // CXXConstructExprs other than for list-initialization and
14960 // CXXTemporaryObjectExpr are always implicit, so when we have
14961 // a 1-argument construction we just transform that argument.
14962 if (getDerived().AllowSkippingCXXConstructExpr() &&
14963 ((E->getNumArgs() == 1 ||
14964 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
14965 (!getDerived().DropCallArgument(E->getArg(0))) &&
14966 !E->isListInitialization()))
14967 return getDerived().TransformInitializer(E->getArg(0),
14968 /*DirectInit*/ false);
14969
14970 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
14971
14972 QualType T = getDerived().TransformType(E->getType());
14973 if (T.isNull())
14974 return ExprError();
14975
14976 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
14977 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
14978 if (!Constructor)
14979 return ExprError();
14980
14981 bool ArgumentChanged = false;
14983 {
14984 EnterExpressionEvaluationContext Context(
14986 E->isListInitialization());
14987 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14988 &ArgumentChanged))
14989 return ExprError();
14990 }
14991
14992 if (!getDerived().AlwaysRebuild() &&
14993 T == E->getType() &&
14994 Constructor == E->getConstructor() &&
14995 !ArgumentChanged) {
14996 // Mark the constructor as referenced.
14997 // FIXME: Instantiation-specific
14998 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
14999 return E;
15000 }
15001
15002 return getDerived().RebuildCXXConstructExpr(
15003 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15004 E->hadMultipleCandidates(), E->isListInitialization(),
15005 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15006 E->getConstructionKind(), E->getParenOrBraceRange());
15007}
15008
15009template<typename Derived>
15010ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr(
15011 CXXInheritedCtorInitExpr *E) {
15012 QualType T = getDerived().TransformType(E->getType());
15013 if (T.isNull())
15014 return ExprError();
15015
15016 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15017 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15018 if (!Constructor)
15019 return ExprError();
15020
15021 if (!getDerived().AlwaysRebuild() &&
15022 T == E->getType() &&
15023 Constructor == E->getConstructor()) {
15024 // Mark the constructor as referenced.
15025 // FIXME: Instantiation-specific
15026 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15027 return E;
15028 }
15029
15030 return getDerived().RebuildCXXInheritedCtorInitExpr(
15031 T, E->getLocation(), Constructor,
15032 E->constructsVBase(), E->inheritedFromVBase());
15033}
15034
15035/// Transform a C++ temporary-binding expression.
15036///
15037/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15038/// transform the subexpression and return that.
15039template<typename Derived>
15041TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
15042 if (auto *Dtor = E->getTemporary()->getDestructor())
15044 const_cast<CXXDestructorDecl *>(Dtor));
15045 return getDerived().TransformExpr(E->getSubExpr());
15046}
15047
15048/// Transform a C++ expression that contains cleanups that should
15049/// be run after the expression is evaluated.
15050///
15051/// Since ExprWithCleanups nodes are implicitly generated, we
15052/// just transform the subexpression and return that.
15053template<typename Derived>
15055TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
15056 return getDerived().TransformExpr(E->getSubExpr());
15057}
15058
15059template<typename Derived>
15061TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
15062 CXXTemporaryObjectExpr *E) {
15063 TypeSourceInfo *T =
15064 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15065 if (!T)
15066 return ExprError();
15067
15068 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15069 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15070 if (!Constructor)
15071 return ExprError();
15072
15073 bool ArgumentChanged = false;
15075 Args.reserve(E->getNumArgs());
15076 {
15077 EnterExpressionEvaluationContext Context(
15079 E->isListInitialization());
15080 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15081 &ArgumentChanged))
15082 return ExprError();
15083
15084 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15085 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc());
15086 if (Res.isInvalid())
15087 return ExprError();
15088 Args = {Res.get()};
15089 }
15090 }
15091
15092 if (!getDerived().AlwaysRebuild() &&
15093 T == E->getTypeSourceInfo() &&
15094 Constructor == E->getConstructor() &&
15095 !ArgumentChanged) {
15096 // FIXME: Instantiation-specific
15097 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15098 return SemaRef.MaybeBindToTemporary(E);
15099 }
15100
15101 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15102 return getDerived().RebuildCXXTemporaryObjectExpr(
15103 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15104}
15105
15106template<typename Derived>
15108TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
15109 // Transform any init-capture expressions before entering the scope of the
15110 // lambda body, because they are not semantically within that scope.
15111 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15112 struct TransformedInitCapture {
15113 // The location of the ... if the result is retaining a pack expansion.
15114 SourceLocation EllipsisLoc;
15115 // Zero or more expansions of the init-capture.
15117 };
15119 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
15120 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15121 CEnd = E->capture_end();
15122 C != CEnd; ++C) {
15123 if (!E->isInitCapture(C))
15124 continue;
15125
15126 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
15127 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15128
15129 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
15130 std::optional<unsigned> NumExpansions) {
15131 ExprResult NewExprInitResult = getDerived().TransformInitializer(
15132 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
15133
15134 if (NewExprInitResult.isInvalid()) {
15135 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
15136 return;
15137 }
15138 Expr *NewExprInit = NewExprInitResult.get();
15139
15140 QualType NewInitCaptureType =
15141 getSema().buildLambdaInitCaptureInitialization(
15142 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
15143 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
15144 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
15146 NewExprInit);
15147 Result.Expansions.push_back(
15148 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
15149 };
15150
15151 // If this is an init-capture pack, consider expanding the pack now.
15152 if (OldVD->isParameterPack()) {
15153 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
15154 ->getTypeLoc()
15155 .castAs<PackExpansionTypeLoc>();
15157 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
15158
15159 // Determine whether the set of unexpanded parameter packs can and should
15160 // be expanded.
15161 bool Expand = true;
15162 bool RetainExpansion = false;
15163 std::optional<unsigned> OrigNumExpansions =
15164 ExpansionTL.getTypePtr()->getNumExpansions();
15165 std::optional<unsigned> NumExpansions = OrigNumExpansions;
15166 if (getDerived().TryExpandParameterPacks(
15167 ExpansionTL.getEllipsisLoc(),
15168 OldVD->getInit()->getSourceRange(), Unexpanded, Expand,
15169 RetainExpansion, NumExpansions))
15170 return ExprError();
15171 assert(!RetainExpansion && "Should not need to retain expansion after a "
15172 "capture since it cannot be extended");
15173 if (Expand) {
15174 for (unsigned I = 0; I != *NumExpansions; ++I) {
15175 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15176 SubstInitCapture(SourceLocation(), std::nullopt);
15177 }
15178 } else {
15179 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
15180 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
15181 }
15182 } else {
15183 SubstInitCapture(SourceLocation(), std::nullopt);
15184 }
15185 }
15186
15187 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
15188 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
15189
15190 // Create the local class that will describe the lambda.
15191
15192 // FIXME: DependencyKind below is wrong when substituting inside a templated
15193 // context that isn't a DeclContext (such as a variable template), or when
15194 // substituting an unevaluated lambda inside of a function's parameter's type
15195 // - as parameter types are not instantiated from within a function's DC. We
15196 // use evaluation contexts to distinguish the function parameter case.
15199 DeclContext *DC = getSema().CurContext;
15200 // A RequiresExprBodyDecl is not interesting for dependencies.
15201 // For the following case,
15202 //
15203 // template <typename>
15204 // concept C = requires { [] {}; };
15205 //
15206 // template <class F>
15207 // struct Widget;
15208 //
15209 // template <C F>
15210 // struct Widget<F> {};
15211 //
15212 // While we are substituting Widget<F>, the parent of DC would be
15213 // the template specialization itself. Thus, the lambda expression
15214 // will be deemed as dependent even if there are no dependent template
15215 // arguments.
15216 // (A ClassTemplateSpecializationDecl is always a dependent context.)
15217 while (DC->isRequiresExprBody())
15218 DC = DC->getParent();
15219 if ((getSema().isUnevaluatedContext() ||
15220 getSema().isConstantEvaluatedContext()) &&
15221 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
15222 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
15223
15224 CXXRecordDecl *OldClass = E->getLambdaClass();
15225 CXXRecordDecl *Class = getSema().createLambdaClosureType(
15226 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
15227 E->getCaptureDefault());
15228 getDerived().transformedLocalDecl(OldClass, {Class});
15229
15230 CXXMethodDecl *NewCallOperator =
15231 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
15232
15233 // Enter the scope of the lambda.
15234 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
15235 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
15236 E->hasExplicitParameters(), E->isMutable());
15237
15238 // Introduce the context of the call operator.
15239 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
15240 /*NewThisContext*/false);
15241
15242 bool Invalid = false;
15243
15244 // Transform captures.
15245 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15246 CEnd = E->capture_end();
15247 C != CEnd; ++C) {
15248 // When we hit the first implicit capture, tell Sema that we've finished
15249 // the list of explicit captures.
15250 if (C->isImplicit())
15251 break;
15252
15253 // Capturing 'this' is trivial.
15254 if (C->capturesThis()) {
15255 // If this is a lambda that is part of a default member initialiser
15256 // and which we're instantiating outside the class that 'this' is
15257 // supposed to refer to, adjust the type of 'this' accordingly.
15258 //
15259 // Otherwise, leave the type of 'this' as-is.
15260 Sema::CXXThisScopeRAII ThisScope(
15261 getSema(),
15262 dyn_cast_if_present<CXXRecordDecl>(
15263 getSema().getFunctionLevelDeclContext()),
15264 Qualifiers());
15265 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15266 /*BuildAndDiagnose*/ true, nullptr,
15267 C->getCaptureKind() == LCK_StarThis);
15268 continue;
15269 }
15270 // Captured expression will be recaptured during captured variables
15271 // rebuilding.
15272 if (C->capturesVLAType())
15273 continue;
15274
15275 // Rebuild init-captures, including the implied field declaration.
15276 if (E->isInitCapture(C)) {
15277 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
15278
15279 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
15281
15282 for (InitCaptureInfoTy &Info : NewC.Expansions) {
15283 ExprResult Init = Info.first;
15284 QualType InitQualType = Info.second;
15285 if (Init.isInvalid() || InitQualType.isNull()) {
15286 Invalid = true;
15287 break;
15288 }
15289 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
15290 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
15291 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
15292 getSema().CurContext);
15293 if (!NewVD) {
15294 Invalid = true;
15295 break;
15296 }
15297 NewVDs.push_back(NewVD);
15298 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
15299 // Cases we want to tackle:
15300 // ([C(Pack)] {}, ...)
15301 // But rule out cases e.g.
15302 // [...C = Pack()] {}
15303 if (NewC.EllipsisLoc.isInvalid())
15304 LSI->ContainsUnexpandedParameterPack |=
15305 Init.get()->containsUnexpandedParameterPack();
15306 }
15307
15308 if (Invalid)
15309 break;
15310
15311 getDerived().transformedLocalDecl(OldVD, NewVDs);
15312 continue;
15313 }
15314
15315 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15316
15317 // Determine the capture kind for Sema.
15319 = C->isImplicit()? Sema::TryCapture_Implicit
15320 : C->getCaptureKind() == LCK_ByCopy
15323 SourceLocation EllipsisLoc;
15324 if (C->isPackExpansion()) {
15325 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
15326 bool ShouldExpand = false;
15327 bool RetainExpansion = false;
15328 std::optional<unsigned> NumExpansions;
15329 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
15330 C->getLocation(),
15331 Unexpanded,
15332 ShouldExpand, RetainExpansion,
15333 NumExpansions)) {
15334 Invalid = true;
15335 continue;
15336 }
15337
15338 if (ShouldExpand) {
15339 // The transform has determined that we should perform an expansion;
15340 // transform and capture each of the arguments.
15341 // expansion of the pattern. Do so.
15342 auto *Pack = cast<VarDecl>(C->getCapturedVar());
15343 for (unsigned I = 0; I != *NumExpansions; ++I) {
15344 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15345 VarDecl *CapturedVar
15346 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
15347 Pack));
15348 if (!CapturedVar) {
15349 Invalid = true;
15350 continue;
15351 }
15352
15353 // Capture the transformed variable.
15354 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
15355 }
15356
15357 // FIXME: Retain a pack expansion if RetainExpansion is true.
15358
15359 continue;
15360 }
15361
15362 EllipsisLoc = C->getEllipsisLoc();
15363 }
15364
15365 // Transform the captured variable.
15366 auto *CapturedVar = cast_or_null<ValueDecl>(
15367 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15368 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
15369 Invalid = true;
15370 continue;
15371 }
15372
15373 // This is not an init-capture; however it contains an unexpanded pack e.g.
15374 // ([Pack] {}(), ...)
15375 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
15376 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
15377
15378 // Capture the transformed variable.
15379 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
15380 EllipsisLoc);
15381 }
15382 getSema().finishLambdaExplicitCaptures(LSI);
15383
15384 // Transform the template parameters, and add them to the current
15385 // instantiation scope. The null case is handled correctly.
15386 auto TPL = getDerived().TransformTemplateParameterList(
15387 E->getTemplateParameterList());
15388 LSI->GLTemplateParameterList = TPL;
15389 if (TPL) {
15390 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
15391 TPL);
15392 LSI->ContainsUnexpandedParameterPack |=
15393 TPL->containsUnexpandedParameterPack();
15394 }
15395
15396 TypeLocBuilder NewCallOpTLBuilder;
15397 TypeLoc OldCallOpTypeLoc =
15398 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
15399 QualType NewCallOpType =
15400 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
15401 if (NewCallOpType.isNull())
15402 return ExprError();
15403 LSI->ContainsUnexpandedParameterPack |=
15404 NewCallOpType->containsUnexpandedParameterPack();
15405 TypeSourceInfo *NewCallOpTSI =
15406 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
15407
15408 // The type may be an AttributedType or some other kind of sugar;
15409 // get the actual underlying FunctionProtoType.
15410 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
15411 assert(FPTL && "Not a FunctionProtoType?");
15412
15413 getSema().CompleteLambdaCallOperator(
15414 NewCallOperator, E->getCallOperator()->getLocation(),
15415 E->getCallOperator()->getInnerLocStart(),
15416 E->getCallOperator()->getTrailingRequiresClause(), NewCallOpTSI,
15417 E->getCallOperator()->getConstexprKind(),
15418 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
15419 E->hasExplicitResultType());
15420
15421 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
15422 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
15423
15424 {
15425 // Number the lambda for linkage purposes if necessary.
15426 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
15427
15428 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
15429 if (getDerived().ReplacingOriginal()) {
15430 Numbering = OldClass->getLambdaNumbering();
15431 }
15432
15433 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
15434 }
15435
15436 // FIXME: Sema's lambda-building mechanism expects us to push an expression
15437 // evaluation context even if we're not transforming the function body.
15438 getSema().PushExpressionEvaluationContext(
15439 E->getCallOperator()->isConsteval() ?
15442 getSema().currentEvaluationContext().InImmediateEscalatingFunctionContext =
15443 getSema().getLangOpts().CPlusPlus20 &&
15444 E->getCallOperator()->isImmediateEscalating();
15445
15446 Sema::CodeSynthesisContext C;
15448 C.PointOfInstantiation = E->getBody()->getBeginLoc();
15449 getSema().pushCodeSynthesisContext(C);
15450
15451 // Instantiate the body of the lambda expression.
15452 StmtResult Body =
15453 Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody());
15454
15455 getSema().popCodeSynthesisContext();
15456
15457 // ActOnLambda* will pop the function scope for us.
15458 FuncScopeCleanup.disable();
15459
15460 if (Body.isInvalid()) {
15461 SavedContext.pop();
15462 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
15463 /*IsInstantiation=*/true);
15464 return ExprError();
15465 }
15466
15467 // Copy the LSI before ActOnFinishFunctionBody removes it.
15468 // FIXME: This is dumb. Store the lambda information somewhere that outlives
15469 // the call operator.
15470 auto LSICopy = *LSI;
15471 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
15472 /*IsInstantiation*/ true);
15473 SavedContext.pop();
15474
15475 // Recompute the dependency of the lambda so that we can defer the lambda call
15476 // construction until after we have all the necessary template arguments. For
15477 // example, given
15478 //
15479 // template <class> struct S {
15480 // template <class U>
15481 // using Type = decltype([](U){}(42.0));
15482 // };
15483 // void foo() {
15484 // using T = S<int>::Type<float>;
15485 // ^~~~~~
15486 // }
15487 //
15488 // We would end up here from instantiating S<int> when ensuring its
15489 // completeness. That would transform the lambda call expression regardless of
15490 // the absence of the corresponding argument for U.
15491 //
15492 // Going ahead with unsubstituted type U makes things worse: we would soon
15493 // compare the argument type (which is float) against the parameter U
15494 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
15495 // error suggesting unmatched types 'U' and 'float'!
15496 //
15497 // That said, everything will be fine if we defer that semantic checking.
15498 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
15499 // dependent. Since the CallExpr's dependency boils down to the lambda's
15500 // dependency in this case, we can harness that by recomputing the dependency
15501 // from the instantiation arguments.
15502 //
15503 // FIXME: Creating the type of a lambda requires us to have a dependency
15504 // value, which happens before its substitution. We update its dependency
15505 // *after* the substitution in case we can't decide the dependency
15506 // so early, e.g. because we want to see if any of the *substituted*
15507 // parameters are dependent.
15508 DependencyKind = getDerived().ComputeLambdaDependency(&LSICopy);
15509 Class->setLambdaDependencyKind(DependencyKind);
15510 // Clean up the type cache created previously. Then, we re-create a type for
15511 // such Decl with the new DependencyKind.
15512 Class->setTypeForDecl(nullptr);
15513 getSema().Context.getTypeDeclType(Class);
15514
15515 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
15516 Body.get()->getEndLoc(), &LSICopy);
15517}
15518
15519template<typename Derived>
15522 return TransformStmt(S);
15523}
15524
15525template<typename Derived>
15528 // Transform captures.
15529 for (LambdaExpr::capture_iterator C = E->capture_begin(),
15530 CEnd = E->capture_end();
15531 C != CEnd; ++C) {
15532 // When we hit the first implicit capture, tell Sema that we've finished
15533 // the list of explicit captures.
15534 if (!C->isImplicit())
15535 continue;
15536
15537 // Capturing 'this' is trivial.
15538 if (C->capturesThis()) {
15539 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
15540 /*BuildAndDiagnose*/ true, nullptr,
15541 C->getCaptureKind() == LCK_StarThis);
15542 continue;
15543 }
15544 // Captured expression will be recaptured during captured variables
15545 // rebuilding.
15546 if (C->capturesVLAType())
15547 continue;
15548
15549 assert(C->capturesVariable() && "unexpected kind of lambda capture");
15550 assert(!E->isInitCapture(C) && "implicit init-capture?");
15551
15552 // Transform the captured variable.
15553 VarDecl *CapturedVar = cast_or_null<VarDecl>(
15554 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
15555 if (!CapturedVar || CapturedVar->isInvalidDecl())
15556 return StmtError();
15557
15558 // Capture the transformed variable.
15559 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
15560 }
15561
15562 return S;
15563}
15564
15565template<typename Derived>
15569 TypeSourceInfo *T =
15570 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15571 if (!T)
15572 return ExprError();
15573
15574 bool ArgumentChanged = false;
15576 Args.reserve(E->getNumArgs());
15577 {
15580 E->isListInitialization());
15581 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
15582 &ArgumentChanged))
15583 return ExprError();
15584 }
15585
15586 if (!getDerived().AlwaysRebuild() &&
15587 T == E->getTypeSourceInfo() &&
15588 !ArgumentChanged)
15589 return E;
15590
15591 // FIXME: we're faking the locations of the commas
15592 return getDerived().RebuildCXXUnresolvedConstructExpr(
15593 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
15594}
15595
15596template<typename Derived>
15598TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
15599 CXXDependentScopeMemberExpr *E) {
15600 // Transform the base of the expression.
15601 ExprResult Base((Expr*) nullptr);
15602 Expr *OldBase;
15603 QualType BaseType;
15604 QualType ObjectType;
15605 if (!E->isImplicitAccess()) {
15606 OldBase = E->getBase();
15607 Base = getDerived().TransformExpr(OldBase);
15608 if (Base.isInvalid())
15609 return ExprError();
15610
15611 // Start the member reference and compute the object's type.
15612 ParsedType ObjectTy;
15613 bool MayBePseudoDestructor = false;
15614 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15615 E->getOperatorLoc(),
15616 E->isArrow()? tok::arrow : tok::period,
15617 ObjectTy,
15618 MayBePseudoDestructor);
15619 if (Base.isInvalid())
15620 return ExprError();
15621
15622 ObjectType = ObjectTy.get();
15623 BaseType = ((Expr*) Base.get())->getType();
15624 } else {
15625 OldBase = nullptr;
15626 BaseType = getDerived().TransformType(E->getBaseType());
15627 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
15628 }
15629
15630 // Transform the first part of the nested-name-specifier that qualifies
15631 // the member name.
15632 NamedDecl *FirstQualifierInScope
15633 = getDerived().TransformFirstQualifierInScope(
15634 E->getFirstQualifierFoundInScope(),
15635 E->getQualifierLoc().getBeginLoc());
15636
15637 NestedNameSpecifierLoc QualifierLoc;
15638 if (E->getQualifier()) {
15639 QualifierLoc
15640 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
15641 ObjectType,
15642 FirstQualifierInScope);
15643 if (!QualifierLoc)
15644 return ExprError();
15645 }
15646
15647 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15648
15649 // TODO: If this is a conversion-function-id, verify that the
15650 // destination type name (if present) resolves the same way after
15651 // instantiation as it did in the local scope.
15652
15653 DeclarationNameInfo NameInfo
15654 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
15655 if (!NameInfo.getName())
15656 return ExprError();
15657
15658 if (!E->hasExplicitTemplateArgs()) {
15659 // This is a reference to a member without an explicitly-specified
15660 // template argument list. Optimize for this common case.
15661 if (!getDerived().AlwaysRebuild() &&
15662 Base.get() == OldBase &&
15663 BaseType == E->getBaseType() &&
15664 QualifierLoc == E->getQualifierLoc() &&
15665 NameInfo.getName() == E->getMember() &&
15666 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
15667 return E;
15668
15669 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15670 BaseType,
15671 E->isArrow(),
15672 E->getOperatorLoc(),
15673 QualifierLoc,
15674 TemplateKWLoc,
15675 FirstQualifierInScope,
15676 NameInfo,
15677 /*TemplateArgs*/nullptr);
15678 }
15679
15680 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15681 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
15682 E->getNumTemplateArgs(),
15683 TransArgs))
15684 return ExprError();
15685
15686 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
15687 BaseType,
15688 E->isArrow(),
15689 E->getOperatorLoc(),
15690 QualifierLoc,
15691 TemplateKWLoc,
15692 FirstQualifierInScope,
15693 NameInfo,
15694 &TransArgs);
15695}
15696
15697template <typename Derived>
15698ExprResult TreeTransform<Derived>::TransformUnresolvedMemberExpr(
15699 UnresolvedMemberExpr *Old) {
15700 // Transform the base of the expression.
15701 ExprResult Base((Expr *)nullptr);
15702 QualType BaseType;
15703 if (!Old->isImplicitAccess()) {
15704 Base = getDerived().TransformExpr(Old->getBase());
15705 if (Base.isInvalid())
15706 return ExprError();
15707 Base =
15708 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
15709 if (Base.isInvalid())
15710 return ExprError();
15711 BaseType = Base.get()->getType();
15712 } else {
15713 BaseType = getDerived().TransformType(Old->getBaseType());
15714 }
15715
15716 NestedNameSpecifierLoc QualifierLoc;
15717 if (Old->getQualifierLoc()) {
15718 QualifierLoc =
15719 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15720 if (!QualifierLoc)
15721 return ExprError();
15722 }
15723
15724 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15725
15726 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
15727
15728 // Transform the declaration set.
15729 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
15730 return ExprError();
15731
15732 // Determine the naming class.
15733 if (Old->getNamingClass()) {
15734 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
15735 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
15736 if (!NamingClass)
15737 return ExprError();
15738
15739 R.setNamingClass(NamingClass);
15740 }
15741
15742 TemplateArgumentListInfo TransArgs;
15743 if (Old->hasExplicitTemplateArgs()) {
15744 TransArgs.setLAngleLoc(Old->getLAngleLoc());
15745 TransArgs.setRAngleLoc(Old->getRAngleLoc());
15746 if (getDerived().TransformTemplateArguments(
15747 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
15748 return ExprError();
15749 }
15750
15751 // FIXME: to do this check properly, we will need to preserve the
15752 // first-qualifier-in-scope here, just in case we had a dependent
15753 // base (and therefore couldn't do the check) and a
15754 // nested-name-qualifier (and therefore could do the lookup).
15755 NamedDecl *FirstQualifierInScope = nullptr;
15756
15757 return getDerived().RebuildUnresolvedMemberExpr(
15758 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
15759 TemplateKWLoc, FirstQualifierInScope, R,
15760 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
15761}
15762
15763template<typename Derived>
15765TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
15766 EnterExpressionEvaluationContext Unevaluated(
15768 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
15769 if (SubExpr.isInvalid())
15770 return ExprError();
15771
15772 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
15773 return E;
15774
15775 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
15776}
15777
15778template<typename Derived>
15780TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
15781 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
15782 if (Pattern.isInvalid())
15783 return ExprError();
15784
15785 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
15786 return E;
15787
15788 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
15789 E->getNumExpansions());
15790}
15791
15792template<typename Derived>
15794TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
15795 // If E is not value-dependent, then nothing will change when we transform it.
15796 // Note: This is an instantiation-centric view.
15797 if (!E->isValueDependent())
15798 return E;
15799
15800 EnterExpressionEvaluationContext Unevaluated(
15802
15804 TemplateArgument ArgStorage;
15805
15806 // Find the argument list to transform.
15807 if (E->isPartiallySubstituted()) {
15808 PackArgs = E->getPartialArguments();
15809 } else if (E->isValueDependent()) {
15810 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
15811 bool ShouldExpand = false;
15812 bool RetainExpansion = false;
15813 std::optional<unsigned> NumExpansions;
15814 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
15815 Unexpanded,
15816 ShouldExpand, RetainExpansion,
15817 NumExpansions))
15818 return ExprError();
15819
15820 // If we need to expand the pack, build a template argument from it and
15821 // expand that.
15822 if (ShouldExpand) {
15823 auto *Pack = E->getPack();
15824 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
15825 ArgStorage = getSema().Context.getPackExpansionType(
15826 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
15827 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
15828 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
15829 } else {
15830 auto *VD = cast<ValueDecl>(Pack);
15831 ExprResult DRE = getSema().BuildDeclRefExpr(
15832 VD, VD->getType().getNonLValueExprType(getSema().Context),
15833 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
15834 E->getPackLoc());
15835 if (DRE.isInvalid())
15836 return ExprError();
15837 ArgStorage = new (getSema().Context)
15838 PackExpansionExpr(getSema().Context.DependentTy, DRE.get(),
15839 E->getPackLoc(), std::nullopt);
15840 }
15841 PackArgs = ArgStorage;
15842 }
15843 }
15844
15845 // If we're not expanding the pack, just transform the decl.
15846 if (!PackArgs.size()) {
15847 auto *Pack = cast_or_null<NamedDecl>(
15848 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
15849 if (!Pack)
15850 return ExprError();
15851 return getDerived().RebuildSizeOfPackExpr(
15852 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
15853 std::nullopt, {});
15854 }
15855
15856 // Try to compute the result without performing a partial substitution.
15857 std::optional<unsigned> Result = 0;
15858 for (const TemplateArgument &Arg : PackArgs) {
15859 if (!Arg.isPackExpansion()) {
15860 Result = *Result + 1;
15861 continue;
15862 }
15863
15864 TemplateArgumentLoc ArgLoc;
15865 InventTemplateArgumentLoc(Arg, ArgLoc);
15866
15867 // Find the pattern of the pack expansion.
15868 SourceLocation Ellipsis;
15869 std::optional<unsigned> OrigNumExpansions;
15870 TemplateArgumentLoc Pattern =
15871 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
15872 OrigNumExpansions);
15873
15874 // Substitute under the pack expansion. Do not expand the pack (yet).
15875 TemplateArgumentLoc OutPattern;
15876 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15877 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
15878 /*Uneval*/ true))
15879 return true;
15880
15881 // See if we can determine the number of arguments from the result.
15882 std::optional<unsigned> NumExpansions =
15883 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
15884 if (!NumExpansions) {
15885 // No: we must be in an alias template expansion, and we're going to need
15886 // to actually expand the packs.
15887 Result = std::nullopt;
15888 break;
15889 }
15890
15891 Result = *Result + *NumExpansions;
15892 }
15893
15894 // Common case: we could determine the number of expansions without
15895 // substituting.
15896 if (Result)
15897 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
15898 E->getPackLoc(),
15899 E->getRParenLoc(), *Result, {});
15900
15901 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
15902 E->getPackLoc());
15903 {
15904 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
15905 typedef TemplateArgumentLocInventIterator<
15906 Derived, const TemplateArgument*> PackLocIterator;
15907 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
15908 PackLocIterator(*this, PackArgs.end()),
15909 TransformedPackArgs, /*Uneval*/true))
15910 return ExprError();
15911 }
15912
15913 // Check whether we managed to fully-expand the pack.
15914 // FIXME: Is it possible for us to do so and not hit the early exit path?
15916 bool PartialSubstitution = false;
15917 for (auto &Loc : TransformedPackArgs.arguments()) {
15918 Args.push_back(Loc.getArgument());
15919 if (Loc.getArgument().isPackExpansion())
15920 PartialSubstitution = true;
15921 }
15922
15923 if (PartialSubstitution)
15924 return getDerived().RebuildSizeOfPackExpr(
15925 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
15926 std::nullopt, Args);
15927
15928 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
15929 E->getPackLoc(), E->getRParenLoc(),
15930 Args.size(), {});
15931}
15932
15933template <typename Derived>
15935TreeTransform<Derived>::TransformPackIndexingExpr(PackIndexingExpr *E) {
15936 if (!E->isValueDependent())
15937 return E;
15938
15939 // Transform the index
15940 ExprResult IndexExpr;
15941 {
15942 EnterExpressionEvaluationContext ConstantContext(
15944 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
15945 if (IndexExpr.isInvalid())
15946 return ExprError();
15947 }
15948
15949 SmallVector<Expr *, 5> ExpandedExprs;
15950 bool FullySubstituted = true;
15951 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
15952 Expr *Pattern = E->getPackIdExpression();
15954 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
15955 Unexpanded);
15956 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
15957
15958 // Determine whether the set of unexpanded parameter packs can and should
15959 // be expanded.
15960 bool ShouldExpand = true;
15961 bool RetainExpansion = false;
15962 std::optional<unsigned> OrigNumExpansions;
15963 std::optional<unsigned> NumExpansions = OrigNumExpansions;
15964 if (getDerived().TryExpandParameterPacks(
15965 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
15966 ShouldExpand, RetainExpansion, NumExpansions))
15967 return true;
15968 if (!ShouldExpand) {
15969 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
15970 ExprResult Pack = getDerived().TransformExpr(Pattern);
15971 if (Pack.isInvalid())
15972 return ExprError();
15973 return getDerived().RebuildPackIndexingExpr(
15974 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
15975 {}, /*FullySubstituted=*/false);
15976 }
15977 for (unsigned I = 0; I != *NumExpansions; ++I) {
15978 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
15979 ExprResult Out = getDerived().TransformExpr(Pattern);
15980 if (Out.isInvalid())
15981 return true;
15982 if (Out.get()->containsUnexpandedParameterPack()) {
15983 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
15984 OrigNumExpansions);
15985 if (Out.isInvalid())
15986 return true;
15987 FullySubstituted = false;
15988 }
15989 ExpandedExprs.push_back(Out.get());
15990 }
15991 // If we're supposed to retain a pack expansion, do so by temporarily
15992 // forgetting the partially-substituted parameter pack.
15993 if (RetainExpansion) {
15994 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15995
15996 ExprResult Out = getDerived().TransformExpr(Pattern);
15997 if (Out.isInvalid())
15998 return true;
15999
16000 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16001 OrigNumExpansions);
16002 if (Out.isInvalid())
16003 return true;
16004 FullySubstituted = false;
16005 ExpandedExprs.push_back(Out.get());
16006 }
16007 } else if (!E->expandsToEmptyPack()) {
16008 if (getDerived().TransformExprs(E->getExpressions().data(),
16009 E->getExpressions().size(), false,
16010 ExpandedExprs))
16011 return ExprError();
16012 }
16013
16014 return getDerived().RebuildPackIndexingExpr(
16015 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16016 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16017}
16018
16019template<typename Derived>
16021TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
16022 SubstNonTypeTemplateParmPackExpr *E) {
16023 // Default behavior is to do nothing with this transformation.
16024 return E;
16025}
16026
16027template<typename Derived>
16029TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
16030 SubstNonTypeTemplateParmExpr *E) {
16031 // Default behavior is to do nothing with this transformation.
16032 return E;
16033}
16034
16035template<typename Derived>
16037TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
16038 // Default behavior is to do nothing with this transformation.
16039 return E;
16040}
16041
16042template<typename Derived>
16044TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
16045 MaterializeTemporaryExpr *E) {
16046 return getDerived().TransformExpr(E->getSubExpr());
16047}
16048
16049template<typename Derived>
16051TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
16052 UnresolvedLookupExpr *Callee = nullptr;
16053 if (Expr *OldCallee = E->getCallee()) {
16054 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
16055 if (CalleeResult.isInvalid())
16056 return ExprError();
16057 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
16058 }
16059
16060 Expr *Pattern = E->getPattern();
16061
16063 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
16064 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16065
16066 // Determine whether the set of unexpanded parameter packs can and should
16067 // be expanded.
16068 bool Expand = true;
16069 bool RetainExpansion = false;
16070 std::optional<unsigned> OrigNumExpansions = E->getNumExpansions(),
16071 NumExpansions = OrigNumExpansions;
16072 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
16073 Pattern->getSourceRange(),
16074 Unexpanded,
16075 Expand, RetainExpansion,
16076 NumExpansions))
16077 return true;
16078
16079 if (!Expand) {
16080 // Do not expand any packs here, just transform and rebuild a fold
16081 // expression.
16082 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16083
16084 ExprResult LHS =
16085 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
16086 if (LHS.isInvalid())
16087 return true;
16088
16089 ExprResult RHS =
16090 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
16091 if (RHS.isInvalid())
16092 return true;
16093
16094 if (!getDerived().AlwaysRebuild() &&
16095 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
16096 return E;
16097
16098 return getDerived().RebuildCXXFoldExpr(
16099 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
16100 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
16101 }
16102
16103 // Formally a fold expression expands to nested parenthesized expressions.
16104 // Enforce this limit to avoid creating trees so deep we can't safely traverse
16105 // them.
16106 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) {
16107 SemaRef.Diag(E->getEllipsisLoc(),
16108 clang::diag::err_fold_expression_limit_exceeded)
16109 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
16110 << E->getSourceRange();
16111 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
16112 return ExprError();
16113 }
16114
16115 // The transform has determined that we should perform an elementwise
16116 // expansion of the pattern. Do so.
16117 ExprResult Result = getDerived().TransformExpr(E->getInit());
16118 if (Result.isInvalid())
16119 return true;
16120 bool LeftFold = E->isLeftFold();
16121
16122 // If we're retaining an expansion for a right fold, it is the innermost
16123 // component and takes the init (if any).
16124 if (!LeftFold && RetainExpansion) {
16125 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16126
16127 ExprResult Out = getDerived().TransformExpr(Pattern);
16128 if (Out.isInvalid())
16129 return true;
16130
16131 Result = getDerived().RebuildCXXFoldExpr(
16132 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
16133 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
16134 if (Result.isInvalid())
16135 return true;
16136 }
16137
16138 for (unsigned I = 0; I != *NumExpansions; ++I) {
16139 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
16140 getSema(), LeftFold ? I : *NumExpansions - I - 1);
16141 ExprResult Out = getDerived().TransformExpr(Pattern);
16142 if (Out.isInvalid())
16143 return true;
16144
16145 if (Out.get()->containsUnexpandedParameterPack()) {
16146 // We still have a pack; retain a pack expansion for this slice.
16147 Result = getDerived().RebuildCXXFoldExpr(
16148 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
16149 E->getOperator(), E->getEllipsisLoc(),
16150 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
16151 OrigNumExpansions);
16152 } else if (Result.isUsable()) {
16153 // We've got down to a single element; build a binary operator.
16154 Expr *LHS = LeftFold ? Result.get() : Out.get();
16155 Expr *RHS = LeftFold ? Out.get() : Result.get();
16156 if (Callee) {
16157 UnresolvedSet<16> Functions;
16158 Functions.append(Callee->decls_begin(), Callee->decls_end());
16159 Result = getDerived().RebuildCXXOperatorCallExpr(
16161 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
16162 Functions, LHS, RHS);
16163 } else {
16164 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
16165 E->getOperator(), LHS, RHS);
16166 }
16167 } else
16168 Result = Out;
16169
16170 if (Result.isInvalid())
16171 return true;
16172 }
16173
16174 // If we're retaining an expansion for a left fold, it is the outermost
16175 // component and takes the complete expansion so far as its init (if any).
16176 if (LeftFold && RetainExpansion) {
16177 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16178
16179 ExprResult Out = getDerived().TransformExpr(Pattern);
16180 if (Out.isInvalid())
16181 return true;
16182
16183 Result = getDerived().RebuildCXXFoldExpr(
16184 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
16185 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
16186 if (Result.isInvalid())
16187 return true;
16188 }
16189
16190 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
16191 PE->setIsProducedByFoldExpansion();
16192
16193 // If we had no init and an empty pack, and we're not retaining an expansion,
16194 // then produce a fallback value or error.
16195 if (Result.isUnset())
16196 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
16197 E->getOperator());
16198 return Result;
16199}
16200
16201template <typename Derived>
16203TreeTransform<Derived>::TransformCXXParenListInitExpr(CXXParenListInitExpr *E) {
16204 SmallVector<Expr *, 4> TransformedInits;
16205 ArrayRef<Expr *> InitExprs = E->getInitExprs();
16206 if (TransformExprs(InitExprs.data(), InitExprs.size(), true,
16207 TransformedInits))
16208 return ExprError();
16209
16210 return getDerived().RebuildParenListExpr(E->getBeginLoc(), TransformedInits,
16211 E->getEndLoc());
16212}
16213
16214template<typename Derived>
16216TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
16217 CXXStdInitializerListExpr *E) {
16218 return getDerived().TransformExpr(E->getSubExpr());
16219}
16220
16221template<typename Derived>
16223TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
16224 return SemaRef.MaybeBindToTemporary(E);
16225}
16226
16227template<typename Derived>
16229TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
16230 return E;
16231}
16232
16233template<typename Derived>
16235TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
16236 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
16237 if (SubExpr.isInvalid())
16238 return ExprError();
16239
16240 if (!getDerived().AlwaysRebuild() &&
16241 SubExpr.get() == E->getSubExpr())
16242 return E;
16243
16244 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
16245}
16246
16247template<typename Derived>
16249TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
16250 // Transform each of the elements.
16251 SmallVector<Expr *, 8> Elements;
16252 bool ArgChanged = false;
16253 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
16254 /*IsCall=*/false, Elements, &ArgChanged))
16255 return ExprError();
16256
16257 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16258 return SemaRef.MaybeBindToTemporary(E);
16259
16260 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
16261 Elements.data(),
16262 Elements.size());
16263}
16264
16265template<typename Derived>
16267TreeTransform<Derived>::TransformObjCDictionaryLiteral(
16268 ObjCDictionaryLiteral *E) {
16269 // Transform each of the elements.
16271 bool ArgChanged = false;
16272 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
16273 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
16274
16275 if (OrigElement.isPackExpansion()) {
16276 // This key/value element is a pack expansion.
16278 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
16279 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
16280 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16281
16282 // Determine whether the set of unexpanded parameter packs can
16283 // and should be expanded.
16284 bool Expand = true;
16285 bool RetainExpansion = false;
16286 std::optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
16287 std::optional<unsigned> NumExpansions = OrigNumExpansions;
16288 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
16289 OrigElement.Value->getEndLoc());
16290 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
16291 PatternRange, Unexpanded, Expand,
16292 RetainExpansion, NumExpansions))
16293 return ExprError();
16294
16295 if (!Expand) {
16296 // The transform has determined that we should perform a simple
16297 // transformation on the pack expansion, producing another pack
16298 // expansion.
16299 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
16300 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16301 if (Key.isInvalid())
16302 return ExprError();
16303
16304 if (Key.get() != OrigElement.Key)
16305 ArgChanged = true;
16306
16307 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16308 if (Value.isInvalid())
16309 return ExprError();
16310
16311 if (Value.get() != OrigElement.Value)
16312 ArgChanged = true;
16313
16314 ObjCDictionaryElement Expansion = {
16315 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
16316 };
16317 Elements.push_back(Expansion);
16318 continue;
16319 }
16320
16321 // Record right away that the argument was changed. This needs
16322 // to happen even if the array expands to nothing.
16323 ArgChanged = true;
16324
16325 // The transform has determined that we should perform an elementwise
16326 // expansion of the pattern. Do so.
16327 for (unsigned I = 0; I != *NumExpansions; ++I) {
16328 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
16329 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16330 if (Key.isInvalid())
16331 return ExprError();
16332
16333 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
16334 if (Value.isInvalid())
16335 return ExprError();
16336
16337 ObjCDictionaryElement Element = {
16338 Key.get(), Value.get(), SourceLocation(), NumExpansions
16339 };
16340
16341 // If any unexpanded parameter packs remain, we still have a
16342 // pack expansion.
16343 // FIXME: Can this really happen?
16344 if (Key.get()->containsUnexpandedParameterPack() ||
16345 Value.get()->containsUnexpandedParameterPack())
16346 Element.EllipsisLoc = OrigElement.EllipsisLoc;
16347
16348 Elements.push_back(Element);
16349 }
16350
16351 // FIXME: Retain a pack expansion if RetainExpansion is true.
16352
16353 // We've finished with this pack expansion.
16354 continue;
16355 }
16356
16357 // Transform and check key.
16358 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
16359 if (Key.isInvalid())
16360 return ExprError();
16361
16362 if (Key.get() != OrigElement.Key)
16363 ArgChanged = true;
16364
16365 // Transform and check value.
16367 = getDerived().TransformExpr(OrigElement.Value);
16368 if (Value.isInvalid())
16369 return ExprError();
16370
16371 if (Value.get() != OrigElement.Value)
16372 ArgChanged = true;
16373
16374 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
16375 std::nullopt};
16376 Elements.push_back(Element);
16377 }
16378
16379 if (!getDerived().AlwaysRebuild() && !ArgChanged)
16380 return SemaRef.MaybeBindToTemporary(E);
16381
16382 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
16383 Elements);
16384}
16385
16386template<typename Derived>
16388TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
16389 TypeSourceInfo *EncodedTypeInfo
16390 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
16391 if (!EncodedTypeInfo)
16392 return ExprError();
16393
16394 if (!getDerived().AlwaysRebuild() &&
16395 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
16396 return E;
16397
16398 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
16399 EncodedTypeInfo,
16400 E->getRParenLoc());
16401}
16402
16403template<typename Derived>
16404ExprResult TreeTransform<Derived>::
16405TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
16406 // This is a kind of implicit conversion, and it needs to get dropped
16407 // and recomputed for the same general reasons that ImplicitCastExprs
16408 // do, as well a more specific one: this expression is only valid when
16409 // it appears *immediately* as an argument expression.
16410 return getDerived().TransformExpr(E->getSubExpr());
16411}
16412
16413template<typename Derived>
16414ExprResult TreeTransform<Derived>::
16415TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
16416 TypeSourceInfo *TSInfo
16417 = getDerived().TransformType(E->getTypeInfoAsWritten());
16418 if (!TSInfo)
16419 return ExprError();
16420
16421 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
16422 if (Result.isInvalid())
16423 return ExprError();
16424
16425 if (!getDerived().AlwaysRebuild() &&
16426 TSInfo == E->getTypeInfoAsWritten() &&
16427 Result.get() == E->getSubExpr())
16428 return E;
16429
16430 return SemaRef.ObjC().BuildObjCBridgedCast(
16431 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
16432 Result.get());
16433}
16434
16435template <typename Derived>
16436ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr(
16437 ObjCAvailabilityCheckExpr *E) {
16438 return E;
16439}
16440
16441template<typename Derived>
16443TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
16444 // Transform arguments.
16445 bool ArgChanged = false;
16447 Args.reserve(E->getNumArgs());
16448 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
16449 &ArgChanged))
16450 return ExprError();
16451
16452 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
16453 // Class message: transform the receiver type.
16454 TypeSourceInfo *ReceiverTypeInfo
16455 = getDerived().TransformType(E->getClassReceiverTypeInfo());
16456 if (!ReceiverTypeInfo)
16457 return ExprError();
16458
16459 // If nothing changed, just retain the existing message send.
16460 if (!getDerived().AlwaysRebuild() &&
16461 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
16462 return SemaRef.MaybeBindToTemporary(E);
16463
16464 // Build a new class message send.
16466 E->getSelectorLocs(SelLocs);
16467 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
16468 E->getSelector(),
16469 SelLocs,
16470 E->getMethodDecl(),
16471 E->getLeftLoc(),
16472 Args,
16473 E->getRightLoc());
16474 }
16475 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
16476 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
16477 if (!E->getMethodDecl())
16478 return ExprError();
16479
16480 // Build a new class message send to 'super'.
16482 E->getSelectorLocs(SelLocs);
16483 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
16484 E->getSelector(),
16485 SelLocs,
16486 E->getReceiverType(),
16487 E->getMethodDecl(),
16488 E->getLeftLoc(),
16489 Args,
16490 E->getRightLoc());
16491 }
16492
16493 // Instance message: transform the receiver
16494 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
16495 "Only class and instance messages may be instantiated");
16496 ExprResult Receiver
16497 = getDerived().TransformExpr(E->getInstanceReceiver());
16498 if (Receiver.isInvalid())
16499 return ExprError();
16500
16501 // If nothing changed, just retain the existing message send.
16502 if (!getDerived().AlwaysRebuild() &&
16503 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
16504 return SemaRef.MaybeBindToTemporary(E);
16505
16506 // Build a new instance message send.
16508 E->getSelectorLocs(SelLocs);
16509 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
16510 E->getSelector(),
16511 SelLocs,
16512 E->getMethodDecl(),
16513 E->getLeftLoc(),
16514 Args,
16515 E->getRightLoc());
16516}
16517
16518template<typename Derived>
16520TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
16521 return E;
16522}
16523
16524template<typename Derived>
16526TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
16527 return E;
16528}
16529
16530template<typename Derived>
16532TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
16533 // Transform the base expression.
16534 ExprResult Base = getDerived().TransformExpr(E->getBase());
16535 if (Base.isInvalid())
16536 return ExprError();
16537
16538 // We don't need to transform the ivar; it will never change.
16539
16540 // If nothing changed, just retain the existing expression.
16541 if (!getDerived().AlwaysRebuild() &&
16542 Base.get() == E->getBase())
16543 return E;
16544
16545 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
16546 E->getLocation(),
16547 E->isArrow(), E->isFreeIvar());
16548}
16549
16550template<typename Derived>
16552TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
16553 // 'super' and types never change. Property never changes. Just
16554 // retain the existing expression.
16555 if (!E->isObjectReceiver())
16556 return E;
16557
16558 // Transform the base expression.
16559 ExprResult Base = getDerived().TransformExpr(E->getBase());
16560 if (Base.isInvalid())
16561 return ExprError();
16562
16563 // We don't need to transform the property; it will never change.
16564
16565 // If nothing changed, just retain the existing expression.
16566 if (!getDerived().AlwaysRebuild() &&
16567 Base.get() == E->getBase())
16568 return E;
16569
16570 if (E->isExplicitProperty())
16571 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16572 E->getExplicitProperty(),
16573 E->getLocation());
16574
16575 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
16576 SemaRef.Context.PseudoObjectTy,
16577 E->getImplicitPropertyGetter(),
16578 E->getImplicitPropertySetter(),
16579 E->getLocation());
16580}
16581
16582template<typename Derived>
16584TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
16585 // Transform the base expression.
16586 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
16587 if (Base.isInvalid())
16588 return ExprError();
16589
16590 // Transform the key expression.
16591 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
16592 if (Key.isInvalid())
16593 return ExprError();
16594
16595 // If nothing changed, just retain the existing expression.
16596 if (!getDerived().AlwaysRebuild() &&
16597 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
16598 return E;
16599
16600 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
16601 Base.get(), Key.get(),
16602 E->getAtIndexMethodDecl(),
16603 E->setAtIndexMethodDecl());
16604}
16605
16606template<typename Derived>
16608TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
16609 // Transform the base expression.
16610 ExprResult Base = getDerived().TransformExpr(E->getBase());
16611 if (Base.isInvalid())
16612 return ExprError();
16613
16614 // If nothing changed, just retain the existing expression.
16615 if (!getDerived().AlwaysRebuild() &&
16616 Base.get() == E->getBase())
16617 return E;
16618
16619 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
16620 E->getOpLoc(),
16621 E->isArrow());
16622}
16623
16624template<typename Derived>
16626TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
16627 bool ArgumentChanged = false;
16628 SmallVector<Expr*, 8> SubExprs;
16629 SubExprs.reserve(E->getNumSubExprs());
16630 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
16631 SubExprs, &ArgumentChanged))
16632 return ExprError();
16633
16634 if (!getDerived().AlwaysRebuild() &&
16635 !ArgumentChanged)
16636 return E;
16637
16638 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
16639 SubExprs,
16640 E->getRParenLoc());
16641}
16642
16643template<typename Derived>
16645TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
16646 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
16647 if (SrcExpr.isInvalid())
16648 return ExprError();
16649
16650 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
16651 if (!Type)
16652 return ExprError();
16653
16654 if (!getDerived().AlwaysRebuild() &&
16655 Type == E->getTypeSourceInfo() &&
16656 SrcExpr.get() == E->getSrcExpr())
16657 return E;
16658
16659 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
16660 SrcExpr.get(), Type,
16661 E->getRParenLoc());
16662}
16663
16664template<typename Derived>
16666TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
16667 BlockDecl *oldBlock = E->getBlockDecl();
16668
16669 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
16670 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
16671
16672 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
16673 blockScope->TheDecl->setBlockMissingReturnType(
16674 oldBlock->blockMissingReturnType());
16675
16677 SmallVector<QualType, 4> paramTypes;
16678
16679 const FunctionProtoType *exprFunctionType = E->getFunctionType();
16680
16681 // Parameter substitution.
16682 Sema::ExtParameterInfoBuilder extParamInfos;
16683 if (getDerived().TransformFunctionTypeParams(
16684 E->getCaretLocation(), oldBlock->parameters(), nullptr,
16685 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
16686 extParamInfos)) {
16687 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
16688 return ExprError();
16689 }
16690
16691 QualType exprResultType =
16692 getDerived().TransformType(exprFunctionType->getReturnType());
16693
16694 auto epi = exprFunctionType->getExtProtoInfo();
16695 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
16696
16697 QualType functionType =
16698 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
16699 blockScope->FunctionType = functionType;
16700
16701 // Set the parameters on the block decl.
16702 if (!params.empty())
16703 blockScope->TheDecl->setParams(params);
16704
16705 if (!oldBlock->blockMissingReturnType()) {
16706 blockScope->HasImplicitReturnType = false;
16707 blockScope->ReturnType = exprResultType;
16708 }
16709
16710 // Transform the body
16711 StmtResult body = getDerived().TransformStmt(E->getBody());
16712 if (body.isInvalid()) {
16713 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
16714 return ExprError();
16715 }
16716
16717#ifndef NDEBUG
16718 // In builds with assertions, make sure that we captured everything we
16719 // captured before.
16720 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
16721 for (const auto &I : oldBlock->captures()) {
16722 VarDecl *oldCapture = I.getVariable();
16723
16724 // Ignore parameter packs.
16725 if (oldCapture->isParameterPack())
16726 continue;
16727
16728 VarDecl *newCapture =
16729 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
16730 oldCapture));
16731 assert(blockScope->CaptureMap.count(newCapture));
16732 }
16733
16734 // The this pointer may not be captured by the instantiated block, even when
16735 // it's captured by the original block, if the expression causing the
16736 // capture is in the discarded branch of a constexpr if statement.
16737 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
16738 "this pointer isn't captured in the old block");
16739 }
16740#endif
16741
16742 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
16743 /*Scope=*/nullptr);
16744}
16745
16746template<typename Derived>
16748TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
16749 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
16750 if (SrcExpr.isInvalid())
16751 return ExprError();
16752
16753 QualType Type = getDerived().TransformType(E->getType());
16754
16755 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
16756 E->getRParenLoc());
16757}
16758
16759template<typename Derived>
16761TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
16762 bool ArgumentChanged = false;
16763 SmallVector<Expr*, 8> SubExprs;
16764 SubExprs.reserve(E->getNumSubExprs());
16765 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
16766 SubExprs, &ArgumentChanged))
16767 return ExprError();
16768
16769 if (!getDerived().AlwaysRebuild() &&
16770 !ArgumentChanged)
16771 return E;
16772
16773 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
16774 E->getOp(), E->getRParenLoc());
16775}
16776
16777//===----------------------------------------------------------------------===//
16778// Type reconstruction
16779//===----------------------------------------------------------------------===//
16780
16781template<typename Derived>
16784 return SemaRef.BuildPointerType(PointeeType, Star,
16785 getDerived().getBaseEntity());
16786}
16787
16788template<typename Derived>
16791 return SemaRef.BuildBlockPointerType(PointeeType, Star,
16792 getDerived().getBaseEntity());
16793}
16794
16795template<typename Derived>
16798 bool WrittenAsLValue,
16799 SourceLocation Sigil) {
16800 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
16801 Sigil, getDerived().getBaseEntity());
16802}
16803
16804template<typename Derived>
16807 QualType ClassType,
16808 SourceLocation Sigil) {
16809 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
16810 getDerived().getBaseEntity());
16811}
16812
16813template<typename Derived>
16815 const ObjCTypeParamDecl *Decl,
16816 SourceLocation ProtocolLAngleLoc,
16818 ArrayRef<SourceLocation> ProtocolLocs,
16819 SourceLocation ProtocolRAngleLoc) {
16820 return SemaRef.ObjC().BuildObjCTypeParamType(
16821 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16822 /*FailOnError=*/true);
16823}
16824
16825template<typename Derived>
16827 QualType BaseType,
16829 SourceLocation TypeArgsLAngleLoc,
16831 SourceLocation TypeArgsRAngleLoc,
16832 SourceLocation ProtocolLAngleLoc,
16834 ArrayRef<SourceLocation> ProtocolLocs,
16835 SourceLocation ProtocolRAngleLoc) {
16836 return SemaRef.ObjC().BuildObjCObjectType(
16837 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
16838 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
16839 /*FailOnError=*/true,
16840 /*Rebuilding=*/true);
16841}
16842
16843template<typename Derived>
16845 QualType PointeeType,
16847 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
16848}
16849
16850template <typename Derived>
16852 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
16853 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16854 if (SizeExpr || !Size)
16855 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
16856 IndexTypeQuals, BracketsRange,
16857 getDerived().getBaseEntity());
16858
16859 QualType Types[] = {
16863 };
16864 QualType SizeType;
16865 for (const auto &T : Types)
16866 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
16867 SizeType = T;
16868 break;
16869 }
16870
16871 // Note that we can return a VariableArrayType here in the case where
16872 // the element type was a dependent VariableArrayType.
16873 IntegerLiteral *ArraySize
16874 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
16875 /*FIXME*/BracketsRange.getBegin());
16876 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
16877 IndexTypeQuals, BracketsRange,
16878 getDerived().getBaseEntity());
16879}
16880
16881template <typename Derived>
16883 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
16884 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
16885 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
16886 IndexTypeQuals, BracketsRange);
16887}
16888
16889template <typename Derived>
16891 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
16892 SourceRange BracketsRange) {
16893 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
16894 IndexTypeQuals, BracketsRange);
16895}
16896
16897template <typename Derived>
16899 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16900 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16901 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16902 SizeExpr,
16903 IndexTypeQuals, BracketsRange);
16904}
16905
16906template <typename Derived>
16908 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
16909 unsigned IndexTypeQuals, SourceRange BracketsRange) {
16910 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
16911 SizeExpr,
16912 IndexTypeQuals, BracketsRange);
16913}
16914
16915template <typename Derived>
16917 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
16918 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
16919 AttributeLoc);
16920}
16921
16922template <typename Derived>
16924 unsigned NumElements,
16925 VectorKind VecKind) {
16926 // FIXME: semantic checking!
16927 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
16928}
16929
16930template <typename Derived>
16932 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
16933 VectorKind VecKind) {
16934 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
16935}
16936
16937template<typename Derived>
16939 unsigned NumElements,
16940 SourceLocation AttributeLoc) {
16941 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
16942 NumElements, true);
16943 IntegerLiteral *VectorSize
16944 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
16945 AttributeLoc);
16946 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
16947}
16948
16949template<typename Derived>
16952 Expr *SizeExpr,
16953 SourceLocation AttributeLoc) {
16954 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
16955}
16956
16957template <typename Derived>
16959 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
16960 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
16961 NumColumns);
16962}
16963
16964template <typename Derived>
16966 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
16967 SourceLocation AttributeLoc) {
16968 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
16969 AttributeLoc);
16970}
16971
16972template<typename Derived>
16974 QualType T,
16975 MutableArrayRef<QualType> ParamTypes,
16977 return SemaRef.BuildFunctionType(T, ParamTypes,
16978 getDerived().getBaseLocation(),
16979 getDerived().getBaseEntity(),
16980 EPI);
16981}
16982
16983template<typename Derived>
16985 return SemaRef.Context.getFunctionNoProtoType(T);
16986}
16987
16988template<typename Derived>
16990 Decl *D) {
16991 assert(D && "no decl found");
16992 if (D->isInvalidDecl()) return QualType();
16993
16994 // FIXME: Doesn't account for ObjCInterfaceDecl!
16995 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
16996 // A valid resolved using typename pack expansion decl can have multiple
16997 // UsingDecls, but they must each have exactly one type, and it must be
16998 // the same type in every case. But we must have at least one expansion!
16999 if (UPD->expansions().empty()) {
17000 getSema().Diag(Loc, diag::err_using_pack_expansion_empty)
17001 << UPD->isCXXClassMember() << UPD;
17002 return QualType();
17003 }
17004
17005 // We might still have some unresolved types. Try to pick a resolved type
17006 // if we can. The final instantiation will check that the remaining
17007 // unresolved types instantiate to the type we pick.
17008 QualType FallbackT;
17009 QualType T;
17010 for (auto *E : UPD->expansions()) {
17011 QualType ThisT = RebuildUnresolvedUsingType(Loc, E);
17012 if (ThisT.isNull())
17013 continue;
17014 else if (ThisT->getAs<UnresolvedUsingType>())
17015 FallbackT = ThisT;
17016 else if (T.isNull())
17017 T = ThisT;
17018 else
17019 assert(getSema().Context.hasSameType(ThisT, T) &&
17020 "mismatched resolved types in using pack expansion");
17021 }
17022 return T.isNull() ? FallbackT : T;
17023 } else if (auto *Using = dyn_cast<UsingDecl>(D)) {
17024 assert(Using->hasTypename() &&
17025 "UnresolvedUsingTypenameDecl transformed to non-typename using");
17026
17027 // A valid resolved using typename decl points to exactly one type decl.
17028 assert(++Using->shadow_begin() == Using->shadow_end());
17029
17030 UsingShadowDecl *Shadow = *Using->shadow_begin();
17031 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), Loc))
17032 return QualType();
17033 return SemaRef.Context.getUsingType(
17034 Shadow, SemaRef.Context.getTypeDeclType(
17035 cast<TypeDecl>(Shadow->getTargetDecl())));
17036 } else {
17037 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
17038 "UnresolvedUsingTypenameDecl transformed to non-using decl");
17039 return SemaRef.Context.getTypeDeclType(
17040 cast<UnresolvedUsingTypenameDecl>(D));
17041 }
17042}
17043
17044template <typename Derived>
17046 TypeOfKind Kind) {
17047 return SemaRef.BuildTypeofExprType(E, Kind);
17048}
17049
17050template<typename Derived>
17052 TypeOfKind Kind) {
17053 return SemaRef.Context.getTypeOfType(Underlying, Kind);
17054}
17055
17056template <typename Derived>
17058 return SemaRef.BuildDecltypeType(E);
17059}
17060
17061template <typename Derived>
17063 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
17064 SourceLocation EllipsisLoc, bool FullySubstituted,
17065 ArrayRef<QualType> Expansions) {
17066 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
17067 FullySubstituted, Expansions);
17068}
17069
17070template<typename Derived>
17074 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
17075}
17076
17077template<typename Derived>
17079 TemplateName Template,
17080 SourceLocation TemplateNameLoc,
17081 TemplateArgumentListInfo &TemplateArgs) {
17082 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
17083}
17084
17085template<typename Derived>
17087 SourceLocation KWLoc) {
17088 return SemaRef.BuildAtomicType(ValueType, KWLoc);
17089}
17090
17091template<typename Derived>
17093 SourceLocation KWLoc,
17094 bool isReadPipe) {
17095 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
17096 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
17097}
17098
17099template <typename Derived>
17101 unsigned NumBits,
17103 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17104 NumBits, true);
17105 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
17106 SemaRef.Context.IntTy, Loc);
17107 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
17108}
17109
17110template <typename Derived>
17112 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
17113 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
17114}
17115
17116template<typename Derived>
17119 bool TemplateKW,
17120 TemplateDecl *Template) {
17121 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
17122 TemplateName(Template));
17123}
17124
17125template<typename Derived>
17128 SourceLocation TemplateKWLoc,
17129 const IdentifierInfo &Name,
17130 SourceLocation NameLoc,
17131 QualType ObjectType,
17132 NamedDecl *FirstQualifierInScope,
17133 bool AllowInjectedClassName) {
17135 TemplateName.setIdentifier(&Name, NameLoc);
17136 Sema::TemplateTy Template;
17137 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
17138 TemplateName, ParsedType::make(ObjectType),
17139 /*EnteringContext=*/false, Template,
17140 AllowInjectedClassName);
17141 return Template.get();
17142}
17143
17144template<typename Derived>
17147 SourceLocation TemplateKWLoc,
17148 OverloadedOperatorKind Operator,
17149 SourceLocation NameLoc,
17150 QualType ObjectType,
17151 bool AllowInjectedClassName) {
17152 UnqualifiedId Name;
17153 // FIXME: Bogus location information.
17154 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
17155 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
17156 Sema::TemplateTy Template;
17157 getSema().ActOnTemplateName(
17158 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
17159 /*EnteringContext=*/false, Template, AllowInjectedClassName);
17160 return Template.get();
17161}
17162
17163template <typename Derived>
17166 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
17167 Expr *Second) {
17168 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
17169
17170 if (First->getObjectKind() == OK_ObjCProperty) {
17173 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
17174 Opc, First, Second);
17176 if (Result.isInvalid())
17177 return ExprError();
17178 First = Result.get();
17179 }
17180
17181 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
17182 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
17183 if (Result.isInvalid())
17184 return ExprError();
17185 Second = Result.get();
17186 }
17187
17188 // Determine whether this should be a builtin operation.
17189 if (Op == OO_Subscript) {
17190 if (!First->getType()->isOverloadableType() &&
17191 !Second->getType()->isOverloadableType())
17192 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
17193 OpLoc);
17194 } else if (Op == OO_Arrow) {
17195 // It is possible that the type refers to a RecoveryExpr created earlier
17196 // in the tree transformation.
17197 if (First->getType()->isDependentType())
17198 return ExprError();
17199 // -> is never a builtin operation.
17200 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
17201 } else if (Second == nullptr || isPostIncDec) {
17202 if (!First->getType()->isOverloadableType() ||
17203 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
17204 // The argument is not of overloadable type, or this is an expression
17205 // of the form &Class::member, so try to create a built-in unary
17206 // operation.
17208 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17209
17210 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
17211 }
17212 } else {
17213 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
17214 !First->getType()->isOverloadableType() &&
17215 !Second->getType()->isOverloadableType()) {
17216 // Neither of the arguments is type-dependent or has an overloadable
17217 // type, so try to create a built-in binary operation.
17220 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
17221 if (Result.isInvalid())
17222 return ExprError();
17223
17224 return Result;
17225 }
17226 }
17227
17228 // Create the overloaded operator invocation for unary operators.
17229 if (!Second || isPostIncDec) {
17231 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
17232 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
17233 RequiresADL);
17234 }
17235
17236 // Create the overloaded operator invocation for binary operators.
17238 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
17239 First, Second, RequiresADL);
17240 if (Result.isInvalid())
17241 return ExprError();
17242
17243 return Result;
17244}
17245
17246template<typename Derived>
17249 SourceLocation OperatorLoc,
17250 bool isArrow,
17251 CXXScopeSpec &SS,
17252 TypeSourceInfo *ScopeType,
17253 SourceLocation CCLoc,
17254 SourceLocation TildeLoc,
17255 PseudoDestructorTypeStorage Destroyed) {
17256 QualType BaseType = Base->getType();
17257 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
17258 (!isArrow && !BaseType->getAs<RecordType>()) ||
17259 (isArrow && BaseType->getAs<PointerType>() &&
17260 !BaseType->castAs<PointerType>()->getPointeeType()
17261 ->template getAs<RecordType>())){
17262 // This pseudo-destructor expression is still a pseudo-destructor.
17263 return SemaRef.BuildPseudoDestructorExpr(
17264 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
17265 CCLoc, TildeLoc, Destroyed);
17266 }
17267
17268 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
17270 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
17271 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
17272 NameInfo.setNamedTypeInfo(DestroyedType);
17273
17274 // The scope type is now known to be a valid nested name specifier
17275 // component. Tack it on to the end of the nested name specifier.
17276 if (ScopeType) {
17277 if (!ScopeType->getType()->getAs<TagType>()) {
17278 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
17279 diag::err_expected_class_or_namespace)
17280 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
17281 return ExprError();
17282 }
17283 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
17284 CCLoc);
17285 }
17286
17287 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
17288 return getSema().BuildMemberReferenceExpr(Base, BaseType,
17289 OperatorLoc, isArrow,
17290 SS, TemplateKWLoc,
17291 /*FIXME: FirstQualifier*/ nullptr,
17292 NameInfo,
17293 /*TemplateArgs*/ nullptr,
17294 /*S*/nullptr);
17295}
17296
17297template<typename Derived>
17300 SourceLocation Loc = S->getBeginLoc();
17301 CapturedDecl *CD = S->getCapturedDecl();
17302 unsigned NumParams = CD->getNumParams();
17303 unsigned ContextParamPos = CD->getContextParamPosition();
17305 for (unsigned I = 0; I < NumParams; ++I) {
17306 if (I != ContextParamPos) {
17307 Params.push_back(
17308 std::make_pair(
17309 CD->getParam(I)->getName(),
17310 getDerived().TransformType(CD->getParam(I)->getType())));
17311 } else {
17312 Params.push_back(std::make_pair(StringRef(), QualType()));
17313 }
17314 }
17315 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
17316 S->getCapturedRegionKind(), Params);
17317 StmtResult Body;
17318 {
17319 Sema::CompoundScopeRAII CompoundScope(getSema());
17320 Body = getDerived().TransformStmt(S->getCapturedStmt());
17321 }
17322
17323 if (Body.isInvalid()) {
17324 getSema().ActOnCapturedRegionError();
17325 return StmtError();
17326 }
17327
17328 return getSema().ActOnCapturedRegionEnd(Body.get());
17329}
17330
17331template <typename Derived>
17332ExprResult TreeTransform<Derived>::TransformHLSLOutArgExpr(HLSLOutArgExpr *E) {
17333 // We can transform the base expression and allow argument resolution to fill
17334 // in the rest.
17335 return getDerived().TransformExpr(E->getArgLValue());
17336}
17337
17338} // end namespace clang
17339
17340#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
MatchType Type
const Decl * D
Expr * E
unsigned OldSize
static Decl::Kind getKind(const Decl *D)
Definition: DeclBase.cpp:1172
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines Expressions and AST nodes for C++2a concepts.
int Priority
Definition: Format.cpp:3055
unsigned Iter
Definition: HTMLLogger.cpp:153
#define X(type, name)
Definition: Value.h:144
llvm::MachO::Target Target
Definition: MachO.h:51
llvm::MachO::Record Record
Definition: MachO.h:31
This file defines OpenMP AST classes for clauses.
Defines some OpenMP-specific enums and functions.
uint32_t Id
Definition: SemaARM.cpp:1134
SourceRange Range
Definition: SemaObjC.cpp:758
SourceLocation Loc
Definition: SemaObjC.cpp:759
This file declares semantic analysis for Objective-C.
This file declares semantic analysis for OpenACC constructs and clauses.
This file declares semantic analysis for OpenMP constructs and clauses.
This file declares semantic analysis for expressions involving.
This file declares semantic analysis for SYCL constructs.
Defines the Objective-C statement AST node classes.
This file defines OpenACC AST classes for statement-level contructs.
This file defines OpenMP AST classes for executable directives and clauses.
static QualType getPointeeType(const MemRegion *R)
SourceLocation Begin
std::string Label
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1141
unsigned getIntWidth(QualType T) const
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, ConceptDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgumentLoc > Args) const
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:684
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2716
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2732
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex, SubstTemplateTypeParmTypeFlag Flag=SubstTemplateTypeParmTypeFlag::None) const
Retrieve a substitution-result type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1703
IdentifierTable & Idents
Definition: ASTContext.h:680
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
CanQualType UnsignedLongTy
Definition: ASTContext.h:1170
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
CanQualType IntTy
Definition: ASTContext.h:1169
CanQualType PseudoObjectTy
Definition: ASTContext.h:1191
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2289
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
CanQualType UnsignedInt128Ty
Definition: ASTContext.h:1171
CanQualType BuiltinFnTy
Definition: ASTContext.h:1190
CanQualType UnsignedCharTy
Definition: ASTContext.h:1170
CanQualType UnsignedIntTy
Definition: ASTContext.h:1170
CanQualType UnsignedLongLongTy
Definition: ASTContext.h:1171
CanQualType UnsignedShortTy
Definition: ASTContext.h:1170
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
QualType getHLSLAttributedResourceType(QualType Wrapped, QualType Contained, const HLSLAttributedResourceType::Attributes &Attrs)
QualType getAddrSpaceQualType(QualType T, LangAS AddressSpace) const
Return the uniqued reference to the type for an address space qualified type with the specified type ...
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
QualType getConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns) const
Return the unique reference to the matrix type of the specified element type and size.
PtrTy get() const
Definition: Ownership.h:170
bool isInvalid() const
Definition: Ownership.h:166
bool isUsable() const
Definition: Ownership.h:168
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2853
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:2665
TypeLoc getValueLoc() const
Definition: TypeLoc.h:2641
SourceLocation getKWLoc() const
Definition: TypeLoc.h:2649
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:2657
Attr - This represents one attribute.
Definition: Attr.h:43
attr::Kind getKind() const
Definition: Attr.h:89
Represents an attribute applied to a statement.
Definition: Stmt.h:2107
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:6556
ArrayRef< TemplateArgument > getTypeConstraintArguments() const
Definition: Type.h:6566
ConceptDecl * getTypeConstraintConcept() const
Definition: Type.h:6571
AutoTypeKeyword getKeyword() const
Definition: Type.h:6587
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition: Expr.cpp:2189
bool isAssignmentOp() const
Definition: Expr.h:4048
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:2151
void setIsVariadic(bool value)
Definition: Decl.h:4550
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5298
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.h:5317
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.h:5316
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1491
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1546
SourceRange getParenOrBraceRange() const
Definition: ExprCXX.h:1714
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition: ExprCXX.h:1689
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition: ExprCXX.h:1639
SourceLocation getEndLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:568
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: ExprCXX.cpp:562
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition: ExprCXX.h:1628
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition: ExprCXX.h:1686
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2553
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:1018
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1737
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
unsigned getLambdaDependencyKind() const
Definition: DeclCXX.h:1871
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2182
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:74
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:236
SourceRange getRange() const
Definition: DeclSpec.h:80
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition: DeclSpec.cpp:101
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition: DeclSpec.cpp:149
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:95
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:240
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:111
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
Definition: DeclSpec.cpp:51
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:129
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:797
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3557
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1492
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4673
unsigned getNumParams() const
Definition: Decl.h:4715
unsigned getContextParamPosition() const
Definition: Decl.h:4744
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4717
This captures a statement into a function.
Definition: Stmt.h:3784
Expr * getSubExpr()
Definition: Expr.h:3597
SourceLocation getBegin() const
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1628
Declaration of a C++20 concept.
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:87
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:421
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1368
reference front() const
Definition: DeclBase.h:1391
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1435
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1854
void addDecl(Decl *D)
Add the declaration D into this context.
Definition: DeclBase.cpp:1768
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1519
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:438
bool isInvalidDecl() const
Definition: DeclBase.h:591
SourceLocation getLocation() const
Definition: DeclBase.h:442
DeclContext * getDeclContext()
Definition: DeclBase.h:451
AccessSpecifier getAccess() const
Definition: DeclBase.h:510
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:434
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
DeclarationName getCXXSpecialName(DeclarationName::NameKind Kind, CanQualType Ty)
Returns a declaration name for special kind of C++ name, e.g., for a constructor, destructor,...
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
The name of a declaration.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition: Decl.h:777
TypeSourceInfo * getTypeSourceInfo() const
Definition: Decl.h:764
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1903
QualType getDeducedType() const
Get the type deduced for this placeholder type, or null if it has not been deduced.
Definition: Type.h:6543
bool isDeduced() const
Definition: Type.h:6544
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3323
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:548
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2503
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:2527
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2523
SourceLocation getTemplateKeywordLoc() const
Definition: TypeLoc.h:2519
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2491
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2547
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2487
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2539
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2555
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2531
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:7076
Designation - Represent a full designation, which is a sequence of designators.
Definition: Designator.h:208
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
Definition: Designator.h:172
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
Definition: Designator.h:142
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Designator.h:115
bool hasErrorOccurred() const
Definition: Diagnostic.h:866
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition: Type.h:4823
Expr * getCondition() const
Definition: Type.h:4830
SourceLocation getElaboratedKeywordLoc() const
Definition: TypeLoc.h:2350
NestedNameSpecifierLoc getQualifierLoc() const
Definition: TypeLoc.h:2362
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2354
TypeLoc getNamedTypeLoc() const
Definition: TypeLoc.h:2392
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2368
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6943
RAII object that enters a new expression evaluation context.
Represents an enum.
Definition: Decl.h:3847
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition: Expr.h:3821
This represents one expression.
Definition: Expr.h:110
bool isGLValue() const
Definition: Expr.h:280
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:277
QualType getType() const
Definition: Expr.h:142
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition: Expr.h:516
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition: Expr.h:427
Represents difference between two FPOptions values.
Definition: LangOptions.h:978
Represents a member of a struct/union/class.
Definition: Decl.h:3033
Represents a function declaration or definition.
Definition: Decl.h:1935
QualType getReturnType() const
Definition: Decl.h:2720
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2649
QualType getCallResultType() const
Determine the type of an expression that calls this function.
Definition: Decl.h:2756
Represents an abstract function effect, using just an enumeration describing its kind.
Definition: Type.h:4716
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition: Type.cpp:5223
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition: Type.cpp:5209
ArrayRef< EffectConditionExpr > conditions() const
Definition: Type.h:4937
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4681
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5102
QualType desugar() const
Definition: Type.h:5646
param_type_iterator param_type_begin() const
Definition: Type.h:5515
const ExtParameterInfo * getExtParameterInfosOrNull() const
Return a pointer to the beginning of the array of extra parameter information, if present,...
Definition: Type.h:5553
bool hasTrailingReturn() const
Whether this function prototype has a trailing return type.
Definition: Type.h:5495
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5366
ArrayRef< QualType > getParamTypes() const
Definition: Type.h:5362
unsigned getNumParams() const
Definition: TypeLoc.h:1531
SourceLocation getLocalRangeEnd() const
Definition: TypeLoc.h:1483
void setLocalRangeBegin(SourceLocation L)
Definition: TypeLoc.h:1479
void setLParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1495
SourceRange getExceptionSpecRange() const
Definition: TypeLoc.h:1511
void setParam(unsigned i, ParmVarDecl *VD)
Definition: TypeLoc.h:1538
ArrayRef< ParmVarDecl * > getParams() const
Definition: TypeLoc.h:1522
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:1503
void setLocalRangeEnd(SourceLocation L)
Definition: TypeLoc.h:1487
void setExceptionSpecRange(SourceRange R)
Definition: TypeLoc.h:1517
TypeLoc getReturnLoc() const
Definition: TypeLoc.h:1540
SourceLocation getLocalRangeBegin() const
Definition: TypeLoc.h:1475
SourceLocation getLParenLoc() const
Definition: TypeLoc.h:1491
SourceLocation getRParenLoc() const
Definition: TypeLoc.h:1499
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition: Type.h:4347
QualType getReturnType() const
Definition: Type.h:4643
AssociationTy< false > Association
Definition: Expr.h:6197
One of these records is kept for each identifier that is lexed.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3724
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5841
const TypeClass * getTypePtr() const
Definition: TypeLoc.h:514
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:973
Represents the declaration of a label.
Definition: Decl.h:503
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1954
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition: ExprCXX.h:2019
Represents the results of name lookup.
Definition: Lookup.h:46
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
Definition: Lookup.h:63
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition: Lookup.h:68
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition: Lookup.h:73
@ NotFound
No entity found met the criteria.
Definition: Lookup.h:50
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition: Lookup.h:55
@ Found
Name lookup found a single declaration that met the criteria.
Definition: Lookup.h:59
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition: Lookup.h:605
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:475
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:362
void resolveKind()
Resolves the result kind of the lookup, possibly hiding decls.
Definition: SemaLookup.cpp:484
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Lookup.h:664
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Lookup.h:575
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Lookup.h:265
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4734
This represents a decl that may have a name.
Definition: Decl.h:253
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:466
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:274
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:280
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:319
Represents a C++ namespace alias.
Definition: DeclCXX.h:3138
Represent a C++ namespace.
Definition: Decl.h:551
A C++ nested-name-specifier augmented with source location information.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
void * getOpaqueData() const
Retrieve the opaque pointer that refers to source-location data.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
This is a basic class for representing single OpenMP clause.
Definition: OpenMPClause.h:55
This is a basic class for representing single OpenMP executable directive.
Definition: StmtOpenMP.h:266
This represents clauses with a list of expressions that are mappable.
This represents '#pragma omp metadirective' directive.
Definition: StmtOpenMP.h:6064
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1951
@ SuperInstance
The receiver is the instance of the superclass object.
Definition: ExprObjC.h:955
@ Instance
The receiver is an object instance.
Definition: ExprObjC.h:949
@ SuperClass
The receiver is a superclass.
Definition: ExprObjC.h:952
@ Class
The receiver is a class.
Definition: ExprObjC.h:946
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
bool isInstanceMethod() const
Definition: DeclObjC.h:426
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition: ExprObjC.h:617
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
@ Array
An index into an array.
Definition: Expr.h:2418
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2422
@ Field
A field.
Definition: Expr.h:2420
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2425
Wrapper for void* pointer.
Definition: Ownership.h:50
PtrTy get() const
Definition: Ownership.h:80
static OpaquePtr make(QualType P)
Definition: Ownership.h:60
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1173
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition: Expr.h:1223
static OpenACCAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCAttachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCAutoClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
This is the base type for all OpenACC Clauses.
Definition: OpenACCClause.h:24
static OpenACCCollapseClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, bool HasForce, Expr *LoopCount, SourceLocation EndLoc)
static OpenACCCopyClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyInClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsReadOnly, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyOutClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCreateClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, bool IsZero, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDefaultAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCDefaultClause * Create(const ASTContext &C, OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static OpenACCDeleteClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDetachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceNumClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCDevicePtrClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceTypeClause * Create(const ASTContext &C, OpenACCClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< DeviceTypeArgument > Archs, SourceLocation EndLoc)
static OpenACCFinalizeClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCFirstPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCIfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCIfPresentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCIndependentClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCNoCreateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCNumGangsClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > IntExprs, SourceLocation EndLoc)
static OpenACCNumWorkersClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCPresentClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCPrivateClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCSelfClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *ConditionExpr, SourceLocation EndLoc)
static OpenACCSeqClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation EndLoc)
static OpenACCTileClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > SizeExprs, SourceLocation EndLoc)
static OpenACCUseDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCVectorClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCVectorLengthClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCWaitClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation EndLoc)
static OpenACCWorkerClause * Create(const ASTContext &Ctx, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition: ExprCXX.h:2983
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition: ExprCXX.h:3135
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition: ExprCXX.h:3117
SourceLocation getNameLoc() const
Gets the location of the name.
Definition: ExprCXX.h:3096
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition: ExprCXX.h:3109
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition: ExprCXX.h:3105
TemplateArgumentLoc const * getTemplateArgs() const
Definition: ExprCXX.h:3137
llvm::iterator_range< decls_iterator > decls() const
Definition: ExprCXX.h:3082
unsigned getNumTemplateArgs() const
Definition: ExprCXX.h:3143
DeclarationName getName() const
Gets the name looked up.
Definition: ExprCXX.h:3093
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition: ExprCXX.h:3125
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition: ExprCXX.h:3132
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4180
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2613
SourceLocation getEllipsisLoc() const
Definition: TypeLoc.h:2609
TypeLoc getPatternLoc() const
Definition: TypeLoc.h:2625
Represents a pack expansion of types.
Definition: Type.h:7141
std::optional< unsigned > getNumExpansions() const
Retrieve the number of expansions that this pack expansion will generate, if known.
Definition: Type.h:7166
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2170
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition: Expr.h:2195
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition: Expr.h:2199
Represents a parameter to a function.
Definition: Decl.h:1725
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition: Decl.h:1785
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1758
static ParmVarDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
Definition: Decl.cpp:2922
unsigned getFunctionScopeDepth() const
Definition: Decl.h:1775
void setSigilLoc(SourceLocation Loc)
Definition: TypeLoc.h:1309
TypeLoc getPointeeLoc() const
Definition: TypeLoc.h:1313
SourceLocation getSigilLoc() const
Definition: TypeLoc.h:1305
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3198
QualType getPointeeType() const
Definition: Type.h:3208
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2566
const IdentifierInfo * getIdentifier() const
Definition: ExprCXX.h:2586
SourceLocation getLocation() const
Definition: ExprCXX.h:2590
TypeSourceInfo * getTypeSourceInfo() const
Definition: ExprCXX.h:2582
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7931
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Definition: Type.h:7971
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
Definition: Type.h:8025
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7963
Represents a template name as written in source code.
Definition: TemplateName.h:491
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition: TypeLoc.h:289
The collection of all-type qualifiers we support.
Definition: Type.h:324
void removeObjCLifetime()
Definition: Type.h:544
bool hasRestrict() const
Definition: Type.h:470
static Qualifiers fromCVRMask(unsigned CVR)
Definition: Type.h:428
bool hasObjCLifetime() const
Definition: Type.h:537
bool empty() const
Definition: Type.h:640
LangAS getAddressSpace() const
Definition: Type.h:564
Represents a struct/union/class.
Definition: Decl.h:4148
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6072
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3439
QualType getPointeeTypeAsWritten() const
Definition: Type.h:3455
Represents the body of a requires-expression.
Definition: DeclCXX.h:2047
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition: DeclCXX.cpp:2268
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
Definition: ExprConcepts.h:502
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition: Stmt.cpp:1282
Represents a __leave statement.
Definition: Stmt.h:3745
Smart pointer class that efficiently represents Objective-C method names.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:60
VarDecl * BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id, bool Invalid=false)
Build a type-check a new Objective-C exception variable declaration.
StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, Expr *collection, SourceLocation RParenLoc)
Definition: SemaObjC.cpp:36
StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body)
FinishObjCForCollectionStmt - Attach the body to a objective-C foreach statement.
Definition: SemaObjC.cpp:198
ExprResult BuildObjCDictionaryLiteral(SourceRange SR, MutableArrayRef< ObjCDictionaryElement > Elements)
ExprResult BuildInstanceMessage(Expr *Receiver, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C instance message expression.
QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc, bool FailOnError=false)
Build an Objective-C type parameter type.
Definition: SemaObjC.cpp:485
ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, QualType ReceiverType, SourceLocation SuperLoc, Selector Sel, ObjCMethodDecl *Method, SourceLocation LBracLoc, ArrayRef< SourceLocation > SelectorLocs, SourceLocation RBracLoc, MultiExprArg Args, bool isImplicit=false)
Build an Objective-C class message expression.
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
Definition: SemaObjC.cpp:325
ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, TypeSourceInfo *EncodedTypeInfo, SourceLocation RParenLoc)
ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements)
ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the '@' prefixed parenthesized expression.
StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, MultiStmtArg Catch, Stmt *Finally)
Definition: SemaObjC.cpp:223
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Definition: SemaObjC.cpp:218
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
Definition: SemaObjC.cpp:243
QualType BuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc, bool FailOnError, bool Rebuilding)
Build an Objective-C object pointer type.
Definition: SemaObjC.cpp:712
ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *operand)
Definition: SemaObjC.cpp:287
ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, ObjCBridgeCastKind Kind, SourceLocation BridgeKeywordLoc, TypeSourceInfo *TSInfo, Expr *SubExpr)
StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, Decl *Parm, Stmt *Body)
Definition: SemaObjC.cpp:207
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Definition: SemaObjC.cpp:334
ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, Expr *IndexExpr, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
Build an ObjC subscript pseudo-object expression, given that that's supported by the runtime.
ArrayRef< Expr * > getQueueIdExprs() const
Definition: SemaOpenACC.h:338
OpenACCDirectiveKind getDirectiveKind() const
Definition: SemaOpenACC.h:260
void setLParenLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:463
void setConditionDetails(Expr *ConditionExpr)
Definition: SemaOpenACC.h:472
void setCollapseDetails(bool IsForce, Expr *LoopCount)
Definition: SemaOpenACC.h:630
OpenACCClauseKind getClauseKind() const
Definition: SemaOpenACC.h:262
SourceLocation getLParenLoc() const
Definition: SemaOpenACC.h:266
SourceLocation getBeginLoc() const
Definition: SemaOpenACC.h:264
void setDefaultDetails(OpenACCDefaultClauseKind DefKind)
Definition: SemaOpenACC.h:466
SourceLocation getQueuesLoc() const
Definition: SemaOpenACC.h:318
void setVarListDetails(ArrayRef< Expr * > VarList, bool IsReadOnly, bool IsZero)
Definition: SemaOpenACC.h:532
void setWaitDetails(Expr *DevNum, SourceLocation QueuesLoc, llvm::SmallVector< Expr * > &&IntExprs)
Definition: SemaOpenACC.h:616
void setEndLoc(SourceLocation EndLoc)
Definition: SemaOpenACC.h:464
void setIntExprDetails(ArrayRef< Expr * > IntExprs)
Definition: SemaOpenACC.h:486
OpenACCDefaultClauseKind getDefaultClauseKind() const
Definition: SemaOpenACC.h:270
void ActOnWhileStmt(SourceLocation WhileLoc)
StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation MiscLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssocStmt)
Called after the directive has been completely parsed, including the declaration group or associated ...
ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
void ActOnDoStmt(SourceLocation DoLoc)
void ActOnRangeForStmtBegin(SourceLocation ForLoc, const Stmt *OldRangeFor, const Stmt *RangeFor)
void ActOnForStmtEnd(SourceLocation ForLoc, StmtResult Body)
void ActOnForStmtBegin(SourceLocation ForLoc, const Stmt *First, const Stmt *Second, const Stmt *Third)
ExprResult ActOnArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, Expr *Length, SourceLocation RBLoc)
Checks and creates an Array Section used in an OpenACC construct/clause.
OMPClause * ActOnOpenMPNocontextClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nocontext' clause.
OMPClause * ActOnOpenMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_dyn_cgroup_mem' clause.
OMPClause * ActOnOpenMPSafelenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'safelen' clause.
OMPClause * ActOnOpenMPHoldsClause(Expr *E, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'holds' clause.
OMPClause * ActOnOpenMPDefaultClause(llvm::omp::DefaultKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'default' clause.
OMPClause * ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'filter' clause.
OMPClause * ActOnOpenMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on well-form 'full' clauses.
OMPClause * ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'detach' clause.
OMPClause * ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'use' clause.
OMPClause * ActOnOpenMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'to' clause.
OMPClause * ActOnOpenMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'private' clause.
OMPClause * ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc=SourceLocation(), Expr *NumForLoops=nullptr)
Called on well-formed 'ordered' clause.
OMPClause * ActOnOpenMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'is_device_ptr' clause.
OMPClause * ActOnOpenMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'has_device_addr' clause.
OMPClause * ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'partial' clauses.
OMPClause * ActOnOpenMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'lastprivate' clause.
OMPClause * ActOnOpenMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'firstprivate' clause.
OMPClause * ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'priority' clause.
OMPClause * ActOnOpenMPAllocateClause(Expr *Allocator, OpenMPAllocateClauseModifier ACModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' clause.
OMPClause * ActOnOpenMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'dist_schedule' clause.
OMPClause * ActOnOpenMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'permutation' clause after parsing its arguments.
OMPClause * ActOnOpenMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'nontemporal' clause.
OMPClause * ActOnOpenMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'from' clause.
OMPClause * ActOnOpenMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'bind' clause.
OMPClause * ActOnOpenMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'thread_limit' clause.
OMPClause * ActOnOpenMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'shared' clause.
OMPClause * ActOnOpenMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyin' clause.
OMPClause * ActOnOpenMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'destroy' clause.
OMPClause * ActOnOpenMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Called on well-formed 'affinity' clause.
OMPClause * ActOnOpenMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' clause.
OMPClause * ActOnOpenMPDependClause(const OMPDependClause::DependDataTy &Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depend' clause.
OMPClause * ActOnOpenMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'doacross' clause.
OMPClause * ActOnOpenMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'grainsize' clause.
ExprResult ActOnOMPArraySectionExpr(Expr *Base, SourceLocation LBLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBLoc)
ExprResult ActOnOMPIteratorExpr(Scope *S, SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< OMPIteratorData > Data)
OMPClause * ActOnOpenMPUsesAllocatorClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, ArrayRef< UsesAllocatorsData > Data)
Called on well-formed 'uses_allocators' clause.
OMPClause * ActOnOpenMPAllocatorClause(Expr *Allocator, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocator' clause.
OMPClause * ActOnOpenMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'inclusive' clause.
OMPClause * ActOnOpenMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'task_reduction' clause.
OMPClause * ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, OpenMPOrderClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'order' clause.
OMPClause * ActOnOpenMPReductionClause(ArrayRef< Expr * > VarList, OpenMPReductionClauseModifier Modifier, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'reduction' clause.
OMPClause * ActOnOpenMPSizesClause(ArrayRef< Expr * > SizeExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'sizes' clause.
OMPClause * ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'device' clause.
OMPClause * ActOnOpenMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_threads' clause.
OMPClause * ActOnOpenMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'in_reduction' clause.
OMPClause * ActOnOpenMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'flush' pseudo clause.
StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
OMPClause * ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'message' clause.
OMPClause * ActOnOpenMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'schedule' clause.
OMPClause * ActOnOpenMPSimdlenClause(Expr *Length, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'simdlen' clause.
OMPClause * ActOnOpenMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_ptr' clause.
OMPClause * ActOnOpenMPProcBindClause(llvm::omp::ProcBindKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'proc_bind' clause.
OMPClause * ActOnOpenMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_bare' clause.
StmtResult ActOnOpenMPInformationalDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Process an OpenMP informational directive.
StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt)
Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to an OpenMP loop directive.
OMPClause * ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'hint' clause.
ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > Brackets)
OMPClause * ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'at' clause.
OMPClause * ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'init' clause.
OMPClause * ActOnOpenMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_addr' clause.
OMPClause * ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'final' clause.
OMPClause * ActOnOpenMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, bool NoDiagnose=false, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'map' clause.
OMPClause * ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_tasks' clause.
OMPClause * ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'severity' clause.
OMPClause * ActOnOpenMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind LinKind, SourceLocation LinLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc)
Called on well-formed 'linear' clause.
OMPClause * ActOnOpenMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'defaultmap' clause.
OMPClause * ActOnOpenMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'aligned' clause.
OMPClause * ActOnOpenMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depobj' pseudo clause.
OMPClause * ActOnOpenMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'novariants' clause.
OMPClause * ActOnOpenMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'copyprivate' clause.
OMPClause * ActOnOpenMPCollapseClause(Expr *NumForLoops, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'collapse' clause.
OMPClause * ActOnOpenMPAlignClause(Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'align' clause.
OMPClause * ActOnOpenMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on a well-formed 'ompx_attribute' clause.
OMPClause * ActOnOpenMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'exclusive' clause.
OMPClause * ActOnOpenMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Called on well-formed 'if' clause.
ExprResult checkAssignment(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opcode, Expr *LHS, Expr *RHS)
Expr * recreateSyntacticForm(PseudoObjectExpr *E)
Given a pseudo-object expression, recreate what it looks like syntactically without the attendant Opa...
ExprResult checkRValue(Expr *E)
ExprResult BuildUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition: SemaSYCL.cpp:139
RAII object used to change the argument pack substitution index within a Sema object.
Definition: Sema.h:13212
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition: Sema.h:8048
A RAII object to enter scope of a compound statement.
Definition: Sema.h:916
A helper class for building up ExtParameterInfos.
Definition: Sema.h:12614
const FunctionProtoType::ExtParameterInfo * getPointerOrNull(unsigned numParams)
Return a pointer (suitable for setting in an ExtProtoInfo) to the ExtParameterInfo array we've built ...
Definition: Sema.h:12633
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition: Sema.h:12621
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition: Sema.h:13581
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:464
QualType BuildParenType(QualType T)
Build a paren type including T.
Definition: SemaType.cpp:1674
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
Definition: SemaType.cpp:6394
QualType getCurrentThisType()
Try to retrieve the type of the 'this' pointer.
bool CheckSpecifiedExceptionType(QualType &T, SourceRange Range)
CheckSpecifiedExceptionType - Check if the given type is valid in an exception specification.
ExprResult BuildOperatorCoawaitCall(SourceLocation Loc, Expr *E, UnresolvedLookupExpr *Lookup)
Build a call to 'operator co_await' if there is a suitable operator for the given expression.
ExprResult BuildMemberReferenceExpr(Expr *Base, QualType BaseType, SourceLocation OpLoc, bool IsArrow, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, const Scope *S, ActOnMemberAccessExtraArgs *ExtraArgs=nullptr)
StmtResult BuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Definition: SemaStmt.cpp:4433
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:8990
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition: Sema.h:8998
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition: Sema.h:8993
bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend)
Check that the expression co_await promise.final_suspend() shall not be potentially-throwing.
QualType BuildAddressSpaceAttr(QualType &T, LangAS ASIdx, Expr *AddrSpace, SourceLocation AttrLoc)
BuildAddressSpaceAttr - Builds a DependentAddressSpaceType if an expression is uninstantiated.
Definition: SemaType.cpp:6497
ExprResult ActOnConstantExpression(ExprResult Res)
Definition: SemaExpr.cpp:19647
StmtResult ActOnMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef< Token > AsmToks, StringRef AsmString, unsigned NumOutputs, unsigned NumInputs, ArrayRef< StringRef > Constraints, ArrayRef< StringRef > Clobbers, ArrayRef< Expr * > Exprs, SourceLocation EndLoc)
StmtResult BuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs)
ExprResult BuildCoyieldExpr(SourceLocation KwLoc, Expr *E)
static std::enable_if_t< std::is_base_of_v< Attr, AttrInfo >, SourceLocation > getAttrLoc(const AttrInfo &AL)
A helper function to provide Attribute Location for the Attr types AND the ParsedAttr.
Definition: Sema.h:4412
QualType BuildVectorType(QualType T, Expr *VecSize, SourceLocation AttrLoc)
Definition: SemaType.cpp:2326
StmtResult BuildAttributedStmt(SourceLocation AttrsLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: SemaStmt.cpp:642
SemaOpenMP & OpenMP()
Definition: Sema.h:1126
@ IER_DoesNotExist
The symbol does not exist.
Definition: Sema.h:8465
@ IER_Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition: Sema.h:8469
@ IER_Error
An error occurred.
Definition: Sema.h:8472
@ IER_Exists
The symbol exists.
Definition: Sema.h:8462
void ActOnStartStmtExpr()
Definition: SemaExpr.cpp:15840
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, sema::LambdaScopeInfo *LSI)
Complete a lambda-expression having processed and attached the lambda body.
void ActOnStmtExprError()
Definition: SemaExpr.cpp:15846
void MarkDeclarationsReferencedInExpr(Expr *E, bool SkipLocalVariables=false, ArrayRef< const Expr * > StopAt={})
Mark any declarations that appear within this expression or any potentially-evaluated subexpressions ...
Definition: SemaExpr.cpp:20164
std::optional< FunctionEffectMode > ActOnEffectExpression(Expr *CondExpr, StringRef AttributeName)
Try to parse the conditional expression attached to an effect attribute (e.g.
Definition: SemaType.cpp:7624
VarDecl * buildCoroutinePromise(SourceLocation Loc)
ExprResult CheckBooleanCondition(SourceLocation Loc, Expr *E, bool IsConstexpr=false)
CheckBooleanCondition - Diagnose problems involving the use of the given expression as a boolean cond...
Definition: SemaExpr.cpp:20380
ConditionKind
Definition: Sema.h:7351
@ Boolean
A boolean condition, from 'if', 'while', 'for', or 'do'.
@ Switch
An integral condition for a 'switch' statement.
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
Definition: SemaCast.cpp:394
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
Definition: SemaStmt.cpp:3171
ExprResult MaybeBindToTemporary(Expr *E)
MaybeBindToTemporary - If the passed in expression has a record type with a non-trivial destructor,...
StmtResult BuildCoreturnStmt(SourceLocation KwLoc, Expr *E, bool IsImplicit=false)
ExprResult ActOnStartCXXMemberReference(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, ParsedType &ObjectType, bool &MayBePseudoDestructor)
ExprResult ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val)
Definition: SemaStmt.cpp:500
QualType BuildExtVectorType(QualType T, Expr *ArraySize, SourceLocation AttrLoc)
Build an ext-vector type.
Definition: SemaType.cpp:2392
ExprResult ActOnDesignatedInitializer(Designation &Desig, SourceLocation EqualOrColonLoc, bool GNUSyntax, ExprResult Init)
Definition: SemaInit.cpp:3488
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth)
Definition: SemaExpr.cpp:15859
ExprResult BuildOverloadedArrowExpr(Scope *S, Expr *Base, SourceLocation OpLoc, bool *NoArrowOperatorFound=nullptr)
BuildOverloadedArrowExpr - Build a call to an overloaded operator-> (if one exists),...
ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, Expr *Awaiter, bool IsImplicit=false)
SemaSYCL & SYCL()
Definition: Sema.h:1151
ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16502
ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, bool ArrayForm, Expr *Operand)
ActOnCXXDelete - Parsed a C++ 'delete' expression (C++ 5.3.5), as in:
ASTContext & Context
Definition: Sema.h:909
ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a C++ typeid expression with a type operand.
QualType BuildFunctionType(QualType T, MutableArrayRef< QualType > ParamTypes, SourceLocation Loc, DeclarationName Entity, const FunctionProtoType::ExtProtoInfo &EPI)
Build a function type.
Definition: SemaType.cpp:2632
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
DiagnosticsEngine & getDiagnostics() const
Definition: Sema.h:529
concepts::TypeRequirement * BuildTypeRequirement(TypeSourceInfo *Type)
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
SemaObjC & ObjC()
Definition: Sema.h:1111
ExprResult BuildPackIndexingExpr(Expr *PackExpression, SourceLocation EllipsisLoc, Expr *IndexExpr, SourceLocation RSquareLoc, ArrayRef< Expr * > ExpandedExprs={}, bool FullySubstituted=false)
ParsedType getDestructorName(const IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, ParsedType ObjectType, bool EnteringContext)
ASTContext & getASTContext() const
Definition: Sema.h:532
CXXDestructorDecl * LookupDestructor(CXXRecordDecl *Class)
Look for the destructor of the given class.
ExprResult BuildUnaryOp(Scope *S, SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *Input, bool IsAfterAmp=false)
Definition: SemaExpr.cpp:15777
ExprResult BuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
ExprResult CreateOverloadedBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *LHS, Expr *RHS, bool RequiresADL=true, bool AllowRewrittenCandidates=true, FunctionDecl *DefaultedFn=nullptr)
Create a binary operation that may resolve to an overloaded operator.
StmtResult ActOnSEHTryBlock(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
Definition: SemaStmt.cpp:4357
ExprResult ImpCastExprToType(Expr *E, QualType Type, CastKind CK, ExprValueKind VK=VK_PRValue, const CXXCastPath *BasePath=nullptr, CheckedConversionKind CCK=CheckedConversionKind::Implicit)
ImpCastExprToType - If Expr is not of type 'Type', insert an implicit cast.
Definition: Sema.cpp:692
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Definition: SemaExpr.cpp:3486
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
Definition: SemaExpr.cpp:7054
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
Definition: SemaExpr.cpp:15827
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
Definition: SemaExpr.cpp:7909
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
Definition: SemaType.cpp:9563
ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocType, TypeSourceInfo *AllocTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
bool isAcceptableTagRedeclaration(const TagDecl *Previous, TagTypeKind NewTag, bool isDefinition, SourceLocation NewTagLoc, const IdentifierInfo *Name)
Determine whether a tag with a given kind is acceptable as a redeclaration of the given tag declarati...
Definition: SemaDecl.cpp:16951
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
Definition: SemaExpr.cpp:2204
QualType BuildBitIntType(bool IsUnsigned, Expr *BitWidth, SourceLocation Loc)
Build a bit-precise integer type.
Definition: SemaType.cpp:1939
ExprResult ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc)
Definition: SemaExpr.cpp:16115
ExprResult CreateGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool PredicateIsExpr, void *ControllingExprOrType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
ControllingExprOrType is either a TypeSourceInfo * or an Expr *.
Definition: SemaExpr.cpp:1671
QualType BuildQualifiedType(QualType T, SourceLocation Loc, Qualifiers Qs, const DeclSpec *DS=nullptr)
Definition: SemaType.cpp:1580
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Definition: SemaStmt.cpp:1290
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition: Sema.cpp:82
const LangOptions & getLangOpts() const
Definition: Sema.h:525
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:1764
SemaOpenACC & OpenACC()
Definition: Sema.h:1116
@ ReuseLambdaContextDecl
Definition: Sema.h:6531
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, std::optional< unsigned > NumExpansions)
bool isPotentialImplicitMemberAccess(const CXXScopeSpec &SS, LookupResult &R, bool IsAddressOfOperand)
Check whether an expression might be an implicit class member access.
void collectUnexpandedParameterPacks(TemplateArgument Arg, SmallVectorImpl< UnexpandedParameterPack > &Unexpanded)
Collect the set of unexpanded parameter packs within the given template argument.
ExprResult BuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
Definition: SemaExpr.cpp:16776
ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, SourceLocation LParenLoc, MultiExprArg Exprs, SourceLocation RParenLoc, bool ListInitialization)
ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, ArrayRef< OffsetOfComponent > Components, SourceLocation RParenLoc)
__builtin_offsetof(type, a.b[123][456].c)
Definition: SemaExpr.cpp:15929
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Definition: Sema.cpp:2406
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
Definition: SemaInit.cpp:7542
ExprResult ConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
ConvertVectorExpr - Handle __builtin_convertvector.
QualType CheckTypenameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo &II, SourceLocation IILoc, TypeSourceInfo **TSI, bool DeducedTSTContext)
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
DeclContext * getCurLexicalContext() const
Definition: Sema.h:736
ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, UnresolvedLookupExpr *Lookup)
NonTagKind getNonTagTypeDeclKind(const Decl *D, TagTypeKind TTK)
Given a non-tag type declaration, returns an enum useful for indicating what kind of non-tag type thi...
Definition: SemaDecl.cpp:16926
ExprResult BuildExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, Expr *Queried, SourceLocation RParen)
bool buildCoroutineParameterMoves(SourceLocation Loc)
ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, SourceLocation RParenLoc, Expr *Op)
Definition: SemaCast.cpp:3351
ExprResult BuildCXXUuidof(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a Microsoft __uuidof expression with a type operand.
sema::FunctionScopeInfo * getCurFunction() const
Definition: Sema.h:940
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
Definition: SemaDecl.cpp:14909
Expr * BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit)
Build a CXXThisExpr and mark it referenced in the current context.
QualType BuildReferenceType(QualType T, bool LValueRef, SourceLocation Loc, DeclarationName Entity)
Build a reference type.
Definition: SemaType.cpp:1856
ExprResult CreateOverloadedUnaryOp(SourceLocation OpLoc, UnaryOperatorKind Opc, const UnresolvedSetImpl &Fns, Expr *input, bool RequiresADL=true)
Create a unary operation that may resolve to an overloaded operator.
int ArgumentPackSubstitutionIndex
The current index into pack expansion arguments that will be used for substitution of parameter packs...
Definition: Sema.h:13206
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
Definition: SemaExpr.cpp:3189
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition: Sema.cpp:2361
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:1044
VarDecl * BuildExceptionDeclaration(Scope *S, TypeSourceInfo *TInfo, SourceLocation StartLoc, SourceLocation IdLoc, const IdentifierInfo *Id)
Perform semantic analysis for the variable declaration that occurs within a C++ catch clause,...
bool BuildCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, bool EnteringContext, CXXScopeSpec &SS, NamedDecl *ScopeLookupResult, bool ErrorRecoveryLookup, bool *IsCorrectedToColon=nullptr, bool OnlyNamespace=false)
Build a new nested-name-specifier for "identifier::", as described by ActOnCXXNestedNameSpecifier.
void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base=nullptr)
Perform reference-marking and odr-use handling for a DeclRefExpr.
Definition: SemaExpr.cpp:20008
ExprResult BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand, SourceLocation RParen)
ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI=nullptr)
BuildQualifiedDeclarationNameExpr - Build a C++ qualified declaration name, generally during template...
Definition: SemaExpr.cpp:2896
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
Definition: SemaStmt.cpp:2209
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
Definition: SemaStmt.cpp:3186
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
Definition: SemaExpr.cpp:4109
ExprResult CheckPlaceholderExpr(Expr *E)
Check for operands with placeholder types and complain if found.
Definition: SemaExpr.cpp:20964
ExprResult BuildCXXConstructExpr(SourceLocation ConstructLoc, QualType DeclInitType, NamedDecl *FoundDecl, CXXConstructorDecl *Constructor, MultiExprArg Exprs, bool HadMultipleCandidates, bool IsListInitialization, bool IsStdInitListInitialization, bool RequiresZeroInit, CXXConstructionKind ConstructKind, SourceRange ParenRange)
BuildCXXConstructExpr - Creates a complete call to a constructor, including handling of its default a...
NonTagKind
Common ways to introduce type names without a tag for use in diagnostics.
Definition: Sema.h:3842
@ NTK_TypeAliasTemplate
Definition: Sema.h:3850
TryCaptureKind
Definition: Sema.h:6593
@ TryCapture_Implicit
Definition: Sema.h:6594
@ TryCapture_ExplicitByVal
Definition: Sema.h:6595
@ TryCapture_ExplicitByRef
Definition: Sema.h:6596
ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Create a new AsTypeExpr node (bitcast) from the arguments.
Definition: SemaExpr.cpp:6710
ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, FieldDecl *Field, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo)
bool CheckRebuiltStmtAttributes(ArrayRef< const Attr * > Attrs)
ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr)
ActOnConditionalOp - Parse a ?: operation.
Definition: SemaExpr.cpp:8776
QualType BuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted=false, ArrayRef< QualType > Expansions={})
Definition: SemaType.cpp:9685
ExprResult BuildPossibleImplicitMemberExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs, const Scope *S)
Builds an expression which might be an implicit member expression.
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
concepts::ExprRequirement * BuildExprRequirement(Expr *E, bool IsSatisfied, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement ReturnTypeRequirement)
QualType BuildAtomicType(QualType T, SourceLocation Loc)
Definition: SemaType.cpp:9968
QualType CheckTemplateIdType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
void ActOnInitializerError(Decl *Dcl)
ActOnInitializerError - Given that there was an error parsing an initializer for the given declaratio...
Definition: SemaDecl.cpp:13903
bool diagnoseConflictingFunctionEffect(const FunctionEffectsRef &FX, const FunctionEffectWithCondition &EC, SourceLocation NewAttrLoc)
Warn and return true if adding a function effect to a set would create a conflict.
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr, bool SkipTrailingRequiresClause=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics.
Definition: SemaExpr.cpp:216
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
Definition: SemaStmt.cpp:3837
ExprResult BuildPseudoDestructorExpr(Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, const CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage DestroyedType)
QualType BuildPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a pointer type.
Definition: SemaType.cpp:1804
StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt, SourceLocation ColonLoc, Stmt *RangeDecl, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVarDecl, SourceLocation RParenLoc, BuildForRangeKind Kind, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
BuildCXXForRangeStmt - Build or instantiate a C++11 for-range statement.
Definition: SemaStmt.cpp:2637
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
Definition: SemaStmt.cpp:1785
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
Definition: SemaStmt.cpp:1166
ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand)
ExprResult BuiltinShuffleVector(CallExpr *TheCall)
BuiltinShuffleVector - Handle __builtin_shufflevector.
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
QualType BuildDecltypeType(Expr *E, bool AsUnevaluated=true)
If AsUnevaluated is false, E is treated as though it were an evaluated context, such as when building...
Definition: SemaType.cpp:9653
QualType BuildUnaryTransformType(QualType BaseType, UTTKind UKind, SourceLocation Loc)
Definition: SemaType.cpp:9912
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
Definition: SemaStmt.cpp:4395
ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a sizeof or alignof expression given a type operand.
Definition: SemaExpr.cpp:4617
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition: SemaStmt.cpp:76
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
Expr * MaybeCreateExprWithCleanups(Expr *SubExpr)
MaybeCreateExprWithCleanups - If the current full-expression requires any cleanups,...
SmallVector< ExpressionEvaluationContextRecord, 8 > ExprEvalContexts
A stack of expression evaluation contexts.
Definition: Sema.h:7917
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, bool IsThrownVarInScope)
QualType BuildArrayType(QualType T, ArraySizeModifier ASM, Expr *ArraySize, unsigned Quals, SourceRange Brackets, DeclarationName Entity)
Build an array type.
Definition: SemaType.cpp:2047
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Definition: SemaExpr.cpp:5581
QualType BuildReadPipeType(QualType T, SourceLocation Loc)
Build a Read-only Pipe type.
Definition: SemaType.cpp:1931
concepts::NestedRequirement * BuildNestedRequirement(Expr *E)
QualType BuildWritePipeType(QualType T, SourceLocation Loc)
Build a Write-only Pipe type.
Definition: SemaType.cpp:1935
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition: Sema.h:10757
ExprResult CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs)
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition: SemaStmt.cpp:583
ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, Scope *CurScope)
ActOnBlockStmtExpr - This is called when the body of a block statement literal was successfully compl...
Definition: SemaExpr.cpp:16301
QualType BuildTypeofExprType(Expr *E, TypeOfKind Kind)
Definition: SemaType.cpp:9540
ExprResult BuildArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParen)
void MarkMemberReferenced(MemberExpr *E)
Perform reference-marking and odr-use handling for a MemberExpr.
Definition: SemaExpr.cpp:20030
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
Definition: SemaCast.cpp:296
void MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, bool MightBeOdrUse=true)
Mark a function referenced, and check whether it is odr-used (C++ [basic.def.odr]p2,...
Definition: SemaExpr.cpp:18078
QualType BuildMatrixType(QualType T, Expr *NumRows, Expr *NumColumns, SourceLocation AttrLoc)
Definition: SemaType.cpp:2446
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
Definition: SemaExpr.cpp:21161
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
Definition: SemaExpr.cpp:15345
ExprResult PerformObjectMemberConversion(Expr *From, NestedNameSpecifier *Qualifier, NamedDecl *FoundDecl, NamedDecl *Member)
Cast a base object to a member's actual type.
Definition: SemaExpr.cpp:2969
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
Definition: SemaStmt.cpp:953
ExprResult BuildInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, SourceLocation RBraceLoc)
Definition: SemaExpr.cpp:7254
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
Definition: SemaExpr.cpp:16153
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
Definition: SemaExpr.cpp:4829
ExprResult CreateBuiltinBinOp(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr)
CreateBuiltinBinOp - Creates a new built-in binary operation with operator Opc at location TokLoc.
Definition: SemaExpr.cpp:14768
ExprResult BuildAtomicExpr(SourceRange CallRange, SourceRange ExprRange, SourceLocation RParenLoc, MultiExprArg Args, AtomicExpr::AtomicOp Op, AtomicArgumentOrder ArgOrder=AtomicArgumentOrder::API)
ExprResult ActOnCallExpr(Scope *S, Expr *Fn, SourceLocation LParenLoc, MultiExprArg ArgExprs, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
ActOnCallExpr - Handle a call to Fn with the specified array of arguments.
Definition: SemaExpr.cpp:6437
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:2750
static ConditionResult ConditionError()
Definition: Sema.h:7338
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition: SemaStmt.cpp:451
SemaPseudoObject & PseudoObject()
Definition: Sema.h:1136
StmtResult ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, SourceLocation ColonLoc, Stmt *SubStmt)
Definition: SemaStmt.cpp:608
StmtResult ActOnCXXTryBlock(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
ActOnCXXTryBlock - Takes a try compound-statement and a number of handlers and creates a try statemen...
Definition: SemaStmt.cpp:4244
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition: SemaStmt.cpp:588
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
Definition: SemaExpr.cpp:17905
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition: SemaStmt.cpp:552
QualType BuildMemberPointerType(QualType T, QualType Class, SourceLocation Loc, DeclarationName Entity)
Build a member pointer type T Class::*.
Definition: SemaType.cpp:2681
QualType BuildBlockPointerType(QualType T, SourceLocation Loc, DeclarationName Entity)
Build a block pointer type.
Definition: SemaType.cpp:2733
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
Definition: SemaStmt.cpp:3153
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition: Sema.h:8268
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
Definition: SemaExpr.cpp:5006
StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition: ExprCXX.cpp:1693
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition: Expr.h:4870
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
bool isInvalid() const
SourceLocation getEnd() const
SourceLocation getBegin() const
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:357
StmtClass
Definition: Stmt.h:86
@ NoStmtClass
Definition: Stmt.h:87
StmtClass getStmtClass() const
Definition: Stmt.h:1380
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:333
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:345
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:149
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:864
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3564
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
void setLAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:650
void setRAngleLoc(SourceLocation Loc)
Definition: TemplateBase.h:651
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:667
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
const TemplateArgumentLoc * operator->() const
Simple iterator that traverses the template arguments in a container that provides a getArgLoc() memb...
TemplateArgumentLocContainerIterator operator++(int)
friend bool operator!=(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator(ArgLocContainer &Container, unsigned Index)
friend bool operator==(const TemplateArgumentLocContainerIterator &X, const TemplateArgumentLocContainerIterator &Y)
TemplateArgumentLocContainerIterator & operator++()
const TemplateArgumentLoc * operator->() const
Iterator adaptor that invents template argument location information for each of the template argumen...
TemplateArgumentLocInventIterator & operator++()
std::iterator_traits< InputIterator >::difference_type difference_type
TemplateArgumentLocInventIterator operator++(int)
friend bool operator==(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
TemplateArgumentLocInventIterator(TreeTransform< Derived > &Self, InputIterator Iter)
friend bool operator!=(const TemplateArgumentLocInventIterator &X, const TemplateArgumentLocInventIterator &Y)
std::input_iterator_tag iterator_category
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:616
TypeSourceInfo * getTypeSourceInfo() const
Definition: TemplateBase.h:578
SourceRange getSourceRange() const LLVM_READONLY
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:609
Expr * getSourceExpression() const
Definition: TemplateBase.h:584
Represents a template argument.
Definition: TemplateBase.h:61
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
QualType getNonTypeTemplateArgumentType() const
If this is a non-type template argument, get its type.
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:319
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
Definition: TemplateBase.h:363
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:343
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:399
Represents a C++ template name within the type system.
Definition: TemplateName.h:220
bool isNull() const
Determine whether this template name is NULL.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1718
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1694
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1735
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1702
SourceLocation getTemplateNameLoc() const
Definition: TypeLoc.h:1731
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1710
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6661
Wrapper for template type parameters.
Definition: TypeLoc.h:758
The top declaration context.
Definition: Decl.h:84
RAII object that temporarily sets the base location and entity used for reporting diagnostics in type...
TemporaryBase(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
A semantic tree transformation that allows one to transform one abstract syntax tree into another.
ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *object)
Rebuild the operand to an Objective-C @synchronized statement.
OMPClause * RebuildOMPNontemporalClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nontemporal' clause.
StmtResult RebuildOpenACCDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
ExprResult TransformInitializer(Expr *Init, bool NotCopyInit)
Transform the given initializer.
StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new label statement.
StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args)
StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @autoreleasepool statement.
OMPClause * RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'dist_schedule' clause.
ExprResult RebuildUnaryOperator(SourceLocation OpLoc, UnaryOperatorKind Opc, Expr *SubExpr)
Build a new unary operator expression.
OMPClause * RebuildOMPProcBindClause(ProcBindKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'proc_bind' clause.
StmtResult RebuildOMPInformationalDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP informational directive.
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
Build a new C++11 default-initialization expression.
OMPClause * RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'priority' clause.
StmtResult RebuildOpenACCSetConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, TypeSourceInfo *EncodeTypeInfo, SourceLocation RParenLoc)
Build a new Objective-C @encode expression.
StmtResult RebuildOpenACCCombinedConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body)
Alternative implementation of TransformLambdaBody that skips transforming the body.
StmtResult RebuildOpenACCExitDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
StmtResult RebuildOpenACCShutdownConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, SourceLocation OpLoc, bool IsArrow)
Build a new Objective-C "isa" expression.
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @finally statement.
SourceLocation getBaseLocation()
Returns the location of the entity being transformed, if that information was not available elsewhere...
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
Build a new call expression.
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, SourceLocation IvarLoc, bool IsArrow, bool IsFreeIvar)
Build a new Objective-C ivar reference expression.
OMPClause * RebuildOMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'at' clause.
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, bool IsImplicit)
Build a new co_return statement.
OMPClause * RebuildOMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'in_reduction' clause.
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *Init)
Build a new compound literal expression.
ExprResult TransformAddressOfOperand(Expr *E)
The operand of a unary address-of operator has special rules: it's allowed to refer to a non-static m...
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, QualType ThisType, bool isImplicit)
Build a new C++ "this" expression.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(expr) expression.
TreeTransform(Sema &SemaRef)
Initializes a new tree transformer.
QualType RebuildDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const IdentifierInfo *Name, SourceLocation NameLoc, TemplateArgumentListInfo &Args, bool AllowInjectedClassName)
Build a new typename type that refers to a template-id.
QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, SourceLocation AttributeLoc)
Build a new matrix type given the type and dependently-defined dimensions.
QualType RebuildUnaryTransformType(QualType BaseType, UnaryTransformType::UTTKind UKind, SourceLocation Loc)
Build a new unary transform type.
ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, ObjCPropertyDecl *Property, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
void InventTemplateArgumentLoc(const TemplateArgument &Arg, TemplateArgumentLoc &ArgLoc)
Fakes up a TemplateArgumentLoc for a given TemplateArgument.
OMPClause * RebuildOMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'use' clause.
StmtResult RebuildOpenACCEnterDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL)
Transform the given type-with-location into a new type, collecting location information in the given ...
ExprResult RebuildCXXRewrittenBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opcode, const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS)
Build a new rewritten operator expression.
ExprResult TransformUnresolvedLookupExpr(UnresolvedLookupExpr *E, bool IsAddressOfOperand)
ExprResult RebuildSourceLocExpr(SourceLocIdentKind Kind, QualType ResultTy, SourceLocation BuiltinLoc, SourceLocation RPLoc, DeclContext *ParentContext)
Build a new expression representing a call to a source location builtin.
QualType RebuildEnumType(EnumDecl *Enum)
Build a new Enum type.
TemplateName RebuildTemplateName(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final)
Build a new template name given a template template parameter pack and the.
ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Build a new expression pack expansion.
QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL)
Transforms a reference type.
OMPClause * RebuildOMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'message' clause.
ExprResult RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
QualType RebuildTypeOfType(QualType Underlying, TypeOfKind Kind)
Build a new typeof(type) type.
ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, Expr *SubExpr, TypeSourceInfo *TInfo, SourceLocation RParenLoc)
Build a new va_arg expression.
ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, SourceLocation RParenLoc)
Build a new C++ zero-initialization expression.
StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr)
OMPClause * RebuildOMPThreadLimitClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'thread_limit' clause.
StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block)
OMPClause * RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'simdlen' clause.
StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, ArrayRef< Stmt * > Handlers)
Build a new C++ try statement.
StmtDiscardKind
The reason why the value of a statement is not discarded, if any.
ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Operand, UnresolvedLookupExpr *OpCoawaitLookup, bool IsImplicit)
Build a new co_await expression.
bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, unsigned NumInputs, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
ExprResult RebuildDesignatedInitExpr(Designation &Desig, MultiExprArg ArrayExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Build a new designated initializer expression.
OMPClause * RebuildOMPSizesClause(ArrayRef< Expr * > Sizes, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Build a new predefined expression.
QualType RebuildElaboratedType(SourceLocation KeywordLoc, ElaboratedTypeKeyword Keyword, NestedNameSpecifierLoc QualifierLoc, QualType Named)
Build a new qualified name type.
ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ static_cast expression.
StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, Sema::FullExprArg Inc, SourceLocation RParenLoc, Stmt *Body)
Build a new for statement.
StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, bool IsIfExists, NestedNameSpecifierLoc QualifierLoc, DeclarationNameInfo NameInfo, Stmt *Nested)
Build a new C++0x range-based for statement.
ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, SourceLocation RParenLoc, unsigned TemplateDepth)
Build a new GNU statement expression.
QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, SourceLocation KeywordLoc, NestedNameSpecifierLoc QualifierLoc, const IdentifierInfo *Id, SourceLocation IdLoc, bool DeducedTSTContext)
Build a new typename type that refers to an identifier.
QualType RebuildTemplateSpecializationType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &Args)
Build a new template specialization type.
bool TryExpandParameterPacks(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, bool &ShouldExpand, bool &RetainExpansion, std::optional< unsigned > &NumExpansions)
Determine whether we should expand a pack expansion with the given set of parameter packs into separa...
Sema & getSema() const
Retrieves a reference to the semantic analysis object used for this tree transform.
ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new shuffle vector expression.
QualType TransformType(QualType T)
Transforms the given type into another type.
OMPClause * RebuildOMPOrderClause(OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc)
Build a new OpenMP 'order' clause.
QualType RebuildReferenceType(QualType ReferentType, bool LValue, SourceLocation Sigil)
Build a new reference type given the type it references.
ExprResult TransformRequiresTypeParams(SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE, RequiresExprBodyDecl *Body, ArrayRef< ParmVarDecl * > Params, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > &TransParams, Sema::ExtParameterInfoBuilder &PInfos)
Transforms the parameters of a requires expresison into the given vectors.
ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, SourceLocation RBraceLoc)
Build a new initializer list expression.
QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Operand)
Build a new Objective-C @throw statement.
OMPClause * RebuildOMPTaskReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'task_reduction' clause.
StmtResult RebuildOpenACCWaitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef< Expr * > QueueIdExprs, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
OMPClause * RebuildOMPCopyinClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyin' clause.
QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, bool isReadPipe)
Build a new pipe type given its value type.
StmtResult RebuildCaseStmt(SourceLocation CaseLoc, Expr *LHS, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation ColonLoc)
Build a new case statement.
ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, LookupResult &R, bool RequiresADL, const TemplateArgumentListInfo *TemplateArgs)
Build a new template-id expression.
StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, VarDecl *ExceptionDecl, Stmt *Handler)
Build a new C++ catch statement.
OMPClause * RebuildOMPDestroyClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'destroy' clause.
ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec step expression with an expression argument.
ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new address-of-label expression.
ExprResult RebuildCxxSubscriptExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc)
TemplateName TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, SourceLocation NameLoc, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr, bool AllowInjectedClassName=false)
Transform the given template name.
OMPClause * RebuildOMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_bare' clause.
const Attr * TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS, const Attr *A)
ExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, Expr *LHS, SourceLocation ColonLoc, Expr *RHS)
Build a new conditional operator expression.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
Attach body to a C++0x range-based for statement.
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *Object, Stmt *Body)
Build a new Objective-C @synchronized statement.
ExprResult RebuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
TemplateName RebuildTemplateName(CXXScopeSpec &SS, bool TemplateKW, TemplateDecl *Template)
Build a new template name given a nested name specifier, a flag indicating whether the "template" key...
OMPClause * RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'device' clause.
QualType TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, TemplateName Template, CXXScopeSpec &SS)
OMPClause * RebuildOMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'has_device_addr' clause.
QualType RebuildDependentSizedExtVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
void RememberPartiallySubstitutedPack(TemplateArgument Arg)
"Remember" the partially-substituted pack template argument after performing an instantiation that mu...
Decl * TransformDefinition(SourceLocation Loc, Decl *D)
Transform the definition of the given declaration.
OMPClause * RebuildOMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'from' clause.
ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, UnresolvedLookupExpr *Lookup)
Build a new co_await expression.
QualType RebuildTypedefType(TypedefNameDecl *Typedef)
Build a new typedef type.
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result)
Build a new return statement.
TemplateArgument ForgetPartiallySubstitutedPack()
"Forget" about the partially-substituted pack template argument, when performing an instantiation tha...
OMPClause * RebuildOMPNocontextClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nocontext' clause.
ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ reinterpret_cast expression.
QualType RebuildVectorType(QualType ElementType, unsigned NumElements, VectorKind VecKind)
Build a new vector type given the element type and number of elements.
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, TypeSourceInfo *Type, ArrayRef< Sema::OffsetOfComponent > Components, SourceLocation RParenLoc)
Build a new builtin offsetof expression.
QualType RebuildParenType(QualType InnerType)
Build a new parenthesized type.
QualType RebuildRecordType(RecordDecl *Record)
Build a new class/struct/union type.
static StmtResult Owned(Stmt *S)
OMPClause * RebuildOMPReductionClause(ArrayRef< Expr * > VarList, OpenMPReductionClauseModifier Modifier, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'reduction' clause.
OMPClause * RebuildOMPPartialClause(Expr *Factor, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'partial' clause.
OMPClause * RebuildOMPScheduleClause(OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Build a new OpenMP 'schedule' clause.
StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body)
Transform the body of a lambda-expression.
StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, Stmt *TryBlock, Stmt *Handler)
OMPClause * RebuildOMPExclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'exclusive' clause.
QualType RebuildDependentAddressSpaceType(QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc)
Build a new DependentAddressSpaceType or return the pointee type variable with the correct address sp...
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Build a new attributed statement.
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, TemplateArgumentListInfo *TALI)
Build a new Objective-C boxed expression.
OMPClause * RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Build a new OpenMP 'defaultmap' clause.
StmtResult RebuildOpenACCLoopConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr)
Build a new C++ default-argument expression.
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Build a new while statement.
OMPClause * RebuildOMPNumTeamsClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' clause.
ExprResult RebuildImplicitValueInitExpr(QualType T)
Build a new value-initialized expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed)
Transforms the parameters of a function type into the given vectors.
StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, bool IsVolatile, unsigned NumOutputs, unsigned NumInputs, IdentifierInfo **Names, MultiExprArg Constraints, MultiExprArg Exprs, Expr *AsmString, MultiExprArg Clobbers, unsigned NumLabels, SourceLocation RParenLoc)
Build a new inline asm statement.
StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S)
ExprResult RebuildObjCMessageExpr(Expr *Receiver, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance message.
QualType TransformSubstTemplateTypeParmPackType(TypeLocBuilder &TLB, SubstTemplateTypeParmPackTypeLoc TL, bool SuppressObjCLifetime)
ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool RequiresADL)
Build a new expression that references a declaration.
bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, SmallVectorImpl< Expr * > &Outputs, bool *ArgChanged=nullptr)
Transform the given list of expressions.
StmtResult TransformSEHHandler(Stmt *Handler)
NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr)
Transform the given nested-name-specifier with source-location information.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, OverloadedOperatorKind Operator, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the overloaded operator name that is refe...
StmtResult RebuildOpenACCHostDataConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc)
Build a new C++11 decltype type.
OMPClause * RebuildOMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_ptr' clause.
QualType TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, NestedNameSpecifierLoc QualifierLoc)
void ExpandingFunctionParameterPack(ParmVarDecl *Pack)
Note to the derived class when a function parameter pack is being expanded.
void setBase(SourceLocation Loc, DeclarationName Entity)
Sets the "base" location and entity when that information is known based on another transformation.
concepts::TypeRequirement * TransformTypeRequirement(concepts::TypeRequirement *Req)
const Derived & getDerived() const
Retrieves a reference to the derived class.
ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, SourceLocation RParen)
Build a new expression in parentheses.
OMPClause * RebuildOMPNumThreadsClause(Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_threads' clause.
QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new block pointer type given its pointee type.
ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, bool isArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, ValueDecl *Member, NamedDecl *FoundDecl, const TemplateArgumentListInfo *ExplicitTemplateArgs, NamedDecl *FirstQualifierInScope)
Build a new member access expression.
OMPClause * RebuildOMPSharedClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'shared' clause.
ExprResult RebuildCXXConstructExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool RequiresZeroInit, CXXConstructionKind ConstructKind, SourceRange ParenRange)
Build a new object-construction expression.
bool TransformFunctionTypeParams(SourceLocation Loc, ArrayRef< ParmVarDecl * > Params, const QualType *ParamTypes, const FunctionProtoType::ExtParameterInfo *ParamInfos, SmallVectorImpl< QualType > &PTypes, SmallVectorImpl< ParmVarDecl * > *PVars, Sema::ExtParameterInfoBuilder &PInfos)
OMPClause * RebuildOMPLinearClause(ArrayRef< Expr * > VarList, Expr *Step, SourceLocation StartLoc, SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation StepModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'linear' clause.
VarDecl * RebuildExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *Declarator, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id)
Build a new C++ exception declaration.
ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg)
Build a new noexcept expression.
QualType RebuildFunctionProtoType(QualType T, MutableArrayRef< QualType > ParamTypes, const FunctionProtoType::ExtProtoInfo &EPI)
Build a new function type.
ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, Expr *Base, Expr *Key, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc, ArrayRef< Expr * > SubExprs, QualType Type)
ExprResult RebuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, LambdaScopeInfo *LSI)
QualType RebuildIncompleteArrayType(QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new incomplete array type given the element type, size modifier, and index type qualifiers.
TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Build a new template argument pack expansion.
CXXRecordDecl::LambdaDependencyKind ComputeLambdaDependency(LambdaScopeInfo *LSI)
ExprResult RebuildPackIndexingExpr(SourceLocation EllipsisLoc, SourceLocation RSquareLoc, Expr *PackIdExpression, Expr *IndexExpr, ArrayRef< Expr * > ExpandedExprs, bool FullySubstituted=false)
StmtResult RebuildOpenACCInitConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, SourceLocation LParenLoc, Expr *Sub, SourceLocation RParenLoc, bool ListInitialization)
Build a new C++ functional-style cast expression.
TypeSourceInfo * TransformType(TypeSourceInfo *DI)
Transforms the given type-with-location into a new type-with-location.
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, MutableArrayRef< ObjCDictionaryElement > Elements)
Build a new Objective-C dictionary literal.
StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK=SDK_Discarded)
Transform the given statement.
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *Target)
Build a new indirect goto statement.
ExprResult RebuildExtVectorElementExpr(Expr *Base, SourceLocation OpLoc, bool IsArrow, SourceLocation AccessorLoc, IdentifierInfo &Accessor)
Build a new extended vector element access expression.
ExprResult RebuildParenListExpr(SourceLocation LParenLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new expression list in parentheses.
OMPClause * RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocator' clause.
QualType RebuildDependentSizedArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new dependent-sized array type given the element type, size modifier, size expression,...
NamedDecl * TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc)
Transform the given declaration, which was the first part of a nested-name-specifier in a member acce...
OMPClause * RebuildOMPInclusiveClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'inclusive' clause.
StmtResult TransformOMPInformationalDirective(OMPExecutableDirective *S)
This is mostly the same as above, but allows 'informational' class directives when rebuilding the stm...
concepts::ExprRequirement * RebuildExprRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
OMPClause * TransformOMPClause(OMPClause *S)
Transform the given statement.
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc)
Build a new atomic type given its value type.
ExprResult RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS)
Build a new binary operator expression.
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *SubExpr)
Build a new C-style cast expression.
OMPClause * RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
OMPClause * RebuildOMPAllocateClause(Expr *Allocate, OpenMPAllocateClauseModifier ACModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocate' clause.
ExprResult TransformExpr(Expr *E)
Transform the given expression.
bool AlreadyTransformed(QualType T)
Determine whether the given type T has already been transformed.
concepts::TypeRequirement * RebuildTypeRequirement(TypeSourceInfo *T)
ExprResult RebuildOMPIteratorExpr(SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, ArrayRef< SemaOpenMP::OMPIteratorData > Data)
Build a new iterator expression.
ExprResult RebuildSYCLUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
OMPClause * RebuildOMPGrainsizeClause(OpenMPGrainsizeClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'grainsize' clause.
OMPClause * RebuildOMPXDynCGroupMemClause(Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
bool TransformTemplateArguments(InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, bool Uneval=false)
Transform the given set of template arguments.
OMPClause * RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'collapse' clause.
static ExprResult Owned(Expr *E)
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(expr) expression.
OMPClause * RebuildOMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_tasks' clause.
OMPClause * RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depobj' pseudo clause.
ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, Expr *Cond, Expr *LHS, Expr *RHS, SourceLocation RParenLoc)
Build a new __builtin_choose_expr expression.
OMPClause * RebuildOMPAlignClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'align' clause.
ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C class message.
bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, LookupResult &R)
Transform the set of declarations in an OverloadExpr.
ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, SourceLocation LParenOrBraceLoc, MultiExprArg Args, SourceLocation RParenOrBraceLoc, bool ListInitialization)
Build a new object-construction expression.
StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init, SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond, Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps)
Build a new C++0x range-based for statement.
OMPClause * RebuildOMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Num)
Build a new OpenMP 'ordered' clause.
ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result)
Build a new co_yield expression.
QualType RebuildObjCObjectType(QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, ArrayRef< TypeSourceInfo * > TypeArgs, SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, ArrayRef< ObjCProtocolDecl * > Protocols, ArrayRef< SourceLocation > ProtocolLocs, SourceLocation ProtocolRAngleLoc)
Build an Objective-C object type.
llvm::DenseMap< Decl *, Decl * > TransformedLocalDecls
The set of local declarations that have been transformed, for cases where we are forced to build new ...
OMPClause * RebuildOMPNovariantsClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'novariants' clause.
StmtResult RebuildOpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult StrBlock)
ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E)
ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocatedType, TypeSourceInfo *AllocatedTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
Build a new C++ "new" expression.
StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, Stmt *Element, Expr *Collection, SourceLocation RParenLoc, Stmt *Body)
Build a new Objective-C fast enumeration statement.
ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
Build a new (previously unresolved) declaration reference expression.
StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, Stmt *TryBody, MultiStmtArg CatchStmts, Stmt *Finally)
Build a new Objective-C @try statement.
DeclarationName getBaseEntity()
Returns the name of the entity being transformed, if that information was not available elsewhere in ...
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, bool ListInitialization)
Build a new object-construction expression.
ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length, ArrayRef< TemplateArgument > PartialArgs)
Build a new expression to compute the length of a parameter pack.
ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, SourceLocation OpLoc, SourceLocation CalleeLoc, bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First, Expr *Second)
Build a new overloaded operator call expression.
OMPClause * RebuildOMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'use_device_addr' clause.
QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc)
Build a dependent bit-precise int given its value type.
OMPClause * RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'hint' clause.
Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind)
Transform the specified condition.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name, SourceLocation NameLoc, QualType ObjectType, NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the name that is referred to as a templat...
OMPClause * RebuildOMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'severity' clause.
OMPClause * RebuildOMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'firstprivate' clause.
StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, ArrayRef< Token > AsmToks, StringRef AsmString, unsigned NumOutputs, unsigned NumInputs, ArrayRef< StringRef > Constraints, ArrayRef< StringRef > Clobbers, ArrayRef< Expr * > Exprs, SourceLocation EndLoc)
Build a new MS style inline asm statement.
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, TemplateName Template)
VarDecl * RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *TInfo, QualType T)
Rebuild an Objective-C exception declaration.
concepts::NestedRequirement * TransformNestedRequirement(concepts::NestedRequirement *Req)
QualType RebuildConstantArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new constant array type given the element type, size modifier, (known) size of the array,...
ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > BracketsRanges)
Build a new array shaping expression.
ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, bool IsGlobalDelete, bool IsArrayForm, Expr *Operand)
Build a new C++ "delete" expression.
bool TransformExceptionSpec(SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, SmallVectorImpl< QualType > &Exceptions, bool &Changed)
QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, SourceLocation StartLoc, TypeSourceInfo *TSInfo, Expr *DimExpr, SourceLocation RParenLoc)
Build a new array type trait expression.
OMPClause * RebuildOMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'is_device_ptr' clause.
QualType RebuildMacroQualifiedType(QualType T, const IdentifierInfo *MacroII)
Build a new MacroDefined type.
concepts::NestedRequirement * RebuildNestedRequirement(Expr *Constraint)
ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBracketLoc)
Build a new matrix subscript expression.
ExprResult TransformParenDependentScopeDeclRefExpr(ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
TemplateParameterList * TransformTemplateParameterList(TemplateParameterList *TPL)
QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the class type it refers into.
void transformAttrs(Decl *Old, Decl *New)
Transform the attributes associated with the given declaration and place them on the new declaration.
Decl * TransformDecl(SourceLocation Loc, Decl *D)
Transform the given declaration, which is referenced from a type or expression.
bool AlwaysRebuild()
Whether the transformation should always rebuild AST nodes, even if none of the children have changed...
ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, Selector Sel, ArrayRef< SourceLocation > SelectorLocs, QualType SuperType, ObjCMethodDecl *Method, SourceLocation LBracLoc, MultiExprArg Args, SourceLocation RBracLoc)
Build a new Objective-C instance/class message to 'super'.
OMPClause * RebuildOMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'lastprivate' clause.
QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, VectorKind)
Build a new potentially dependently-sized extended vector type given the element type and number of e...
bool AllowSkippingCXXConstructExpr()
Wether CXXConstructExpr can be skipped when they are implicit.
OMPClause * RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'safelen' clause.
StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *Init, Sema::ConditionResult Cond, SourceLocation RParenLoc)
Start building a new switch statement.
StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt)
Build a new default statement.
StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParenLoc, VarDecl *Var, Stmt *Body)
Build a new Objective-C @catch statement.
OMPClause * RebuildOMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'filter' clause.
ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, SourceLocation OperatorLoc, bool isArrow, CXXScopeSpec &SS, TypeSourceInfo *ScopeType, SourceLocation CCLoc, SourceLocation TildeLoc, PseudoDestructorTypeStorage Destroyed)
Build a new pseudo-destructor expression.
QualType RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, SourceLocation EllipsisLoc, std::optional< unsigned > NumExpansions)
Build a new pack expansion type.
QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits, SourceLocation Loc)
Build a bit-precise int given its value type.
ExprResult RebuildObjCArrayLiteral(SourceRange Range, Expr **Elements, unsigned NumElements)
Build a new Objective-C array literal.
ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ __uuidof(type) expression.
ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, SourceLocation OperatorLoc, bool IsArrow, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, LookupResult &R, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
OMPClause * RebuildOMPBindClause(OpenMPBindClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'bind' clause.
concepts::NestedRequirement * RebuildNestedRequirement(StringRef InvalidConstraintEntity, const ASTConstraintSatisfaction &Satisfaction)
OMPClause * RebuildOMPCopyprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'copyprivate' clause.
QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, ConceptDecl *TypeConstraintConcept, ArrayRef< TemplateArgument > TypeConstraintArgs)
Build a new C++11 auto type.
QualType RebuildVariableArrayType(QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new variable-length array type given the element type, size modifier, size expression,...
ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ dynamic_cast expression.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, TypeSourceInfo *ControllingType, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with a type predicate.
QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil)
Build a new pointer type given its pointee type.
concepts::TypeRequirement * RebuildTypeRequirement(concepts::Requirement::SubstitutionDiagnostic *SubstDiag)
OMPClause * RebuildOMPPermutationClause(ArrayRef< Expr * > PermExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'permutation' clause.
OMPClause * RebuildOMPUsesAllocatorsClause(ArrayRef< SemaOpenMP::UsesAllocatorsData > Data, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'uses_allocators' clause.
ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, CXXConstructorDecl *Constructor, bool ConstructsVBase, bool InheritedFromVBase)
Build a new implicit construction via inherited constructor expression.
ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ const_cast expression.
ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, AtomicExpr::AtomicOp Op, SourceLocation RParenLoc)
Build a new atomic operation expression.
DeclarationNameInfo TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo)
Transform the given declaration name.
OMPClause * RebuildOMPXAttributeClause(ArrayRef< const Attr * > Attrs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_attribute' clause.
ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, std::optional< unsigned > NumExpansions)
Build a new C++1z fold-expression.
OMPClause * RebuildOMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'to' clause.
StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation LParenLoc, Expr *Cond, SourceLocation RParenLoc)
Build a new do-while statement.
OMPClause * RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation NameModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'if' clause.
StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body)
Attach the body to a new case statement.
ExprResult RebuildTypeTrait(TypeTrait Trait, SourceLocation StartLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
Build a new type trait expression.
ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
Build an empty C++1z fold-expression with the given operator.
QualType TransformTypeWithDeducedTST(QualType T)
Transform a type that is permitted to produce a DeducedTemplateSpecializationType.
OMPClause * RebuildOMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Build a new OpenMP 'init' clause.
OMPClause * RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'detach' clause.
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, MultiStmtArg Statements, SourceLocation RBraceLoc, bool IsStmtExpr)
Build a new compound statement.
ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, ValueDecl *VD, const DeclarationNameInfo &NameInfo, NamedDecl *Found, TemplateArgumentListInfo *TemplateArgs)
Build a new expression that references a declaration.
QualType RebuildArrayType(QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size, Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange)
Build a new array type given the element type, size modifier, size of the array (if known),...
StmtResult RebuildDeclStmt(MutableArrayRef< Decl * > Decls, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new declaration statement.
QualType RebuildUsingType(UsingShadowDecl *Found, QualType Underlying)
Build a new type found via an alias.
ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, Expr *SrcExpr, TypeSourceInfo *DstTInfo, SourceLocation RParenLoc)
Build a new convert vector expression.
QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL)
Build a new qualified type given its unqualified type and type location.
OMPClause * RebuildOMPDependClause(OMPDependClause::DependDataTy Data, Expr *DepModifier, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depend' pseudo clause.
OMPClause * RebuildOMPAlignedClause(ArrayRef< Expr * > VarList, Expr *Alignment, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'aligned' clause.
unsigned TransformTemplateDepth(unsigned Depth)
Transform a template parameter depth level.
QualType RebuildFunctionNoProtoType(QualType ResultType)
Build a new unprototyped function type.
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals, Fn TransformExceptionSpec)
const Attr * TransformAttr(const Attr *S)
Transform the given attribute.
QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns)
Build a new matrix type given the element type and dimensions.
OMPClause * RebuildOMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'map' clause.
ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Sub, SourceLocation RParenLoc)
Build a new C++ __builtin_bit_cast expression.
QualType RebuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, SourceLocation EllipsisLoc, bool FullySubstituted, ArrayRef< QualType > Expansions={})
StmtResult RebuildOMPCanonicalLoop(Stmt *LoopStmt)
Build a new OpenMP Canonical loop.
StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, DeclarationNameInfo DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP executable directive.
concepts::ExprRequirement * RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, concepts::ExprRequirement::ReturnTypeRequirement Ret)
ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI)
OMPClause * RebuildOMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'full' clause.
StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
OMPClause * RebuildOMPAffinityClause(SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, Expr *Modifier, ArrayRef< Expr * > Locators)
Build a new OpenMP 'affinity' clause.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(type) expression.
TypeSourceInfo * TransformTypeWithDeducedTST(TypeSourceInfo *DI)
ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierInScope, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Build a new member reference expression.
ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, Stmt::StmtClass Class, SourceLocation LAngleLoc, TypeSourceInfo *TInfo, SourceLocation RAngleLoc, SourceLocation LParenLoc, Expr *SubExpr, SourceLocation RParenLoc)
Build a new C++ "named" cast expression, such as static_cast or reinterpret_cast.
StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
Attach the body to the switch statement.
TypeSourceInfo * InventTypeSourceInfo(QualType T)
Fakes up a TypeSourceInfo for a type.
ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a new sizeof, alignof or vec_step expression with a type argument.
ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, SourceLocation DefaultLoc, SourceLocation RParenLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > Types, ArrayRef< Expr * > Exprs)
Build a new generic selection expression with an expression predicate.
QualType TransformTemplateTypeParmType(TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool SuppressObjCLifetime)
Derived & getDerived()
Retrieves a reference to the derived class.
OMPClause * RebuildOMPHoldsClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'holds' clause.
ExprResult RebuildArraySectionExpr(bool IsOMPArraySection, Expr *Base, SourceLocation LBracketLoc, Expr *LowerBound, SourceLocation ColonLocFirst, SourceLocation ColonLocSecond, Expr *Length, Expr *Stride, SourceLocation RBracketLoc)
Build a new array section expression.
concepts::ExprRequirement * TransformExprRequirement(concepts::ExprRequirement *Req)
QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc, TypeOfKind Kind)
Build a new typeof(expr) type.
ParmVarDecl * TransformFunctionTypeParam(ParmVarDecl *OldParm, int indexAdjustment, std::optional< unsigned > NumExpansions, bool ExpectParameterPack)
Transforms a single function-type parameter.
bool ReplacingOriginal()
Whether the transformation is forming an expression or statement that replaces the original.
OMPClause * RebuildOMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'flush' pseudo clause.
bool TransformTemplateArgument(const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output, bool Uneval=false)
Transform the given template argument.
QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, QualType Deduced)
By default, builds a new DeducedTemplateSpecializationType with the given deduced type.
ExprResult RebuildArraySubscriptExpr(Expr *LHS, SourceLocation LBracketLoc, Expr *RHS, SourceLocation RBracketLoc)
Build a new array subscript expression.
QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, SourceLocation AttributeLoc)
Build a new extended vector type given the element type and number of elements.
void transformedLocalDecl(Decl *Old, ArrayRef< Decl * > New)
Note that a local declaration has been transformed by this transformer.
ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr)
Build a new Objective-C boxed expression.
ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, bool IsThrownVariableInScope)
Build a new C++ throw expression.
bool TransformRequiresExprRequirements(ArrayRef< concepts::Requirement * > Reqs, llvm::SmallVectorImpl< concepts::Requirement * > &Transformed)
bool DropCallArgument(Expr *E)
Determine whether the given call argument should be dropped, e.g., because it is a default argument.
StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *Label)
Build a new goto statement.
OMPClause * RebuildOMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'private' clause.
ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, ObjCMethodDecl *Getter, ObjCMethodDecl *Setter, SourceLocation PropertyLoc)
Build a new Objective-C property reference expression.
ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation ClosingBraceLoc)
Build a new requires expression.
ExprResult RebuildExpressionTrait(ExpressionTrait Trait, SourceLocation StartLoc, Expr *Queried, SourceLocation RParenLoc)
Build a new expression trait expression.
OMPClause * RebuildOMPDoacrossClause(OpenMPDoacrossClauseModifier DepType, SourceLocation DepLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'doacross' clause.
OMPClause * RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'final' clause.
StmtResult RebuildIfStmt(SourceLocation IfLoc, IfStatementKind Kind, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Init, Stmt *Then, SourceLocation ElseLoc, Stmt *Else)
Build a new "if" statement.
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
void reserve(size_t Requested)
Ensures that this buffer has at least as much capacity as described.
void TypeWasModifiedSafely(QualType T)
Tell the TypeLocBuilder that the type it is storing has been modified in some safe way that doesn't a...
TypeSourceInfo * getTypeSourceInfo(ASTContext &Context, QualType T)
Creates a TypeSourceInfo for the given type.
Base wrapper for a particular "section" of type source info.
Definition: TypeLoc.h:59
UnqualTypeLoc getUnqualifiedLoc() const
Skips past any qualifiers, if this is qualified.
Definition: TypeLoc.h:338
QualType getType() const
Get the type for which this source info wrapper provides information.
Definition: TypeLoc.h:133
T getAs() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:89
T castAs() const
Convert to the specified TypeLoc type, asserting that this TypeLoc is of the desired type.
Definition: TypeLoc.h:78
SourceRange getSourceRange() const LLVM_READONLY
Get the full source range.
Definition: TypeLoc.h:153
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition: TypeLoc.h:164
SourceLocation getTemplateKeywordLoc() const
Get the SourceLocation of the template keyword (if any).
Definition: TypeLoc.cpp:756
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition: TypeLoc.h:2715
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
A container of type source information.
Definition: Type.h:7902
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7913
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition: Type.cpp:3213
ElaboratedTypeKeyword getKeyword() const
Definition: Type.h:6901
The base class of the type hierarchy.
Definition: Type.h:1828
bool isPointerType() const
Definition: Type.h:8186
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:8800
bool isReferenceType() const
Definition: Type.h:8204
bool isEnumeralType() const
Definition: Type.h:8290
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:738
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
Definition: Type.h:2811
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2706
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition: Type.h:2361
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition: Type.h:8651
bool isObjCLifetimeType() const
Returns true if objects of this type have lifetime semantics under ARC.
Definition: Type.cpp:5048
bool isFunctionType() const
Definition: Type.h:8182
bool isObjCObjectPointerType() const
Definition: Type.h:8328
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
bool isRecordType() const
Definition: Type.h:8286
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3413
Wrapper for source info for typedefs.
Definition: TypeLoc.h:693
TypedefNameDecl * getTypedefNameDecl() const
Definition: TypeLoc.h:695
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2232
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition: Expr.cpp:1410
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:1028
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3203
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition: ExprCXX.h:3277
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition: ExprCXX.h:3272
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition: ExprCXX.cpp:419
A set of unresolved declarations.
Definition: UnresolvedSet.h:62
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:92
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5667
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3338
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition: DeclCXX.h:3402
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
QualType getType() const
Definition: Decl.h:682
Represents a variable declaration or definition.
Definition: Decl.h:882
@ CInit
C-style initialization with assignment.
Definition: Decl.h:887
@ CallInit
Call-style initialization (C++98)
Definition: Decl.h:890
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition: Decl.h:1119
bool isParameterPack() const
Determine whether this variable is actually a function parameter pack or init-capture pack.
Definition: Decl.cpp:2662
A requires-expression requirement which queries the validity and properties of an expression ('simple...
Definition: ExprConcepts.h:280
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
Definition: ExprConcepts.h:408
const ReturnTypeRequirement & getReturnTypeRequirement() const
Definition: ExprConcepts.h:398
SourceLocation getNoexceptLoc() const
Definition: ExprConcepts.h:390
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
Definition: ExprConcepts.h:429
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
Definition: ExprConcepts.h:484
A static requirement that can be used in a requires-expression to check properties of types and expre...
Definition: ExprConcepts.h:168
A requires-expression requirement which queries the existence of a type name or type template special...
Definition: ExprConcepts.h:225
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
Definition: ExprConcepts.h:260
TypeSourceInfo * getType() const
Definition: ExprConcepts.h:267
bool ContainsUnexpandedParameterPack
Whether this contains an unexpanded parameter pack.
Definition: ScopeInfo.h:728
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition: ScopeInfo.h:871
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Definition: ScopeInfo.h:874
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const AstTypeMatcher< FunctionType > functionType
Matches FunctionType nodes.
bool Inc(InterpState &S, CodePtr OpPC)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
Definition: Interp.h:824
bool Comp(InterpState &S, CodePtr OpPC)
1) Pops the value from the stack.
Definition: Interp.h:925
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition: Descriptor.h:29
CharSourceRange getSourceRange(const SourceRange &Range)
Returns the token CharSourceRange corresponding to Range.
Definition: FixIt.h:32
The JSON file list parser is used to communicate input to InstallAPI.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
@ OO_None
Not an overloaded operator.
Definition: OperatorKinds.h:22
@ NUM_OVERLOADED_OPERATORS
Definition: OperatorKinds.h:26
OpenACCDirectiveKind
Definition: OpenACCKinds.h:25
ArrayTypeTrait
Names for the array type traits.
Definition: TypeTraits.h:42
@ CPlusPlus23
Definition: LangStandard.h:60
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition: Type.h:1778
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition: OpenMPKinds.h:25
OpenMPDefaultmapClauseModifier
OpenMP modifiers for 'defaultmap' clause.
Definition: OpenMPKinds.h:119
OpenMPOrderClauseModifier
OpenMP modifiers for 'order' clause.
Definition: OpenMPKinds.h:172
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
Definition: Specifiers.h:39
CXXConstructionKind
Definition: ExprCXX.h:1538
@ OK_ObjCProperty
An Objective-C property is a logical field of an Objective-C object which is read and written via Obj...
Definition: Specifiers.h:161
OpenMPAtClauseKind
OpenMP attributes for 'at' clause.
Definition: OpenMPKinds.h:136
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
Definition: Lambda.h:36
@ LCK_ByRef
Capturing by reference.
Definition: Lambda.h:37
@ LCK_StarThis
Capturing the *this object by copy.
Definition: Lambda.h:35
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
Definition: OpenMPKinds.h:187
BinaryOperatorKind
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
TypeOfKind
The kind of 'typeof' expression we're after.
Definition: Type.h:910
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition: OpenMPKinds.h:39
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Definition: OpenMPKinds.h:104
OpenMPDoacrossClauseModifier
OpenMP dependence types for 'doacross' clause.
Definition: OpenMPKinds.h:220
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition: TypeTraits.h:51
ExprResult ExprEmpty()
Definition: Ownership.h:271
StmtResult StmtError()
Definition: Ownership.h:265
@ Property
The type of a property.
@ Result
The result type of a method or function.
OpenMPBindClauseKind
OpenMP bindings for the 'bind' clause.
Definition: OpenMPKinds.h:201
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition: Type.h:3574
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
Definition: OpenMPKinds.h:158
OpenMPGrainsizeClauseModifier
Definition: OpenMPKinds.h:207
OpenMPNumTasksClauseModifier
Definition: OpenMPKinds.h:213
UnaryOperatorKind
ActionResult< Expr * > ExprResult
Definition: Ownership.h:248
TagTypeKind
The kind of a tag type.
Definition: Type.h:6871
bool transformOMPMappableExprListClause(TreeTransform< Derived > &TT, OMPMappableExprListClause< T > *C, llvm::SmallVectorImpl< Expr * > &Vars, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperIdInfo, llvm::SmallVectorImpl< Expr * > &UnresolvedMappers)
ExprResult ExprError()
Definition: Ownership.h:264
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
Definition: Diagnostic.h:1488
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
Definition: OpenMPKinds.h:143
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:249
OpenMPDefaultmapClauseKind
OpenMP attributes for 'defaultmap' clause.
Definition: OpenMPKinds.h:111
OpenMPAllocateClauseModifier
OpenMP modifiers for 'allocate' clause.
Definition: OpenMPKinds.h:227
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition: OpenMPKinds.h:63
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition: Specifiers.h:135
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition: Specifiers.h:139
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition: Ownership.h:229
const FunctionProtoType * T
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl * >, SourceLocation > UnexpandedParameterPack
Definition: Sema.h:236
VectorKind
Definition: Type.h:3993
OpenMPDeviceClauseModifier
OpenMP modifiers for 'device' clause.
Definition: OpenMPKinds.h:48
SourceLocIdentKind
Definition: Expr.h:4797
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition: Type.h:6846
@ None
No keyword precedes the qualified type name.
@ Class
The "class" keyword introduces the elaborated-type-specifier.
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
OpenMPOrderClauseKind
OpenMP attributes for 'order' clause.
Definition: OpenMPKinds.h:165
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
@ Parens
New-expression has a C++98 paren-delimited initializer.
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_DynamicNone
throw()
@ EST_Uninstantiated
not instantiated yet
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_Dynamic
throw(T1, T2)
PredefinedIdentKind
Definition: Expr.h:1975
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition: OpenMPKinds.h:31
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
MutableArrayRef< Expr * > MultiExprArg
Definition: Ownership.h:258
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition: OpenMPKinds.h:71
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition: ASTConcept.h:89
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setName(DeclarationName N)
setName - Sets the embedded declaration name.
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition: Type.h:4840
EffectConditionExpr Cond
Definition: Type.h:4842
Holds information about the various types of exception specification.
Definition: Type.h:5159
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:5175
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5161
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5164
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:5167
Extra information about a function prototype.
Definition: Type.h:5187
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5194
FunctionEffectsRef FunctionEffects
Definition: Type.h:5197
const ExtParameterInfo * ExtParameterInfos
Definition: Type.h:5195
This structure contains most locations needed for by an OMPVarListClause.
Definition: OpenMPClause.h:259
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition: Sema.h:12691
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:2810
Location information for a TemplateArgument.
Definition: TemplateBase.h:472