clang 24.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"
32#include "clang/AST/StmtSYCL.h"
37#include "clang/Sema/Lookup.h"
42#include "clang/Sema/SemaHLSL.h"
44#include "clang/Sema/SemaObjC.h"
48#include "clang/Sema/SemaSYCL.h"
49#include "clang/Sema/Template.h"
50#include "llvm/ADT/ArrayRef.h"
51#include "llvm/Support/ErrorHandling.h"
52#include <algorithm>
53#include <optional>
54
55using namespace llvm::omp;
56
57namespace clang {
58using namespace sema;
59
60// This helper class is used to facilitate pack expansion during tree transform.
70
71/// A semantic tree transformation that allows one to transform one
72/// abstract syntax tree into another.
73///
74/// A new tree transformation is defined by creating a new subclass \c X of
75/// \c TreeTransform<X> and then overriding certain operations to provide
76/// behavior specific to that transformation. For example, template
77/// instantiation is implemented as a tree transformation where the
78/// transformation of TemplateTypeParmType nodes involves substituting the
79/// template arguments for their corresponding template parameters; a similar
80/// transformation is performed for non-type template parameters and
81/// template template parameters.
82///
83/// This tree-transformation template uses static polymorphism to allow
84/// subclasses to customize any of its operations. Thus, a subclass can
85/// override any of the transformation or rebuild operators by providing an
86/// operation with the same signature as the default implementation. The
87/// overriding function should not be virtual.
88///
89/// Semantic tree transformations are split into two stages, either of which
90/// can be replaced by a subclass. The "transform" step transforms an AST node
91/// or the parts of an AST node using the various transformation functions,
92/// then passes the pieces on to the "rebuild" step, which constructs a new AST
93/// node of the appropriate kind from the pieces. The default transformation
94/// routines recursively transform the operands to composite AST nodes (e.g.,
95/// the pointee type of a PointerType node) and, if any of those operand nodes
96/// were changed by the transformation, invokes the rebuild operation to create
97/// a new AST node.
98///
99/// Subclasses can customize the transformation at various levels. The
100/// most coarse-grained transformations involve replacing TransformType(),
101/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
102/// TransformTemplateName(), or TransformTemplateArgument() with entirely
103/// new implementations.
104///
105/// For more fine-grained transformations, subclasses can replace any of the
106/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
107/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
108/// replacing TransformTemplateTypeParmType() allows template instantiation
109/// to substitute template arguments for their corresponding template
110/// parameters. Additionally, subclasses can override the \c RebuildXXX
111/// functions to control how AST nodes are rebuilt when their operands change.
112/// By default, \c TreeTransform will invoke semantic analysis to rebuild
113/// AST nodes. However, certain other tree transformations (e.g, cloning) may
114/// be able to use more efficient rebuild steps.
115///
116/// There are a handful of other functions that can be overridden, allowing one
117/// to avoid traversing nodes that don't need any transformation
118/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
119/// operands have not changed (\c AlwaysRebuild()), and customize the
120/// default locations and entity names used for type-checking
121/// (\c getBaseLocation(), \c getBaseEntity()).
122template<typename Derived>
124 /// Private RAII object that helps us forget and then re-remember
125 /// the template argument corresponding to a partially-substituted parameter
126 /// pack.
127 class ForgetPartiallySubstitutedPackRAII {
128 Derived &Self;
130 // Set the pack expansion index to -1 to avoid pack substitution and
131 // indicate that parameter packs should be instantiated as themselves.
132 Sema::ArgPackSubstIndexRAII ResetPackSubstIndex;
133
134 public:
135 ForgetPartiallySubstitutedPackRAII(Derived &Self)
136 : Self(Self), ResetPackSubstIndex(Self.getSema(), std::nullopt) {
137 Old = Self.ForgetPartiallySubstitutedPack();
138 }
139
140 ~ForgetPartiallySubstitutedPackRAII() {
141 Self.RememberPartiallySubstitutedPack(Old);
142 }
143 ForgetPartiallySubstitutedPackRAII(
144 const ForgetPartiallySubstitutedPackRAII &) = delete;
145 ForgetPartiallySubstitutedPackRAII &
146 operator=(const ForgetPartiallySubstitutedPackRAII &) = delete;
147 };
148
149protected:
151
152 /// The set of local declarations that have been transformed, for
153 /// cases where we are forced to build new declarations within the transformer
154 /// rather than in the subclass (e.g., lambda closure types).
155 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
156
157public:
158 /// Initializes a new tree transformer.
160
161 /// Retrieves a reference to the derived class.
162 Derived &getDerived() { return static_cast<Derived&>(*this); }
163
164 /// Retrieves a reference to the derived class.
165 const Derived &getDerived() const {
166 return static_cast<const Derived&>(*this);
167 }
168
169 static inline ExprResult Owned(Expr *E) { return E; }
170 static inline StmtResult Owned(Stmt *S) { return S; }
171
172 /// Retrieves a reference to the semantic analysis object used for
173 /// this tree transform.
174 Sema &getSema() const { return SemaRef; }
175
176 /// Whether the transformation should always rebuild AST nodes, even
177 /// if none of the children have changed.
178 ///
179 /// Subclasses may override this function to specify when the transformation
180 /// should rebuild all AST nodes.
181 ///
182 /// We must always rebuild all AST nodes when performing variadic template
183 /// pack expansion, in order to avoid violating the AST invariant that each
184 /// statement node appears at most once in its containing declaration.
185 bool AlwaysRebuild() { return static_cast<bool>(SemaRef.ArgPackSubstIndex); }
186
187 /// Whether the transformation is forming an expression or statement that
188 /// replaces the original. In this case, we'll reuse mangling numbers from
189 /// existing lambdas.
190 bool ReplacingOriginal() { return false; }
191
192 /// Wether CXXConstructExpr can be skipped when they are implicit.
193 /// They will be reconstructed when used if needed.
194 /// This is useful when the user that cause rebuilding of the
195 /// CXXConstructExpr is outside of the expression at which the TreeTransform
196 /// started.
197 bool AllowSkippingCXXConstructExpr() { return true; }
198
199 /// Returns the location of the entity being transformed, if that
200 /// information was not available elsewhere in the AST.
201 ///
202 /// By default, returns no source-location information. Subclasses can
203 /// provide an alternative implementation that provides better location
204 /// information.
206
207 /// Returns the name of the entity being transformed, if that
208 /// information was not available elsewhere in the AST.
209 ///
210 /// By default, returns an empty name. Subclasses can provide an alternative
211 /// implementation with a more precise name.
213
214 /// Sets the "base" location and entity when that
215 /// information is known based on another transformation.
216 ///
217 /// By default, the source location and entity are ignored. Subclasses can
218 /// override this function to provide a customized implementation.
220
221 /// RAII object that temporarily sets the base location and entity
222 /// used for reporting diagnostics in types.
224 TreeTransform &Self;
225 SourceLocation OldLocation;
226 DeclarationName OldEntity;
227
228 public:
230 DeclarationName Entity) : Self(Self) {
231 OldLocation = Self.getDerived().getBaseLocation();
232 OldEntity = Self.getDerived().getBaseEntity();
233
234 if (Location.isValid())
235 Self.getDerived().setBase(Location, Entity);
236 }
237
239 Self.getDerived().setBase(OldLocation, OldEntity);
240 }
241 TemporaryBase(const TemporaryBase &) = delete;
243 };
244
245 /// Determine whether the given type \p T has already been
246 /// transformed.
247 ///
248 /// Subclasses can provide an alternative implementation of this routine
249 /// to short-circuit evaluation when it is known that a given type will
250 /// not change. For example, template instantiation need not traverse
251 /// non-dependent types.
253 return T.isNull();
254 }
255
256 /// Transform a template parameter depth level.
257 ///
258 /// During a transformation that transforms template parameters, this maps
259 /// an old template parameter depth to a new depth.
260 unsigned TransformTemplateDepth(unsigned Depth) {
261 return Depth;
262 }
263
264 /// Determine whether the given call argument should be dropped, e.g.,
265 /// because it is a default argument.
266 ///
267 /// Subclasses can provide an alternative implementation of this routine to
268 /// determine which kinds of call arguments get dropped. By default,
269 /// CXXDefaultArgument nodes are dropped (prior to transformation).
271 return E->isDefaultArgument();
272 }
273
274 /// Determine whether we should expand a pack expansion with the
275 /// given set of parameter packs into separate arguments by repeatedly
276 /// transforming the pattern.
277 ///
278 /// By default, the transformer never tries to expand pack expansions.
279 /// Subclasses can override this routine to provide different behavior.
280 ///
281 /// \param EllipsisLoc The location of the ellipsis that identifies the
282 /// pack expansion.
283 ///
284 /// \param PatternRange The source range that covers the entire pattern of
285 /// the pack expansion.
286 ///
287 /// \param Unexpanded The set of unexpanded parameter packs within the
288 /// pattern.
289 ///
290 /// \param ShouldExpand Will be set to \c true if the transformer should
291 /// expand the corresponding pack expansions into separate arguments. When
292 /// set, \c NumExpansions must also be set.
293 ///
294 /// \param RetainExpansion Whether the caller should add an unexpanded
295 /// pack expansion after all of the expanded arguments. This is used
296 /// when extending explicitly-specified template argument packs per
297 /// C++0x [temp.arg.explicit]p9.
298 ///
299 /// \param NumExpansions The number of separate arguments that will be in
300 /// the expanded form of the corresponding pack expansion. This is both an
301 /// input and an output parameter, which can be set by the caller if the
302 /// number of expansions is known a priori (e.g., due to a prior substitution)
303 /// and will be set by the callee when the number of expansions is known.
304 /// The callee must set this value when \c ShouldExpand is \c true; it may
305 /// set this value in other cases.
306 ///
307 /// \returns true if an error occurred (e.g., because the parameter packs
308 /// are to be instantiated with arguments of different lengths), false
309 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
310 /// must be set.
312 SourceRange PatternRange,
314 bool FailOnPackProducingTemplates,
315 bool &ShouldExpand, bool &RetainExpansion,
316 UnsignedOrNone &NumExpansions) {
317 ShouldExpand = false;
318 return false;
319 }
320
321 /// "Forget" about the partially-substituted pack template argument,
322 /// when performing an instantiation that must preserve the parameter pack
323 /// use.
324 ///
325 /// This routine is meant to be overridden by the template instantiator.
329
330 /// "Remember" the partially-substituted pack template argument
331 /// after performing an instantiation that must preserve the parameter pack
332 /// use.
333 ///
334 /// This routine is meant to be overridden by the template instantiator.
336
337 /// "Forget" the template substitution to allow transforming the AST without
338 /// any template instantiations. This is used to expand template packs when
339 /// their size is not known in advance (e.g. for builtins that produce type
340 /// packs).
343
344private:
345 struct ForgetSubstitutionRAII {
346 Derived &Self;
348
349 public:
350 ForgetSubstitutionRAII(Derived &Self) : Self(Self) {
351 Old = Self.ForgetSubstitution();
352 }
353
354 ~ForgetSubstitutionRAII() { Self.RememberSubstitution(std::move(Old)); }
355 };
356
357public:
358 /// Note to the derived class when a function parameter pack is
359 /// being expanded.
361
362 /// Transforms the given type into another type.
363 ///
364 /// By default, this routine transforms a type by creating a
365 /// TypeSourceInfo for it and delegating to the appropriate
366 /// function. This is expensive, but we don't mind, because
367 /// this method is deprecated anyway; all users should be
368 /// switched to storing TypeSourceInfos.
369 ///
370 /// \returns the transformed type.
372
373 /// Transforms the given type-with-location into a new
374 /// type-with-location.
375 ///
376 /// By default, this routine transforms a type by delegating to the
377 /// appropriate TransformXXXType to build a new type. Subclasses
378 /// may override this function (to take over all type
379 /// transformations) or some set of the TransformXXXType functions
380 /// to alter the transformation.
382
383 /// Transform the given type-with-location into a new
384 /// type, collecting location information in the given builder
385 /// as necessary.
386 ///
388
389 /// Transform a type that is permitted to produce a
390 /// DeducedTemplateSpecializationType.
391 ///
392 /// This is used in the (relatively rare) contexts where it is acceptable
393 /// for transformation to produce a class template type with deduced
394 /// template arguments.
395 /// @{
398 /// @}
399
400 /// The reason why the value of a statement is not discarded, if any.
406
407 /// Transform the given statement.
408 ///
409 /// By default, this routine transforms a statement by delegating to the
410 /// appropriate TransformXXXStmt function to transform a specific kind of
411 /// statement or the TransformExpr() function to transform an expression.
412 /// Subclasses may override this function to transform statements using some
413 /// other mechanism.
414 ///
415 /// \returns the transformed statement.
418
419 /// Transform the given statement.
420 ///
421 /// By default, this routine transforms a statement by delegating to the
422 /// appropriate TransformOMPXXXClause function to transform a specific kind
423 /// of clause. Subclasses may override this function to transform statements
424 /// using some other mechanism.
425 ///
426 /// \returns the transformed OpenMP clause.
428
429 /// Transform the given attribute.
430 ///
431 /// By default, this routine transforms a statement by delegating to the
432 /// appropriate TransformXXXAttr function to transform a specific kind
433 /// of attribute. Subclasses may override this function to transform
434 /// attributed statements/types using some other mechanism.
435 ///
436 /// \returns the transformed attribute
437 const Attr *TransformAttr(const Attr *S);
438
439 // Transform the given statement attribute.
440 //
441 // Delegates to the appropriate TransformXXXAttr function to transform a
442 // specific kind of statement attribute. Unlike the non-statement taking
443 // version of this, this implements all attributes, not just pragmas.
444 const Attr *TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS,
445 const Attr *A);
446
447 // Transform the specified attribute.
448 //
449 // Subclasses should override the transformation of attributes with a pragma
450 // spelling to transform expressions stored within the attribute.
451 //
452 // \returns the transformed attribute.
453#define ATTR(X) \
454 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
455#include "clang/Basic/AttrList.inc"
456
457 // Transform the specified attribute.
458 //
459 // Subclasses should override the transformation of attributes to do
460 // transformation and checking of statement attributes. By default, this
461 // delegates to the non-statement taking version.
462 //
463 // \returns the transformed attribute.
464#define ATTR(X) \
465 const X##Attr *TransformStmt##X##Attr(const Stmt *, const Stmt *, \
466 const X##Attr *A) { \
467 return getDerived().Transform##X##Attr(A); \
468 }
469#include "clang/Basic/AttrList.inc"
470
471 /// Transform the given expression.
472 ///
473 /// By default, this routine transforms an expression by delegating to the
474 /// appropriate TransformXXXExpr function to build a new expression.
475 /// Subclasses may override this function to transform expressions using some
476 /// other mechanism.
477 ///
478 /// \returns the transformed expression.
480
481 /// Transform the given initializer.
482 ///
483 /// By default, this routine transforms an initializer by stripping off the
484 /// semantic nodes added by initialization, then passing the result to
485 /// TransformExpr or TransformExprs.
486 ///
487 /// \returns the transformed initializer.
489
490 /// Transform the given list of expressions.
491 ///
492 /// This routine transforms a list of expressions by invoking
493 /// \c TransformExpr() for each subexpression. However, it also provides
494 /// support for variadic templates by expanding any pack expansions (if the
495 /// derived class permits such expansion) along the way. When pack expansions
496 /// are present, the number of outputs may not equal the number of inputs.
497 ///
498 /// \param Inputs The set of expressions to be transformed.
499 ///
500 /// \param NumInputs The number of expressions in \c Inputs.
501 ///
502 /// \param IsCall If \c true, then this transform is being performed on
503 /// function-call arguments, and any arguments that should be dropped, will
504 /// be.
505 ///
506 /// \param Outputs The transformed input expressions will be added to this
507 /// vector.
508 ///
509 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
510 /// due to transformation.
511 ///
512 /// \returns true if an error occurred, false otherwise.
513 bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall,
515 bool *ArgChanged = nullptr);
516
517 /// Transform the given declaration, which is referenced from a type
518 /// or expression.
519 ///
520 /// By default, acts as the identity function on declarations, unless the
521 /// transformer has had to transform the declaration itself. Subclasses
522 /// may override this function to provide alternate behavior.
524 llvm::DenseMap<Decl *, Decl *>::iterator Known
525 = TransformedLocalDecls.find(D);
526 if (Known != TransformedLocalDecls.end())
527 return Known->second;
528
529 return D;
530 }
531
532 /// Transform the specified condition.
533 ///
534 /// By default, this transforms the variable and expression and rebuilds
535 /// the condition.
537 Expr *Expr,
539
540 /// Transform the attributes associated with the given declaration and
541 /// place them on the new declaration.
542 ///
543 /// By default, this operation does nothing. Subclasses may override this
544 /// behavior to transform attributes.
545 void transformAttrs(Decl *Old, Decl *New) { }
546
547 /// Note that a local declaration has been transformed by this
548 /// transformer.
549 ///
550 /// Local declarations are typically transformed via a call to
551 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
552 /// the transformer itself has to transform the declarations. This routine
553 /// can be overridden by a subclass that keeps track of such mappings.
555 assert(New.size() == 1 &&
556 "must override transformedLocalDecl if performing pack expansion");
557 TransformedLocalDecls[Old] = New.front();
558 }
559
560 /// Transform the definition of the given declaration.
561 ///
562 /// By default, invokes TransformDecl() to transform the declaration.
563 /// Subclasses may override this function to provide alternate behavior.
565 return getDerived().TransformDecl(Loc, D);
566 }
567
568 /// Transform the given declaration, which was the first part of a
569 /// nested-name-specifier in a member access expression.
570 ///
571 /// This specific declaration transformation only applies to the first
572 /// identifier in a nested-name-specifier of a member access expression, e.g.,
573 /// the \c T in \c x->T::member
574 ///
575 /// By default, invokes TransformDecl() to transform the declaration.
576 /// Subclasses may override this function to provide alternate behavior.
578 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
579 }
580
581 /// Transform the set of declarations in an OverloadExpr.
582 bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL,
583 LookupResult &R);
584
585 /// Transform the given nested-name-specifier with source-location
586 /// information.
587 ///
588 /// By default, transforms all of the types and declarations within the
589 /// nested-name-specifier. Subclasses may override this function to provide
590 /// alternate behavior.
593 QualType ObjectType = QualType(),
594 NamedDecl *FirstQualifierInScope = nullptr);
595
596 /// Transform the given declaration name.
597 ///
598 /// By default, transforms the types of conversion function, constructor,
599 /// and destructor names and then (if needed) rebuilds the declaration name.
600 /// Identifiers and selectors are returned unmodified. Subclasses may
601 /// override this function to provide alternate behavior.
604
614
615 /// Transform the given template name.
616 ///
617 /// \param SS The nested-name-specifier that qualifies the template
618 /// name. This nested-name-specifier must already have been transformed.
619 ///
620 /// \param Name The template name to transform.
621 ///
622 /// \param NameLoc The source location of the template name.
623 ///
624 /// \param ObjectType If we're translating a template name within a member
625 /// access expression, this is the type of the object whose member template
626 /// is being referenced.
627 ///
628 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
629 /// also refers to a name within the current (lexical) scope, this is the
630 /// declaration it refers to.
631 ///
632 /// By default, transforms the template name by transforming the declarations
633 /// and nested-name-specifiers that occur within the template name.
634 /// Subclasses may override this function to provide alternate behavior.
636 SourceLocation TemplateKWLoc,
637 TemplateName Name, SourceLocation NameLoc,
638 QualType ObjectType = QualType(),
639 NamedDecl *FirstQualifierInScope = nullptr,
640 bool AllowInjectedClassName = false);
641
642 /// Transform the given template argument.
643 ///
644 /// By default, this operation transforms the type, expression, or
645 /// declaration stored within the template argument and constructs a
646 /// new template argument from the transformed result. Subclasses may
647 /// override this function to provide alternate behavior.
648 ///
649 /// Returns true if there was an error.
651 TemplateArgumentLoc &Output,
652 bool Uneval = false);
653
655 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
656 TemplateName Name, SourceLocation NameLoc);
657
658 /// Transform the given set of template arguments.
659 ///
660 /// By default, this operation transforms all of the template arguments
661 /// in the input set using \c TransformTemplateArgument(), and appends
662 /// the transformed arguments to the output list.
663 ///
664 /// Note that this overload of \c TransformTemplateArguments() is merely
665 /// a convenience function. Subclasses that wish to override this behavior
666 /// should override the iterator-based member template version.
667 ///
668 /// \param Inputs The set of template arguments to be transformed.
669 ///
670 /// \param NumInputs The number of template arguments in \p Inputs.
671 ///
672 /// \param Outputs The set of transformed template arguments output by this
673 /// routine.
674 ///
675 /// Returns true if an error occurred.
677 unsigned NumInputs,
679 bool Uneval = false) {
680 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
681 Uneval);
682 }
683
684 /// Transform the given set of template arguments.
685 ///
686 /// By default, this operation transforms all of the template arguments
687 /// in the input set using \c TransformTemplateArgument(), and appends
688 /// the transformed arguments to the output list.
689 ///
690 /// \param First An iterator to the first template argument.
691 ///
692 /// \param Last An iterator one step past the last template argument.
693 ///
694 /// \param Outputs The set of transformed template arguments output by this
695 /// routine.
696 ///
697 /// Returns true if an error occurred.
698 template<typename InputIterator>
700 InputIterator Last,
702 bool Uneval = false);
703
704 template <typename InputIterator>
706 InputIterator Last,
708 bool Uneval = false);
709
710 /// Checks if the argument pack from \p In will need to be expanded and does
711 /// the necessary prework.
712 /// Whether the expansion is needed is captured in Info.Expand.
713 ///
714 /// - When the expansion is required, \p Out will be a template pattern that
715 /// would need to be expanded.
716 /// - When the expansion must not happen, \p Out will be a pack that must be
717 /// returned to the outputs directly.
718 ///
719 /// \return true iff the error occurred
722
723 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
725 TemplateArgumentLoc &ArgLoc);
726
727 /// Fakes up a TypeSourceInfo for a type.
729 return SemaRef.Context.getTrivialTypeSourceInfo(T,
731 }
732
733#define ABSTRACT_TYPELOC(CLASS, PARENT)
734#define TYPELOC(CLASS, PARENT) \
735 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
736#include "clang/AST/TypeLocNodes.def"
737
740 bool SuppressObjCLifetime);
744 bool SuppressObjCLifetime);
745
746 template<typename Fn>
749 CXXRecordDecl *ThisContext,
750 Qualifiers ThisTypeQuals,
752
755 SmallVectorImpl<QualType> &Exceptions,
756 bool &Changed);
757
759
762 QualType ObjectType,
763 NamedDecl *FirstQualifierInScope,
764 bool AllowInjectedClassName);
765
767
768 /// Transforms the parameters of a function type into the
769 /// given vectors.
770 ///
771 /// The result vectors should be kept in sync; null entries in the
772 /// variables vector are acceptable.
773 ///
774 /// LastParamTransformed, if non-null, will be set to the index of the last
775 /// parameter on which transformation was started. In the event of an error,
776 /// this will contain the parameter which failed to instantiate.
777 ///
778 /// Return true on error.
781 const QualType *ParamTypes,
782 const FunctionProtoType::ExtParameterInfo *ParamInfos,
784 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
785
788 const QualType *ParamTypes,
789 const FunctionProtoType::ExtParameterInfo *ParamInfos,
792 return getDerived().TransformFunctionTypeParams(
793 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
794 }
795
796 /// Transforms the parameters of a requires expresison into the given vectors.
797 ///
798 /// The result vectors should be kept in sync; null entries in the
799 /// variables vector are acceptable.
800 ///
801 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
802 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
803 /// which are cases where transformation shouldn't continue.
805 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
811 KWLoc, Params, /*ParamTypes=*/nullptr,
812 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
813 return ExprError();
814
815 return ExprResult{};
816 }
817
818 /// Transforms a single function-type parameter. Return null
819 /// on error.
820 ///
821 /// \param indexAdjustment - A number to add to the parameter's
822 /// scope index; can be negative
824 int indexAdjustment,
825 UnsignedOrNone NumExpansions,
826 bool ExpectParameterPack);
827
828 /// Transform the body of a lambda-expression.
830 /// Alternative implementation of TransformLambdaBody that skips transforming
831 /// the body.
833
839
841
843
846
851
853
855 bool IsAddressOfOperand,
856 TypeSourceInfo **RecoveryTSI);
857
859 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
860 TypeSourceInfo **RecoveryTSI);
861
863 bool IsAddressOfOperand);
864
866
868
869// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
870// amount of stack usage with clang.
871#define STMT(Node, Parent) \
872 LLVM_ATTRIBUTE_NOINLINE \
873 StmtResult Transform##Node(Node *S);
874#define VALUESTMT(Node, Parent) \
875 LLVM_ATTRIBUTE_NOINLINE \
876 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
877#define EXPR(Node, Parent) \
878 LLVM_ATTRIBUTE_NOINLINE \
879 ExprResult Transform##Node(Node *E);
880#define ABSTRACT_STMT(Stmt)
881#include "clang/AST/StmtNodes.inc"
882
883#define GEN_CLANG_CLAUSE_CLASS
884#define CLAUSE_CLASS(Enum, Str, Class) \
885 LLVM_ATTRIBUTE_NOINLINE \
886 OMPClause *Transform##Class(Class *S);
887#include "llvm/Frontend/OpenMP/OMP.inc"
888
889 /// Build a new qualified type given its unqualified type and type location.
890 ///
891 /// By default, this routine adds type qualifiers only to types that can
892 /// have qualifiers, and silently suppresses those qualifiers that are not
893 /// permitted. Subclasses may override this routine to provide different
894 /// behavior.
896
897 /// Build a new pointer type given its pointee type.
898 ///
899 /// By default, performs semantic analysis when building the pointer type.
900 /// Subclasses may override this routine to provide different behavior.
902
903 /// Build a new block pointer type given its pointee type.
904 ///
905 /// By default, performs semantic analysis when building the block pointer
906 /// type. Subclasses may override this routine to provide different behavior.
908
909 /// Build a new reference type given the type it references.
910 ///
911 /// By default, performs semantic analysis when building the
912 /// reference type. Subclasses may override this routine to provide
913 /// different behavior.
914 ///
915 /// \param LValue whether the type was written with an lvalue sigil
916 /// or an rvalue sigil.
918 bool LValue,
919 SourceLocation Sigil);
920
921 /// Build a new member pointer type given the pointee type and the
922 /// qualifier it refers into.
923 ///
924 /// By default, performs semantic analysis when building the member pointer
925 /// type. Subclasses may override this routine to provide different behavior.
927 const CXXScopeSpec &SS, CXXRecordDecl *Cls,
928 SourceLocation Sigil);
929
931 SourceLocation ProtocolLAngleLoc,
933 ArrayRef<SourceLocation> ProtocolLocs,
934 SourceLocation ProtocolRAngleLoc);
935
936 /// Build an Objective-C object type.
937 ///
938 /// By default, performs semantic analysis when building the object type.
939 /// Subclasses may override this routine to provide different behavior.
941 SourceLocation Loc,
942 SourceLocation TypeArgsLAngleLoc,
944 SourceLocation TypeArgsRAngleLoc,
945 SourceLocation ProtocolLAngleLoc,
947 ArrayRef<SourceLocation> ProtocolLocs,
948 SourceLocation ProtocolRAngleLoc);
949
950 /// Build a new Objective-C object pointer type given the pointee type.
951 ///
952 /// By default, directly builds the pointer type, with no additional semantic
953 /// analysis.
956
957 /// Build a new array type given the element type, size
958 /// modifier, size of the array (if known), size expression, and index type
959 /// qualifiers.
960 ///
961 /// By default, performs semantic analysis when building the array type.
962 /// Subclasses may override this routine to provide different behavior.
963 /// Also by default, all of the other Rebuild*Array
965 const llvm::APInt *Size, Expr *SizeExpr,
966 unsigned IndexTypeQuals, SourceRange BracketsRange);
967
968 /// Build a new constant array type given the element type, size
969 /// modifier, (known) size of the array, and index type qualifiers.
970 ///
971 /// By default, performs semantic analysis when building the array type.
972 /// Subclasses may override this routine to provide different behavior.
974 ArraySizeModifier SizeMod,
975 const llvm::APInt &Size, Expr *SizeExpr,
976 unsigned IndexTypeQuals,
977 SourceRange BracketsRange);
978
979 /// Build a new incomplete array type given the element type, size
980 /// modifier, and index type qualifiers.
981 ///
982 /// By default, performs semantic analysis when building the array type.
983 /// Subclasses may override this routine to provide different behavior.
985 ArraySizeModifier SizeMod,
986 unsigned IndexTypeQuals,
987 SourceRange BracketsRange);
988
989 /// Build a new variable-length array type given the element type,
990 /// size modifier, size expression, and index type qualifiers.
991 ///
992 /// By default, performs semantic analysis when building the array type.
993 /// Subclasses may override this routine to provide different behavior.
995 ArraySizeModifier SizeMod, Expr *SizeExpr,
996 unsigned IndexTypeQuals,
997 SourceRange BracketsRange);
998
999 /// Build a new dependent-sized array type given the element type,
1000 /// size modifier, size expression, and index type qualifiers.
1001 ///
1002 /// By default, performs semantic analysis when building the array type.
1003 /// Subclasses may override this routine to provide different behavior.
1005 ArraySizeModifier SizeMod,
1006 Expr *SizeExpr,
1007 unsigned IndexTypeQuals,
1008 SourceRange BracketsRange);
1009
1010 /// Build a new vector type given the element type and
1011 /// number of elements.
1012 ///
1013 /// By default, performs semantic analysis when building the vector type.
1014 /// Subclasses may override this routine to provide different behavior.
1015 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
1016 VectorKind VecKind);
1017
1018 /// Build a new potentially dependently-sized extended vector type
1019 /// given the element type and number of elements.
1020 ///
1021 /// By default, performs semantic analysis when building the vector type.
1022 /// Subclasses may override this routine to provide different behavior.
1024 SourceLocation AttributeLoc, VectorKind);
1025
1026 /// Build a new extended vector type given the element type and
1027 /// number of elements.
1028 ///
1029 /// By default, performs semantic analysis when building the vector type.
1030 /// Subclasses may override this routine to provide different behavior.
1031 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
1032 SourceLocation AttributeLoc);
1033
1034 /// Build a new potentially dependently-sized extended vector type
1035 /// given the element type and number of elements.
1036 ///
1037 /// By default, performs semantic analysis when building the vector type.
1038 /// Subclasses may override this routine to provide different behavior.
1040 Expr *SizeExpr,
1041 SourceLocation AttributeLoc);
1042
1043 /// Build a new matrix type given the element type and dimensions.
1044 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
1045 unsigned NumColumns);
1046
1047 /// Build a new matrix type given the type and dependently-defined
1048 /// dimensions.
1050 Expr *ColumnExpr,
1051 SourceLocation AttributeLoc);
1052
1053 /// Build a new DependentAddressSpaceType or return the pointee
1054 /// type variable with the correct address space (retrieved from
1055 /// AddrSpaceExpr) applied to it. The former will be returned in cases
1056 /// where the address space remains dependent.
1057 ///
1058 /// By default, performs semantic analysis when building the type with address
1059 /// space applied. Subclasses may override this routine to provide different
1060 /// behavior.
1062 Expr *AddrSpaceExpr,
1063 SourceLocation AttributeLoc);
1064
1065 /// Build a new function type.
1066 ///
1067 /// By default, performs semantic analysis when building the function type.
1068 /// Subclasses may override this routine to provide different behavior.
1070 MutableArrayRef<QualType> ParamTypes,
1072
1073 /// Build a new unprototyped function type.
1075
1076 /// Rebuild an unresolved typename type, given the decl that
1077 /// the UnresolvedUsingTypenameDecl was transformed to.
1079 NestedNameSpecifier Qualifier,
1080 SourceLocation NameLoc, Decl *D);
1081
1082 /// Build a new type found via an alias.
1085 QualType UnderlyingType) {
1086 return SemaRef.Context.getUsingType(Keyword, Qualifier, D, UnderlyingType);
1087 }
1088
1089 /// Build a new typedef type.
1091 NestedNameSpecifier Qualifier,
1093 return SemaRef.Context.getTypedefType(Keyword, Qualifier, Typedef);
1094 }
1095
1096 /// Build a new MacroDefined type.
1098 const IdentifierInfo *MacroII) {
1099 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1100 }
1101
1102 /// Build a new class/struct/union/enum type.
1104 NestedNameSpecifier Qualifier, TagDecl *Tag) {
1105 return SemaRef.Context.getTagType(Keyword, Qualifier, Tag,
1106 /*OwnsTag=*/false);
1107 }
1109 return SemaRef.Context.getCanonicalTagType(Tag);
1110 }
1111
1112 /// Build a new typeof(expr) type.
1113 ///
1114 /// By default, performs semantic analysis when building the typeof type.
1115 /// Subclasses may override this routine to provide different behavior.
1117 TypeOfKind Kind);
1118
1119 /// Build a new typeof(type) type.
1120 ///
1121 /// By default, builds a new TypeOfType with the given underlying type.
1123
1124 /// Build a new unary transform type.
1126 UnaryTransformType::UTTKind UKind,
1127 SourceLocation Loc);
1128
1129 /// Build a new C++11 decltype type.
1130 ///
1131 /// By default, performs semantic analysis when building the decltype type.
1132 /// Subclasses may override this routine to provide different behavior.
1134
1136 SourceLocation Loc,
1137 SourceLocation EllipsisLoc,
1138 bool FullySubstituted,
1139 ArrayRef<QualType> Expansions = {});
1140
1141 /// Build a new C++11 auto type.
1142 ///
1143 /// By default, builds a new AutoType with the given deduced type.
1146 ConceptDecl *TypeConstraintConcept,
1147 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1148 return SemaRef.Context.getAutoType(
1149 DK, DeducedAsType, Keyword, TypeConstraintConcept, TypeConstraintArgs);
1150 }
1151
1152 /// By default, builds a new DeducedTemplateSpecializationType with the given
1153 /// deduced type.
1157 return SemaRef.Context.getDeducedTemplateSpecializationType(
1158 DK, DeducedAsType, Keyword, Template);
1159 }
1160
1161 /// Build a new template specialization type.
1162 ///
1163 /// By default, performs semantic analysis when building the template
1164 /// specialization type. Subclasses may override this routine to provide
1165 /// different behavior.
1168 SourceLocation TemplateLoc,
1170
1171 /// Build a new parenthesized type.
1172 ///
1173 /// By default, builds a new ParenType type from the inner type.
1174 /// Subclasses may override this routine to provide different behavior.
1176 return SemaRef.BuildParenType(InnerType);
1177 }
1178
1179 /// Build a new typename type that refers to an identifier.
1180 ///
1181 /// By default, performs semantic analysis when building the typename type
1182 /// (or elaborated type). Subclasses may override this routine to provide
1183 /// different behavior.
1185 SourceLocation KeywordLoc,
1186 NestedNameSpecifierLoc QualifierLoc,
1187 const IdentifierInfo *Id,
1188 SourceLocation IdLoc,
1189 bool DeducedTSTContext) {
1190 CXXScopeSpec SS;
1191 SS.Adopt(QualifierLoc);
1192
1193 if (QualifierLoc.getNestedNameSpecifier().isDependent()) {
1194 // If the name is still dependent, just build a new dependent name type.
1195 if (!SemaRef.computeDeclContext(SS))
1196 return SemaRef.Context.getDependentNameType(Keyword,
1197 QualifierLoc.getNestedNameSpecifier(),
1198 Id);
1199 }
1200
1203 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1204 *Id, IdLoc, DeducedTSTContext);
1205 }
1206
1208
1209 // We had a dependent elaborated-type-specifier that has been transformed
1210 // into a non-dependent elaborated-type-specifier. Find the tag we're
1211 // referring to.
1213 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1214 if (!DC)
1215 return QualType();
1216
1217 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1218 return QualType();
1219
1220 TagDecl *Tag = nullptr;
1221 SemaRef.LookupQualifiedName(Result, DC);
1222 switch (Result.getResultKind()) {
1225 break;
1226
1228 Tag = Result.getAsSingle<TagDecl>();
1229 break;
1230
1233 llvm_unreachable("Tag lookup cannot find non-tags");
1234
1236 // Let the LookupResult structure handle ambiguities.
1237 return QualType();
1238 }
1239
1240 if (!Tag) {
1241 // Check where the name exists but isn't a tag type and use that to emit
1242 // better diagnostics.
1244 SemaRef.LookupQualifiedName(Result, DC);
1245 switch (Result.getResultKind()) {
1249 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1250 NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1251 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1252 << SomeDecl << NTK << Kind;
1253 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1254 break;
1255 }
1256 default:
1257 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1258 << Kind << Id << DC << QualifierLoc.getSourceRange();
1259 break;
1260 }
1261 return QualType();
1262 }
1263 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1264 IdLoc, Id)) {
1265 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1266 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1267 return QualType();
1268 }
1269 return getDerived().RebuildTagType(
1270 Keyword, QualifierLoc.getNestedNameSpecifier(), Tag);
1271 }
1272
1273 /// Build a new pack expansion type.
1274 ///
1275 /// By default, builds a new PackExpansionType type from the given pattern.
1276 /// Subclasses may override this routine to provide different behavior.
1278 SourceLocation EllipsisLoc,
1279 UnsignedOrNone NumExpansions) {
1280 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1281 NumExpansions);
1282 }
1283
1284 /// Build a new atomic type given its value type.
1285 ///
1286 /// By default, performs semantic analysis when building the atomic type.
1287 /// Subclasses may override this routine to provide different behavior.
1289
1290 /// Build a new pipe type given its value type.
1292 bool isReadPipe);
1293
1294 /// Build a bit-precise int given its value type.
1295 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1296 SourceLocation Loc);
1297
1298 /// Build a dependent bit-precise int given its value type.
1299 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1300 SourceLocation Loc);
1301
1302 /// Build a new template name given a nested name specifier, a flag
1303 /// indicating whether the "template" keyword was provided, and the template
1304 /// that the template name refers to.
1305 ///
1306 /// By default, builds the new template name directly. Subclasses may override
1307 /// this routine to provide different behavior.
1309 TemplateName Name);
1310
1311 /// Build a new template name given a nested name specifier and the
1312 /// name that is referred to as a template.
1313 ///
1314 /// By default, performs semantic analysis to determine whether the name can
1315 /// be resolved to a specific template, then builds the appropriate kind of
1316 /// template name. Subclasses may override this routine to provide different
1317 /// behavior.
1319 SourceLocation TemplateKWLoc,
1320 const IdentifierInfo &Name,
1321 SourceLocation NameLoc, QualType ObjectType,
1322 bool AllowInjectedClassName);
1323
1324 /// Build a new template name given a nested name specifier and the
1325 /// overloaded operator name that is referred to as a template.
1326 ///
1327 /// By default, performs semantic analysis to determine whether the name can
1328 /// be resolved to a specific template, then builds the appropriate kind of
1329 /// template name. Subclasses may override this routine to provide different
1330 /// behavior.
1332 SourceLocation TemplateKWLoc,
1333 OverloadedOperatorKind Operator,
1334 SourceLocation NameLoc, QualType ObjectType,
1335 bool AllowInjectedClassName);
1336
1338 SourceLocation TemplateKWLoc,
1340 SourceLocation NameLoc, QualType ObjectType,
1341 bool AllowInjectedClassName);
1342
1343 /// Build a new template name given a template template parameter pack
1344 /// and the
1345 ///
1346 /// By default, performs semantic analysis to determine whether the name can
1347 /// be resolved to a specific template, then builds the appropriate kind of
1348 /// template name. Subclasses may override this routine to provide different
1349 /// behavior.
1351 Decl *AssociatedDecl, unsigned Index,
1352 bool Final) {
1354 ArgPack, AssociatedDecl, Index, Final);
1355 }
1356
1357 /// Build a new compound statement.
1358 ///
1359 /// By default, performs semantic analysis to build the new statement.
1360 /// Subclasses may override this routine to provide different behavior.
1362 MultiStmtArg Statements,
1363 SourceLocation RBraceLoc,
1364 bool IsStmtExpr) {
1365 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1366 IsStmtExpr);
1367 }
1368
1369 /// Build a new case statement.
1370 ///
1371 /// By default, performs semantic analysis to build the new statement.
1372 /// Subclasses may override this routine to provide different behavior.
1374 Expr *LHS,
1375 SourceLocation EllipsisLoc,
1376 Expr *RHS,
1377 SourceLocation ColonLoc) {
1378 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1379 ColonLoc);
1380 }
1381
1382 /// Attach the body to a new case statement.
1383 ///
1384 /// By default, performs semantic analysis to build the new statement.
1385 /// Subclasses may override this routine to provide different behavior.
1387 getSema().ActOnCaseStmtBody(S, Body);
1388 return S;
1389 }
1390
1391 /// Build a new default statement.
1392 ///
1393 /// By default, performs semantic analysis to build the new statement.
1394 /// Subclasses may override this routine to provide different behavior.
1396 SourceLocation ColonLoc,
1397 Stmt *SubStmt) {
1398 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1399 /*CurScope=*/nullptr);
1400 }
1401
1402 /// Build a new label statement.
1403 ///
1404 /// By default, performs semantic analysis to build the new statement.
1405 /// Subclasses may override this routine to provide different behavior.
1407 SourceLocation ColonLoc, Stmt *SubStmt) {
1408 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1409 }
1410
1411 /// Build a new attributed statement.
1412 ///
1413 /// By default, performs semantic analysis to build the new statement.
1414 /// Subclasses may override this routine to provide different behavior.
1417 Stmt *SubStmt) {
1418 if (SemaRef.CheckRebuiltStmtAttributes(Attrs))
1419 return StmtError();
1420 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1421 }
1422
1423 /// Build a new "if" statement.
1424 ///
1425 /// By default, performs semantic analysis to build the new statement.
1426 /// Subclasses may override this routine to provide different behavior.
1429 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1430 SourceLocation ElseLoc, Stmt *Else) {
1431 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1432 Then, ElseLoc, Else);
1433 }
1434
1435 /// Start building a new switch statement.
1436 ///
1437 /// By default, performs semantic analysis to build the new statement.
1438 /// Subclasses may override this routine to provide different behavior.
1440 SourceLocation LParenLoc, Stmt *Init,
1442 SourceLocation RParenLoc) {
1443 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1444 RParenLoc);
1445 }
1446
1447 /// Attach the body to the switch statement.
1448 ///
1449 /// By default, performs semantic analysis to build the new statement.
1450 /// Subclasses may override this routine to provide different behavior.
1452 Stmt *Switch, Stmt *Body) {
1453 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1454 }
1455
1456 /// Build a new while statement.
1457 ///
1458 /// By default, performs semantic analysis to build the new statement.
1459 /// Subclasses may override this routine to provide different behavior.
1462 SourceLocation RParenLoc, Stmt *Body) {
1463 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1464 }
1465
1466 /// Build a new do-while statement.
1467 ///
1468 /// By default, performs semantic analysis to build the new statement.
1469 /// Subclasses may override this routine to provide different behavior.
1471 SourceLocation WhileLoc, SourceLocation LParenLoc,
1472 Expr *Cond, SourceLocation RParenLoc) {
1473 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1474 Cond, RParenLoc);
1475 }
1476
1477 /// Build a new for statement.
1478 ///
1479 /// By default, performs semantic analysis to build the new statement.
1480 /// Subclasses may override this routine to provide different behavior.
1483 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1484 Stmt *Body) {
1485 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1486 Inc, RParenLoc, Body);
1487 }
1488
1489 /// Build a new goto statement.
1490 ///
1491 /// By default, performs semantic analysis to build the new statement.
1492 /// Subclasses may override this routine to provide different behavior.
1494 LabelDecl *Label) {
1495 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1496 }
1497
1498 /// Build a new indirect goto statement.
1499 ///
1500 /// By default, performs semantic analysis to build the new statement.
1501 /// Subclasses may override this routine to provide different behavior.
1503 SourceLocation StarLoc,
1504 Expr *Target) {
1505 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1506 }
1507
1508 /// Build a new return statement.
1509 ///
1510 /// By default, performs semantic analysis to build the new statement.
1511 /// Subclasses may override this routine to provide different behavior.
1513 return getSema().BuildReturnStmt(ReturnLoc, Result);
1514 }
1515
1516 /// Build a new declaration statement.
1517 ///
1518 /// By default, performs semantic analysis to build the new statement.
1519 /// Subclasses may override this routine to provide different behavior.
1521 SourceLocation StartLoc, SourceLocation EndLoc) {
1523 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1524 }
1525
1526 /// Build a new inline asm statement.
1527 ///
1528 /// By default, performs semantic analysis to build the new statement.
1529 /// Subclasses may override this routine to provide different behavior.
1531 bool IsVolatile, unsigned NumOutputs,
1532 unsigned NumInputs, IdentifierInfo **Names,
1533 MultiExprArg Constraints, MultiExprArg Exprs,
1534 Expr *AsmString, MultiExprArg Clobbers,
1535 unsigned NumLabels,
1536 SourceLocation RParenLoc) {
1537 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1538 NumInputs, Names, Constraints, Exprs,
1539 AsmString, Clobbers, NumLabels, RParenLoc);
1540 }
1541
1542 /// Build a new MS style inline asm statement.
1543 ///
1544 /// By default, performs semantic analysis to build the new statement.
1545 /// Subclasses may override this routine to provide different behavior.
1547 ArrayRef<Token> AsmToks,
1548 StringRef AsmString,
1549 unsigned NumOutputs, unsigned NumInputs,
1550 ArrayRef<StringRef> Constraints,
1551 ArrayRef<StringRef> Clobbers,
1552 ArrayRef<Expr*> Exprs,
1553 SourceLocation EndLoc) {
1554 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1555 NumOutputs, NumInputs,
1556 Constraints, Clobbers, Exprs, EndLoc);
1557 }
1558
1559 /// Build a new co_return statement.
1560 ///
1561 /// By default, performs semantic analysis to build the new statement.
1562 /// Subclasses may override this routine to provide different behavior.
1564 bool IsImplicit) {
1565 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1566 }
1567
1568 /// Build a new co_await expression.
1569 ///
1570 /// By default, performs semantic analysis to build the new expression.
1571 /// Subclasses may override this routine to provide different behavior.
1573 UnresolvedLookupExpr *OpCoawaitLookup,
1574 bool IsImplicit) {
1575 // This function rebuilds a coawait-expr given its operator.
1576 // For an explicit coawait-expr, the rebuild involves the full set
1577 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1578 // including calling await_transform().
1579 // For an implicit coawait-expr, we need to rebuild the "operator
1580 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1581 // This mirrors how the implicit CoawaitExpr is originally created
1582 // in Sema::ActOnCoroutineBodyStart().
1583 if (IsImplicit) {
1585 CoawaitLoc, Operand, OpCoawaitLookup);
1586 if (Suspend.isInvalid())
1587 return ExprError();
1588 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1589 Suspend.get(), true);
1590 }
1591
1592 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1593 OpCoawaitLookup);
1594 }
1595
1596 /// Build a new co_await expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
1601 Expr *Result,
1602 UnresolvedLookupExpr *Lookup) {
1603 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1604 }
1605
1606 /// Build a new co_yield expression.
1607 ///
1608 /// By default, performs semantic analysis to build the new expression.
1609 /// Subclasses may override this routine to provide different behavior.
1611 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1612 }
1613
1617
1618 /// Build a new Objective-C \@try statement.
1619 ///
1620 /// By default, performs semantic analysis to build the new statement.
1621 /// Subclasses may override this routine to provide different behavior.
1623 Stmt *TryBody,
1624 MultiStmtArg CatchStmts,
1625 Stmt *Finally) {
1626 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1627 Finally);
1628 }
1629
1630 /// Rebuild an Objective-C exception declaration.
1631 ///
1632 /// By default, performs semantic analysis to build the new declaration.
1633 /// Subclasses may override this routine to provide different behavior.
1635 TypeSourceInfo *TInfo, QualType T) {
1637 TInfo, T, ExceptionDecl->getInnerLocStart(),
1638 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1639 }
1640
1641 /// Build a new Objective-C \@catch statement.
1642 ///
1643 /// By default, performs semantic analysis to build the new statement.
1644 /// Subclasses may override this routine to provide different behavior.
1646 SourceLocation RParenLoc,
1647 VarDecl *Var,
1648 Stmt *Body) {
1649 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1650 }
1651
1652 /// Build a new Objective-C \@finally statement.
1653 ///
1654 /// By default, performs semantic analysis to build the new statement.
1655 /// Subclasses may override this routine to provide different behavior.
1657 Stmt *Body) {
1658 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1659 }
1660
1661 /// Build a new Objective-C \@throw statement.
1662 ///
1663 /// By default, performs semantic analysis to build the new statement.
1664 /// Subclasses may override this routine to provide different behavior.
1666 Expr *Operand) {
1667 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1668 }
1669
1670 /// Build a new OpenMP Canonical loop.
1671 ///
1672 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1673 /// OMPCanonicalLoop.
1675 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1676 }
1677
1678 /// Build a new OpenMP executable directive.
1679 ///
1680 /// By default, performs semantic analysis to build the new statement.
1681 /// Subclasses may override this routine to provide different behavior.
1683 DeclarationNameInfo DirName,
1684 OpenMPDirectiveKind CancelRegion,
1685 ArrayRef<OMPClause *> Clauses,
1686 Stmt *AStmt, SourceLocation StartLoc,
1687 SourceLocation EndLoc) {
1688
1690 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1691 }
1692
1693 /// Build a new OpenMP informational directive.
1695 DeclarationNameInfo DirName,
1696 ArrayRef<OMPClause *> Clauses,
1697 Stmt *AStmt,
1698 SourceLocation StartLoc,
1699 SourceLocation EndLoc) {
1700
1702 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1703 }
1704
1705 /// Build a new OpenMP 'if' clause.
1706 ///
1707 /// By default, performs semantic analysis to build the new OpenMP clause.
1708 /// Subclasses may override this routine to provide different behavior.
1710 Expr *Condition, SourceLocation StartLoc,
1711 SourceLocation LParenLoc,
1712 SourceLocation NameModifierLoc,
1713 SourceLocation ColonLoc,
1714 SourceLocation EndLoc) {
1716 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1717 EndLoc);
1718 }
1719
1720 /// Build a new OpenMP 'final' clause.
1721 ///
1722 /// By default, performs semantic analysis to build the new OpenMP clause.
1723 /// Subclasses may override this routine to provide different behavior.
1725 SourceLocation LParenLoc,
1726 SourceLocation EndLoc) {
1727 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1728 LParenLoc, EndLoc);
1729 }
1730
1731 /// Build a new OpenMP 'num_threads' clause.
1732 ///
1733 /// By default, performs semantic analysis to build the new OpenMP clause.
1734 /// Subclasses may override this routine to provide different behavior.
1736 Expr *NumThreads,
1737 SourceLocation StartLoc,
1738 SourceLocation LParenLoc,
1739 SourceLocation ModifierLoc,
1740 SourceLocation EndLoc) {
1742 Modifier, NumThreads, StartLoc, LParenLoc, ModifierLoc, EndLoc);
1743 }
1744
1745 /// Build a new OpenMP 'safelen' clause.
1746 ///
1747 /// By default, performs semantic analysis to build the new OpenMP clause.
1748 /// Subclasses may override this routine to provide different behavior.
1750 SourceLocation LParenLoc,
1751 SourceLocation EndLoc) {
1752 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1753 EndLoc);
1754 }
1755
1756 /// Build a new OpenMP 'simdlen' clause.
1757 ///
1758 /// By default, performs semantic analysis to build the new OpenMP clause.
1759 /// Subclasses may override this routine to provide different behavior.
1761 SourceLocation LParenLoc,
1762 SourceLocation EndLoc) {
1763 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1764 EndLoc);
1765 }
1766
1768 SourceLocation StartLoc,
1769 SourceLocation LParenLoc,
1770 SourceLocation EndLoc) {
1771 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1772 EndLoc);
1773 }
1774
1776 SourceLocation StartLoc,
1777 SourceLocation LParenLoc,
1778 SourceLocation EndLoc,
1779 std::optional<unsigned> FillIdx,
1780 SourceLocation FillLoc) {
1781 unsigned FillCount = FillIdx ? 1 : 0;
1783 Counts, StartLoc, LParenLoc, EndLoc, FillIdx, FillLoc, FillCount);
1784 }
1785
1786 /// Build a new OpenMP 'permutation' clause.
1788 SourceLocation StartLoc,
1789 SourceLocation LParenLoc,
1790 SourceLocation EndLoc) {
1791 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1792 LParenLoc, EndLoc);
1793 }
1794
1795 /// Build a new OpenMP 'full' clause.
1797 SourceLocation EndLoc) {
1798 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1799 }
1800
1801 /// Build a new OpenMP 'partial' clause.
1803 SourceLocation LParenLoc,
1804 SourceLocation EndLoc) {
1805 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1806 LParenLoc, EndLoc);
1807 }
1808
1809 OMPClause *
1811 SourceLocation LParenLoc, SourceLocation FirstLoc,
1812 SourceLocation CountLoc, SourceLocation EndLoc) {
1814 First, Count, StartLoc, LParenLoc, FirstLoc, CountLoc, EndLoc);
1815 }
1816
1817 /// Build a new OpenMP 'allocator' clause.
1818 ///
1819 /// By default, performs semantic analysis to build the new OpenMP clause.
1820 /// Subclasses may override this routine to provide different behavior.
1822 SourceLocation LParenLoc,
1823 SourceLocation EndLoc) {
1824 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1825 EndLoc);
1826 }
1827
1828 /// Build a new OpenMP 'collapse' clause.
1829 ///
1830 /// By default, performs semantic analysis to build the new OpenMP clause.
1831 /// Subclasses may override this routine to provide different behavior.
1833 SourceLocation LParenLoc,
1834 SourceLocation EndLoc) {
1835 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1836 LParenLoc, EndLoc);
1837 }
1838
1839 /// Build a new OpenMP 'default' clause.
1840 ///
1841 /// By default, performs semantic analysis to build the new OpenMP clause.
1842 /// Subclasses may override this routine to provide different behavior.
1845 SourceLocation VCLoc,
1846 SourceLocation StartLoc,
1847 SourceLocation LParenLoc,
1848 SourceLocation EndLoc) {
1850 Kind, KindKwLoc, VCKind, VCLoc, StartLoc, LParenLoc, EndLoc);
1851 }
1852
1853 /// Build a new OpenMP 'proc_bind' clause.
1854 ///
1855 /// By default, performs semantic analysis to build the new OpenMP clause.
1856 /// Subclasses may override this routine to provide different behavior.
1858 SourceLocation KindKwLoc,
1859 SourceLocation StartLoc,
1860 SourceLocation LParenLoc,
1861 SourceLocation EndLoc) {
1863 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1864 }
1866 SourceLocation StartLoc,
1867 SourceLocation LParenLoc,
1868 SourceLocation EndLoc) {
1870 ImpexTypeArg, StartLoc, LParenLoc, EndLoc);
1871 }
1872
1873 /// Build a new OpenMP 'schedule' clause.
1874 ///
1875 /// By default, performs semantic analysis to build the new OpenMP clause.
1876 /// Subclasses may override this routine to provide different behavior.
1879 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1880 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1881 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1883 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1884 CommaLoc, EndLoc);
1885 }
1886
1887 /// Build a new OpenMP 'ordered' clause.
1888 ///
1889 /// By default, performs semantic analysis to build the new OpenMP clause.
1890 /// Subclasses may override this routine to provide different behavior.
1892 SourceLocation EndLoc,
1893 SourceLocation LParenLoc, Expr *Num) {
1894 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1895 LParenLoc, Num);
1896 }
1897
1898 /// Build a new OpenMP 'nowait' clause.
1899 ///
1900 /// By default, performs semantic analysis to build the new OpenMP clause.
1901 /// Subclasses may override this routine to provide different behavior.
1903 SourceLocation LParenLoc,
1904 SourceLocation EndLoc) {
1905 return getSema().OpenMP().ActOnOpenMPNowaitClause(StartLoc, EndLoc,
1906 LParenLoc, Condition);
1907 }
1908
1909 /// Build a new OpenMP 'private' clause.
1910 ///
1911 /// By default, performs semantic analysis to build the new OpenMP clause.
1912 /// Subclasses may override this routine to provide different behavior.
1914 SourceLocation StartLoc,
1915 SourceLocation LParenLoc,
1916 SourceLocation EndLoc) {
1917 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1918 LParenLoc, EndLoc);
1919 }
1920
1921 /// Build a new OpenMP 'firstprivate' clause.
1922 ///
1923 /// By default, performs semantic analysis to build the new OpenMP clause.
1924 /// Subclasses may override this routine to provide different behavior.
1926 SourceLocation StartLoc,
1927 SourceLocation LParenLoc,
1928 SourceLocation EndLoc) {
1929 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1930 LParenLoc, EndLoc);
1931 }
1932
1933 /// Build a new OpenMP 'lastprivate' clause.
1934 ///
1935 /// By default, performs semantic analysis to build the new OpenMP clause.
1936 /// Subclasses may override this routine to provide different behavior.
1939 SourceLocation LPKindLoc,
1940 SourceLocation ColonLoc,
1941 SourceLocation StartLoc,
1942 SourceLocation LParenLoc,
1943 SourceLocation EndLoc) {
1945 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1946 }
1947
1948 /// Build a new OpenMP 'shared' clause.
1949 ///
1950 /// By default, performs semantic analysis to build the new OpenMP clause.
1951 /// Subclasses may override this routine to provide different behavior.
1953 SourceLocation StartLoc,
1954 SourceLocation LParenLoc,
1955 SourceLocation EndLoc) {
1956 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1957 LParenLoc, EndLoc);
1958 }
1959
1960 /// Build a new OpenMP 'reduction' clause.
1961 ///
1962 /// By default, performs semantic analysis to build the new statement.
1963 /// Subclasses may override this routine to provide different behavior.
1966 OpenMPOriginalSharingModifier OriginalSharingModifier,
1967 SourceLocation StartLoc, SourceLocation LParenLoc,
1968 SourceLocation ModifierLoc, SourceLocation ColonLoc,
1969 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
1970 const DeclarationNameInfo &ReductionId,
1971 ArrayRef<Expr *> UnresolvedReductions) {
1973 VarList, {Modifier, OriginalSharingModifier}, StartLoc, LParenLoc,
1974 ModifierLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, ReductionId,
1975 UnresolvedReductions);
1976 }
1977
1978 /// Build a new OpenMP 'task_reduction' clause.
1979 ///
1980 /// By default, performs semantic analysis to build the new statement.
1981 /// Subclasses may override this routine to provide different behavior.
1983 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
1984 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
1985 CXXScopeSpec &ReductionIdScopeSpec,
1986 const DeclarationNameInfo &ReductionId,
1987 ArrayRef<Expr *> UnresolvedReductions) {
1989 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1990 ReductionId, UnresolvedReductions);
1991 }
1992
1993 /// Build a new OpenMP 'in_reduction' clause.
1994 ///
1995 /// By default, performs semantic analysis to build the new statement.
1996 /// Subclasses may override this routine to provide different behavior.
1997 OMPClause *
1999 SourceLocation LParenLoc, SourceLocation ColonLoc,
2000 SourceLocation EndLoc,
2001 CXXScopeSpec &ReductionIdScopeSpec,
2002 const DeclarationNameInfo &ReductionId,
2003 ArrayRef<Expr *> UnresolvedReductions) {
2005 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
2006 ReductionId, UnresolvedReductions);
2007 }
2008
2009 /// Build a new OpenMP 'linear' clause.
2010 ///
2011 /// By default, performs semantic analysis to build the new OpenMP clause.
2012 /// Subclasses may override this routine to provide different behavior.
2014 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
2015 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
2016 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2017 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
2019 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
2020 StepModifierLoc, EndLoc);
2021 }
2022
2023 /// Build a new OpenMP 'aligned' clause.
2024 ///
2025 /// By default, performs semantic analysis to build the new OpenMP clause.
2026 /// Subclasses may override this routine to provide different behavior.
2028 SourceLocation StartLoc,
2029 SourceLocation LParenLoc,
2030 SourceLocation ColonLoc,
2031 SourceLocation EndLoc) {
2033 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
2034 }
2035
2036 /// Build a new OpenMP 'copyin' clause.
2037 ///
2038 /// By default, performs semantic analysis to build the new OpenMP clause.
2039 /// Subclasses may override this routine to provide different behavior.
2041 SourceLocation StartLoc,
2042 SourceLocation LParenLoc,
2043 SourceLocation EndLoc) {
2044 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
2045 LParenLoc, EndLoc);
2046 }
2047
2048 /// Build a new OpenMP 'copyprivate' clause.
2049 ///
2050 /// By default, performs semantic analysis to build the new OpenMP clause.
2051 /// Subclasses may override this routine to provide different behavior.
2053 SourceLocation StartLoc,
2054 SourceLocation LParenLoc,
2055 SourceLocation EndLoc) {
2056 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2057 LParenLoc, EndLoc);
2058 }
2059
2060 /// Build a new OpenMP 'flush' pseudo clause.
2061 ///
2062 /// By default, performs semantic analysis to build the new OpenMP clause.
2063 /// Subclasses may override this routine to provide different behavior.
2065 SourceLocation StartLoc,
2066 SourceLocation LParenLoc,
2067 SourceLocation EndLoc) {
2068 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2069 LParenLoc, EndLoc);
2070 }
2071
2072 /// Build a new OpenMP 'depobj' pseudo clause.
2073 ///
2074 /// By default, performs semantic analysis to build the new OpenMP clause.
2075 /// Subclasses may override this routine to provide different behavior.
2077 SourceLocation LParenLoc,
2078 SourceLocation EndLoc) {
2079 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2080 LParenLoc, EndLoc);
2081 }
2082
2083 /// Build a new OpenMP 'depend' pseudo clause.
2084 ///
2085 /// By default, performs semantic analysis to build the new OpenMP clause.
2086 /// Subclasses may override this routine to provide different behavior.
2088 Expr *DepModifier, ArrayRef<Expr *> VarList,
2089 SourceLocation StartLoc,
2090 SourceLocation LParenLoc,
2091 SourceLocation EndLoc) {
2093 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2094 }
2095
2096 /// Build a new OpenMP 'device' clause.
2097 ///
2098 /// By default, performs semantic analysis to build the new statement.
2099 /// Subclasses may override this routine to provide different behavior.
2101 Expr *Device, SourceLocation StartLoc,
2102 SourceLocation LParenLoc,
2103 SourceLocation ModifierLoc,
2104 SourceLocation EndLoc) {
2106 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2107 }
2108
2109 /// Build a new OpenMP 'map' clause.
2110 ///
2111 /// By default, performs semantic analysis to build the new OpenMP clause.
2112 /// Subclasses may override this routine to provide different behavior.
2114 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2115 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2116 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2117 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2118 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2119 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2121 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2122 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2123 ColonLoc, VarList, Locs,
2124 /*NoDiagnose=*/false, UnresolvedMappers);
2125 }
2126
2127 /// Build a new OpenMP 'allocate' clause.
2128 ///
2129 /// By default, performs semantic analysis to build the new OpenMP clause.
2130 /// Subclasses may override this routine to provide different behavior.
2131 OMPClause *
2132 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2133 OpenMPAllocateClauseModifier FirstModifier,
2134 SourceLocation FirstModifierLoc,
2135 OpenMPAllocateClauseModifier SecondModifier,
2136 SourceLocation SecondModifierLoc,
2137 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2138 SourceLocation LParenLoc, SourceLocation ColonLoc,
2139 SourceLocation EndLoc) {
2141 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2142 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2143 }
2144
2145 /// Build a new OpenMP 'num_teams' clause.
2146 ///
2147 /// By default, performs semantic analysis to build the new statement.
2148 /// Subclasses may override this routine to provide different behavior.
2151 Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc,
2152 SourceLocation LParenLoc, SourceLocation EndLoc) {
2154 VarList, Modifier, ModifierExpr, ModifierLoc, StartLoc, LParenLoc,
2155 EndLoc);
2156 }
2157
2158 /// Build a new OpenMP 'thread_limit' clause.
2159 ///
2160 /// By default, performs semantic analysis to build the new statement.
2161 /// Subclasses may override this routine to provide different behavior.
2163 SourceLocation StartLoc,
2164 SourceLocation LParenLoc,
2165 SourceLocation EndLoc) {
2166 return getSema().OpenMP().ActOnOpenMPThreadLimitClause(VarList, StartLoc,
2167 LParenLoc, EndLoc);
2168 }
2169
2170 /// Build a new OpenMP 'priority' clause.
2171 ///
2172 /// By default, performs semantic analysis to build the new statement.
2173 /// Subclasses may override this routine to provide different behavior.
2175 SourceLocation LParenLoc,
2176 SourceLocation EndLoc) {
2177 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2178 LParenLoc, EndLoc);
2179 }
2180
2181 /// Build a new OpenMP 'grainsize' clause.
2182 ///
2183 /// By default, performs semantic analysis to build the new statement.
2184 /// Subclasses may override this routine to provide different behavior.
2186 Expr *Device, SourceLocation StartLoc,
2187 SourceLocation LParenLoc,
2188 SourceLocation ModifierLoc,
2189 SourceLocation EndLoc) {
2191 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2192 }
2193
2194 /// Build a new OpenMP 'num_tasks' clause.
2195 ///
2196 /// By default, performs semantic analysis to build the new statement.
2197 /// Subclasses may override this routine to provide different behavior.
2199 Expr *NumTasks, SourceLocation StartLoc,
2200 SourceLocation LParenLoc,
2201 SourceLocation ModifierLoc,
2202 SourceLocation EndLoc) {
2204 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2205 }
2206
2207 /// Build a new OpenMP 'hint' clause.
2208 ///
2209 /// By default, performs semantic analysis to build the new statement.
2210 /// Subclasses may override this routine to provide different behavior.
2212 SourceLocation LParenLoc,
2213 SourceLocation EndLoc) {
2214 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2215 EndLoc);
2216 }
2217
2218 /// Build a new OpenMP 'detach' clause.
2219 ///
2220 /// By default, performs semantic analysis to build the new statement.
2221 /// Subclasses may override this routine to provide different behavior.
2223 SourceLocation LParenLoc,
2224 SourceLocation EndLoc) {
2225 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2226 EndLoc);
2227 }
2228
2229 /// Build a new OpenMP 'dist_schedule' clause.
2230 ///
2231 /// By default, performs semantic analysis to build the new OpenMP clause.
2232 /// Subclasses may override this routine to provide different behavior.
2233 OMPClause *
2235 Expr *ChunkSize, SourceLocation StartLoc,
2236 SourceLocation LParenLoc, SourceLocation KindLoc,
2237 SourceLocation CommaLoc, SourceLocation EndLoc) {
2239 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2240 }
2241
2242 /// Build a new OpenMP 'to' clause.
2243 ///
2244 /// By default, performs semantic analysis to build the new statement.
2245 /// Subclasses may override this routine to provide different behavior.
2246 OMPClause *
2248 ArrayRef<SourceLocation> MotionModifiersLoc,
2249 Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
2250 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2251 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2252 ArrayRef<Expr *> UnresolvedMappers) {
2254 MotionModifiers, MotionModifiersLoc, IteratorModifier,
2255 MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs,
2256 UnresolvedMappers);
2257 }
2258
2259 /// Build a new OpenMP 'from' clause.
2260 ///
2261 /// By default, performs semantic analysis to build the new statement.
2262 /// Subclasses may override this routine to provide different behavior.
2263 OMPClause *
2265 ArrayRef<SourceLocation> MotionModifiersLoc,
2266 Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
2267 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2268 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2269 ArrayRef<Expr *> UnresolvedMappers) {
2271 MotionModifiers, MotionModifiersLoc, IteratorModifier,
2272 MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs,
2273 UnresolvedMappers);
2274 }
2275
2276 /// Build a new OpenMP 'use_device_ptr' clause.
2277 ///
2278 /// By default, performs semantic analysis to build the new OpenMP clause.
2279 /// Subclasses may override this routine to provide different behavior.
2281 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2282 OpenMPUseDevicePtrFallbackModifier FallbackModifier,
2283 SourceLocation FallbackModifierLoc) {
2285 VarList, Locs, FallbackModifier, FallbackModifierLoc);
2286 }
2287
2288 /// Build a new OpenMP 'use_device_addr' clause.
2289 ///
2290 /// By default, performs semantic analysis to build the new OpenMP clause.
2291 /// Subclasses may override this routine to provide different behavior.
2296
2297 /// Build a new OpenMP 'is_device_ptr' clause.
2298 ///
2299 /// By default, performs semantic analysis to build the new OpenMP clause.
2300 /// Subclasses may override this routine to provide different behavior.
2302 const OMPVarListLocTy &Locs) {
2303 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2304 }
2305
2306 /// Build a new OpenMP 'has_device_addr' clause.
2307 ///
2308 /// By default, performs semantic analysis to build the new OpenMP clause.
2309 /// Subclasses may override this routine to provide different behavior.
2314
2315 /// Build a new OpenMP 'defaultmap' clause.
2316 ///
2317 /// By default, performs semantic analysis to build the new OpenMP clause.
2318 /// Subclasses may override this routine to provide different behavior.
2321 SourceLocation StartLoc,
2322 SourceLocation LParenLoc,
2323 SourceLocation MLoc,
2324 SourceLocation KindLoc,
2325 SourceLocation EndLoc) {
2327 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2328 }
2329
2330 /// Build a new OpenMP 'nontemporal' clause.
2331 ///
2332 /// By default, performs semantic analysis to build the new OpenMP clause.
2333 /// Subclasses may override this routine to provide different behavior.
2335 SourceLocation StartLoc,
2336 SourceLocation LParenLoc,
2337 SourceLocation EndLoc) {
2338 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2339 LParenLoc, EndLoc);
2340 }
2341
2342 /// Build a new OpenMP 'inclusive' clause.
2343 ///
2344 /// By default, performs semantic analysis to build the new OpenMP clause.
2345 /// Subclasses may override this routine to provide different behavior.
2347 SourceLocation StartLoc,
2348 SourceLocation LParenLoc,
2349 SourceLocation EndLoc) {
2350 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2351 LParenLoc, EndLoc);
2352 }
2353
2354 /// Build a new OpenMP 'exclusive' clause.
2355 ///
2356 /// By default, performs semantic analysis to build the new OpenMP clause.
2357 /// Subclasses may override this routine to provide different behavior.
2359 SourceLocation StartLoc,
2360 SourceLocation LParenLoc,
2361 SourceLocation EndLoc) {
2362 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2363 LParenLoc, EndLoc);
2364 }
2365
2366 /// Build a new OpenMP 'uses_allocators' clause.
2367 ///
2368 /// By default, performs semantic analysis to build the new OpenMP clause.
2369 /// Subclasses may override this routine to provide different behavior.
2376
2377 /// Build a new OpenMP 'affinity' clause.
2378 ///
2379 /// By default, performs semantic analysis to build the new OpenMP clause.
2380 /// Subclasses may override this routine to provide different behavior.
2382 SourceLocation LParenLoc,
2383 SourceLocation ColonLoc,
2384 SourceLocation EndLoc, Expr *Modifier,
2385 ArrayRef<Expr *> Locators) {
2387 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2388 }
2389
2390 /// Build a new OpenMP 'order' clause.
2391 ///
2392 /// By default, performs semantic analysis to build the new OpenMP clause.
2393 /// Subclasses may override this routine to provide different behavior.
2395 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2396 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2397 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2399 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2400 }
2401
2402 /// Build a new OpenMP 'init' clause.
2403 ///
2404 /// By default, performs semantic analysis to build the new OpenMP clause.
2405 /// Subclasses may override this routine to provide different behavior.
2407 SourceLocation StartLoc,
2408 SourceLocation LParenLoc,
2409 SourceLocation VarLoc,
2410 SourceLocation EndLoc) {
2412 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2413 }
2414
2415 /// Build a new OpenMP 'use' clause.
2416 ///
2417 /// By default, performs semantic analysis to build the new OpenMP clause.
2418 /// Subclasses may override this routine to provide different behavior.
2420 SourceLocation LParenLoc,
2421 SourceLocation VarLoc, SourceLocation EndLoc) {
2422 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2423 LParenLoc, VarLoc, EndLoc);
2424 }
2425
2426 /// Build a new OpenMP 'destroy' clause.
2427 ///
2428 /// By default, performs semantic analysis to build the new OpenMP clause.
2429 /// Subclasses may override this routine to provide different behavior.
2431 SourceLocation LParenLoc,
2432 SourceLocation VarLoc,
2433 SourceLocation EndLoc) {
2435 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2436 }
2437
2438 /// Build a new OpenMP 'novariants' clause.
2439 ///
2440 /// By default, performs semantic analysis to build the new OpenMP clause.
2441 /// Subclasses may override this routine to provide different behavior.
2443 SourceLocation StartLoc,
2444 SourceLocation LParenLoc,
2445 SourceLocation EndLoc) {
2447 LParenLoc, EndLoc);
2448 }
2449
2450 /// Build a new OpenMP 'nocontext' clause.
2451 ///
2452 /// By default, performs semantic analysis to build the new OpenMP clause.
2453 /// Subclasses may override this routine to provide different behavior.
2455 SourceLocation LParenLoc,
2456 SourceLocation EndLoc) {
2458 LParenLoc, EndLoc);
2459 }
2460
2461 /// Build a new OpenMP 'filter' clause.
2462 ///
2463 /// By default, performs semantic analysis to build the new OpenMP clause.
2464 /// Subclasses may override this routine to provide different behavior.
2466 SourceLocation LParenLoc,
2467 SourceLocation EndLoc) {
2468 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2469 LParenLoc, EndLoc);
2470 }
2471
2472 /// Build a new OpenMP 'bind' clause.
2473 ///
2474 /// By default, performs semantic analysis to build the new OpenMP clause.
2475 /// Subclasses may override this routine to provide different behavior.
2477 SourceLocation KindLoc,
2478 SourceLocation StartLoc,
2479 SourceLocation LParenLoc,
2480 SourceLocation EndLoc) {
2481 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2482 LParenLoc, EndLoc);
2483 }
2484
2485 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2486 ///
2487 /// By default, performs semantic analysis to build the new OpenMP clause.
2488 /// Subclasses may override this routine to provide different behavior.
2490 SourceLocation LParenLoc,
2491 SourceLocation EndLoc) {
2492 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2493 LParenLoc, EndLoc);
2494 }
2495
2496 /// Build a new OpenMP 'dyn_groupprivate' clause.
2497 ///
2498 /// By default, performs semantic analysis to build the new OpenMP clause.
2499 /// Subclasses may override this routine to provide different behavior.
2503 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc,
2504 SourceLocation M2Loc, SourceLocation EndLoc) {
2506 M1, M2, Size, StartLoc, LParenLoc, M1Loc, M2Loc, EndLoc);
2507 }
2508
2509 /// Build a new OpenMP 'ompx_attribute' clause.
2510 ///
2511 /// By default, performs semantic analysis to build the new OpenMP clause.
2512 /// Subclasses may override this routine to provide different behavior.
2514 SourceLocation StartLoc,
2515 SourceLocation LParenLoc,
2516 SourceLocation EndLoc) {
2517 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2518 LParenLoc, EndLoc);
2519 }
2520
2521 /// Build a new OpenMP 'ompx_bare' clause.
2522 ///
2523 /// By default, performs semantic analysis to build the new OpenMP clause.
2524 /// Subclasses may override this routine to provide different behavior.
2526 SourceLocation EndLoc) {
2527 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2528 }
2529
2530 /// Build a new OpenMP 'align' clause.
2531 ///
2532 /// By default, performs semantic analysis to build the new OpenMP clause.
2533 /// Subclasses may override this routine to provide different behavior.
2535 SourceLocation LParenLoc,
2536 SourceLocation EndLoc) {
2537 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2538 EndLoc);
2539 }
2540
2541 /// Build a new OpenMP 'at' clause.
2542 ///
2543 /// By default, performs semantic analysis to build the new OpenMP clause.
2544 /// Subclasses may override this routine to provide different behavior.
2546 SourceLocation StartLoc,
2547 SourceLocation LParenLoc,
2548 SourceLocation EndLoc) {
2549 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2550 LParenLoc, EndLoc);
2551 }
2552
2553 /// Build a new OpenMP 'severity' clause.
2554 ///
2555 /// By default, performs semantic analysis to build the new OpenMP clause.
2556 /// Subclasses may override this routine to provide different behavior.
2558 SourceLocation KwLoc,
2559 SourceLocation StartLoc,
2560 SourceLocation LParenLoc,
2561 SourceLocation EndLoc) {
2562 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2563 LParenLoc, EndLoc);
2564 }
2565
2566 /// Build a new OpenMP 'message' clause.
2567 ///
2568 /// By default, performs semantic analysis to build the new OpenMP clause.
2569 /// Subclasses may override this routine to provide different behavior.
2571 SourceLocation LParenLoc,
2572 SourceLocation EndLoc) {
2573 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2574 EndLoc);
2575 }
2576
2577 /// Build a new OpenMP 'doacross' clause.
2578 ///
2579 /// By default, performs semantic analysis to build the new OpenMP clause.
2580 /// Subclasses may override this routine to provide different behavior.
2581 OMPClause *
2583 SourceLocation DepLoc, SourceLocation ColonLoc,
2584 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2585 SourceLocation LParenLoc, SourceLocation EndLoc) {
2587 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2588 }
2589
2590 /// Build a new OpenMP 'holds' clause.
2592 SourceLocation LParenLoc,
2593 SourceLocation EndLoc) {
2594 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2595 EndLoc);
2596 }
2597
2598 /// Rebuild the operand to an Objective-C \@synchronized statement.
2599 ///
2600 /// By default, performs semantic analysis to build the new statement.
2601 /// Subclasses may override this routine to provide different behavior.
2606
2607 /// Build a new Objective-C \@synchronized statement.
2608 ///
2609 /// By default, performs semantic analysis to build the new statement.
2610 /// Subclasses may override this routine to provide different behavior.
2615
2616 /// Build a new Objective-C \@autoreleasepool statement.
2617 ///
2618 /// By default, performs semantic analysis to build the new statement.
2619 /// Subclasses may override this routine to provide different behavior.
2624
2625 /// Build a new Objective-C fast enumeration statement.
2626 ///
2627 /// By default, performs semantic analysis to build the new statement.
2628 /// Subclasses may override this routine to provide different behavior.
2630 Stmt *Element,
2631 Expr *Collection,
2632 SourceLocation RParenLoc,
2633 Stmt *Body) {
2635 ForLoc, Element, Collection, RParenLoc);
2636 if (ForEachStmt.isInvalid())
2637 return StmtError();
2638
2639 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2640 Body);
2641 }
2642
2643 /// Build a new C++ exception declaration.
2644 ///
2645 /// By default, performs semantic analysis to build the new decaration.
2646 /// Subclasses may override this routine to provide different behavior.
2649 SourceLocation StartLoc,
2650 SourceLocation IdLoc,
2651 IdentifierInfo *Id) {
2653 StartLoc, IdLoc, Id);
2654 if (Var)
2655 getSema().CurContext->addDecl(Var);
2656 return Var;
2657 }
2658
2659 /// Build a new C++ catch statement.
2660 ///
2661 /// By default, performs semantic analysis to build the new statement.
2662 /// Subclasses may override this routine to provide different behavior.
2664 VarDecl *ExceptionDecl,
2665 Stmt *Handler) {
2666 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2667 Handler));
2668 }
2669
2670 /// Build a new C++ try statement.
2671 ///
2672 /// By default, performs semantic analysis to build the new statement.
2673 /// Subclasses may override this routine to provide different behavior.
2675 ArrayRef<Stmt *> Handlers) {
2676 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2677 }
2678
2679 /// Build a new C++0x range-based for statement.
2680 ///
2681 /// By default, performs semantic analysis to build the new statement.
2682 /// Subclasses may override this routine to provide different behavior.
2684 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2685 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2686 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2687 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2688 // If we've just learned that the range is actually an Objective-C
2689 // collection, treat this as an Objective-C fast enumeration loop.
2690 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2691 if (RangeStmt->isSingleDecl()) {
2692 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2693 if (RangeVar->isInvalidDecl())
2694 return StmtError();
2695
2696 Expr *RangeExpr = RangeVar->getInit();
2697 if (!RangeExpr->isTypeDependent() &&
2698 RangeExpr->getType()->isObjCObjectPointerType()) {
2699 // FIXME: Support init-statements in Objective-C++20 ranged for
2700 // statement.
2701 if (Init) {
2702 return SemaRef.Diag(Init->getBeginLoc(),
2703 diag::err_objc_for_range_init_stmt)
2704 << Init->getSourceRange();
2705 }
2707 ForLoc, LoopVar, RangeExpr, RParenLoc);
2708 }
2709 }
2710 }
2711 }
2712
2714 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2715 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2716 }
2717
2718 /// Build a new C++0x range-based for statement.
2719 ///
2720 /// By default, performs semantic analysis to build the new statement.
2721 /// Subclasses may override this routine to provide different behavior.
2723 bool IsIfExists,
2724 NestedNameSpecifierLoc QualifierLoc,
2725 DeclarationNameInfo NameInfo,
2726 Stmt *Nested) {
2727 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2728 QualifierLoc, NameInfo, Nested);
2729 }
2730
2731 /// Attach body to a C++0x range-based for statement.
2732 ///
2733 /// By default, performs semantic analysis to finish the new statement.
2734 /// Subclasses may override this routine to provide different behavior.
2736 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2737 }
2738
2740 Stmt *TryBlock, Stmt *Handler) {
2741 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2742 }
2743
2745 Stmt *Block) {
2746 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2747 }
2748
2750 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2751 }
2752
2754 SourceLocation LParen,
2755 SourceLocation RParen,
2756 TypeSourceInfo *TSI) {
2757 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2758 TSI);
2759 }
2760
2761 /// Build a new predefined expression.
2762 ///
2763 /// By default, performs semantic analysis to build the new expression.
2764 /// Subclasses may override this routine to provide different behavior.
2768
2769 /// Build a new expression that references a declaration.
2770 ///
2771 /// By default, performs semantic analysis to build the new expression.
2772 /// Subclasses may override this routine to provide different behavior.
2774 LookupResult &R,
2775 bool RequiresADL) {
2776 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2777 }
2778
2779
2780 /// Build a new expression that references a declaration.
2781 ///
2782 /// By default, performs semantic analysis to build the new expression.
2783 /// Subclasses may override this routine to provide different behavior.
2785 ValueDecl *VD,
2786 const DeclarationNameInfo &NameInfo,
2788 TemplateArgumentListInfo *TemplateArgs) {
2789 CXXScopeSpec SS;
2790 SS.Adopt(QualifierLoc);
2791 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2792 TemplateArgs);
2793 }
2794
2795 /// Build a new expression in parentheses.
2796 ///
2797 /// By default, performs semantic analysis to build the new expression.
2798 /// Subclasses may override this routine to provide different behavior.
2800 SourceLocation RParen) {
2801 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2802 }
2803
2804 /// Build a new pseudo-destructor expression.
2805 ///
2806 /// By default, performs semantic analysis to build the new expression.
2807 /// Subclasses may override this routine to provide different behavior.
2809 SourceLocation OperatorLoc,
2810 bool isArrow,
2811 CXXScopeSpec &SS,
2812 TypeSourceInfo *ScopeType,
2813 SourceLocation CCLoc,
2814 SourceLocation TildeLoc,
2815 PseudoDestructorTypeStorage Destroyed);
2816
2817 /// Build a new unary operator expression.
2818 ///
2819 /// By default, performs semantic analysis to build the new expression.
2820 /// Subclasses may override this routine to provide different behavior.
2823 Expr *SubExpr) {
2824 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2825 }
2826
2827 /// Build a new builtin offsetof expression.
2828 ///
2829 /// By default, performs semantic analysis to build the new expression.
2830 /// Subclasses may override this routine to provide different behavior.
2832 TypeSourceInfo *Type, const Designation &Desig,
2833 SourceLocation RParenLoc) {
2834 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Desig, RParenLoc);
2835 }
2836
2837 /// Build a new sizeof, alignof or vec_step expression with a
2838 /// type argument.
2839 ///
2840 /// By default, performs semantic analysis to build the new expression.
2841 /// Subclasses may override this routine to provide different behavior.
2843 SourceLocation OpLoc,
2844 UnaryExprOrTypeTrait ExprKind,
2845 SourceRange R) {
2846 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2847 }
2848
2849 /// Build a new sizeof, alignof or vec step expression with an
2850 /// expression argument.
2851 ///
2852 /// By default, performs semantic analysis to build the new expression.
2853 /// Subclasses may override this routine to provide different behavior.
2855 UnaryExprOrTypeTrait ExprKind,
2856 SourceRange R) {
2858 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2859 if (Result.isInvalid())
2860 return ExprError();
2861
2862 return Result;
2863 }
2864
2865 /// Build a new array subscript expression.
2866 ///
2867 /// By default, performs semantic analysis to build the new expression.
2868 /// Subclasses may override this routine to provide different behavior.
2870 SourceLocation LBracketLoc,
2871 Expr *RHS,
2872 SourceLocation RBracketLoc) {
2873 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2874 LBracketLoc, RHS,
2875 RBracketLoc);
2876 }
2877
2878 /// Build a new matrix single subscript expression.
2879 ///
2880 /// By default, performs semantic analysis to build the new expression.
2881 /// Subclasses may override this routine to provide different behavior.
2883 SourceLocation RBracketLoc) {
2885 RBracketLoc);
2886 }
2887
2888 /// Build a new matrix subscript expression.
2889 ///
2890 /// By default, performs semantic analysis to build the new expression.
2891 /// Subclasses may override this routine to provide different behavior.
2893 Expr *ColumnIdx,
2894 SourceLocation RBracketLoc) {
2895 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2896 RBracketLoc);
2897 }
2898
2899 /// Build a new array section expression.
2900 ///
2901 /// By default, performs semantic analysis to build the new expression.
2902 /// Subclasses may override this routine to provide different behavior.
2904 SourceLocation LBracketLoc,
2905 Expr *LowerBound,
2906 SourceLocation ColonLocFirst,
2907 SourceLocation ColonLocSecond,
2908 Expr *Length, Expr *Stride,
2909 SourceLocation RBracketLoc) {
2910 if (IsOMPArraySection)
2912 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2913 Stride, RBracketLoc);
2914
2915 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2916 "Stride/second colon not allowed for OpenACC");
2917
2919 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2920 }
2921
2922 /// Build a new array shaping expression.
2923 ///
2924 /// By default, performs semantic analysis to build the new expression.
2925 /// Subclasses may override this routine to provide different behavior.
2927 SourceLocation RParenLoc,
2928 ArrayRef<Expr *> Dims,
2929 ArrayRef<SourceRange> BracketsRanges) {
2931 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2932 }
2933
2934 /// Build a new iterator expression.
2935 ///
2936 /// By default, performs semantic analysis to build the new expression.
2937 /// Subclasses may override this routine to provide different behavior.
2940 SourceLocation RLoc,
2943 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2944 }
2945
2946 /// Build a new call expression.
2947 ///
2948 /// By default, performs semantic analysis to build the new expression.
2949 /// Subclasses may override this routine to provide different behavior.
2951 MultiExprArg Args,
2952 SourceLocation RParenLoc,
2953 Expr *ExecConfig = nullptr) {
2954 return getSema().ActOnCallExpr(
2955 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2956 }
2957
2959 MultiExprArg Args,
2960 SourceLocation RParenLoc) {
2962 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
2963 }
2964
2965 /// Build a new member access expression.
2966 ///
2967 /// By default, performs semantic analysis to build the new expression.
2968 /// Subclasses may override this routine to provide different behavior.
2970 bool isArrow,
2971 NestedNameSpecifierLoc QualifierLoc,
2972 SourceLocation TemplateKWLoc,
2973 const DeclarationNameInfo &MemberNameInfo,
2975 NamedDecl *FoundDecl,
2976 const TemplateArgumentListInfo *ExplicitTemplateArgs,
2977 NamedDecl *FirstQualifierInScope) {
2979 isArrow);
2980 if (!Member->getDeclName()) {
2981 // We have a reference to an unnamed field. This is always the
2982 // base of an anonymous struct/union member access, i.e. the
2983 // field is always of record type.
2984 assert(Member->getType()->isRecordType() &&
2985 "unnamed member not of record type?");
2986
2987 BaseResult =
2989 QualifierLoc.getNestedNameSpecifier(),
2990 FoundDecl, Member);
2991 if (BaseResult.isInvalid())
2992 return ExprError();
2993 Base = BaseResult.get();
2994
2995 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
2996 // from the AST, so we need to re-insert them if needed (since
2997 // `BuildFieldRefereneExpr()` doesn't do this).
2998 if (!isArrow && Base->isPRValue()) {
3000 if (BaseResult.isInvalid())
3001 return ExprError();
3002 Base = BaseResult.get();
3003 }
3004
3005 CXXScopeSpec EmptySS;
3007 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
3008 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
3009 MemberNameInfo);
3010 }
3011
3012 CXXScopeSpec SS;
3013 SS.Adopt(QualifierLoc);
3014
3015 Base = BaseResult.get();
3016 if (Base->containsErrors())
3017 return ExprError();
3018
3019 QualType BaseType = Base->getType();
3020
3021 if (isArrow && !BaseType->isPointerType())
3022 return ExprError();
3023
3024 // FIXME: this involves duplicating earlier analysis in a lot of
3025 // cases; we should avoid this when possible.
3026 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
3027 R.addDecl(FoundDecl);
3028 R.resolveKind();
3029
3030 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
3032 if (auto *ThisClass = cast<CXXThisExpr>(Base)
3033 ->getType()
3034 ->getPointeeType()
3035 ->getAsCXXRecordDecl()) {
3036 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
3037 // In unevaluated contexts, an expression supposed to be a member access
3038 // might reference a member in an unrelated class.
3039 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
3040 return getSema().BuildDeclRefExpr(Member, Member->getType(),
3041 VK_LValue, Member->getLocation());
3042 }
3043 }
3044
3045 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
3046 SS, TemplateKWLoc,
3047 FirstQualifierInScope,
3048 R, ExplicitTemplateArgs,
3049 /*S*/nullptr);
3050 }
3051
3052 /// Build a new binary operator expression.
3053 ///
3054 /// By default, performs semantic analysis to build the new expression.
3055 /// Subclasses may override this routine to provide different behavior.
3057 Expr *LHS, Expr *RHS,
3058 bool ForFoldExpression = false) {
3059 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS,
3060 ForFoldExpression);
3061 }
3062
3063 /// Build a new rewritten operator expression.
3064 ///
3065 /// By default, performs semantic analysis to build the new expression.
3066 /// Subclasses may override this routine to provide different behavior.
3068 SourceLocation OpLoc, BinaryOperatorKind Opcode,
3069 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
3070 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
3071 RHS, /*RequiresADL*/false);
3072 }
3073
3074 /// Build a new conditional operator expression.
3075 ///
3076 /// By default, performs semantic analysis to build the new expression.
3077 /// Subclasses may override this routine to provide different behavior.
3079 SourceLocation QuestionLoc,
3080 Expr *LHS,
3081 SourceLocation ColonLoc,
3082 Expr *RHS) {
3083 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3084 LHS, RHS);
3085 }
3086
3087 /// Build a new C-style cast expression.
3088 ///
3089 /// By default, performs semantic analysis to build the new expression.
3090 /// Subclasses may override this routine to provide different behavior.
3092 TypeSourceInfo *TInfo,
3093 SourceLocation RParenLoc,
3094 Expr *SubExpr) {
3095 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3096 SubExpr);
3097 }
3098
3099 /// Build a new compound literal expression.
3100 ///
3101 /// By default, performs semantic analysis to build the new expression.
3102 /// Subclasses may override this routine to provide different behavior.
3104 TypeSourceInfo *TInfo,
3105 SourceLocation RParenLoc,
3106 Expr *Init) {
3107 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3108 Init);
3109 }
3110
3111 /// Build a new extended vector or matrix element access expression.
3112 ///
3113 /// By default, performs semantic analysis to build the new expression.
3114 /// Subclasses may override this routine to provide different behavior.
3116 SourceLocation OpLoc,
3117 bool IsArrow,
3118 SourceLocation AccessorLoc,
3119 IdentifierInfo &Accessor) {
3120
3121 CXXScopeSpec SS;
3122 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3124 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3125 /*FirstQualifierInScope*/ nullptr, NameInfo,
3126 /* TemplateArgs */ nullptr,
3127 /*S*/ nullptr);
3128 }
3129
3130 /// Build a new initializer list expression.
3131 ///
3132 /// By default, performs semantic analysis to build the new expression.
3133 /// Subclasses may override this routine to provide different behavior.
3135 SourceLocation RBraceLoc, bool IsExplicit) {
3136 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc, IsExplicit);
3137 }
3138
3139 /// Build a new designated initializer expression.
3140 ///
3141 /// By default, performs semantic analysis to build the new expression.
3142 /// Subclasses may override this routine to provide different behavior.
3144 MultiExprArg ArrayExprs,
3145 SourceLocation EqualOrColonLoc,
3146 bool GNUSyntax,
3147 Expr *Init) {
3149 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3150 Init);
3151 if (Result.isInvalid())
3152 return ExprError();
3153
3154 return Result;
3155 }
3156
3157 /// Build a new value-initialized expression.
3158 ///
3159 /// By default, builds the implicit value initialization without performing
3160 /// any semantic analysis. Subclasses may override this routine to provide
3161 /// different behavior.
3165
3166 /// Build a new \c va_arg expression.
3167 ///
3168 /// By default, performs semantic analysis to build the new expression.
3169 /// Subclasses may override this routine to provide different behavior.
3171 Expr *SubExpr, TypeSourceInfo *TInfo,
3172 SourceLocation RParenLoc) {
3173 return getSema().BuildVAArgExpr(BuiltinLoc,
3174 SubExpr, TInfo,
3175 RParenLoc);
3176 }
3177
3178 /// Build a new expression list in parentheses.
3179 ///
3180 /// By default, performs semantic analysis to build the new expression.
3181 /// Subclasses may override this routine to provide different behavior.
3183 MultiExprArg SubExprs,
3184 SourceLocation RParenLoc) {
3185 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3186 }
3187
3189 unsigned NumUserSpecifiedExprs,
3190 SourceLocation InitLoc,
3191 SourceLocation LParenLoc,
3192 SourceLocation RParenLoc) {
3193 return getSema().ActOnCXXParenListInitExpr(Args, T, NumUserSpecifiedExprs,
3194 InitLoc, LParenLoc, RParenLoc);
3195 }
3196
3197 /// Build a new address-of-label expression.
3198 ///
3199 /// By default, performs semantic analysis, using the name of the label
3200 /// rather than attempting to map the label statement itself.
3201 /// Subclasses may override this routine to provide different behavior.
3203 SourceLocation LabelLoc, LabelDecl *Label) {
3204 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3205 }
3206
3207 /// Build a new GNU statement expression.
3208 ///
3209 /// By default, performs semantic analysis to build the new expression.
3210 /// Subclasses may override this routine to provide different behavior.
3212 SourceLocation RParenLoc, unsigned TemplateDepth) {
3213 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3214 TemplateDepth);
3215 }
3216
3217 /// Build a new __builtin_choose_expr expression.
3218 ///
3219 /// By default, performs semantic analysis to build the new expression.
3220 /// Subclasses may override this routine to provide different behavior.
3222 Expr *Cond, Expr *LHS, Expr *RHS,
3223 SourceLocation RParenLoc) {
3224 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3225 Cond, LHS, RHS,
3226 RParenLoc);
3227 }
3228
3229 /// Build a new generic selection expression with an expression predicate.
3230 ///
3231 /// By default, performs semantic analysis to build the new expression.
3232 /// Subclasses may override this routine to provide different behavior.
3234 SourceLocation DefaultLoc,
3235 SourceLocation RParenLoc,
3236 Expr *ControllingExpr,
3238 ArrayRef<Expr *> Exprs) {
3239 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3240 /*PredicateIsExpr=*/true,
3241 ControllingExpr, Types, Exprs);
3242 }
3243
3244 /// Build a new generic selection expression with a type predicate.
3245 ///
3246 /// By default, performs semantic analysis to build the new expression.
3247 /// Subclasses may override this routine to provide different behavior.
3249 SourceLocation DefaultLoc,
3250 SourceLocation RParenLoc,
3251 TypeSourceInfo *ControllingType,
3253 ArrayRef<Expr *> Exprs) {
3254 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3255 /*PredicateIsExpr=*/false,
3256 ControllingType, Types, Exprs);
3257 }
3258
3259 /// Build a new overloaded operator call expression.
3260 ///
3261 /// By default, performs semantic analysis to build the new expression.
3262 /// The semantic analysis provides the behavior of template instantiation,
3263 /// copying with transformations that turn what looks like an overloaded
3264 /// operator call into a use of a builtin operator, performing
3265 /// argument-dependent lookup, etc. Subclasses may override this routine to
3266 /// provide different behavior.
3268 SourceLocation OpLoc,
3269 SourceLocation CalleeLoc,
3270 bool RequiresADL,
3271 const UnresolvedSetImpl &Functions,
3272 Expr *First, Expr *Second);
3273
3274 /// Build a new C++ "named" cast expression, such as static_cast or
3275 /// reinterpret_cast.
3276 ///
3277 /// By default, this routine dispatches to one of the more-specific routines
3278 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3279 /// 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 switch (Class) {
3289 case Stmt::CXXStaticCastExprClass:
3290 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3291 RAngleLoc, LParenLoc,
3292 SubExpr, RParenLoc);
3293
3294 case Stmt::CXXDynamicCastExprClass:
3295 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3296 RAngleLoc, LParenLoc,
3297 SubExpr, RParenLoc);
3298
3299 case Stmt::CXXReinterpretCastExprClass:
3300 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3301 RAngleLoc, LParenLoc,
3302 SubExpr,
3303 RParenLoc);
3304
3305 case Stmt::CXXConstCastExprClass:
3306 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3307 RAngleLoc, LParenLoc,
3308 SubExpr, RParenLoc);
3309
3310 case Stmt::CXXAddrspaceCastExprClass:
3311 return getDerived().RebuildCXXAddrspaceCastExpr(
3312 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3313
3314 default:
3315 llvm_unreachable("Invalid C++ named cast");
3316 }
3317 }
3318
3319 /// Build a new C++ static_cast expression.
3320 ///
3321 /// By default, performs semantic analysis to build the new expression.
3322 /// Subclasses may override this routine to provide different behavior.
3324 SourceLocation LAngleLoc,
3325 TypeSourceInfo *TInfo,
3326 SourceLocation RAngleLoc,
3327 SourceLocation LParenLoc,
3328 Expr *SubExpr,
3329 SourceLocation RParenLoc) {
3330 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3331 TInfo, SubExpr,
3332 SourceRange(LAngleLoc, RAngleLoc),
3333 SourceRange(LParenLoc, RParenLoc));
3334 }
3335
3336 /// Build a new C++ dynamic_cast expression.
3337 ///
3338 /// By default, performs semantic analysis to build the new expression.
3339 /// Subclasses may override this routine to provide different behavior.
3341 SourceLocation LAngleLoc,
3342 TypeSourceInfo *TInfo,
3343 SourceLocation RAngleLoc,
3344 SourceLocation LParenLoc,
3345 Expr *SubExpr,
3346 SourceLocation RParenLoc) {
3347 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3348 TInfo, SubExpr,
3349 SourceRange(LAngleLoc, RAngleLoc),
3350 SourceRange(LParenLoc, RParenLoc));
3351 }
3352
3353 /// Build a new C++ reinterpret_cast expression.
3354 ///
3355 /// By default, performs semantic analysis to build the new expression.
3356 /// Subclasses may override this routine to provide different behavior.
3358 SourceLocation LAngleLoc,
3359 TypeSourceInfo *TInfo,
3360 SourceLocation RAngleLoc,
3361 SourceLocation LParenLoc,
3362 Expr *SubExpr,
3363 SourceLocation RParenLoc) {
3364 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3365 TInfo, SubExpr,
3366 SourceRange(LAngleLoc, RAngleLoc),
3367 SourceRange(LParenLoc, RParenLoc));
3368 }
3369
3370 /// Build a new C++ const_cast expression.
3371 ///
3372 /// By default, performs semantic analysis to build the new expression.
3373 /// Subclasses may override this routine to provide different behavior.
3375 SourceLocation LAngleLoc,
3376 TypeSourceInfo *TInfo,
3377 SourceLocation RAngleLoc,
3378 SourceLocation LParenLoc,
3379 Expr *SubExpr,
3380 SourceLocation RParenLoc) {
3381 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3382 TInfo, SubExpr,
3383 SourceRange(LAngleLoc, RAngleLoc),
3384 SourceRange(LParenLoc, RParenLoc));
3385 }
3386
3389 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3390 SourceLocation LParenLoc, Expr *SubExpr,
3391 SourceLocation RParenLoc) {
3392 return getSema().BuildCXXNamedCast(
3393 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3394 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3395 }
3396
3397 /// Build a new C++ functional-style cast expression.
3398 ///
3399 /// By default, performs semantic analysis to build the new expression.
3400 /// Subclasses may override this routine to provide different behavior.
3402 SourceLocation LParenLoc,
3403 Expr *Sub,
3404 SourceLocation RParenLoc,
3405 bool ListInitialization) {
3406 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3407 // CXXParenListInitExpr. Pass its expanded arguments so that the
3408 // CXXParenListInitExpr can be rebuilt.
3409 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3411 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3412 RParenLoc, ListInitialization);
3413
3414 if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub))
3416 TInfo, LParenLoc, PLE->getInitExprs(), RParenLoc, ListInitialization);
3417
3418 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3419 MultiExprArg(&Sub, 1), RParenLoc,
3420 ListInitialization);
3421 }
3422
3423 /// Build a new C++ __builtin_bit_cast expression.
3424 ///
3425 /// By default, performs semantic analysis to build the new expression.
3426 /// Subclasses may override this routine to provide different behavior.
3428 TypeSourceInfo *TSI, Expr *Sub,
3429 SourceLocation RParenLoc) {
3430 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3431 }
3432
3433 /// Build a new C++ typeid(type) expression.
3434 ///
3435 /// By default, performs semantic analysis to build the new expression.
3436 /// Subclasses may override this routine to provide different behavior.
3438 SourceLocation TypeidLoc,
3439 TypeSourceInfo *Operand,
3440 SourceLocation RParenLoc) {
3441 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3442 RParenLoc);
3443 }
3444
3445
3446 /// Build a new C++ typeid(expr) expression.
3447 ///
3448 /// By default, performs semantic analysis to build the new expression.
3449 /// Subclasses may override this routine to provide different behavior.
3451 SourceLocation TypeidLoc,
3452 Expr *Operand,
3453 SourceLocation RParenLoc) {
3454 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3455 RParenLoc);
3456 }
3457
3458 /// Build a new C++ __uuidof(type) expression.
3459 ///
3460 /// By default, performs semantic analysis to build the new expression.
3461 /// Subclasses may override this routine to provide different behavior.
3463 TypeSourceInfo *Operand,
3464 SourceLocation RParenLoc) {
3465 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3466 }
3467
3468 /// Build a new C++ __uuidof(expr) expression.
3469 ///
3470 /// By default, performs semantic analysis to build the new expression.
3471 /// Subclasses may override this routine to provide different behavior.
3473 Expr *Operand, SourceLocation RParenLoc) {
3474 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3475 }
3476
3477 /// Build a new C++ "this" expression.
3478 ///
3479 /// By default, performs semantic analysis to build a new "this" expression.
3480 /// Subclasses may override this routine to provide different behavior.
3482 QualType ThisType,
3483 bool isImplicit) {
3484 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3485 return ExprError();
3486 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3487 }
3488
3489 /// Build a new C++ throw expression.
3490 ///
3491 /// By default, performs semantic analysis to build the new expression.
3492 /// Subclasses may override this routine to provide different behavior.
3494 bool IsThrownVariableInScope) {
3495 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3496 }
3497
3498 /// Build a new C++ default-argument expression.
3499 ///
3500 /// By default, builds a new default-argument expression, which does not
3501 /// require any semantic analysis. Subclasses may override this routine to
3502 /// provide different behavior.
3504 Expr *RewrittenExpr) {
3505 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3506 RewrittenExpr, getSema().CurContext);
3507 }
3508
3509 /// Build a new C++11 default-initialization expression.
3510 ///
3511 /// By default, builds a new default field initialization expression, which
3512 /// does not require any semantic analysis. Subclasses may override this
3513 /// routine to provide different behavior.
3518
3519 /// Build a new C++ zero-initialization expression.
3520 ///
3521 /// By default, performs semantic analysis to build the new expression.
3522 /// Subclasses may override this routine to provide different behavior.
3524 SourceLocation LParenLoc,
3525 SourceLocation RParenLoc) {
3526 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3527 /*ListInitialization=*/false);
3528 }
3529
3530 /// Build a new C++ "new" expression.
3531 ///
3532 /// By default, performs semantic analysis to build the new expression.
3533 /// Subclasses may override this routine to provide different behavior.
3535 SourceLocation PlacementLParen,
3536 MultiExprArg PlacementArgs,
3537 SourceLocation PlacementRParen,
3538 SourceRange TypeIdParens, QualType AllocatedType,
3539 TypeSourceInfo *AllocatedTypeInfo,
3540 std::optional<Expr *> ArraySize,
3541 SourceRange DirectInitRange, Expr *Initializer) {
3542 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3543 PlacementLParen,
3544 PlacementArgs,
3545 PlacementRParen,
3546 TypeIdParens,
3547 AllocatedType,
3548 AllocatedTypeInfo,
3549 ArraySize,
3550 DirectInitRange,
3551 Initializer);
3552 }
3553
3554 /// Build a new C++ "delete" expression.
3555 ///
3556 /// By default, performs semantic analysis to build the new expression.
3557 /// Subclasses may override this routine to provide different behavior.
3559 bool IsGlobalDelete,
3560 bool IsArrayForm,
3561 Expr *Operand) {
3562 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3563 Operand);
3564 }
3565
3566 /// Build a new type trait expression.
3567 ///
3568 /// By default, performs semantic analysis to build the new expression.
3569 /// Subclasses may override this routine to provide different behavior.
3571 SourceLocation StartLoc,
3573 SourceLocation RParenLoc) {
3574 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3575 }
3576
3577 /// Build a new array type trait expression.
3578 ///
3579 /// By default, performs semantic analysis to build the new expression.
3580 /// Subclasses may override this routine to provide different behavior.
3582 SourceLocation StartLoc,
3583 TypeSourceInfo *TSInfo,
3584 Expr *DimExpr,
3585 SourceLocation RParenLoc) {
3586 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3587 }
3588
3589 /// Build a new expression trait expression.
3590 ///
3591 /// By default, performs semantic analysis to build the new expression.
3592 /// Subclasses may override this routine to provide different behavior.
3594 SourceLocation StartLoc,
3595 Expr *Queried,
3596 SourceLocation RParenLoc) {
3597 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3598 }
3599
3600 /// Build a new (previously unresolved) declaration reference
3601 /// expression.
3602 ///
3603 /// By default, performs semantic analysis to build the new expression.
3604 /// Subclasses may override this routine to provide different behavior.
3606 NestedNameSpecifierLoc QualifierLoc,
3607 SourceLocation TemplateKWLoc,
3608 const DeclarationNameInfo &NameInfo,
3609 const TemplateArgumentListInfo *TemplateArgs,
3610 bool IsAddressOfOperand,
3611 TypeSourceInfo **RecoveryTSI) {
3612 CXXScopeSpec SS;
3613 SS.Adopt(QualifierLoc);
3614
3615 if (TemplateArgs || TemplateKWLoc.isValid())
3617 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3618
3620 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3621 }
3622
3623 /// Build a new template-id expression.
3624 ///
3625 /// By default, performs semantic analysis to build the new expression.
3626 /// Subclasses may override this routine to provide different behavior.
3628 SourceLocation TemplateKWLoc,
3629 LookupResult &R,
3630 bool RequiresADL,
3631 const TemplateArgumentListInfo *TemplateArgs) {
3632 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3633 TemplateArgs);
3634 }
3635
3636 /// Build a new object-construction expression.
3637 ///
3638 /// By default, performs semantic analysis to build the new expression.
3639 /// Subclasses may override this routine to provide different behavior.
3642 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3643 bool ListInitialization, bool StdInitListInitialization,
3644 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3645 SourceRange ParenRange) {
3646 // Reconstruct the constructor we originally found, which might be
3647 // different if this is a call to an inherited constructor.
3648 CXXConstructorDecl *FoundCtor = Constructor;
3649 if (Constructor->isInheritingConstructor())
3650 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3651
3652 SmallVector<Expr *, 8> ConvertedArgs;
3653 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3654 ConvertedArgs))
3655 return ExprError();
3656
3657 return getSema().BuildCXXConstructExpr(Loc, T, Constructor,
3658 IsElidable,
3659 ConvertedArgs,
3660 HadMultipleCandidates,
3661 ListInitialization,
3662 StdInitListInitialization,
3663 RequiresZeroInit, ConstructKind,
3664 ParenRange);
3665 }
3666
3667 /// Build a new implicit construction via inherited constructor
3668 /// expression.
3671 bool ConstructsVBase,
3672 bool InheritedFromVBase) {
3674 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3675 }
3676
3677 /// Build a new object-construction expression.
3678 ///
3679 /// By default, performs semantic analysis to build the new expression.
3680 /// Subclasses may override this routine to provide different behavior.
3682 SourceLocation LParenOrBraceLoc,
3683 MultiExprArg Args,
3684 SourceLocation RParenOrBraceLoc,
3685 bool ListInitialization) {
3687 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3688 }
3689
3690 /// Build a new object-construction expression.
3691 ///
3692 /// By default, performs semantic analysis to build the new expression.
3693 /// Subclasses may override this routine to provide different behavior.
3695 SourceLocation LParenLoc,
3696 MultiExprArg Args,
3697 SourceLocation RParenLoc,
3698 bool ListInitialization) {
3699 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3700 RParenLoc, ListInitialization);
3701 }
3702
3703 /// Build a new member reference expression.
3704 ///
3705 /// By default, performs semantic analysis to build the new expression.
3706 /// Subclasses may override this routine to provide different behavior.
3708 QualType BaseType,
3709 bool IsArrow,
3710 SourceLocation OperatorLoc,
3711 NestedNameSpecifierLoc QualifierLoc,
3712 SourceLocation TemplateKWLoc,
3713 NamedDecl *FirstQualifierInScope,
3714 const DeclarationNameInfo &MemberNameInfo,
3715 const TemplateArgumentListInfo *TemplateArgs) {
3716 CXXScopeSpec SS;
3717 SS.Adopt(QualifierLoc);
3718
3719 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3720 OperatorLoc, IsArrow,
3721 SS, TemplateKWLoc,
3722 FirstQualifierInScope,
3723 MemberNameInfo,
3724 TemplateArgs, /*S*/nullptr);
3725 }
3726
3727 /// Build a new member reference expression.
3728 ///
3729 /// By default, performs semantic analysis to build the new expression.
3730 /// Subclasses may override this routine to provide different behavior.
3732 SourceLocation OperatorLoc,
3733 bool IsArrow,
3734 NestedNameSpecifierLoc QualifierLoc,
3735 SourceLocation TemplateKWLoc,
3736 NamedDecl *FirstQualifierInScope,
3737 LookupResult &R,
3738 const TemplateArgumentListInfo *TemplateArgs) {
3739 CXXScopeSpec SS;
3740 SS.Adopt(QualifierLoc);
3741
3742 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3743 OperatorLoc, IsArrow,
3744 SS, TemplateKWLoc,
3745 FirstQualifierInScope,
3746 R, TemplateArgs, /*S*/nullptr);
3747 }
3748
3749 /// Build a new noexcept expression.
3750 ///
3751 /// By default, performs semantic analysis to build the new expression.
3752 /// Subclasses may override this routine to provide different behavior.
3754 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3755 }
3756
3759
3760 /// Build a new expression to compute the length of a parameter pack.
3762 SourceLocation PackLoc,
3763 SourceLocation RParenLoc,
3764 UnsignedOrNone Length,
3765 ArrayRef<TemplateArgument> PartialArgs) {
3766 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3767 RParenLoc, Length, PartialArgs);
3768 }
3769
3771 SourceLocation RSquareLoc,
3772 Expr *PackIdExpression, Expr *IndexExpr,
3773 ArrayRef<Expr *> ExpandedExprs,
3774 bool FullySubstituted = false) {
3775 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3776 IndexExpr, RSquareLoc, ExpandedExprs,
3777 FullySubstituted);
3778 }
3779
3780 /// Build a new expression representing a call to a source location
3781 /// builtin.
3782 ///
3783 /// By default, performs semantic analysis to build the new expression.
3784 /// Subclasses may override this routine to provide different behavior.
3786 SourceLocation BuiltinLoc,
3787 SourceLocation RPLoc,
3788 DeclContext *ParentContext) {
3789 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3790 ParentContext);
3791 }
3792
3794 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3795 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3797 CXXScopeSpec SS;
3798 SS.Adopt(NNS);
3799 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3800 ConceptNameInfo,
3801 FoundDecl,
3802 NamedConcept, TALI);
3803 if (Result.isInvalid())
3804 return ExprError();
3805 return Result;
3806 }
3807
3808 /// \brief Build a new requires expression.
3809 ///
3810 /// By default, performs semantic analysis to build the new expression.
3811 /// Subclasses may override this routine to provide different behavior.
3814 SourceLocation LParenLoc,
3815 ArrayRef<ParmVarDecl *> LocalParameters,
3816 SourceLocation RParenLoc,
3818 SourceLocation ClosingBraceLoc) {
3819 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3820 LocalParameters, RParenLoc, Requirements,
3821 ClosingBraceLoc);
3822 }
3823
3827 return SemaRef.BuildTypeRequirement(SubstDiag);
3828 }
3829
3831 return SemaRef.BuildTypeRequirement(T);
3832 }
3833
3836 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3837 SourceLocation NoexceptLoc,
3839 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3840 std::move(Ret));
3841 }
3842
3844 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3846 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3847 std::move(Ret));
3848 }
3849
3851 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3852 const ASTConstraintSatisfaction &Satisfaction) {
3853 return SemaRef.BuildNestedRequirement(InvalidConstraintEntity,
3854 Satisfaction);
3855 }
3856
3858 return SemaRef.BuildNestedRequirement(Constraint);
3859 }
3860
3861 /// \brief Build a new Objective-C boxed expression.
3862 ///
3863 /// By default, performs semantic analysis to build the new expression.
3864 /// Subclasses may override this routine to provide different behavior.
3866 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3867 }
3868
3869 /// Build a new Objective-C array literal.
3870 ///
3871 /// By default, performs semantic analysis to build the new expression.
3872 /// Subclasses may override this routine to provide different behavior.
3874 Expr **Elements, unsigned NumElements) {
3876 Range, MultiExprArg(Elements, NumElements));
3877 }
3878
3880 Expr *Base, Expr *Key,
3881 ObjCMethodDecl *getterMethod,
3882 ObjCMethodDecl *setterMethod) {
3884 RB, Base, Key, getterMethod, setterMethod);
3885 }
3886
3887 /// Build a new Objective-C dictionary literal.
3888 ///
3889 /// By default, performs semantic analysis to build the new expression.
3890 /// Subclasses may override this routine to provide different behavior.
3895
3896 /// Build a new Objective-C \@encode expression.
3897 ///
3898 /// By default, performs semantic analysis to build the new expression.
3899 /// Subclasses may override this routine to provide different behavior.
3901 TypeSourceInfo *EncodeTypeInfo,
3902 SourceLocation RParenLoc) {
3903 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3904 RParenLoc);
3905 }
3906
3907 /// Build a new Objective-C class message.
3909 Selector Sel,
3910 ArrayRef<SourceLocation> SelectorLocs,
3912 SourceLocation LBracLoc,
3913 MultiExprArg Args,
3914 SourceLocation RBracLoc) {
3915 return SemaRef.ObjC().BuildClassMessage(
3916 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3917 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3918 RBracLoc, Args);
3919 }
3920
3921 /// Build a new Objective-C instance message.
3923 Selector Sel,
3924 ArrayRef<SourceLocation> SelectorLocs,
3926 SourceLocation LBracLoc,
3927 MultiExprArg Args,
3928 SourceLocation RBracLoc) {
3929 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3930 /*SuperLoc=*/SourceLocation(),
3931 Sel, Method, LBracLoc,
3932 SelectorLocs, RBracLoc, Args);
3933 }
3934
3935 /// Build a new Objective-C instance/class message to 'super'.
3937 Selector Sel,
3938 ArrayRef<SourceLocation> SelectorLocs,
3939 QualType SuperType,
3941 SourceLocation LBracLoc,
3942 MultiExprArg Args,
3943 SourceLocation RBracLoc) {
3944 return Method->isInstanceMethod()
3945 ? SemaRef.ObjC().BuildInstanceMessage(
3946 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3947 SelectorLocs, RBracLoc, Args)
3948 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3949 Sel, Method, LBracLoc,
3950 SelectorLocs, RBracLoc, Args);
3951 }
3952
3953 /// Build a new Objective-C ivar reference expression.
3954 ///
3955 /// By default, performs semantic analysis to build the new expression.
3956 /// Subclasses may override this routine to provide different behavior.
3958 SourceLocation IvarLoc,
3959 bool IsArrow, bool IsFreeIvar) {
3960 CXXScopeSpec SS;
3961 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
3963 BaseArg, BaseArg->getType(),
3964 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
3965 /*FirstQualifierInScope=*/nullptr, NameInfo,
3966 /*TemplateArgs=*/nullptr,
3967 /*S=*/nullptr);
3968 if (IsFreeIvar && Result.isUsable())
3969 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
3970 return Result;
3971 }
3972
3973 /// Build a new Objective-C property reference expression.
3974 ///
3975 /// By default, performs semantic analysis to build the new expression.
3976 /// Subclasses may override this routine to provide different behavior.
3979 SourceLocation PropertyLoc) {
3980 CXXScopeSpec SS;
3981 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
3982 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
3983 /*FIXME:*/PropertyLoc,
3984 /*IsArrow=*/false,
3985 SS, SourceLocation(),
3986 /*FirstQualifierInScope=*/nullptr,
3987 NameInfo,
3988 /*TemplateArgs=*/nullptr,
3989 /*S=*/nullptr);
3990 }
3991
3992 /// Build a new Objective-C property reference expression.
3993 ///
3994 /// By default, performs semantic analysis to build the new expression.
3995 /// Subclasses may override this routine to provide different behavior.
3997 ObjCMethodDecl *Getter,
3998 ObjCMethodDecl *Setter,
3999 SourceLocation PropertyLoc) {
4000 // Since these expressions can only be value-dependent, we do not
4001 // need to perform semantic analysis again.
4002 return Owned(
4003 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
4005 PropertyLoc, Base));
4006 }
4007
4008 /// Build a new Objective-C "isa" expression.
4009 ///
4010 /// By default, performs semantic analysis to build the new expression.
4011 /// Subclasses may override this routine to provide different behavior.
4013 SourceLocation OpLoc, bool IsArrow) {
4014 CXXScopeSpec SS;
4015 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
4016 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
4017 OpLoc, IsArrow,
4018 SS, SourceLocation(),
4019 /*FirstQualifierInScope=*/nullptr,
4020 NameInfo,
4021 /*TemplateArgs=*/nullptr,
4022 /*S=*/nullptr);
4023 }
4024
4025 /// Build a new shuffle vector expression.
4026 ///
4027 /// By default, performs semantic analysis to build the new expression.
4028 /// Subclasses may override this routine to provide different behavior.
4030 MultiExprArg SubExprs,
4031 SourceLocation RParenLoc) {
4032 // Find the declaration for __builtin_shufflevector
4033 const IdentifierInfo &Name
4034 = SemaRef.Context.Idents.get("__builtin_shufflevector");
4035 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
4036 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
4037 assert(!Lookup.empty() && "No __builtin_shufflevector?");
4038
4039 // Build a reference to the __builtin_shufflevector builtin
4041 Expr *Callee = new (SemaRef.Context)
4042 DeclRefExpr(SemaRef.Context, Builtin, false,
4043 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
4044 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
4045 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
4046 CK_BuiltinFnToFnPtr).get();
4047
4048 // Build the CallExpr
4049 ExprResult TheCall = CallExpr::Create(
4050 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
4051 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
4053
4054 // Type-check the __builtin_shufflevector expression.
4055 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
4056 }
4057
4058 /// Build a new convert vector expression.
4060 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
4061 SourceLocation RParenLoc) {
4062 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
4063 }
4064
4065 /// Build a new template argument pack expansion.
4066 ///
4067 /// By default, performs semantic analysis to build a new pack expansion
4068 /// for a template argument. Subclasses may override this routine to provide
4069 /// different behavior.
4071 SourceLocation EllipsisLoc,
4072 UnsignedOrNone NumExpansions) {
4073 switch (Pattern.getArgument().getKind()) {
4077 EllipsisLoc, NumExpansions);
4078 if (Result.isInvalid())
4079 return TemplateArgumentLoc();
4080
4082 /*IsCanonical=*/false),
4083 Result.get());
4084 }
4085
4087 return TemplateArgumentLoc(
4088 SemaRef.Context,
4090 NumExpansions),
4091 Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(),
4092 Pattern.getTemplateNameLoc(), EllipsisLoc);
4093
4101 llvm_unreachable("Pack expansion pattern has no parameter packs");
4102
4104 if (TypeSourceInfo *Expansion
4105 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4106 EllipsisLoc,
4107 NumExpansions))
4108 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4109 Expansion);
4110 break;
4111 }
4112
4113 return TemplateArgumentLoc();
4114 }
4115
4116 /// Build a new expression pack expansion.
4117 ///
4118 /// By default, performs semantic analysis to build a new pack expansion
4119 /// for an expression. Subclasses may override this routine to provide
4120 /// different behavior.
4122 UnsignedOrNone NumExpansions) {
4123 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4124 }
4125
4126 /// Build a new C++1z fold-expression.
4127 ///
4128 /// By default, performs semantic analysis in order to build a new fold
4129 /// expression.
4131 SourceLocation LParenLoc, Expr *LHS,
4132 BinaryOperatorKind Operator,
4133 SourceLocation EllipsisLoc, Expr *RHS,
4134 SourceLocation RParenLoc,
4135 UnsignedOrNone NumExpansions) {
4136 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4137 EllipsisLoc, RHS, RParenLoc,
4138 NumExpansions);
4139 }
4140
4142 LambdaScopeInfo *LSI) {
4143 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4144 if (Expr *Init = PVD->getInit())
4146 Init->containsUnexpandedParameterPack();
4147 else if (PVD->hasUninstantiatedDefaultArg())
4149 PVD->getUninstantiatedDefaultArg()
4150 ->containsUnexpandedParameterPack();
4151 }
4152 return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4153 }
4154
4155 /// Build an empty C++1z fold-expression with the given operator.
4156 ///
4157 /// By default, produces the fallback value for the fold-expression, or
4158 /// produce an error if there is no fallback value.
4160 BinaryOperatorKind Operator) {
4161 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4162 }
4163
4164 /// Build a new atomic operation expression.
4165 ///
4166 /// By default, performs semantic analysis to build the new expression.
4167 /// Subclasses may override this routine to provide different behavior.
4170 SourceLocation RParenLoc) {
4171 // Use this for all of the locations, since we don't know the difference
4172 // between the call and the expr at this point.
4173 SourceRange Range{BuiltinLoc, RParenLoc};
4174 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4176 }
4177
4179 ArrayRef<Expr *> SubExprs, QualType Type) {
4180 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4181 }
4182
4184 SourceLocation BeginLoc,
4185 SourceLocation DirLoc,
4186 SourceLocation EndLoc,
4188 StmtResult StrBlock) {
4190 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4191 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock);
4192 }
4193
4204
4206 SourceLocation BeginLoc,
4207 SourceLocation DirLoc,
4208 SourceLocation EndLoc,
4210 StmtResult Loop) {
4212 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4213 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop);
4214 }
4215
4217 SourceLocation DirLoc,
4218 SourceLocation EndLoc,
4220 StmtResult StrBlock) {
4222 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4224 Clauses, StrBlock);
4225 }
4226
4236
4246
4248 SourceLocation DirLoc,
4249 SourceLocation EndLoc,
4251 StmtResult StrBlock) {
4255 Clauses, StrBlock);
4256 }
4257
4259 SourceLocation DirLoc,
4260 SourceLocation EndLoc,
4261 ArrayRef<OpenACCClause *> Clauses) {
4263 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4265 Clauses, {});
4266 }
4267
4277
4279 SourceLocation DirLoc,
4280 SourceLocation EndLoc,
4281 ArrayRef<OpenACCClause *> Clauses) {
4283 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4285 Clauses, {});
4286 }
4287
4289 SourceLocation DirLoc,
4290 SourceLocation EndLoc,
4291 ArrayRef<OpenACCClause *> Clauses) {
4293 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4295 Clauses, {});
4296 }
4297
4299 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4300 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4301 SourceLocation RParenLoc, SourceLocation EndLoc,
4302 ArrayRef<OpenACCClause *> Clauses) {
4304 Exprs.push_back(DevNumExpr);
4305 llvm::append_range(Exprs, QueueIdExprs);
4307 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4308 Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {});
4309 }
4310
4312 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4313 SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList,
4314 SourceLocation RParenLoc, SourceLocation EndLoc) {
4316 OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc,
4317 VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {});
4318 }
4319
4321 SourceLocation DirLoc,
4322 OpenACCAtomicKind AtKind,
4323 SourceLocation EndLoc,
4325 StmtResult AssociatedStmt) {
4327 OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{},
4328 SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses,
4329 AssociatedStmt);
4330 }
4331
4335
4337 RebuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, unsigned Index,
4338 QualType ParamType, SourceLocation Loc,
4339 TemplateArgument Arg,
4340 UnsignedOrNone PackIndex, bool Final) {
4342 AssociatedDecl, Index, ParamType, Loc, Arg, PackIndex, Final);
4343 }
4344
4346 SourceLocation StartLoc,
4347 SourceLocation LParenLoc,
4348 SourceLocation EndLoc) {
4349 return getSema().OpenMP().ActOnOpenMPTransparentClause(ImpexType, StartLoc,
4350 LParenLoc, EndLoc);
4351 }
4352
4353private:
4354 QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL,
4355 QualType ObjectType,
4356 NamedDecl *FirstQualifierInScope);
4357
4358 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4359 QualType ObjectType,
4360 NamedDecl *FirstQualifierInScope) {
4361 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4362 return TSInfo;
4363
4364 TypeLocBuilder TLB;
4365 QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(),
4366 ObjectType, FirstQualifierInScope);
4367 if (T.isNull())
4368 return nullptr;
4369 return TLB.getTypeSourceInfo(SemaRef.Context, T);
4370 }
4371
4372 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4373 DependentNameTypeLoc TL,
4374 bool DeducibleTSTContext,
4375 QualType ObjectType = QualType(),
4376 NamedDecl *UnqualLookup = nullptr);
4377
4379 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4381
4382 OpenACCClause *
4383 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4384 OpenACCDirectiveKind DirKind,
4385 const OpenACCClause *OldClause);
4386};
4387
4388template <typename Derived>
4390 if (!S)
4391 return S;
4392
4393 switch (S->getStmtClass()) {
4394 case Stmt::NoStmtClass: break;
4395
4396 // Transform individual statement nodes
4397 // Pass SDK into statements that can produce a value
4398#define STMT(Node, Parent) \
4399 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4400#define VALUESTMT(Node, Parent) \
4401 case Stmt::Node##Class: \
4402 return getDerived().Transform##Node(cast<Node>(S), SDK);
4403#define ABSTRACT_STMT(Node)
4404#define EXPR(Node, Parent)
4405#include "clang/AST/StmtNodes.inc"
4406
4407 // Transform expressions by calling TransformExpr.
4408#define STMT(Node, Parent)
4409#define ABSTRACT_STMT(Stmt)
4410#define EXPR(Node, Parent) case Stmt::Node##Class:
4411#include "clang/AST/StmtNodes.inc"
4412 {
4413 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4414
4416 E = getSema().ActOnStmtExprResult(E);
4417 return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded);
4418 }
4419 }
4420
4421 return S;
4422}
4423
4424template<typename Derived>
4426 if (!S)
4427 return S;
4428
4429 switch (S->getClauseKind()) {
4430 default: break;
4431 // Transform individual clause nodes
4432#define GEN_CLANG_CLAUSE_CLASS
4433#define CLAUSE_CLASS(Enum, Str, Class) \
4434 case Enum: \
4435 return getDerived().Transform##Class(cast<Class>(S));
4436#include "llvm/Frontend/OpenMP/OMP.inc"
4437 }
4438
4439 return S;
4440}
4441
4442
4443template<typename Derived>
4445 if (!E)
4446 return E;
4447
4448 switch (E->getStmtClass()) {
4449 case Stmt::NoStmtClass: break;
4450#define STMT(Node, Parent) case Stmt::Node##Class: break;
4451#define ABSTRACT_STMT(Stmt)
4452#define EXPR(Node, Parent) \
4453 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4454#include "clang/AST/StmtNodes.inc"
4455 }
4456
4457 return E;
4458}
4459
4460template<typename Derived>
4462 bool NotCopyInit) {
4463 // Initializers are instantiated like expressions, except that various outer
4464 // layers are stripped.
4465 if (!Init)
4466 return Init;
4467
4468 if (auto *FE = dyn_cast<FullExpr>(Init))
4469 Init = FE->getSubExpr();
4470
4471 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4472 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4473 Init = OVE->getSourceExpr();
4474 }
4475
4476 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4477 Init = MTE->getSubExpr();
4478
4479 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4480 Init = Binder->getSubExpr();
4481
4482 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4483 Init = ICE->getSubExprAsWritten();
4484
4485 if (CXXStdInitializerListExpr *ILE =
4486 dyn_cast<CXXStdInitializerListExpr>(Init))
4487 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4488
4489 // If this is copy-initialization, we only need to reconstruct
4490 // InitListExprs. Other forms of copy-initialization will be a no-op if
4491 // the initializer is already the right type.
4492 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4493 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4494 return getDerived().TransformExpr(Init);
4495
4496 // Revert value-initialization back to empty parens.
4497 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4498 SourceRange Parens = VIE->getSourceRange();
4499 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4500 Parens.getEnd());
4501 }
4502
4503 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4505 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4506 SourceLocation());
4507
4508 // Revert initialization by constructor back to a parenthesized or braced list
4509 // of expressions. Any other form of initializer can just be reused directly.
4510 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4511 return getDerived().TransformExpr(Init);
4512
4513 // If the initialization implicitly converted an initializer list to a
4514 // std::initializer_list object, unwrap the std::initializer_list too.
4515 if (Construct && Construct->isStdInitListInitialization())
4516 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4517
4518 // Enter a list-init context if this was list initialization.
4521 Construct->isListInitialization());
4522
4523 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4524 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4525 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4526 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4527 SmallVector<Expr*, 8> NewArgs;
4528 bool ArgChanged = false;
4529 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4530 /*IsCall*/true, NewArgs, &ArgChanged))
4531 return ExprError();
4532
4533 // If this was list initialization, revert to syntactic list form.
4534 if (Construct->isListInitialization())
4535 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4536 Construct->getEndLoc(),
4537 /*IsExplicit=*/true);
4538
4539 // Build a ParenListExpr to represent anything else.
4541 if (Parens.isInvalid()) {
4542 // This was a variable declaration's initialization for which no initializer
4543 // was specified.
4544 assert(NewArgs.empty() &&
4545 "no parens or braces but have direct init with arguments?");
4546 return ExprEmpty();
4547 }
4548 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4549 Parens.getEnd());
4550}
4551
4552template<typename Derived>
4554 unsigned NumInputs,
4555 bool IsCall,
4556 SmallVectorImpl<Expr *> &Outputs,
4557 bool *ArgChanged) {
4558 for (unsigned I = 0; I != NumInputs; ++I) {
4559 // If requested, drop call arguments that need to be dropped.
4560 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4561 if (ArgChanged)
4562 *ArgChanged = true;
4563
4564 break;
4565 }
4566
4567 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4568 Expr *Pattern = Expansion->getPattern();
4569
4571 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4572 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4573
4574 // Determine whether the set of unexpanded parameter packs can and should
4575 // be expanded.
4576 bool Expand = true;
4577 bool RetainExpansion = false;
4578 UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions();
4579 UnsignedOrNone NumExpansions = OrigNumExpansions;
4581 Expansion->getEllipsisLoc(), Pattern->getSourceRange(),
4582 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
4583 RetainExpansion, NumExpansions))
4584 return true;
4585
4586 if (!Expand) {
4587 // The transform has determined that we should perform a simple
4588 // transformation on the pack expansion, producing another pack
4589 // expansion.
4590 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
4591 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4592 if (OutPattern.isInvalid())
4593 return true;
4594
4595 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4596 Expansion->getEllipsisLoc(),
4597 NumExpansions);
4598 if (Out.isInvalid())
4599 return true;
4600
4601 if (ArgChanged)
4602 *ArgChanged = true;
4603 Outputs.push_back(Out.get());
4604 continue;
4605 }
4606
4607 // Record right away that the argument was changed. This needs
4608 // to happen even if the array expands to nothing.
4609 if (ArgChanged) *ArgChanged = true;
4610
4611 // The transform has determined that we should perform an elementwise
4612 // expansion of the pattern. Do so.
4613 for (unsigned I = 0; I != *NumExpansions; ++I) {
4614 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
4615 ExprResult Out = getDerived().TransformExpr(Pattern);
4616 if (Out.isInvalid())
4617 return true;
4618
4619 if (Out.get()->containsUnexpandedParameterPack()) {
4620 Out = getDerived().RebuildPackExpansion(
4621 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4622 if (Out.isInvalid())
4623 return true;
4624 }
4625
4626 Outputs.push_back(Out.get());
4627 }
4628
4629 // If we're supposed to retain a pack expansion, do so by temporarily
4630 // forgetting the partially-substituted parameter pack.
4631 if (RetainExpansion) {
4632 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4633
4634 ExprResult Out = getDerived().TransformExpr(Pattern);
4635 if (Out.isInvalid())
4636 return true;
4637
4638 Out = getDerived().RebuildPackExpansion(
4639 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4640 if (Out.isInvalid())
4641 return true;
4642
4643 Outputs.push_back(Out.get());
4644 }
4645
4646 continue;
4647 }
4648
4650 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4651 : getDerived().TransformExpr(Inputs[I]);
4652 if (Result.isInvalid())
4653 return true;
4654
4655 if (Result.get() != Inputs[I] && ArgChanged)
4656 *ArgChanged = true;
4657
4658 Outputs.push_back(Result.get());
4659 }
4660
4661 return false;
4662}
4663
4664template <typename Derived>
4667
4670 /*LambdaContextDecl=*/nullptr,
4672 /*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf);
4673
4674 if (Var) {
4675 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4677
4678 if (!ConditionVar)
4679 return Sema::ConditionError();
4680
4681 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4682 }
4683
4684 if (Expr) {
4685 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4686
4687 if (CondExpr.isInvalid())
4688 return Sema::ConditionError();
4689
4690 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4691 /*MissingOK=*/true);
4692 }
4693
4694 return Sema::ConditionResult();
4695}
4696
4697template <typename Derived>
4699 NestedNameSpecifierLoc NNS, QualType ObjectType,
4700 NamedDecl *FirstQualifierInScope) {
4702
4703 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4704 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4705 Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix)
4706 Qualifiers.push_back(Qualifier);
4707 };
4708 insertNNS(NNS);
4709
4710 CXXScopeSpec SS;
4711 while (!Qualifiers.empty()) {
4712 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4714
4715 switch (QNNS.getKind()) {
4717 llvm_unreachable("unexpected null nested name specifier");
4718
4721 Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>(
4723 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4724 break;
4725 }
4726
4728 // There is no meaningful transformation that one could perform on the
4729 // global scope.
4730 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4731 break;
4732
4734 CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>(
4736 SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(),
4737 Q.getEndLoc());
4738 break;
4739 }
4740
4742 assert(SS.isEmpty());
4743 TypeLoc TL = Q.castAsTypeLoc();
4744
4745 if (auto DNT = TL.getAs<DependentNameTypeLoc>()) {
4746 NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc();
4747 if (QualifierLoc) {
4748 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4749 QualifierLoc, ObjectType, FirstQualifierInScope);
4750 if (!QualifierLoc)
4751 return NestedNameSpecifierLoc();
4752 ObjectType = QualType();
4753 FirstQualifierInScope = nullptr;
4754 }
4755 SS.Adopt(QualifierLoc);
4757 const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()),
4758 DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType);
4759 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo,
4760 false, SS,
4761 FirstQualifierInScope, false))
4762 return NestedNameSpecifierLoc();
4763 return SS.getWithLocInContext(SemaRef.Context);
4764 }
4765
4766 QualType T = TL.getType();
4767 TypeLocBuilder TLB;
4768 if (!getDerived().AlreadyTransformed(T)) {
4769 T = TransformTypeInObjectScope(TLB, TL, ObjectType,
4770 FirstQualifierInScope);
4771 if (T.isNull())
4772 return NestedNameSpecifierLoc();
4773 TL = TLB.getTypeLocInContext(SemaRef.Context, T);
4774 }
4775
4776 if (T->isDependentType() || T->isRecordType() ||
4777 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4778 if (T->isEnumeralType())
4779 SemaRef.Diag(TL.getBeginLoc(),
4780 diag::warn_cxx98_compat_enum_nested_name_spec);
4781 SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc());
4782 break;
4783 }
4784 // If the nested-name-specifier is an invalid type def, don't emit an
4785 // error because a previous error should have already been emitted.
4787 if (!TTL || !TTL.getDecl()->isInvalidDecl()) {
4788 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4789 << T << SS.getRange();
4790 }
4791 return NestedNameSpecifierLoc();
4792 }
4793 }
4794 }
4795
4796 // Don't rebuild the nested-name-specifier if we don't have to.
4797 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4799 return NNS;
4800
4801 // If we can re-use the source-location data from the original
4802 // nested-name-specifier, do so.
4803 if (SS.location_size() == NNS.getDataLength() &&
4804 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4806
4807 // Allocate new nested-name-specifier location information.
4808 return SS.getWithLocInContext(SemaRef.Context);
4809}
4810
4811template<typename Derived>
4815 DeclarationName Name = NameInfo.getName();
4816 if (!Name)
4817 return DeclarationNameInfo();
4818
4819 switch (Name.getNameKind()) {
4827 return NameInfo;
4828
4830 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4831 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4832 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4833 if (!NewTemplate)
4834 return DeclarationNameInfo();
4835
4836 DeclarationNameInfo NewNameInfo(NameInfo);
4837 NewNameInfo.setName(
4838 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4839 return NewNameInfo;
4840 }
4841
4845 TypeSourceInfo *NewTInfo;
4846 CanQualType NewCanTy;
4847 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4848 NewTInfo = getDerived().TransformType(OldTInfo);
4849 if (!NewTInfo)
4850 return DeclarationNameInfo();
4851 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4852 }
4853 else {
4854 NewTInfo = nullptr;
4855 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4856 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4857 if (NewT.isNull())
4858 return DeclarationNameInfo();
4859 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4860 }
4861
4862 DeclarationName NewName
4863 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4864 NewCanTy);
4865 DeclarationNameInfo NewNameInfo(NameInfo);
4866 NewNameInfo.setName(NewName);
4867 NewNameInfo.setNamedTypeInfo(NewTInfo);
4868 return NewNameInfo;
4869 }
4870 }
4871
4872 llvm_unreachable("Unknown name kind.");
4873}
4874
4875template <typename Derived>
4877 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4879 QualType ObjectType, bool AllowInjectedClassName) {
4880 if (const IdentifierInfo *II = IO.getIdentifier())
4881 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc,
4882 ObjectType, AllowInjectedClassName);
4883 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(),
4884 NameLoc, ObjectType,
4885 AllowInjectedClassName);
4886}
4887
4888template <typename Derived>
4890 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
4891 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
4892 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
4894 TemplateName UnderlyingName = QTN->getUnderlyingTemplate();
4895
4896 if (QualifierLoc) {
4897 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4898 QualifierLoc, ObjectType, FirstQualifierInScope);
4899 if (!QualifierLoc)
4900 return TemplateName();
4901 }
4902
4903 NestedNameSpecifierLoc UnderlyingQualifier;
4904 TemplateName NewUnderlyingName = getDerived().TransformTemplateName(
4905 UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType,
4906 FirstQualifierInScope, AllowInjectedClassName);
4907 if (NewUnderlyingName.isNull())
4908 return TemplateName();
4909 assert(!UnderlyingQualifier && "unexpected qualifier");
4910
4911 if (!getDerived().AlwaysRebuild() &&
4912 QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() &&
4913 NewUnderlyingName == UnderlyingName)
4914 return Name;
4915 CXXScopeSpec SS;
4916 SS.Adopt(QualifierLoc);
4917 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4918 NewUnderlyingName);
4919 }
4920
4922 if (QualifierLoc) {
4923 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4924 QualifierLoc, ObjectType, FirstQualifierInScope);
4925 if (!QualifierLoc)
4926 return TemplateName();
4927 // The qualifier-in-scope and object type only apply to the leftmost
4928 // entity.
4929 ObjectType = QualType();
4930 }
4931
4932 if (!getDerived().AlwaysRebuild() &&
4933 QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() &&
4934 ObjectType.isNull())
4935 return Name;
4936
4937 CXXScopeSpec SS;
4938 SS.Adopt(QualifierLoc);
4939 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(),
4940 NameLoc, ObjectType,
4941 AllowInjectedClassName);
4942 }
4943
4946 assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm");
4947
4948 NestedNameSpecifierLoc ReplacementQualifierLoc;
4949 TemplateName ReplacementName = S->getReplacement();
4950 if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) {
4952 Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc);
4953 ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context);
4954 }
4955
4956 TemplateName NewName = getDerived().TransformTemplateName(
4957 ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc,
4958 ObjectType, FirstQualifierInScope, AllowInjectedClassName);
4959 if (NewName.isNull())
4960 return TemplateName();
4961 Decl *AssociatedDecl =
4962 getDerived().TransformDecl(NameLoc, S->getAssociatedDecl());
4963 if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() &&
4964 AssociatedDecl == S->getAssociatedDecl())
4965 return Name;
4966 return SemaRef.Context.getSubstTemplateTemplateParm(
4967 NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(),
4968 S->getFinal());
4969 }
4970
4971 assert(!Name.getAsDeducedTemplateName() &&
4972 "DeducedTemplateName should not escape partial ordering");
4973
4974 // FIXME: Preserve UsingTemplateName.
4975 if (auto *Template = Name.getAsTemplateDecl()) {
4976 assert(!QualifierLoc && "Unexpected qualifier");
4977 return TemplateName(cast_or_null<TemplateDecl>(
4978 getDerived().TransformDecl(NameLoc, Template)));
4979 }
4980
4983 assert(!QualifierLoc &&
4984 "Unexpected qualified SubstTemplateTemplateParmPack");
4985 return getDerived().RebuildTemplateName(
4986 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
4987 SubstPack->getIndex(), SubstPack->getFinal());
4988 }
4989
4990 // These should be getting filtered out before they reach the AST.
4991 llvm_unreachable("overloaded function decl survived to here");
4992}
4993
4994template <typename Derived>
4996 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
4997 TemplateName Name, SourceLocation NameLoc) {
4998 TemplateName TN = getDerived().TransformTemplateName(
4999 QualifierLoc, TemplateKeywordLoc, Name, NameLoc);
5000 if (TN.isNull())
5001 return TemplateArgument();
5002 return TemplateArgument(TN);
5003}
5004
5005template<typename Derived>
5007 const TemplateArgument &Arg,
5008 TemplateArgumentLoc &Output) {
5009 Output = getSema().getTrivialTemplateArgumentLoc(
5010 Arg, QualType(), getDerived().getBaseLocation());
5011}
5012
5013template <typename Derived>
5015 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
5016 bool Uneval) {
5017 const TemplateArgument &Arg = Input.getArgument();
5018 switch (Arg.getKind()) {
5021 llvm_unreachable("Unexpected TemplateArgument");
5022
5027 // Transform a resolved template argument straight to a resolved template
5028 // argument. We get here when substituting into an already-substituted
5029 // template type argument during concept satisfaction checking.
5031 QualType NewT = getDerived().TransformType(T);
5032 if (NewT.isNull())
5033 return true;
5034
5036 ? Arg.getAsDecl()
5037 : nullptr;
5038 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
5040 : nullptr;
5041 if (D && !NewD)
5042 return true;
5043
5044 if (NewT == T && D == NewD)
5045 Output = Input;
5046 else if (Arg.getKind() == TemplateArgument::Integral)
5047 Output = TemplateArgumentLoc(
5048 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
5050 else if (Arg.getKind() == TemplateArgument::NullPtr)
5051 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
5053 else if (Arg.getKind() == TemplateArgument::Declaration)
5054 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
5057 Output = TemplateArgumentLoc(
5058 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
5060 else
5061 llvm_unreachable("unexpected template argument kind");
5062
5063 return false;
5064 }
5065
5067 TypeSourceInfo *TSI = Input.getTypeSourceInfo();
5068 if (!TSI)
5070
5071 TSI = getDerived().TransformType(TSI);
5072 if (!TSI)
5073 return true;
5074
5075 Output = TemplateArgumentLoc(TemplateArgument(TSI->getType()), TSI);
5076 return false;
5077 }
5078
5080 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
5081
5082 TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument(
5083 QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(),
5084 Input.getTemplateNameLoc());
5085 if (Out.isNull())
5086 return true;
5087 Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(),
5088 QualifierLoc, Input.getTemplateNameLoc());
5089 return false;
5090 }
5091
5093 llvm_unreachable("Caller should expand pack expansions");
5094
5096 // Template argument expressions are constant expressions.
5098 getSema(),
5101 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
5103
5104 Expr *InputExpr = Input.getSourceExpression();
5105 if (!InputExpr)
5106 InputExpr = Input.getArgument().getAsExpr();
5107
5108 ExprResult E = getDerived().TransformExpr(InputExpr);
5109 E = SemaRef.ActOnConstantExpression(E);
5110 if (E.isInvalid())
5111 return true;
5112 Output = TemplateArgumentLoc(
5113 TemplateArgument(E.get(), /*IsCanonical=*/false), E.get());
5114 return false;
5115 }
5116 }
5117
5118 // Work around bogus GCC warning
5119 return true;
5120}
5121
5122/// Iterator adaptor that invents template argument location information
5123/// for each of the template arguments in its underlying iterator.
5124template<typename Derived, typename InputIterator>
5127 InputIterator Iter;
5128
5129public:
5132 typedef typename std::iterator_traits<InputIterator>::difference_type
5134 typedef std::input_iterator_tag iterator_category;
5135
5136 class pointer {
5138
5139 public:
5140 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5141
5142 const TemplateArgumentLoc *operator->() const { return &Arg; }
5143 };
5144
5146 InputIterator Iter)
5147 : Self(Self), Iter(Iter) { }
5148
5150 ++Iter;
5151 return *this;
5152 }
5153
5156 ++(*this);
5157 return Old;
5158 }
5159
5162 Self.InventTemplateArgumentLoc(*Iter, Result);
5163 return Result;
5164 }
5165
5166 pointer operator->() const { return pointer(**this); }
5167
5170 return X.Iter == Y.Iter;
5171 }
5172
5175 return X.Iter != Y.Iter;
5176 }
5177};
5178
5179template<typename Derived>
5180template<typename InputIterator>
5182 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5183 bool Uneval) {
5184 for (TemplateArgumentLoc In : llvm::make_range(First, Last)) {
5186 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5187 // Unpack argument packs, which we translate them into separate
5188 // arguments.
5189 // FIXME: We could do much better if we could guarantee that the
5190 // TemplateArgumentLocInfo for the pack expansion would be usable for
5191 // all of the template arguments in the argument pack.
5192 typedef TemplateArgumentLocInventIterator<Derived,
5194 PackLocIterator;
5195
5196 TemplateArgumentListInfo *PackOutput = &Outputs;
5198
5200 PackLocIterator(*this, In.getArgument().pack_begin()),
5201 PackLocIterator(*this, In.getArgument().pack_end()), *PackOutput,
5202 Uneval))
5203 return true;
5204
5205 continue;
5206 }
5207
5208 if (In.getArgument().isPackExpansion()) {
5209 UnexpandedInfo Info;
5210 TemplateArgumentLoc Prepared;
5211 if (getDerived().PreparePackForExpansion(In, Uneval, Prepared, Info))
5212 return true;
5213 if (!Info.Expand) {
5214 Outputs.addArgument(Prepared);
5215 continue;
5216 }
5217
5218 // The transform has determined that we should perform an elementwise
5219 // expansion of the pattern. Do so.
5220 std::optional<ForgetSubstitutionRAII> ForgetSubst;
5222 ForgetSubst.emplace(getDerived());
5223 for (unsigned I = 0; I != *Info.NumExpansions; ++I) {
5224 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5225
5227 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5228 return true;
5229
5230 if (Out.getArgument().containsUnexpandedParameterPack()) {
5231 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5232 Info.OrigNumExpansions);
5233 if (Out.getArgument().isNull())
5234 return true;
5235 }
5236
5237 Outputs.addArgument(Out);
5238 }
5239
5240 // If we're supposed to retain a pack expansion, do so by temporarily
5241 // forgetting the partially-substituted parameter pack.
5242 if (Info.RetainExpansion) {
5243 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5244
5246 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5247 return true;
5248
5249 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5250 Info.OrigNumExpansions);
5251 if (Out.getArgument().isNull())
5252 return true;
5253
5254 Outputs.addArgument(Out);
5255 }
5256
5257 continue;
5258 }
5259
5260 // The simple case:
5261 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5262 return true;
5263
5264 Outputs.addArgument(Out);
5265 }
5266
5267 return false;
5268}
5269
5270template <typename Derived>
5271template <typename InputIterator>
5273 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5274 bool Uneval) {
5275
5276 // [C++26][temp.constr.normal]
5277 // any non-dependent concept template argument
5278 // is substituted into the constraint-expression of C.
5279 auto isNonDependentConceptArgument = [](const TemplateArgument &Arg) {
5280 return !Arg.isDependent() && Arg.isConceptOrConceptTemplateParameter();
5281 };
5282
5283 for (; First != Last; ++First) {
5286
5287 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5288 typedef TemplateArgumentLocInventIterator<Derived,
5290 PackLocIterator;
5292 PackLocIterator(*this, In.getArgument().pack_begin()),
5293 PackLocIterator(*this, In.getArgument().pack_end()), Outputs,
5294 Uneval))
5295 return true;
5296 continue;
5297 }
5298
5299 if (!isNonDependentConceptArgument(In.getArgument())) {
5300 Outputs.addArgument(In);
5301 continue;
5302 }
5303
5304 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5305 return true;
5306
5307 Outputs.addArgument(Out);
5308 }
5309
5310 return false;
5311}
5312
5313// FIXME: Find ways to reduce code duplication for pack expansions.
5314template <typename Derived>
5316 bool Uneval,
5318 UnexpandedInfo &Info) {
5319 auto ComputeInfo = [this](TemplateArgumentLoc Arg,
5320 bool IsLateExpansionAttempt, UnexpandedInfo &Info,
5321 TemplateArgumentLoc &Pattern) {
5322 assert(Arg.getArgument().isPackExpansion());
5323 // We have a pack expansion, for which we will be substituting into the
5324 // pattern.
5325 Pattern = getSema().getTemplateArgumentPackExpansionPattern(
5326 Arg, Info.Ellipsis, Info.OrigNumExpansions);
5328 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5329 if (IsLateExpansionAttempt) {
5330 // Request expansion only when there is an opportunity to expand a pack
5331 // that required a substituion first.
5332 bool SawPackTypes =
5333 llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) {
5334 return P.first.dyn_cast<const SubstBuiltinTemplatePackType *>();
5335 });
5336 if (!SawPackTypes) {
5337 Info.Expand = false;
5338 return false;
5339 }
5340 }
5341 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5342
5343 // Determine whether the set of unexpanded parameter packs can and
5344 // should be expanded.
5345 Info.Expand = true;
5346 Info.RetainExpansion = false;
5347 Info.NumExpansions = Info.OrigNumExpansions;
5348 return getDerived().TryExpandParameterPacks(
5349 Info.Ellipsis, Pattern.getSourceRange(), Unexpanded,
5350 /*FailOnPackProducingTemplates=*/false, Info.Expand,
5351 Info.RetainExpansion, Info.NumExpansions);
5352 };
5353
5354 TemplateArgumentLoc Pattern;
5355 if (ComputeInfo(In, false, Info, Pattern))
5356 return true;
5357
5358 if (Info.Expand) {
5359 Out = Pattern;
5360 return false;
5361 }
5362
5363 // The transform has determined that we should perform a simple
5364 // transformation on the pack expansion, producing another pack
5365 // expansion.
5366 TemplateArgumentLoc OutPattern;
5367 std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex(
5368 std::in_place, getSema(), std::nullopt);
5369 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5370 return true;
5371
5372 Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis,
5373 Info.NumExpansions);
5374 if (Out.getArgument().isNull())
5375 return true;
5376 SubstIndex.reset();
5377
5378 if (!OutPattern.getArgument().containsUnexpandedParameterPack())
5379 return false;
5380
5381 // Some packs will learn their length after substitution, e.g.
5382 // __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution
5383 // value of `T`.
5384 //
5385 // We only expand after we know sizes of all packs, check if this is the case
5386 // or not. However, we avoid a full template substitution and only do
5387 // expanstions after this point.
5388
5389 // E.g. when substituting template arguments of tuple with {T -> int} in the
5390 // following example:
5391 // template <class T>
5392 // struct TupleWithInt {
5393 // using type = std::tuple<__builtin_dedup_pack<T, int>...>;
5394 // };
5395 // TupleWithInt<int>::type y;
5396 // At this point we will see the `__builtin_dedup_pack<int, int>` with a known
5397 // length and run `ComputeInfo()` to provide the necessary information to our
5398 // caller.
5399 //
5400 // Note that we may still have situations where builtin is not going to be
5401 // expanded. For example:
5402 // template <class T>
5403 // struct Foo {
5404 // template <class U> using tuple_with_t =
5405 // std::tuple<__builtin_dedup_pack<T, U, int>...>; using type =
5406 // tuple_with_t<short>;
5407 // }
5408 // Because the substitution into `type` happens in dependent context, `type`
5409 // will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution
5410 // and the caller will not be able to expand it.
5411 ForgetSubstitutionRAII ForgetSubst(getDerived());
5412 if (ComputeInfo(Out, true, Info, OutPattern))
5413 return true;
5414 if (!Info.Expand)
5415 return false;
5416 Out = OutPattern;
5417 Info.ExpandUnderForgetSubstitions = true;
5418 return false;
5419}
5420
5421//===----------------------------------------------------------------------===//
5422// Type transformation
5423//===----------------------------------------------------------------------===//
5424
5425template<typename Derived>
5428 return T;
5429
5430 // Temporary workaround. All of these transformations should
5431 // eventually turn into transformations on TypeLocs.
5432 TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo(
5434
5435 TypeSourceInfo *NewTSI = getDerived().TransformType(TSI);
5436
5437 if (!NewTSI)
5438 return QualType();
5439
5440 return NewTSI->getType();
5441}
5442
5443template <typename Derived>
5445 // Refine the base location to the type's location.
5446 TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(),
5449 return TSI;
5450
5451 TypeLocBuilder TLB;
5452
5453 TypeLoc TL = TSI->getTypeLoc();
5454 TLB.reserve(TL.getFullDataSize());
5455
5456 QualType Result = getDerived().TransformType(TLB, TL);
5457 if (Result.isNull())
5458 return nullptr;
5459
5460 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5461}
5462
5463template<typename Derived>
5466 switch (T.getTypeLocClass()) {
5467#define ABSTRACT_TYPELOC(CLASS, PARENT)
5468#define TYPELOC(CLASS, PARENT) \
5469 case TypeLoc::CLASS: \
5470 return getDerived().Transform##CLASS##Type(TLB, \
5471 T.castAs<CLASS##TypeLoc>());
5472#include "clang/AST/TypeLocNodes.def"
5473 }
5474
5475 llvm_unreachable("unhandled type loc!");
5476}
5477
5478template<typename Derived>
5480 if (!isa<DependentNameType>(T))
5481 return TransformType(T);
5482
5484 return T;
5485 TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo(
5487 TypeSourceInfo *NewTSI = getDerived().TransformTypeWithDeducedTST(TSI);
5488 return NewTSI ? NewTSI->getType() : QualType();
5489}
5490
5491template <typename Derived>
5494 if (!isa<DependentNameType>(TSI->getType()))
5495 return TransformType(TSI);
5496
5497 // Refine the base location to the type's location.
5498 TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(),
5501 return TSI;
5502
5503 TypeLocBuilder TLB;
5504
5505 TypeLoc TL = TSI->getTypeLoc();
5506 TLB.reserve(TL.getFullDataSize());
5507
5508 auto QTL = TL.getAs<QualifiedTypeLoc>();
5509 if (QTL)
5510 TL = QTL.getUnqualifiedLoc();
5511
5512 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5513
5514 QualType Result = getDerived().TransformDependentNameType(
5515 TLB, DNTL, /*DeducedTSTContext*/true);
5516 if (Result.isNull())
5517 return nullptr;
5518
5519 if (QTL) {
5520 Result = getDerived().RebuildQualifiedType(Result, QTL);
5521 if (Result.isNull())
5522 return nullptr;
5524 }
5525
5526 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5527}
5528
5529template<typename Derived>
5532 QualifiedTypeLoc T) {
5534 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5535 auto SuppressObjCLifetime =
5537 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5538 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5539 SuppressObjCLifetime);
5540 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5541 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5542 TLB, STTP, SuppressObjCLifetime);
5543 } else {
5544 Result = getDerived().TransformType(TLB, UnqualTL);
5545 }
5546
5547 if (Result.isNull())
5548 return QualType();
5549
5550 Result = getDerived().RebuildQualifiedType(Result, T);
5551
5552 if (Result.isNull())
5553 return QualType();
5554
5555 // RebuildQualifiedType might have updated the type, but not in a way
5556 // that invalidates the TypeLoc. (There's no location information for
5557 // qualifiers.)
5559
5560 return Result;
5561}
5562
5563template <typename Derived>
5565 QualifiedTypeLoc TL) {
5566
5567 SourceLocation Loc = TL.getBeginLoc();
5568 Qualifiers Quals = TL.getType().getLocalQualifiers();
5569
5570 if ((T.getAddressSpace() != LangAS::Default &&
5571 Quals.getAddressSpace() != LangAS::Default) &&
5572 T.getAddressSpace() != Quals.getAddressSpace()) {
5573 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5574 << TL.getType() << T;
5575 return QualType();
5576 }
5577
5578 PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth();
5579 if (LocalPointerAuth.isPresent()) {
5580 if (T.getPointerAuth().isPresent()) {
5581 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType();
5582 return QualType();
5583 }
5584 if (!T->isDependentType()) {
5585 if (!T->isSignableType(SemaRef.getASTContext())) {
5586 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T;
5587 return QualType();
5588 }
5589 }
5590 }
5591 // C++ [dcl.fct]p7:
5592 // [When] adding cv-qualifications on top of the function type [...] the
5593 // cv-qualifiers are ignored.
5594 if (T->isFunctionType()) {
5595 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
5596 Quals.getAddressSpace());
5597 return T;
5598 }
5599
5600 // C++ [dcl.ref]p1:
5601 // when the cv-qualifiers are introduced through the use of a typedef-name
5602 // or decltype-specifier [...] the cv-qualifiers are ignored.
5603 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5604 // applied to a reference type.
5605 if (T->isReferenceType()) {
5606 // The only qualifier that applies to a reference type is restrict.
5607 if (!Quals.hasRestrict())
5608 return T;
5610 }
5611
5612 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5613 // resulting type.
5614 if (Quals.hasObjCLifetime()) {
5615 if (!T->isObjCLifetimeType() && !T->isDependentType())
5616 Quals.removeObjCLifetime();
5617 else if (T.getObjCLifetime()) {
5618 // Objective-C ARC:
5619 // A lifetime qualifier applied to a substituted template parameter
5620 // overrides the lifetime qualifier from the template argument.
5621 const AutoType *AutoTy;
5622 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5623 // 'auto' types behave the same way as template parameters.
5624 QualType Deduced = AutoTy->getDeducedType();
5625 Qualifiers Qs = Deduced.getQualifiers();
5626 Qs.removeObjCLifetime();
5627 Deduced =
5628 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5629 T = SemaRef.Context.getAutoType(AutoTy->getDeducedKind(), Deduced,
5630 AutoTy->getKeyword(),
5631 AutoTy->getTypeConstraintConcept(),
5632 AutoTy->getTypeConstraintArguments());
5633 } else {
5634 // Otherwise, complain about the addition of a qualifier to an
5635 // already-qualified type.
5636 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5637 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5638 Quals.removeObjCLifetime();
5639 }
5640 }
5641 }
5642
5643 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5644}
5645
5646template <typename Derived>
5647QualType TreeTransform<Derived>::TransformTypeInObjectScope(
5648 TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType,
5649 NamedDecl *FirstQualifierInScope) {
5650 assert(!getDerived().AlreadyTransformed(TL.getType()));
5651
5652 switch (TL.getTypeLocClass()) {
5653 case TypeLoc::TemplateSpecialization:
5654 return getDerived().TransformTemplateSpecializationType(
5655 TLB, TL.castAs<TemplateSpecializationTypeLoc>(), ObjectType,
5656 FirstQualifierInScope, /*AllowInjectedClassName=*/true);
5657 case TypeLoc::DependentName:
5658 return getDerived().TransformDependentNameType(
5659 TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false,
5660 ObjectType, FirstQualifierInScope);
5661 default:
5662 // Any dependent canonical type can appear here, through type alias
5663 // templates.
5664 return getDerived().TransformType(TLB, TL);
5665 }
5666}
5667
5668template <class TyLoc> static inline
5670 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5671 NewT.setNameLoc(T.getNameLoc());
5672 return T.getType();
5673}
5674
5675template<typename Derived>
5676QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5677 BuiltinTypeLoc T) {
5678 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5679 NewT.setBuiltinLoc(T.getBuiltinLoc());
5680 if (T.needsExtraLocalData())
5681 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5682 return T.getType();
5683}
5684
5685template<typename Derived>
5687 ComplexTypeLoc T) {
5688 // FIXME: recurse?
5689 return TransformTypeSpecType(TLB, T);
5690}
5691
5692template <typename Derived>
5694 AdjustedTypeLoc TL) {
5695 // Adjustments applied during transformation are handled elsewhere.
5696 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5697}
5698
5699template<typename Derived>
5701 DecayedTypeLoc TL) {
5702 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5703 if (OriginalType.isNull())
5704 return QualType();
5705
5706 QualType Result = TL.getType();
5707 if (getDerived().AlwaysRebuild() ||
5708 OriginalType != TL.getOriginalLoc().getType())
5709 Result = SemaRef.Context.getDecayedType(OriginalType);
5710 TLB.push<DecayedTypeLoc>(Result);
5711 // Nothing to set for DecayedTypeLoc.
5712 return Result;
5713}
5714
5715template <typename Derived>
5719 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5720 if (OriginalType.isNull())
5721 return QualType();
5722
5723 QualType Result = TL.getType();
5724 if (getDerived().AlwaysRebuild() ||
5725 OriginalType != TL.getElementLoc().getType())
5726 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5727 TLB.push<ArrayParameterTypeLoc>(Result);
5728 // Nothing to set for ArrayParameterTypeLoc.
5729 return Result;
5730}
5731
5732template<typename Derived>
5734 PointerTypeLoc TL) {
5735 QualType PointeeType
5736 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5737 if (PointeeType.isNull())
5738 return QualType();
5739
5740 QualType Result = TL.getType();
5741 if (PointeeType->getAs<ObjCObjectType>()) {
5742 // A dependent pointer type 'T *' has is being transformed such
5743 // that an Objective-C class type is being replaced for 'T'. The
5744 // resulting pointer type is an ObjCObjectPointerType, not a
5745 // PointerType.
5746 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5747
5749 NewT.setStarLoc(TL.getStarLoc());
5750 return Result;
5751 }
5752
5753 if (getDerived().AlwaysRebuild() ||
5754 PointeeType != TL.getPointeeLoc().getType()) {
5755 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5756 if (Result.isNull())
5757 return QualType();
5758 }
5759
5760 // Objective-C ARC can add lifetime qualifiers to the type that we're
5761 // pointing to.
5762 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5763
5764 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5765 NewT.setSigilLoc(TL.getSigilLoc());
5766 return Result;
5767}
5768
5769template<typename Derived>
5773 QualType PointeeType
5774 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5775 if (PointeeType.isNull())
5776 return QualType();
5777
5778 QualType Result = TL.getType();
5779 if (getDerived().AlwaysRebuild() ||
5780 PointeeType != TL.getPointeeLoc().getType()) {
5781 Result = getDerived().RebuildBlockPointerType(PointeeType,
5782 TL.getSigilLoc());
5783 if (Result.isNull())
5784 return QualType();
5785 }
5786
5788 NewT.setSigilLoc(TL.getSigilLoc());
5789 return Result;
5790}
5791
5792/// Transforms a reference type. Note that somewhat paradoxically we
5793/// don't care whether the type itself is an l-value type or an r-value
5794/// type; we only care if the type was *written* as an l-value type
5795/// or an r-value type.
5796template<typename Derived>
5799 ReferenceTypeLoc TL) {
5800 const ReferenceType *T = TL.getTypePtr();
5801
5802 // Note that this works with the pointee-as-written.
5803 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5804 if (PointeeType.isNull())
5805 return QualType();
5806
5807 QualType Result = TL.getType();
5808 if (getDerived().AlwaysRebuild() ||
5809 PointeeType != T->getPointeeTypeAsWritten()) {
5810 Result = getDerived().RebuildReferenceType(PointeeType,
5811 T->isSpelledAsLValue(),
5812 TL.getSigilLoc());
5813 if (Result.isNull())
5814 return QualType();
5815 }
5816
5817 // Objective-C ARC can add lifetime qualifiers to the type that we're
5818 // referring to.
5821
5822 // r-value references can be rebuilt as l-value references.
5823 ReferenceTypeLoc NewTL;
5825 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5826 else
5827 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5828 NewTL.setSigilLoc(TL.getSigilLoc());
5829
5830 return Result;
5831}
5832
5833template<typename Derived>
5837 return TransformReferenceType(TLB, TL);
5838}
5839
5840template<typename Derived>
5841QualType
5842TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5843 RValueReferenceTypeLoc TL) {
5844 return TransformReferenceType(TLB, TL);
5845}
5846
5847template<typename Derived>
5851 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5852 if (PointeeType.isNull())
5853 return QualType();
5854
5855 const MemberPointerType *T = TL.getTypePtr();
5856
5857 NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc();
5858 NestedNameSpecifierLoc NewQualifierLoc =
5859 getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc);
5860 if (!NewQualifierLoc)
5861 return QualType();
5862
5863 CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr;
5864 if (OldCls) {
5865 NewCls = cast_or_null<CXXRecordDecl>(
5866 getDerived().TransformDecl(TL.getStarLoc(), OldCls));
5867 if (!NewCls)
5868 return QualType();
5869 }
5870
5871 QualType Result = TL.getType();
5872 if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() ||
5873 NewQualifierLoc.getNestedNameSpecifier() !=
5874 OldQualifierLoc.getNestedNameSpecifier() ||
5875 NewCls != OldCls) {
5876 CXXScopeSpec SS;
5877 SS.Adopt(NewQualifierLoc);
5878 Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
5879 TL.getStarLoc());
5880 if (Result.isNull())
5881 return QualType();
5882 }
5883
5884 // If we had to adjust the pointee type when building a member pointer, make
5885 // sure to push TypeLoc info for it.
5886 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
5887 if (MPT && PointeeType != MPT->getPointeeType()) {
5888 assert(isa<AdjustedType>(MPT->getPointeeType()));
5889 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
5890 }
5891
5893 NewTL.setSigilLoc(TL.getSigilLoc());
5894 NewTL.setQualifierLoc(NewQualifierLoc);
5895
5896 return Result;
5897}
5898
5899template<typename Derived>
5903 const ConstantArrayType *T = TL.getTypePtr();
5904 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5905 if (ElementType.isNull())
5906 return QualType();
5907
5908 // Prefer the expression from the TypeLoc; the other may have been uniqued.
5909 Expr *OldSize = TL.getSizeExpr();
5910 if (!OldSize)
5911 OldSize = const_cast<Expr*>(T->getSizeExpr());
5912 Expr *NewSize = nullptr;
5913 if (OldSize) {
5916 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
5917 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
5918 }
5919
5920 QualType Result = TL.getType();
5921 if (getDerived().AlwaysRebuild() ||
5922 ElementType != T->getElementType() ||
5923 (T->getSizeExpr() && NewSize != OldSize)) {
5924 Result = getDerived().RebuildConstantArrayType(ElementType,
5925 T->getSizeModifier(),
5926 T->getSize(), NewSize,
5927 T->getIndexTypeCVRQualifiers(),
5928 TL.getBracketsRange());
5929 if (Result.isNull())
5930 return QualType();
5931 }
5932
5933 // We might have either a ConstantArrayType or a VariableArrayType now:
5934 // a ConstantArrayType is allowed to have an element type which is a
5935 // VariableArrayType if the type is dependent. Fortunately, all array
5936 // types have the same location layout.
5937 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
5938 NewTL.setLBracketLoc(TL.getLBracketLoc());
5939 NewTL.setRBracketLoc(TL.getRBracketLoc());
5940 NewTL.setSizeExpr(NewSize);
5941
5942 return Result;
5943}
5944
5945template<typename Derived>
5947 TypeLocBuilder &TLB,
5949 const IncompleteArrayType *T = TL.getTypePtr();
5950 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5951 if (ElementType.isNull())
5952 return QualType();
5953
5954 QualType Result = TL.getType();
5955 if (getDerived().AlwaysRebuild() ||
5956 ElementType != T->getElementType()) {
5957 Result = getDerived().RebuildIncompleteArrayType(ElementType,
5958 T->getSizeModifier(),
5959 T->getIndexTypeCVRQualifiers(),
5960 TL.getBracketsRange());
5961 if (Result.isNull())
5962 return QualType();
5963 }
5964
5966 NewTL.setLBracketLoc(TL.getLBracketLoc());
5967 NewTL.setRBracketLoc(TL.getRBracketLoc());
5968 NewTL.setSizeExpr(nullptr);
5969
5970 return Result;
5971}
5972
5973template<typename Derived>
5977 const VariableArrayType *T = TL.getTypePtr();
5978 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
5979 if (ElementType.isNull())
5980 return QualType();
5981
5982 ExprResult SizeResult;
5983 {
5986 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
5987 }
5988 if (SizeResult.isInvalid())
5989 return QualType();
5990 SizeResult =
5991 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
5992 if (SizeResult.isInvalid())
5993 return QualType();
5994
5995 Expr *Size = SizeResult.get();
5996
5997 QualType Result = TL.getType();
5998 if (getDerived().AlwaysRebuild() ||
5999 ElementType != T->getElementType() ||
6000 Size != T->getSizeExpr()) {
6001 Result = getDerived().RebuildVariableArrayType(ElementType,
6002 T->getSizeModifier(),
6003 Size,
6004 T->getIndexTypeCVRQualifiers(),
6005 TL.getBracketsRange());
6006 if (Result.isNull())
6007 return QualType();
6008 }
6009
6010 // We might have constant size array now, but fortunately it has the same
6011 // location layout.
6012 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6013 NewTL.setLBracketLoc(TL.getLBracketLoc());
6014 NewTL.setRBracketLoc(TL.getRBracketLoc());
6015 NewTL.setSizeExpr(Size);
6016
6017 return Result;
6018}
6019
6020template<typename Derived>
6024 const DependentSizedArrayType *T = TL.getTypePtr();
6025 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6026 if (ElementType.isNull())
6027 return QualType();
6028
6029 // Array bounds are constant expressions.
6032
6033 // If we have a VLA then it won't be a constant.
6034 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
6035
6036 // Prefer the expression from the TypeLoc; the other may have been uniqued.
6037 Expr *origSize = TL.getSizeExpr();
6038 if (!origSize) origSize = T->getSizeExpr();
6039
6040 ExprResult sizeResult
6041 = getDerived().TransformExpr(origSize);
6042 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
6043 if (sizeResult.isInvalid())
6044 return QualType();
6045
6046 Expr *size = sizeResult.get();
6047
6048 QualType Result = TL.getType();
6049 if (getDerived().AlwaysRebuild() ||
6050 ElementType != T->getElementType() ||
6051 size != origSize) {
6052 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
6053 T->getSizeModifier(),
6054 size,
6055 T->getIndexTypeCVRQualifiers(),
6056 TL.getBracketsRange());
6057 if (Result.isNull())
6058 return QualType();
6059 }
6060
6061 // We might have any sort of array type now, but fortunately they
6062 // all have the same location layout.
6063 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6064 NewTL.setLBracketLoc(TL.getLBracketLoc());
6065 NewTL.setRBracketLoc(TL.getRBracketLoc());
6066 NewTL.setSizeExpr(size);
6067
6068 return Result;
6069}
6070
6071template <typename Derived>
6074 const DependentVectorType *T = TL.getTypePtr();
6075 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6076 if (ElementType.isNull())
6077 return QualType();
6078
6081
6082 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
6083 Size = SemaRef.ActOnConstantExpression(Size);
6084 if (Size.isInvalid())
6085 return QualType();
6086
6087 QualType Result = TL.getType();
6088 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6089 Size.get() != T->getSizeExpr()) {
6090 Result = getDerived().RebuildDependentVectorType(
6091 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
6092 if (Result.isNull())
6093 return QualType();
6094 }
6095
6096 // Result might be dependent or not.
6099 TLB.push<DependentVectorTypeLoc>(Result);
6100 NewTL.setNameLoc(TL.getNameLoc());
6101 } else {
6102 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6103 NewTL.setNameLoc(TL.getNameLoc());
6104 }
6105
6106 return Result;
6107}
6108
6109template<typename Derived>
6111 TypeLocBuilder &TLB,
6113 const DependentSizedExtVectorType *T = TL.getTypePtr();
6114
6115 // FIXME: ext vector locs should be nested
6116 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6117 if (ElementType.isNull())
6118 return QualType();
6119
6120 // Vector sizes are constant expressions.
6123
6124 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
6125 Size = SemaRef.ActOnConstantExpression(Size);
6126 if (Size.isInvalid())
6127 return QualType();
6128
6129 QualType Result = TL.getType();
6130 if (getDerived().AlwaysRebuild() ||
6131 ElementType != T->getElementType() ||
6132 Size.get() != T->getSizeExpr()) {
6133 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
6134 Size.get(),
6135 T->getAttributeLoc());
6136 if (Result.isNull())
6137 return QualType();
6138 }
6139
6140 // Result might be dependent or not.
6144 NewTL.setNameLoc(TL.getNameLoc());
6145 } else {
6146 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6147 NewTL.setNameLoc(TL.getNameLoc());
6148 }
6149
6150 return Result;
6151}
6152
6153template <typename Derived>
6157 const ConstantMatrixType *T = TL.getTypePtr();
6158 QualType ElementType = getDerived().TransformType(T->getElementType());
6159 if (ElementType.isNull())
6160 return QualType();
6161
6162 QualType Result = TL.getType();
6163 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6164 Result = getDerived().RebuildConstantMatrixType(
6165 ElementType, T->getNumRows(), T->getNumColumns());
6166 if (Result.isNull())
6167 return QualType();
6168 }
6169
6171 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6172 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6173 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6174 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6175
6176 return Result;
6177}
6178
6179template <typename Derived>
6182 const DependentSizedMatrixType *T = TL.getTypePtr();
6183
6184 QualType ElementType = getDerived().TransformType(T->getElementType());
6185 if (ElementType.isNull()) {
6186 return QualType();
6187 }
6188
6189 // Matrix dimensions are constant expressions.
6192
6193 Expr *origRows = TL.getAttrRowOperand();
6194 if (!origRows)
6195 origRows = T->getRowExpr();
6196 Expr *origColumns = TL.getAttrColumnOperand();
6197 if (!origColumns)
6198 origColumns = T->getColumnExpr();
6199
6200 ExprResult rowResult = getDerived().TransformExpr(origRows);
6201 rowResult = SemaRef.ActOnConstantExpression(rowResult);
6202 if (rowResult.isInvalid())
6203 return QualType();
6204
6205 ExprResult columnResult = getDerived().TransformExpr(origColumns);
6206 columnResult = SemaRef.ActOnConstantExpression(columnResult);
6207 if (columnResult.isInvalid())
6208 return QualType();
6209
6210 Expr *rows = rowResult.get();
6211 Expr *columns = columnResult.get();
6212
6213 QualType Result = TL.getType();
6214 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6215 rows != origRows || columns != origColumns) {
6216 Result = getDerived().RebuildDependentSizedMatrixType(
6217 ElementType, rows, columns, T->getAttributeLoc());
6218
6219 if (Result.isNull())
6220 return QualType();
6221 }
6222
6223 // We might have any sort of matrix type now, but fortunately they
6224 // all have the same location layout.
6225 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
6226 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6227 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6228 NewTL.setAttrRowOperand(rows);
6229 NewTL.setAttrColumnOperand(columns);
6230 return Result;
6231}
6232
6233template <typename Derived>
6236 const DependentAddressSpaceType *T = TL.getTypePtr();
6237
6238 QualType pointeeType =
6239 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
6240
6241 if (pointeeType.isNull())
6242 return QualType();
6243
6244 // Address spaces are constant expressions.
6247
6248 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
6249 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
6250 if (AddrSpace.isInvalid())
6251 return QualType();
6252
6253 QualType Result = TL.getType();
6254 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
6255 AddrSpace.get() != T->getAddrSpaceExpr()) {
6256 Result = getDerived().RebuildDependentAddressSpaceType(
6257 pointeeType, AddrSpace.get(), T->getAttributeLoc());
6258 if (Result.isNull())
6259 return QualType();
6260 }
6261
6262 // Result might be dependent or not.
6266
6267 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6268 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
6269 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6270
6271 } else {
6272 TLB.TypeWasModifiedSafely(Result);
6273 }
6274
6275 return Result;
6276}
6277
6278template <typename Derived>
6280 VectorTypeLoc TL) {
6281 const VectorType *T = TL.getTypePtr();
6282 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6283 if (ElementType.isNull())
6284 return QualType();
6285
6286 QualType Result = TL.getType();
6287 if (getDerived().AlwaysRebuild() ||
6288 ElementType != T->getElementType()) {
6289 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6290 T->getVectorKind());
6291 if (Result.isNull())
6292 return QualType();
6293 }
6294
6295 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6296 NewTL.setNameLoc(TL.getNameLoc());
6297
6298 return Result;
6299}
6300
6301template<typename Derived>
6303 ExtVectorTypeLoc TL) {
6304 const VectorType *T = TL.getTypePtr();
6305 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6306 if (ElementType.isNull())
6307 return QualType();
6308
6309 QualType Result = TL.getType();
6310 if (getDerived().AlwaysRebuild() ||
6311 ElementType != T->getElementType()) {
6312 Result = getDerived().RebuildExtVectorType(ElementType,
6313 T->getNumElements(),
6314 /*FIXME*/ SourceLocation());
6315 if (Result.isNull())
6316 return QualType();
6317 }
6318
6319 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6320 NewTL.setNameLoc(TL.getNameLoc());
6321
6322 return Result;
6323}
6324
6325template <typename Derived>
6327 ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions,
6328 bool ExpectParameterPack) {
6329 TypeSourceInfo *OldTSI = OldParm->getTypeSourceInfo();
6330 TypeSourceInfo *NewTSI = nullptr;
6331
6332 if (NumExpansions && isa<PackExpansionType>(OldTSI->getType())) {
6333 // If we're substituting into a pack expansion type and we know the
6334 // length we want to expand to, just substitute for the pattern.
6335 TypeLoc OldTL = OldTSI->getTypeLoc();
6336 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6337
6338 TypeLocBuilder TLB;
6339 TypeLoc NewTL = OldTSI->getTypeLoc();
6340 TLB.reserve(NewTL.getFullDataSize());
6341
6342 QualType Result = getDerived().TransformType(TLB,
6343 OldExpansionTL.getPatternLoc());
6344 if (Result.isNull())
6345 return nullptr;
6346
6348 OldExpansionTL.getPatternLoc().getSourceRange(),
6349 OldExpansionTL.getEllipsisLoc(),
6350 NumExpansions);
6351 if (Result.isNull())
6352 return nullptr;
6353
6354 PackExpansionTypeLoc NewExpansionTL
6355 = TLB.push<PackExpansionTypeLoc>(Result);
6356 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6357 NewTSI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6358 } else
6359 NewTSI = getDerived().TransformType(OldTSI);
6360 if (!NewTSI)
6361 return nullptr;
6362
6363 if (NewTSI == OldTSI && indexAdjustment == 0)
6364 return OldParm;
6365
6367 SemaRef.Context, OldParm->getDeclContext(), OldParm->getInnerLocStart(),
6368 OldParm->getLocation(), OldParm->getIdentifier(), NewTSI->getType(),
6369 NewTSI, OldParm->getStorageClass(),
6370 /* DefArg */ nullptr);
6371 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6372 OldParm->getFunctionScopeIndex() + indexAdjustment);
6373 getDerived().transformedLocalDecl(OldParm, {newParm});
6374 return newParm;
6375}
6376
6377template <typename Derived>
6380 const QualType *ParamTypes,
6381 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6382 SmallVectorImpl<QualType> &OutParamTypes,
6385 unsigned *LastParamTransformed) {
6386 int indexAdjustment = 0;
6387
6388 unsigned NumParams = Params.size();
6389 for (unsigned i = 0; i != NumParams; ++i) {
6390 if (LastParamTransformed)
6391 *LastParamTransformed = i;
6392 if (ParmVarDecl *OldParm = Params[i]) {
6393 assert(OldParm->getFunctionScopeIndex() == i);
6394
6395 UnsignedOrNone NumExpansions = std::nullopt;
6396 ParmVarDecl *NewParm = nullptr;
6397 if (OldParm->isParameterPack()) {
6398 // We have a function parameter pack that may need to be expanded.
6400
6401 // Find the parameter packs that could be expanded.
6402 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6404 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6405 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6406
6407 // Determine whether we should expand the parameter packs.
6408 bool ShouldExpand = false;
6409 bool RetainExpansion = false;
6410 UnsignedOrNone OrigNumExpansions = std::nullopt;
6411 if (Unexpanded.size() > 0) {
6412 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6413 NumExpansions = OrigNumExpansions;
6415 ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
6416 Unexpanded, /*FailOnPackProducingTemplates=*/true,
6417 ShouldExpand, RetainExpansion, NumExpansions)) {
6418 return true;
6419 }
6420 } else {
6421#ifndef NDEBUG
6422 const AutoType *AT =
6423 Pattern.getType().getTypePtr()->getContainedAutoType();
6424 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6425 "Could not find parameter packs or undeduced auto type!");
6426#endif
6427 }
6428
6429 if (ShouldExpand) {
6430 // Expand the function parameter pack into multiple, separate
6431 // parameters.
6432 getDerived().ExpandingFunctionParameterPack(OldParm);
6433 for (unsigned I = 0; I != *NumExpansions; ++I) {
6434 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6435 ParmVarDecl *NewParm
6436 = getDerived().TransformFunctionTypeParam(OldParm,
6437 indexAdjustment++,
6438 OrigNumExpansions,
6439 /*ExpectParameterPack=*/false);
6440 if (!NewParm)
6441 return true;
6442
6443 if (ParamInfos)
6444 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6445 OutParamTypes.push_back(NewParm->getType());
6446 if (PVars)
6447 PVars->push_back(NewParm);
6448 }
6449
6450 // If we're supposed to retain a pack expansion, do so by temporarily
6451 // forgetting the partially-substituted parameter pack.
6452 if (RetainExpansion) {
6453 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6454 ParmVarDecl *NewParm
6455 = getDerived().TransformFunctionTypeParam(OldParm,
6456 indexAdjustment++,
6457 OrigNumExpansions,
6458 /*ExpectParameterPack=*/false);
6459 if (!NewParm)
6460 return true;
6461
6462 if (ParamInfos)
6463 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6464 OutParamTypes.push_back(NewParm->getType());
6465 if (PVars)
6466 PVars->push_back(NewParm);
6467 }
6468
6469 // The next parameter should have the same adjustment as the
6470 // last thing we pushed, but we post-incremented indexAdjustment
6471 // on every push. Also, if we push nothing, the adjustment should
6472 // go down by one.
6473 indexAdjustment--;
6474
6475 // We're done with the pack expansion.
6476 continue;
6477 }
6478
6479 // We'll substitute the parameter now without expanding the pack
6480 // expansion.
6481 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6482 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6483 indexAdjustment,
6484 NumExpansions,
6485 /*ExpectParameterPack=*/true);
6486 assert(NewParm->isParameterPack() &&
6487 "Parameter pack no longer a parameter pack after "
6488 "transformation.");
6489 } else {
6490 NewParm = getDerived().TransformFunctionTypeParam(
6491 OldParm, indexAdjustment, std::nullopt,
6492 /*ExpectParameterPack=*/false);
6493 }
6494
6495 if (!NewParm)
6496 return true;
6497
6498 if (ParamInfos)
6499 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6500 OutParamTypes.push_back(NewParm->getType());
6501 if (PVars)
6502 PVars->push_back(NewParm);
6503 continue;
6504 }
6505
6506 // Deal with the possibility that we don't have a parameter
6507 // declaration for this parameter.
6508 assert(ParamTypes);
6509 QualType OldType = ParamTypes[i];
6510 bool IsPackExpansion = false;
6511 UnsignedOrNone NumExpansions = std::nullopt;
6512 QualType NewType;
6513 if (const PackExpansionType *Expansion
6514 = dyn_cast<PackExpansionType>(OldType)) {
6515 // We have a function parameter pack that may need to be expanded.
6516 QualType Pattern = Expansion->getPattern();
6518 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6519
6520 // Determine whether we should expand the parameter packs.
6521 bool ShouldExpand = false;
6522 bool RetainExpansion = false;
6524 Loc, SourceRange(), Unexpanded,
6525 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
6526 RetainExpansion, NumExpansions)) {
6527 return true;
6528 }
6529
6530 if (ShouldExpand) {
6531 // Expand the function parameter pack into multiple, separate
6532 // parameters.
6533 for (unsigned I = 0; I != *NumExpansions; ++I) {
6534 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6535 QualType NewType = getDerived().TransformType(Pattern);
6536 if (NewType.isNull())
6537 return true;
6538
6539 if (NewType->containsUnexpandedParameterPack()) {
6540 NewType = getSema().getASTContext().getPackExpansionType(
6541 NewType, std::nullopt);
6542
6543 if (NewType.isNull())
6544 return true;
6545 }
6546
6547 if (ParamInfos)
6548 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6549 OutParamTypes.push_back(NewType);
6550 if (PVars)
6551 PVars->push_back(nullptr);
6552 }
6553
6554 // We're done with the pack expansion.
6555 continue;
6556 }
6557
6558 // If we're supposed to retain a pack expansion, do so by temporarily
6559 // forgetting the partially-substituted parameter pack.
6560 if (RetainExpansion) {
6561 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6562 QualType NewType = getDerived().TransformType(Pattern);
6563 if (NewType.isNull())
6564 return true;
6565
6566 if (ParamInfos)
6567 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6568 OutParamTypes.push_back(NewType);
6569 if (PVars)
6570 PVars->push_back(nullptr);
6571 }
6572
6573 // We'll substitute the parameter now without expanding the pack
6574 // expansion.
6575 OldType = Expansion->getPattern();
6576 IsPackExpansion = true;
6577 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6578 NewType = getDerived().TransformType(OldType);
6579 } else {
6580 NewType = getDerived().TransformType(OldType);
6581 }
6582
6583 if (NewType.isNull())
6584 return true;
6585
6586 if (IsPackExpansion)
6587 NewType = getSema().Context.getPackExpansionType(NewType,
6588 NumExpansions);
6589
6590 if (ParamInfos)
6591 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6592 OutParamTypes.push_back(NewType);
6593 if (PVars)
6594 PVars->push_back(nullptr);
6595 }
6596
6597#ifndef NDEBUG
6598 if (PVars) {
6599 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6600 if (ParmVarDecl *parm = (*PVars)[i])
6601 assert(parm->getFunctionScopeIndex() == i);
6602 }
6603#endif
6604
6605 return false;
6606}
6607
6608template<typename Derived>
6612 SmallVector<QualType, 4> ExceptionStorage;
6613 return getDerived().TransformFunctionProtoType(
6614 TLB, TL, nullptr, Qualifiers(),
6615 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6616 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6617 ExceptionStorage, Changed);
6618 });
6619}
6620
6621template<typename Derived> template<typename Fn>
6623 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6624 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6625
6626 // Transform the parameters and return type.
6627 //
6628 // We are required to instantiate the params and return type in source order.
6629 // When the function has a trailing return type, we instantiate the
6630 // parameters before the return type, since the return type can then refer
6631 // to the parameters themselves (via decltype, sizeof, etc.).
6632 //
6633 SmallVector<QualType, 4> ParamTypes;
6635 Sema::ExtParameterInfoBuilder ExtParamInfos;
6636 const FunctionProtoType *T = TL.getTypePtr();
6637
6638 QualType ResultType;
6639
6640 if (T->hasTrailingReturn()) {
6642 TL.getBeginLoc(), TL.getParams(),
6644 T->getExtParameterInfosOrNull(),
6645 ParamTypes, &ParamDecls, ExtParamInfos))
6646 return QualType();
6647
6648 {
6649 // C++11 [expr.prim.general]p3:
6650 // If a declaration declares a member function or member function
6651 // template of a class X, the expression this is a prvalue of type
6652 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6653 // and the end of the function-definition, member-declarator, or
6654 // declarator.
6655 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6656 Sema::CXXThisScopeRAII ThisScope(
6657 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6658
6659 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6660 if (ResultType.isNull())
6661 return QualType();
6662 }
6663 }
6664 else {
6665 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6666 if (ResultType.isNull())
6667 return QualType();
6668
6670 TL.getBeginLoc(), TL.getParams(),
6672 T->getExtParameterInfosOrNull(),
6673 ParamTypes, &ParamDecls, ExtParamInfos))
6674 return QualType();
6675 }
6676
6677 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
6678
6679 bool EPIChanged = false;
6680 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6681 return QualType();
6682
6683 // Handle extended parameter information.
6684 if (auto NewExtParamInfos =
6685 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6686 if (!EPI.ExtParameterInfos ||
6688 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6689 EPIChanged = true;
6690 }
6691 EPI.ExtParameterInfos = NewExtParamInfos;
6692 } else if (EPI.ExtParameterInfos) {
6693 EPIChanged = true;
6694 EPI.ExtParameterInfos = nullptr;
6695 }
6696
6697 // Transform any function effects with unevaluated conditions.
6698 // Hold this set in a local for the rest of this function, since EPI
6699 // may need to hold a FunctionEffectsRef pointing into it.
6700 std::optional<FunctionEffectSet> NewFX;
6701 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6702 NewFX.emplace();
6705
6706 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6707 FunctionEffectWithCondition NewEC = PrevEC;
6708 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6709 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6710 if (NewExpr.isInvalid())
6711 return QualType();
6712 std::optional<FunctionEffectMode> Mode =
6713 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6714 if (!Mode)
6715 return QualType();
6716
6717 // The condition expression has been transformed, and re-evaluated.
6718 // It may or may not have become constant.
6719 switch (*Mode) {
6721 NewEC.Cond = {};
6722 break;
6724 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6725 NewEC.Cond = {};
6726 break;
6728 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6729 break;
6731 llvm_unreachable(
6732 "FunctionEffectMode::None shouldn't be possible here");
6733 }
6734 }
6735 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6736 TL.getBeginLoc())) {
6738 NewFX->insert(NewEC, Errs);
6739 assert(Errs.empty());
6740 }
6741 }
6742 EPI.FunctionEffects = *NewFX;
6743 EPIChanged = true;
6744 }
6745
6746 QualType Result = TL.getType();
6747 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6748 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6749 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6750 if (Result.isNull())
6751 return QualType();
6752 }
6753
6756 NewTL.setLParenLoc(TL.getLParenLoc());
6757 NewTL.setRParenLoc(TL.getRParenLoc());
6760 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6761 NewTL.setParam(i, ParamDecls[i]);
6762
6763 return Result;
6764}
6765
6766template<typename Derived>
6769 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6770 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6771
6772 // Instantiate a dynamic noexcept expression, if any.
6773 if (isComputedNoexcept(ESI.Type)) {
6774 // Update this scrope because ContextDecl in Sema will be used in
6775 // TransformExpr.
6776 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6777 Sema::CXXThisScopeRAII ThisScope(
6778 SemaRef, Method ? Method->getParent() : nullptr,
6779 Method ? Method->getMethodQualifiers() : Qualifiers{},
6780 Method != nullptr);
6783 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6784 if (NoexceptExpr.isInvalid())
6785 return true;
6786
6788 NoexceptExpr =
6789 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6790 if (NoexceptExpr.isInvalid())
6791 return true;
6792
6793 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6794 Changed = true;
6795 ESI.NoexceptExpr = NoexceptExpr.get();
6796 ESI.Type = EST;
6797 }
6798
6799 if (ESI.Type != EST_Dynamic)
6800 return false;
6801
6802 // Instantiate a dynamic exception specification's type.
6803 for (QualType T : ESI.Exceptions) {
6804 if (const PackExpansionType *PackExpansion =
6805 T->getAs<PackExpansionType>()) {
6806 Changed = true;
6807
6808 // We have a pack expansion. Instantiate it.
6810 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6811 Unexpanded);
6812 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6813
6814 // Determine whether the set of unexpanded parameter packs can and
6815 // should
6816 // be expanded.
6817 bool Expand = false;
6818 bool RetainExpansion = false;
6819 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
6820 // FIXME: Track the location of the ellipsis (and track source location
6821 // information for the types in the exception specification in general).
6823 Loc, SourceRange(), Unexpanded,
6824 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
6825 NumExpansions))
6826 return true;
6827
6828 if (!Expand) {
6829 // We can't expand this pack expansion into separate arguments yet;
6830 // just substitute into the pattern and create a new pack expansion
6831 // type.
6832 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6833 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6834 if (U.isNull())
6835 return true;
6836
6837 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6838 Exceptions.push_back(U);
6839 continue;
6840 }
6841
6842 // Substitute into the pack expansion pattern for each slice of the
6843 // pack.
6844 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6845 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
6846
6847 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6848 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6849 return true;
6850
6851 Exceptions.push_back(U);
6852 }
6853 } else {
6854 QualType U = getDerived().TransformType(T);
6855 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6856 return true;
6857 if (T != U)
6858 Changed = true;
6859
6860 Exceptions.push_back(U);
6861 }
6862 }
6863
6864 ESI.Exceptions = Exceptions;
6865 if (ESI.Exceptions.empty())
6866 ESI.Type = EST_DynamicNone;
6867 return false;
6868}
6869
6870template<typename Derived>
6872 TypeLocBuilder &TLB,
6874 const FunctionNoProtoType *T = TL.getTypePtr();
6875 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6876 if (ResultType.isNull())
6877 return QualType();
6878
6879 QualType Result = TL.getType();
6880 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
6881 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
6882
6885 NewTL.setLParenLoc(TL.getLParenLoc());
6886 NewTL.setRParenLoc(TL.getRParenLoc());
6888
6889 return Result;
6890}
6891
6892template <typename Derived>
6893QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
6894 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
6895
6896 const UnresolvedUsingType *T = TL.getTypePtr();
6897 bool Changed = false;
6898
6899 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6900 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6901 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6902 if (!QualifierLoc)
6903 return QualType();
6904 Changed |= QualifierLoc != OldQualifierLoc;
6905 }
6906
6907 auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
6908 if (!D)
6909 return QualType();
6910 Changed |= D != T->getDecl();
6911
6912 QualType Result = TL.getType();
6913 if (getDerived().AlwaysRebuild() || Changed) {
6914 Result = getDerived().RebuildUnresolvedUsingType(
6915 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(),
6916 D);
6917 if (Result.isNull())
6918 return QualType();
6919 }
6920
6922 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6923 QualifierLoc, TL.getNameLoc());
6924 else
6925 TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6926 QualifierLoc, TL.getNameLoc());
6927 return Result;
6928}
6929
6930template <typename Derived>
6932 UsingTypeLoc TL) {
6933 const UsingType *T = TL.getTypePtr();
6934 bool Changed = false;
6935
6936 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6937 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6938 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6939 if (!QualifierLoc)
6940 return QualType();
6941 Changed |= QualifierLoc != OldQualifierLoc;
6942 }
6943
6944 auto *D = cast_or_null<UsingShadowDecl>(
6945 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6946 if (!D)
6947 return QualType();
6948 Changed |= D != T->getDecl();
6949
6950 QualType UnderlyingType = getDerived().TransformType(T->desugar());
6951 if (UnderlyingType.isNull())
6952 return QualType();
6953 Changed |= UnderlyingType != T->desugar();
6954
6955 QualType Result = TL.getType();
6956 if (getDerived().AlwaysRebuild() || Changed) {
6957 Result = getDerived().RebuildUsingType(
6958 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D,
6959 UnderlyingType);
6960 if (Result.isNull())
6961 return QualType();
6962 }
6963 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc,
6964 TL.getNameLoc());
6965 return Result;
6966}
6967
6968template<typename Derived>
6970 TypedefTypeLoc TL) {
6971 const TypedefType *T = TL.getTypePtr();
6972 bool Changed = false;
6973
6974 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
6975 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
6976 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
6977 if (!QualifierLoc)
6978 return QualType();
6979 Changed |= QualifierLoc != OldQualifierLoc;
6980 }
6981
6982 auto *Typedef = cast_or_null<TypedefNameDecl>(
6983 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
6984 if (!Typedef)
6985 return QualType();
6986 Changed |= Typedef != T->getDecl();
6987
6988 // FIXME: Transform the UnderlyingType if different from decl.
6989
6990 QualType Result = TL.getType();
6991 if (getDerived().AlwaysRebuild() || Changed) {
6992 Result = getDerived().RebuildTypedefType(
6993 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef);
6994 if (Result.isNull())
6995 return QualType();
6996 }
6997
6998 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
6999 QualifierLoc, TL.getNameLoc());
7000 return Result;
7001}
7002
7003template<typename Derived>
7005 TypeOfExprTypeLoc TL) {
7006 // typeof expressions are not potentially evaluated contexts
7010
7011 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
7012 if (E.isInvalid())
7013 return QualType();
7014
7015 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
7016 if (E.isInvalid())
7017 return QualType();
7018
7019 QualType Result = TL.getType();
7021 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
7022 Result =
7023 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
7024 if (Result.isNull())
7025 return QualType();
7026 }
7027
7028 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
7029 NewTL.setTypeofLoc(TL.getTypeofLoc());
7030 NewTL.setLParenLoc(TL.getLParenLoc());
7031 NewTL.setRParenLoc(TL.getRParenLoc());
7032
7033 return Result;
7034}
7035
7036template<typename Derived>
7038 TypeOfTypeLoc TL) {
7039 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
7040 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
7041 if (!New_Under_TI)
7042 return QualType();
7043
7044 QualType Result = TL.getType();
7045 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
7046 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
7047 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
7048 if (Result.isNull())
7049 return QualType();
7050 }
7051
7052 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
7053 NewTL.setTypeofLoc(TL.getTypeofLoc());
7054 NewTL.setLParenLoc(TL.getLParenLoc());
7055 NewTL.setRParenLoc(TL.getRParenLoc());
7056 NewTL.setUnmodifiedTInfo(New_Under_TI);
7057
7058 return Result;
7059}
7060
7061template<typename Derived>
7063 DecltypeTypeLoc TL) {
7064 const DecltypeType *T = TL.getTypePtr();
7065
7066 // decltype expressions are not potentially evaluated contexts
7070
7071 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
7072 if (E.isInvalid())
7073 return QualType();
7074
7075 E = getSema().ActOnDecltypeExpression(E.get());
7076 if (E.isInvalid())
7077 return QualType();
7078
7079 QualType Result = TL.getType();
7080 if (getDerived().AlwaysRebuild() ||
7081 E.get() != T->getUnderlyingExpr()) {
7082 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
7083 if (Result.isNull())
7084 return QualType();
7085 }
7086 else E.get();
7087
7088 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
7089 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
7090 NewTL.setRParenLoc(TL.getRParenLoc());
7091 return Result;
7092}
7093
7094template <typename Derived>
7098 // Transform the index
7099 ExprResult IndexExpr;
7100 {
7101 EnterExpressionEvaluationContext ConstantContext(
7103
7104 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
7105 if (IndexExpr.isInvalid())
7106 return QualType();
7107 }
7108 QualType Pattern = TL.getPattern();
7109
7110 const PackIndexingType *PIT = TL.getTypePtr();
7111 SmallVector<QualType, 5> SubtitutedTypes;
7112 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
7113
7114 bool NotYetExpanded = Types.empty();
7115 bool FullySubstituted = true;
7116
7117 if (Types.empty() && !PIT->expandsToEmptyPack())
7118 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
7119
7120 for (QualType T : Types) {
7121 if (!T->containsUnexpandedParameterPack()) {
7122 QualType Transformed = getDerived().TransformType(T);
7123 if (Transformed.isNull())
7124 return QualType();
7125 SubtitutedTypes.push_back(Transformed);
7126 continue;
7127 }
7128
7130 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
7131 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7132 // Determine whether the set of unexpanded parameter packs can and should
7133 // be expanded.
7134 bool ShouldExpand = true;
7135 bool RetainExpansion = false;
7136 UnsignedOrNone NumExpansions = std::nullopt;
7137 if (getDerived().TryExpandParameterPacks(
7138 TL.getEllipsisLoc(), SourceRange(), Unexpanded,
7139 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
7140 RetainExpansion, NumExpansions))
7141 return QualType();
7142 if (!ShouldExpand) {
7143 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7144 // FIXME: should we keep TypeLoc for individual expansions in
7145 // PackIndexingTypeLoc?
7146 TypeSourceInfo *TI =
7147 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
7148 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
7149 if (Pack.isNull())
7150 return QualType();
7151 if (NotYetExpanded) {
7152 FullySubstituted = false;
7153 QualType Out = getDerived().RebuildPackIndexingType(
7154 Pack, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7155 FullySubstituted);
7156 if (Out.isNull())
7157 return QualType();
7158
7160 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7161 return Out;
7162 }
7163 SubtitutedTypes.push_back(Pack);
7164 continue;
7165 }
7166 for (unsigned I = 0; I != *NumExpansions; ++I) {
7167 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
7168 QualType Out = getDerived().TransformType(T);
7169 if (Out.isNull())
7170 return QualType();
7171 SubtitutedTypes.push_back(Out);
7172 FullySubstituted &= !Out->containsUnexpandedParameterPack();
7173 }
7174 // If we're supposed to retain a pack expansion, do so by temporarily
7175 // forgetting the partially-substituted parameter pack.
7176 if (RetainExpansion) {
7177 FullySubstituted = false;
7178 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7179 QualType Out = getDerived().TransformType(T);
7180 if (Out.isNull())
7181 return QualType();
7182 SubtitutedTypes.push_back(Out);
7183 }
7184 }
7185
7186 // A pack indexing type can appear in a larger pack expansion,
7187 // e.g. `Pack...[pack_of_indexes]...`
7188 // so we need to temporarily disable substitution of pack elements
7189 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7190 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
7191
7192 QualType Out = getDerived().RebuildPackIndexingType(
7193 Result, IndexExpr.get(), SourceLocation(), TL.getEllipsisLoc(),
7194 FullySubstituted, SubtitutedTypes);
7195 if (Out.isNull())
7196 return Out;
7197
7199 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7200 return Out;
7201}
7202
7203template<typename Derived>
7205 TypeLocBuilder &TLB,
7207 QualType Result = TL.getType();
7208 TypeSourceInfo *NewBaseTSI = TL.getUnderlyingTInfo();
7209 if (Result->isDependentType()) {
7210 const UnaryTransformType *T = TL.getTypePtr();
7211
7212 NewBaseTSI = getDerived().TransformType(TL.getUnderlyingTInfo());
7213 if (!NewBaseTSI)
7214 return QualType();
7215 QualType NewBase = NewBaseTSI->getType();
7216
7217 Result = getDerived().RebuildUnaryTransformType(NewBase,
7218 T->getUTTKind(),
7219 TL.getKWLoc());
7220 if (Result.isNull())
7221 return QualType();
7222 }
7223
7225 NewTL.setKWLoc(TL.getKWLoc());
7226 NewTL.setParensRange(TL.getParensRange());
7227 NewTL.setUnderlyingTInfo(NewBaseTSI);
7228 return Result;
7229}
7230
7231template<typename Derived>
7234 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
7235
7236 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7237 TemplateName TemplateName = getDerived().TransformTemplateName(
7238 QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(),
7239 TL.getTemplateNameLoc());
7240 if (TemplateName.isNull())
7241 return QualType();
7242
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 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
7252 NewDeduced.isNull() ? DeducedKind::Undeduced : DeducedKind::Deduced,
7253 NewDeduced, T->getKeyword(), TemplateName);
7254 if (Result.isNull())
7255 return QualType();
7256
7257 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7258 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7259 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7260 NewTL.setQualifierLoc(QualifierLoc);
7261 return Result;
7262}
7263
7264template <typename Derived>
7266 TagTypeLoc TL) {
7267 const TagType *T = TL.getTypePtr();
7268
7269 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7270 if (QualifierLoc) {
7271 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7272 if (!QualifierLoc)
7273 return QualType();
7274 }
7275
7276 auto *TD = cast_or_null<TagDecl>(
7277 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
7278 if (!TD)
7279 return QualType();
7280
7281 QualType Result = TL.getType();
7282 if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() ||
7283 TD != T->getDecl()) {
7284 if (T->isCanonicalUnqualified())
7285 Result = getDerived().RebuildCanonicalTagType(TD);
7286 else
7287 Result = getDerived().RebuildTagType(
7288 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD);
7289 if (Result.isNull())
7290 return QualType();
7291 }
7292
7293 TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result);
7295 NewTL.setQualifierLoc(QualifierLoc);
7296 NewTL.setNameLoc(TL.getNameLoc());
7297
7298 return Result;
7299}
7300
7301template <typename Derived>
7303 EnumTypeLoc TL) {
7304 return getDerived().TransformTagType(TLB, TL);
7305}
7306
7307template <typename Derived>
7308QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
7309 RecordTypeLoc TL) {
7310 return getDerived().TransformTagType(TLB, TL);
7311}
7312
7313template<typename Derived>
7315 TypeLocBuilder &TLB,
7317 return getDerived().TransformTagType(TLB, TL);
7318}
7319
7320template<typename Derived>
7322 TypeLocBuilder &TLB,
7324 return getDerived().TransformTemplateTypeParmType(
7325 TLB, TL,
7326 /*SuppressObjCLifetime=*/false);
7327}
7328
7329template <typename Derived>
7331 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7332 return TransformTypeSpecType(TLB, TL);
7333}
7334
7335template<typename Derived>
7336QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7337 TypeLocBuilder &TLB,
7338 SubstTemplateTypeParmTypeLoc TL) {
7339 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7340
7341 Decl *NewReplaced =
7342 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7343
7344 // Substitute into the replacement type, which itself might involve something
7345 // that needs to be transformed. This only tends to occur with default
7346 // template arguments of template template parameters.
7347 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7348 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7349 if (Replacement.isNull())
7350 return QualType();
7351
7352 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7353 Replacement, NewReplaced, T->getIndex(), T->getPackIndex(),
7354 T->getFinal());
7355
7356 // Propagate type-source information.
7357 SubstTemplateTypeParmTypeLoc NewTL
7358 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7359 NewTL.setNameLoc(TL.getNameLoc());
7360 return Result;
7361
7362}
7363template <typename Derived>
7366 return TransformTypeSpecType(TLB, TL);
7367}
7368
7369template<typename Derived>
7371 TypeLocBuilder &TLB,
7373 return getDerived().TransformSubstTemplateTypeParmPackType(
7374 TLB, TL, /*SuppressObjCLifetime=*/false);
7375}
7376
7377template <typename Derived>
7380 return TransformTypeSpecType(TLB, TL);
7381}
7382
7383template<typename Derived>
7384QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
7385 AtomicTypeLoc TL) {
7386 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7387 if (ValueType.isNull())
7388 return QualType();
7389
7390 QualType Result = TL.getType();
7391 if (getDerived().AlwaysRebuild() ||
7392 ValueType != TL.getValueLoc().getType()) {
7393 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7394 if (Result.isNull())
7395 return QualType();
7396 }
7397
7398 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7399 NewTL.setKWLoc(TL.getKWLoc());
7400 NewTL.setLParenLoc(TL.getLParenLoc());
7401 NewTL.setRParenLoc(TL.getRParenLoc());
7402
7403 return Result;
7404}
7405
7406template <typename Derived>
7408 PipeTypeLoc TL) {
7409 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7410 if (ValueType.isNull())
7411 return QualType();
7412
7413 QualType Result = TL.getType();
7414 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7415 const PipeType *PT = Result->castAs<PipeType>();
7416 bool isReadPipe = PT->isReadOnly();
7417 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7418 if (Result.isNull())
7419 return QualType();
7420 }
7421
7422 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7423 NewTL.setKWLoc(TL.getKWLoc());
7424
7425 return Result;
7426}
7427
7428template <typename Derived>
7430 BitIntTypeLoc TL) {
7431 const BitIntType *EIT = TL.getTypePtr();
7432 QualType Result = TL.getType();
7433
7434 if (getDerived().AlwaysRebuild()) {
7435 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7436 EIT->getNumBits(), TL.getNameLoc());
7437 if (Result.isNull())
7438 return QualType();
7439 }
7440
7441 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7442 NewTL.setNameLoc(TL.getNameLoc());
7443 return Result;
7444}
7445
7446template <typename Derived>
7449 const DependentBitIntType *EIT = TL.getTypePtr();
7450
7453 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7454 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7455
7456 if (BitsExpr.isInvalid())
7457 return QualType();
7458
7459 QualType Result = TL.getType();
7460
7461 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7462 Result = getDerived().RebuildDependentBitIntType(
7463 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7464
7465 if (Result.isNull())
7466 return QualType();
7467 }
7468
7471 NewTL.setNameLoc(TL.getNameLoc());
7472 } else {
7473 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7474 NewTL.setNameLoc(TL.getNameLoc());
7475 }
7476 return Result;
7477}
7478
7479template <typename Derived>
7482 llvm_unreachable("This type does not need to be transformed.");
7483}
7484
7485 /// Simple iterator that traverses the template arguments in a
7486 /// container that provides a \c getArgLoc() member function.
7487 ///
7488 /// This iterator is intended to be used with the iterator form of
7489 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7490 template<typename ArgLocContainer>
7492 ArgLocContainer *Container;
7493 unsigned Index;
7494
7495 public:
7498 typedef int difference_type;
7499 typedef std::input_iterator_tag iterator_category;
7500
7501 class pointer {
7503
7504 public:
7505 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7506
7508 return &Arg;
7509 }
7510 };
7511
7512
7514
7515 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7516 unsigned Index)
7517 : Container(&Container), Index(Index) { }
7518
7520 ++Index;
7521 return *this;
7522 }
7523
7526 ++(*this);
7527 return Old;
7528 }
7529
7531 return Container->getArgLoc(Index);
7532 }
7533
7535 return pointer(Container->getArgLoc(Index));
7536 }
7537
7540 return X.Container == Y.Container && X.Index == Y.Index;
7541 }
7542
7545 return !(X == Y);
7546 }
7547 };
7548
7549template<typename Derived>
7550QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7551 AutoTypeLoc TL) {
7552 const AutoType *T = TL.getTypePtr();
7553 QualType OldDeduced = T->getDeducedType();
7554 QualType NewDeduced;
7555 if (!OldDeduced.isNull()) {
7556 NewDeduced = getDerived().TransformType(OldDeduced);
7557 if (NewDeduced.isNull())
7558 return QualType();
7559 }
7560
7561 ConceptDecl *NewCD = nullptr;
7562 TemplateArgumentListInfo NewTemplateArgs;
7563 NestedNameSpecifierLoc NewNestedNameSpec;
7564 if (T->isConstrained()) {
7565 assert(TL.getConceptReference());
7566 NewCD = cast_or_null<ConceptDecl>(getDerived().TransformDecl(
7567 TL.getConceptNameLoc(), T->getTypeConstraintConcept()));
7568
7569 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7570 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7572 if (getDerived().TransformTemplateArguments(
7573 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7574 NewTemplateArgs))
7575 return QualType();
7576
7577 if (TL.getNestedNameSpecifierLoc()) {
7578 NewNestedNameSpec
7579 = getDerived().TransformNestedNameSpecifierLoc(
7580 TL.getNestedNameSpecifierLoc());
7581 if (!NewNestedNameSpec)
7582 return QualType();
7583 }
7584 }
7585
7586 QualType Result = TL.getType();
7587 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7588 T->isDependentType() || T->isConstrained()) {
7589 // FIXME: Maybe don't rebuild if all template arguments are the same.
7591 NewArgList.reserve(NewTemplateArgs.size());
7592 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7593 NewArgList.push_back(ArgLoc.getArgument());
7594 Result = getDerived().RebuildAutoType(
7595 NewDeduced.isNull() ? DeducedKind::Undeduced : DeducedKind::Deduced,
7596 NewDeduced, T->getKeyword(), NewCD, NewArgList);
7597 if (Result.isNull())
7598 return QualType();
7599 }
7600
7601 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7602 NewTL.setNameLoc(TL.getNameLoc());
7603 NewTL.setRParenLoc(TL.getRParenLoc());
7604 NewTL.setConceptReference(nullptr);
7605
7606 if (T->isConstrained()) {
7608 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName(),
7609 TL.getConceptNameLoc(),
7610 TL.getTypePtr()->getTypeConstraintConcept()->getDeclName());
7611 auto *CR = ConceptReference::Create(
7612 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7613 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7614 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7615 NewTL.setConceptReference(CR);
7616 }
7617
7618 return Result;
7619}
7620
7621template <typename Derived>
7624 return getDerived().TransformTemplateSpecializationType(
7625 TLB, TL, /*ObjectType=*/QualType(), /*FirstQualifierInScope=*/nullptr,
7626 /*AllowInjectedClassName=*/false);
7627}
7628
7629template <typename Derived>
7632 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
7633 const TemplateSpecializationType *T = TL.getTypePtr();
7634
7635 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7636 TemplateName Template = getDerived().TransformTemplateName(
7637 QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(),
7638 TL.getTemplateNameLoc(), ObjectType, FirstQualifierInScope,
7639 AllowInjectedClassName);
7640 if (Template.isNull())
7641 return QualType();
7642
7643 TemplateArgumentListInfo NewTemplateArgs;
7644 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7645 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7647 ArgIterator;
7648 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7649 ArgIterator(TL, TL.getNumArgs()),
7650 NewTemplateArgs))
7651 return QualType();
7652
7653 // This needs to be rebuilt if either the arguments changed, or if the
7654 // original template changed. If the template changed, and even if the
7655 // arguments didn't change, these arguments might not correspond to their
7656 // respective parameters, therefore needing conversions.
7657 QualType Result = getDerived().RebuildTemplateSpecializationType(
7658 TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(),
7659 NewTemplateArgs);
7660
7661 if (!Result.isNull()) {
7663 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7664 TL.getTemplateNameLoc(), NewTemplateArgs);
7665 }
7666
7667 return Result;
7668}
7669
7670template <typename Derived>
7672 AttributedTypeLoc TL) {
7673 const AttributedType *oldType = TL.getTypePtr();
7674 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7675 if (modifiedType.isNull())
7676 return QualType();
7677
7678 // HLSL: re-validate matrix-layout markers after substitution. If the
7679 // post-substitution type is no longer a matrix, diagnose now.
7680 if (SemaRef.getLangOpts().HLSL &&
7682 oldType->getAttrKind(), modifiedType,
7683 TL.getAttr() ? TL.getAttr()->getLocation()
7684 : TL.getModifiedLoc().getBeginLoc()))
7685 return QualType();
7686
7687 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7688 const Attr *oldAttr = TL.getAttr();
7689 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7690 if (oldAttr && !newAttr)
7691 return QualType();
7692
7693 QualType result = TL.getType();
7694
7695 // FIXME: dependent operand expressions?
7696 if (getDerived().AlwaysRebuild() ||
7697 modifiedType != oldType->getModifiedType()) {
7698 // If the equivalent type is equal to the modified type, we don't want to
7699 // transform it as well because:
7700 //
7701 // 1. The transformation would yield the same result and is therefore
7702 // superfluous, and
7703 //
7704 // 2. Transforming the same type twice can cause problems, e.g. if it
7705 // is a FunctionProtoType, we may end up instantiating the function
7706 // parameters twice, which causes an assertion since the parameters
7707 // are already bound to their counterparts in the template for this
7708 // instantiation.
7709 //
7710 QualType equivalentType = modifiedType;
7711 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7712 TypeLocBuilder AuxiliaryTLB;
7713 AuxiliaryTLB.reserve(TL.getFullDataSize());
7714 equivalentType =
7715 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7716 if (equivalentType.isNull())
7717 return QualType();
7718 }
7719
7720 // Check whether we can add nullability; it is only represented as
7721 // type sugar, and therefore cannot be diagnosed in any other way.
7722 if (auto nullability = oldType->getImmediateNullability()) {
7723 if (!modifiedType->canHaveNullability()) {
7724 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7725 : TL.getModifiedLoc().getBeginLoc()),
7726 diag::err_nullability_nonpointer)
7727 << DiagNullabilityKind(*nullability, false) << modifiedType;
7728 return QualType();
7729 }
7730 }
7731
7732 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7733 modifiedType,
7734 equivalentType,
7735 TL.getAttr());
7736 }
7737
7738 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7739 newTL.setAttr(newAttr);
7740 return result;
7741}
7742
7743template <typename Derived>
7746 const CountAttributedType *OldTy = TL.getTypePtr();
7747 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7748 if (InnerTy.isNull())
7749 return QualType();
7750
7751 Expr *OldCount = TL.getCountExpr();
7752 Expr *NewCount = nullptr;
7753 if (OldCount) {
7754 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7755 if (CountResult.isInvalid())
7756 return QualType();
7757 NewCount = CountResult.get();
7758 }
7759
7760 QualType Result = TL.getType();
7761 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7762 OldCount != NewCount) {
7763 // Currently, CountAttributedType can only wrap incomplete array types.
7765 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7766 }
7767
7768 TLB.push<CountAttributedTypeLoc>(Result);
7769 return Result;
7770}
7771
7772template <typename Derived>
7775 // The BTFTagAttributedType is available for C only.
7776 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7777}
7778
7779template <typename Derived>
7782 const OverflowBehaviorType *OldTy = TL.getTypePtr();
7783 QualType InnerTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7784 if (InnerTy.isNull())
7785 return QualType();
7786
7787 QualType Result = TL.getType();
7788 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->getUnderlyingType()) {
7789 Result = SemaRef.Context.getOverflowBehaviorType(OldTy->getBehaviorKind(),
7790 InnerTy);
7791 if (Result.isNull())
7792 return QualType();
7793 }
7794
7796 NewTL.initializeLocal(SemaRef.Context, TL.getAttrLoc());
7797 return Result;
7798}
7799
7800template <typename Derived>
7803
7804 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7805
7806 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7807 if (WrappedTy.isNull())
7808 return QualType();
7809
7810 QualType ContainedTy = QualType();
7811 QualType OldContainedTy = oldType->getContainedType();
7812 TypeSourceInfo *ContainedTSI = nullptr;
7813 if (!OldContainedTy.isNull()) {
7814 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7815 if (!oldContainedTSI)
7816 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7817 OldContainedTy, SourceLocation());
7818 ContainedTSI = getDerived().TransformType(oldContainedTSI);
7819 if (!ContainedTSI)
7820 return QualType();
7821 ContainedTy = ContainedTSI->getType();
7822 }
7823
7824 QualType Result = TL.getType();
7825 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
7826 ContainedTy != oldType->getContainedType()) {
7828 WrappedTy, ContainedTy, oldType->getAttrs());
7829 }
7830
7833 NewTL.setSourceRange(TL.getLocalSourceRange());
7834 NewTL.setContainedTypeSourceInfo(ContainedTSI);
7835 return Result;
7836}
7837
7838template <typename Derived>
7841 // No transformations needed.
7842 return TL.getType();
7843}
7844
7845template<typename Derived>
7848 ParenTypeLoc TL) {
7849 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7850 if (Inner.isNull())
7851 return QualType();
7852
7853 QualType Result = TL.getType();
7854 if (getDerived().AlwaysRebuild() ||
7855 Inner != TL.getInnerLoc().getType()) {
7856 Result = getDerived().RebuildParenType(Inner);
7857 if (Result.isNull())
7858 return QualType();
7859 }
7860
7861 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
7862 NewTL.setLParenLoc(TL.getLParenLoc());
7863 NewTL.setRParenLoc(TL.getRParenLoc());
7864 return Result;
7865}
7866
7867template <typename Derived>
7871 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
7872 if (Inner.isNull())
7873 return QualType();
7874
7875 QualType Result = TL.getType();
7876 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
7877 Result =
7878 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
7879 if (Result.isNull())
7880 return QualType();
7881 }
7882
7884 NewTL.setExpansionLoc(TL.getExpansionLoc());
7885 return Result;
7886}
7887
7888template<typename Derived>
7889QualType TreeTransform<Derived>::TransformDependentNameType(
7891 return TransformDependentNameType(TLB, TL, false);
7892}
7893
7894template <typename Derived>
7895QualType TreeTransform<Derived>::TransformDependentNameType(
7896 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext,
7897 QualType ObjectType, NamedDecl *UnqualLookup) {
7898 const DependentNameType *T = TL.getTypePtr();
7899
7900 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7901 if (QualifierLoc) {
7902 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
7903 QualifierLoc, ObjectType, UnqualLookup);
7904 if (!QualifierLoc)
7905 return QualType();
7906 } else {
7907 assert((ObjectType.isNull() && !UnqualLookup) &&
7908 "must be transformed by TransformNestedNameSpecifierLoc");
7909 }
7910
7912 = getDerived().RebuildDependentNameType(T->getKeyword(),
7913 TL.getElaboratedKeywordLoc(),
7914 QualifierLoc,
7915 T->getIdentifier(),
7916 TL.getNameLoc(),
7917 DeducedTSTContext);
7918 if (Result.isNull())
7919 return QualType();
7920
7921 if (isa<TagType>(Result)) {
7922 auto NewTL = TLB.push<TagTypeLoc>(Result);
7923 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7924 NewTL.setQualifierLoc(QualifierLoc);
7925 NewTL.setNameLoc(TL.getNameLoc());
7927 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7928 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7929 NewTL.setTemplateNameLoc(TL.getNameLoc());
7930 NewTL.setQualifierLoc(QualifierLoc);
7931 } else if (isa<TypedefType>(Result)) {
7932 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7933 QualifierLoc, TL.getNameLoc());
7934 } else if (isa<UnresolvedUsingType>(Result)) {
7935 auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result);
7936 NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc());
7937 } else {
7938 auto NewTL = TLB.push<DependentNameTypeLoc>(Result);
7939 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7940 NewTL.setQualifierLoc(QualifierLoc);
7941 NewTL.setNameLoc(TL.getNameLoc());
7942 }
7943 return Result;
7944}
7945
7946template<typename Derived>
7949 QualType Pattern
7950 = getDerived().TransformType(TLB, TL.getPatternLoc());
7951 if (Pattern.isNull())
7952 return QualType();
7953
7954 QualType Result = TL.getType();
7955 if (getDerived().AlwaysRebuild() ||
7956 Pattern != TL.getPatternLoc().getType()) {
7957 Result = getDerived().RebuildPackExpansionType(Pattern,
7958 TL.getPatternLoc().getSourceRange(),
7959 TL.getEllipsisLoc(),
7960 TL.getTypePtr()->getNumExpansions());
7961 if (Result.isNull())
7962 return QualType();
7963 }
7964
7966 NewT.setEllipsisLoc(TL.getEllipsisLoc());
7967 return Result;
7968}
7969
7970template<typename Derived>
7974 // ObjCInterfaceType is never dependent.
7975 TLB.pushFullCopy(TL);
7976 return TL.getType();
7977}
7978
7979template<typename Derived>
7983 const ObjCTypeParamType *T = TL.getTypePtr();
7984 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
7985 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
7986 if (!OTP)
7987 return QualType();
7988
7989 QualType Result = TL.getType();
7990 if (getDerived().AlwaysRebuild() ||
7991 OTP != T->getDecl()) {
7992 Result = getDerived().RebuildObjCTypeParamType(
7993 OTP, TL.getProtocolLAngleLoc(),
7994 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
7995 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
7996 if (Result.isNull())
7997 return QualType();
7998 }
7999
8001 if (TL.getNumProtocols()) {
8002 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8003 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8004 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
8005 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8006 }
8007 return Result;
8008}
8009
8010template<typename Derived>
8013 ObjCObjectTypeLoc TL) {
8014 // Transform base type.
8015 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
8016 if (BaseType.isNull())
8017 return QualType();
8018
8019 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
8020
8021 // Transform type arguments.
8022 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
8023 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
8024 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
8025 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
8026 QualType TypeArg = TypeArgInfo->getType();
8027 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
8028 AnyChanged = true;
8029
8030 // We have a pack expansion. Instantiate it.
8031 const auto *PackExpansion = PackExpansionLoc.getType()
8032 ->castAs<PackExpansionType>();
8034 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
8035 Unexpanded);
8036 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8037
8038 // Determine whether the set of unexpanded parameter packs can
8039 // and should be expanded.
8040 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
8041 bool Expand = false;
8042 bool RetainExpansion = false;
8043 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
8044 if (getDerived().TryExpandParameterPacks(
8045 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
8046 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
8047 RetainExpansion, NumExpansions))
8048 return QualType();
8049
8050 if (!Expand) {
8051 // We can't expand this pack expansion into separate arguments yet;
8052 // just substitute into the pattern and create a new pack expansion
8053 // type.
8054 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
8055
8056 TypeLocBuilder TypeArgBuilder;
8057 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
8058 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
8059 PatternLoc);
8060 if (NewPatternType.isNull())
8061 return QualType();
8062
8063 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
8064 NewPatternType, NumExpansions);
8065 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
8066 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
8067 NewTypeArgInfos.push_back(
8068 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
8069 continue;
8070 }
8071
8072 // Substitute into the pack expansion pattern for each slice of the
8073 // pack.
8074 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
8075 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
8076
8077 TypeLocBuilder TypeArgBuilder;
8078 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
8079
8080 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
8081 PatternLoc);
8082 if (NewTypeArg.isNull())
8083 return QualType();
8084
8085 NewTypeArgInfos.push_back(
8086 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8087 }
8088
8089 continue;
8090 }
8091
8092 TypeLocBuilder TypeArgBuilder;
8093 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
8094 QualType NewTypeArg =
8095 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
8096 if (NewTypeArg.isNull())
8097 return QualType();
8098
8099 // If nothing changed, just keep the old TypeSourceInfo.
8100 if (NewTypeArg == TypeArg) {
8101 NewTypeArgInfos.push_back(TypeArgInfo);
8102 continue;
8103 }
8104
8105 NewTypeArgInfos.push_back(
8106 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8107 AnyChanged = true;
8108 }
8109
8110 QualType Result = TL.getType();
8111 if (getDerived().AlwaysRebuild() || AnyChanged) {
8112 // Rebuild the type.
8113 Result = getDerived().RebuildObjCObjectType(
8114 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
8115 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
8116 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
8117 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
8118
8119 if (Result.isNull())
8120 return QualType();
8121 }
8122
8123 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
8124 NewT.setHasBaseTypeAsWritten(true);
8125 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
8126 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
8127 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
8128 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
8129 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8130 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8131 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
8132 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8133 return Result;
8134}
8135
8136template<typename Derived>
8140 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
8141 if (PointeeType.isNull())
8142 return QualType();
8143
8144 QualType Result = TL.getType();
8145 if (getDerived().AlwaysRebuild() ||
8146 PointeeType != TL.getPointeeLoc().getType()) {
8147 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
8148 TL.getStarLoc());
8149 if (Result.isNull())
8150 return QualType();
8151 }
8152
8154 NewT.setStarLoc(TL.getStarLoc());
8155 return Result;
8156}
8157
8158//===----------------------------------------------------------------------===//
8159// Statement transformation
8160//===----------------------------------------------------------------------===//
8161template<typename Derived>
8164 return S;
8165}
8166
8167template<typename Derived>
8170 return getDerived().TransformCompoundStmt(S, false);
8171}
8172
8173template<typename Derived>
8176 bool IsStmtExpr) {
8177 Sema::CompoundScopeRAII CompoundScope(getSema());
8178 Sema::FPFeaturesStateRAII FPSave(getSema());
8179 if (S->hasStoredFPFeatures())
8180 getSema().resetFPOptions(
8181 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8182
8183 bool SubStmtInvalid = false;
8184 bool SubStmtChanged = false;
8185 SmallVector<Stmt*, 8> Statements;
8186 for (auto *B : S->body()) {
8187 StmtResult Result = getDerived().TransformStmt(
8188 B, IsStmtExpr && B == S->body_back() ? StmtDiscardKind::StmtExprResult
8189 : StmtDiscardKind::Discarded);
8190
8191 if (Result.isInvalid()) {
8192 // Immediately fail if this was a DeclStmt, since it's very
8193 // likely that this will cause problems for future statements.
8194 if (isa<DeclStmt>(B))
8195 return StmtError();
8196
8197 // Otherwise, just keep processing substatements and fail later.
8198 SubStmtInvalid = true;
8199 continue;
8200 }
8201
8202 SubStmtChanged = SubStmtChanged || Result.get() != B;
8203 Statements.push_back(Result.getAs<Stmt>());
8204 }
8205
8206 if (SubStmtInvalid)
8207 return StmtError();
8208
8209 if (!getDerived().AlwaysRebuild() &&
8210 !SubStmtChanged)
8211 return S;
8212
8213 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8214 Statements,
8215 S->getRBracLoc(),
8216 IsStmtExpr);
8217}
8218
8219template<typename Derived>
8222 ExprResult LHS, RHS;
8223 {
8226
8227 // Transform the left-hand case value.
8228 LHS = getDerived().TransformExpr(S->getLHS());
8229 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8230 if (LHS.isInvalid())
8231 return StmtError();
8232
8233 // Transform the right-hand case value (for the GNU case-range extension).
8234 RHS = getDerived().TransformExpr(S->getRHS());
8235 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8236 if (RHS.isInvalid())
8237 return StmtError();
8238 }
8239
8240 // Build the case statement.
8241 // Case statements are always rebuilt so that they will attached to their
8242 // transformed switch statement.
8243 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8244 LHS.get(),
8245 S->getEllipsisLoc(),
8246 RHS.get(),
8247 S->getColonLoc());
8248 if (Case.isInvalid())
8249 return StmtError();
8250
8251 // Transform the statement following the case
8252 StmtResult SubStmt =
8253 getDerived().TransformStmt(S->getSubStmt());
8254 if (SubStmt.isInvalid())
8255 return StmtError();
8256
8257 // Attach the body to the case statement
8258 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8259}
8260
8261template <typename Derived>
8263 // Transform the statement following the default case
8264 StmtResult SubStmt =
8265 getDerived().TransformStmt(S->getSubStmt());
8266 if (SubStmt.isInvalid())
8267 return StmtError();
8268
8269 // Default statements are always rebuilt
8270 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8271 SubStmt.get());
8272}
8273
8274template<typename Derived>
8277 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8278 if (SubStmt.isInvalid())
8279 return StmtError();
8280
8281 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8282 S->getDecl());
8283 if (!LD)
8284 return StmtError();
8285
8286 // If we're transforming "in-place" (we're not creating new local
8287 // declarations), assume we're replacing the old label statement
8288 // and clear out the reference to it.
8289 if (LD == S->getDecl())
8290 S->getDecl()->setStmt(nullptr);
8291
8292 // FIXME: Pass the real colon location in.
8293 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8295 SubStmt.get());
8296}
8297
8298template <typename Derived>
8300 if (!R)
8301 return R;
8302
8303 switch (R->getKind()) {
8304// Transform attributes by calling TransformXXXAttr.
8305#define ATTR(X) \
8306 case attr::X: \
8307 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8308#include "clang/Basic/AttrList.inc"
8309 }
8310 return R;
8311}
8312
8313template <typename Derived>
8315 const Stmt *InstS,
8316 const Attr *R) {
8317 if (!R)
8318 return R;
8319
8320 switch (R->getKind()) {
8321// Transform attributes by calling TransformStmtXXXAttr.
8322#define ATTR(X) \
8323 case attr::X: \
8324 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8325#include "clang/Basic/AttrList.inc"
8326 }
8327 return TransformAttr(R);
8328}
8329
8330template <typename Derived>
8333 StmtDiscardKind SDK) {
8334 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8335 if (SubStmt.isInvalid())
8336 return StmtError();
8337
8338 bool AttrsChanged = false;
8340
8341 // Visit attributes and keep track if any are transformed.
8342 for (const auto *I : S->getAttrs()) {
8343 const Attr *R =
8344 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8345 AttrsChanged |= (I != R);
8346 if (R)
8347 Attrs.push_back(R);
8348 }
8349
8350 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8351 return S;
8352
8353 // If transforming the attributes failed for all of the attributes in the
8354 // statement, don't make an AttributedStmt without attributes.
8355 if (Attrs.empty())
8356 return SubStmt;
8357
8358 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8359 SubStmt.get());
8360}
8361
8362template<typename Derived>
8365 // Transform the initialization statement
8366 StmtResult Init = getDerived().TransformStmt(S->getInit());
8367 if (Init.isInvalid())
8368 return StmtError();
8369
8371 if (!S->isConsteval()) {
8372 // Transform the condition
8373 Cond = getDerived().TransformCondition(
8374 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8375 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8377 if (Cond.isInvalid())
8378 return StmtError();
8379 }
8380
8381 // If this is a constexpr if, determine which arm we should instantiate.
8382 std::optional<bool> ConstexprConditionValue;
8383 if (S->isConstexpr())
8384 ConstexprConditionValue = Cond.getKnownValue();
8385
8386 // Transform the "then" branch.
8387 StmtResult Then;
8388 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8392 S->isNonNegatedConsteval());
8393
8394 Then = getDerived().TransformStmt(S->getThen());
8395 if (Then.isInvalid())
8396 return StmtError();
8397 } else {
8398 // Discarded branch is replaced with empty CompoundStmt so we can keep
8399 // proper source location for start and end of original branch, so
8400 // subsequent transformations like CoverageMapping work properly
8401 Then = new (getSema().Context)
8402 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8403 }
8404
8405 // Transform the "else" branch.
8406 StmtResult Else;
8407 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8411 S->isNegatedConsteval());
8412
8413 Else = getDerived().TransformStmt(S->getElse());
8414 if (Else.isInvalid())
8415 return StmtError();
8416 } else if (S->getElse() && ConstexprConditionValue &&
8417 *ConstexprConditionValue) {
8418 // Same thing here as with <then> branch, we are discarding it, we can't
8419 // replace it with NULL nor NullStmt as we need to keep for source location
8420 // range, for CoverageMapping
8421 Else = new (getSema().Context)
8422 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8423 }
8424
8425 if (!getDerived().AlwaysRebuild() &&
8426 Init.get() == S->getInit() &&
8427 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8428 Then.get() == S->getThen() &&
8429 Else.get() == S->getElse())
8430 return S;
8431
8432 return getDerived().RebuildIfStmt(
8433 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8434 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8435}
8436
8437template<typename Derived>
8440 // Transform the initialization statement
8441 StmtResult Init = getDerived().TransformStmt(S->getInit());
8442 if (Init.isInvalid())
8443 return StmtError();
8444
8445 // Transform the condition.
8446 Sema::ConditionResult Cond = getDerived().TransformCondition(
8447 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8449 if (Cond.isInvalid())
8450 return StmtError();
8451
8452 // Rebuild the switch statement.
8454 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8455 Init.get(), Cond, S->getRParenLoc());
8456 if (Switch.isInvalid())
8457 return StmtError();
8458
8459 // Transform the body of the switch statement.
8460 StmtResult Body = getDerived().TransformStmt(S->getBody());
8461 if (Body.isInvalid())
8462 return StmtError();
8463
8464 // Complete the switch statement.
8465 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8466 Body.get());
8467}
8468
8469template<typename Derived>
8472 // Transform the condition
8473 Sema::ConditionResult Cond = getDerived().TransformCondition(
8474 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8476 if (Cond.isInvalid())
8477 return StmtError();
8478
8479 // OpenACC Restricts a while-loop inside of certain construct/clause
8480 // combinations, so diagnose that here in OpenACC mode.
8482 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8483
8484 // Transform the body
8485 StmtResult Body = getDerived().TransformStmt(S->getBody());
8486 if (Body.isInvalid())
8487 return StmtError();
8488
8489 if (!getDerived().AlwaysRebuild() &&
8490 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8491 Body.get() == S->getBody())
8492 return Owned(S);
8493
8494 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8495 Cond, S->getRParenLoc(), Body.get());
8496}
8497
8498template<typename Derived>
8501 // OpenACC Restricts a do-loop inside of certain construct/clause
8502 // combinations, so diagnose that here in OpenACC mode.
8504 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8505
8506 // Transform the body
8507 StmtResult Body = getDerived().TransformStmt(S->getBody());
8508 if (Body.isInvalid())
8509 return StmtError();
8510
8511 // Transform the condition
8512 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8513 if (Cond.isInvalid())
8514 return StmtError();
8515
8516 if (!getDerived().AlwaysRebuild() &&
8517 Cond.get() == S->getCond() &&
8518 Body.get() == S->getBody())
8519 return S;
8520
8521 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8522 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8523 S->getRParenLoc());
8524}
8525
8526template<typename Derived>
8529 if (getSema().getLangOpts().OpenMP)
8530 getSema().OpenMP().startOpenMPLoop();
8531
8532 // Transform the initialization statement
8533 StmtResult Init = getDerived().TransformStmt(S->getInit());
8534 if (Init.isInvalid())
8535 return StmtError();
8536
8537 // In OpenMP loop region loop control variable must be captured and be
8538 // private. Perform analysis of first part (if any).
8539 if (getSema().getLangOpts().OpenMP && Init.isUsable())
8540 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8541 Init.get());
8542
8543 // Transform the condition
8544 Sema::ConditionResult Cond = getDerived().TransformCondition(
8545 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8547 if (Cond.isInvalid())
8548 return StmtError();
8549
8550 // Transform the increment
8551 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8552 if (Inc.isInvalid())
8553 return StmtError();
8554
8555 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8556 if (S->getInc() && !FullInc.get())
8557 return StmtError();
8558
8559 // OpenACC Restricts a for-loop inside of certain construct/clause
8560 // combinations, so diagnose that here in OpenACC mode.
8562 SemaRef.OpenACC().ActOnForStmtBegin(
8563 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8564 Cond.get().second, S->getInc(), Inc.get());
8565
8566 // Transform the body
8567 StmtResult Body = getDerived().TransformStmt(S->getBody());
8568 if (Body.isInvalid())
8569 return StmtError();
8570
8571 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8572
8573 if (!getDerived().AlwaysRebuild() &&
8574 Init.get() == S->getInit() &&
8575 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8576 Inc.get() == S->getInc() &&
8577 Body.get() == S->getBody())
8578 return S;
8579
8580 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8581 Init.get(), Cond, FullInc,
8582 S->getRParenLoc(), Body.get());
8583}
8584
8585template<typename Derived>
8588 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8589 S->getLabel());
8590 if (!LD)
8591 return StmtError();
8592
8593 // Goto statements must always be rebuilt, to resolve the label.
8594 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8595 cast<LabelDecl>(LD));
8596}
8597
8598template<typename Derived>
8601 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8602 if (Target.isInvalid())
8603 return StmtError();
8604 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8605
8606 if (!getDerived().AlwaysRebuild() &&
8607 Target.get() == S->getTarget())
8608 return S;
8609
8610 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8611 Target.get());
8612}
8613
8614template<typename Derived>
8617 if (!S->hasLabelTarget())
8618 return S;
8619
8620 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8621 S->getLabelDecl());
8622 if (!LD)
8623 return StmtError();
8624
8625 return new (SemaRef.Context)
8626 ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8627}
8628
8629template<typename Derived>
8632 if (!S->hasLabelTarget())
8633 return S;
8634
8635 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8636 S->getLabelDecl());
8637 if (!LD)
8638 return StmtError();
8639
8640 return new (SemaRef.Context)
8641 BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8642}
8643
8644template <typename Derived>
8646 StmtResult Result = getDerived().TransformStmt(S->getBody());
8647 if (!Result.isUsable())
8648 return StmtError();
8649 return DeferStmt::Create(getSema().Context, S->getDeferLoc(), Result.get());
8650}
8651
8652template<typename Derived>
8655 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8656 /*NotCopyInit*/false);
8657 if (Result.isInvalid())
8658 return StmtError();
8659
8660 // FIXME: We always rebuild the return statement because there is no way
8661 // to tell whether the return type of the function has changed.
8662 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8663}
8664
8665template<typename Derived>
8668 bool DeclChanged = false;
8670 LambdaScopeInfo *LSI = getSema().getCurLambda();
8671 for (auto *D : S->decls()) {
8672 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8673 if (!Transformed)
8674 return StmtError();
8675
8676 if (Transformed != D)
8677 DeclChanged = true;
8678
8679 if (LSI) {
8680 if (auto *TD = dyn_cast<TypeDecl>(Transformed)) {
8681 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
8682 LSI->ContainsUnexpandedParameterPack |=
8683 TN->getUnderlyingType()->containsUnexpandedParameterPack();
8684 } else {
8685 LSI->ContainsUnexpandedParameterPack |=
8686 getSema()
8687 .getASTContext()
8688 .getTypeDeclType(TD)
8689 ->containsUnexpandedParameterPack();
8690 }
8691 }
8692 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8693 LSI->ContainsUnexpandedParameterPack |=
8694 VD->getType()->containsUnexpandedParameterPack();
8695 }
8696
8697 Decls.push_back(Transformed);
8698 }
8699
8700 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8701 return S;
8702
8703 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8704}
8705
8706template<typename Derived>
8709
8710 SmallVector<Expr*, 8> Constraints;
8713
8714 SmallVector<Expr*, 8> Clobbers;
8715
8716 bool ExprsChanged = false;
8717
8718 auto RebuildString = [&](Expr *E) {
8719 ExprResult Result = getDerived().TransformExpr(E);
8720 if (!Result.isUsable())
8721 return Result;
8722 if (Result.get() != E) {
8723 ExprsChanged = true;
8724 Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false);
8725 }
8726 return Result;
8727 };
8728
8729 // Go through the outputs.
8730 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8731 Names.push_back(S->getOutputIdentifier(I));
8732
8733 ExprResult Result = RebuildString(S->getOutputConstraintExpr(I));
8734 if (Result.isInvalid())
8735 return StmtError();
8736
8737 Constraints.push_back(Result.get());
8738
8739 // Transform the output expr.
8740 Expr *OutputExpr = S->getOutputExpr(I);
8741 Result = getDerived().TransformExpr(OutputExpr);
8742 if (Result.isInvalid())
8743 return StmtError();
8744
8745 ExprsChanged |= Result.get() != OutputExpr;
8746
8747 Exprs.push_back(Result.get());
8748 }
8749
8750 // Go through the inputs.
8751 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8752 Names.push_back(S->getInputIdentifier(I));
8753
8754 ExprResult Result = RebuildString(S->getInputConstraintExpr(I));
8755 if (Result.isInvalid())
8756 return StmtError();
8757
8758 Constraints.push_back(Result.get());
8759
8760 // Transform the input expr.
8761 Expr *InputExpr = S->getInputExpr(I);
8762 Result = getDerived().TransformExpr(InputExpr);
8763 if (Result.isInvalid())
8764 return StmtError();
8765
8766 ExprsChanged |= Result.get() != InputExpr;
8767
8768 Exprs.push_back(Result.get());
8769 }
8770
8771 // Go through the Labels.
8772 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8773 Names.push_back(S->getLabelIdentifier(I));
8774
8775 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8776 if (Result.isInvalid())
8777 return StmtError();
8778 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8779 Exprs.push_back(Result.get());
8780 }
8781
8782 // Go through the clobbers.
8783 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) {
8784 ExprResult Result = RebuildString(S->getClobberExpr(I));
8785 if (Result.isInvalid())
8786 return StmtError();
8787 Clobbers.push_back(Result.get());
8788 }
8789
8790 ExprResult AsmString = RebuildString(S->getAsmStringExpr());
8791 if (AsmString.isInvalid())
8792 return StmtError();
8793
8794 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8795 return S;
8796
8797 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8798 S->isVolatile(), S->getNumOutputs(),
8799 S->getNumInputs(), Names.data(),
8800 Constraints, Exprs, AsmString.get(),
8801 Clobbers, S->getNumLabels(),
8802 S->getRParenLoc());
8803}
8804
8805template<typename Derived>
8808 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8809
8810 bool HadError = false, HadChange = false;
8811
8812 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8813 SmallVector<Expr*, 8> TransformedExprs;
8814 TransformedExprs.reserve(SrcExprs.size());
8815 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
8816 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
8817 if (!Result.isUsable()) {
8818 HadError = true;
8819 } else {
8820 HadChange |= (Result.get() != SrcExprs[i]);
8821 TransformedExprs.push_back(Result.get());
8822 }
8823 }
8824
8825 if (HadError) return StmtError();
8826 if (!HadChange && !getDerived().AlwaysRebuild())
8827 return Owned(S);
8828
8829 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
8830 AsmToks, S->getAsmString(),
8831 S->getNumOutputs(), S->getNumInputs(),
8832 S->getAllConstraints(), S->getClobbers(),
8833 TransformedExprs, S->getEndLoc());
8834}
8835
8836// C++ Coroutines
8837template<typename Derived>
8840 auto *ScopeInfo = SemaRef.getCurFunction();
8841 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
8842 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
8843 ScopeInfo->NeedsCoroutineSuspends &&
8844 ScopeInfo->CoroutineSuspends.first == nullptr &&
8845 ScopeInfo->CoroutineSuspends.second == nullptr &&
8846 "expected clean scope info");
8847
8848 // Set that we have (possibly-invalid) suspend points before we do anything
8849 // that may fail.
8850 ScopeInfo->setNeedsCoroutineSuspends(false);
8851
8852 // We re-build the coroutine promise object (and the coroutine parameters its
8853 // type and constructor depend on) based on the types used in our current
8854 // function. We must do so, and set it on the current FunctionScopeInfo,
8855 // before attempting to transform the other parts of the coroutine body
8856 // statement, such as the implicit suspend statements (because those
8857 // statements reference the FunctionScopeInfo::CoroutinePromise).
8858 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
8859 return StmtError();
8860 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
8861 if (!Promise)
8862 return StmtError();
8863 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
8864 ScopeInfo->CoroutinePromise = Promise;
8865
8866 // Transform the implicit coroutine statements constructed using dependent
8867 // types during the previous parse: initial and final suspensions, the return
8868 // object, and others. We also transform the coroutine function's body.
8869 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
8870 if (InitSuspend.isInvalid())
8871 return StmtError();
8872 StmtResult FinalSuspend =
8873 getDerived().TransformStmt(S->getFinalSuspendStmt());
8874 if (FinalSuspend.isInvalid() ||
8875 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
8876 return StmtError();
8877 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
8878 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
8879
8880 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
8881 if (BodyRes.isInvalid())
8882 return StmtError();
8883
8884 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
8885 if (Builder.isInvalid())
8886 return StmtError();
8887
8888 Expr *ReturnObject = S->getReturnValueInit();
8889 assert(ReturnObject && "the return object is expected to be valid");
8890 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
8891 /*NoCopyInit*/ false);
8892 if (Res.isInvalid())
8893 return StmtError();
8894 Builder.ReturnValue = Res.get();
8895
8896 // If during the previous parse the coroutine still had a dependent promise
8897 // statement, we may need to build some implicit coroutine statements
8898 // (such as exception and fallthrough handlers) for the first time.
8899 if (S->hasDependentPromiseType()) {
8900 // We can only build these statements, however, if the current promise type
8901 // is not dependent.
8902 if (!Promise->getType()->isDependentType()) {
8903 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
8904 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
8905 "these nodes should not have been built yet");
8906 if (!Builder.buildDependentStatements())
8907 return StmtError();
8908 }
8909 } else {
8910 if (auto *OnFallthrough = S->getFallthroughHandler()) {
8911 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
8912 if (Res.isInvalid())
8913 return StmtError();
8914 Builder.OnFallthrough = Res.get();
8915 }
8916
8917 if (auto *OnException = S->getExceptionHandler()) {
8918 StmtResult Res = getDerived().TransformStmt(OnException);
8919 if (Res.isInvalid())
8920 return StmtError();
8921 Builder.OnException = Res.get();
8922 }
8923
8924 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
8925 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
8926 if (Res.isInvalid())
8927 return StmtError();
8928 Builder.ReturnStmtOnAllocFailure = Res.get();
8929 }
8930
8931 // Transform any additional statements we may have already built
8932 assert(S->getAllocate() && S->getDeallocate() &&
8933 "allocation and deallocation calls must already be built");
8934 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
8935 if (AllocRes.isInvalid())
8936 return StmtError();
8937 Builder.Allocate = AllocRes.get();
8938
8939 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
8940 if (DeallocRes.isInvalid())
8941 return StmtError();
8942 Builder.Deallocate = DeallocRes.get();
8943
8944 if (auto *ResultDecl = S->getResultDecl()) {
8945 StmtResult Res = getDerived().TransformStmt(ResultDecl);
8946 if (Res.isInvalid())
8947 return StmtError();
8948 Builder.ResultDecl = Res.get();
8949 }
8950
8951 if (auto *ReturnStmt = S->getReturnStmt()) {
8952 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
8953 if (Res.isInvalid())
8954 return StmtError();
8955 Builder.ReturnStmt = Res.get();
8956 }
8957 }
8958
8959 return getDerived().RebuildCoroutineBodyStmt(Builder);
8960}
8961
8962template<typename Derived>
8965 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
8966 /*NotCopyInit*/false);
8967 if (Result.isInvalid())
8968 return StmtError();
8969
8970 // Always rebuild; we don't know if this needs to be injected into a new
8971 // context or if the promise type has changed.
8972 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
8973 S->isImplicit());
8974}
8975
8976template <typename Derived>
8978 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
8979 /*NotCopyInit*/ false);
8980 if (Operand.isInvalid())
8981 return ExprError();
8982
8983 // Rebuild the common-expr from the operand rather than transforming it
8984 // separately.
8985
8986 // FIXME: getCurScope() should not be used during template instantiation.
8987 // We should pick up the set of unqualified lookup results for operator
8988 // co_await during the initial parse.
8989 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
8990 getSema().getCurScope(), E->getKeywordLoc());
8991
8992 // Always rebuild; we don't know if this needs to be injected into a new
8993 // context or if the promise type has changed.
8994 return getDerived().RebuildCoawaitExpr(
8995 E->getKeywordLoc(), Operand.get(),
8996 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
8997}
8998
8999template <typename Derived>
9002 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
9003 /*NotCopyInit*/ false);
9004 if (OperandResult.isInvalid())
9005 return ExprError();
9006
9007 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
9008 E->getOperatorCoawaitLookup());
9009
9010 if (LookupResult.isInvalid())
9011 return ExprError();
9012
9013 // Always rebuild; we don't know if this needs to be injected into a new
9014 // context or if the promise type has changed.
9015 return getDerived().RebuildDependentCoawaitExpr(
9016 E->getKeywordLoc(), OperandResult.get(),
9018}
9019
9020template<typename Derived>
9023 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
9024 /*NotCopyInit*/false);
9025 if (Result.isInvalid())
9026 return ExprError();
9027
9028 // Always rebuild; we don't know if this needs to be injected into a new
9029 // context or if the promise type has changed.
9030 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
9031}
9032
9033// Objective-C Statements.
9034
9035template<typename Derived>
9038 // Transform the body of the @try.
9039 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
9040 if (TryBody.isInvalid())
9041 return StmtError();
9042
9043 // Transform the @catch statements (if present).
9044 bool AnyCatchChanged = false;
9045 SmallVector<Stmt*, 8> CatchStmts;
9046 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
9047 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
9048 if (Catch.isInvalid())
9049 return StmtError();
9050 if (Catch.get() != S->getCatchStmt(I))
9051 AnyCatchChanged = true;
9052 CatchStmts.push_back(Catch.get());
9053 }
9054
9055 // Transform the @finally statement (if present).
9056 StmtResult Finally;
9057 if (S->getFinallyStmt()) {
9058 Finally = getDerived().TransformStmt(S->getFinallyStmt());
9059 if (Finally.isInvalid())
9060 return StmtError();
9061 }
9062
9063 // If nothing changed, just retain this statement.
9064 if (!getDerived().AlwaysRebuild() &&
9065 TryBody.get() == S->getTryBody() &&
9066 !AnyCatchChanged &&
9067 Finally.get() == S->getFinallyStmt())
9068 return S;
9069
9070 // Build a new statement.
9071 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
9072 CatchStmts, Finally.get());
9073}
9074
9075template<typename Derived>
9078 // Transform the @catch parameter, if there is one.
9079 VarDecl *Var = nullptr;
9080 if (VarDecl *FromVar = S->getCatchParamDecl()) {
9081 TypeSourceInfo *TSInfo = nullptr;
9082 if (FromVar->getTypeSourceInfo()) {
9083 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
9084 if (!TSInfo)
9085 return StmtError();
9086 }
9087
9088 QualType T;
9089 if (TSInfo)
9090 T = TSInfo->getType();
9091 else {
9092 T = getDerived().TransformType(FromVar->getType());
9093 if (T.isNull())
9094 return StmtError();
9095 }
9096
9097 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
9098 if (!Var)
9099 return StmtError();
9100 }
9101
9102 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
9103 if (Body.isInvalid())
9104 return StmtError();
9105
9106 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
9107 S->getRParenLoc(),
9108 Var, Body.get());
9109}
9110
9111template<typename Derived>
9114 // Transform the body.
9115 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
9116 if (Body.isInvalid())
9117 return StmtError();
9118
9119 // If nothing changed, just retain this statement.
9120 if (!getDerived().AlwaysRebuild() &&
9121 Body.get() == S->getFinallyBody())
9122 return S;
9123
9124 // Build a new statement.
9125 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
9126 Body.get());
9127}
9128
9129template<typename Derived>
9133 if (S->getThrowExpr()) {
9134 Operand = getDerived().TransformExpr(S->getThrowExpr());
9135 if (Operand.isInvalid())
9136 return StmtError();
9137 }
9138
9139 if (!getDerived().AlwaysRebuild() &&
9140 Operand.get() == S->getThrowExpr())
9141 return S;
9142
9143 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
9144}
9145
9146template<typename Derived>
9150 // Transform the object we are locking.
9151 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
9152 if (Object.isInvalid())
9153 return StmtError();
9154 Object =
9155 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
9156 Object.get());
9157 if (Object.isInvalid())
9158 return StmtError();
9159
9160 // Transform the body.
9161 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
9162 if (Body.isInvalid())
9163 return StmtError();
9164
9165 // If nothing change, just retain the current statement.
9166 if (!getDerived().AlwaysRebuild() &&
9167 Object.get() == S->getSynchExpr() &&
9168 Body.get() == S->getSynchBody())
9169 return S;
9170
9171 // Build a new statement.
9172 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
9173 Object.get(), Body.get());
9174}
9175
9176template<typename Derived>
9180 // Transform the body.
9181 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
9182 if (Body.isInvalid())
9183 return StmtError();
9184
9185 // If nothing changed, just retain this statement.
9186 if (!getDerived().AlwaysRebuild() &&
9187 Body.get() == S->getSubStmt())
9188 return S;
9189
9190 // Build a new statement.
9191 return getDerived().RebuildObjCAutoreleasePoolStmt(
9192 S->getAtLoc(), Body.get());
9193}
9194
9195template<typename Derived>
9199 // Transform the element statement.
9200 StmtResult Element = getDerived().TransformStmt(
9201 S->getElement(), StmtDiscardKind::NotDiscarded);
9202 if (Element.isInvalid())
9203 return StmtError();
9204
9205 // Transform the collection expression.
9206 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
9207 if (Collection.isInvalid())
9208 return StmtError();
9209
9210 // Transform the body.
9211 StmtResult Body = getDerived().TransformStmt(S->getBody());
9212 if (Body.isInvalid())
9213 return StmtError();
9214
9215 // If nothing changed, just retain this statement.
9216 if (!getDerived().AlwaysRebuild() &&
9217 Element.get() == S->getElement() &&
9218 Collection.get() == S->getCollection() &&
9219 Body.get() == S->getBody())
9220 return S;
9221
9222 // Build a new statement.
9223 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9224 Element.get(),
9225 Collection.get(),
9226 S->getRParenLoc(),
9227 Body.get());
9228}
9229
9230template <typename Derived>
9232 // Transform the exception declaration, if any.
9233 VarDecl *Var = nullptr;
9234 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9235 TypeSourceInfo *T =
9236 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9237 if (!T)
9238 return StmtError();
9239
9240 Var = getDerived().RebuildExceptionDecl(
9241 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9242 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9243 if (!Var || Var->isInvalidDecl())
9244 return StmtError();
9245 }
9246
9247 // Transform the actual exception handler.
9248 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9249 if (Handler.isInvalid())
9250 return StmtError();
9251
9252 if (!getDerived().AlwaysRebuild() && !Var &&
9253 Handler.get() == S->getHandlerBlock())
9254 return S;
9255
9256 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9257}
9258
9259template <typename Derived>
9261 // Transform the try block itself.
9262 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9263 if (TryBlock.isInvalid())
9264 return StmtError();
9265
9266 // Transform the handlers.
9267 bool HandlerChanged = false;
9268 SmallVector<Stmt *, 8> Handlers;
9269 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9270 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9271 if (Handler.isInvalid())
9272 return StmtError();
9273
9274 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9275 Handlers.push_back(Handler.getAs<Stmt>());
9276 }
9277
9278 getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true);
9279
9280 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9281 !HandlerChanged)
9282 return S;
9283
9284 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9285 Handlers);
9286}
9287
9288template<typename Derived>
9291 EnterExpressionEvaluationContext ForRangeInitContext(
9293 /*LambdaContextDecl=*/nullptr,
9295 getSema().getLangOpts().CPlusPlus23);
9296
9297 // P2718R0 - Lifetime extension in range-based for loops.
9298 if (getSema().getLangOpts().CPlusPlus23) {
9299 auto &LastRecord = getSema().currentEvaluationContext();
9300 LastRecord.InLifetimeExtendingContext = true;
9301 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9302 }
9304 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9305 if (Init.isInvalid())
9306 return StmtError();
9307
9308 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9309 if (Range.isInvalid())
9310 return StmtError();
9311
9312 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9313 assert(getSema().getLangOpts().CPlusPlus23 ||
9314 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9315 auto ForRangeLifetimeExtendTemps =
9316 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9317
9318 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9319 if (Begin.isInvalid())
9320 return StmtError();
9321 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9322 if (End.isInvalid())
9323 return StmtError();
9324
9325 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9326 if (Cond.isInvalid())
9327 return StmtError();
9328 if (Cond.get())
9329 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9330 if (Cond.isInvalid())
9331 return StmtError();
9332 if (Cond.get())
9333 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9334
9335 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9336 if (Inc.isInvalid())
9337 return StmtError();
9338 if (Inc.get())
9339 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9340
9341 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9342 if (LoopVar.isInvalid())
9343 return StmtError();
9344
9345 StmtResult NewStmt = S;
9346 if (getDerived().AlwaysRebuild() ||
9347 Init.get() != S->getInit() ||
9348 Range.get() != S->getRangeStmt() ||
9349 Begin.get() != S->getBeginStmt() ||
9350 End.get() != S->getEndStmt() ||
9351 Cond.get() != S->getCond() ||
9352 Inc.get() != S->getInc() ||
9353 LoopVar.get() != S->getLoopVarStmt()) {
9354 NewStmt = getDerived().RebuildCXXForRangeStmt(
9355 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9356 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9357 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9358 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9359 // Might not have attached any initializer to the loop variable.
9360 getSema().ActOnInitializerError(
9361 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9362 return StmtError();
9363 }
9364 }
9365
9366 // OpenACC Restricts a while-loop inside of certain construct/clause
9367 // combinations, so diagnose that here in OpenACC mode.
9369 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9370
9371 StmtResult Body = getDerived().TransformStmt(S->getBody());
9372 if (Body.isInvalid())
9373 return StmtError();
9374
9375 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9376
9377 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9378 // it now so we have a new statement to attach the body to.
9379 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9380 NewStmt = getDerived().RebuildCXXForRangeStmt(
9381 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9382 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9383 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9384 if (NewStmt.isInvalid())
9385 return StmtError();
9386 }
9387
9388 if (NewStmt.get() == S)
9389 return S;
9390
9391 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9392}
9393
9394template <typename Derived>
9397 assert(SemaRef.CurContext->isExpansionStmt());
9398
9399 Decl *ESD =
9400 getDerived().TransformDecl(S->getDecl()->getLocation(), S->getDecl());
9401 if (!ESD || ESD->isInvalidDecl())
9402 return StmtError();
9404
9405 // This is required because some parts of an expansion statement (e.g. the
9406 // init-statement) are not in a dependent context and must thus be transformed
9407 // in the parent context.
9408 auto TransformStmtInParentContext = [&](Stmt *SubStmt) -> StmtResult {
9409 Sema::ContextRAII CtxGuard(SemaRef, SemaRef.CurContext->getParent(),
9410 /*NewThis=*/false);
9411 return getDerived().TransformStmt(SubStmt);
9412 };
9413
9414 Stmt *Init = S->getInit();
9415 if (Init) {
9416 StmtResult SR = TransformStmtInParentContext(Init);
9417 if (SR.isInvalid())
9418 return StmtError();
9419 Init = SR.get();
9420 }
9421
9422 // Collect lifetime-extended temporaries in case this ends up being a
9423 // destructuring or iterating expansion statement.
9424 //
9425 // CWG 3140: Additionally, for iterating expansions statements, we need to
9426 // apply lifetime extension to the initializer of the range.
9427 ExprResult ExpansionInitializer;
9430 if (S->isDependent() || S->isIterating()) {
9432 SemaRef, SemaRef.currentEvaluationContext().Context);
9435
9436 if (S->isDependent()) {
9437 // The expansion initializer should not be in the context of the expansion
9438 // statement because it isn't instantiated when the expansion statement is
9439 // expanded.
9440 Sema::ContextRAII CtxGuard(SemaRef, SemaRef.CurContext->getParent(),
9441 /*NewThis=*/false);
9442 ExpansionInitializer =
9443 getDerived().TransformExpr(S->getExpansionInitializer());
9444 if (ExpansionInitializer.isInvalid())
9445 return StmtError();
9446 } else if (S->isIterating()) {
9447 Range = TransformStmtInParentContext(S->getRangeVarStmt());
9448 if (Range.isInvalid())
9449 return StmtError();
9450 }
9451
9452 ExpansionInitializer =
9453 SemaRef.MaybeCreateExprWithCleanups(ExpansionInitializer);
9454
9455 LifetimeExtendTemps =
9457 }
9458
9459 CXXExpansionStmtPattern *NewPattern = nullptr;
9460 if (S->isEnumerating()) {
9461 StmtResult ExpansionVar =
9462 getDerived().TransformStmt(S->getExpansionVarStmt());
9463 if (ExpansionVar.isInvalid())
9464 return StmtError();
9465
9467 SemaRef.Context, NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9468 S->getLParenLoc(), S->getColonLoc(), S->getRParenLoc());
9469 } else if (S->isIterating()) {
9470 StmtResult Begin = TransformStmtInParentContext(S->getBeginVarStmt());
9471 StmtResult Iter = TransformStmtInParentContext(S->getIterVarStmt());
9472 if (Begin.isInvalid() || Iter.isInvalid())
9473 return StmtError();
9474
9475 // The expansion variable is part of the pattern only and never ends
9476 // up in the instantiations, so keep it in the expansion statement's
9477 // DeclContext.
9478 StmtResult ExpansionVar =
9479 getDerived().TransformStmt(S->getExpansionVarStmt());
9480 if (ExpansionVar.isInvalid())
9481 return StmtError();
9482
9484 SemaRef.Context, NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9485 Range.getAs<DeclStmt>(), Begin.getAs<DeclStmt>(),
9486 Iter.getAs<DeclStmt>(), S->getLParenLoc(), S->getColonLoc(),
9487 S->getRParenLoc());
9488
9490 NewPattern->getRangeVar(), LifetimeExtendTemps);
9491 } else if (S->isDependent()) {
9492 StmtResult ExpansionVar =
9493 getDerived().TransformStmt(S->getExpansionVarStmt());
9494 if (ExpansionVar.isInvalid())
9495 return StmtError();
9496
9498 NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9499 ExpansionInitializer.get(), S->getLParenLoc(), S->getColonLoc(),
9500 S->getRParenLoc(), LifetimeExtendTemps);
9501
9502 if (Res.isInvalid())
9503 return StmtError();
9504
9505 NewPattern = cast<CXXExpansionStmtPattern>(Res.get());
9506 } else {
9507 // The only time we instantiate an expansion statement is if its expansion
9508 // size is dependent (otherwise, we only instantiate the expansions and
9509 // leave the underlying CXXExpansionStmtPattern as-is). Since destructuring
9510 // expansion statements never have a dependent size, we should never get
9511 // here.
9512 llvm_unreachable("destructuring pattern should never be instantiated");
9513 }
9514
9515 StmtResult Body = getDerived().TransformStmt(S->getBody());
9516 if (Body.isInvalid())
9517 return StmtError();
9518
9519 return SemaRef.FinishCXXExpansionStmt(NewPattern, Body.get());
9520}
9521
9522template <typename Derived>
9525 bool SubStmtChanged = false;
9526 auto TransformStmts = [&](SmallVectorImpl<Stmt *> &NewStmts,
9527 ArrayRef<Stmt *> OldStmts) {
9528 for (Stmt *OldDS : OldStmts) {
9529 StmtResult NewDS = getDerived().TransformStmt(OldDS);
9530 if (NewDS.isInvalid())
9531 return true;
9532
9533 SubStmtChanged |= NewDS.get() != OldDS;
9534 NewStmts.push_back(NewDS.get());
9535 }
9536
9537 return false;
9538 };
9539
9540 Decl *ESD =
9541 getDerived().TransformDecl(S->getParent()->getLocation(), S->getParent());
9542 if (!ESD || ESD->isInvalidDecl())
9543 return StmtError();
9545
9546 SmallVector<Stmt *> PreambleStmts;
9547 SmallVector<Stmt *> Instantiations;
9548
9549 // Apply lifetime extension to the preamble statements if this was a
9550 // destructuring expansion statement.
9551 {
9553 SemaRef, SemaRef.currentEvaluationContext().Context);
9556 if (TransformStmts(PreambleStmts, S->getPreambleStmts()))
9557 return StmtError();
9558
9559 if (S->shouldApplyLifetimeExtensionToPreamble()) {
9560 auto *VD =
9561 cast<VarDecl>(cast<DeclStmt>(PreambleStmts.front())->getSingleDecl());
9564 }
9565 }
9566
9567 if (TransformStmts(Instantiations, S->getInstantiations()))
9568 return StmtError();
9569
9570 if (!getDerived().AlwaysRebuild() && !SubStmtChanged)
9571 return S;
9572
9574 SemaRef.Context, NewESD, Instantiations, PreambleStmts,
9575 S->shouldApplyLifetimeExtensionToPreamble());
9576}
9577
9578template <typename Derived>
9581 ExprResult Range = getDerived().TransformExpr(E->getRangeExpr());
9582 ExprResult Idx = getDerived().TransformExpr(E->getIndexExpr());
9583 if (Range.isInvalid() || Idx.isInvalid())
9584 return ExprError();
9585
9586 if (!getDerived().AlwaysRebuild() && Range.get() == E->getRangeExpr() &&
9587 Idx.get() == E->getIndexExpr())
9588 return E;
9589
9590 return SemaRef.BuildCXXExpansionSelectExpr(Range.getAs<InitListExpr>(),
9591 Idx.get());
9592}
9593
9594template<typename Derived>
9598 // Transform the nested-name-specifier, if any.
9599 NestedNameSpecifierLoc QualifierLoc;
9600 if (S->getQualifierLoc()) {
9601 QualifierLoc
9602 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9603 if (!QualifierLoc)
9604 return StmtError();
9605 }
9606
9607 // Transform the declaration name.
9608 DeclarationNameInfo NameInfo = S->getNameInfo();
9609 if (NameInfo.getName()) {
9610 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9611 if (!NameInfo.getName())
9612 return StmtError();
9613 }
9614
9615 // Check whether anything changed.
9616 if (!getDerived().AlwaysRebuild() &&
9617 QualifierLoc == S->getQualifierLoc() &&
9618 NameInfo.getName() == S->getNameInfo().getName())
9619 return S;
9620
9621 // Determine whether this name exists, if we can.
9622 CXXScopeSpec SS;
9623 SS.Adopt(QualifierLoc);
9624 bool Dependent = false;
9625 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9627 if (S->isIfExists())
9628 break;
9629
9630 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9631
9633 if (S->isIfNotExists())
9634 break;
9635
9636 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9637
9639 Dependent = true;
9640 break;
9641
9643 return StmtError();
9644 }
9645
9646 // We need to continue with the instantiation, so do so now.
9647 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9648 if (SubStmt.isInvalid())
9649 return StmtError();
9650
9651 // If we have resolved the name, just transform to the substatement.
9652 if (!Dependent)
9653 return SubStmt;
9654
9655 // The name is still dependent, so build a dependent expression again.
9656 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9657 S->isIfExists(),
9658 QualifierLoc,
9659 NameInfo,
9660 SubStmt.get());
9661}
9662
9663template<typename Derived>
9666 NestedNameSpecifierLoc QualifierLoc;
9667 if (E->getQualifierLoc()) {
9668 QualifierLoc
9669 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9670 if (!QualifierLoc)
9671 return ExprError();
9672 }
9673
9674 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9675 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9676 if (!PD)
9677 return ExprError();
9678
9679 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9680 if (Base.isInvalid())
9681 return ExprError();
9682
9683 return new (SemaRef.getASTContext())
9684 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9686 QualifierLoc, E->getMemberLoc());
9687}
9688
9689template <typename Derived>
9692 auto BaseRes = getDerived().TransformExpr(E->getBase());
9693 if (BaseRes.isInvalid())
9694 return ExprError();
9695 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9696 if (IdxRes.isInvalid())
9697 return ExprError();
9698
9699 if (!getDerived().AlwaysRebuild() &&
9700 BaseRes.get() == E->getBase() &&
9701 IdxRes.get() == E->getIdx())
9702 return E;
9703
9704 return getDerived().RebuildArraySubscriptExpr(
9705 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9706}
9707
9708template <typename Derived>
9710 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9711 if (TryBlock.isInvalid())
9712 return StmtError();
9713
9714 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9715 if (Handler.isInvalid())
9716 return StmtError();
9717
9718 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9719 Handler.get() == S->getHandler())
9720 return S;
9721
9722 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9723 TryBlock.get(), Handler.get());
9724}
9725
9726template <typename Derived>
9728 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9729 if (Block.isInvalid())
9730 return StmtError();
9731
9732 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9733}
9734
9735template <typename Derived>
9737 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9738 if (FilterExpr.isInvalid())
9739 return StmtError();
9740
9741 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9742 if (Block.isInvalid())
9743 return StmtError();
9744
9745 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9746 Block.get());
9747}
9748
9749template <typename Derived>
9751 if (isa<SEHFinallyStmt>(Handler))
9752 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9753 else
9754 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9755}
9756
9757template<typename Derived>
9760 return S;
9761}
9762
9763//===----------------------------------------------------------------------===//
9764// OpenMP directive transformation
9765//===----------------------------------------------------------------------===//
9766
9767template <typename Derived>
9768StmtResult
9769TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9770 // OMPCanonicalLoops are eliminated during transformation, since they will be
9771 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9772 // after transformation.
9773 return getDerived().TransformStmt(L->getLoopStmt());
9774}
9775
9776template <typename Derived>
9779
9780 // Transform the clauses
9782 ArrayRef<OMPClause *> Clauses = D->clauses();
9783 TClauses.reserve(Clauses.size());
9784 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9785 I != E; ++I) {
9786 if (*I) {
9787 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9788 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9789 getDerived().getSema().OpenMP().EndOpenMPClause();
9790 if (Clause)
9791 TClauses.push_back(Clause);
9792 } else {
9793 TClauses.push_back(nullptr);
9794 }
9795 }
9796 StmtResult AssociatedStmt;
9797 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9798 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9799 D->getDirectiveKind(),
9800 /*CurScope=*/nullptr);
9801 StmtResult Body;
9802 {
9803 Sema::CompoundScopeRAII CompoundScope(getSema());
9804 Stmt *CS;
9805 if (D->getDirectiveKind() == OMPD_atomic ||
9806 D->getDirectiveKind() == OMPD_critical ||
9807 D->getDirectiveKind() == OMPD_section ||
9808 D->getDirectiveKind() == OMPD_master)
9809 CS = D->getAssociatedStmt();
9810 else
9811 CS = D->getRawStmt();
9812 Body = getDerived().TransformStmt(CS);
9813 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
9814 getSema().getLangOpts().OpenMPIRBuilder)
9815 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
9816 }
9817 AssociatedStmt =
9818 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9819 if (AssociatedStmt.isInvalid()) {
9820 return StmtError();
9821 }
9822 }
9823 if (TClauses.size() != Clauses.size()) {
9824 return StmtError();
9825 }
9826
9827 // Transform directive name for 'omp critical' directive.
9828 DeclarationNameInfo DirName;
9829 if (D->getDirectiveKind() == OMPD_critical) {
9830 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
9831 DirName = getDerived().TransformDeclarationNameInfo(DirName);
9832 }
9833 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
9834 if (D->getDirectiveKind() == OMPD_cancellation_point) {
9835 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
9836 } else if (D->getDirectiveKind() == OMPD_cancel) {
9837 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
9838 }
9839
9840 return getDerived().RebuildOMPExecutableDirective(
9841 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
9842 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
9843}
9844
9845/// This is mostly the same as above, but allows 'informational' class
9846/// directives when rebuilding the stmt. It still takes an
9847/// OMPExecutableDirective-type argument because we're reusing that as the
9848/// superclass for the 'assume' directive at present, instead of defining a
9849/// mostly-identical OMPInformationalDirective parent class.
9850template <typename Derived>
9853
9854 // Transform the clauses
9856 ArrayRef<OMPClause *> Clauses = D->clauses();
9857 TClauses.reserve(Clauses.size());
9858 for (OMPClause *C : Clauses) {
9859 if (C) {
9860 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
9861 OMPClause *Clause = getDerived().TransformOMPClause(C);
9862 getDerived().getSema().OpenMP().EndOpenMPClause();
9863 if (Clause)
9864 TClauses.push_back(Clause);
9865 } else {
9866 TClauses.push_back(nullptr);
9867 }
9868 }
9869 StmtResult AssociatedStmt;
9870 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9871 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9872 D->getDirectiveKind(),
9873 /*CurScope=*/nullptr);
9874 StmtResult Body;
9875 {
9876 Sema::CompoundScopeRAII CompoundScope(getSema());
9877 assert(D->getDirectiveKind() == OMPD_assume &&
9878 "Unexpected informational directive");
9879 Stmt *CS = D->getAssociatedStmt();
9880 Body = getDerived().TransformStmt(CS);
9881 }
9882 AssociatedStmt =
9883 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
9884 if (AssociatedStmt.isInvalid())
9885 return StmtError();
9886 }
9887 if (TClauses.size() != Clauses.size())
9888 return StmtError();
9889
9890 DeclarationNameInfo DirName;
9891
9892 return getDerived().RebuildOMPInformationalDirective(
9893 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
9894 D->getBeginLoc(), D->getEndLoc());
9895}
9896
9897template <typename Derived>
9900 // TODO: Fix This
9901 unsigned OMPVersion = getDerived().getSema().getLangOpts().OpenMP;
9902 SemaRef.Diag(D->getBeginLoc(), diag::err_omp_instantiation_not_supported)
9903 << getOpenMPDirectiveName(D->getDirectiveKind(), OMPVersion);
9904 return StmtError();
9905}
9906
9907template <typename Derived>
9908StmtResult
9909TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
9910 DeclarationNameInfo DirName;
9911 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9912 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
9913 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9914 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9915 return Res;
9916}
9917
9918template <typename Derived>
9921 DeclarationNameInfo DirName;
9922 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9923 OMPD_simd, DirName, nullptr, D->getBeginLoc());
9924 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9925 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9926 return Res;
9927}
9928
9929template <typename Derived>
9932 DeclarationNameInfo DirName;
9933 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9934 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9935 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9936 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9937 return Res;
9938}
9939
9940template <typename Derived>
9943 DeclarationNameInfo DirName;
9944 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9945 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9946 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9947 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9948 return Res;
9949}
9950
9951template <typename Derived>
9954 DeclarationNameInfo DirName;
9955 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9956 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9957 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9958 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9959 return Res;
9960}
9961
9962template <typename Derived>
9965 DeclarationNameInfo DirName;
9966 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9967 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9968 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9969 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9970 return Res;
9971}
9972
9973template <typename Derived>
9975 OMPInterchangeDirective *D) {
9976 DeclarationNameInfo DirName;
9977 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9978 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9979 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9980 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9981 return Res;
9982}
9983
9984template <typename Derived>
9987 DeclarationNameInfo DirName;
9988 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
9989 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
9990 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
9991 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
9992 return Res;
9993}
9994
9995template <typename Derived>
9998 DeclarationNameInfo DirName;
9999 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10000 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10001 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10002 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10003 return Res;
10004}
10005
10006template <typename Derived>
10009 DeclarationNameInfo DirName;
10010 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10011 OMPD_for, DirName, nullptr, D->getBeginLoc());
10012 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10013 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10014 return Res;
10015}
10016
10017template <typename Derived>
10020 DeclarationNameInfo DirName;
10021 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10022 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
10023 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10024 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10025 return Res;
10026}
10027
10028template <typename Derived>
10031 DeclarationNameInfo DirName;
10032 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10033 OMPD_sections, DirName, nullptr, D->getBeginLoc());
10034 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10035 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10036 return Res;
10037}
10038
10039template <typename Derived>
10042 DeclarationNameInfo DirName;
10043 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10044 OMPD_section, DirName, nullptr, D->getBeginLoc());
10045 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10046 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10047 return Res;
10048}
10049
10050template <typename Derived>
10053 DeclarationNameInfo DirName;
10054 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10055 OMPD_scope, DirName, nullptr, D->getBeginLoc());
10056 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10057 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10058 return Res;
10059}
10060
10061template <typename Derived>
10064 DeclarationNameInfo DirName;
10065 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10066 OMPD_single, DirName, nullptr, D->getBeginLoc());
10067 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10068 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10069 return Res;
10070}
10071
10072template <typename Derived>
10075 DeclarationNameInfo DirName;
10076 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10077 OMPD_master, DirName, nullptr, D->getBeginLoc());
10078 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10079 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10080 return Res;
10081}
10082
10083template <typename Derived>
10086 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10087 OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc());
10088 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10089 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10090 return Res;
10091}
10092
10093template <typename Derived>
10095 OMPParallelForDirective *D) {
10096 DeclarationNameInfo DirName;
10097 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10098 OMPD_parallel_for, DirName, nullptr, D->getBeginLoc());
10099 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10100 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10101 return Res;
10102}
10103
10104template <typename Derived>
10106 OMPParallelForSimdDirective *D) {
10107 DeclarationNameInfo DirName;
10108 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10109 OMPD_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10110 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10111 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10112 return Res;
10113}
10114
10115template <typename Derived>
10117 OMPParallelMasterDirective *D) {
10118 DeclarationNameInfo DirName;
10119 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10120 OMPD_parallel_master, DirName, nullptr, D->getBeginLoc());
10121 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10122 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10123 return Res;
10124}
10125
10126template <typename Derived>
10128 OMPParallelMaskedDirective *D) {
10129 DeclarationNameInfo DirName;
10130 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10131 OMPD_parallel_masked, DirName, nullptr, D->getBeginLoc());
10132 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10133 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10134 return Res;
10135}
10136
10137template <typename Derived>
10139 OMPParallelSectionsDirective *D) {
10140 DeclarationNameInfo DirName;
10141 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10142 OMPD_parallel_sections, DirName, nullptr, D->getBeginLoc());
10143 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10144 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10145 return Res;
10146}
10147
10148template <typename Derived>
10151 DeclarationNameInfo DirName;
10152 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10153 OMPD_task, DirName, nullptr, D->getBeginLoc());
10154 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10155 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10156 return Res;
10157}
10158
10159template <typename Derived>
10161 OMPTaskyieldDirective *D) {
10162 DeclarationNameInfo DirName;
10163 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10164 OMPD_taskyield, DirName, nullptr, D->getBeginLoc());
10165 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10166 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10167 return Res;
10168}
10169
10170template <typename Derived>
10173 DeclarationNameInfo DirName;
10174 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10175 OMPD_barrier, DirName, nullptr, D->getBeginLoc());
10176 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10177 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10178 return Res;
10179}
10180
10181template <typename Derived>
10184 DeclarationNameInfo DirName;
10185 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10186 OMPD_taskwait, DirName, nullptr, D->getBeginLoc());
10187 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10188 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10189 return Res;
10190}
10191
10192template <typename Derived>
10195 DeclarationNameInfo DirName;
10196 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10197 OMPD_assume, DirName, nullptr, D->getBeginLoc());
10198 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
10199 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10200 return Res;
10201}
10202
10203template <typename Derived>
10206 DeclarationNameInfo DirName;
10207 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10208 OMPD_error, DirName, nullptr, D->getBeginLoc());
10209 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10210 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10211 return Res;
10212}
10213
10214template <typename Derived>
10216 OMPTaskgroupDirective *D) {
10217 DeclarationNameInfo DirName;
10218 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10219 OMPD_taskgroup, DirName, nullptr, D->getBeginLoc());
10220 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10221 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10222 return Res;
10223}
10224
10225template <typename Derived>
10228 DeclarationNameInfo DirName;
10229 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10230 OMPD_flush, DirName, nullptr, D->getBeginLoc());
10231 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10232 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10233 return Res;
10234}
10235
10236template <typename Derived>
10239 DeclarationNameInfo DirName;
10240 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10241 OMPD_depobj, DirName, nullptr, D->getBeginLoc());
10242 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10243 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10244 return Res;
10245}
10246
10247template <typename Derived>
10250 DeclarationNameInfo DirName;
10251 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10252 OMPD_scan, DirName, nullptr, D->getBeginLoc());
10253 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10254 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10255 return Res;
10256}
10257
10258template <typename Derived>
10261 DeclarationNameInfo DirName;
10262 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10263 OMPD_ordered, DirName, nullptr, D->getBeginLoc());
10264 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10265 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10266 return Res;
10267}
10268
10269template <typename Derived>
10272 DeclarationNameInfo DirName;
10273 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10274 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
10275 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10276 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10277 return Res;
10278}
10279
10280template <typename Derived>
10283 DeclarationNameInfo DirName;
10284 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10285 OMPD_target, DirName, nullptr, D->getBeginLoc());
10286 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10287 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10288 return Res;
10289}
10290
10291template <typename Derived>
10293 OMPTargetDataDirective *D) {
10294 DeclarationNameInfo DirName;
10295 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10296 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
10297 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10298 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10299 return Res;
10300}
10301
10302template <typename Derived>
10304 OMPTargetEnterDataDirective *D) {
10305 DeclarationNameInfo DirName;
10306 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10307 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
10308 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10309 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10310 return Res;
10311}
10312
10313template <typename Derived>
10315 OMPTargetExitDataDirective *D) {
10316 DeclarationNameInfo DirName;
10317 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10318 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
10319 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10320 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10321 return Res;
10322}
10323
10324template <typename Derived>
10326 OMPTargetParallelDirective *D) {
10327 DeclarationNameInfo DirName;
10328 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10329 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
10330 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10331 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10332 return Res;
10333}
10334
10335template <typename Derived>
10337 OMPTargetParallelForDirective *D) {
10338 DeclarationNameInfo DirName;
10339 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10340 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
10341 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10342 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10343 return Res;
10344}
10345
10346template <typename Derived>
10348 OMPTargetUpdateDirective *D) {
10349 DeclarationNameInfo DirName;
10350 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10351 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
10352 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10353 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10354 return Res;
10355}
10356
10357template <typename Derived>
10360 DeclarationNameInfo DirName;
10361 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10362 OMPD_teams, DirName, nullptr, D->getBeginLoc());
10363 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10364 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10365 return Res;
10366}
10367
10368template <typename Derived>
10370 OMPCancellationPointDirective *D) {
10371 DeclarationNameInfo DirName;
10372 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10373 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
10374 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10375 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10376 return Res;
10377}
10378
10379template <typename Derived>
10382 DeclarationNameInfo DirName;
10383 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10384 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
10385 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10386 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10387 return Res;
10388}
10389
10390template <typename Derived>
10393 DeclarationNameInfo DirName;
10394 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10395 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
10396 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10397 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10398 return Res;
10399}
10400
10401template <typename Derived>
10403 OMPTaskLoopSimdDirective *D) {
10404 DeclarationNameInfo DirName;
10405 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10406 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10407 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10408 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10409 return Res;
10410}
10411
10412template <typename Derived>
10414 OMPMasterTaskLoopDirective *D) {
10415 DeclarationNameInfo DirName;
10416 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10417 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
10418 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10419 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10420 return Res;
10421}
10422
10423template <typename Derived>
10425 OMPMaskedTaskLoopDirective *D) {
10426 DeclarationNameInfo DirName;
10427 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10428 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10429 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10430 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10431 return Res;
10432}
10433
10434template <typename Derived>
10436 OMPMasterTaskLoopSimdDirective *D) {
10437 DeclarationNameInfo DirName;
10438 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10439 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10440 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10441 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10442 return Res;
10443}
10444
10445template <typename Derived>
10447 OMPMaskedTaskLoopSimdDirective *D) {
10448 DeclarationNameInfo DirName;
10449 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10450 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10451 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10452 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10453 return Res;
10454}
10455
10456template <typename Derived>
10458 OMPParallelMasterTaskLoopDirective *D) {
10459 DeclarationNameInfo DirName;
10460 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10461 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10462 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10463 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10464 return Res;
10465}
10466
10467template <typename Derived>
10469 OMPParallelMaskedTaskLoopDirective *D) {
10470 DeclarationNameInfo DirName;
10471 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10472 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10473 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10474 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10475 return Res;
10476}
10477
10478template <typename Derived>
10481 OMPParallelMasterTaskLoopSimdDirective *D) {
10482 DeclarationNameInfo DirName;
10483 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10484 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10485 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10486 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10487 return Res;
10488}
10489
10490template <typename Derived>
10493 OMPParallelMaskedTaskLoopSimdDirective *D) {
10494 DeclarationNameInfo DirName;
10495 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10496 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10497 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10498 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10499 return Res;
10500}
10501
10502template <typename Derived>
10504 OMPDistributeDirective *D) {
10505 DeclarationNameInfo DirName;
10506 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10507 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10508 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10509 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10510 return Res;
10511}
10512
10513template <typename Derived>
10515 OMPDistributeParallelForDirective *D) {
10516 DeclarationNameInfo DirName;
10517 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10518 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10519 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10520 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10521 return Res;
10522}
10523
10524template <typename Derived>
10527 OMPDistributeParallelForSimdDirective *D) {
10528 DeclarationNameInfo DirName;
10529 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10530 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10531 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10532 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10533 return Res;
10534}
10535
10536template <typename Derived>
10538 OMPDistributeSimdDirective *D) {
10539 DeclarationNameInfo DirName;
10540 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10541 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10542 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10543 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10544 return Res;
10545}
10546
10547template <typename Derived>
10549 OMPTargetParallelForSimdDirective *D) {
10550 DeclarationNameInfo DirName;
10551 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10552 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10553 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10554 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10555 return Res;
10556}
10557
10558template <typename Derived>
10560 OMPTargetSimdDirective *D) {
10561 DeclarationNameInfo DirName;
10562 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10563 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10564 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10565 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10566 return Res;
10567}
10568
10569template <typename Derived>
10571 OMPTeamsDistributeDirective *D) {
10572 DeclarationNameInfo DirName;
10573 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10574 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10575 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10576 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10577 return Res;
10578}
10579
10580template <typename Derived>
10582 OMPTeamsDistributeSimdDirective *D) {
10583 DeclarationNameInfo DirName;
10584 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10585 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10586 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10587 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10588 return Res;
10589}
10590
10591template <typename Derived>
10593 OMPTeamsDistributeParallelForSimdDirective *D) {
10594 DeclarationNameInfo DirName;
10595 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10596 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10597 D->getBeginLoc());
10598 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10599 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10600 return Res;
10601}
10602
10603template <typename Derived>
10605 OMPTeamsDistributeParallelForDirective *D) {
10606 DeclarationNameInfo DirName;
10607 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10608 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10609 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10610 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10611 return Res;
10612}
10613
10614template <typename Derived>
10616 OMPTargetTeamsDirective *D) {
10617 DeclarationNameInfo DirName;
10618 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10619 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10620 auto Res = getDerived().TransformOMPExecutableDirective(D);
10621 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10622 return Res;
10623}
10624
10625template <typename Derived>
10627 OMPTargetTeamsDistributeDirective *D) {
10628 DeclarationNameInfo DirName;
10629 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10630 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10631 auto Res = getDerived().TransformOMPExecutableDirective(D);
10632 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10633 return Res;
10634}
10635
10636template <typename Derived>
10639 OMPTargetTeamsDistributeParallelForDirective *D) {
10640 DeclarationNameInfo DirName;
10641 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10642 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10643 D->getBeginLoc());
10644 auto Res = getDerived().TransformOMPExecutableDirective(D);
10645 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10646 return Res;
10647}
10648
10649template <typename Derived>
10652 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10653 DeclarationNameInfo DirName;
10654 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10655 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10656 D->getBeginLoc());
10657 auto Res = getDerived().TransformOMPExecutableDirective(D);
10658 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10659 return Res;
10660}
10661
10662template <typename Derived>
10665 OMPTargetTeamsDistributeSimdDirective *D) {
10666 DeclarationNameInfo DirName;
10667 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10668 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10669 auto Res = getDerived().TransformOMPExecutableDirective(D);
10670 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10671 return Res;
10672}
10673
10674template <typename Derived>
10677 DeclarationNameInfo DirName;
10678 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10679 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10680 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10681 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10682 return Res;
10683}
10684
10685template <typename Derived>
10688 DeclarationNameInfo DirName;
10689 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10690 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10691 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10692 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10693 return Res;
10694}
10695
10696template <typename Derived>
10699 DeclarationNameInfo DirName;
10700 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10701 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10702 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10703 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10704 return Res;
10705}
10706
10707template <typename Derived>
10709 OMPGenericLoopDirective *D) {
10710 DeclarationNameInfo DirName;
10711 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10712 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10713 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10714 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10715 return Res;
10716}
10717
10718template <typename Derived>
10720 OMPTeamsGenericLoopDirective *D) {
10721 DeclarationNameInfo DirName;
10722 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10723 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10724 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10725 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10726 return Res;
10727}
10728
10729template <typename Derived>
10731 OMPTargetTeamsGenericLoopDirective *D) {
10732 DeclarationNameInfo DirName;
10733 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10734 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10735 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10736 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10737 return Res;
10738}
10739
10740template <typename Derived>
10742 OMPParallelGenericLoopDirective *D) {
10743 DeclarationNameInfo DirName;
10744 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10745 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10746 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10747 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10748 return Res;
10749}
10750
10751template <typename Derived>
10754 OMPTargetParallelGenericLoopDirective *D) {
10755 DeclarationNameInfo DirName;
10756 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10757 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
10758 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10759 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10760 return Res;
10761}
10762
10763//===----------------------------------------------------------------------===//
10764// OpenMP clause transformation
10765//===----------------------------------------------------------------------===//
10766template <typename Derived>
10768 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10769 if (Cond.isInvalid())
10770 return nullptr;
10771 return getDerived().RebuildOMPIfClause(
10772 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
10773 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
10774}
10775
10776template <typename Derived>
10778 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
10779 if (Cond.isInvalid())
10780 return nullptr;
10781 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
10782 C->getLParenLoc(), C->getEndLoc());
10783}
10784
10785template <typename Derived>
10786OMPClause *
10788 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
10789 if (NumThreads.isInvalid())
10790 return nullptr;
10791 return getDerived().RebuildOMPNumThreadsClause(
10792 C->getModifier(), NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(),
10793 C->getModifierLoc(), C->getEndLoc());
10794}
10795
10796template <typename Derived>
10797OMPClause *
10799 ExprResult E = getDerived().TransformExpr(C->getSafelen());
10800 if (E.isInvalid())
10801 return nullptr;
10802 return getDerived().RebuildOMPSafelenClause(
10803 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10804}
10805
10806template <typename Derived>
10807OMPClause *
10809 ExprResult E = getDerived().TransformExpr(C->getAllocator());
10810 if (E.isInvalid())
10811 return nullptr;
10812 return getDerived().RebuildOMPAllocatorClause(
10813 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10814}
10815
10816template <typename Derived>
10817OMPClause *
10819 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
10820 if (E.isInvalid())
10821 return nullptr;
10822 return getDerived().RebuildOMPSimdlenClause(
10823 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10824}
10825
10826template <typename Derived>
10828 SmallVector<Expr *, 4> TransformedSizes;
10829 TransformedSizes.reserve(C->getNumSizes());
10830 bool Changed = false;
10831 for (Expr *E : C->getSizesRefs()) {
10832 if (!E) {
10833 TransformedSizes.push_back(nullptr);
10834 continue;
10835 }
10836
10837 ExprResult T = getDerived().TransformExpr(E);
10838 if (T.isInvalid())
10839 return nullptr;
10840 if (E != T.get())
10841 Changed = true;
10842 TransformedSizes.push_back(T.get());
10843 }
10844
10845 if (!Changed && !getDerived().AlwaysRebuild())
10846 return C;
10847 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
10848 C->getLParenLoc(), C->getEndLoc());
10849}
10850
10851template <typename Derived>
10852OMPClause *
10854 SmallVector<Expr *, 4> TransformedCounts;
10855 TransformedCounts.reserve(C->getNumCounts());
10856 for (Expr *E : C->getCountsRefs()) {
10857 if (!E) {
10858 TransformedCounts.push_back(nullptr);
10859 continue;
10860 }
10861
10862 ExprResult T = getDerived().TransformExpr(E);
10863 if (T.isInvalid())
10864 return nullptr;
10865 TransformedCounts.push_back(T.get());
10866 }
10867
10868 return RebuildOMPCountsClause(TransformedCounts, C->getBeginLoc(),
10869 C->getLParenLoc(), C->getEndLoc(),
10870 C->getOmpFillIndex(), C->getOmpFillLoc());
10871}
10872
10873template <typename Derived>
10874OMPClause *
10876 SmallVector<Expr *> TransformedArgs;
10877 TransformedArgs.reserve(C->getNumLoops());
10878 bool Changed = false;
10879 for (Expr *E : C->getArgsRefs()) {
10880 if (!E) {
10881 TransformedArgs.push_back(nullptr);
10882 continue;
10883 }
10884
10885 ExprResult T = getDerived().TransformExpr(E);
10886 if (T.isInvalid())
10887 return nullptr;
10888 if (E != T.get())
10889 Changed = true;
10890 TransformedArgs.push_back(T.get());
10891 }
10892
10893 if (!Changed && !getDerived().AlwaysRebuild())
10894 return C;
10895 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
10896 C->getLParenLoc(), C->getEndLoc());
10897}
10898
10899template <typename Derived>
10901 if (!getDerived().AlwaysRebuild())
10902 return C;
10903 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
10904}
10905
10906template <typename Derived>
10907OMPClause *
10909 ExprResult T = getDerived().TransformExpr(C->getFactor());
10910 if (T.isInvalid())
10911 return nullptr;
10912 Expr *Factor = T.get();
10913 bool Changed = Factor != C->getFactor();
10914
10915 if (!Changed && !getDerived().AlwaysRebuild())
10916 return C;
10917 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
10918 C->getEndLoc());
10919}
10920
10921template <typename Derived>
10922OMPClause *
10924 ExprResult F = getDerived().TransformExpr(C->getFirst());
10925 if (F.isInvalid())
10926 return nullptr;
10927
10928 ExprResult Cn = getDerived().TransformExpr(C->getCount());
10929 if (Cn.isInvalid())
10930 return nullptr;
10931
10932 Expr *First = F.get();
10933 Expr *Count = Cn.get();
10934
10935 bool Changed = (First != C->getFirst()) || (Count != C->getCount());
10936
10937 // If no changes and AlwaysRebuild() is false, return the original clause
10938 if (!Changed && !getDerived().AlwaysRebuild())
10939 return C;
10940
10941 return RebuildOMPLoopRangeClause(First, Count, C->getBeginLoc(),
10942 C->getLParenLoc(), C->getFirstLoc(),
10943 C->getCountLoc(), C->getEndLoc());
10944}
10945
10946template <typename Derived>
10947OMPClause *
10949 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
10950 if (E.isInvalid())
10951 return nullptr;
10952 return getDerived().RebuildOMPCollapseClause(
10953 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
10954}
10955
10956template <typename Derived>
10957OMPClause *
10959 return getDerived().RebuildOMPDefaultClause(
10960 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(),
10961 C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(),
10962 C->getEndLoc());
10963}
10964
10965template <typename Derived>
10966OMPClause *
10968 // No need to rebuild this clause, no template-dependent parameters.
10969 return C;
10970}
10971
10972template <typename Derived>
10973OMPClause *
10975 Expr *Impex = C->getImpexType();
10976 ExprResult TransformedImpex = getDerived().TransformExpr(Impex);
10977
10978 if (TransformedImpex.isInvalid())
10979 return nullptr;
10980
10981 return getDerived().RebuildOMPTransparentClause(
10982 TransformedImpex.get(), C->getBeginLoc(), C->getLParenLoc(),
10983 C->getEndLoc());
10984}
10985
10986template <typename Derived>
10987OMPClause *
10989 return getDerived().RebuildOMPProcBindClause(
10990 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
10991 C->getLParenLoc(), C->getEndLoc());
10992}
10993
10994template <typename Derived>
10995OMPClause *
10997 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
10998 if (E.isInvalid())
10999 return nullptr;
11000 return getDerived().RebuildOMPScheduleClause(
11001 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
11002 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11003 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
11004 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11005}
11006
11007template <typename Derived>
11008OMPClause *
11010 ExprResult E;
11011 if (auto *Num = C->getNumForLoops()) {
11012 E = getDerived().TransformExpr(Num);
11013 if (E.isInvalid())
11014 return nullptr;
11015 }
11016 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
11017 C->getLParenLoc(), E.get());
11018}
11019
11020template <typename Derived>
11021OMPClause *
11023 ExprResult E;
11024 if (Expr *Evt = C->getEventHandler()) {
11025 E = getDerived().TransformExpr(Evt);
11026 if (E.isInvalid())
11027 return nullptr;
11028 }
11029 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
11030 C->getLParenLoc(), C->getEndLoc());
11031}
11032
11033template <typename Derived>
11034OMPClause *
11037 if (auto *Condition = C->getCondition()) {
11038 Cond = getDerived().TransformExpr(Condition);
11039 if (Cond.isInvalid())
11040 return nullptr;
11041 }
11042 return getDerived().RebuildOMPNowaitClause(Cond.get(), C->getBeginLoc(),
11043 C->getLParenLoc(), C->getEndLoc());
11044}
11045
11046template <typename Derived>
11047OMPClause *
11049 // No need to rebuild this clause, no template-dependent parameters.
11050 return C;
11051}
11052
11053template <typename Derived>
11054OMPClause *
11056 // No need to rebuild this clause, no template-dependent parameters.
11057 return C;
11058}
11059
11060template <typename Derived>
11062 // No need to rebuild this clause, no template-dependent parameters.
11063 return C;
11064}
11065
11066template <typename Derived>
11068 // No need to rebuild this clause, no template-dependent parameters.
11069 return C;
11070}
11071
11072template <typename Derived>
11073OMPClause *
11075 // No need to rebuild this clause, no template-dependent parameters.
11076 return C;
11077}
11078
11079template <typename Derived>
11080OMPClause *
11082 // No need to rebuild this clause, no template-dependent parameters.
11083 return C;
11084}
11085
11086template <typename Derived>
11087OMPClause *
11089 // No need to rebuild this clause, no template-dependent parameters.
11090 return C;
11091}
11092
11093template <typename Derived>
11095 // No need to rebuild this clause, no template-dependent parameters.
11096 return C;
11097}
11098
11099template <typename Derived>
11100OMPClause *
11102 return C;
11103}
11104
11105template <typename Derived>
11107 ExprResult E = getDerived().TransformExpr(C->getExpr());
11108 if (E.isInvalid())
11109 return nullptr;
11110 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
11111 C->getLParenLoc(), C->getEndLoc());
11112}
11113
11114template <typename Derived>
11115OMPClause *
11117 return C;
11118}
11119
11120template <typename Derived>
11121OMPClause *
11123 return C;
11124}
11125template <typename Derived>
11127 OMPNoOpenMPRoutinesClause *C) {
11128 return C;
11129}
11130template <typename Derived>
11132 OMPNoOpenMPConstructsClause *C) {
11133 return C;
11134}
11135template <typename Derived>
11137 OMPNoParallelismClause *C) {
11138 return C;
11139}
11140
11141template <typename Derived>
11142OMPClause *
11144 // No need to rebuild this clause, no template-dependent parameters.
11145 return C;
11146}
11147
11148template <typename Derived>
11149OMPClause *
11151 // No need to rebuild this clause, no template-dependent parameters.
11152 return C;
11153}
11154
11155template <typename Derived>
11156OMPClause *
11158 // No need to rebuild this clause, no template-dependent parameters.
11159 return C;
11160}
11161
11162template <typename Derived>
11163OMPClause *
11165 // No need to rebuild this clause, no template-dependent parameters.
11166 return C;
11167}
11168
11169template <typename Derived>
11170OMPClause *
11172 // No need to rebuild this clause, no template-dependent parameters.
11173 return C;
11174}
11175
11176template <typename Derived>
11178 // No need to rebuild this clause, no template-dependent parameters.
11179 return C;
11180}
11181
11182template <typename Derived>
11183OMPClause *
11185 // No need to rebuild this clause, no template-dependent parameters.
11186 return C;
11187}
11188
11189template <typename Derived>
11191 // No need to rebuild this clause, no template-dependent parameters.
11192 return C;
11193}
11194
11195template <typename Derived>
11196OMPClause *
11198 // No need to rebuild this clause, no template-dependent parameters.
11199 return C;
11200}
11201
11202template <typename Derived>
11204 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
11205 if (IVR.isInvalid())
11206 return nullptr;
11207
11208 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
11209 for (OMPInitClause::PrefView P : C->prefs()) {
11210 Expr *NewFr = nullptr;
11211 if (P.Fr) {
11212 ExprResult ER = getDerived().TransformExpr(P.Fr);
11213 if (ER.isInvalid())
11214 return nullptr;
11215 NewFr = ER.get();
11216 }
11217 SmallVector<Expr *, 2> NewAttrs;
11218 NewAttrs.reserve(P.Attrs.size());
11219 for (Expr *A : P.Attrs) {
11220 ExprResult ER = getDerived().TransformExpr(A);
11221 if (ER.isInvalid())
11222 return nullptr;
11223 NewAttrs.push_back(ER.get());
11224 }
11225 InteropInfo.Prefs.emplace_back(NewFr, std::move(NewAttrs));
11226 }
11227 InteropInfo.HasPreferAttrs = C->hasPreferAttrs();
11228 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
11229 C->getBeginLoc(), C->getLParenLoc(),
11230 C->getVarLoc(), C->getEndLoc());
11231}
11232
11233template <typename Derived>
11235 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
11236 if (ER.isInvalid())
11237 return nullptr;
11238 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
11239 C->getLParenLoc(), C->getVarLoc(),
11240 C->getEndLoc());
11241}
11242
11243template <typename Derived>
11244OMPClause *
11246 ExprResult ER;
11247 if (Expr *IV = C->getInteropVar()) {
11248 ER = getDerived().TransformExpr(IV);
11249 if (ER.isInvalid())
11250 return nullptr;
11251 }
11252 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
11253 C->getLParenLoc(), C->getVarLoc(),
11254 C->getEndLoc());
11255}
11256
11257template <typename Derived>
11258OMPClause *
11260 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11261 if (Cond.isInvalid())
11262 return nullptr;
11263 return getDerived().RebuildOMPNovariantsClause(
11264 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11265}
11266
11267template <typename Derived>
11268OMPClause *
11270 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11271 if (Cond.isInvalid())
11272 return nullptr;
11273 return getDerived().RebuildOMPNocontextClause(
11274 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11275}
11276
11277template <typename Derived>
11278OMPClause *
11280 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
11281 if (ThreadID.isInvalid())
11282 return nullptr;
11283 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
11284 C->getLParenLoc(), C->getEndLoc());
11285}
11286
11287template <typename Derived>
11289 ExprResult E = getDerived().TransformExpr(C->getAlignment());
11290 if (E.isInvalid())
11291 return nullptr;
11292 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
11293 C->getLParenLoc(), C->getEndLoc());
11294}
11295
11296template <typename Derived>
11298 OMPUnifiedAddressClause *C) {
11299 llvm_unreachable("unified_address clause cannot appear in dependent context");
11300}
11301
11302template <typename Derived>
11304 OMPUnifiedSharedMemoryClause *C) {
11305 llvm_unreachable(
11306 "unified_shared_memory clause cannot appear in dependent context");
11307}
11308
11309template <typename Derived>
11311 OMPReverseOffloadClause *C) {
11312 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
11313}
11314
11315template <typename Derived>
11317 OMPDynamicAllocatorsClause *C) {
11318 llvm_unreachable(
11319 "dynamic_allocators clause cannot appear in dependent context");
11320}
11321
11322template <typename Derived>
11324 OMPAtomicDefaultMemOrderClause *C) {
11325 llvm_unreachable(
11326 "atomic_default_mem_order clause cannot appear in dependent context");
11327}
11328
11329template <typename Derived>
11330OMPClause *
11332 llvm_unreachable("self_maps clause cannot appear in dependent context");
11333}
11334
11335template <typename Derived>
11337 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
11338 C->getBeginLoc(), C->getLParenLoc(),
11339 C->getEndLoc());
11340}
11341
11342template <typename Derived>
11343OMPClause *
11345 return getDerived().RebuildOMPSeverityClause(
11346 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
11347 C->getLParenLoc(), C->getEndLoc());
11348}
11349
11350template <typename Derived>
11351OMPClause *
11353 ExprResult E = getDerived().TransformExpr(C->getMessageString());
11354 if (E.isInvalid())
11355 return nullptr;
11356 return getDerived().RebuildOMPMessageClause(
11357 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11358}
11359
11360template <typename Derived>
11361OMPClause *
11364 Vars.reserve(C->varlist_size());
11365 for (auto *VE : C->varlist()) {
11366 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11367 if (EVar.isInvalid())
11368 return nullptr;
11369 Vars.push_back(EVar.get());
11370 }
11371 return getDerived().RebuildOMPPrivateClause(
11372 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11373}
11374
11375template <typename Derived>
11377 OMPFirstprivateClause *C) {
11379 Vars.reserve(C->varlist_size());
11380 for (auto *VE : C->varlist()) {
11381 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11382 if (EVar.isInvalid())
11383 return nullptr;
11384 Vars.push_back(EVar.get());
11385 }
11386 return getDerived().RebuildOMPFirstprivateClause(
11387 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11388}
11389
11390template <typename Derived>
11391OMPClause *
11394 Vars.reserve(C->varlist_size());
11395 for (auto *VE : C->varlist()) {
11396 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11397 if (EVar.isInvalid())
11398 return nullptr;
11399 Vars.push_back(EVar.get());
11400 }
11401 return getDerived().RebuildOMPLastprivateClause(
11402 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
11403 C->getLParenLoc(), C->getEndLoc());
11404}
11405
11406template <typename Derived>
11407OMPClause *
11410 Vars.reserve(C->varlist_size());
11411 for (auto *VE : C->varlist()) {
11412 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11413 if (EVar.isInvalid())
11414 return nullptr;
11415 Vars.push_back(EVar.get());
11416 }
11417 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
11418 C->getLParenLoc(), C->getEndLoc());
11419}
11420
11421template <typename Derived>
11422OMPClause *
11425 Vars.reserve(C->varlist_size());
11426 for (auto *VE : C->varlist()) {
11427 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11428 if (EVar.isInvalid())
11429 return nullptr;
11430 Vars.push_back(EVar.get());
11431 }
11432 CXXScopeSpec ReductionIdScopeSpec;
11433 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11434
11435 DeclarationNameInfo NameInfo = C->getNameInfo();
11436 if (NameInfo.getName()) {
11437 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11438 if (!NameInfo.getName())
11439 return nullptr;
11440 }
11441 // Build a list of all UDR decls with the same names ranged by the Scopes.
11442 // The Scope boundary is a duplication of the previous decl.
11443 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11444 for (auto *E : C->reduction_ops()) {
11445 // Transform all the decls.
11446 if (E) {
11447 auto *ULE = cast<UnresolvedLookupExpr>(E);
11448 UnresolvedSet<8> Decls;
11449 for (auto *D : ULE->decls()) {
11450 NamedDecl *InstD =
11451 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11452 Decls.addDecl(InstD, InstD->getAccess());
11453 }
11454 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11455 SemaRef.Context, /*NamingClass=*/nullptr,
11456 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11457 /*ADL=*/true, Decls.begin(), Decls.end(),
11458 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11459 } else
11460 UnresolvedReductions.push_back(nullptr);
11461 }
11462 return getDerived().RebuildOMPReductionClause(
11463 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
11464 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
11465 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11466}
11467
11468template <typename Derived>
11470 OMPTaskReductionClause *C) {
11472 Vars.reserve(C->varlist_size());
11473 for (auto *VE : C->varlist()) {
11474 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11475 if (EVar.isInvalid())
11476 return nullptr;
11477 Vars.push_back(EVar.get());
11478 }
11479 CXXScopeSpec ReductionIdScopeSpec;
11480 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11481
11482 DeclarationNameInfo NameInfo = C->getNameInfo();
11483 if (NameInfo.getName()) {
11484 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11485 if (!NameInfo.getName())
11486 return nullptr;
11487 }
11488 // Build a list of all UDR decls with the same names ranged by the Scopes.
11489 // The Scope boundary is a duplication of the previous decl.
11490 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11491 for (auto *E : C->reduction_ops()) {
11492 // Transform all the decls.
11493 if (E) {
11494 auto *ULE = cast<UnresolvedLookupExpr>(E);
11495 UnresolvedSet<8> Decls;
11496 for (auto *D : ULE->decls()) {
11497 NamedDecl *InstD =
11498 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11499 Decls.addDecl(InstD, InstD->getAccess());
11500 }
11501 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11502 SemaRef.Context, /*NamingClass=*/nullptr,
11503 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11504 /*ADL=*/true, Decls.begin(), Decls.end(),
11505 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11506 } else
11507 UnresolvedReductions.push_back(nullptr);
11508 }
11509 return getDerived().RebuildOMPTaskReductionClause(
11510 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11511 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11512}
11513
11514template <typename Derived>
11515OMPClause *
11518 Vars.reserve(C->varlist_size());
11519 for (auto *VE : C->varlist()) {
11520 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11521 if (EVar.isInvalid())
11522 return nullptr;
11523 Vars.push_back(EVar.get());
11524 }
11525 CXXScopeSpec ReductionIdScopeSpec;
11526 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11527
11528 DeclarationNameInfo NameInfo = C->getNameInfo();
11529 if (NameInfo.getName()) {
11530 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11531 if (!NameInfo.getName())
11532 return nullptr;
11533 }
11534 // Build a list of all UDR decls with the same names ranged by the Scopes.
11535 // The Scope boundary is a duplication of the previous decl.
11536 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11537 for (auto *E : C->reduction_ops()) {
11538 // Transform all the decls.
11539 if (E) {
11540 auto *ULE = cast<UnresolvedLookupExpr>(E);
11541 UnresolvedSet<8> Decls;
11542 for (auto *D : ULE->decls()) {
11543 NamedDecl *InstD =
11544 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11545 Decls.addDecl(InstD, InstD->getAccess());
11546 }
11547 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11548 SemaRef.Context, /*NamingClass=*/nullptr,
11549 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11550 /*ADL=*/true, Decls.begin(), Decls.end(),
11551 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11552 } else
11553 UnresolvedReductions.push_back(nullptr);
11554 }
11555 return getDerived().RebuildOMPInReductionClause(
11556 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11557 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11558}
11559
11560template <typename Derived>
11561OMPClause *
11564 Vars.reserve(C->varlist_size());
11565 for (auto *VE : C->varlist()) {
11566 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11567 if (EVar.isInvalid())
11568 return nullptr;
11569 Vars.push_back(EVar.get());
11570 }
11571 ExprResult Step = getDerived().TransformExpr(C->getStep());
11572 if (Step.isInvalid())
11573 return nullptr;
11574 return getDerived().RebuildOMPLinearClause(
11575 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11576 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11577 C->getEndLoc());
11578}
11579
11580template <typename Derived>
11581OMPClause *
11584 Vars.reserve(C->varlist_size());
11585 for (auto *VE : C->varlist()) {
11586 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11587 if (EVar.isInvalid())
11588 return nullptr;
11589 Vars.push_back(EVar.get());
11590 }
11591 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11592 if (Alignment.isInvalid())
11593 return nullptr;
11594 return getDerived().RebuildOMPAlignedClause(
11595 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11596 C->getColonLoc(), C->getEndLoc());
11597}
11598
11599template <typename Derived>
11600OMPClause *
11603 Vars.reserve(C->varlist_size());
11604 for (auto *VE : C->varlist()) {
11605 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11606 if (EVar.isInvalid())
11607 return nullptr;
11608 Vars.push_back(EVar.get());
11609 }
11610 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11611 C->getLParenLoc(), C->getEndLoc());
11612}
11613
11614template <typename Derived>
11615OMPClause *
11618 Vars.reserve(C->varlist_size());
11619 for (auto *VE : C->varlist()) {
11620 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11621 if (EVar.isInvalid())
11622 return nullptr;
11623 Vars.push_back(EVar.get());
11624 }
11625 return getDerived().RebuildOMPCopyprivateClause(
11626 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11627}
11628
11629template <typename Derived>
11632 Vars.reserve(C->varlist_size());
11633 for (auto *VE : C->varlist()) {
11634 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11635 if (EVar.isInvalid())
11636 return nullptr;
11637 Vars.push_back(EVar.get());
11638 }
11639 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11640 C->getLParenLoc(), C->getEndLoc());
11641}
11642
11643template <typename Derived>
11644OMPClause *
11646 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11647 if (E.isInvalid())
11648 return nullptr;
11649 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11650 C->getLParenLoc(), C->getEndLoc());
11651}
11652
11653template <typename Derived>
11654OMPClause *
11657 Expr *DepModifier = C->getModifier();
11658 if (DepModifier) {
11659 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11660 if (DepModRes.isInvalid())
11661 return nullptr;
11662 DepModifier = DepModRes.get();
11663 }
11664 Vars.reserve(C->varlist_size());
11665 for (auto *VE : C->varlist()) {
11666 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11667 if (EVar.isInvalid())
11668 return nullptr;
11669 Vars.push_back(EVar.get());
11670 }
11671 return getDerived().RebuildOMPDependClause(
11672 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11673 C->getOmpAllMemoryLoc()},
11674 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11675}
11676
11677template <typename Derived>
11678OMPClause *
11680 ExprResult E = getDerived().TransformExpr(C->getDevice());
11681 if (E.isInvalid())
11682 return nullptr;
11683 return getDerived().RebuildOMPDeviceClause(
11684 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11685 C->getModifierLoc(), C->getEndLoc());
11686}
11687
11688template <typename Derived, class T>
11691 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11692 DeclarationNameInfo &MapperIdInfo,
11693 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11694 // Transform expressions in the list.
11695 Vars.reserve(C->varlist_size());
11696 for (auto *VE : C->varlist()) {
11697 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11698 if (EVar.isInvalid())
11699 return true;
11700 Vars.push_back(EVar.get());
11701 }
11702 // Transform mapper scope specifier and identifier.
11703 NestedNameSpecifierLoc QualifierLoc;
11704 if (C->getMapperQualifierLoc()) {
11705 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11706 C->getMapperQualifierLoc());
11707 if (!QualifierLoc)
11708 return true;
11709 }
11710 MapperIdScopeSpec.Adopt(QualifierLoc);
11711 MapperIdInfo = C->getMapperIdInfo();
11712 if (MapperIdInfo.getName()) {
11713 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
11714 if (!MapperIdInfo.getName())
11715 return true;
11716 }
11717 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
11718 // the previous user-defined mapper lookup in dependent environment.
11719 for (auto *E : C->mapperlists()) {
11720 // Transform all the decls.
11721 if (E) {
11722 auto *ULE = cast<UnresolvedLookupExpr>(E);
11723 UnresolvedSet<8> Decls;
11724 for (auto *D : ULE->decls()) {
11725 NamedDecl *InstD =
11726 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
11727 Decls.addDecl(InstD, InstD->getAccess());
11728 }
11729 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
11730 TT.getSema().Context, /*NamingClass=*/nullptr,
11731 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
11732 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
11733 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11734 } else {
11735 UnresolvedMappers.push_back(nullptr);
11736 }
11737 }
11738 return false;
11739}
11740
11741template <typename Derived>
11742OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
11743 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11745 Expr *IteratorModifier = C->getIteratorModifier();
11746 if (IteratorModifier) {
11747 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11748 if (MapModRes.isInvalid())
11749 return nullptr;
11750 IteratorModifier = MapModRes.get();
11751 }
11752 CXXScopeSpec MapperIdScopeSpec;
11753 DeclarationNameInfo MapperIdInfo;
11754 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11756 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11757 return nullptr;
11758 return getDerived().RebuildOMPMapClause(
11759 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
11760 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
11761 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
11762}
11763
11764template <typename Derived>
11765OMPClause *
11767 Expr *Allocator = C->getAllocator();
11768 if (Allocator) {
11769 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
11770 if (AllocatorRes.isInvalid())
11771 return nullptr;
11772 Allocator = AllocatorRes.get();
11773 }
11774 Expr *Alignment = C->getAlignment();
11775 if (Alignment) {
11776 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
11777 if (AlignmentRes.isInvalid())
11778 return nullptr;
11779 Alignment = AlignmentRes.get();
11780 }
11782 Vars.reserve(C->varlist_size());
11783 for (auto *VE : C->varlist()) {
11784 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11785 if (EVar.isInvalid())
11786 return nullptr;
11787 Vars.push_back(EVar.get());
11788 }
11789 return getDerived().RebuildOMPAllocateClause(
11790 Allocator, Alignment, C->getFirstAllocateModifier(),
11791 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
11792 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
11793 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
11794}
11795
11796template <typename Derived>
11797OMPClause *
11800 Vars.reserve(C->varlist_size());
11801 for (auto *VE : C->varlist()) {
11802 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11803 if (EVar.isInvalid())
11804 return nullptr;
11805 Vars.push_back(EVar.get());
11806 }
11807 Expr *ModifierExpr = C->getModifierExpr();
11808 if (ModifierExpr) {
11809 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(ModifierExpr));
11810 if (EVar.isInvalid())
11811 return nullptr;
11812 ModifierExpr = EVar.get();
11813 }
11814 return getDerived().RebuildOMPNumTeamsClause(
11815 Vars, C->getModifier(), ModifierExpr, C->getModifierLoc(),
11816 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11817}
11818
11819template <typename Derived>
11820OMPClause *
11823 Vars.reserve(C->varlist_size());
11824 for (auto *VE : C->varlist()) {
11825 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11826 if (EVar.isInvalid())
11827 return nullptr;
11828 Vars.push_back(EVar.get());
11829 }
11830 return getDerived().RebuildOMPThreadLimitClause(
11831 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11832}
11833
11834template <typename Derived>
11835OMPClause *
11837 ExprResult E = getDerived().TransformExpr(C->getPriority());
11838 if (E.isInvalid())
11839 return nullptr;
11840 return getDerived().RebuildOMPPriorityClause(
11841 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11842}
11843
11844template <typename Derived>
11845OMPClause *
11847 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
11848 if (E.isInvalid())
11849 return nullptr;
11850 return getDerived().RebuildOMPGrainsizeClause(
11851 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11852 C->getModifierLoc(), C->getEndLoc());
11853}
11854
11855template <typename Derived>
11856OMPClause *
11858 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
11859 if (E.isInvalid())
11860 return nullptr;
11861 return getDerived().RebuildOMPNumTasksClause(
11862 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11863 C->getModifierLoc(), C->getEndLoc());
11864}
11865
11866template <typename Derived>
11868 ExprResult E = getDerived().TransformExpr(C->getHint());
11869 if (E.isInvalid())
11870 return nullptr;
11871 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
11872 C->getLParenLoc(), C->getEndLoc());
11873}
11874
11875template <typename Derived>
11877 OMPDistScheduleClause *C) {
11878 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11879 if (E.isInvalid())
11880 return nullptr;
11881 return getDerived().RebuildOMPDistScheduleClause(
11882 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11883 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11884}
11885
11886template <typename Derived>
11887OMPClause *
11889 // Rebuild Defaultmap Clause since we need to invoke the checking of
11890 // defaultmap(none:variable-category) after template initialization.
11891 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
11892 C->getDefaultmapKind(),
11893 C->getBeginLoc(),
11894 C->getLParenLoc(),
11895 C->getDefaultmapModifierLoc(),
11896 C->getDefaultmapKindLoc(),
11897 C->getEndLoc());
11898}
11899
11900template <typename Derived>
11902 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11904 Expr *IteratorModifier = C->getIteratorModifier();
11905 if (IteratorModifier) {
11906 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11907 if (MapModRes.isInvalid())
11908 return nullptr;
11909 IteratorModifier = MapModRes.get();
11910 }
11911 CXXScopeSpec MapperIdScopeSpec;
11912 DeclarationNameInfo MapperIdInfo;
11913 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11915 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11916 return nullptr;
11917 return getDerived().RebuildOMPToClause(
11918 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
11919 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
11920 UnresolvedMappers);
11921}
11922
11923template <typename Derived>
11925 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11927 Expr *IteratorModifier = C->getIteratorModifier();
11928 if (IteratorModifier) {
11929 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
11930 if (MapModRes.isInvalid())
11931 return nullptr;
11932 IteratorModifier = MapModRes.get();
11933 }
11934 CXXScopeSpec MapperIdScopeSpec;
11935 DeclarationNameInfo MapperIdInfo;
11936 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
11938 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
11939 return nullptr;
11940 return getDerived().RebuildOMPFromClause(
11941 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
11942 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
11943 UnresolvedMappers);
11944}
11945
11946template <typename Derived>
11948 OMPUseDevicePtrClause *C) {
11950 Vars.reserve(C->varlist_size());
11951 for (auto *VE : C->varlist()) {
11952 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11953 if (EVar.isInvalid())
11954 return nullptr;
11955 Vars.push_back(EVar.get());
11956 }
11957 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11958 return getDerived().RebuildOMPUseDevicePtrClause(
11959 Vars, Locs, C->getFallbackModifier(), C->getFallbackModifierLoc());
11960}
11961
11962template <typename Derived>
11964 OMPUseDeviceAddrClause *C) {
11966 Vars.reserve(C->varlist_size());
11967 for (auto *VE : C->varlist()) {
11968 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11969 if (EVar.isInvalid())
11970 return nullptr;
11971 Vars.push_back(EVar.get());
11972 }
11973 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11974 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
11975}
11976
11977template <typename Derived>
11978OMPClause *
11981 Vars.reserve(C->varlist_size());
11982 for (auto *VE : C->varlist()) {
11983 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11984 if (EVar.isInvalid())
11985 return nullptr;
11986 Vars.push_back(EVar.get());
11987 }
11988 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11989 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
11990}
11991
11992template <typename Derived>
11994 OMPHasDeviceAddrClause *C) {
11996 Vars.reserve(C->varlist_size());
11997 for (auto *VE : C->varlist()) {
11998 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11999 if (EVar.isInvalid())
12000 return nullptr;
12001 Vars.push_back(EVar.get());
12002 }
12003 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12004 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
12005}
12006
12007template <typename Derived>
12008OMPClause *
12011 Vars.reserve(C->varlist_size());
12012 for (auto *VE : C->varlist()) {
12013 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12014 if (EVar.isInvalid())
12015 return nullptr;
12016 Vars.push_back(EVar.get());
12017 }
12018 return getDerived().RebuildOMPNontemporalClause(
12019 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12020}
12021
12022template <typename Derived>
12023OMPClause *
12026 Vars.reserve(C->varlist_size());
12027 for (auto *VE : C->varlist()) {
12028 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12029 if (EVar.isInvalid())
12030 return nullptr;
12031 Vars.push_back(EVar.get());
12032 }
12033 return getDerived().RebuildOMPInclusiveClause(
12034 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12035}
12036
12037template <typename Derived>
12038OMPClause *
12041 Vars.reserve(C->varlist_size());
12042 for (auto *VE : C->varlist()) {
12043 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12044 if (EVar.isInvalid())
12045 return nullptr;
12046 Vars.push_back(EVar.get());
12047 }
12048 return getDerived().RebuildOMPExclusiveClause(
12049 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12050}
12051
12052template <typename Derived>
12054 OMPUsesAllocatorsClause *C) {
12056 Data.reserve(C->getNumberOfAllocators());
12057 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
12058 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
12059 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
12060 if (Allocator.isInvalid())
12061 continue;
12062 ExprResult AllocatorTraits;
12063 if (Expr *AT = D.AllocatorTraits) {
12064 AllocatorTraits = getDerived().TransformExpr(AT);
12065 if (AllocatorTraits.isInvalid())
12066 continue;
12067 }
12068 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
12069 NewD.Allocator = Allocator.get();
12070 NewD.AllocatorTraits = AllocatorTraits.get();
12071 NewD.LParenLoc = D.LParenLoc;
12072 NewD.RParenLoc = D.RParenLoc;
12073 }
12074 return getDerived().RebuildOMPUsesAllocatorsClause(
12075 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12076}
12077
12078template <typename Derived>
12079OMPClause *
12081 SmallVector<Expr *, 4> Locators;
12082 Locators.reserve(C->varlist_size());
12083 ExprResult ModifierRes;
12084 if (Expr *Modifier = C->getModifier()) {
12085 ModifierRes = getDerived().TransformExpr(Modifier);
12086 if (ModifierRes.isInvalid())
12087 return nullptr;
12088 }
12089 for (Expr *E : C->varlist()) {
12090 ExprResult Locator = getDerived().TransformExpr(E);
12091 if (Locator.isInvalid())
12092 continue;
12093 Locators.push_back(Locator.get());
12094 }
12095 return getDerived().RebuildOMPAffinityClause(
12096 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
12097 ModifierRes.get(), Locators);
12098}
12099
12100template <typename Derived>
12102 return getDerived().RebuildOMPOrderClause(
12103 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
12104 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
12105}
12106
12107template <typename Derived>
12109 return getDerived().RebuildOMPBindClause(
12110 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
12111 C->getLParenLoc(), C->getEndLoc());
12112}
12113
12114template <typename Derived>
12116 OMPXDynCGroupMemClause *C) {
12117 ExprResult Size = getDerived().TransformExpr(C->getSize());
12118 if (Size.isInvalid())
12119 return nullptr;
12120 return getDerived().RebuildOMPXDynCGroupMemClause(
12121 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12122}
12123
12124template <typename Derived>
12126 OMPDynGroupprivateClause *C) {
12127 ExprResult Size = getDerived().TransformExpr(C->getSize());
12128 if (Size.isInvalid())
12129 return nullptr;
12130 return getDerived().RebuildOMPDynGroupprivateClause(
12131 C->getDynGroupprivateModifier(), C->getDynGroupprivateFallbackModifier(),
12132 Size.get(), C->getBeginLoc(), C->getLParenLoc(),
12133 C->getDynGroupprivateModifierLoc(),
12134 C->getDynGroupprivateFallbackModifierLoc(), C->getEndLoc());
12135}
12136
12137template <typename Derived>
12138OMPClause *
12141 Vars.reserve(C->varlist_size());
12142 for (auto *VE : C->varlist()) {
12143 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12144 if (EVar.isInvalid())
12145 return nullptr;
12146 Vars.push_back(EVar.get());
12147 }
12148 return getDerived().RebuildOMPDoacrossClause(
12149 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
12150 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12151}
12152
12153template <typename Derived>
12154OMPClause *
12157 for (auto *A : C->getAttrs())
12158 NewAttrs.push_back(getDerived().TransformAttr(A));
12159 return getDerived().RebuildOMPXAttributeClause(
12160 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12161}
12162
12163template <typename Derived>
12165 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
12166}
12167
12168//===----------------------------------------------------------------------===//
12169// OpenACC transformation
12170//===----------------------------------------------------------------------===//
12171namespace {
12172template <typename Derived>
12173class OpenACCClauseTransform final
12174 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
12175 TreeTransform<Derived> &Self;
12176 ArrayRef<const OpenACCClause *> ExistingClauses;
12177 SemaOpenACC::OpenACCParsedClause &ParsedClause;
12178 OpenACCClause *NewClause = nullptr;
12179
12180 ExprResult VisitVar(Expr *VarRef) {
12181 ExprResult Res = Self.TransformExpr(VarRef);
12182
12183 if (!Res.isUsable())
12184 return Res;
12185
12186 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12187 ParsedClause.getClauseKind(),
12188 Res.get());
12189
12190 return Res;
12191 }
12192
12193 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
12194 llvm::SmallVector<Expr *> InstantiatedVarList;
12195 for (Expr *CurVar : VarList) {
12196 ExprResult VarRef = VisitVar(CurVar);
12197
12198 if (VarRef.isUsable())
12199 InstantiatedVarList.push_back(VarRef.get());
12200 }
12201
12202 return InstantiatedVarList;
12203 }
12204
12205public:
12206 OpenACCClauseTransform(TreeTransform<Derived> &Self,
12207 ArrayRef<const OpenACCClause *> ExistingClauses,
12208 SemaOpenACC::OpenACCParsedClause &PC)
12209 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
12210
12211 OpenACCClause *CreatedClause() const { return NewClause; }
12212
12213#define VISIT_CLAUSE(CLAUSE_NAME) \
12214 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
12215#include "clang/Basic/OpenACCClauses.def"
12216};
12217
12218template <typename Derived>
12219void OpenACCClauseTransform<Derived>::VisitDefaultClause(
12220 const OpenACCDefaultClause &C) {
12221 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
12222
12223 NewClause = OpenACCDefaultClause::Create(
12224 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
12225 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12226 ParsedClause.getEndLoc());
12227}
12228
12229template <typename Derived>
12230void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
12231 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12232 assert(Cond && "If constructed with invalid Condition");
12233 Sema::ConditionResult Res = Self.TransformCondition(
12234 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
12235
12236 if (Res.isInvalid() || !Res.get().second)
12237 return;
12238
12239 ParsedClause.setConditionDetails(Res.get().second);
12240
12241 NewClause = OpenACCIfClause::Create(
12242 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12243 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12244 ParsedClause.getEndLoc());
12245}
12246
12247template <typename Derived>
12248void OpenACCClauseTransform<Derived>::VisitSelfClause(
12249 const OpenACCSelfClause &C) {
12250
12251 // If this is an 'update' 'self' clause, this is actually a var list instead.
12252 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
12253 llvm::SmallVector<Expr *> InstantiatedVarList;
12254 for (Expr *CurVar : C.getVarList()) {
12255 ExprResult Res = Self.TransformExpr(CurVar);
12256
12257 if (!Res.isUsable())
12258 continue;
12259
12260 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12261 ParsedClause.getClauseKind(),
12262 Res.get());
12263
12264 if (Res.isUsable())
12265 InstantiatedVarList.push_back(Res.get());
12266 }
12267
12268 ParsedClause.setVarListDetails(InstantiatedVarList,
12270
12271 NewClause = OpenACCSelfClause::Create(
12272 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12273 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12274 ParsedClause.getEndLoc());
12275 } else {
12276
12277 if (C.hasConditionExpr()) {
12278 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12280 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
12282
12283 if (Res.isInvalid() || !Res.get().second)
12284 return;
12285
12286 ParsedClause.setConditionDetails(Res.get().second);
12287 }
12288
12289 NewClause = OpenACCSelfClause::Create(
12290 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12291 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12292 ParsedClause.getEndLoc());
12293 }
12294}
12295
12296template <typename Derived>
12297void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
12298 const OpenACCNumGangsClause &C) {
12299 llvm::SmallVector<Expr *> InstantiatedIntExprs;
12300
12301 for (Expr *CurIntExpr : C.getIntExprs()) {
12302 ExprResult Res = Self.TransformExpr(CurIntExpr);
12303
12304 if (!Res.isUsable())
12305 return;
12306
12307 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12308 C.getClauseKind(),
12309 C.getBeginLoc(), Res.get());
12310 if (!Res.isUsable())
12311 return;
12312
12313 InstantiatedIntExprs.push_back(Res.get());
12314 }
12315
12316 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
12318 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12319 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12320 ParsedClause.getEndLoc());
12321}
12322
12323template <typename Derived>
12324void OpenACCClauseTransform<Derived>::VisitPrivateClause(
12325 const OpenACCPrivateClause &C) {
12326 llvm::SmallVector<Expr *> InstantiatedVarList;
12328
12329 for (const auto [RefExpr, InitRecipe] :
12330 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12331 ExprResult VarRef = VisitVar(RefExpr);
12332
12333 if (VarRef.isUsable()) {
12334 InstantiatedVarList.push_back(VarRef.get());
12335
12336 // We only have to create a new one if it is dependent, and Sema won't
12337 // make one of these unless the type is non-dependent.
12338 if (InitRecipe.isSet())
12339 InitRecipes.push_back(InitRecipe);
12340 else
12341 InitRecipes.push_back(
12342 Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get()));
12343 }
12344 }
12345 ParsedClause.setVarListDetails(InstantiatedVarList,
12347
12348 NewClause = OpenACCPrivateClause::Create(
12349 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12350 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12351 ParsedClause.getEndLoc());
12352}
12353
12354template <typename Derived>
12355void OpenACCClauseTransform<Derived>::VisitHostClause(
12356 const OpenACCHostClause &C) {
12357 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12359
12360 NewClause = OpenACCHostClause::Create(
12361 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12362 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12363 ParsedClause.getEndLoc());
12364}
12365
12366template <typename Derived>
12367void OpenACCClauseTransform<Derived>::VisitDeviceClause(
12368 const OpenACCDeviceClause &C) {
12369 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12371
12372 NewClause = OpenACCDeviceClause::Create(
12373 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12374 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12375 ParsedClause.getEndLoc());
12376}
12377
12378template <typename Derived>
12379void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
12381 llvm::SmallVector<Expr *> InstantiatedVarList;
12383
12384 for (const auto [RefExpr, InitRecipe] :
12385 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12386 ExprResult VarRef = VisitVar(RefExpr);
12387
12388 if (VarRef.isUsable()) {
12389 InstantiatedVarList.push_back(VarRef.get());
12390
12391 // We only have to create a new one if it is dependent, and Sema won't
12392 // make one of these unless the type is non-dependent.
12393 if (InitRecipe.isSet())
12394 InitRecipes.push_back(InitRecipe);
12395 else
12396 InitRecipes.push_back(
12397 Self.getSema().OpenACC().CreateFirstPrivateInitRecipe(
12398 VarRef.get()));
12399 }
12400 }
12401 ParsedClause.setVarListDetails(InstantiatedVarList,
12403
12405 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12406 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12407 ParsedClause.getEndLoc());
12408}
12409
12410template <typename Derived>
12411void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
12412 const OpenACCNoCreateClause &C) {
12413 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12415
12417 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12418 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12419 ParsedClause.getEndLoc());
12420}
12421
12422template <typename Derived>
12423void OpenACCClauseTransform<Derived>::VisitPresentClause(
12424 const OpenACCPresentClause &C) {
12425 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12427
12428 NewClause = OpenACCPresentClause::Create(
12429 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12430 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12431 ParsedClause.getEndLoc());
12432}
12433
12434template <typename Derived>
12435void OpenACCClauseTransform<Derived>::VisitCopyClause(
12436 const OpenACCCopyClause &C) {
12437 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12438 C.getModifierList());
12439
12440 NewClause = OpenACCCopyClause::Create(
12441 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12442 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12443 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12444 ParsedClause.getEndLoc());
12445}
12446
12447template <typename Derived>
12448void OpenACCClauseTransform<Derived>::VisitLinkClause(
12449 const OpenACCLinkClause &C) {
12450 llvm_unreachable("link clause not valid unless a decl transform");
12451}
12452
12453template <typename Derived>
12454void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
12456 llvm_unreachable("device_resident clause not valid unless a decl transform");
12457}
12458template <typename Derived>
12459void OpenACCClauseTransform<Derived>::VisitNoHostClause(
12460 const OpenACCNoHostClause &C) {
12461 llvm_unreachable("nohost clause not valid unless a decl transform");
12462}
12463template <typename Derived>
12464void OpenACCClauseTransform<Derived>::VisitBindClause(
12465 const OpenACCBindClause &C) {
12466 llvm_unreachable("bind clause not valid unless a decl transform");
12467}
12468
12469template <typename Derived>
12470void OpenACCClauseTransform<Derived>::VisitCopyInClause(
12471 const OpenACCCopyInClause &C) {
12472 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12473 C.getModifierList());
12474
12475 NewClause = OpenACCCopyInClause::Create(
12476 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12477 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12478 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12479 ParsedClause.getEndLoc());
12480}
12481
12482template <typename Derived>
12483void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
12484 const OpenACCCopyOutClause &C) {
12485 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12486 C.getModifierList());
12487
12488 NewClause = OpenACCCopyOutClause::Create(
12489 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12490 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12491 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12492 ParsedClause.getEndLoc());
12493}
12494
12495template <typename Derived>
12496void OpenACCClauseTransform<Derived>::VisitCreateClause(
12497 const OpenACCCreateClause &C) {
12498 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12499 C.getModifierList());
12500
12501 NewClause = OpenACCCreateClause::Create(
12502 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12503 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12504 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12505 ParsedClause.getEndLoc());
12506}
12507template <typename Derived>
12508void OpenACCClauseTransform<Derived>::VisitAttachClause(
12509 const OpenACCAttachClause &C) {
12510 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12511
12512 // Ensure each var is a pointer type.
12513 llvm::erase_if(VarList, [&](Expr *E) {
12514 return Self.getSema().OpenACC().CheckVarIsPointerType(
12516 });
12517
12518 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12519 NewClause = OpenACCAttachClause::Create(
12520 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12521 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12522 ParsedClause.getEndLoc());
12523}
12524
12525template <typename Derived>
12526void OpenACCClauseTransform<Derived>::VisitDetachClause(
12527 const OpenACCDetachClause &C) {
12528 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12529
12530 // Ensure each var is a pointer type.
12531 llvm::erase_if(VarList, [&](Expr *E) {
12532 return Self.getSema().OpenACC().CheckVarIsPointerType(
12534 });
12535
12536 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12537 NewClause = OpenACCDetachClause::Create(
12538 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12539 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12540 ParsedClause.getEndLoc());
12541}
12542
12543template <typename Derived>
12544void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12545 const OpenACCDeleteClause &C) {
12546 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12548 NewClause = OpenACCDeleteClause::Create(
12549 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12550 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12551 ParsedClause.getEndLoc());
12552}
12553
12554template <typename Derived>
12555void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12556 const OpenACCUseDeviceClause &C) {
12557 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12560 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12561 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12562 ParsedClause.getEndLoc());
12563}
12564
12565template <typename Derived>
12566void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12567 const OpenACCDevicePtrClause &C) {
12568 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12569
12570 // Ensure each var is a pointer type.
12571 llvm::erase_if(VarList, [&](Expr *E) {
12572 return Self.getSema().OpenACC().CheckVarIsPointerType(
12574 });
12575
12576 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12578 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12579 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12580 ParsedClause.getEndLoc());
12581}
12582
12583template <typename Derived>
12584void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12585 const OpenACCNumWorkersClause &C) {
12586 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12587 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12588
12589 ExprResult Res = Self.TransformExpr(IntExpr);
12590 if (!Res.isUsable())
12591 return;
12592
12593 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12594 C.getClauseKind(),
12595 C.getBeginLoc(), Res.get());
12596 if (!Res.isUsable())
12597 return;
12598
12599 ParsedClause.setIntExprDetails(Res.get());
12601 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12602 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12603 ParsedClause.getEndLoc());
12604}
12605
12606template <typename Derived>
12607void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12608 const OpenACCDeviceNumClause &C) {
12609 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12610 assert(IntExpr && "device_num clause constructed with invalid int expr");
12611
12612 ExprResult Res = Self.TransformExpr(IntExpr);
12613 if (!Res.isUsable())
12614 return;
12615
12616 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12617 C.getClauseKind(),
12618 C.getBeginLoc(), Res.get());
12619 if (!Res.isUsable())
12620 return;
12621
12622 ParsedClause.setIntExprDetails(Res.get());
12624 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12625 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12626 ParsedClause.getEndLoc());
12627}
12628
12629template <typename Derived>
12630void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12632 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12633 assert(IntExpr && "default_async clause constructed with invalid int expr");
12634
12635 ExprResult Res = Self.TransformExpr(IntExpr);
12636 if (!Res.isUsable())
12637 return;
12638
12639 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12640 C.getClauseKind(),
12641 C.getBeginLoc(), Res.get());
12642 if (!Res.isUsable())
12643 return;
12644
12645 ParsedClause.setIntExprDetails(Res.get());
12647 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12648 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12649 ParsedClause.getEndLoc());
12650}
12651
12652template <typename Derived>
12653void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12655 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12656 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12657
12658 ExprResult Res = Self.TransformExpr(IntExpr);
12659 if (!Res.isUsable())
12660 return;
12661
12662 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12663 C.getClauseKind(),
12664 C.getBeginLoc(), Res.get());
12665 if (!Res.isUsable())
12666 return;
12667
12668 ParsedClause.setIntExprDetails(Res.get());
12670 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12671 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12672 ParsedClause.getEndLoc());
12673}
12674
12675template <typename Derived>
12676void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12677 const OpenACCAsyncClause &C) {
12678 if (C.hasIntExpr()) {
12679 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12680 if (!Res.isUsable())
12681 return;
12682
12683 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12684 C.getClauseKind(),
12685 C.getBeginLoc(), Res.get());
12686 if (!Res.isUsable())
12687 return;
12688 ParsedClause.setIntExprDetails(Res.get());
12689 }
12690
12691 NewClause = OpenACCAsyncClause::Create(
12692 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12693 ParsedClause.getLParenLoc(),
12694 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12695 : nullptr,
12696 ParsedClause.getEndLoc());
12697}
12698
12699template <typename Derived>
12700void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12701 const OpenACCWorkerClause &C) {
12702 if (C.hasIntExpr()) {
12703 // restrictions on this expression are all "does it exist in certain
12704 // situations" that are not possible to be dependent, so the only check we
12705 // have is that it transforms, and is an int expression.
12706 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12707 if (!Res.isUsable())
12708 return;
12709
12710 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12711 C.getClauseKind(),
12712 C.getBeginLoc(), Res.get());
12713 if (!Res.isUsable())
12714 return;
12715 ParsedClause.setIntExprDetails(Res.get());
12716 }
12717
12718 NewClause = OpenACCWorkerClause::Create(
12719 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12720 ParsedClause.getLParenLoc(),
12721 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12722 : nullptr,
12723 ParsedClause.getEndLoc());
12724}
12725
12726template <typename Derived>
12727void OpenACCClauseTransform<Derived>::VisitVectorClause(
12728 const OpenACCVectorClause &C) {
12729 if (C.hasIntExpr()) {
12730 // restrictions on this expression are all "does it exist in certain
12731 // situations" that are not possible to be dependent, so the only check we
12732 // have is that it transforms, and is an int expression.
12733 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12734 if (!Res.isUsable())
12735 return;
12736
12737 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12738 C.getClauseKind(),
12739 C.getBeginLoc(), Res.get());
12740 if (!Res.isUsable())
12741 return;
12742 ParsedClause.setIntExprDetails(Res.get());
12743 }
12744
12745 NewClause = OpenACCVectorClause::Create(
12746 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12747 ParsedClause.getLParenLoc(),
12748 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12749 : nullptr,
12750 ParsedClause.getEndLoc());
12751}
12752
12753template <typename Derived>
12754void OpenACCClauseTransform<Derived>::VisitWaitClause(
12755 const OpenACCWaitClause &C) {
12756 if (C.hasExprs()) {
12757 Expr *DevNumExpr = nullptr;
12758 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
12759
12760 // Instantiate devnum expr if it exists.
12761 if (C.getDevNumExpr()) {
12762 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
12763 if (!Res.isUsable())
12764 return;
12765 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12766 C.getClauseKind(),
12767 C.getBeginLoc(), Res.get());
12768 if (!Res.isUsable())
12769 return;
12770
12771 DevNumExpr = Res.get();
12772 }
12773
12774 // Instantiate queue ids.
12775 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
12776 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
12777 if (!Res.isUsable())
12778 return;
12779 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12780 C.getClauseKind(),
12781 C.getBeginLoc(), Res.get());
12782 if (!Res.isUsable())
12783 return;
12784
12785 InstantiatedQueueIdExprs.push_back(Res.get());
12786 }
12787
12788 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
12789 std::move(InstantiatedQueueIdExprs));
12790 }
12791
12792 NewClause = OpenACCWaitClause::Create(
12793 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12794 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
12795 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
12796 ParsedClause.getEndLoc());
12797}
12798
12799template <typename Derived>
12800void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
12801 const OpenACCDeviceTypeClause &C) {
12802 // Nothing to transform here, just create a new version of 'C'.
12804 Self.getSema().getASTContext(), C.getClauseKind(),
12805 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12806 C.getArchitectures(), ParsedClause.getEndLoc());
12807}
12808
12809template <typename Derived>
12810void OpenACCClauseTransform<Derived>::VisitAutoClause(
12811 const OpenACCAutoClause &C) {
12812 // Nothing to do, so just create a new node.
12813 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
12814 ParsedClause.getBeginLoc(),
12815 ParsedClause.getEndLoc());
12816}
12817
12818template <typename Derived>
12819void OpenACCClauseTransform<Derived>::VisitIndependentClause(
12820 const OpenACCIndependentClause &C) {
12821 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
12822 ParsedClause.getBeginLoc(),
12823 ParsedClause.getEndLoc());
12824}
12825
12826template <typename Derived>
12827void OpenACCClauseTransform<Derived>::VisitSeqClause(
12828 const OpenACCSeqClause &C) {
12829 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
12830 ParsedClause.getBeginLoc(),
12831 ParsedClause.getEndLoc());
12832}
12833template <typename Derived>
12834void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
12835 const OpenACCFinalizeClause &C) {
12836 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
12837 ParsedClause.getBeginLoc(),
12838 ParsedClause.getEndLoc());
12839}
12840
12841template <typename Derived>
12842void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
12843 const OpenACCIfPresentClause &C) {
12844 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
12845 ParsedClause.getBeginLoc(),
12846 ParsedClause.getEndLoc());
12847}
12848
12849template <typename Derived>
12850void OpenACCClauseTransform<Derived>::VisitReductionClause(
12851 const OpenACCReductionClause &C) {
12852 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
12853 SmallVector<Expr *> ValidVars;
12855
12856 for (const auto [Var, OrigRecipe] :
12857 llvm::zip(TransformedVars, C.getRecipes())) {
12858 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
12859 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
12860 if (Res.isUsable()) {
12861 ValidVars.push_back(Res.get());
12862
12863 if (OrigRecipe.isSet())
12864 Recipes.emplace_back(OrigRecipe.AllocaDecl, OrigRecipe.CombinerRecipes);
12865 else
12866 Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe(
12867 C.getReductionOp(), Res.get()));
12868 }
12869 }
12870
12871 NewClause = Self.getSema().OpenACC().CheckReductionClause(
12872 ExistingClauses, ParsedClause.getDirectiveKind(),
12873 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12874 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
12875}
12876
12877template <typename Derived>
12878void OpenACCClauseTransform<Derived>::VisitCollapseClause(
12879 const OpenACCCollapseClause &C) {
12880 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
12881 assert(LoopCount && "collapse clause constructed with invalid loop count");
12882
12883 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
12884
12885 if (!NewLoopCount.isUsable())
12886 return;
12887
12888 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
12889 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12890 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
12891
12892 // FIXME: It isn't clear whether this is properly tested here, we should
12893 // probably see if we can come up with a test for this.
12894 if (!NewLoopCount.isUsable())
12895 return;
12896
12897 NewLoopCount =
12898 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
12899
12900 // FIXME: It isn't clear whether this is properly tested here, we should
12901 // probably see if we can come up with a test for this.
12902 if (!NewLoopCount.isUsable())
12903 return;
12904
12905 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
12907 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12908 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
12909 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
12910}
12911
12912template <typename Derived>
12913void OpenACCClauseTransform<Derived>::VisitTileClause(
12914 const OpenACCTileClause &C) {
12915
12916 llvm::SmallVector<Expr *> TransformedExprs;
12917
12918 for (Expr *E : C.getSizeExprs()) {
12919 ExprResult NewSizeExpr = Self.TransformExpr(E);
12920
12921 if (!NewSizeExpr.isUsable())
12922 return;
12923
12924 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
12925 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
12926 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
12927
12928 // FIXME: It isn't clear whether this is properly tested here, we should
12929 // probably see if we can come up with a test for this.
12930 if (!NewSizeExpr.isUsable())
12931 return;
12932
12933 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
12934
12935 if (!NewSizeExpr.isUsable())
12936 return;
12937 TransformedExprs.push_back(NewSizeExpr.get());
12938 }
12939
12940 ParsedClause.setIntExprDetails(TransformedExprs);
12941 NewClause = OpenACCTileClause::Create(
12942 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12943 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12944 ParsedClause.getEndLoc());
12945}
12946template <typename Derived>
12947void OpenACCClauseTransform<Derived>::VisitGangClause(
12948 const OpenACCGangClause &C) {
12949 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
12950 llvm::SmallVector<Expr *> TransformedIntExprs;
12951
12952 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
12953 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
12954 if (!ER.isUsable())
12955 continue;
12956
12957 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
12958 ParsedClause.getDirectiveKind(),
12959 C.getExpr(I).first, ER.get());
12960 if (!ER.isUsable())
12961 continue;
12962 TransformedGangKinds.push_back(C.getExpr(I).first);
12963 TransformedIntExprs.push_back(ER.get());
12964 }
12965
12966 NewClause = Self.getSema().OpenACC().CheckGangClause(
12967 ParsedClause.getDirectiveKind(), ExistingClauses,
12968 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12969 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
12970}
12971} // namespace
12972template <typename Derived>
12973OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
12974 ArrayRef<const OpenACCClause *> ExistingClauses,
12975 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
12976
12978 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
12979 ParsedClause.setEndLoc(OldClause->getEndLoc());
12980
12981 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
12982 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
12983
12984 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
12985 ParsedClause};
12986 Transform.Visit(OldClause);
12987
12988 return Transform.CreatedClause();
12989}
12990
12991template <typename Derived>
12993TreeTransform<Derived>::TransformOpenACCClauseList(
12995 llvm::SmallVector<OpenACCClause *> TransformedClauses;
12996 for (const auto *Clause : OldClauses) {
12997 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
12998 TransformedClauses, DirKind, Clause))
12999 TransformedClauses.push_back(TransformedClause);
13000 }
13001 return TransformedClauses;
13002}
13003
13004template <typename Derived>
13007 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13008
13009 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13010 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13011 C->clauses());
13012
13013 if (getSema().OpenACC().ActOnStartStmtDirective(
13014 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13015 return StmtError();
13016
13017 // Transform Structured Block.
13018 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13019 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13020 C->clauses(), TransformedClauses);
13021 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13022 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13023 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13024
13025 return getDerived().RebuildOpenACCComputeConstruct(
13026 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13027 C->getEndLoc(), TransformedClauses, StrBlock);
13028}
13029
13030template <typename Derived>
13033
13034 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13035
13036 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13037 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13038 C->clauses());
13039
13040 if (getSema().OpenACC().ActOnStartStmtDirective(
13041 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13042 return StmtError();
13043
13044 // Transform Loop.
13045 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13046 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13047 C->clauses(), TransformedClauses);
13048 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13049 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13050 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13051
13052 return getDerived().RebuildOpenACCLoopConstruct(
13053 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13054 TransformedClauses, Loop);
13055}
13056
13057template <typename Derived>
13059 OpenACCCombinedConstruct *C) {
13060 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13061
13062 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13063 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13064 C->clauses());
13065
13066 if (getSema().OpenACC().ActOnStartStmtDirective(
13067 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13068 return StmtError();
13069
13070 // Transform Loop.
13071 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13072 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13073 C->clauses(), TransformedClauses);
13074 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13075 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13076 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13077
13078 return getDerived().RebuildOpenACCCombinedConstruct(
13079 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13080 C->getEndLoc(), TransformedClauses, Loop);
13081}
13082
13083template <typename Derived>
13086 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13087
13088 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13089 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13090 C->clauses());
13091 if (getSema().OpenACC().ActOnStartStmtDirective(
13092 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13093 return StmtError();
13094
13095 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13096 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13097 C->clauses(), TransformedClauses);
13098 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13099 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13100 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13101
13102 return getDerived().RebuildOpenACCDataConstruct(
13103 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13104 TransformedClauses, StrBlock);
13105}
13106
13107template <typename Derived>
13109 OpenACCEnterDataConstruct *C) {
13110 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13111
13112 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13113 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13114 C->clauses());
13115 if (getSema().OpenACC().ActOnStartStmtDirective(
13116 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13117 return StmtError();
13118
13119 return getDerived().RebuildOpenACCEnterDataConstruct(
13120 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13121 TransformedClauses);
13122}
13123
13124template <typename Derived>
13126 OpenACCExitDataConstruct *C) {
13127 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13128
13129 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13130 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13131 C->clauses());
13132 if (getSema().OpenACC().ActOnStartStmtDirective(
13133 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13134 return StmtError();
13135
13136 return getDerived().RebuildOpenACCExitDataConstruct(
13137 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13138 TransformedClauses);
13139}
13140
13141template <typename Derived>
13143 OpenACCHostDataConstruct *C) {
13144 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13145
13146 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13147 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13148 C->clauses());
13149 if (getSema().OpenACC().ActOnStartStmtDirective(
13150 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13151 return StmtError();
13152
13153 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13154 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13155 C->clauses(), TransformedClauses);
13156 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13157 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13158 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13159
13160 return getDerived().RebuildOpenACCHostDataConstruct(
13161 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13162 TransformedClauses, StrBlock);
13163}
13164
13165template <typename Derived>
13168 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13169
13170 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13171 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13172 C->clauses());
13173 if (getSema().OpenACC().ActOnStartStmtDirective(
13174 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13175 return StmtError();
13176
13177 return getDerived().RebuildOpenACCInitConstruct(
13178 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13179 TransformedClauses);
13180}
13181
13182template <typename Derived>
13184 OpenACCShutdownConstruct *C) {
13185 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13186
13187 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13188 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13189 C->clauses());
13190 if (getSema().OpenACC().ActOnStartStmtDirective(
13191 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13192 return StmtError();
13193
13194 return getDerived().RebuildOpenACCShutdownConstruct(
13195 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13196 TransformedClauses);
13197}
13198template <typename Derived>
13201 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13202
13203 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13204 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13205 C->clauses());
13206 if (getSema().OpenACC().ActOnStartStmtDirective(
13207 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13208 return StmtError();
13209
13210 return getDerived().RebuildOpenACCSetConstruct(
13211 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13212 TransformedClauses);
13213}
13214
13215template <typename Derived>
13217 OpenACCUpdateConstruct *C) {
13218 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13219
13220 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13221 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13222 C->clauses());
13223 if (getSema().OpenACC().ActOnStartStmtDirective(
13224 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13225 return StmtError();
13226
13227 return getDerived().RebuildOpenACCUpdateConstruct(
13228 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13229 TransformedClauses);
13230}
13231
13232template <typename Derived>
13235 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13236
13237 ExprResult DevNumExpr;
13238 if (C->hasDevNumExpr()) {
13239 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
13240
13241 if (DevNumExpr.isUsable())
13242 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
13244 C->getBeginLoc(), DevNumExpr.get());
13245 }
13246
13247 llvm::SmallVector<Expr *> QueueIdExprs;
13248
13249 for (Expr *QE : C->getQueueIdExprs()) {
13250 assert(QE && "Null queue id expr?");
13251 ExprResult NewEQ = getDerived().TransformExpr(QE);
13252
13253 if (!NewEQ.isUsable())
13254 break;
13255 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
13257 C->getBeginLoc(), NewEQ.get());
13258 if (NewEQ.isUsable())
13259 QueueIdExprs.push_back(NewEQ.get());
13260 }
13261
13262 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13263 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13264 C->clauses());
13265
13266 if (getSema().OpenACC().ActOnStartStmtDirective(
13267 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13268 return StmtError();
13269
13270 return getDerived().RebuildOpenACCWaitConstruct(
13271 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13272 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
13273 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
13274}
13275template <typename Derived>
13277 OpenACCCacheConstruct *C) {
13278 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13279
13280 llvm::SmallVector<Expr *> TransformedVarList;
13281 for (Expr *Var : C->getVarList()) {
13282 assert(Var && "Null var listexpr?");
13283
13284 ExprResult NewVar = getDerived().TransformExpr(Var);
13285
13286 if (!NewVar.isUsable())
13287 break;
13288
13289 NewVar = getSema().OpenACC().ActOnVar(
13290 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
13291 if (!NewVar.isUsable())
13292 break;
13293
13294 TransformedVarList.push_back(NewVar.get());
13295 }
13296
13297 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13298 C->getBeginLoc(), {}))
13299 return StmtError();
13300
13301 return getDerived().RebuildOpenACCCacheConstruct(
13302 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13303 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
13304 C->getEndLoc());
13305}
13306
13307template <typename Derived>
13309 OpenACCAtomicConstruct *C) {
13310 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13311
13312 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13313 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13314 C->clauses());
13315
13316 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13317 C->getBeginLoc(), {}))
13318 return StmtError();
13319
13320 // Transform Associated Stmt.
13321 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13322 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
13323
13324 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
13325 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
13326 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
13327 AssocStmt);
13328
13329 return getDerived().RebuildOpenACCAtomicConstruct(
13330 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
13331 C->getEndLoc(), TransformedClauses, AssocStmt);
13332}
13333
13334template <typename Derived>
13337 if (getDerived().AlwaysRebuild())
13338 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
13339 // Nothing can ever change, so there is never anything to transform.
13340 return E;
13341}
13342
13343//===----------------------------------------------------------------------===//
13344// Expression transformation
13345//===----------------------------------------------------------------------===//
13346template<typename Derived>
13349 return TransformExpr(E->getSubExpr());
13350}
13351
13352template <typename Derived>
13355 if (!E->isTypeDependent())
13356 return E;
13357
13358 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
13359
13360 if (!NewT)
13361 return ExprError();
13362
13363 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
13364 return E;
13365
13366 return getDerived().RebuildSYCLUniqueStableNameExpr(
13367 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
13368}
13369
13370template <typename Derived>
13373 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
13374 const auto *SKEPAttr = FD->template getAttr<SYCLKernelEntryPointAttr>();
13375 if (!SKEPAttr || SKEPAttr->isInvalidAttr())
13376 return StmtError();
13377
13378 ExprResult IdExpr = getDerived().TransformExpr(S->getKernelLaunchIdExpr());
13379 if (IdExpr.isInvalid())
13380 return StmtError();
13381
13382 StmtResult Body = getDerived().TransformStmt(S->getOriginalStmt());
13383 if (Body.isInvalid())
13384 return StmtError();
13385
13387 cast<FunctionDecl>(SemaRef.CurContext), cast<CompoundStmt>(Body.get()),
13388 IdExpr.get());
13389 if (SR.isInvalid())
13390 return StmtError();
13391
13392 return SR;
13393}
13394
13395template <typename Derived>
13397 // TODO(reflection): Implement its transform
13398 assert(false && "not implemented yet");
13399 return ExprError();
13400}
13401
13402template<typename Derived>
13405 if (!E->isTypeDependent())
13406 return E;
13407
13408 return getDerived().RebuildPredefinedExpr(E->getLocation(),
13409 E->getIdentKind());
13410}
13411
13412template<typename Derived>
13415 NestedNameSpecifierLoc QualifierLoc;
13416 if (E->getQualifierLoc()) {
13417 QualifierLoc
13418 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13419 if (!QualifierLoc)
13420 return ExprError();
13421 }
13422
13423 ValueDecl *ND
13424 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
13425 E->getDecl()));
13426 if (!ND || ND->isInvalidDecl())
13427 return ExprError();
13428
13429 NamedDecl *Found = ND;
13430 if (E->getFoundDecl() != E->getDecl()) {
13431 Found = cast_or_null<NamedDecl>(
13432 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
13433 if (!Found)
13434 return ExprError();
13435 }
13436
13437 DeclarationNameInfo NameInfo = E->getNameInfo();
13438 if (NameInfo.getName()) {
13439 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
13440 if (!NameInfo.getName())
13441 return ExprError();
13442 }
13443
13444 if (!getDerived().AlwaysRebuild() &&
13445 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
13446 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
13447 Found == E->getFoundDecl() &&
13448 NameInfo.getName() == E->getDecl()->getDeclName() &&
13449 !E->hasExplicitTemplateArgs()) {
13450
13451 // Mark it referenced in the new context regardless.
13452 // FIXME: this is a bit instantiation-specific.
13453 SemaRef.MarkDeclRefReferenced(E);
13454
13455 return E;
13456 }
13457
13458 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
13459 if (E->hasExplicitTemplateArgs()) {
13460 TemplateArgs = &TransArgs;
13461 TransArgs.setLAngleLoc(E->getLAngleLoc());
13462 TransArgs.setRAngleLoc(E->getRAngleLoc());
13463 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13464 E->getNumTemplateArgs(),
13465 TransArgs))
13466 return ExprError();
13467 }
13468
13469 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
13470 Found, TemplateArgs);
13471}
13472
13473template<typename Derived>
13476 return E;
13477}
13478
13479template <typename Derived>
13481 FixedPointLiteral *E) {
13482 return E;
13483}
13484
13485template<typename Derived>
13488 return E;
13489}
13490
13491template<typename Derived>
13494 return E;
13495}
13496
13497template<typename Derived>
13500 return E;
13501}
13502
13503template<typename Derived>
13506 return E;
13507}
13508
13509template<typename Derived>
13512 return getDerived().TransformCallExpr(E);
13513}
13514
13515template<typename Derived>
13518 ExprResult ControllingExpr;
13519 TypeSourceInfo *ControllingType = nullptr;
13520 if (E->isExprPredicate())
13521 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
13522 else
13523 ControllingType = getDerived().TransformType(E->getControllingType());
13524
13525 if (ControllingExpr.isInvalid() && !ControllingType)
13526 return ExprError();
13527
13528 SmallVector<Expr *, 4> AssocExprs;
13530 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
13531 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
13532 if (TSI) {
13533 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
13534 if (!AssocType)
13535 return ExprError();
13536 AssocTypes.push_back(AssocType);
13537 } else {
13538 AssocTypes.push_back(nullptr);
13539 }
13540
13541 ExprResult AssocExpr =
13542 getDerived().TransformExpr(Assoc.getAssociationExpr());
13543 if (AssocExpr.isInvalid())
13544 return ExprError();
13545 AssocExprs.push_back(AssocExpr.get());
13546 }
13547
13548 if (!ControllingType)
13549 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
13550 E->getDefaultLoc(),
13551 E->getRParenLoc(),
13552 ControllingExpr.get(),
13553 AssocTypes,
13554 AssocExprs);
13555 return getDerived().RebuildGenericSelectionExpr(
13556 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
13557 ControllingType, AssocTypes, AssocExprs);
13558}
13559
13560template<typename Derived>
13563 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13564 if (SubExpr.isInvalid())
13565 return ExprError();
13566
13567 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13568 return E;
13569
13570 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13571 E->getRParen());
13572}
13573
13574/// The operand of a unary address-of operator has special rules: it's
13575/// allowed to refer to a non-static member of a class even if there's no 'this'
13576/// object available.
13577template<typename Derived>
13580 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13581 return getDerived().TransformDependentScopeDeclRefExpr(
13582 DRE, /*IsAddressOfOperand=*/true, nullptr);
13583 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13584 return getDerived().TransformUnresolvedLookupExpr(
13585 ULE, /*IsAddressOfOperand=*/true);
13586 else
13587 return getDerived().TransformExpr(E);
13588}
13589
13590template<typename Derived>
13593 ExprResult SubExpr;
13594 if (E->getOpcode() == UO_AddrOf)
13595 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13596 else
13597 SubExpr = TransformExpr(E->getSubExpr());
13598 if (SubExpr.isInvalid())
13599 return ExprError();
13600
13601 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13602 return E;
13603
13604 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13605 E->getOpcode(),
13606 SubExpr.get());
13607}
13608
13609template<typename Derived>
13611TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13612 // Transform the type.
13613 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13614 if (!Type)
13615 return ExprError();
13616
13617 // Transform all of the components into a Designation similar to what the
13618 // parser builds.
13619 // FIXME: It would be slightly more efficient in the non-dependent case to
13620 // just map FieldDecls, rather than requiring the rebuilder to look for
13621 // the fields again. However, __builtin_offsetof is rare enough in
13622 // template code that we don't care.
13623 bool ExprChanged = false;
13624 Designation Desig;
13625 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
13626 const OffsetOfNode &ON = E->getComponent(I);
13627 switch (ON.getKind()) {
13628 case OffsetOfNode::Array: {
13629 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
13630 ExprResult Index = getDerived().TransformExpr(FromIndex);
13631 if (Index.isInvalid())
13632 return ExprError();
13633
13634 ExprChanged = ExprChanged || Index.get() != FromIndex;
13635 Designator AD =
13636 Designator::CreateArrayDesignator(Index.get(), ON.getBeginLoc());
13637 AD.setRBracketLoc(ON.getEndLoc());
13638 Desig.AddDesignator(AD);
13639 break;
13640 }
13641
13644 const IdentifierInfo *Name = ON.getFieldName();
13645 if (!Name)
13646 continue;
13647 // The leading designator has no '.'; subsequent ones do.
13648 SourceLocation DotLoc =
13649 Desig.empty() ? SourceLocation() : ON.getBeginLoc();
13650 Desig.AddDesignator(
13651 Designator::CreateFieldDesignator(Name, DotLoc, ON.getEndLoc()));
13652 break;
13653 }
13654
13655 case OffsetOfNode::Base:
13656 // Will be recomputed during the rebuild.
13657 continue;
13658 }
13659 }
13660
13661 // If nothing changed, retain the existing expression.
13662 if (!getDerived().AlwaysRebuild() &&
13663 Type == E->getTypeSourceInfo() &&
13664 !ExprChanged)
13665 return E;
13666
13667 // Build a new offsetof expression.
13668 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, Desig,
13669 E->getRParenLoc());
13670}
13671
13672template<typename Derived>
13675 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
13676 "opaque value expression requires transformation");
13677 return E;
13678}
13679
13680template <typename Derived>
13683 bool Changed = false;
13684 for (Expr *C : E->subExpressions()) {
13685 ExprResult NewC = getDerived().TransformExpr(C);
13686 if (NewC.isInvalid())
13687 return ExprError();
13688 Children.push_back(NewC.get());
13689
13690 Changed |= NewC.get() != C;
13691 }
13692 if (!getDerived().AlwaysRebuild() && !Changed)
13693 return E;
13694 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
13695 Children, E->getType());
13696}
13697
13698template<typename Derived>
13701 // Rebuild the syntactic form. The original syntactic form has
13702 // opaque-value expressions in it, so strip those away and rebuild
13703 // the result. This is a really awful way of doing this, but the
13704 // better solution (rebuilding the semantic expressions and
13705 // rebinding OVEs as necessary) doesn't work; we'd need
13706 // TreeTransform to not strip away implicit conversions.
13707 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
13708 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
13709 if (result.isInvalid()) return ExprError();
13710
13711 // If that gives us a pseudo-object result back, the pseudo-object
13712 // expression must have been an lvalue-to-rvalue conversion which we
13713 // should reapply.
13714 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
13715 result = SemaRef.PseudoObject().checkRValue(result.get());
13716
13717 return result;
13718}
13719
13720template<typename Derived>
13724 if (E->isArgumentType()) {
13725 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
13726
13727 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
13728 if (!NewT)
13729 return ExprError();
13730
13731 if (!getDerived().AlwaysRebuild() && OldT == NewT)
13732 return E;
13733
13734 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
13735 E->getKind(),
13736 E->getSourceRange());
13737 }
13738
13739 // C++0x [expr.sizeof]p1:
13740 // The operand is either an expression, which is an unevaluated operand
13741 // [...]
13745
13746 // Try to recover if we have something like sizeof(T::X) where X is a type.
13747 // Notably, there must be *exactly* one set of parens if X is a type.
13748 TypeSourceInfo *RecoveryTSI = nullptr;
13749 ExprResult SubExpr;
13750 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
13751 if (auto *DRE =
13752 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
13753 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
13754 PE, DRE, false, &RecoveryTSI);
13755 else
13756 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
13757
13758 if (RecoveryTSI) {
13759 return getDerived().RebuildUnaryExprOrTypeTrait(
13760 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
13761 } else if (SubExpr.isInvalid())
13762 return ExprError();
13763
13764 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
13765 return E;
13766
13767 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
13768 E->getOperatorLoc(),
13769 E->getKind(),
13770 E->getSourceRange());
13771}
13772
13773template<typename Derived>
13776 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
13777 if (LHS.isInvalid())
13778 return ExprError();
13779
13780 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
13781 if (RHS.isInvalid())
13782 return ExprError();
13783
13784
13785 if (!getDerived().AlwaysRebuild() &&
13786 LHS.get() == E->getLHS() &&
13787 RHS.get() == E->getRHS())
13788 return E;
13789
13790 return getDerived().RebuildArraySubscriptExpr(
13791 LHS.get(),
13792 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
13793}
13794
13795template <typename Derived>
13798 ExprResult Base = getDerived().TransformExpr(E->getBase());
13799 if (Base.isInvalid())
13800 return ExprError();
13801
13802 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13803 if (RowIdx.isInvalid())
13804 return ExprError();
13805
13806 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13807 RowIdx.get() == E->getRowIdx())
13808 return E;
13809
13810 return getDerived().RebuildMatrixSingleSubscriptExpr(Base.get(), RowIdx.get(),
13811 E->getRBracketLoc());
13812}
13813
13814template <typename Derived>
13817 ExprResult Base = getDerived().TransformExpr(E->getBase());
13818 if (Base.isInvalid())
13819 return ExprError();
13820
13821 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
13822 if (RowIdx.isInvalid())
13823 return ExprError();
13824
13825 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
13826 if (ColumnIdx.isInvalid())
13827 return ExprError();
13828
13829 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13830 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
13831 return E;
13832
13833 return getDerived().RebuildMatrixSubscriptExpr(
13834 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
13835}
13836
13837template <typename Derived>
13840 ExprResult Base = getDerived().TransformExpr(E->getBase());
13841 if (Base.isInvalid())
13842 return ExprError();
13843
13844 ExprResult LowerBound;
13845 if (E->getLowerBound()) {
13846 LowerBound = getDerived().TransformExpr(E->getLowerBound());
13847 if (LowerBound.isInvalid())
13848 return ExprError();
13849 }
13850
13851 ExprResult Length;
13852 if (E->getLength()) {
13853 Length = getDerived().TransformExpr(E->getLength());
13854 if (Length.isInvalid())
13855 return ExprError();
13856 }
13857
13858 ExprResult Stride;
13859 if (E->isOMPArraySection()) {
13860 if (Expr *Str = E->getStride()) {
13861 Stride = getDerived().TransformExpr(Str);
13862 if (Stride.isInvalid())
13863 return ExprError();
13864 }
13865 }
13866
13867 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
13868 LowerBound.get() == E->getLowerBound() &&
13869 Length.get() == E->getLength() &&
13870 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
13871 return E;
13872
13873 return getDerived().RebuildArraySectionExpr(
13874 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
13875 LowerBound.get(), E->getColonLocFirst(),
13876 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
13877 Length.get(), Stride.get(), E->getRBracketLoc());
13878}
13879
13880template <typename Derived>
13883 ExprResult Base = getDerived().TransformExpr(E->getBase());
13884 if (Base.isInvalid())
13885 return ExprError();
13886
13888 bool ErrorFound = false;
13889 for (Expr *Dim : E->getDimensions()) {
13890 ExprResult DimRes = getDerived().TransformExpr(Dim);
13891 if (DimRes.isInvalid()) {
13892 ErrorFound = true;
13893 continue;
13894 }
13895 Dims.push_back(DimRes.get());
13896 }
13897
13898 if (ErrorFound)
13899 return ExprError();
13900 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
13901 E->getRParenLoc(), Dims,
13902 E->getBracketsRanges());
13903}
13904
13905template <typename Derived>
13908 unsigned NumIterators = E->numOfIterators();
13910
13911 bool ErrorFound = false;
13912 bool NeedToRebuild = getDerived().AlwaysRebuild();
13913 for (unsigned I = 0; I < NumIterators; ++I) {
13914 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
13915 Data[I].DeclIdent = D->getIdentifier();
13916 Data[I].DeclIdentLoc = D->getLocation();
13917 if (D->getLocation() == D->getBeginLoc()) {
13918 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
13919 "Implicit type must be int.");
13920 } else {
13921 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
13922 QualType DeclTy = getDerived().TransformType(D->getType());
13923 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
13924 }
13925 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
13926 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
13927 ExprResult End = getDerived().TransformExpr(Range.End);
13928 ExprResult Step = getDerived().TransformExpr(Range.Step);
13929 ErrorFound = ErrorFound ||
13930 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
13931 !Data[I].Type.get().isNull())) ||
13932 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
13933 if (ErrorFound)
13934 continue;
13935 Data[I].Range.Begin = Begin.get();
13936 Data[I].Range.End = End.get();
13937 Data[I].Range.Step = Step.get();
13938 Data[I].AssignLoc = E->getAssignLoc(I);
13939 Data[I].ColonLoc = E->getColonLoc(I);
13940 Data[I].SecColonLoc = E->getSecondColonLoc(I);
13941 NeedToRebuild =
13942 NeedToRebuild ||
13943 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
13944 D->getType().getTypePtrOrNull()) ||
13945 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
13946 Range.Step != Data[I].Range.Step;
13947 }
13948 if (ErrorFound)
13949 return ExprError();
13950 if (!NeedToRebuild)
13951 return E;
13952
13953 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
13954 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
13955 if (!Res.isUsable())
13956 return Res;
13957 auto *IE = cast<OMPIteratorExpr>(Res.get());
13958 for (unsigned I = 0; I < NumIterators; ++I)
13959 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
13960 IE->getIteratorDecl(I));
13961 return Res;
13962}
13963
13964template<typename Derived>
13967 // Transform the callee.
13968 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
13969 if (Callee.isInvalid())
13970 return ExprError();
13971
13972 // Transform arguments.
13973 bool ArgChanged = false;
13975 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
13976 &ArgChanged))
13977 return ExprError();
13978
13979 if (!getDerived().AlwaysRebuild() &&
13980 Callee.get() == E->getCallee() &&
13981 !ArgChanged)
13982 return SemaRef.MaybeBindToTemporary(E);
13983
13984 // FIXME: Wrong source location information for the '('.
13985 SourceLocation FakeLParenLoc
13986 = ((Expr *)Callee.get())->getSourceRange().getBegin();
13987
13988 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
13989 if (E->hasStoredFPFeatures()) {
13990 FPOptionsOverride NewOverrides = E->getFPFeatures();
13991 getSema().CurFPFeatures =
13992 NewOverrides.applyOverrides(getSema().getLangOpts());
13993 getSema().FpPragmaStack.CurrentValue = NewOverrides;
13994 }
13995
13996 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
13997 Args,
13998 E->getRParenLoc());
13999}
14000
14001template<typename Derived>
14004 ExprResult Base = getDerived().TransformExpr(E->getBase());
14005 if (Base.isInvalid())
14006 return ExprError();
14007
14008 NestedNameSpecifierLoc QualifierLoc;
14009 if (E->hasQualifier()) {
14010 QualifierLoc
14011 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
14012
14013 if (!QualifierLoc)
14014 return ExprError();
14015 }
14016 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14017
14019 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
14020 E->getMemberDecl()));
14021 if (!Member)
14022 return ExprError();
14023
14024 NamedDecl *FoundDecl = E->getFoundDecl();
14025 if (FoundDecl == E->getMemberDecl()) {
14026 FoundDecl = Member;
14027 } else {
14028 FoundDecl = cast_or_null<NamedDecl>(
14029 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
14030 if (!FoundDecl)
14031 return ExprError();
14032 }
14033
14034 if (!getDerived().AlwaysRebuild() &&
14035 Base.get() == E->getBase() &&
14036 QualifierLoc == E->getQualifierLoc() &&
14037 Member == E->getMemberDecl() &&
14038 FoundDecl == E->getFoundDecl() &&
14039 !E->hasExplicitTemplateArgs()) {
14040
14041 // Skip for member expression of (this->f), rebuilt thisi->f is needed
14042 // for Openmp where the field need to be privatizized in the case.
14043 if (!(isa<CXXThisExpr>(E->getBase()) &&
14044 getSema().OpenMP().isOpenMPRebuildMemberExpr(
14046 // Mark it referenced in the new context regardless.
14047 // FIXME: this is a bit instantiation-specific.
14048 SemaRef.MarkMemberReferenced(E);
14049 return E;
14050 }
14051 }
14052
14053 TemplateArgumentListInfo TransArgs;
14054 if (E->hasExplicitTemplateArgs()) {
14055 TransArgs.setLAngleLoc(E->getLAngleLoc());
14056 TransArgs.setRAngleLoc(E->getRAngleLoc());
14057 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
14058 E->getNumTemplateArgs(),
14059 TransArgs))
14060 return ExprError();
14061 }
14062
14063 // FIXME: Bogus source location for the operator
14064 SourceLocation FakeOperatorLoc =
14065 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
14066
14067 // FIXME: to do this check properly, we will need to preserve the
14068 // first-qualifier-in-scope here, just in case we had a dependent
14069 // base (and therefore couldn't do the check) and a
14070 // nested-name-qualifier (and therefore could do the lookup).
14071 NamedDecl *FirstQualifierInScope = nullptr;
14072 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
14073 if (MemberNameInfo.getName()) {
14074 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
14075 if (!MemberNameInfo.getName())
14076 return ExprError();
14077 }
14078
14079 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
14080 E->isArrow(),
14081 QualifierLoc,
14082 TemplateKWLoc,
14083 MemberNameInfo,
14084 Member,
14085 FoundDecl,
14086 (E->hasExplicitTemplateArgs()
14087 ? &TransArgs : nullptr),
14088 FirstQualifierInScope);
14089}
14090
14091template<typename Derived>
14094 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14095 if (LHS.isInvalid())
14096 return ExprError();
14097
14098 ExprResult RHS =
14099 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
14100 if (RHS.isInvalid())
14101 return ExprError();
14102
14103 if (!getDerived().AlwaysRebuild() &&
14104 LHS.get() == E->getLHS() &&
14105 RHS.get() == E->getRHS())
14106 return E;
14107
14108 if (E->isCompoundAssignmentOp())
14109 // FPFeatures has already been established from trailing storage
14110 return getDerived().RebuildBinaryOperator(
14111 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
14112 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14113 FPOptionsOverride NewOverrides(E->getFPFeatures());
14114 getSema().CurFPFeatures =
14115 NewOverrides.applyOverrides(getSema().getLangOpts());
14116 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14117 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
14118 LHS.get(), RHS.get());
14119}
14120
14121template <typename Derived>
14124 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
14125
14126 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
14127 if (LHS.isInvalid())
14128 return ExprError();
14129
14130 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
14131 if (RHS.isInvalid())
14132 return ExprError();
14133
14134 // Extract the already-resolved callee declarations so that we can restrict
14135 // ourselves to using them as the unqualified lookup results when rebuilding.
14136 UnresolvedSet<2> UnqualLookups;
14137 bool ChangedAnyLookups = false;
14138 Expr *PossibleBinOps[] = {E->getSemanticForm(),
14139 const_cast<Expr *>(Decomp.InnerBinOp)};
14140 for (Expr *PossibleBinOp : PossibleBinOps) {
14141 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
14142 if (!Op)
14143 continue;
14144 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
14145 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
14146 continue;
14147
14148 // Transform the callee in case we built a call to a local extern
14149 // declaration.
14150 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
14151 E->getOperatorLoc(), Callee->getFoundDecl()));
14152 if (!Found)
14153 return ExprError();
14154 if (Found != Callee->getFoundDecl())
14155 ChangedAnyLookups = true;
14156 UnqualLookups.addDecl(Found);
14157 }
14158
14159 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
14160 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
14161 // Mark all functions used in the rewrite as referenced. Note that when
14162 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
14163 // function calls, and/or there might be a user-defined conversion sequence
14164 // applied to the operands of the <.
14165 // FIXME: this is a bit instantiation-specific.
14166 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
14167 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
14168 return E;
14169 }
14170
14171 return getDerived().RebuildCXXRewrittenBinaryOperator(
14172 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
14173}
14174
14175template<typename Derived>
14179 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14180 FPOptionsOverride NewOverrides(E->getFPFeatures());
14181 getSema().CurFPFeatures =
14182 NewOverrides.applyOverrides(getSema().getLangOpts());
14183 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14184 return getDerived().TransformBinaryOperator(E);
14185}
14186
14187template<typename Derived>
14190 // Just rebuild the common and RHS expressions and see whether we
14191 // get any changes.
14192
14193 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
14194 if (commonExpr.isInvalid())
14195 return ExprError();
14196
14197 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
14198 if (rhs.isInvalid())
14199 return ExprError();
14200
14201 if (!getDerived().AlwaysRebuild() &&
14202 commonExpr.get() == e->getCommon() &&
14203 rhs.get() == e->getFalseExpr())
14204 return e;
14205
14206 return getDerived().RebuildConditionalOperator(commonExpr.get(),
14207 e->getQuestionLoc(),
14208 nullptr,
14209 e->getColonLoc(),
14210 rhs.get());
14211}
14212
14213template<typename Derived>
14216 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14217 if (Cond.isInvalid())
14218 return ExprError();
14219
14220 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14221 if (LHS.isInvalid())
14222 return ExprError();
14223
14224 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14225 if (RHS.isInvalid())
14226 return ExprError();
14227
14228 if (!getDerived().AlwaysRebuild() &&
14229 Cond.get() == E->getCond() &&
14230 LHS.get() == E->getLHS() &&
14231 RHS.get() == E->getRHS())
14232 return E;
14233
14234 return getDerived().RebuildConditionalOperator(Cond.get(),
14235 E->getQuestionLoc(),
14236 LHS.get(),
14237 E->getColonLoc(),
14238 RHS.get());
14239}
14240
14241template<typename Derived>
14244 // Implicit casts are eliminated during transformation, since they
14245 // will be recomputed by semantic analysis after transformation.
14246 return getDerived().TransformExpr(E->getSubExprAsWritten());
14247}
14248
14249template<typename Derived>
14252 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14253 if (!Type)
14254 return ExprError();
14255
14256 ExprResult SubExpr
14257 = getDerived().TransformExpr(E->getSubExprAsWritten());
14258 if (SubExpr.isInvalid())
14259 return ExprError();
14260
14261 if (!getDerived().AlwaysRebuild() &&
14262 Type == E->getTypeInfoAsWritten() &&
14263 SubExpr.get() == E->getSubExpr())
14264 return E;
14265
14266 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
14267 Type,
14268 E->getRParenLoc(),
14269 SubExpr.get());
14270}
14271
14272template<typename Derived>
14275 TypeSourceInfo *OldT = E->getTypeSourceInfo();
14276 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
14277 if (!NewT)
14278 return ExprError();
14279
14280 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
14281 if (Init.isInvalid())
14282 return ExprError();
14283
14284 if (!getDerived().AlwaysRebuild() &&
14285 OldT == NewT &&
14286 Init.get() == E->getInitializer())
14287 return SemaRef.MaybeBindToTemporary(E);
14288
14289 // Note: the expression type doesn't necessarily match the
14290 // type-as-written, but that's okay, because it should always be
14291 // derivable from the initializer.
14292
14293 return getDerived().RebuildCompoundLiteralExpr(
14294 E->getLParenLoc(), NewT,
14295 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
14296}
14297
14298template<typename Derived>
14301 ExprResult Base = getDerived().TransformExpr(E->getBase());
14302 if (Base.isInvalid())
14303 return ExprError();
14304
14305 if (!getDerived().AlwaysRebuild() &&
14306 Base.get() == E->getBase())
14307 return E;
14308
14309 // FIXME: Bad source location
14310 SourceLocation FakeOperatorLoc =
14311 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14312 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14313 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
14314 E->getAccessor());
14315}
14316
14317template <typename Derived>
14320 ExprResult Base = getDerived().TransformExpr(E->getBase());
14321 if (Base.isInvalid())
14322 return ExprError();
14323
14324 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase())
14325 return E;
14326
14327 // FIXME: Bad source location
14328 SourceLocation FakeOperatorLoc =
14329 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14330 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14331 Base.get(), FakeOperatorLoc, /*isArrow*/ false, E->getAccessorLoc(),
14332 E->getAccessor());
14333}
14334
14335template<typename Derived>
14338 if (InitListExpr *Syntactic = E->getSyntacticForm())
14339 E = Syntactic;
14340
14341 bool InitChanged = false;
14342
14345
14347 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
14348 Inits, &InitChanged))
14349 return ExprError();
14350
14351 if (!getDerived().AlwaysRebuild() && !InitChanged) {
14352 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
14353 // in some cases. We can't reuse it in general, because the syntactic and
14354 // semantic forms are linked, and we can't know that semantic form will
14355 // match even if the syntactic form does.
14356 }
14357
14358 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
14359 E->getRBraceLoc(), E->isExplicit());
14360}
14361
14362template<typename Derived>
14365 Designation Desig;
14366
14367 // transform the initializer value
14368 ExprResult Init = getDerived().TransformExpr(E->getInit());
14369 if (Init.isInvalid())
14370 return ExprError();
14371
14372 // transform the designators.
14373 SmallVector<Expr*, 4> ArrayExprs;
14374 bool ExprChanged = false;
14375 for (const DesignatedInitExpr::Designator &D : E->designators()) {
14376 if (D.isFieldDesignator()) {
14377 if (D.getFieldDecl()) {
14378 FieldDecl *Field = cast_or_null<FieldDecl>(
14379 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
14380 if (Field != D.getFieldDecl())
14381 // Rebuild the expression when the transformed FieldDecl is
14382 // different to the already assigned FieldDecl.
14383 ExprChanged = true;
14384 if (Field->isAnonymousStructOrUnion())
14385 continue;
14386 } else {
14387 // Ensure that the designator expression is rebuilt when there isn't
14388 // a resolved FieldDecl in the designator as we don't want to assign
14389 // a FieldDecl to a pattern designator that will be instantiated again.
14390 ExprChanged = true;
14391 }
14392 Desig.AddDesignator(Designator::CreateFieldDesignator(
14393 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
14394 continue;
14395 }
14396
14397 if (D.isArrayDesignator()) {
14398 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
14399 if (Index.isInvalid())
14400 return ExprError();
14401
14402 Desig.AddDesignator(
14403 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
14404
14405 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
14406 ArrayExprs.push_back(Index.get());
14407 continue;
14408 }
14409
14410 assert(D.isArrayRangeDesignator() && "New kind of designator?");
14411 ExprResult Start
14412 = getDerived().TransformExpr(E->getArrayRangeStart(D));
14413 if (Start.isInvalid())
14414 return ExprError();
14415
14416 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
14417 if (End.isInvalid())
14418 return ExprError();
14419
14420 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
14421 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
14422
14423 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
14424 End.get() != E->getArrayRangeEnd(D);
14425
14426 ArrayExprs.push_back(Start.get());
14427 ArrayExprs.push_back(End.get());
14428 }
14429
14430 if (!getDerived().AlwaysRebuild() &&
14431 Init.get() == E->getInit() &&
14432 !ExprChanged)
14433 return E;
14434
14435 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
14436 E->getEqualOrColonLoc(),
14437 E->usesGNUSyntax(), Init.get());
14438}
14439
14440// Seems that if TransformInitListExpr() only works on the syntactic form of an
14441// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
14442template<typename Derived>
14446 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
14447 "initializer");
14448 return ExprError();
14449}
14450
14451template<typename Derived>
14454 NoInitExpr *E) {
14455 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
14456 return ExprError();
14457}
14458
14459template<typename Derived>
14462 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
14463 return ExprError();
14464}
14465
14466template<typename Derived>
14469 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
14470 return ExprError();
14471}
14472
14473template<typename Derived>
14477 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
14478
14479 // FIXME: Will we ever have proper type location here? Will we actually
14480 // need to transform the type?
14481 QualType T = getDerived().TransformType(E->getType());
14482 if (T.isNull())
14483 return ExprError();
14484
14485 if (!getDerived().AlwaysRebuild() &&
14486 T == E->getType())
14487 return E;
14488
14489 return getDerived().RebuildImplicitValueInitExpr(T);
14490}
14491
14492template<typename Derived>
14495 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
14496 if (!TInfo)
14497 return ExprError();
14498
14499 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14500 if (SubExpr.isInvalid())
14501 return ExprError();
14502
14503 if (!getDerived().AlwaysRebuild() &&
14504 TInfo == E->getWrittenTypeInfo() &&
14505 SubExpr.get() == E->getSubExpr())
14506 return E;
14507
14508 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
14509 TInfo, E->getRParenLoc());
14510}
14511
14512template<typename Derived>
14515 bool ArgumentChanged = false;
14517 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
14518 &ArgumentChanged))
14519 return ExprError();
14520
14521 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
14522 Inits,
14523 E->getRParenLoc());
14524}
14525
14526/// Transform an address-of-label expression.
14527///
14528/// By default, the transformation of an address-of-label expression always
14529/// rebuilds the expression, so that the label identifier can be resolved to
14530/// the corresponding label statement by semantic analysis.
14531template<typename Derived>
14534 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
14535 E->getLabel());
14536 if (!LD)
14537 return ExprError();
14538
14539 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
14540 cast<LabelDecl>(LD));
14541}
14542
14543template<typename Derived>
14546 SemaRef.ActOnStartStmtExpr();
14547 StmtResult SubStmt
14548 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
14549 if (SubStmt.isInvalid()) {
14550 SemaRef.ActOnStmtExprError();
14551 return ExprError();
14552 }
14553
14554 unsigned OldDepth = E->getTemplateDepth();
14555 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
14556
14557 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
14558 SubStmt.get() == E->getSubStmt()) {
14559 // Calling this an 'error' is unintuitive, but it does the right thing.
14560 SemaRef.ActOnStmtExprError();
14561 return SemaRef.MaybeBindToTemporary(E);
14562 }
14563
14564 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
14565 E->getRParenLoc(), NewDepth);
14566}
14567
14568template<typename Derived>
14571 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14572 if (Cond.isInvalid())
14573 return ExprError();
14574
14575 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14576 if (LHS.isInvalid())
14577 return ExprError();
14578
14579 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14580 if (RHS.isInvalid())
14581 return ExprError();
14582
14583 if (!getDerived().AlwaysRebuild() &&
14584 Cond.get() == E->getCond() &&
14585 LHS.get() == E->getLHS() &&
14586 RHS.get() == E->getRHS())
14587 return E;
14588
14589 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
14590 Cond.get(), LHS.get(), RHS.get(),
14591 E->getRParenLoc());
14592}
14593
14594template<typename Derived>
14597 return E;
14598}
14599
14600template<typename Derived>
14603 switch (E->getOperator()) {
14604 case OO_New:
14605 case OO_Delete:
14606 case OO_Array_New:
14607 case OO_Array_Delete:
14608 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14609
14610 case OO_Subscript:
14611 case OO_Call: {
14612 // This is a call to an object's operator().
14613 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14614
14615 // Transform the object itself.
14616 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14617 if (Object.isInvalid())
14618 return ExprError();
14619
14620 // FIXME: Poor location information. Also, if the location for the end of
14621 // the token is within a macro expansion, getLocForEndOfToken() will return
14622 // an invalid source location. If that happens and we have an otherwise
14623 // valid end location, use the valid one instead of the invalid one.
14624 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
14625 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
14626 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
14627 FakeLParenLoc = EndLoc;
14628
14629 // Transform the call arguments.
14631 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
14632 Args))
14633 return ExprError();
14634
14635 if (E->getOperator() == OO_Subscript)
14636 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
14637 Args, E->getEndLoc());
14638
14639 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
14640 E->getEndLoc());
14641 }
14642
14643#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
14644 case OO_##Name: \
14645 break;
14646
14647#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
14648#include "clang/Basic/OperatorKinds.def"
14649
14650 case OO_Conditional:
14651 llvm_unreachable("conditional operator is not actually overloadable");
14652
14653 case OO_None:
14655 llvm_unreachable("not an overloaded operator?");
14656 }
14657
14659 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
14660 First = getDerived().TransformAddressOfOperand(E->getArg(0));
14661 else
14662 First = getDerived().TransformExpr(E->getArg(0));
14663 if (First.isInvalid())
14664 return ExprError();
14665
14666 ExprResult Second;
14667 if (E->getNumArgs() == 2) {
14668 Second =
14669 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
14670 if (Second.isInvalid())
14671 return ExprError();
14672 }
14673
14674 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14675 FPOptionsOverride NewOverrides(E->getFPFeatures());
14676 getSema().CurFPFeatures =
14677 NewOverrides.applyOverrides(getSema().getLangOpts());
14678 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14679
14680 Expr *Callee = E->getCallee();
14681 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
14682 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
14684 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
14685 return ExprError();
14686
14687 return getDerived().RebuildCXXOperatorCallExpr(
14688 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14689 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
14690 }
14691
14692 UnresolvedSet<1> Functions;
14693 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
14694 Callee = ICE->getSubExprAsWritten();
14695 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
14696 ValueDecl *VD = cast_or_null<ValueDecl>(
14697 getDerived().TransformDecl(DR->getLocation(), DR));
14698 if (!VD)
14699 return ExprError();
14700
14701 if (!isa<CXXMethodDecl>(VD))
14702 Functions.addDecl(VD);
14703
14704 return getDerived().RebuildCXXOperatorCallExpr(
14705 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14706 /*RequiresADL=*/false, Functions, First.get(), Second.get());
14707}
14708
14709template<typename Derived>
14712 return getDerived().TransformCallExpr(E);
14713}
14714
14715template <typename Derived>
14717 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
14718 getSema().CurContext != E->getParentContext();
14719
14720 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
14721 return E;
14722
14723 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
14724 E->getBeginLoc(), E->getEndLoc(),
14725 getSema().CurContext);
14726}
14727
14728template <typename Derived>
14730 return E;
14731}
14732
14733template<typename Derived>
14736 // Transform the callee.
14737 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14738 if (Callee.isInvalid())
14739 return ExprError();
14740
14741 // Transform exec config.
14742 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
14743 if (EC.isInvalid())
14744 return ExprError();
14745
14746 // Transform arguments.
14747 bool ArgChanged = false;
14749 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14750 &ArgChanged))
14751 return ExprError();
14752
14753 if (!getDerived().AlwaysRebuild() &&
14754 Callee.get() == E->getCallee() &&
14755 !ArgChanged)
14756 return SemaRef.MaybeBindToTemporary(E);
14757
14758 // FIXME: Wrong source location information for the '('.
14759 SourceLocation FakeLParenLoc
14760 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14761 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14762 Args,
14763 E->getRParenLoc(), EC.get());
14764}
14765
14766template<typename Derived>
14769 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14770 if (!Type)
14771 return ExprError();
14772
14773 ExprResult SubExpr
14774 = getDerived().TransformExpr(E->getSubExprAsWritten());
14775 if (SubExpr.isInvalid())
14776 return ExprError();
14777
14778 if (!getDerived().AlwaysRebuild() &&
14779 Type == E->getTypeInfoAsWritten() &&
14780 SubExpr.get() == E->getSubExpr())
14781 return E;
14782 return getDerived().RebuildCXXNamedCastExpr(
14785 // FIXME. this should be '(' location
14786 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
14787}
14788
14789template<typename Derived>
14792 TypeSourceInfo *TSI =
14793 getDerived().TransformType(BCE->getTypeInfoAsWritten());
14794 if (!TSI)
14795 return ExprError();
14796
14797 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
14798 if (Sub.isInvalid())
14799 return ExprError();
14800
14801 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
14802 Sub.get(), BCE->getEndLoc());
14803}
14804
14805template<typename Derived>
14807TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
14808 return getDerived().TransformCXXNamedCastExpr(E);
14809}
14810
14811template<typename Derived>
14814 return getDerived().TransformCXXNamedCastExpr(E);
14815}
14816
14817template<typename Derived>
14821 return getDerived().TransformCXXNamedCastExpr(E);
14822}
14823
14824template<typename Derived>
14827 return getDerived().TransformCXXNamedCastExpr(E);
14828}
14829
14830template<typename Derived>
14833 return getDerived().TransformCXXNamedCastExpr(E);
14834}
14835
14836template<typename Derived>
14841 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
14842 if (!Type)
14843 return ExprError();
14844
14845 ExprResult SubExpr
14846 = getDerived().TransformExpr(E->getSubExprAsWritten());
14847 if (SubExpr.isInvalid())
14848 return ExprError();
14849
14850 if (!getDerived().AlwaysRebuild() &&
14851 Type == E->getTypeInfoAsWritten() &&
14852 SubExpr.get() == E->getSubExpr())
14853 return E;
14854
14855 return getDerived().RebuildCXXFunctionalCastExpr(Type,
14856 E->getLParenLoc(),
14857 SubExpr.get(),
14858 E->getRParenLoc(),
14859 E->isListInitialization());
14860}
14861
14862template<typename Derived>
14865 if (E->isTypeOperand()) {
14866 TypeSourceInfo *TInfo
14867 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14868 if (!TInfo)
14869 return ExprError();
14870
14871 if (!getDerived().AlwaysRebuild() &&
14872 TInfo == E->getTypeOperandSourceInfo())
14873 return E;
14874
14875 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14876 TInfo, E->getEndLoc());
14877 }
14878
14879 // Typeid's operand is an unevaluated context, unless it's a polymorphic
14880 // type. We must not unilaterally enter unevaluated context here, as then
14881 // semantic processing can re-transform an already transformed operand.
14882 Expr *Op = E->getExprOperand();
14884 if (E->isGLValue()) {
14885 QualType OpType = Op->getType();
14886 if (auto *RD = OpType->getAsCXXRecordDecl()) {
14887 if (SemaRef.RequireCompleteType(E->getBeginLoc(), OpType,
14888 diag::err_incomplete_typeid))
14889 return ExprError();
14890
14891 if (RD->isPolymorphic())
14892 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
14893 }
14894 }
14895
14898
14899 ExprResult SubExpr = getDerived().TransformExpr(Op);
14900 if (SubExpr.isInvalid())
14901 return ExprError();
14902
14903 if (!getDerived().AlwaysRebuild() &&
14904 SubExpr.get() == E->getExprOperand())
14905 return E;
14906
14907 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
14908 SubExpr.get(), E->getEndLoc());
14909}
14910
14911template<typename Derived>
14914 if (E->isTypeOperand()) {
14915 TypeSourceInfo *TInfo
14916 = getDerived().TransformType(E->getTypeOperandSourceInfo());
14917 if (!TInfo)
14918 return ExprError();
14919
14920 if (!getDerived().AlwaysRebuild() &&
14921 TInfo == E->getTypeOperandSourceInfo())
14922 return E;
14923
14924 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14925 TInfo, E->getEndLoc());
14926 }
14927
14930
14931 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
14932 if (SubExpr.isInvalid())
14933 return ExprError();
14934
14935 if (!getDerived().AlwaysRebuild() &&
14936 SubExpr.get() == E->getExprOperand())
14937 return E;
14938
14939 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
14940 SubExpr.get(), E->getEndLoc());
14941}
14942
14943template<typename Derived>
14946 return E;
14947}
14948
14949template<typename Derived>
14953 return E;
14954}
14955
14956template<typename Derived>
14959
14960 // In lambdas, the qualifiers of the type depends of where in
14961 // the call operator `this` appear, and we do not have a good way to
14962 // rebuild this information, so we transform the type.
14963 //
14964 // In other contexts, the type of `this` may be overrided
14965 // for type deduction, so we need to recompute it.
14966 //
14967 // Always recompute the type if we're in the body of a lambda, and
14968 // 'this' is dependent on a lambda's explicit object parameter; we
14969 // also need to always rebuild the expression in this case to clear
14970 // the flag.
14971 QualType T = [&]() {
14972 auto &S = getSema();
14973 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
14974 return S.getCurrentThisType();
14975 if (S.getCurLambda())
14976 return getDerived().TransformType(E->getType());
14977 return S.getCurrentThisType();
14978 }();
14979
14980 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
14981 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
14982 // Mark it referenced in the new context regardless.
14983 // FIXME: this is a bit instantiation-specific.
14984 getSema().MarkThisReferenced(E);
14985 return E;
14986 }
14987
14988 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
14989}
14990
14991template<typename Derived>
14994 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14995 if (SubExpr.isInvalid())
14996 return ExprError();
14997
14998 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
14999
15000 if (!getDerived().AlwaysRebuild() &&
15001 SubExpr.get() == E->getSubExpr())
15002 return E;
15003
15004 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
15005 E->isThrownVariableInScope());
15006}
15007
15008template<typename Derived>
15011 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
15012 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
15013 if (!Param)
15014 return ExprError();
15015
15016 ExprResult InitRes;
15017 if (E->hasRewrittenInit()) {
15018 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
15019 if (InitRes.isInvalid())
15020 return ExprError();
15021 }
15022
15023 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
15024 E->getUsedContext() == SemaRef.CurContext &&
15025 InitRes.get() == E->getRewrittenExpr())
15026 return E;
15027
15028 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
15029 InitRes.get());
15030}
15031
15032template<typename Derived>
15035 FieldDecl *Field = cast_or_null<FieldDecl>(
15036 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
15037 if (!Field)
15038 return ExprError();
15039
15040 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
15041 E->getUsedContext() == SemaRef.CurContext)
15042 return E;
15043
15044 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
15045}
15046
15047template<typename Derived>
15051 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
15052 if (!T)
15053 return ExprError();
15054
15055 if (!getDerived().AlwaysRebuild() &&
15056 T == E->getTypeSourceInfo())
15057 return E;
15058
15059 return getDerived().RebuildCXXScalarValueInitExpr(T,
15060 /*FIXME:*/T->getTypeLoc().getEndLoc(),
15061 E->getRParenLoc());
15062}
15063
15064template<typename Derived>
15067 // Transform the type that we're allocating
15068 TypeSourceInfo *AllocTypeInfo =
15069 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
15070 if (!AllocTypeInfo)
15071 return ExprError();
15072
15073 // Transform the size of the array we're allocating (if any).
15074 std::optional<Expr *> ArraySize;
15075 if (E->isArray()) {
15076 ExprResult NewArraySize;
15077 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
15078 NewArraySize = getDerived().TransformExpr(*OldArraySize);
15079 if (NewArraySize.isInvalid())
15080 return ExprError();
15081 }
15082 ArraySize = NewArraySize.get();
15083 }
15084
15085 // Transform the placement arguments (if any).
15086 bool ArgumentChanged = false;
15087 SmallVector<Expr*, 8> PlacementArgs;
15088 if (getDerived().TransformExprs(E->getPlacementArgs(),
15089 E->getNumPlacementArgs(), true,
15090 PlacementArgs, &ArgumentChanged))
15091 return ExprError();
15092
15093 // Transform the initializer (if any).
15094 Expr *OldInit = E->getInitializer();
15095 ExprResult NewInit;
15096 if (OldInit)
15097 NewInit = getDerived().TransformInitializer(OldInit, true);
15098 if (NewInit.isInvalid())
15099 return ExprError();
15100
15101 // Transform new operator and delete operator.
15102 FunctionDecl *OperatorNew = nullptr;
15103 if (E->getOperatorNew()) {
15104 OperatorNew = cast_or_null<FunctionDecl>(
15105 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
15106 if (!OperatorNew)
15107 return ExprError();
15108 }
15109
15110 FunctionDecl *OperatorDelete = nullptr;
15111 if (E->getOperatorDelete()) {
15112 OperatorDelete = cast_or_null<FunctionDecl>(
15113 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15114 if (!OperatorDelete)
15115 return ExprError();
15116 }
15117
15118 if (!getDerived().AlwaysRebuild() &&
15119 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
15120 ArraySize == E->getArraySize() &&
15121 NewInit.get() == OldInit &&
15122 OperatorNew == E->getOperatorNew() &&
15123 OperatorDelete == E->getOperatorDelete() &&
15124 !ArgumentChanged) {
15125 // Mark any declarations we need as referenced.
15126 // FIXME: instantiation-specific.
15127 if (OperatorNew)
15128 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
15129 if (OperatorDelete)
15130 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15131
15132 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
15133 QualType ElementType
15134 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
15135 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
15137 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
15138 }
15139 }
15140
15141 return E;
15142 }
15143
15144 QualType AllocType = AllocTypeInfo->getType();
15145 if (!ArraySize) {
15146 // If no array size was specified, but the new expression was
15147 // instantiated with an array type (e.g., "new T" where T is
15148 // instantiated with "int[4]"), extract the outer bound from the
15149 // array type as our array size. We do this with constant and
15150 // dependently-sized array types.
15151 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
15152 if (!ArrayT) {
15153 // Do nothing
15154 } else if (const ConstantArrayType *ConsArrayT
15155 = dyn_cast<ConstantArrayType>(ArrayT)) {
15156 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
15157 SemaRef.Context.getSizeType(),
15158 /*FIXME:*/ E->getBeginLoc());
15159 AllocType = ConsArrayT->getElementType();
15160 } else if (const DependentSizedArrayType *DepArrayT
15161 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
15162 if (DepArrayT->getSizeExpr()) {
15163 ArraySize = DepArrayT->getSizeExpr();
15164 AllocType = DepArrayT->getElementType();
15165 }
15166 }
15167 }
15168
15169 return getDerived().RebuildCXXNewExpr(
15170 E->getBeginLoc(), E->isGlobalNew(),
15171 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
15172 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
15173 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
15174}
15175
15176template<typename Derived>
15179 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
15180 if (Operand.isInvalid())
15181 return ExprError();
15182
15183 // Transform the delete operator, if known.
15184 FunctionDecl *OperatorDelete = nullptr;
15185 if (E->getOperatorDelete()) {
15186 OperatorDelete = cast_or_null<FunctionDecl>(
15187 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15188 if (!OperatorDelete)
15189 return ExprError();
15190 }
15191
15192 if (!getDerived().AlwaysRebuild() &&
15193 Operand.get() == E->getArgument() &&
15194 OperatorDelete == E->getOperatorDelete()) {
15195 // Mark any declarations we need as referenced.
15196 // FIXME: instantiation-specific.
15197 if (OperatorDelete)
15198 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15199
15200 if (!E->getArgument()->isTypeDependent()) {
15202 E->getDestroyedType());
15203 if (auto *Record = Destroyed->getAsCXXRecordDecl())
15204 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15205 SemaRef.LookupDestructor(Record));
15206 }
15207
15208 return E;
15209 }
15210
15211 return getDerived().RebuildCXXDeleteExpr(
15212 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
15213}
15214
15215template<typename Derived>
15219 ExprResult Base = getDerived().TransformExpr(E->getBase());
15220 if (Base.isInvalid())
15221 return ExprError();
15222
15223 ParsedType ObjectTypePtr;
15224 bool MayBePseudoDestructor = false;
15225 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15226 E->getOperatorLoc(),
15227 E->isArrow()? tok::arrow : tok::period,
15228 ObjectTypePtr,
15229 MayBePseudoDestructor);
15230 if (Base.isInvalid())
15231 return ExprError();
15232
15233 QualType ObjectType = ObjectTypePtr.get();
15234 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
15235 if (QualifierLoc) {
15236 QualifierLoc
15237 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
15238 if (!QualifierLoc)
15239 return ExprError();
15240 }
15241 CXXScopeSpec SS;
15242 SS.Adopt(QualifierLoc);
15243
15245 if (E->getDestroyedTypeInfo()) {
15246 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
15247 E->getDestroyedTypeInfo(), ObjectType,
15248 /*FirstQualifierInScope=*/nullptr);
15249 if (!DestroyedTypeInfo)
15250 return ExprError();
15251 Destroyed = DestroyedTypeInfo;
15252 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
15253 // We aren't likely to be able to resolve the identifier down to a type
15254 // now anyway, so just retain the identifier.
15255 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
15256 E->getDestroyedTypeLoc());
15257 } else {
15258 // Look for a destructor known with the given name.
15259 ParsedType T = SemaRef.getDestructorName(
15260 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
15261 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
15262 if (!T)
15263 return ExprError();
15264
15265 Destroyed
15267 E->getDestroyedTypeLoc());
15268 }
15269
15270 TypeSourceInfo *ScopeTypeInfo = nullptr;
15271 if (E->getScopeTypeInfo()) {
15272 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
15273 E->getScopeTypeInfo(), ObjectType, nullptr);
15274 if (!ScopeTypeInfo)
15275 return ExprError();
15276 }
15277
15278 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
15279 E->getOperatorLoc(),
15280 E->isArrow(),
15281 SS,
15282 ScopeTypeInfo,
15283 E->getColonColonLoc(),
15284 E->getTildeLoc(),
15285 Destroyed);
15286}
15287
15288template <typename Derived>
15290 bool RequiresADL,
15291 LookupResult &R) {
15292 // Transform all the decls.
15293 bool AllEmptyPacks = true;
15294 for (auto *OldD : Old->decls()) {
15295 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
15296 if (!InstD) {
15297 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
15298 // This can happen because of dependent hiding.
15299 if (isa<UsingShadowDecl>(OldD))
15300 continue;
15301 else {
15302 R.clear();
15303 return true;
15304 }
15305 }
15306
15307 // Expand using pack declarations.
15308 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
15309 ArrayRef<NamedDecl*> Decls = SingleDecl;
15310 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
15311 Decls = UPD->expansions();
15312
15313 // Expand using declarations.
15314 for (auto *D : Decls) {
15315 if (auto *UD = dyn_cast<UsingDecl>(D)) {
15316 for (auto *SD : UD->shadows())
15317 R.addDecl(SD);
15318 } else {
15319 R.addDecl(D);
15320 }
15321 }
15322
15323 AllEmptyPacks &= Decls.empty();
15324 }
15325
15326 // C++ [temp.res]/8.4.2:
15327 // The program is ill-formed, no diagnostic required, if [...] lookup for
15328 // a name in the template definition found a using-declaration, but the
15329 // lookup in the corresponding scope in the instantiation odoes not find
15330 // any declarations because the using-declaration was a pack expansion and
15331 // the corresponding pack is empty
15332 if (AllEmptyPacks && !RequiresADL) {
15333 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
15334 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
15335 return true;
15336 }
15337
15338 // Resolve a kind, but don't do any further analysis. If it's
15339 // ambiguous, the callee needs to deal with it.
15340 R.resolveKind();
15341
15342 if (Old->hasTemplateKeyword() && !R.empty()) {
15343 NamedDecl *FoundDecl = R.getRepresentativeDecl()->getUnderlyingDecl();
15344 getSema().FilterAcceptableTemplateNames(R,
15345 /*AllowFunctionTemplates=*/true,
15346 /*AllowDependent=*/true);
15347 if (R.empty()) {
15348 // If a 'template' keyword was used, a lookup that finds only non-template
15349 // names is an error.
15350 getSema().Diag(R.getNameLoc(),
15351 diag::err_template_kw_refers_to_non_template)
15352 << R.getLookupName() << Old->getQualifierLoc().getSourceRange()
15353 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
15354 getSema().Diag(FoundDecl->getLocation(),
15355 diag::note_template_kw_refers_to_non_template)
15356 << R.getLookupName();
15357 return true;
15358 }
15359 }
15360
15361 return false;
15362}
15363
15364template <typename Derived>
15369
15370template <typename Derived>
15373 bool IsAddressOfOperand) {
15374 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
15376
15377 // Transform the declaration set.
15378 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
15379 return ExprError();
15380
15381 // Rebuild the nested-name qualifier, if present.
15382 CXXScopeSpec SS;
15383 if (Old->getQualifierLoc()) {
15384 NestedNameSpecifierLoc QualifierLoc
15385 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15386 if (!QualifierLoc)
15387 return ExprError();
15388
15389 SS.Adopt(QualifierLoc);
15390 }
15391
15392 if (Old->getNamingClass()) {
15393 CXXRecordDecl *NamingClass
15394 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
15395 Old->getNameLoc(),
15396 Old->getNamingClass()));
15397 if (!NamingClass) {
15398 R.clear();
15399 return ExprError();
15400 }
15401
15402 R.setNamingClass(NamingClass);
15403 }
15404
15405 // Rebuild the template arguments, if any.
15406 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15407 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
15408 if (Old->hasExplicitTemplateArgs() &&
15409 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15410 Old->getNumTemplateArgs(),
15411 TransArgs)) {
15412 R.clear();
15413 return ExprError();
15414 }
15415
15416 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
15417 // a non-static data member is named in an unevaluated operand, or when
15418 // a member is named in a dependent class scope function template explicit
15419 // specialization that is neither declared static nor with an explicit object
15420 // parameter.
15421 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
15422 return SemaRef.BuildPossibleImplicitMemberExpr(
15423 SS, TemplateKWLoc, R,
15424 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
15425 /*S=*/nullptr);
15426
15427 // If we have neither explicit template arguments, nor the template keyword,
15428 // it's a normal declaration name or member reference.
15429 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
15430 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
15431
15432 // If we have template arguments, then rebuild the template-id expression.
15433 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
15434 Old->requiresADL(), &TransArgs);
15435}
15436
15437template<typename Derived>
15440 bool ArgChanged = false;
15442 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
15443 TypeSourceInfo *From = E->getArg(I);
15444 TypeLoc FromTL = From->getTypeLoc();
15445 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
15446 TypeLocBuilder TLB;
15447 TLB.reserve(FromTL.getFullDataSize());
15448 QualType To = getDerived().TransformType(TLB, FromTL);
15449 if (To.isNull())
15450 return ExprError();
15451
15452 if (To == From->getType())
15453 Args.push_back(From);
15454 else {
15455 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15456 ArgChanged = true;
15457 }
15458 continue;
15459 }
15460
15461 ArgChanged = true;
15462
15463 // We have a pack expansion. Instantiate it.
15464 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
15465 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
15467 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
15468
15469 // Determine whether the set of unexpanded parameter packs can and should
15470 // be expanded.
15471 bool Expand = true;
15472 bool RetainExpansion = false;
15473 UnsignedOrNone OrigNumExpansions =
15474 ExpansionTL.getTypePtr()->getNumExpansions();
15475 UnsignedOrNone NumExpansions = OrigNumExpansions;
15476 if (getDerived().TryExpandParameterPacks(
15477 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
15478 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15479 RetainExpansion, NumExpansions))
15480 return ExprError();
15481
15482 if (!Expand) {
15483 // The transform has determined that we should perform a simple
15484 // transformation on the pack expansion, producing another pack
15485 // expansion.
15486 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
15487
15488 TypeLocBuilder TLB;
15489 TLB.reserve(From->getTypeLoc().getFullDataSize());
15490
15491 QualType To = getDerived().TransformType(TLB, PatternTL);
15492 if (To.isNull())
15493 return ExprError();
15494
15495 To = getDerived().RebuildPackExpansionType(To,
15496 PatternTL.getSourceRange(),
15497 ExpansionTL.getEllipsisLoc(),
15498 NumExpansions);
15499 if (To.isNull())
15500 return ExprError();
15501
15502 PackExpansionTypeLoc ToExpansionTL
15503 = TLB.push<PackExpansionTypeLoc>(To);
15504 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15505 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15506 continue;
15507 }
15508
15509 // Expand the pack expansion by substituting for each argument in the
15510 // pack(s).
15511 for (unsigned I = 0; I != *NumExpansions; ++I) {
15512 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
15513 TypeLocBuilder TLB;
15514 TLB.reserve(PatternTL.getFullDataSize());
15515 QualType To = getDerived().TransformType(TLB, PatternTL);
15516 if (To.isNull())
15517 return ExprError();
15518
15519 if (To->containsUnexpandedParameterPack()) {
15520 To = getDerived().RebuildPackExpansionType(To,
15521 PatternTL.getSourceRange(),
15522 ExpansionTL.getEllipsisLoc(),
15523 NumExpansions);
15524 if (To.isNull())
15525 return ExprError();
15526
15527 PackExpansionTypeLoc ToExpansionTL
15528 = TLB.push<PackExpansionTypeLoc>(To);
15529 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15530 }
15531
15532 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15533 }
15534
15535 if (!RetainExpansion)
15536 continue;
15537
15538 // If we're supposed to retain a pack expansion, do so by temporarily
15539 // forgetting the partially-substituted parameter pack.
15540 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15541
15542 TypeLocBuilder TLB;
15543 TLB.reserve(From->getTypeLoc().getFullDataSize());
15544
15545 QualType To = getDerived().TransformType(TLB, PatternTL);
15546 if (To.isNull())
15547 return ExprError();
15548
15549 To = getDerived().RebuildPackExpansionType(To,
15550 PatternTL.getSourceRange(),
15551 ExpansionTL.getEllipsisLoc(),
15552 NumExpansions);
15553 if (To.isNull())
15554 return ExprError();
15555
15556 PackExpansionTypeLoc ToExpansionTL
15557 = TLB.push<PackExpansionTypeLoc>(To);
15558 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15559 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15560 }
15561
15562 if (!getDerived().AlwaysRebuild() && !ArgChanged)
15563 return E;
15564
15565 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
15566 E->getEndLoc());
15567}
15568
15569template<typename Derived>
15573 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
15574 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
15575 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15576 Old->NumTemplateArgs, TransArgs))
15577 return ExprError();
15578
15579 return getDerived().RebuildConceptSpecializationExpr(
15580 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
15581 E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(),
15582 &TransArgs);
15583}
15584
15585template<typename Derived>
15588 SmallVector<ParmVarDecl*, 4> TransParams;
15589 SmallVector<QualType, 4> TransParamTypes;
15590 Sema::ExtParameterInfoBuilder ExtParamInfos;
15591
15592 // C++2a [expr.prim.req]p2
15593 // Expressions appearing within a requirement-body are unevaluated operands.
15597
15599 getSema().Context, getSema().CurContext,
15600 E->getBody()->getBeginLoc());
15601
15602 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
15603
15604 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
15605 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
15606 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
15607
15608 for (ParmVarDecl *Param : TransParams)
15609 if (Param)
15610 Param->setDeclContext(Body);
15611
15612 // On failure to transform, TransformRequiresTypeParams returns an expression
15613 // in the event that the transformation of the type params failed in some way.
15614 // It is expected that this will result in a 'not satisfied' Requires clause
15615 // when instantiating.
15616 if (!TypeParamResult.isUnset())
15617 return TypeParamResult;
15618
15620 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
15621 TransReqs))
15622 return ExprError();
15623
15624 for (concepts::Requirement *Req : TransReqs) {
15625 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
15626 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
15627 ER->getReturnTypeRequirement()
15628 .getTypeConstraintTemplateParameterList()->getParam(0)
15629 ->setDeclContext(Body);
15630 }
15631 }
15632 }
15633
15634 return getDerived().RebuildRequiresExpr(
15635 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
15636 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
15637}
15638
15639template<typename Derived>
15643 for (concepts::Requirement *Req : Reqs) {
15644 concepts::Requirement *TransReq = nullptr;
15645 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
15646 TransReq = getDerived().TransformTypeRequirement(TypeReq);
15647 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
15648 TransReq = getDerived().TransformExprRequirement(ExprReq);
15649 else
15650 TransReq = getDerived().TransformNestedRequirement(
15652 if (!TransReq)
15653 return true;
15654 Transformed.push_back(TransReq);
15655 }
15656 return false;
15657}
15658
15659template<typename Derived>
15663 if (Req->isSubstitutionFailure()) {
15664 if (getDerived().AlwaysRebuild())
15665 return getDerived().RebuildTypeRequirement(
15667 return Req;
15668 }
15669 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
15670 if (!TransType)
15671 return nullptr;
15672 return getDerived().RebuildTypeRequirement(TransType);
15673}
15674
15675template<typename Derived>
15678 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
15679 if (Req->isExprSubstitutionFailure())
15680 TransExpr = Req->getExprSubstitutionDiagnostic();
15681 else {
15682 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
15683 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
15684 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
15685 if (TransExprRes.isInvalid())
15686 return nullptr;
15687 TransExpr = TransExprRes.get();
15688 }
15689
15690 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
15691 const auto &RetReq = Req->getReturnTypeRequirement();
15692 if (RetReq.isEmpty())
15693 TransRetReq.emplace();
15694 else if (RetReq.isSubstitutionFailure())
15695 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
15696 else if (RetReq.isTypeConstraint()) {
15697 TemplateParameterList *OrigTPL =
15698 RetReq.getTypeConstraintTemplateParameterList();
15700 getDerived().TransformTemplateParameterList(OrigTPL);
15701 if (!TPL)
15702 return nullptr;
15703 TransRetReq.emplace(TPL);
15704 }
15705 assert(TransRetReq && "All code paths leading here must set TransRetReq");
15706 if (Expr *E = dyn_cast<Expr *>(TransExpr))
15707 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
15708 Req->getNoexceptLoc(),
15709 std::move(*TransRetReq));
15710 return getDerived().RebuildExprRequirement(
15712 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
15713}
15714
15715template<typename Derived>
15719 if (Req->hasInvalidConstraint()) {
15720 if (getDerived().AlwaysRebuild())
15721 return getDerived().RebuildNestedRequirement(
15723 return Req;
15724 }
15725 ExprResult TransConstraint =
15726 getDerived().TransformExpr(Req->getConstraintExpr());
15727 if (TransConstraint.isInvalid())
15728 return nullptr;
15729 return getDerived().RebuildNestedRequirement(TransConstraint.get());
15730}
15731
15732template<typename Derived>
15735 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
15736 if (!T)
15737 return ExprError();
15738
15739 if (!getDerived().AlwaysRebuild() &&
15740 T == E->getQueriedTypeSourceInfo())
15741 return E;
15742
15743 ExprResult SubExpr;
15744 {
15747 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
15748 if (SubExpr.isInvalid())
15749 return ExprError();
15750 }
15751
15752 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
15753 SubExpr.get(), E->getEndLoc());
15754}
15755
15756template<typename Derived>
15759 ExprResult SubExpr;
15760 {
15763 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
15764 if (SubExpr.isInvalid())
15765 return ExprError();
15766
15767 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
15768 return E;
15769 }
15770
15771 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
15772 SubExpr.get(), E->getEndLoc());
15773}
15774
15775template <typename Derived>
15777 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
15778 TypeSourceInfo **RecoveryTSI) {
15779 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
15780 DRE, AddrTaken, RecoveryTSI);
15781
15782 // Propagate both errors and recovered types, which return ExprEmpty.
15783 if (!NewDRE.isUsable())
15784 return NewDRE;
15785
15786 // We got an expr, wrap it up in parens.
15787 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
15788 return PE;
15789 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
15790 PE->getRParen());
15791}
15792
15793template <typename Derived>
15799
15800template <typename Derived>
15802 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
15803 TypeSourceInfo **RecoveryTSI) {
15804 assert(E->getQualifierLoc());
15805 NestedNameSpecifierLoc QualifierLoc =
15806 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
15807 if (!QualifierLoc)
15808 return ExprError();
15809 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
15810
15811 // TODO: If this is a conversion-function-id, verify that the
15812 // destination type name (if present) resolves the same way after
15813 // instantiation as it did in the local scope.
15814
15815 DeclarationNameInfo NameInfo =
15816 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
15817 if (!NameInfo.getName())
15818 return ExprError();
15819
15820 if (!E->hasExplicitTemplateArgs()) {
15821 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
15822 // Note: it is sufficient to compare the Name component of NameInfo:
15823 // if name has not changed, DNLoc has not changed either.
15824 NameInfo.getName() == E->getDeclName())
15825 return E;
15826
15827 return getDerived().RebuildDependentScopeDeclRefExpr(
15828 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
15829 IsAddressOfOperand, RecoveryTSI);
15830 }
15831
15832 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
15833 if (getDerived().TransformTemplateArguments(
15834 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
15835 return ExprError();
15836
15837 return getDerived().RebuildDependentScopeDeclRefExpr(
15838 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
15839 RecoveryTSI);
15840}
15841
15842template<typename Derived>
15845 // CXXConstructExprs other than for list-initialization and
15846 // CXXTemporaryObjectExpr are always implicit, so when we have
15847 // a 1-argument construction we just transform that argument.
15848 if (getDerived().AllowSkippingCXXConstructExpr() &&
15849 ((E->getNumArgs() == 1 ||
15850 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
15851 (!getDerived().DropCallArgument(E->getArg(0))) &&
15852 !E->isListInitialization()))
15853 return getDerived().TransformInitializer(E->getArg(0),
15854 /*DirectInit*/ false);
15855
15856 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
15857
15858 QualType T = getDerived().TransformType(E->getType());
15859 if (T.isNull())
15860 return ExprError();
15861
15862 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15863 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15864 if (!Constructor)
15865 return ExprError();
15866
15867 bool ArgumentChanged = false;
15869 {
15872 E->isListInitialization());
15873 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15874 &ArgumentChanged))
15875 return ExprError();
15876 }
15877
15878 if (!getDerived().AlwaysRebuild() &&
15879 T == E->getType() &&
15880 Constructor == E->getConstructor() &&
15881 !ArgumentChanged) {
15882 // Mark the constructor as referenced.
15883 // FIXME: Instantiation-specific
15884 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15885 return E;
15886 }
15887
15888 return getDerived().RebuildCXXConstructExpr(
15889 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
15890 E->hadMultipleCandidates(), E->isListInitialization(),
15891 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
15892 E->getConstructionKind(), E->getParenOrBraceRange());
15893}
15894
15895template<typename Derived>
15898 QualType T = getDerived().TransformType(E->getType());
15899 if (T.isNull())
15900 return ExprError();
15901
15902 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15903 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15904 if (!Constructor)
15905 return ExprError();
15906
15907 if (!getDerived().AlwaysRebuild() &&
15908 T == E->getType() &&
15909 Constructor == E->getConstructor()) {
15910 // Mark the constructor as referenced.
15911 // FIXME: Instantiation-specific
15912 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15913 return E;
15914 }
15915
15916 return getDerived().RebuildCXXInheritedCtorInitExpr(
15917 T, E->getLocation(), Constructor,
15918 E->constructsVBase(), E->inheritedFromVBase());
15919}
15920
15921/// Transform a C++ temporary-binding expression.
15922///
15923/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
15924/// transform the subexpression and return that.
15925template<typename Derived>
15928 if (auto *Dtor = E->getTemporary()->getDestructor())
15929 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15930 const_cast<CXXDestructorDecl *>(Dtor));
15931 return getDerived().TransformExpr(E->getSubExpr());
15932}
15933
15934/// Transform a C++ expression that contains cleanups that should
15935/// be run after the expression is evaluated.
15936///
15937/// Since ExprWithCleanups nodes are implicitly generated, we
15938/// just transform the subexpression and return that.
15939template<typename Derived>
15942 return getDerived().TransformExpr(E->getSubExpr());
15943}
15944
15945template<typename Derived>
15949 TypeSourceInfo *T =
15950 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
15951 if (!T)
15952 return ExprError();
15953
15954 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
15955 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
15956 if (!Constructor)
15957 return ExprError();
15958
15959 bool ArgumentChanged = false;
15961 Args.reserve(E->getNumArgs());
15962 {
15965 E->isListInitialization());
15966 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15967 &ArgumentChanged))
15968 return ExprError();
15969
15970 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
15971 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc(),
15972 /*IsExplicit=*/true);
15973 if (Res.isInvalid())
15974 return ExprError();
15975 Args = {Res.get()};
15976 }
15977 }
15978
15979 if (!getDerived().AlwaysRebuild() &&
15980 T == E->getTypeSourceInfo() &&
15981 Constructor == E->getConstructor() &&
15982 !ArgumentChanged) {
15983 // FIXME: Instantiation-specific
15984 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
15985 return SemaRef.MaybeBindToTemporary(E);
15986 }
15987
15988 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
15989 return getDerived().RebuildCXXTemporaryObjectExpr(
15990 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
15991}
15992
15993template<typename Derived>
15996 // Transform any init-capture expressions before entering the scope of the
15997 // lambda body, because they are not semantically within that scope.
15998 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
15999 struct TransformedInitCapture {
16000 // The location of the ... if the result is retaining a pack expansion.
16001 SourceLocation EllipsisLoc;
16002 // Zero or more expansions of the init-capture.
16003 SmallVector<InitCaptureInfoTy, 4> Expansions;
16004 };
16006 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
16007 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16008 CEnd = E->capture_end();
16009 C != CEnd; ++C) {
16010 if (!E->isInitCapture(C))
16011 continue;
16012
16013 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
16014 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16015
16016 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
16017 UnsignedOrNone NumExpansions) {
16018 ExprResult NewExprInitResult = getDerived().TransformInitializer(
16019 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
16020
16021 if (NewExprInitResult.isInvalid()) {
16022 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
16023 return;
16024 }
16025 Expr *NewExprInit = NewExprInitResult.get();
16026
16027 QualType NewInitCaptureType =
16028 getSema().buildLambdaInitCaptureInitialization(
16029 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
16030 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
16031 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
16033 NewExprInit);
16034 Result.Expansions.push_back(
16035 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
16036 };
16037
16038 // If this is an init-capture pack, consider expanding the pack now.
16039 if (OldVD->isParameterPack()) {
16040 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
16041 ->getTypeLoc()
16044 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
16045
16046 // Determine whether the set of unexpanded parameter packs can and should
16047 // be expanded.
16048 bool Expand = true;
16049 bool RetainExpansion = false;
16050 UnsignedOrNone OrigNumExpansions =
16051 ExpansionTL.getTypePtr()->getNumExpansions();
16052 UnsignedOrNone NumExpansions = OrigNumExpansions;
16053 if (getDerived().TryExpandParameterPacks(
16054 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
16055 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
16056 RetainExpansion, NumExpansions))
16057 return ExprError();
16058 assert(!RetainExpansion && "Should not need to retain expansion after a "
16059 "capture since it cannot be extended");
16060 if (Expand) {
16061 for (unsigned I = 0; I != *NumExpansions; ++I) {
16062 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16063 SubstInitCapture(SourceLocation(), std::nullopt);
16064 }
16065 } else {
16066 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
16067 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
16068 }
16069 } else {
16070 SubstInitCapture(SourceLocation(), std::nullopt);
16071 }
16072 }
16073
16074 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
16075 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
16076
16077 // Create the local class that will describe the lambda.
16078
16079 // FIXME: DependencyKind below is wrong when substituting inside a templated
16080 // context that isn't a DeclContext (such as a variable template), or when
16081 // substituting an unevaluated lambda inside of a function's parameter's type
16082 // - as parameter types are not instantiated from within a function's DC. We
16083 // use evaluation contexts to distinguish the function parameter case.
16086 DeclContext *DC = getSema().CurContext;
16087 // A RequiresExprBodyDecl is not interesting for dependencies.
16088 // For the following case,
16089 //
16090 // template <typename>
16091 // concept C = requires { [] {}; };
16092 //
16093 // template <class F>
16094 // struct Widget;
16095 //
16096 // template <C F>
16097 // struct Widget<F> {};
16098 //
16099 // While we are substituting Widget<F>, the parent of DC would be
16100 // the template specialization itself. Thus, the lambda expression
16101 // will be deemed as dependent even if there are no dependent template
16102 // arguments.
16103 // (A ClassTemplateSpecializationDecl is always a dependent context.)
16104 while (DC->isRequiresExprBody() || isa<CXXExpansionStmtDecl>(DC))
16105 DC = DC->getParent();
16106 if ((getSema().isUnevaluatedContext() ||
16107 getSema().isConstantEvaluatedContext()) &&
16108 !(dyn_cast_or_null<CXXRecordDecl>(DC->getParent()) &&
16109 cast<CXXRecordDecl>(DC->getParent())->isGenericLambda()) &&
16110 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
16111 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
16112
16113 CXXRecordDecl *OldClass = E->getLambdaClass();
16114 CXXRecordDecl *Class = getSema().createLambdaClosureType(
16115 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
16116 E->getCaptureDefault());
16117 getDerived().transformedLocalDecl(OldClass, {Class});
16118
16119 CXXMethodDecl *NewCallOperator =
16120 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
16121
16122 // Enter the scope of the lambda.
16123 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
16124 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
16125 E->hasExplicitParameters(), E->isMutable());
16126
16127 // Introduce the context of the call operator.
16128 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
16129 /*NewThisContext*/false);
16130
16131 bool Invalid = false;
16132
16133 // Transform captures.
16134 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16135 CEnd = E->capture_end();
16136 C != CEnd; ++C) {
16137 // When we hit the first implicit capture, tell Sema that we've finished
16138 // the list of explicit captures.
16139 if (C->isImplicit())
16140 break;
16141
16142 // Capturing 'this' is trivial.
16143 if (C->capturesThis()) {
16144 // If this is a lambda that is part of a default member initialiser
16145 // and which we're instantiating outside the class that 'this' is
16146 // supposed to refer to, adjust the type of 'this' accordingly.
16147 //
16148 // Otherwise, leave the type of 'this' as-is.
16149 Sema::CXXThisScopeRAII ThisScope(
16150 getSema(),
16151 dyn_cast_if_present<CXXRecordDecl>(
16152 getSema().getFunctionLevelDeclContext()),
16153 Qualifiers());
16154 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16155 /*BuildAndDiagnose*/ true, nullptr,
16156 C->getCaptureKind() == LCK_StarThis);
16157 continue;
16158 }
16159 // Captured expression will be recaptured during captured variables
16160 // rebuilding.
16161 if (C->capturesVLAType())
16162 continue;
16163
16164 // Rebuild init-captures, including the implied field declaration.
16165 if (E->isInitCapture(C)) {
16166 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
16167
16168 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16170
16171 for (InitCaptureInfoTy &Info : NewC.Expansions) {
16172 ExprResult Init = Info.first;
16173 QualType InitQualType = Info.second;
16174 if (Init.isInvalid() || InitQualType.isNull()) {
16175 Invalid = true;
16176 break;
16177 }
16178 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
16179 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
16180 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
16181 getSema().CurContext);
16182 if (!NewVD) {
16183 Invalid = true;
16184 break;
16185 }
16186 NewVDs.push_back(NewVD);
16187 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
16188 // Cases we want to tackle:
16189 // ([C(Pack)] {}, ...)
16190 // But rule out cases e.g.
16191 // [...C = Pack()] {}
16192 if (NewC.EllipsisLoc.isInvalid())
16193 LSI->ContainsUnexpandedParameterPack |=
16194 Init.get()->containsUnexpandedParameterPack();
16195 }
16196
16197 if (Invalid)
16198 break;
16199
16200 getDerived().transformedLocalDecl(OldVD, NewVDs);
16201 continue;
16202 }
16203
16204 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16205
16206 // Determine the capture kind for Sema.
16208 : C->getCaptureKind() == LCK_ByCopy
16211 SourceLocation EllipsisLoc;
16212 if (C->isPackExpansion()) {
16213 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
16214 bool ShouldExpand = false;
16215 bool RetainExpansion = false;
16216 UnsignedOrNone NumExpansions = std::nullopt;
16217 if (getDerived().TryExpandParameterPacks(
16218 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
16219 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16220 RetainExpansion, NumExpansions)) {
16221 Invalid = true;
16222 continue;
16223 }
16224
16225 if (ShouldExpand) {
16226 // The transform has determined that we should perform an expansion;
16227 // transform and capture each of the arguments.
16228 // expansion of the pattern. Do so.
16229 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
16230 for (unsigned I = 0; I != *NumExpansions; ++I) {
16231 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16232 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
16233 getDerived().TransformDecl(C->getLocation(), Pack));
16234 if (!CapturedVar) {
16235 Invalid = true;
16236 continue;
16237 }
16238
16239 // Capture the transformed variable.
16240 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
16241 }
16242
16243 // FIXME: Retain a pack expansion if RetainExpansion is true.
16244
16245 continue;
16246 }
16247
16248 EllipsisLoc = C->getEllipsisLoc();
16249 }
16250
16251 // Transform the captured variable.
16252 auto *CapturedVar = cast_or_null<ValueDecl>(
16253 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16254 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
16255 Invalid = true;
16256 continue;
16257 }
16258
16259 // This is not an init-capture; however it contains an unexpanded pack e.g.
16260 // ([Pack] {}(), ...)
16261 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
16262 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
16263
16264 // Capture the transformed variable.
16265 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
16266 EllipsisLoc);
16267 }
16268 getSema().finishLambdaExplicitCaptures(LSI);
16269
16270 // Transform the template parameters, and add them to the current
16271 // instantiation scope. The null case is handled correctly.
16272 auto TPL = getDerived().TransformTemplateParameterList(
16273 E->getTemplateParameterList());
16274 LSI->GLTemplateParameterList = TPL;
16275 if (TPL) {
16276 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
16277 TPL);
16278 LSI->ContainsUnexpandedParameterPack |=
16279 TPL->containsUnexpandedParameterPack();
16280 }
16281
16282 TypeLocBuilder NewCallOpTLBuilder;
16283 TypeLoc OldCallOpTypeLoc =
16284 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
16285 QualType NewCallOpType =
16286 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
16287 if (NewCallOpType.isNull())
16288 return ExprError();
16289 LSI->ContainsUnexpandedParameterPack |=
16290 NewCallOpType->containsUnexpandedParameterPack();
16291 TypeSourceInfo *NewCallOpTSI =
16292 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
16293
16294 // The type may be an AttributedType or some other kind of sugar;
16295 // get the actual underlying FunctionProtoType.
16296 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
16297 assert(FPTL && "Not a FunctionProtoType?");
16298
16299 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
16300 if (TRC) {
16301 ExprResult E = getDerived().TransformLambdaConstraint(
16302 const_cast<Expr *>(TRC.ConstraintExpr));
16303 if (E.isInvalid())
16304 return E;
16305 TRC.ConstraintExpr = E.get();
16306 }
16307
16308 getSema().CompleteLambdaCallOperator(
16309 NewCallOperator, E->getCallOperator()->getLocation(),
16310 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
16311 E->getCallOperator()->getConstexprKind(),
16312 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
16313 E->hasExplicitResultType());
16314
16315 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
16316 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
16317
16318 {
16319 // Number the lambda for linkage purposes if necessary.
16320 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
16321
16322 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
16323 if (getDerived().ReplacingOriginal()) {
16324 Numbering = OldClass->getLambdaNumbering();
16325 }
16326
16327 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
16328 }
16329
16330 // FIXME: Sema's lambda-building mechanism expects us to push an expression
16331 // evaluation context even if we're not transforming the function body.
16332 getSema().PushExpressionEvaluationContextForFunction(
16334 E->getCallOperator());
16335
16336 StmtResult Body;
16337 {
16338 Sema::NonSFINAEContext _(getSema());
16341 C.PointOfInstantiation = E->getBody()->getBeginLoc();
16342 getSema().pushCodeSynthesisContext(C);
16343
16344 // Instantiate the body of the lambda expression.
16345 Body = Invalid ? StmtError()
16346 : getDerived().TransformLambdaBody(E, E->getBody());
16347
16348 getSema().popCodeSynthesisContext();
16349 }
16350
16351 // ActOnLambda* will pop the function scope for us.
16352 FuncScopeCleanup.disable();
16353
16354 if (Body.isInvalid()) {
16355 SavedContext.pop();
16356 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
16357 /*IsInstantiation=*/true);
16358 return ExprError();
16359 }
16360
16361 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
16362 /*IsInstantiation=*/true,
16363 /*RetainFunctionScopeInfo=*/true);
16364 SavedContext.pop();
16365
16366 // Recompute the dependency of the lambda so that we can defer the lambda call
16367 // construction until after we have all the necessary template arguments. For
16368 // example, given
16369 //
16370 // template <class> struct S {
16371 // template <class U>
16372 // using Type = decltype([](U){}(42.0));
16373 // };
16374 // void foo() {
16375 // using T = S<int>::Type<float>;
16376 // ^~~~~~
16377 // }
16378 //
16379 // We would end up here from instantiating S<int> when ensuring its
16380 // completeness. That would transform the lambda call expression regardless of
16381 // the absence of the corresponding argument for U.
16382 //
16383 // Going ahead with unsubstituted type U makes things worse: we would soon
16384 // compare the argument type (which is float) against the parameter U
16385 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
16386 // error suggesting unmatched types 'U' and 'float'!
16387 //
16388 // That said, everything will be fine if we defer that semantic checking.
16389 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
16390 // dependent. Since the CallExpr's dependency boils down to the lambda's
16391 // dependency in this case, we can harness that by recomputing the dependency
16392 // from the instantiation arguments.
16393 //
16394 // FIXME: Creating the type of a lambda requires us to have a dependency
16395 // value, which happens before its substitution. We update its dependency
16396 // *after* the substitution in case we can't decide the dependency
16397 // so early, e.g. because we want to see if any of the *substituted*
16398 // parameters are dependent.
16399 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
16400 Class->setLambdaDependencyKind(DependencyKind);
16401
16402 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
16403 Body.get()->getEndLoc(), LSI);
16404}
16405
16406template<typename Derived>
16411
16412template<typename Derived>
16415 // Transform captures.
16417 CEnd = E->capture_end();
16418 C != CEnd; ++C) {
16419 // When we hit the first implicit capture, tell Sema that we've finished
16420 // the list of explicit captures.
16421 if (!C->isImplicit())
16422 continue;
16423
16424 // Capturing 'this' is trivial.
16425 if (C->capturesThis()) {
16426 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16427 /*BuildAndDiagnose*/ true, nullptr,
16428 C->getCaptureKind() == LCK_StarThis);
16429 continue;
16430 }
16431 // Captured expression will be recaptured during captured variables
16432 // rebuilding.
16433 if (C->capturesVLAType())
16434 continue;
16435
16436 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16437 assert(!E->isInitCapture(C) && "implicit init-capture?");
16438
16439 // Transform the captured variable.
16440 VarDecl *CapturedVar = cast_or_null<VarDecl>(
16441 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16442 if (!CapturedVar || CapturedVar->isInvalidDecl())
16443 return StmtError();
16444
16445 // Capture the transformed variable.
16446 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
16447 }
16448
16449 return S;
16450}
16451
16452template<typename Derived>
16456 TypeSourceInfo *T =
16457 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
16458 if (!T)
16459 return ExprError();
16460
16461 bool ArgumentChanged = false;
16463 Args.reserve(E->getNumArgs());
16464 {
16468 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
16469 &ArgumentChanged))
16470 return ExprError();
16471 }
16472
16473 if (!getDerived().AlwaysRebuild() &&
16474 T == E->getTypeSourceInfo() &&
16475 !ArgumentChanged)
16476 return E;
16477
16478 // FIXME: we're faking the locations of the commas
16479 return getDerived().RebuildCXXUnresolvedConstructExpr(
16480 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
16481}
16482
16483template<typename Derived>
16487 // Transform the base of the expression.
16488 ExprResult Base((Expr*) nullptr);
16489 Expr *OldBase;
16490 QualType BaseType;
16491 QualType ObjectType;
16492 if (!E->isImplicitAccess()) {
16493 OldBase = E->getBase();
16494 Base = getDerived().TransformExpr(OldBase);
16495 if (Base.isInvalid())
16496 return ExprError();
16497
16498 // Start the member reference and compute the object's type.
16499 ParsedType ObjectTy;
16500 bool MayBePseudoDestructor = false;
16501 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
16502 E->getOperatorLoc(),
16503 E->isArrow()? tok::arrow : tok::period,
16504 ObjectTy,
16505 MayBePseudoDestructor);
16506 if (Base.isInvalid())
16507 return ExprError();
16508
16509 ObjectType = ObjectTy.get();
16510 BaseType = ((Expr*) Base.get())->getType();
16511 } else {
16512 OldBase = nullptr;
16513 BaseType = getDerived().TransformType(E->getBaseType());
16514 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
16515 }
16516
16517 // Transform the first part of the nested-name-specifier that qualifies
16518 // the member name.
16519 NamedDecl *FirstQualifierInScope
16520 = getDerived().TransformFirstQualifierInScope(
16521 E->getFirstQualifierFoundInScope(),
16522 E->getQualifierLoc().getBeginLoc());
16523
16524 NestedNameSpecifierLoc QualifierLoc;
16525 if (E->getQualifier()) {
16526 QualifierLoc
16527 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
16528 ObjectType,
16529 FirstQualifierInScope);
16530 if (!QualifierLoc)
16531 return ExprError();
16532 }
16533
16534 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
16535
16536 // TODO: If this is a conversion-function-id, verify that the
16537 // destination type name (if present) resolves the same way after
16538 // instantiation as it did in the local scope.
16539
16540 DeclarationNameInfo NameInfo
16541 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
16542 if (!NameInfo.getName())
16543 return ExprError();
16544
16545 if (!E->hasExplicitTemplateArgs()) {
16546 // This is a reference to a member without an explicitly-specified
16547 // template argument list. Optimize for this common case.
16548 if (!getDerived().AlwaysRebuild() &&
16549 Base.get() == OldBase &&
16550 BaseType == E->getBaseType() &&
16551 QualifierLoc == E->getQualifierLoc() &&
16552 NameInfo.getName() == E->getMember() &&
16553 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
16554 return E;
16555
16556 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16557 BaseType,
16558 E->isArrow(),
16559 E->getOperatorLoc(),
16560 QualifierLoc,
16561 TemplateKWLoc,
16562 FirstQualifierInScope,
16563 NameInfo,
16564 /*TemplateArgs*/nullptr);
16565 }
16566
16567 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16568 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
16569 E->getNumTemplateArgs(),
16570 TransArgs))
16571 return ExprError();
16572
16573 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16574 BaseType,
16575 E->isArrow(),
16576 E->getOperatorLoc(),
16577 QualifierLoc,
16578 TemplateKWLoc,
16579 FirstQualifierInScope,
16580 NameInfo,
16581 &TransArgs);
16582}
16583
16584template <typename Derived>
16586 UnresolvedMemberExpr *Old) {
16587 // Transform the base of the expression.
16588 ExprResult Base((Expr *)nullptr);
16589 QualType BaseType;
16590 if (!Old->isImplicitAccess()) {
16591 Base = getDerived().TransformExpr(Old->getBase());
16592 if (Base.isInvalid())
16593 return ExprError();
16594 Base =
16595 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
16596 if (Base.isInvalid())
16597 return ExprError();
16598 BaseType = Base.get()->getType();
16599 } else {
16600 BaseType = getDerived().TransformType(Old->getBaseType());
16601 }
16602
16603 NestedNameSpecifierLoc QualifierLoc;
16604 if (Old->getQualifierLoc()) {
16605 QualifierLoc =
16606 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
16607 if (!QualifierLoc)
16608 return ExprError();
16609 }
16610
16611 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
16612
16613 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
16614
16615 // Transform the declaration set.
16616 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
16617 return ExprError();
16618
16619 // Determine the naming class.
16620 if (Old->getNamingClass()) {
16621 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
16622 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
16623 if (!NamingClass)
16624 return ExprError();
16625
16626 R.setNamingClass(NamingClass);
16627 }
16628
16629 TemplateArgumentListInfo TransArgs;
16630 if (Old->hasExplicitTemplateArgs()) {
16631 TransArgs.setLAngleLoc(Old->getLAngleLoc());
16632 TransArgs.setRAngleLoc(Old->getRAngleLoc());
16633 if (getDerived().TransformTemplateArguments(
16634 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
16635 return ExprError();
16636 }
16637
16638 // FIXME: to do this check properly, we will need to preserve the
16639 // first-qualifier-in-scope here, just in case we had a dependent
16640 // base (and therefore couldn't do the check) and a
16641 // nested-name-qualifier (and therefore could do the lookup).
16642 NamedDecl *FirstQualifierInScope = nullptr;
16643
16644 return getDerived().RebuildUnresolvedMemberExpr(
16645 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
16646 TemplateKWLoc, FirstQualifierInScope, R,
16647 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
16648}
16649
16650template<typename Derived>
16655 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
16656 if (SubExpr.isInvalid())
16657 return ExprError();
16658
16659 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
16660 return E;
16661
16662 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
16663}
16664
16665template<typename Derived>
16668 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
16669 if (Pattern.isInvalid())
16670 return ExprError();
16671
16672 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
16673 return E;
16674
16675 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
16676 E->getNumExpansions());
16677}
16678
16679template <typename Derived>
16681 ArrayRef<TemplateArgument> PackArgs) {
16683 for (const TemplateArgument &Arg : PackArgs) {
16684 if (!Arg.isPackExpansion()) {
16685 Result = *Result + 1;
16686 continue;
16687 }
16688
16689 TemplateArgumentLoc ArgLoc;
16690 InventTemplateArgumentLoc(Arg, ArgLoc);
16691
16692 // Find the pattern of the pack expansion.
16693 SourceLocation Ellipsis;
16694 UnsignedOrNone OrigNumExpansions = std::nullopt;
16695 TemplateArgumentLoc Pattern =
16696 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
16697 OrigNumExpansions);
16698
16699 // Substitute under the pack expansion. Do not expand the pack (yet).
16700 TemplateArgumentLoc OutPattern;
16701 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16702 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
16703 /*Uneval*/ true))
16704 return 1u;
16705
16706 // See if we can determine the number of arguments from the result.
16707 UnsignedOrNone NumExpansions =
16708 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
16709 if (!NumExpansions) {
16710 // No: we must be in an alias template expansion, and we're going to
16711 // need to actually expand the packs.
16712 Result = std::nullopt;
16713 break;
16714 }
16715
16716 Result = *Result + *NumExpansions;
16717 }
16718 return Result;
16719}
16720
16721template<typename Derived>
16724 // If E is not value-dependent, then nothing will change when we transform it.
16725 // Note: This is an instantiation-centric view.
16726 if (!E->isValueDependent())
16727 return E;
16728
16731
16733 TemplateArgument ArgStorage;
16734
16735 // Find the argument list to transform.
16736 if (E->isPartiallySubstituted()) {
16737 PackArgs = E->getPartialArguments();
16738 } else if (E->isValueDependent()) {
16739 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
16740 bool ShouldExpand = false;
16741 bool RetainExpansion = false;
16742 UnsignedOrNone NumExpansions = std::nullopt;
16743 if (getDerived().TryExpandParameterPacks(
16744 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
16745 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16746 RetainExpansion, NumExpansions))
16747 return ExprError();
16748
16749 // If we need to expand the pack, build a template argument from it and
16750 // expand that.
16751 if (ShouldExpand) {
16752 auto *Pack = E->getPack();
16753 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
16754 ArgStorage = getSema().Context.getPackExpansionType(
16755 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
16756 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
16757 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
16758 } else {
16759 auto *VD = cast<ValueDecl>(Pack);
16760 ExprResult DRE = getSema().BuildDeclRefExpr(
16761 VD, VD->getType().getNonLValueExprType(getSema().Context),
16762 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
16763 E->getPackLoc());
16764 if (DRE.isInvalid())
16765 return ExprError();
16766 ArgStorage = TemplateArgument(
16767 new (getSema().Context)
16768 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
16769 /*IsCanonical=*/false);
16770 }
16771 PackArgs = ArgStorage;
16772 }
16773 }
16774
16775 // If we're not expanding the pack, just transform the decl.
16776 if (!PackArgs.size()) {
16777 auto *Pack = cast_or_null<NamedDecl>(
16778 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
16779 if (!Pack)
16780 return ExprError();
16781 return getDerived().RebuildSizeOfPackExpr(
16782 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
16783 std::nullopt, {});
16784 }
16785
16786 // Try to compute the result without performing a partial substitution.
16788 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
16789
16790 // Common case: we could determine the number of expansions without
16791 // substituting.
16792 if (Result)
16793 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
16794 E->getPackLoc(),
16795 E->getRParenLoc(), *Result, {});
16796
16797 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
16798 E->getPackLoc());
16799 {
16800 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
16802 Derived, const TemplateArgument*> PackLocIterator;
16803 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
16804 PackLocIterator(*this, PackArgs.end()),
16805 TransformedPackArgs, /*Uneval*/true))
16806 return ExprError();
16807 }
16808
16809 // Check whether we managed to fully-expand the pack.
16810 // FIXME: Is it possible for us to do so and not hit the early exit path?
16812 bool PartialSubstitution = false;
16813 for (auto &Loc : TransformedPackArgs.arguments()) {
16814 Args.push_back(Loc.getArgument());
16815 if (Loc.getArgument().isPackExpansion())
16816 PartialSubstitution = true;
16817 }
16818
16819 if (PartialSubstitution)
16820 return getDerived().RebuildSizeOfPackExpr(
16821 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16822 std::nullopt, Args);
16823
16824 return getDerived().RebuildSizeOfPackExpr(
16825 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
16826 /*Length=*/static_cast<unsigned>(Args.size()),
16827 /*PartialArgs=*/{});
16828}
16829
16830template <typename Derived>
16833 if (!E->isValueDependent())
16834 return E;
16835
16836 // Transform the index
16837 ExprResult IndexExpr;
16838 {
16839 EnterExpressionEvaluationContext ConstantContext(
16841 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
16842 if (IndexExpr.isInvalid())
16843 return ExprError();
16844 }
16845
16846 SmallVector<Expr *, 5> ExpandedExprs;
16847 bool FullySubstituted = true;
16848 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
16849 Expr *Pattern = E->getPackIdExpression();
16851 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
16852 Unexpanded);
16853 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
16854
16855 // Determine whether the set of unexpanded parameter packs can and should
16856 // be expanded.
16857 bool ShouldExpand = true;
16858 bool RetainExpansion = false;
16859 UnsignedOrNone OrigNumExpansions = std::nullopt,
16860 NumExpansions = std::nullopt;
16861 if (getDerived().TryExpandParameterPacks(
16862 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
16863 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16864 RetainExpansion, NumExpansions))
16865 return true;
16866 if (!ShouldExpand) {
16867 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
16868 ExprResult Pack = getDerived().TransformExpr(Pattern);
16869 if (Pack.isInvalid())
16870 return ExprError();
16871 return getDerived().RebuildPackIndexingExpr(
16872 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
16873 {}, /*FullySubstituted=*/false);
16874 }
16875 for (unsigned I = 0; I != *NumExpansions; ++I) {
16876 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16877 ExprResult Out = getDerived().TransformExpr(Pattern);
16878 if (Out.isInvalid())
16879 return true;
16880 if (Out.get()->containsUnexpandedParameterPack()) {
16881 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16882 OrigNumExpansions);
16883 if (Out.isInvalid())
16884 return true;
16885 FullySubstituted = false;
16886 }
16887 ExpandedExprs.push_back(Out.get());
16888 }
16889 // If we're supposed to retain a pack expansion, do so by temporarily
16890 // forgetting the partially-substituted parameter pack.
16891 if (RetainExpansion) {
16892 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
16893
16894 ExprResult Out = getDerived().TransformExpr(Pattern);
16895 if (Out.isInvalid())
16896 return true;
16897
16898 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
16899 OrigNumExpansions);
16900 if (Out.isInvalid())
16901 return true;
16902 FullySubstituted = false;
16903 ExpandedExprs.push_back(Out.get());
16904 }
16905 } else if (!E->expandsToEmptyPack()) {
16906 if (getDerived().TransformExprs(E->getExpressions().data(),
16907 E->getExpressions().size(), false,
16908 ExpandedExprs))
16909 return ExprError();
16910 }
16911
16912 return getDerived().RebuildPackIndexingExpr(
16913 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
16914 IndexExpr.get(), ExpandedExprs, FullySubstituted);
16915}
16916
16917template <typename Derived>
16920 if (!getSema().ArgPackSubstIndex)
16921 // We aren't expanding the parameter pack, so just return ourselves.
16922 return E;
16923
16924 TemplateArgument Pack = E->getArgumentPack();
16926 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
16927 E->getAssociatedDecl(), E->getParameterPack()->getPosition(),
16928 E->getParameterPack()->getType(), E->getParameterPackLocation(), Arg,
16929 SemaRef.getPackIndex(Pack), E->getFinal());
16930}
16931
16932template <typename Derived>
16935 Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten();
16936
16937 // Insert a constant-evaluated context for the transform.
16938 // Otherwise, when a normalized constraint places the replacement inside
16939 // an unevaluated operand (e.g. decltype), entities it refers to are not
16940 // odr-used, and the constant evaluation performed by CheckTemplateArgument
16941 // below can spuriously fail for otherwise valid replacements,
16942 // e.g. when a call materializes a function parameter of class type whose
16943 // special members were never instantiated.
16944 EnterExpressionEvaluationContext ConstantEvaluated(
16948
16949 ExprResult Replacement = getDerived().TransformExpr(OrigReplacement);
16950 if (Replacement.isInvalid())
16951 return true;
16952
16953 Decl *AssociatedDecl =
16954 getDerived().TransformDecl(E->getNameLoc(), E->getAssociatedDecl());
16955 if (!AssociatedDecl)
16956 return true;
16957
16958 QualType ParamType = TransformType(E->getParameterType());
16959 if (ParamType.isNull())
16960 return true;
16961
16962 if (Replacement.get() == OrigReplacement &&
16963 AssociatedDecl == E->getAssociatedDecl() &&
16964 ParamType == E->getParameterType())
16965 return E;
16966
16967 if (Replacement.get() != OrigReplacement ||
16968 ParamType != E->getParameterType()) {
16969 auto *Param = cast<NonTypeTemplateParmDecl>(std::get<0>(
16970 getReplacedTemplateParameter(AssociatedDecl, E->getIndex())));
16971 // When transforming the replacement expression previously, all Sema
16972 // specific annotations, such as implicit casts, are discarded. Calling the
16973 // corresponding sema action is necessary to recover those. Otherwise,
16974 // equivalency of the result would be lost.
16975 TemplateArgument SugaredConverted, CanonicalConverted;
16976 Replacement = SemaRef.CheckTemplateArgument(
16977 Param, ParamType, Replacement.get(), SugaredConverted,
16978 CanonicalConverted,
16979 /*StrictCheck=*/false, Sema::CTAK_Specified);
16980 if (Replacement.isInvalid())
16981 return true;
16982 } else {
16983 // Otherwise, the same expression would have been produced.
16984 Replacement = E->getReplacement();
16985 }
16986
16987 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
16988 AssociatedDecl, E->getIndex(), ParamType, E->getNameLoc(),
16989 TemplateArgument(Replacement.get(), /*IsCanonical=*/false),
16990 E->getPackIndex(), E->getFinal());
16991}
16992
16993template<typename Derived>
16996 // Default behavior is to do nothing with this transformation.
16997 return E;
16998}
16999
17000template<typename Derived>
17004 return getDerived().TransformExpr(E->getSubExpr());
17005}
17006
17007template<typename Derived>
17010 UnresolvedLookupExpr *Callee = nullptr;
17011 if (Expr *OldCallee = E->getCallee()) {
17012 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
17013 if (CalleeResult.isInvalid())
17014 return ExprError();
17015 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
17016 }
17017
17018 Expr *Pattern = E->getPattern();
17019
17021 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
17022 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17023
17024 // Determine whether the set of unexpanded parameter packs can and should
17025 // be expanded.
17026 bool Expand = true;
17027 bool RetainExpansion = false;
17028 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
17029 NumExpansions = OrigNumExpansions;
17030 if (getDerived().TryExpandParameterPacks(
17031 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
17032 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17033 NumExpansions))
17034 return true;
17035
17036 if (!Expand) {
17037 // Do not expand any packs here, just transform and rebuild a fold
17038 // expression.
17039 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17040
17041 ExprResult LHS =
17042 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
17043 if (LHS.isInvalid())
17044 return true;
17045
17046 ExprResult RHS =
17047 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
17048 if (RHS.isInvalid())
17049 return true;
17050
17051 if (!getDerived().AlwaysRebuild() &&
17052 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
17053 return E;
17054
17055 return getDerived().RebuildCXXFoldExpr(
17056 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
17057 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
17058 }
17059
17060 // Formally a fold expression expands to nested parenthesized expressions.
17061 // Enforce this limit to avoid creating trees so deep we can't safely traverse
17062 // them.
17063 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
17064 SemaRef.Diag(E->getEllipsisLoc(),
17065 clang::diag::err_fold_expression_limit_exceeded)
17066 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
17067 << E->getSourceRange();
17068 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
17069 return ExprError();
17070 }
17071
17072 // The transform has determined that we should perform an elementwise
17073 // expansion of the pattern. Do so.
17074 ExprResult Result = getDerived().TransformExpr(E->getInit());
17075 if (Result.isInvalid())
17076 return true;
17077 bool LeftFold = E->isLeftFold();
17078
17079 // If we're retaining an expansion for a right fold, it is the innermost
17080 // component and takes the init (if any).
17081 if (!LeftFold && RetainExpansion) {
17082 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17083
17084 ExprResult Out = getDerived().TransformExpr(Pattern);
17085 if (Out.isInvalid())
17086 return true;
17087
17088 Result = getDerived().RebuildCXXFoldExpr(
17089 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
17090 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
17091 if (Result.isInvalid())
17092 return true;
17093 }
17094
17095 bool WarnedOnComparison = false;
17096 for (unsigned I = 0; I != *NumExpansions; ++I) {
17097 Sema::ArgPackSubstIndexRAII SubstIndex(
17098 getSema(), LeftFold ? I : *NumExpansions - I - 1);
17099 ExprResult Out = getDerived().TransformExpr(Pattern);
17100 if (Out.isInvalid())
17101 return true;
17102
17103 if (Out.get()->containsUnexpandedParameterPack()) {
17104 // We still have a pack; retain a pack expansion for this slice.
17105 Result = getDerived().RebuildCXXFoldExpr(
17106 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
17107 E->getOperator(), E->getEllipsisLoc(),
17108 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
17109 OrigNumExpansions);
17110 } else if (Result.isUsable()) {
17111 // We've got down to a single element; build a binary operator.
17112 Expr *LHS = LeftFold ? Result.get() : Out.get();
17113 Expr *RHS = LeftFold ? Out.get() : Result.get();
17114 if (Callee) {
17115 UnresolvedSet<16> Functions;
17116 Functions.append(Callee->decls_begin(), Callee->decls_end());
17117 Result = getDerived().RebuildCXXOperatorCallExpr(
17118 BinaryOperator::getOverloadedOperator(E->getOperator()),
17119 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
17120 Functions, LHS, RHS);
17121 } else {
17122 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
17123 E->getOperator(), LHS, RHS,
17124 /*ForFoldExpresion=*/true);
17125 if (!WarnedOnComparison && Result.isUsable()) {
17126 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
17127 BO && BO->isComparisonOp()) {
17128 WarnedOnComparison = true;
17129 SemaRef.Diag(BO->getBeginLoc(),
17130 diag::warn_comparison_in_fold_expression)
17131 << BO->getOpcodeStr();
17132 }
17133 }
17134 }
17135 } else
17136 Result = Out;
17137
17138 if (Result.isInvalid())
17139 return true;
17140 }
17141
17142 // If we're retaining an expansion for a left fold, it is the outermost
17143 // component and takes the complete expansion so far as its init (if any).
17144 if (LeftFold && RetainExpansion) {
17145 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17146
17147 ExprResult Out = getDerived().TransformExpr(Pattern);
17148 if (Out.isInvalid())
17149 return true;
17150
17151 Result = getDerived().RebuildCXXFoldExpr(
17152 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
17153 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
17154 if (Result.isInvalid())
17155 return true;
17156 }
17157
17158 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
17159 PE->setIsProducedByFoldExpansion();
17160
17161 // If we had no init and an empty pack, and we're not retaining an expansion,
17162 // then produce a fallback value or error.
17163 if (Result.isUnset())
17164 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
17165 E->getOperator());
17166 return Result;
17167}
17168
17169template <typename Derived>
17172 SmallVector<Expr *, 4> TransformedInits;
17173 ArrayRef<Expr *> InitExprs = E->getInitExprs();
17174
17175 QualType T = getDerived().TransformType(E->getType());
17176
17177 bool ArgChanged = false;
17178
17179 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
17180 TransformedInits, &ArgChanged))
17181 return ExprError();
17182
17183 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
17184 return E;
17185
17186 return getDerived().RebuildCXXParenListInitExpr(
17187 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
17188 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
17189}
17190
17191template<typename Derived>
17195 return getDerived().TransformExpr(E->getSubExpr());
17196}
17197
17198template<typename Derived>
17201 return SemaRef.MaybeBindToTemporary(E);
17202}
17203
17204template<typename Derived>
17207 return E;
17208}
17209
17210template<typename Derived>
17213 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
17214 if (SubExpr.isInvalid())
17215 return ExprError();
17216
17217 if (!getDerived().AlwaysRebuild() &&
17218 SubExpr.get() == E->getSubExpr())
17219 return E;
17220
17221 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
17222}
17223
17224template<typename Derived>
17227 // Transform each of the elements.
17228 SmallVector<Expr *, 8> Elements;
17229 bool ArgChanged = false;
17230 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
17231 /*IsCall=*/false, Elements, &ArgChanged))
17232 return ExprError();
17233
17234 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17235 return SemaRef.MaybeBindToTemporary(E);
17236
17237 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
17238 Elements.data(),
17239 Elements.size());
17240}
17241
17242template<typename Derived>
17246 // Transform each of the elements.
17248 bool ArgChanged = false;
17249 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
17250 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
17251
17252 if (OrigElement.isPackExpansion()) {
17253 // This key/value element is a pack expansion.
17255 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
17256 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
17257 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17258
17259 // Determine whether the set of unexpanded parameter packs can
17260 // and should be expanded.
17261 bool Expand = true;
17262 bool RetainExpansion = false;
17263 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
17264 UnsignedOrNone NumExpansions = OrigNumExpansions;
17265 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
17266 OrigElement.Value->getEndLoc());
17267 if (getDerived().TryExpandParameterPacks(
17268 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
17269 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17270 NumExpansions))
17271 return ExprError();
17272
17273 if (!Expand) {
17274 // The transform has determined that we should perform a simple
17275 // transformation on the pack expansion, producing another pack
17276 // expansion.
17277 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17278 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17279 if (Key.isInvalid())
17280 return ExprError();
17281
17282 if (Key.get() != OrigElement.Key)
17283 ArgChanged = true;
17284
17285 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17286 if (Value.isInvalid())
17287 return ExprError();
17288
17289 if (Value.get() != OrigElement.Value)
17290 ArgChanged = true;
17291
17292 ObjCDictionaryElement Expansion = {
17293 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
17294 };
17295 Elements.push_back(Expansion);
17296 continue;
17297 }
17298
17299 // Record right away that the argument was changed. This needs
17300 // to happen even if the array expands to nothing.
17301 ArgChanged = true;
17302
17303 // The transform has determined that we should perform an elementwise
17304 // expansion of the pattern. Do so.
17305 for (unsigned I = 0; I != *NumExpansions; ++I) {
17306 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
17307 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17308 if (Key.isInvalid())
17309 return ExprError();
17310
17311 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17312 if (Value.isInvalid())
17313 return ExprError();
17314
17315 ObjCDictionaryElement Element = {
17316 Key.get(), Value.get(), SourceLocation(), NumExpansions
17317 };
17318
17319 // If any unexpanded parameter packs remain, we still have a
17320 // pack expansion.
17321 // FIXME: Can this really happen?
17322 if (Key.get()->containsUnexpandedParameterPack() ||
17323 Value.get()->containsUnexpandedParameterPack())
17324 Element.EllipsisLoc = OrigElement.EllipsisLoc;
17325
17326 Elements.push_back(Element);
17327 }
17328
17329 // FIXME: Retain a pack expansion if RetainExpansion is true.
17330
17331 // We've finished with this pack expansion.
17332 continue;
17333 }
17334
17335 // Transform and check key.
17336 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17337 if (Key.isInvalid())
17338 return ExprError();
17339
17340 if (Key.get() != OrigElement.Key)
17341 ArgChanged = true;
17342
17343 // Transform and check value.
17345 = getDerived().TransformExpr(OrigElement.Value);
17346 if (Value.isInvalid())
17347 return ExprError();
17348
17349 if (Value.get() != OrigElement.Value)
17350 ArgChanged = true;
17351
17352 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
17353 std::nullopt};
17354 Elements.push_back(Element);
17355 }
17356
17357 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17358 return SemaRef.MaybeBindToTemporary(E);
17359
17360 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
17361 Elements);
17362}
17363
17364template<typename Derived>
17367 TypeSourceInfo *EncodedTypeInfo
17368 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
17369 if (!EncodedTypeInfo)
17370 return ExprError();
17371
17372 if (!getDerived().AlwaysRebuild() &&
17373 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
17374 return E;
17375
17376 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
17377 EncodedTypeInfo,
17378 E->getRParenLoc());
17379}
17380
17381template<typename Derived>
17384 // This is a kind of implicit conversion, and it needs to get dropped
17385 // and recomputed for the same general reasons that ImplicitCastExprs
17386 // do, as well a more specific one: this expression is only valid when
17387 // it appears *immediately* as an argument expression.
17388 return getDerived().TransformExpr(E->getSubExpr());
17389}
17390
17391template<typename Derived>
17394 TypeSourceInfo *TSInfo
17395 = getDerived().TransformType(E->getTypeInfoAsWritten());
17396 if (!TSInfo)
17397 return ExprError();
17398
17399 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
17400 if (Result.isInvalid())
17401 return ExprError();
17402
17403 if (!getDerived().AlwaysRebuild() &&
17404 TSInfo == E->getTypeInfoAsWritten() &&
17405 Result.get() == E->getSubExpr())
17406 return E;
17407
17408 return SemaRef.ObjC().BuildObjCBridgedCast(
17409 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
17410 Result.get());
17411}
17412
17413template <typename Derived>
17416 return E;
17417}
17418
17419template<typename Derived>
17422 // Transform arguments.
17423 bool ArgChanged = false;
17425 Args.reserve(E->getNumArgs());
17426 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
17427 &ArgChanged))
17428 return ExprError();
17429
17430 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
17431 // Class message: transform the receiver type.
17432 TypeSourceInfo *ReceiverTypeInfo
17433 = getDerived().TransformType(E->getClassReceiverTypeInfo());
17434 if (!ReceiverTypeInfo)
17435 return ExprError();
17436
17437 // If nothing changed, just retain the existing message send.
17438 if (!getDerived().AlwaysRebuild() &&
17439 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
17440 return SemaRef.MaybeBindToTemporary(E);
17441
17442 // Build a new class message send.
17444 E->getSelectorLocs(SelLocs);
17445 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
17446 E->getSelector(),
17447 SelLocs,
17448 E->getMethodDecl(),
17449 E->getLeftLoc(),
17450 Args,
17451 E->getRightLoc());
17452 }
17453 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
17454 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
17455 if (!E->getMethodDecl())
17456 return ExprError();
17457
17458 // Build a new class message send to 'super'.
17460 E->getSelectorLocs(SelLocs);
17461 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
17462 E->getSelector(),
17463 SelLocs,
17464 E->getReceiverType(),
17465 E->getMethodDecl(),
17466 E->getLeftLoc(),
17467 Args,
17468 E->getRightLoc());
17469 }
17470
17471 // Instance message: transform the receiver
17472 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
17473 "Only class and instance messages may be instantiated");
17474 ExprResult Receiver
17475 = getDerived().TransformExpr(E->getInstanceReceiver());
17476 if (Receiver.isInvalid())
17477 return ExprError();
17478
17479 // If nothing changed, just retain the existing message send.
17480 if (!getDerived().AlwaysRebuild() &&
17481 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
17482 return SemaRef.MaybeBindToTemporary(E);
17483
17484 // Build a new instance message send.
17486 E->getSelectorLocs(SelLocs);
17487 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
17488 E->getSelector(),
17489 SelLocs,
17490 E->getMethodDecl(),
17491 E->getLeftLoc(),
17492 Args,
17493 E->getRightLoc());
17494}
17495
17496template<typename Derived>
17499 return E;
17500}
17501
17502template<typename Derived>
17505 return E;
17506}
17507
17508template<typename Derived>
17511 // Transform the base expression.
17512 ExprResult Base = getDerived().TransformExpr(E->getBase());
17513 if (Base.isInvalid())
17514 return ExprError();
17515
17516 // We don't need to transform the ivar; it will never change.
17517
17518 // If nothing changed, just retain the existing expression.
17519 if (!getDerived().AlwaysRebuild() &&
17520 Base.get() == E->getBase())
17521 return E;
17522
17523 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
17524 E->getLocation(),
17525 E->isArrow(), E->isFreeIvar());
17526}
17527
17528template<typename Derived>
17531 // 'super' and types never change. Property never changes. Just
17532 // retain the existing expression.
17533 if (!E->isObjectReceiver())
17534 return E;
17535
17536 // Transform the base expression.
17537 ExprResult Base = getDerived().TransformExpr(E->getBase());
17538 if (Base.isInvalid())
17539 return ExprError();
17540
17541 // We don't need to transform the property; it will never change.
17542
17543 // If nothing changed, just retain the existing expression.
17544 if (!getDerived().AlwaysRebuild() &&
17545 Base.get() == E->getBase())
17546 return E;
17547
17548 if (E->isExplicitProperty())
17549 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17550 E->getExplicitProperty(),
17551 E->getLocation());
17552
17553 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17554 SemaRef.Context.PseudoObjectTy,
17555 E->getImplicitPropertyGetter(),
17556 E->getImplicitPropertySetter(),
17557 E->getLocation());
17558}
17559
17560template<typename Derived>
17563 // Transform the base expression.
17564 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
17565 if (Base.isInvalid())
17566 return ExprError();
17567
17568 // Transform the key expression.
17569 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
17570 if (Key.isInvalid())
17571 return ExprError();
17572
17573 // If nothing changed, just retain the existing expression.
17574 if (!getDerived().AlwaysRebuild() &&
17575 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
17576 return E;
17577
17578 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
17579 Base.get(), Key.get(),
17580 E->getAtIndexMethodDecl(),
17581 E->setAtIndexMethodDecl());
17582}
17583
17584template<typename Derived>
17587 // Transform the base expression.
17588 ExprResult Base = getDerived().TransformExpr(E->getBase());
17589 if (Base.isInvalid())
17590 return ExprError();
17591
17592 // If nothing changed, just retain the existing expression.
17593 if (!getDerived().AlwaysRebuild() &&
17594 Base.get() == E->getBase())
17595 return E;
17596
17597 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
17598 E->getOpLoc(),
17599 E->isArrow());
17600}
17601
17602template<typename Derived>
17605 bool ArgumentChanged = false;
17606 SmallVector<Expr*, 8> SubExprs;
17607 SubExprs.reserve(E->getNumSubExprs());
17608 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17609 SubExprs, &ArgumentChanged))
17610 return ExprError();
17611
17612 if (!getDerived().AlwaysRebuild() &&
17613 !ArgumentChanged)
17614 return E;
17615
17616 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
17617 SubExprs,
17618 E->getRParenLoc());
17619}
17620
17621template<typename Derived>
17624 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17625 if (SrcExpr.isInvalid())
17626 return ExprError();
17627
17628 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
17629 if (!Type)
17630 return ExprError();
17631
17632 if (!getDerived().AlwaysRebuild() &&
17633 Type == E->getTypeSourceInfo() &&
17634 SrcExpr.get() == E->getSrcExpr())
17635 return E;
17636
17637 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
17638 SrcExpr.get(), Type,
17639 E->getRParenLoc());
17640}
17641
17642template<typename Derived>
17645 BlockDecl *oldBlock = E->getBlockDecl();
17646
17647 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
17648 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
17649
17650 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
17651 blockScope->TheDecl->setBlockMissingReturnType(
17652 oldBlock->blockMissingReturnType());
17653
17655 SmallVector<QualType, 4> paramTypes;
17656
17657 const FunctionProtoType *exprFunctionType = E->getFunctionType();
17658
17659 // Parameter substitution.
17660 Sema::ExtParameterInfoBuilder extParamInfos;
17661 if (getDerived().TransformFunctionTypeParams(
17662 E->getCaretLocation(), oldBlock->parameters(), nullptr,
17663 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
17664 extParamInfos)) {
17665 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17666 return ExprError();
17667 }
17668
17669 QualType exprResultType =
17670 getDerived().TransformType(exprFunctionType->getReturnType());
17671
17672 auto epi = exprFunctionType->getExtProtoInfo();
17673 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
17674
17676 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
17677 blockScope->FunctionType = functionType;
17678
17679 // Set the parameters on the block decl.
17680 if (!params.empty())
17681 blockScope->TheDecl->setParams(params);
17682
17683 if (!oldBlock->blockMissingReturnType()) {
17684 blockScope->HasImplicitReturnType = false;
17685 blockScope->ReturnType = exprResultType;
17686 }
17687
17688 // Transform the body
17689 StmtResult body = getDerived().TransformStmt(E->getBody());
17690 if (body.isInvalid()) {
17691 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
17692 return ExprError();
17693 }
17694
17695#ifndef NDEBUG
17696 // In builds with assertions, make sure that we captured everything we
17697 // captured before.
17698 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
17699 for (const auto &I : oldBlock->captures()) {
17700 VarDecl *oldCapture = I.getVariable();
17701
17702 // Ignore parameter packs.
17703 if (oldCapture->isParameterPack())
17704 continue;
17705
17706 VarDecl *newCapture =
17707 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
17708 oldCapture));
17709 assert(blockScope->CaptureMap.count(newCapture));
17710 }
17711
17712 // The this pointer may not be captured by the instantiated block, even when
17713 // it's captured by the original block, if the expression causing the
17714 // capture is in the discarded branch of a constexpr if statement.
17715 assert((!blockScope->isCXXThisCaptured() || oldBlock->capturesCXXThis()) &&
17716 "this pointer isn't captured in the old block");
17717 }
17718#endif
17719
17720 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
17721 /*Scope=*/nullptr);
17722}
17723
17724template<typename Derived>
17727 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17728 if (SrcExpr.isInvalid())
17729 return ExprError();
17730
17731 QualType Type = getDerived().TransformType(E->getType());
17732
17733 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
17734 E->getRParenLoc());
17735}
17736
17737template<typename Derived>
17740 bool ArgumentChanged = false;
17741 SmallVector<Expr*, 8> SubExprs;
17742 SubExprs.reserve(E->getNumSubExprs());
17743 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17744 SubExprs, &ArgumentChanged))
17745 return ExprError();
17746
17747 if (!getDerived().AlwaysRebuild() &&
17748 !ArgumentChanged)
17749 return E;
17750
17751 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
17752 E->getOp(), E->getRParenLoc());
17753}
17754
17755//===----------------------------------------------------------------------===//
17756// Type reconstruction
17757//===----------------------------------------------------------------------===//
17758
17759template<typename Derived>
17762 return SemaRef.BuildPointerType(PointeeType, Star,
17764}
17765
17766template<typename Derived>
17769 return SemaRef.BuildBlockPointerType(PointeeType, Star,
17771}
17772
17773template<typename Derived>
17776 bool WrittenAsLValue,
17777 SourceLocation Sigil) {
17778 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
17779 Sigil, getDerived().getBaseEntity());
17780}
17781
17782template <typename Derived>
17784 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
17785 SourceLocation Sigil) {
17786 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
17788}
17789
17790template<typename Derived>
17792 const ObjCTypeParamDecl *Decl,
17793 SourceLocation ProtocolLAngleLoc,
17795 ArrayRef<SourceLocation> ProtocolLocs,
17796 SourceLocation ProtocolRAngleLoc) {
17797 return SemaRef.ObjC().BuildObjCTypeParamType(
17798 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17799 /*FailOnError=*/true);
17800}
17801
17802template<typename Derived>
17804 QualType BaseType,
17805 SourceLocation Loc,
17806 SourceLocation TypeArgsLAngleLoc,
17808 SourceLocation TypeArgsRAngleLoc,
17809 SourceLocation ProtocolLAngleLoc,
17811 ArrayRef<SourceLocation> ProtocolLocs,
17812 SourceLocation ProtocolRAngleLoc) {
17813 return SemaRef.ObjC().BuildObjCObjectType(
17814 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
17815 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
17816 /*FailOnError=*/true,
17817 /*Rebuilding=*/true);
17818}
17819
17820template<typename Derived>
17822 QualType PointeeType,
17824 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
17825}
17826
17827template <typename Derived>
17829 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
17830 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17831 if (SizeExpr || !Size)
17832 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
17833 IndexTypeQuals, BracketsRange,
17835
17836 QualType Types[] = {
17837 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
17838 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
17839 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
17840 };
17841 QualType SizeType;
17842 for (const auto &T : Types)
17843 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
17844 SizeType = T;
17845 break;
17846 }
17847
17848 // Note that we can return a VariableArrayType here in the case where
17849 // the element type was a dependent VariableArrayType.
17850 IntegerLiteral *ArraySize
17851 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
17852 /*FIXME*/BracketsRange.getBegin());
17853 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
17854 IndexTypeQuals, BracketsRange,
17856}
17857
17858template <typename Derived>
17860 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
17861 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
17862 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
17863 IndexTypeQuals, BracketsRange);
17864}
17865
17866template <typename Derived>
17868 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
17869 SourceRange BracketsRange) {
17870 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
17871 IndexTypeQuals, BracketsRange);
17872}
17873
17874template <typename Derived>
17876 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17877 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17878 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17879 SizeExpr,
17880 IndexTypeQuals, BracketsRange);
17881}
17882
17883template <typename Derived>
17885 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
17886 unsigned IndexTypeQuals, SourceRange BracketsRange) {
17887 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
17888 SizeExpr,
17889 IndexTypeQuals, BracketsRange);
17890}
17891
17892template <typename Derived>
17894 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
17895 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
17896 AttributeLoc);
17897}
17898
17899template <typename Derived>
17901 unsigned NumElements,
17902 VectorKind VecKind) {
17903 // FIXME: semantic checking!
17904 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
17905}
17906
17907template <typename Derived>
17909 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
17910 VectorKind VecKind) {
17911 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
17912}
17913
17914template<typename Derived>
17916 unsigned NumElements,
17917 SourceLocation AttributeLoc) {
17918 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
17919 NumElements, true);
17920 IntegerLiteral *VectorSize
17921 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
17922 AttributeLoc);
17923 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
17924}
17925
17926template<typename Derived>
17929 Expr *SizeExpr,
17930 SourceLocation AttributeLoc) {
17931 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
17932}
17933
17934template <typename Derived>
17936 QualType ElementType, unsigned NumRows, unsigned NumColumns) {
17937 return SemaRef.Context.getConstantMatrixType(ElementType, NumRows,
17938 NumColumns);
17939}
17940
17941template <typename Derived>
17943 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
17944 SourceLocation AttributeLoc) {
17945 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
17946 AttributeLoc);
17947}
17948
17949template <typename Derived>
17951 QualType T, MutableArrayRef<QualType> ParamTypes,
17953 return SemaRef.BuildFunctionType(T, ParamTypes,
17956 EPI);
17957}
17958
17959template<typename Derived>
17961 return SemaRef.Context.getFunctionNoProtoType(T);
17962}
17963
17964template <typename Derived>
17967 SourceLocation NameLoc, Decl *D) {
17968 assert(D && "no decl found");
17969 if (D->isInvalidDecl()) return QualType();
17970
17971 // FIXME: Doesn't account for ObjCInterfaceDecl!
17972 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
17973 // A valid resolved using typename pack expansion decl can have multiple
17974 // UsingDecls, but they must each have exactly one type, and it must be
17975 // the same type in every case. But we must have at least one expansion!
17976 if (UPD->expansions().empty()) {
17977 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
17978 << UPD->isCXXClassMember() << UPD;
17979 return QualType();
17980 }
17981
17982 // We might still have some unresolved types. Try to pick a resolved type
17983 // if we can. The final instantiation will check that the remaining
17984 // unresolved types instantiate to the type we pick.
17985 QualType FallbackT;
17986 QualType T;
17987 for (auto *E : UPD->expansions()) {
17988 QualType ThisT =
17989 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
17990 if (ThisT.isNull())
17991 continue;
17992 if (ThisT->getAs<UnresolvedUsingType>())
17993 FallbackT = ThisT;
17994 else if (T.isNull())
17995 T = ThisT;
17996 else
17997 assert(getSema().Context.hasSameType(ThisT, T) &&
17998 "mismatched resolved types in using pack expansion");
17999 }
18000 return T.isNull() ? FallbackT : T;
18001 }
18002 if (auto *Using = dyn_cast<UsingDecl>(D)) {
18003 assert(Using->hasTypename() &&
18004 "UnresolvedUsingTypenameDecl transformed to non-typename using");
18005
18006 // A valid resolved using typename decl points to exactly one type decl.
18007 assert(++Using->shadow_begin() == Using->shadow_end());
18008
18009 UsingShadowDecl *Shadow = *Using->shadow_begin();
18010 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
18011 return QualType();
18012 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
18013 }
18015 "UnresolvedUsingTypenameDecl transformed to non-using decl");
18016 return SemaRef.Context.getUnresolvedUsingType(
18018}
18019
18020template <typename Derived>
18022 TypeOfKind Kind) {
18023 return SemaRef.BuildTypeofExprType(E, Kind);
18024}
18025
18026template<typename Derived>
18028 TypeOfKind Kind) {
18029 return SemaRef.Context.getTypeOfType(Underlying, Kind);
18030}
18031
18032template <typename Derived>
18034 return SemaRef.BuildDecltypeType(E);
18035}
18036
18037template <typename Derived>
18039 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
18040 SourceLocation EllipsisLoc, bool FullySubstituted,
18041 ArrayRef<QualType> Expansions) {
18042 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc, EllipsisLoc,
18043 FullySubstituted, Expansions);
18044}
18045
18046template<typename Derived>
18048 UnaryTransformType::UTTKind UKind,
18049 SourceLocation Loc) {
18050 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
18051}
18052
18053template <typename Derived>
18056 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
18057 return SemaRef.CheckTemplateIdType(
18058 Keyword, Template, TemplateNameLoc, TemplateArgs,
18059 /*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false);
18060}
18061
18062template<typename Derived>
18064 SourceLocation KWLoc) {
18065 return SemaRef.BuildAtomicType(ValueType, KWLoc);
18066}
18067
18068template<typename Derived>
18070 SourceLocation KWLoc,
18071 bool isReadPipe) {
18072 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
18073 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
18074}
18075
18076template <typename Derived>
18078 unsigned NumBits,
18079 SourceLocation Loc) {
18080 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
18081 NumBits, true);
18082 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
18083 SemaRef.Context.IntTy, Loc);
18084 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
18085}
18086
18087template <typename Derived>
18089 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
18090 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
18091}
18092
18093template <typename Derived>
18095 bool TemplateKW,
18096 TemplateName Name) {
18097 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
18098 Name);
18099}
18100
18101template <typename Derived>
18103 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
18104 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
18106 TemplateName.setIdentifier(&Name, NameLoc);
18108 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
18109 TemplateName, ParsedType::make(ObjectType),
18110 /*EnteringContext=*/false, Template,
18111 AllowInjectedClassName);
18112 return Template.get();
18113}
18114
18115template<typename Derived>
18118 SourceLocation TemplateKWLoc,
18119 OverloadedOperatorKind Operator,
18120 SourceLocation NameLoc,
18121 QualType ObjectType,
18122 bool AllowInjectedClassName) {
18123 UnqualifiedId Name;
18124 // FIXME: Bogus location information.
18125 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
18126 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
18128 getSema().ActOnTemplateName(
18129 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
18130 /*EnteringContext=*/false, Template, AllowInjectedClassName);
18131 return Template.get();
18132}
18133
18134template <typename Derived>
18137 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
18138 Expr *Second) {
18139 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
18140
18141 if (First->getObjectKind() == OK_ObjCProperty) {
18144 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
18145 Opc, First, Second);
18146 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
18147 if (Result.isInvalid())
18148 return ExprError();
18149 First = Result.get();
18150 }
18151
18152 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
18153 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
18154 if (Result.isInvalid())
18155 return ExprError();
18156 Second = Result.get();
18157 }
18158
18159 // Determine whether this should be a builtin operation.
18160 if (Op == OO_Subscript) {
18161 if (!First->getType()->isOverloadableType() &&
18162 !Second->getType()->isOverloadableType())
18163 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
18164 OpLoc);
18165 } else if (Op == OO_Arrow) {
18166 // It is possible that the type refers to a RecoveryExpr created earlier
18167 // in the tree transformation.
18168 if (First->getType()->isDependentType())
18169 return ExprError();
18170 // -> is never a builtin operation.
18171 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
18172 } else if (Second == nullptr || isPostIncDec) {
18173 if (!First->getType()->isOverloadableType() ||
18174 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
18175 // The argument is not of overloadable type, or this is an expression
18176 // of the form &Class::member, so try to create a built-in unary
18177 // operation.
18179 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18180
18181 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
18182 }
18183 } else {
18184 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
18185 !First->getType()->isOverloadableType() &&
18186 !Second->getType()->isOverloadableType()) {
18187 // Neither of the arguments is type-dependent or has an overloadable
18188 // type, so try to create a built-in binary operation.
18191 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
18192 if (Result.isInvalid())
18193 return ExprError();
18194
18195 return Result;
18196 }
18197 }
18198
18199 // Create the overloaded operator invocation for unary operators.
18200 if (!Second || isPostIncDec) {
18202 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18203 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
18204 RequiresADL);
18205 }
18206
18207 // Create the overloaded operator invocation for binary operators.
18209 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
18210 First, Second, RequiresADL);
18211 if (Result.isInvalid())
18212 return ExprError();
18213
18214 return Result;
18215}
18216
18217template<typename Derived>
18220 SourceLocation OperatorLoc,
18221 bool isArrow,
18222 CXXScopeSpec &SS,
18223 TypeSourceInfo *ScopeType,
18224 SourceLocation CCLoc,
18225 SourceLocation TildeLoc,
18226 PseudoDestructorTypeStorage Destroyed) {
18227 QualType CanonicalBaseType = Base->getType().getCanonicalType();
18228 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
18229 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
18230 (isArrow && isa<PointerType>(CanonicalBaseType) &&
18231 !cast<PointerType>(CanonicalBaseType)
18232 ->getPointeeType()
18233 ->getAsCanonical<RecordType>())) {
18234 // This pseudo-destructor expression is still a pseudo-destructor.
18235 return SemaRef.BuildPseudoDestructorExpr(
18236 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
18237 CCLoc, TildeLoc, Destroyed);
18238 }
18239
18240 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
18241 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
18242 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
18243 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
18244 NameInfo.setNamedTypeInfo(DestroyedType);
18245
18246 // The scope type is now known to be a valid nested name specifier
18247 // component. Tack it on to the nested name specifier.
18248 if (ScopeType) {
18249 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
18250 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
18251 diag::err_expected_class_or_namespace)
18252 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
18253 return ExprError();
18254 }
18255 SS.clear();
18256 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
18257 }
18258
18259 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
18260 return getSema().BuildMemberReferenceExpr(
18261 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
18262 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
18263 /*TemplateArgs*/ nullptr,
18264 /*S*/ nullptr);
18265}
18266
18267template<typename Derived>
18270 SourceLocation Loc = S->getBeginLoc();
18271 CapturedDecl *CD = S->getCapturedDecl();
18272 unsigned NumParams = CD->getNumParams();
18273 unsigned ContextParamPos = CD->getContextParamPosition();
18275 for (unsigned I = 0; I < NumParams; ++I) {
18276 if (I != ContextParamPos) {
18277 Params.push_back(
18278 std::make_pair(
18279 CD->getParam(I)->getName(),
18280 getDerived().TransformType(CD->getParam(I)->getType())));
18281 } else {
18282 Params.push_back(std::make_pair(StringRef(), QualType()));
18283 }
18284 }
18285 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
18286 S->getCapturedRegionKind(), Params);
18287 StmtResult Body;
18288 {
18289 Sema::CompoundScopeRAII CompoundScope(getSema());
18290 Body = getDerived().TransformStmt(S->getCapturedStmt());
18291 }
18292
18293 if (Body.isInvalid()) {
18294 getSema().ActOnCapturedRegionError();
18295 return StmtError();
18296 }
18297
18298 return getSema().ActOnCapturedRegionEnd(Body.get());
18299}
18300
18301template <typename Derived>
18304 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
18305 // function definition or instantiation of a function template specialization
18306 // and will therefore never appear in a dependent context.
18307 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
18308 "context");
18309}
18310
18311template <typename Derived>
18313 // We can transform the base expression and allow argument resolution to fill
18314 // in the rest.
18315 return getDerived().TransformExpr(E->getArgLValue());
18316}
18317
18318} // end namespace clang
18319
18320#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
static Decl::Kind getKind(const Decl *D)
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.
TokenType getType() const
Returns the token's type, e.g.
SmallVector< AnnotatedLine *, 1 > Children
If this token starts a block, this contains all the unwrapped lines in it.
Result
Implement __builtin_bit_cast and related operations.
#define X(type, name)
Definition Value.h:97
llvm::MachO::Record Record
Definition MachO.h:31
This file defines OpenMP AST classes for clauses.
Defines some OpenMP-specific enums and functions.
llvm::json::Object Object
This file declares semantic analysis for HLSL constructs.
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.
static bool PreparePackForExpansion(Sema &S, const CXXBaseSpecifier &Base, const MultiLevelTemplateArgumentList &TemplateArgs, TypeSourceInfo *&Out, UnexpandedInfo &Info)
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.
This file defines SYCL AST classes used to represent calls to SYCL kernels.
static QualType getPointeeType(const MemRegion *R)
This represents clause 'map' in the 'pragma omp ...' directives.
This represents clauses with a list of expressions that are mappable. Examples of these clauses are '...
This represents 'pragma omp metadirective' directive.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, UnsignedOrNone PackIndex, bool Final) const
Retrieve a substitution-result type.
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.
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
CanQualType IntTy
CanQualType PseudoObjectTy
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getPackExpansionType(QualType Pattern, UnsignedOrNone NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
static bool hasSameType(QualType T1, QualType T2)
Determine whether the given types T1 and T2 are equivalent.
QualType getSizeType() const
Return the unique type for "size_t" (C99 7.17), defined in <stddef.h>.
QualType getOverflowBehaviorType(const OverflowBehaviorAttr *Attr, QualType Wrapped) const
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
QualType getHLSLAttributedResourceType(QualType Wrapped, QualType Contained, const HLSLAttributedResourceType::Attributes &Attrs)
PtrTy get() const
Definition Ownership.h:171
bool isInvalid() const
Definition Ownership.h:167
bool isUsable() const
Definition Ownership.h:169
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition Expr.h:4556
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6033
Represents a loop initializing the elements of an array.
Definition Expr.h:5980
Wrapper for source info for array parameter types.
Definition TypeLoc.h:1833
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition Expr.h:7231
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2727
Wrapper for source info for arrays.
Definition TypeLoc.h:1777
void setLBracketLoc(SourceLocation Loc)
Definition TypeLoc.h:1783
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:3000
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3038
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3040
Expr * getDimensionExpression() const
Definition ExprCXX.h:3050
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3046
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3037
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3786
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition Expr.h:6745
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:6940
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2673
Attr - This represents one attribute.
Definition Attr.h:46
Represents an attribute applied to a statement.
Definition Stmt.h:2213
Stmt * getSubStmt()
Definition Stmt.h:2249
SourceLocation getAttrLoc() const
Definition Stmt.h:2244
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2245
Type source information for an attributed type.
Definition TypeLoc.h:1008
void setAttr(const Attr *A)
Definition TypeLoc.h:1034
Type source information for an btf_tag attributed type.
Definition TypeLoc.h:1058
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition Expr.h:4459
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4044
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition Expr.cpp:2187
static bool isAssignmentOp(Opcode Opc)
Definition Expr.h:4180
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:2149
A fixed int type of a specified bitwidth.
Definition TypeBase.h:8299
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4716
void setIsVariadic(bool value)
Definition Decl.h:4792
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6684
Wrapper for source info for block pointers.
Definition TypeLoc.h:1526
BreakStmt - This represents a break.
Definition Stmt.h:3145
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5472
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5491
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5490
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition Expr.h:3975
Represents a call to a CUDA kernel function.
Definition ExprCXX.h:238
A C++ addrspace_cast expression (currently only enabled for OpenCL).
Definition ExprCXX.h:608
Represents binding an expression to a temporary.
Definition ExprCXX.h:1497
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:727
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:29
A C++ const_cast expression (C++ [expr.const.cast]).
Definition ExprCXX.h:570
Represents a call to a C++ constructor.
Definition ExprCXX.h:1552
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1733
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition ExprCXX.h:1695
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1645
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.cpp:586
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.cpp:580
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1634
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1692
Represents a C++ constructor within a class.
Definition DeclCXX.h:2633
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1274
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1046
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1381
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2630
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3870
Represents a C++ destructor within a class.
Definition DeclCXX.h:2898
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:485
Helper that selects an expression from an InitListExpr depending on the current expansion index.
Definition ExprCXX.h:5554
Represents a C++26 expansion statement declaration.
Represents the code generated for an expanded expansion statement.
Definition StmtCXX.h:1028
static CXXExpansionStmtInstantiation * Create(ASTContext &C, CXXExpansionStmtDecl *Parent, ArrayRef< Stmt * > Instantiations, ArrayRef< Stmt * > PreambleStmts, bool ShouldApplyLifetimeExtensionToPreamble)
Definition StmtCXX.cpp:261
CXXExpansionStmtPattern - Represents an unexpanded C++ expansion statement.
Definition StmtCXX.h:675
static CXXExpansionStmtPattern * CreateIterating(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, DeclStmt *Range, DeclStmt *Begin, DeclStmt *Iter, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create an iterating expansion statement pattern.
Definition StmtCXX.cpp:194
static CXXExpansionStmtPattern * CreateEnumerating(ASTContext &Context, CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVar, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc)
Create an enumerating expansion statement pattern.
Definition StmtCXX.cpp:185
Represents a folding of a pack over an operator.
Definition ExprCXX.h:5032
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition StmtCXX.h:136
Represents an explicit C++ type conversion that uses "functional" notation (C++ [expr....
Definition ExprCXX.h:1835
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1755
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:183
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2145
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:379
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:410
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:417
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:413
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2359
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4309
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:772
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:85
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5141
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2749
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
unsigned getLambdaDependencyKind() const
Definition DeclCXX.h:1874
Represents a C++26 reflect expression [expr.reflect].
Definition ExprCXX.h:5504
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition ExprCXX.h:530
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:290
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2200
Represents a C++ nested-name-specifier or a global scope specifier.
Definition DeclSpec.h:76
void Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc)
Make a nested-name-specifier of the form 'type::'.
Definition DeclSpec.cpp:51
char * location_data() const
Retrieve the data associated with the source-location information.
Definition DeclSpec.h:209
SourceRange getRange() const
Definition DeclSpec.h:82
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition DeclSpec.cpp:75
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition DeclSpec.h:97
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition DeclSpec.cpp:123
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition DeclSpec.h:213
void Extend(ASTContext &Context, NamespaceBaseDecl *Namespace, SourceLocation NamespaceLoc, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'name...
Definition DeclSpec.cpp:62
void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition DeclSpec.cpp:85
bool isEmpty() const
No scope specifier.
Definition DeclSpec.h:181
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition DeclSpec.cpp:103
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition ExprCXX.h:804
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1903
Represents the this expression in C++.
Definition ExprCXX.h:1158
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1212
CXXTryStmt - A C++ try block, including all handlers.
Definition StmtCXX.h:70
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition ExprCXX.h:852
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3744
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3788
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3799
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3782
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3793
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3802
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition ExprCXX.h:1072
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:2949
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:1523
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:4988
unsigned getNumParams() const
Definition Decl.h:5026
unsigned getContextParamPosition() const
Definition Decl.h:5055
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5028
This captures a statement into a function.
Definition Stmt.h:3947
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition Stmt.cpp:1493
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition Stmt.h:4051
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:4142
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition Stmt.cpp:1508
CaseStmt - Represent a case statement.
Definition Stmt.h:1930
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition Expr.cpp:1986
Expr * getSubExpr()
Definition Expr.h:3732
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4854
Represents a 'co_await' expression.
Definition ExprCXX.h:5365
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4306
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3611
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1750
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1800
body_range body()
Definition Stmt.h:1813
SourceLocation getLBracLoc() const
Definition Stmt.h:1867
bool hasStoredFPFeatures() const
Definition Stmt.h:1797
Stmt * body_back()
Definition Stmt.h:1818
SourceLocation getRBracLoc() const
Definition Stmt.h:1868
Declaration of a C++20 concept.
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Represents the specialization of a concept - evaluates to a prvalue of type bool.
const TypeClass * getTypePtr() const
Definition TypeLoc.h:433
ConditionalOperator - The ?
Definition Expr.h:4397
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3824
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition Expr.h:1088
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4451
ContinueStmt - This represents a continue.
Definition Stmt.h:3129
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4725
Represents a 'co_return' statement in the C++ Coroutines TS.
Definition StmtCXX.h:474
Represents the body of a coroutine.
Definition StmtCXX.h:321
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition TypeBase.h:3500
Represents a 'co_yield' expression.
Definition ExprCXX.h:5446
Wrapper for source info for pointers decayed from arrays and functions.
Definition TypeLoc.h:1474
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1466
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2126
DeclContextLookupResult lookup_result
Definition DeclBase.h:2607
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
void addDecl(Decl *D)
Add the declaration D into this context.
bool isExpansionStmt() const
Definition DeclBase.h:2215
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1276
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1641
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool isInvalidDecl() const
Definition DeclBase.h:596
SourceLocation getLocation() const
Definition DeclBase.h:447
DeclContext * getDeclContext()
Definition DeclBase.h:456
AccessSpecifier getAccess() const
Definition DeclBase.h:515
The name of a declaration.
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
NameKind getNameKind() const
Determine what kind of name this is.
SourceLocation getInnerLocStart() const
Return start of source range ignoring outer template declarations.
Definition Decl.h:822
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:809
Information about one declarator, including the parsed type information and the identifier.
Definition DeclSpec.h:2001
void setDecltypeLoc(SourceLocation Loc)
Definition TypeLoc.h:2288
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2513
DeferStmt - This represents a deferred statement.
Definition Stmt.h:3246
static DeferStmt * Create(ASTContext &Context, SourceLocation DeferLoc, Stmt *Body)
Definition Stmt.cpp:1552
void setAttrOperandParensRange(SourceRange range)
Definition TypeLoc.h:1998
Represents an extended address space qualifier where the input address space value is dependent.
Definition TypeBase.h:4125
Represents a 'co_await' expression while the type of the promise is dependent.
Definition ExprCXX.h:5397
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2581
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3510
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3584
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3558
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3576
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3594
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3568
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3611
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3549
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3604
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3546
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h:4075
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2096
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4165
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition TypeBase.h:4537
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2068
Represents a vector type where either the type or size is dependent.
Definition TypeBase.h:4291
Represents a single C99 designator.
Definition Expr.h:5606
Represents a C99 designated initializer expression.
Definition Expr.h:5563
Designation - Represent a full designation, which is a sequence of designators.
Definition Designator.h:221
static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc)
Creates a GNU array-range designator.
Definition Designator.h:185
static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc)
Creates an array designator.
Definition Designator.h:155
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition Designator.h:115
bool hasErrorOccurred() const
Definition Diagnostic.h:882
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2842
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition TypeBase.h:5091
Expr * getCondition() const
Definition TypeBase.h:5098
void set(SourceLocation ElaboratedKeywordLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation NameLoc)
Definition TypeLoc.h:744
Represents a reference to emded data.
Definition Expr.h:5141
RAII object that enters a new expression evaluation context.
Wrapper for source info for enum types.
Definition TypeLoc.h:863
TypeSourceInfo * getTypeInfoAsWritten() const
getTypeInfoAsWritten - Returns the type source info for the type that this expression is casting to.
Definition Expr.h:3956
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3661
This represents one expression.
Definition Expr.h:112
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:177
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:194
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:454
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3091
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition Expr.cpp:3223
QualType getType() const
Definition Expr.h:144
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition Expr.h:526
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition Expr.h:437
An expression trait intrinsic.
Definition ExprCXX.h:3073
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6622
Represents difference between two FPOptions values.
FPOptions applyOverrides(FPOptions Base)
Represents a member of a struct/union/class.
Definition Decl.h:3204
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2898
Represents a function declaration or definition.
Definition Decl.h:2029
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2814
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5339
Represents an abstract function effect, using just an enumeration describing its kind.
Definition TypeBase.h:4984
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5746
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition Type.cpp:5732
ArrayRef< EffectConditionExpr > conditions() const
Definition TypeBase.h:5205
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:4949
Represents a reference to a function parameter pack, init-capture pack, or binding pack that has been...
Definition ExprCXX.h:4841
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5371
param_type_iterator param_type_begin() const
Definition TypeBase.h:5815
unsigned getNumParams() const
Definition TypeLoc.h:1716
SourceLocation getLocalRangeEnd() const
Definition TypeLoc.h:1668
void setLocalRangeBegin(SourceLocation L)
Definition TypeLoc.h:1664
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1680
SourceRange getExceptionSpecRange() const
Definition TypeLoc.h:1696
void setParam(unsigned i, ParmVarDecl *VD)
Definition TypeLoc.h:1723
ArrayRef< ParmVarDecl * > getParams() const
Definition TypeLoc.h:1707
void setRParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1688
void setLocalRangeEnd(SourceLocation L)
Definition TypeLoc.h:1672
void setExceptionSpecRange(SourceRange R)
Definition TypeLoc.h:1702
TypeLoc getReturnLoc() const
Definition TypeLoc.h:1725
SourceLocation getLocalRangeBegin() const
Definition TypeLoc.h:1660
SourceLocation getLParenLoc() const
Definition TypeLoc.h:1676
SourceLocation getRParenLoc() const
Definition TypeLoc.h:1684
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition TypeBase.h:4593
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3456
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4929
Represents a C11 generic selection.
Definition Expr.h:6194
AssociationTy< false > Association
Definition Expr.h:6427
GotoStmt - This represents a direct goto.
Definition Stmt.h:2979
Type source information for HLSL attributed resource type.
Definition TypeLoc.h:1113
void setSourceRange(const SourceRange &R)
Definition TypeLoc.h:1124
This class represents temporary values used to represent inout and out arguments in HLSL.
Definition Expr.h:7409
One of these records is kept for each identifier that is lexed.
IfStmt - This represents an if/then/else.
Definition Stmt.h:2269
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1737
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3859
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6069
Represents a C array with an unspecified size.
Definition TypeBase.h:3973
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3018
const TypeClass * getTypePtr() const
Definition TypeLoc.h:526
Describes an C or C++ initializer list.
Definition Expr.h:5314
InitListExpr * getSyntacticForm() const
Definition Expr.h:5484
Wrapper for source info for injected class names of class templates.
Definition TypeLoc.h:872
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:981
Represents the declaration of a label.
Definition Decl.h:524
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2156
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1972
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition ExprCXX.cpp:1370
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition ExprCXX.cpp:1365
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition ExprCXX.cpp:1374
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition ExprCXX.h:2037
Represents the results of name lookup.
Definition Lookup.h:147
This represents a Microsoft inline-assembly statement extension.
Definition Stmt.h:3675
Representation of a Microsoft __if_exists or __if_not_exists statement with a dependent name.
Definition StmtCXX.h:254
An instance of this class represents the declaration of a property member.
Definition DeclCXX.h:4370
A member reference to an MSPropertyDecl.
Definition ExprCXX.h:940
MS property subscript expression.
Definition ExprCXX.h:1010
void setExpansionLoc(SourceLocation Loc)
Definition TypeLoc.h:1383
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4920
MatrixSingleSubscriptExpr - Matrix single subscript expression for the MatrixType extension when you ...
Definition Expr.h:2801
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition Expr.h:2871
void setAttrNameLoc(SourceLocation loc)
Definition TypeLoc.h:2125
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3370
Wrapper for source info for member pointers.
Definition TypeLoc.h:1544
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3717
Data structure that captures multiple levels of template argument lists for use in template instantia...
Definition Template.h:76
This represents a decl that may have a name.
Definition Decl.h:274
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:301
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:340
Represents C++ namespaces and their aliases.
Definition Decl.h:573
Class that aids in the construction of nested-name-specifiers along with source-location information ...
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
A C++ nested-name-specifier augmented with source location information.
NestedNameSpecifier getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end 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.
SourceLocation getEndLoc() const
Retrieve the location of the end of this nested-name-specifier.
SourceLocation getBeginLoc() const
Retrieve the location of the beginning of this nested-name-specifier.
TypeLoc castAsTypeLoc() 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.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
NamespaceAndPrefix getAsNamespaceAndPrefix() const
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier, or null.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
Represents a place-holder for an object not to be initialized by anything.
Definition Expr.h:5889
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1713
This represents the 'align' clause in the 'pragma omp allocate' directive.
This represents clause 'allocate' in the 'pragma omp ...' directives.
This represents 'allocator' clause in the 'pragma omp ...' directive.
An explicit cast in C or a C-style cast in C++, which uses the syntax ([s1][s2]......
Definition ExprOpenMP.h:24
This is a basic class for representing single OpenMP clause.
OpenMPClauseKind getClauseKind() const
Returns kind of OpenMP clause (private, shared, reduction, etc.).
This represents 'collapse' clause in the 'pragma omp ...' directive.
This represents the 'counts' clause in the 'pragma omp split' directive.
This represents 'default' clause in the 'pragma omp ...' directive.
This represents 'final' clause in the 'pragma omp ...' directive.
Representation of the 'full' clause of the 'pragma omp unroll' directive.
This represents 'if' clause in the 'pragma omp ...' directive.
OpenMP 5.0 [2.1.6 Iterators] Iterators are identifiers that expand to multiple values in the clause o...
Definition ExprOpenMP.h:151
This class represents the 'looprange' clause in the 'pragma omp fuse' directive.
This represents 'num_threads' clause in the 'pragma omp ...' directive.
Representation of the 'partial' clause of the 'pragma omp unroll' directive.
This class represents the 'permutation' clause in the 'pragma omp interchange' directive.
This represents 'safelen' clause in the 'pragma omp ...' directive.
This represents 'simdlen' clause in the 'pragma omp ...' directive.
This represents the 'sizes' clause in the 'pragma omp tile' directive.
This represents 'threadset' clause in the 'pragma omp task ...' directive.
ObjCArrayLiteral - used for objective-c array containers; as in: @["Hello", NSApp,...
Definition ExprObjC.h:220
Represents Objective-C's @catch statement.
Definition StmtObjC.h:77
Represents Objective-C's @finally statement.
Definition StmtObjC.h:127
Represents Objective-C's @synchronized statement.
Definition StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition StmtObjC.h:167
Represents Objective-C's @autoreleasepool Statement.
Definition StmtObjC.h:394
A runtime availability query.
Definition ExprObjC.h:1734
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition ExprObjC.h:119
ObjCBoxedExpr - used for generalized expression boxing.
Definition ExprObjC.h:159
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition ExprObjC.h:1674
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition ExprObjC.h:342
ObjCEncodeExpr, used for @encode in Objective-C.
Definition ExprObjC.h:441
Represents Objective-C's collection statement.
Definition StmtObjC.h:23
ObjCIndirectCopyRestoreExpr - Represents the passing of a function argument by indirect copy-restore ...
Definition ExprObjC.h:1613
Wrapper for source info for ObjC interfaces.
Definition TypeLoc.h:1303
ObjCIsaExpr - Represent X->isa and X.isa when X is an ObjC 'id' type.
Definition ExprObjC.h:1529
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1952
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition ExprObjC.h:580
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:971
@ SuperInstance
The receiver is the instance of the superclass object.
Definition ExprObjC.h:985
@ Instance
The receiver is an object instance.
Definition ExprObjC.h:979
@ SuperClass
The receiver is a superclass.
Definition ExprObjC.h:982
@ Class
The receiver is a class.
Definition ExprObjC.h:976
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Wraps an ObjCPointerType with source location information.
Definition TypeLoc.h:1586
void setStarLoc(SourceLocation Loc)
Definition TypeLoc.h:1592
void setHasBaseTypeAsWritten(bool HasBaseType)
Definition TypeLoc.h:1258
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:731
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition ExprObjC.h:648
ObjCProtocolExpr used for protocol expression in Objective-C.
Definition ExprObjC.h:536
ObjCSelectorExpr used for @selector in Objective-C.
Definition ExprObjC.h:486
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition ExprObjC.h:84
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition ExprObjC.h:870
Represents the declaration of an Objective-C type parameter.
Definition DeclObjC.h:578
ProtocolLAngleLoc, ProtocolRAngleLoc, and the source locations for protocol qualifiers are stored aft...
Definition TypeLoc.h:895
@ Array
An index into an array.
Definition Expr.h:2432
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2436
@ Field
A field.
Definition Expr.h:2434
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2439
static OpaquePtr make(QualType P)
Definition Ownership.h:61
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition Expr.h:1184
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1234
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition Expr.h:2096
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.
Represents a 'collapse' clause on a 'loop' construct.
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, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyInClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCopyOutClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCCreateClause * Create(const ASTContext &C, OpenACCClauseKind Spelling, SourceLocation BeginLoc, SourceLocation LParenLoc, OpenACCModifierKind Mods, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDefaultAsyncClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
A 'default' clause, has the optional 'none' or 'present' argument.
static OpenACCDefaultClause * Create(const ASTContext &C, OpenACCDefaultClauseKind K, SourceLocation BeginLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
static OpenACCDeleteClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDetachClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
static OpenACCDeviceNumClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, Expr *IntExpr, SourceLocation EndLoc)
static OpenACCDevicePtrClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
A 'device_type' or 'dtype' clause, takes a list of either an 'asterisk' or an identifier.
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, ArrayRef< OpenACCFirstPrivateRecipe > InitRecipes, SourceLocation EndLoc)
static OpenACCHostClause * Create(const ASTContext &C, SourceLocation BeginLoc, SourceLocation LParenLoc, ArrayRef< Expr * > VarList, SourceLocation EndLoc)
An 'if' clause, which has a required condition expression.
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, ArrayRef< OpenACCPrivateRecipe > InitRecipes, SourceLocation EndLoc)
A 'self' clause, which has an optional condition expression, or, in the event of an 'update' directiv...
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)
void initializeLocal(ASTContext &Context, SourceLocation loc)
Definition TypeLoc.h:1093
A reference to an overloaded function set, either an UnresolvedLookupExpr or an UnresolvedMemberExpr.
Definition ExprCXX.h:3132
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3284
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3266
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3245
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3258
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3254
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3324
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3231
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3330
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3242
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3274
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition ExprCXX.h:3281
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition ExprCXX.h:4363
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2633
SourceLocation getEllipsisLoc() const
Definition TypeLoc.h:2629
TypeLoc getPatternLoc() const
Definition TypeLoc.h:2645
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2316
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2188
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2213
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2217
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1411
Represents a parameter to a function.
Definition Decl.h:1819
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1879
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1852
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:2934
unsigned getFunctionScopeDepth() const
Definition Decl.h:1869
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2725
PipeType - OpenCL20.
Definition TypeBase.h:8265
bool isReadOnly() const
Definition TypeBase.h:8295
Pointer-authentication qualifiers.
Definition TypeBase.h:152
void setSigilLoc(SourceLocation Loc)
Definition TypeLoc.h:1490
TypeLoc getPointeeLoc() const
Definition TypeLoc.h:1494
SourceLocation getSigilLoc() const
Definition TypeLoc.h:1486
Wrapper for source info for pointers.
Definition TypeLoc.h:1513
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3392
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2011
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2698
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6816
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8447
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8479
Represents a template name as written in source code.
Wrapper of type source information for a type with non-trivial direct qualifiers.
Definition TypeLoc.h:300
The collection of all-type qualifiers we support.
Definition TypeBase.h:331
void removeObjCLifetime()
Definition TypeBase.h:551
bool hasRestrict() const
Definition TypeBase.h:477
static Qualifiers fromCVRMask(unsigned CVR)
Definition TypeBase.h:435
PointerAuthQualifier getPointerAuth() const
Definition TypeBase.h:603
bool hasObjCLifetime() const
Definition TypeBase.h:544
bool empty() const
Definition TypeBase.h:647
LangAS getAddressSpace() const
Definition TypeBase.h:571
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition Expr.h:7515
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3637
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3653
Represents the body of a requires-expression.
Definition DeclCXX.h:2114
static RequiresExprBodyDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
Definition DeclCXX.cpp:2405
C++2a [expr.prim.req]: A requires-expression provides a concise way to express requirements on templa...
static RequiresExpr * Create(ASTContext &C, SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, SourceLocation LParenLoc, ArrayRef< ParmVarDecl * > LocalParameters, SourceLocation RParenLoc, ArrayRef< concepts::Requirement * > Requirements, SourceLocation RBraceLoc)
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition Stmt.h:3170
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition Stmt.cpp:1361
Represents a __leave statement.
Definition Stmt.h:3908
SYCLKernelCallStmt represents the transformation that is applied to the body of a function declared w...
Definition StmtSYCL.h:36
Smart pointer class that efficiently represents Objective-C method names.
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition SemaBase.cpp:61
bool diagnoseMatrixLayoutInstantiation(attr::Kind K, QualType T, SourceLocation Loc)
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:193
ExprResult BuildObjCDictionaryLiteral(SourceRange SR, MutableArrayRef< ObjCDictionaryElement > Elements)
StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, Stmt *SynchBody)
Definition SemaObjC.cpp:320
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:218
StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Definition SemaObjC.cpp:213
StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw)
Definition SemaObjC.cpp:238
ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, Expr *operand)
Definition SemaObjC.cpp:282
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:202
StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body)
Definition SemaObjC.cpp:329
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.
Helper type for the registration/assignment of constructs that need to 'know' about their parent cons...
Helper type to restore the state of various 'loop' constructs when we run into a loop (for,...
A type to represent all the data for an OpenACC Clause that has been parsed, but not yet created/sema...
void ActOnWhileStmt(SourceLocation WhileLoc)
ExprResult ActOnOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
void ActOnDoStmt(SourceLocation DoLoc)
void ActOnRangeForStmtBegin(SourceLocation ForLoc, const Stmt *OldRangeFor, const Stmt *RangeFor)
StmtResult ActOnEndStmtDirective(OpenACCDirectiveKind K, SourceLocation StartLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation MiscLoc, ArrayRef< Expr * > Exprs, OpenACCAtomicKind AK, SourceLocation RParenLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssocStmt)
Called after the directive has been completely parsed, including the declaration group or associated ...
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 * ActOnOpenMPFilterClause(Expr *ThreadID, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'filter' clause.
OMPClause * ActOnOpenMPFullClause(SourceLocation StartLoc, SourceLocation EndLoc)
Called on well-form 'full' clauses.
OMPClause * ActOnOpenMPDetachClause(Expr *Evt, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'detach' clause.
OMPClause * ActOnOpenMPUseClause(Expr *InteropVar, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'use' clause.
OMPClause * ActOnOpenMPPrivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'private' clause.
OMPClause * ActOnOpenMPOrderedClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc=SourceLocation(), Expr *NumForLoops=nullptr)
Called on well-formed 'ordered' clause.
OMPClause * ActOnOpenMPIsDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'is_device_ptr' clause.
OMPClause * ActOnOpenMPCountsClause(ArrayRef< Expr * > CountExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, std::optional< unsigned > FillIdx, SourceLocation FillLoc, unsigned FillCount)
Called on well-formed 'counts' clause after parsing its arguments.
OMPClause * ActOnOpenMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'has_device_addr' clause.
OMPClause * ActOnOpenMPPartialClause(Expr *FactorExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'partial' clauses.
OMPClause * ActOnOpenMPLastprivateClause(ArrayRef< Expr * > VarList, OpenMPLastprivateModifier LPKind, SourceLocation LPKindLoc, SourceLocation ColonLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'lastprivate' clause.
OMPClause * ActOnOpenMPFirstprivateClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'firstprivate' clause.
OMPClause * ActOnOpenMPPriorityClause(Expr *Priority, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'priority' clause.
OMPClause * ActOnOpenMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc)
Called on well-formed 'dist_schedule' clause.
OMPClause * ActOnOpenMPLoopRangeClause(Expr *First, Expr *Count, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation FirstLoc, SourceLocation CountLoc, SourceLocation EndLoc)
Called on well-form 'looprange' clause after parsing its arguments.
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 * 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 * 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 * ActOnOpenMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, OpenMPUseDevicePtrFallbackModifier FallbackModifier, SourceLocation FallbackModifierLoc)
Called on well-formed 'use_device_ptr' 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 * ActOnOpenMPNowaitClause(SourceLocation StartLoc, SourceLocation EndLoc, SourceLocation LParenLoc, Expr *Condition)
Called on well-formed 'nowait' clause.
OMPClause * ActOnOpenMPOrderClause(OpenMPOrderClauseModifier Modifier, OpenMPOrderClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Called on well-formed 'order' clause.
OMPClause * ActOnOpenMPSizesClause(ArrayRef< Expr * > SizeExprs, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-form 'sizes' clause.
OMPClause * ActOnOpenMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'device' clause.
OMPClause * 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 * 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.
OMPClause * ActOnOpenMPNumTeamsClause(ArrayRef< Expr * > VarList, OpenMPNumTeamsClauseModifier Modifier, Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' clause.
StmtResult ActOnOpenMPCanonicalLoop(Stmt *AStmt)
Called for syntactical loops (ForStmt or CXXForRangeStmt) associated to an OpenMP loop directive.
OMPClause * ActOnOpenMPTransparentClause(Expr *Transparent, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'transparent' clause.
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 * ActOnOpenMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_threads' clause.
OMPClause * ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'at' clause.
OMPClause * ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'init' clause.
OMPClause * ActOnOpenMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_addr' clause.
OMPClause * ActOnOpenMPAllocateClause(Expr *Allocator, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation ColonLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'allocate' clause.
OMPClause * ActOnOpenMPFinalClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'final' clause.
OMPClause * ActOnOpenMPMapClause(Expr *IteratorModifier, ArrayRef< OpenMPMapModifierKind > MapTypeModifiers, ArrayRef< SourceLocation > MapTypeModifiersLoc, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, bool NoDiagnose=false, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'map' clause.
OMPClause * ActOnOpenMPNumTasksClause(OpenMPNumTasksClauseModifier Modifier, Expr *NumTasks, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Called on well-formed 'num_tasks' clause.
OMPClause * ActOnOpenMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'from' clause.
OMPClause * ActOnOpenMPDynGroupprivateClause(OpenMPDynGroupprivateClauseModifier M1, OpenMPDynGroupprivateClauseFallbackModifier M2, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation EndLoc)
Called on a well-formed 'dyn_groupprivate' clause.
void StartOpenMPDSABlock(OpenMPDirectiveKind K, const DeclarationNameInfo &DirName, Scope *CurScope, SourceLocation Loc)
Called on start of new data sharing attribute block.
OMPClause * ActOnOpenMPSeverityClause(OpenMPSeverityClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'severity' clause.
OMPClause * ActOnOpenMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers={})
Called on well-formed 'to' 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 * ActOnOpenMPReductionClause(ArrayRef< Expr * > VarList, OpenMPVarListDataTy::OpenMPReductionClauseModifiers Modifiers, 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 * 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 * ActOnOpenMPDefaultClause(llvm::omp::DefaultKind M, SourceLocation MLoc, OpenMPDefaultClauseVariableCategory VCKind, SourceLocation VCKindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'default' 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.
Expr * recreateSyntacticForm(PseudoObjectExpr *E)
Given a pseudo-object expression, recreate what it looks like syntactically without the attendant Opa...
ExprResult checkRValue(Expr *E)
StmtResult BuildSYCLKernelCallStmt(FunctionDecl *FD, CompoundStmt *Body, Expr *LaunchIdExpr)
Builds a SYCLKernelCallStmt to wrap 'Body' and to be used as the body of 'FD'.
Definition SemaSYCL.cpp:774
ExprResult BuildUniqueStableNameExpr(SourceLocation OpLoc, SourceLocation LParen, SourceLocation RParen, TypeSourceInfo *TSI)
Definition SemaSYCL.cpp:154
RAII object used to change the argument pack substitution index within a Sema object.
Definition Sema.h:13801
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition Sema.h:8535
A RAII object to enter scope of a compound statement.
Definition Sema.h:1317
A RAII object to temporarily push a declaration context.
Definition Sema.h:3532
A helper class for building up ExtParameterInfos.
Definition Sema.h:13162
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:13181
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition Sema.h:13169
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition Sema.h:14191
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:869
ParsedType CreateParsedType(QualType T, TypeSourceInfo *TInfo)
Package the given type and TSI into a ParsedType.
ExprResult ActOnCXXParenListInitExpr(ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
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)
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition Sema.h:9421
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9429
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition Sema.h:9424
bool checkFinalSuspendNoThrow(const Stmt *FinalSuspend)
Check that the expression co_await promise.final_suspend() shall not be potentially-throwing.
ExprResult CreateBuiltinMatrixSingleSubscriptExpr(Expr *Base, Expr *RowIdx, SourceLocation RBLoc)
ExprResult ActOnConstantExpression(ExprResult Res)
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)
SemaOpenMP & OpenMP()
Definition Sema.h:1535
void ActOnStartStmtExpr()
void ActOnStmtExprError()
void MarkDeclarationsReferencedInExpr(Expr *E, bool SkipLocalVariables=false, ArrayRef< const Expr * > StopAt={})
Mark any declarations that appear within this expression or any potentially-evaluated subexpressions ...
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...
@ Boolean
A boolean condition, from 'if', 'while', 'for', or 'do'.
Definition Sema.h:7925
@ Switch
An integral condition for a 'switch' statement.
Definition Sema.h:7927
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
Definition Sema.h:7926
const ExpressionEvaluationContextRecord & currentEvaluationContext() const
Definition Sema.h:7023
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
Definition SemaCast.cpp:439
StmtResult ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, LabelDecl *TheDecl)
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:486
StmtResult BuildNonEnumeratingCXXExpansionStmtPattern(CXXExpansionStmtDecl *ESD, Stmt *Init, DeclStmt *ExpansionVarStmt, Expr *ExpansionInitializer, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation RParenLoc, ArrayRef< MaterializeTemporaryExpr * > LifetimeExtendTemps={})
ExprResult BuildStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, SourceLocation RPLoc, unsigned TemplateDepth)
ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, Expr *Awaiter, bool IsImplicit=false)
SemaSYCL & SYCL()
Definition Sema.h:1560
ExprResult BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, TypeSourceInfo *TInfo, SourceLocation RPLoc)
@ CTAK_Specified
The template argument was specified in the code or was instantiated with some deduced template argume...
Definition Sema.h:12109
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:1310
ExprResult BuildCXXTypeId(QualType TypeInfoType, SourceLocation TypeidLoc, TypeSourceInfo *Operand, SourceLocation RParenLoc)
Build a C++ typeid expression with a type operand.
ExprResult PerformMemberExprBaseConversion(Expr *Base, bool IsArrow)
Perform conversions on the LHS of a member access expression.
DiagnosticsEngine & getDiagnostics() const
Definition Sema.h:938
SemaObjC & ObjC()
Definition Sema.h:1520
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:941
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)
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)
ExprResult BuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
ExprResult CheckConceptTemplateId(const CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &ConceptNameInfo, NamedDecl *FoundDecl, TemplateDecl *NamedConcept, const TemplateArgumentListInfo *TemplateArgs, bool DoCheckConstraintSatisfaction=true)
ExprResult BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *LiteralExpr)
ExprResult ActOnAddrLabel(SourceLocation OpLoc, SourceLocation LabLoc, LabelDecl *TheDecl)
ActOnAddrLabel - Parse the GNU address of label extension: "&&foo".
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
QualType BuildCountAttributedArrayOrPointerType(QualType WrappedTy, Expr *CountExpr, bool CountInBytes, bool OrNull)
ExprResult BuildCXXNew(SourceRange Range, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, QualType AllocType, TypeSourceInfo *AllocTypeInfo, std::optional< Expr * > ArraySize, SourceRange DirectInitRange, Expr *Initializer)
ExprResult BuildBuiltinOffsetOf(SourceLocation BuiltinLoc, TypeSourceInfo *TInfo, const Designation &Desig, SourceLocation RParenLoc)
__builtin_offsetof(type, a.b[123][456].c)
DeclRefExpr * BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, SourceLocation Loc, const CXXScopeSpec *SS=nullptr)
ExprResult BuildCXXFoldExpr(UnresolvedLookupExpr *Callee, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
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 *.
bool CheckTemplateArgument(NamedDecl *Param, TemplateArgumentLoc &Arg, NamedDecl *Template, SourceLocation TemplateLoc, SourceLocation RAngleLoc, unsigned ArgumentPackIndex, CheckTemplateArgumentInfo &CTAI, CheckTemplateArgumentKind CTAK)
Check that the given template argument corresponds to the given template parameter.
StmtResult ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, Stmt *Body)
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Calls Lexer::getLocForEndOfToken()
Definition Sema.cpp:84
const LangOptions & getLangOpts() const
Definition Sema.h:934
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
SemaOpenACC & OpenACC()
Definition Sema.h:1525
@ ReuseLambdaContextDecl
Definition Sema.h:7114
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)
ExprResult BuildCXXTypeConstructExpr(TypeSourceInfo *Type, SourceLocation LParenLoc, MultiExprArg Exprs, SourceLocation RParenLoc, bool ListInitialization)
ExprResult TemporaryMaterializationConversion(Expr *E)
If E is a prvalue denoting an unmaterialized temporary, materialize it as an xvalue.
SemaHLSL & HLSL()
Definition Sema.h:1485
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) const
Definition Sema.h:11911
ExprResult BuildUnresolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, UnresolvedLookupExpr *Lookup)
ExprResult BuildExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, Expr *Queried, SourceLocation RParen)
bool buildCoroutineParameterMoves(SourceLocation Loc)
ExprResult BuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *Ty, SourceLocation RParenLoc, Expr *Op)
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:1343
DeclGroupPtrTy BuildDeclaratorGroup(MutableArrayRef< Decl * > Group)
BuildDeclaratorGroup - convert a list of declarations into a declaration group, performing any necess...
Expr * BuildCXXThisExpr(SourceLocation Loc, QualType Type, bool IsImplicit)
Build a CXXThisExpr and mark it referenced in the current context.
UnsignedOrNone getPackIndex(TemplateArgument Pack) const
Definition Sema.h:11906
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition Sema.cpp:2652
void ApplyForRangeOrExpansionStatementLifetimeExtension(VarDecl *RangeVar, ArrayRef< MaterializeTemporaryExpr * > Temporaries)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition Sema.h:1448
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,...
void MarkDeclRefReferenced(DeclRefExpr *E, const Expr *Base=nullptr)
Perform reference-marking and odr-use handling for a DeclRefExpr.
ExprResult BuildQualifiedDeclarationNameExpr(CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, bool IsAddressOfOperand, TypeSourceInfo **RecoveryTSI=nullptr)
BuildQualifiedDeclarationNameExpr - Build a C++ qualified declaration name, generally during template...
StmtResult ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, Stmt *First, ConditionResult Second, FullExprArg Third, SourceLocation RParenLoc, Stmt *Body)
StmtResult ActOnIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *DestExp)
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
ExprResult BuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, unsigned Index, QualType ParamType, SourceLocation loc, TemplateArgument Replacement, UnsignedOrNone PackIndex, bool Final)
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...
ExprResult BuildAsTypeExpr(Expr *E, QualType DestTy, SourceLocation BuiltinLoc, SourceLocation RParenLoc)
Create a new AsTypeExpr node (bitcast) from the arguments.
ExprResult BuildFieldReferenceExpr(Expr *BaseExpr, bool IsArrow, SourceLocation OpLoc, const CXXScopeSpec &SS, FieldDecl *Field, DeclAccessPair FoundDecl, const DeclarationNameInfo &MemberNameInfo)
ExprResult ActOnConditionalOp(SourceLocation QuestionLoc, SourceLocation ColonLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr)
ActOnConditionalOp - Parse a ?
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.
StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp, bool AllowRecovery=false)
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.
StmtResult ActOnDoStmt(SourceLocation DoLoc, Stmt *Body, SourceLocation WhileLoc, SourceLocation CondLParen, Expr *Cond, SourceLocation CondRParen)
StmtResult ActOnStartOfSwitchStmt(SourceLocation SwitchLoc, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc)
ExprResult BuildQualifiedTemplateIdExpr(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs, bool IsAddressOfOperand)
@ ConstantEvaluated
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
Definition Sema.h:6824
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6834
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6803
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
Definition Sema.h:6829
StmtResult ActOnSEHExceptBlock(SourceLocation Loc, Expr *FilterExpr, Stmt *Block)
ExprResult CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, SourceLocation OpLoc, UnaryExprOrTypeTrait ExprKind, SourceRange R)
Build a sizeof or alignof expression given a type operand.
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition SemaStmt.cpp:76
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
ExprResult PerformObjectMemberConversion(Expr *From, NestedNameSpecifier Qualifier, NamedDecl *FoundDecl, NamedDecl *Member)
Cast a base object to a member's actual type.
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:8404
ExprResult BuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, BinaryOperatorKind Operator)
ExprResult BuildCXXThrow(SourceLocation OpLoc, Expr *Ex, bool IsThrownVarInScope)
ExprResult BuildCXXExpansionSelectExpr(InitListExpr *Range, Expr *Idx)
ExprResult BuildBinOp(Scope *S, SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHSExpr, Expr *RHSExpr, bool ForFoldExpression=false)
StmtResult FinishCXXExpansionStmt(Stmt *Expansion, Stmt *Body)
ExprResult BuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field)
ExprResult BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc)
Complete a lambda-expression having processed and attached the lambda body.
@ BFRK_Rebuild
Instantiation or recovery rebuild of a for-range statement.
Definition Sema.h:11159
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition SemaStmt.cpp:586
ExprResult ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, Scope *CurScope)
ActOnBlockStmtExpr - This is called when the body of a block statement literal was successfully compl...
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.
ExprResult BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, TypeSourceInfo *Ty, Expr *E, SourceRange AngleBrackets, SourceRange Parens)
Definition SemaCast.cpp:338
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,...
ExprResult CreateRecoveryExpr(SourceLocation Begin, SourceLocation End, ArrayRef< Expr * > SubExprs, QualType T=QualType())
Attempts to produce a RecoveryExpr after some AST node cannot be created.
ExprResult ActOnGCCAsmStmtString(Expr *Stm, bool ForAsmLabel)
StmtResult ActOnIfStmt(SourceLocation IfLoc, IfStatementKind StatementKind, SourceLocation LParenLoc, Stmt *InitStmt, ConditionResult Cond, SourceLocation RParenLoc, Stmt *ThenVal, SourceLocation ElseLoc, Stmt *ElseVal)
Definition SemaStmt.cpp:976
void ActOnBlockStart(SourceLocation CaretLoc, Scope *CurScope)
ActOnBlockStart - This callback is invoked when a block literal is started.
ExprResult ActOnArraySubscriptExpr(Scope *S, Expr *Base, SourceLocation LLoc, MultiExprArg ArgExprs, SourceLocation RLoc)
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.
OpaquePtr< TemplateName > TemplateTy
Definition Sema.h:1302
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Definition Sema.h:7911
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition SemaStmt.cpp:437
SemaPseudoObject & PseudoObject()
Definition Sema.h:1545
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...
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Definition Sema.h:1301
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition SemaStmt.cpp:591
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition SemaStmt.cpp:552
TypeSourceInfo * CheckPackExpansion(TypeSourceInfo *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Construct a pack expansion type from the pattern of the pack expansion.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
FinishCXXForRangeStmt - Attach the body to a C++0x for-range statement.
ExprResult ActOnFinishFullExpr(Expr *Expr, bool DiscardedValue)
Definition Sema.h:8749
ExprResult CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, Expr *ColumnIdx, SourceLocation RBLoc)
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)
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition Expr.h:4649
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4441
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4503
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4526
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1716
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4531
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4500
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4506
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4509
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:5032
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition Expr.h:5092
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition Expr.h:4601
Stmt - This represents one statement.
Definition Stmt.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:367
@ NoStmtClass
Definition Stmt.h:89
StmtClass getStmtClass() const
Definition Stmt.h:1503
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
StringLiteral - This represents a string literal expression, e.g.
Definition Expr.h:1805
Wrapper for substituted template type parameters.
Definition TypeLoc.h:998
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition ExprCXX.h:4664
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4754
A structure for storing an already-substituted template template parameter pack.
A structure for storing the information associated with a substituted template template parameter.
Wrapper for substituted template type parameters.
Definition TypeLoc.h:992
SwitchStmt - This represents a 'switch' stmt.
Definition Stmt.h:2519
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3761
SourceLocation getNameLoc() const
Definition TypeLoc.h:822
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:801
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:809
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition TypeLoc.h:816
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:824
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:805
A convenient class for passing around template argument information.
void setLAngleLoc(SourceLocation Loc)
void setRAngleLoc(SourceLocation Loc)
void addArgument(const TemplateArgumentLoc &Loc)
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)
Location wrapper for a TemplateArgument.
const TemplateArgument & getArgument() const
SourceLocation getTemplateNameLoc() const
SourceLocation getTemplateKWLoc() const
TypeSourceInfo * getTypeSourceInfo() const
Expr * getSourceExpression() const
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Represents a template argument.
Expr * getAsExpr() const
Retrieve the template argument as an expression.
const TemplateArgument * pack_iterator
Iterator that traverses the elements of a template argument pack.
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.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
bool containsUnexpandedParameterPack() const
Whether this template argument contains an unexpanded parameter pack.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
bool isPackExpansion() const
Determine whether this template argument is a pack expansion.
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
Represents a C++ template name within the type system.
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DeducedTemplateStorage * getAsDeducedTemplateName() const
Retrieve the deduced template info, if any.
bool isNull() const
Determine whether this template name is NULL.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
NestedNameSpecifier getQualifier() const
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
SourceLocation getLAngleLoc() const
Definition TypeLoc.h:1907
SourceLocation getRAngleLoc() const
Definition TypeLoc.h:1922
SourceLocation getTemplateNameLoc() const
Definition TypeLoc.h:1905
SourceLocation getTemplateKeywordLoc() const
Definition TypeLoc.h:1901
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:1891
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:1887
Wrapper for template type parameters.
Definition TypeLoc.h:881
The top declaration context.
Definition Decl.h:105
RAII object that temporarily sets the base location and entity used for reporting diagnostics in type...
TemporaryBase(const TemporaryBase &)=delete
TemporaryBase(TreeTransform &Self, SourceLocation Location, DeclarationName Entity)
TemporaryBase & operator=(const TemporaryBase &)=delete
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)
TemplateArgument TransformNamedTemplateTemplateArgument(NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc, TemplateName Name, SourceLocation NameLoc)
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.
ParmVarDecl * TransformFunctionTypeParam(ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions, bool ExpectParameterPack)
Transforms a single function-type parameter.
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)
ExprResult TransformLambdaConstraint(Expr *AC)
StmtResult RebuildOpenACCShutdownConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
OMPClause * RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment, OpenMPAllocateClauseModifier FirstModifier, SourceLocation FirstModifierLoc, OpenMPAllocateClauseModifier SecondModifier, SourceLocation SecondModifierLoc, ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocate' clause.
ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, SourceLocation OpLoc, bool IsArrow)
Build a new Objective-C "isa" expression.
StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body)
Build a new Objective-C @finally statement.
SourceLocation getBaseLocation()
Returns the location of the entity being transformed, if that information was not available elsewhere...
ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, Expr *ExecConfig=nullptr)
Build a new call expression.
ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, SourceLocation IvarLoc, bool IsArrow, bool IsFreeIvar)
Build a new Objective-C ivar reference expression.
OMPClause * RebuildOMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KwLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'at' clause.
StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, bool IsImplicit)
Build a new co_return statement.
OMPClause * RebuildOMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'in_reduction' clause.
ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *Init)
Build a new compound literal expression.
ExprResult TransformAddressOfOperand(Expr *E)
The operand of a unary address-of operator has special rules: it's allowed to refer to a non-static m...
ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, QualType ThisType, bool isImplicit)
Build a new C++ "this" expression.
ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, SourceLocation TypeidLoc, Expr *Operand, SourceLocation RParenLoc)
Build a new C++ typeid(expr) expression.
TreeTransform(Sema &SemaRef)
Initializes a new tree transformer.
QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, SourceLocation AttributeLoc)
Build a new matrix type given the type and dependently-defined dimensions.
QualType RebuildTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, TagDecl *Tag)
Build a new class/struct/union/enum type.
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 RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new expression pack expansion.
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.
TemplateName RebuildTemplateName(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final)
Build a new template name given a template template parameter pack and the.
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.
QualType RebuildUnresolvedUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, SourceLocation NameLoc, Decl *D)
Rebuild an unresolved typename type, given the decl that the UnresolvedUsingTypenameDecl was transfor...
OMPClause * RebuildOMPSizesClause(ArrayRef< Expr * > Sizes, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
ExprResult RebuildPredefinedExpr(SourceLocation Loc, PredefinedIdentKind IK)
Build a new predefined expression.
ExprResult RebuildInitList(SourceLocation LBraceLoc, MultiExprArg Inits, SourceLocation RBraceLoc, bool IsExplicit)
Build a new initializer list expression.
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.
OMPClause * RebuildOpenMPTransparentClause(Expr *ImpexType, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
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.
OMPClause * RebuildOMPNowaitClause(Expr *Condition, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'nowait' clause.
QualType TransformType(QualType T)
Transforms the given type into another type.
UnsignedOrNone ComputeSizeOfPackExprWithoutSubstitution(ArrayRef< TemplateArgument > PackArgs)
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.
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)
OMPClause * RebuildOMPXBareClause(SourceLocation StartLoc, SourceLocation EndLoc)
Build a new OpenMP 'ompx_bare' clause.
const Attr * TransformStmtAttr(const Stmt *OrigS, const Stmt *InstS, const Attr *A)
ExprResult RebuildConditionalOperator(Expr *Cond, SourceLocation QuestionLoc, Expr *LHS, SourceLocation ColonLoc, Expr *RHS)
Build a new conditional operator expression.
StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body)
Attach body to a C++0x range-based for statement.
StmtResult RebuildOpenACCUpdateConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses)
StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *Object, Stmt *Body)
Build a new Objective-C @synchronized statement.
ExprResult RebuildOpenACCAsteriskSizeExpr(SourceLocation AsteriskLoc)
OMPClause * RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, Expr *Device, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'device' clause.
OMPClause * RebuildOMPHasDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Build a new OpenMP 'has_device_addr' clause.
bool TryExpandParameterPacks(SourceLocation EllipsisLoc, SourceRange PatternRange, ArrayRef< UnexpandedParameterPack > Unexpanded, bool FailOnPackProducingTemplates, bool &ShouldExpand, bool &RetainExpansion, UnsignedOrNone &NumExpansions)
Determine whether we should expand a pack expansion with the given set of parameter packs into separa...
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...
OMPClause * RebuildOMPNumThreadsClause(OpenMPNumThreadsClauseModifier Modifier, Expr *NumThreads, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_threads' clause.
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.
ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, UnresolvedLookupExpr *Lookup)
Build a new co_await expression.
StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result)
Build a new return statement.
QualType TransformTemplateSpecializationType(TypeLocBuilder &TLB, TemplateSpecializationTypeLoc TL, QualType ObjectType, NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName)
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.
QualType RebuildParenType(QualType InnerType)
Build a new parenthesized type.
QualType RebuildAutoType(DeducedKind DK, QualType DeducedAsType, AutoTypeKeyword Keyword, ConceptDecl *TypeConstraintConcept, ArrayRef< TemplateArgument > TypeConstraintArgs)
Build a new C++11 auto type.
static StmtResult Owned(Stmt *S)
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.
QualType RebuildMemberPointerType(QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls, SourceLocation Sigil)
Build a new member pointer type given the pointee type and the qualifier it refers into.
ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, TemplateArgumentListInfo *TALI)
OMPClause * RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, OpenMPDefaultmapClauseKind Kind, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation MLoc, SourceLocation KindLoc, SourceLocation EndLoc)
Build a new OpenMP 'defaultmap' clause.
StmtResult RebuildOpenACCCacheConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc, SourceLocation ReadOnlyLoc, ArrayRef< Expr * > VarList, SourceLocation RParenLoc, SourceLocation EndLoc)
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.
OMPClause * RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, OpenMPDefaultClauseVariableCategory VCKind, SourceLocation VCLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'default' clause.
StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, Sema::ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
Build a new while statement.
OMPClause * RebuildOMPDynGroupprivateClause(OpenMPDynGroupprivateClauseModifier M1, OpenMPDynGroupprivateClauseFallbackModifier M2, Expr *Size, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, SourceLocation EndLoc)
Build a new OpenMP 'dyn_groupprivate' 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)
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
Build a new template name given a nested name specifier and the name that is referred to as a templat...
TemplateName RebuildTemplateName(CXXScopeSpec &SS, bool TemplateKW, TemplateName Name)
Build a new template name given a nested name specifier, a flag indicating whether the "template" key...
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.
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.
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 RebuildMatrixSingleSubscriptExpr(Expr *Base, Expr *RowIdx, SourceLocation RBracketLoc)
Build a new matrix single subscript expression.
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 RebuildBinaryOperator(SourceLocation OpLoc, BinaryOperatorKind Opc, Expr *LHS, Expr *RHS, bool ForFoldExpression=false)
Build a new binary operator expression.
ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, Expr *Base, Expr *Key, ObjCMethodDecl *getterMethod, ObjCMethodDecl *setterMethod)
OMPClause * RebuildOMPCountsClause(ArrayRef< Expr * > Counts, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc, std::optional< unsigned > FillIdx, SourceLocation FillLoc)
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.
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.
QualType RebuildCanonicalTagType(TagDecl *Tag)
ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, MutableArrayRef< ObjCDictionaryElement > Elements)
Build a new Objective-C dictionary literal.
StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, SourceLocation StarLoc, Expr *Target)
Build a new indirect goto statement.
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 * RebuildOMPTransparentClause(Expr *ImpexTypeArg, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, SourceLocation LParenLoc, Expr *LHS, BinaryOperatorKind Operator, SourceLocation EllipsisLoc, Expr *RHS, SourceLocation RParenLoc, UnsignedOrNone NumExpansions)
Build a new C++1z fold-expression.
OMPClause * TransformOMPClause(OMPClause *S)
Transform the given statement.
QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc)
Build a new atomic type given its value type.
ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, SourceLocation RParenLoc, Expr *SubExpr)
Build a new C-style cast expression.
QualType RebuildObjCObjectPointerType(QualType PointeeType, SourceLocation Star)
Build a new Objective-C object pointer type given the pointee type.
OMPClause * RebuildOMPLoopRangeClause(Expr *First, Expr *Count, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation FirstLoc, SourceLocation CountLoc, SourceLocation EndLoc)
bool PreparePackForExpansion(TemplateArgumentLoc In, bool Uneval, TemplateArgumentLoc &Out, UnexpandedInfo &Info)
Checks if the argument pack from In will need to be expanded and does the necessary prework.
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.
QualType RebuildUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, UsingShadowDecl *D, QualType UnderlyingType)
Build a new type found via an alias.
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.
StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK=StmtDiscardKind::Discarded)
Transform the given statement.
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
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 RebuildExtVectorOrMatrixElementExpr(Expr *Base, SourceLocation OpLoc, bool IsArrow, SourceLocation AccessorLoc, IdentifierInfo &Accessor)
Build a new extended vector or matrix element access expression.
ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, SourceLocation LParenLoc, MultiExprArg Args, SourceLocation RParenLoc, bool ListInitialization)
Build a new object-construction expression.
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.
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.
VarDecl * RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, TypeSourceInfo *TInfo, QualType T)
Rebuild an Objective-C exception declaration.
TemplateName RebuildTemplateName(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, IdentifierOrOverloadedOperator IO, SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName)
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.
MultiLevelTemplateArgumentList ForgetSubstitution()
"Forget" the template substitution to allow transforming the AST without any template instantiations.
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)
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 RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length, ArrayRef< TemplateArgument > PartialArgs)
Build a new expression to compute the length of a parameter pack.
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)
void transformAttrs(Decl *Old, Decl *New)
Transform the attributes associated with the given declaration and place them on the new declaration.
QualType TransformTagType(TypeLocBuilder &TLB, TagTypeLoc TL)
QualType RebuildTemplateSpecializationType(ElaboratedTypeKeyword Keyword, TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &Args)
Build a new template specialization type.
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'.
ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, TypeSourceInfo *Type, const Designation &Desig, SourceLocation RParenLoc)
Build a new builtin offsetof expression.
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 RebuildBitIntType(bool IsUnsigned, unsigned NumBits, SourceLocation Loc)
Build a bit-precise int given its value type.
QualType RebuildDeducedTemplateSpecializationType(DeducedKind DK, QualType DeducedAsType, ElaboratedTypeKeyword Keyword, TemplateName Template)
By default, builds a new DeducedTemplateSpecializationType with the given deduced 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.
OMPClause * RebuildOMPNumTeamsClause(ArrayRef< Expr * > VarList, OpenMPNumTeamsClauseModifier Modifier, Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' clause.
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 RebuildPackExpansionType(QualType Pattern, SourceRange PatternRange, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new pack expansion 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.
OMPClause * RebuildOMPToClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'to' clause.
ExprResult RebuildCXXParenListInitExpr(ArrayRef< Expr * > Args, QualType T, unsigned NumUserSpecifiedExprs, SourceLocation InitLoc, SourceLocation LParenLoc, SourceLocation RParenLoc)
TypeSourceInfo * TransformTypeWithDeducedTST(TypeSourceInfo *TSI)
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.
void RememberSubstitution(MultiLevelTemplateArgumentList)
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.
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 RebuildTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, TypedefNameDecl *Typedef)
Build a new typedef type.
QualType TransformFunctionProtoType(TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, Qualifiers ThisTypeQuals, Fn TransformExceptionSpec)
OMPClause * RebuildOMPUseDevicePtrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, OpenMPUseDevicePtrFallbackModifier FallbackModifier, SourceLocation FallbackModifierLoc)
Build a new OpenMP 'use_device_ptr' clause.
TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, SourceLocation EllipsisLoc, UnsignedOrNone NumExpansions)
Build a new template argument pack expansion.
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)
TypeSourceInfo * TransformType(TypeSourceInfo *TSI)
Transforms the given type-with-location into a new type-with-location.
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.
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.
StmtResult RebuildOpenACCAtomicConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, OpenACCAtomicKind AtKind, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult AssociatedStmt)
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.
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.
ExprResult RebuildArraySubscriptExpr(Expr *LHS, SourceLocation LBracketLoc, Expr *RHS, SourceLocation RBracketLoc)
Build a new array subscript expression.
OMPClause * RebuildOMPReductionClause(ArrayRef< Expr * > VarList, OpenMPReductionClauseModifier Modifier, OpenMPOriginalSharingModifier OriginalSharingModifier, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ModifierLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions)
Build a new OpenMP 'reduction' clause.
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)
TemplateName TransformTemplateName(NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc, TemplateName Name, SourceLocation NameLoc, QualType ObjectType=QualType(), NamedDecl *FirstQualifierInScope=nullptr, bool AllowInjectedClassName=false)
Transform the given template name.
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.
ExprResult RebuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, unsigned Index, QualType ParamType, SourceLocation Loc, TemplateArgument Arg, UnsignedOrNone PackIndex, bool Final)
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.
OMPClause * RebuildOMPFromClause(ArrayRef< OpenMPMotionModifierKind > MotionModifiers, ArrayRef< SourceLocation > MotionModifiersLoc, Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperId, SourceLocation ColonLoc, ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs, ArrayRef< Expr * > UnresolvedMappers)
Build a new OpenMP 'from' clause.
bool TransformConceptTemplateArguments(InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, bool Uneval=false)
TypeLoc getTypeLocInContext(ASTContext &Context, QualType T)
Copies the type-location information to the given AST context and returns a TypeLoc referring into th...
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:349
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:154
unsigned getFullDataSize() const
Returns the size of the type source info data block.
Definition TypeLoc.h:165
TypeLocClass getTypeLocClass() const
Definition TypeLoc.h:116
T getAsAdjusted() const
Convert to the specified TypeLoc type, returning a null TypeLoc if this TypeLoc is not of the desired...
Definition TypeLoc.h:2735
SourceLocation getBeginLoc() const
Get the begin source location.
Definition TypeLoc.cpp:193
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition TypeBase.h:6282
A container of type source information.
Definition TypeBase.h:8418
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition TypeLoc.h:267
QualType getType() const
Return the type wrapped by this type source info.
Definition TypeBase.h:8429
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:551
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition ExprCXX.h:2900
The base class of the type hierarchy.
Definition TypeBase.h:1875
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition TypeBase.h:2465
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition TypeBase.h:9200
bool isObjCObjectPointerType() const
Definition TypeBase.h:8863
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9277
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3606
Wrapper for source info for typedefs.
Definition TypeLoc.h:777
void setTypeofLoc(SourceLocation Loc)
Definition TypeLoc.h:2200
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2631
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2250
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2295
Expr * getSubExpr() const
Definition Expr.h:2291
Opcode getOpcode() const
Definition Expr.h:2286
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:1421
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2344
Represents a C++ unqualified-id that has been parsed.
Definition DeclSpec.h:1088
void setOperatorFunctionId(SourceLocation OperatorLoc, OverloadedOperatorKind Op, SourceLocation SymbolLocations[3])
Specify that this unqualified-id was parsed as an operator-function-id.
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition ExprCXX.h:3390
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3464
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3459
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:437
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4126
A set of unresolved declarations.
void append(iterator I, iterator E)
A set of unresolved declarations.
Wrapper for source info for unresolved typename using decls.
Definition TypeLoc.h:782
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition TypeBase.h:6087
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
Definition ExprCXX.h:644
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3420
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3484
Wrapper for source info for types used via transparent aliases.
Definition TypeLoc.h:785
Represents a call to the builtin function __builtin_va_arg.
Definition Expr.h:4963
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
QualType getType() const
Definition Decl.h:723
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition Decl.cpp:5591
Value()=default
Represents a variable declaration or definition.
Definition Decl.h:932
@ CInit
C-style initialization with assignment.
Definition Decl.h:937
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:940
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1174
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4030
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2045
Represents a GCC generic vector type.
Definition TypeBase.h:4239
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2707
A requires-expression requirement which queries the validity and properties of an expression ('simple...
SubstitutionDiagnostic * getExprSubstitutionDiagnostic() const
const ReturnTypeRequirement & getReturnTypeRequirement() const
SourceLocation getNoexceptLoc() const
A requires-expression requirement which is satisfied when a general constraint expression is satisfie...
const ASTConstraintSatisfaction & getConstraintSatisfaction() const
A static requirement that can be used in a requires-expression to check properties of types and expre...
A requires-expression requirement which queries the existence of a type name or type template special...
SubstitutionDiagnostic * getSubstitutionDiagnostic() const
TypeSourceInfo * getType() const
Retains information about a block that is currently being parsed.
Definition ScopeInfo.h:791
bool ContainsUnexpandedParameterPack
Whether this contains an unexpanded parameter pack.
Definition ScopeInfo.h:729
CXXRecordDecl * Lambda
The class that describes the lambda.
Definition ScopeInfo.h:872
CXXMethodDecl * CallOperator
The lambda's compiler-generated operator().
Definition ScopeInfo.h:875
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
VE builtins.
const AstTypeMatcher< FunctionType > functionType
llvm::PointerUnion< const Decl *, const Expr * > DeclTy
Definition Descriptor.h:29
bool Inc(InterpState &S, CodePtr OpPC, bool CanOverflow)
1) Pops a pointer from the stack 2) Load the value from the pointer 3) Writes the value increased by ...
Definition Interp.h:975
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
OpenMPOriginalSharingModifier
OpenMP 6.0 original sharing modifiers.
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
@ OO_None
Not an overloaded operator.
@ NUM_OVERLOADED_OPERATORS
OpenACCDirectiveKind
bool isa(CodeGen::Address addr)
Definition Address.h:330
ArrayTypeTrait
Names for the array type traits.
Definition TypeTraits.h:42
@ CPlusPlus23
OpenACCAtomicKind
OpenMPDefaultClauseVariableCategory
OpenMP variable-category for 'default' clause.
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition TypeBase.h:1834
OpenMPDefaultmapClauseModifier
OpenMP modifiers for 'defaultmap' clause.
OpenMPOrderClauseModifier
OpenMP modifiers for 'order' clause.
TryCaptureKind
Definition Sema.h:653
@ Ambiguous
Name lookup results in an ambiguity; use getAmbiguityKind to figure out what kind of ambiguity we hav...
Definition Lookup.h:64
@ NotFound
No entity found met the criteria.
Definition Lookup.h:41
@ FoundOverloaded
Name lookup found a set of overloaded functions that met the criteria.
Definition Lookup.h:54
@ Found
Name lookup found a single declaration that met the criteria.
Definition Lookup.h:50
@ FoundUnresolvedValue
Name lookup found an unresolvable value declaration and cannot yet complete.
Definition Lookup.h:59
@ NotFoundInCurrentInstantiation
No entity found met the criteria within the current instantiation,, but there were dependent base cla...
Definition Lookup.h:46
IfStatementKind
In an if statement, this denotes whether the statement is a constexpr or consteval if statement.
Definition Specifiers.h:40
@ TemplateName
The identifier is a template name. FIXME: Add an annotation for that.
Definition Parser.h:61
CXXConstructionKind
Definition ExprCXX.h:1544
@ 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:162
OpenMPAtClauseKind
OpenMP attributes for 'at' clause.
@ 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
NonTagKind
Common ways to introduce type names without a tag for use in diagnostics.
Definition Sema.h:604
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
Definition Sema.h:238
@ DevicePtr
'deviceptr' clause, allowed on Compute and Combined Constructs, plus 'data' and 'declare'.
@ Invalid
Represents an invalid clause, for the purposes of parsing.
@ Attach
'attach' clause, allowed on Compute and Combined constructs, plus 'data' and 'enter data'.
@ Self
'self' clause, allowed on Compute and Combined Constructs, plus 'update'.
@ Detach
'detach' clause, allowed on the 'exit data' construct.
TypeOfKind
The kind of 'typeof' expression we're after.
Definition TypeBase.h:918
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition OpenMPKinds.h:39
OpenMPNumTeamsClauseModifier
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
Expr * Cond
};
OpenMPDoacrossClauseModifier
OpenMP dependence types for 'doacross' clause.
@ Dependent
Parse the block as a dependent block, which may be used in some template instantiations but not other...
Definition Parser.h:142
UnaryExprOrTypeTrait
Names for the "expression or type" traits.
Definition TypeTraits.h:51
std::pair< NullabilityKind, bool > DiagNullabilityKind
A nullability kind paired with a bit indicating whether it used a context-sensitive keyword.
ExprResult ExprEmpty()
Definition Ownership.h:272
OpenMPDynGroupprivateClauseFallbackModifier
MutableArrayRef< Expr * > MultiExprArg
Definition Ownership.h:259
StmtResult StmtError()
Definition Ownership.h:266
@ Property
The type of a property.
Definition TypeBase.h:911
@ Result
The result type of a method or function.
Definition TypeBase.h:905
OpenMPBindClauseKind
OpenMP bindings for the 'bind' clause.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition TypeBase.h:3783
OptionalUnsigned< unsigned > UnsignedOrNone
bool isComputedNoexcept(ExceptionSpecificationType ESpecType)
OpenMPLastprivateModifier
OpenMP 'lastprivate' clause modifier.
@ Template
We are parsing a template declaration.
Definition Parser.h:81
ActionResult< CXXBaseSpecifier * > BaseResult
Definition Ownership.h:252
OpenMPGrainsizeClauseModifier
OpenMPNumTasksClauseModifier
TagTypeKind
The kind of a tag type.
Definition TypeBase.h:5995
bool transformOMPMappableExprListClause(TreeTransform< Derived > &TT, OMPMappableExprListClause< T > *C, llvm::SmallVectorImpl< Expr * > &Vars, CXXScopeSpec &MapperIdScopeSpec, DeclarationNameInfo &MapperIdInfo, llvm::SmallVectorImpl< Expr * > &UnresolvedMappers)
OpenMPUseDevicePtrFallbackModifier
OpenMP 6.1 use_device_ptr fallback modifier.
ExprResult ExprError()
Definition Ownership.h:265
@ Keyword
The name has been typo-corrected to a keyword.
Definition Sema.h:562
bool isOpenMPLoopDirective(OpenMPDirectiveKind DKind)
Checks if the specified directive is a directive with an associated loop construct.
OpenMPSeverityClauseKind
OpenMP attributes for 'severity' clause.
DeducedKind
Definition TypeBase.h:1807
@ Deduced
The normal deduced case.
Definition TypeBase.h:1814
@ Undeduced
Not deduced yet. This is for example an 'auto' which was just parsed.
Definition TypeBase.h:1809
std::tuple< NamedDecl *, TemplateArgument > getReplacedTemplateParameter(Decl *D, unsigned Index)
Internal helper used by Subst* nodes to retrieve a parameter from the AssociatedDecl,...
OpenMPDefaultmapClauseKind
OpenMP attributes for 'defaultmap' clause.
OpenMPAllocateClauseModifier
OpenMP modifiers for 'allocate' clause.
OpenMPLinearClauseKind
OpenMP attributes for 'linear' clause.
Definition OpenMPKinds.h:63
llvm::omp::Directive OpenMPDirectiveKind
OpenMP directives.
Definition OpenMPKinds.h:25
OpenMPDynGroupprivateClauseModifier
@ VK_PRValue
A pr-value expression (in the C++11 taxonomy) produces a temporary value.
Definition Specifiers.h:136
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:140
@ Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition Sema.h:812
@ Exists
The symbol exists.
Definition Sema.h:805
@ Error
An error occurred.
Definition Sema.h:815
@ DoesNotExist
The symbol does not exist.
Definition Sema.h:808
MutableArrayRef< Stmt * > MultiStmtArg
Definition Ownership.h:260
OpenMPNumThreadsClauseModifier
U cast(CodeGen::Address addr)
Definition Address.h:327
@ PackIndex
Index of a pack indexing expression or specifier.
Definition Sema.h:851
OpenMPDeviceClauseModifier
OpenMP modifiers for 'device' clause.
Definition OpenMPKinds.h:48
OpaquePtr< QualType > ParsedType
An opaque type for threading parsed type information through the parser.
Definition Ownership.h:230
SourceLocIdentKind
Definition Expr.h:5019
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:5970
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:5991
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:5981
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:5988
ActionResult< Expr * > ExprResult
Definition Ownership.h:249
OpenMPOrderClauseKind
OpenMP attributes for 'order' clause.
TypeTrait
Names for traits that operate specifically on types.
Definition TypeTraits.h:21
@ Parens
New-expression has a C++98 paren-delimited initializer.
Definition ExprCXX.h:2249
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
@ EST_Uninstantiated
not instantiated yet
@ EST_Unevaluated
not evaluated yet, for special member function
@ EST_Dynamic
throw(T1, T2)
PredefinedIdentKind
Definition Expr.h:1995
OpenMPScheduleClauseKind
OpenMP attributes for 'schedule' clause.
Definition OpenMPKinds.h:31
static QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T)
ActionResult< Stmt * > StmtResult
Definition Ownership.h:250
OpenMPMapClauseKind
OpenMP mapping kind for 'map' clause.
Definition OpenMPKinds.h:71
Expr * AllocatorTraits
Allocator traits.
SourceLocation LParenLoc
Locations of '(' and ')' symbols.
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:91
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
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
A FunctionEffect plus a potential boolean expression determining whether the effect is declared (e....
Definition TypeBase.h:5108
Holds information about the various types of exception specification.
Definition TypeBase.h:5428
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5444
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5430
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5433
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5436
Extra information about a function prototype.
Definition TypeBase.h:5456
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5461
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition Type.cpp:3406
const NamespaceBaseDecl * Namespace
Iterator range representation begin:end[:step].
Definition ExprOpenMP.h:154
This structure contains most locations needed for by an OMPVarListClause.
An element in an Objective-C dictionary literal.
Definition ExprObjC.h:295
Data for list of allocators.
A context in which code is being synthesized (where a source location alone is not sufficient to iden...
Definition Sema.h:13242
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition Sema.h:13273
bool InLifetimeExtendingContext
Whether we are currently in a context in which all temporaries must be lifetime-extended,...
Definition Sema.h:6945
SmallVector< MaterializeTemporaryExpr *, 8 > ForRangeLifetimeExtendTemps
P2718R0 - Lifetime extension in range-based for loops.
Definition Sema.h:6913
bool RebuildDefaultArgOrDefaultInit
Whether we should rebuild CXXDefaultArgExpr and CXXDefaultInitExpr.
Definition Sema.h:6951
ExpressionEvaluationContext Context
The expression evaluation context.
Definition Sema.h:6861
An RAII helper that pops function a function scope on exit.
Definition Sema.h:1332
Keeps information about an identifier in a nested-name-spec.
Definition Sema.h:3332
Location information for a TemplateArgument.
UnsignedOrNone OrigNumExpansions
SourceLocation Ellipsis
UnsignedOrNone NumExpansions