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
643 SourceLocation NameLoc);
644
645 /// Transform the given template argument.
646 ///
647 /// By default, this operation transforms the type, expression, or
648 /// declaration stored within the template argument and constructs a
649 /// new template argument from the transformed result. Subclasses may
650 /// override this function to provide alternate behavior.
651 ///
652 /// Returns true if there was an error.
654 TemplateArgumentLoc &Output,
655 bool Uneval = false);
656
658 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
659 TemplateName Name, SourceLocation NameLoc);
660
661 /// Transform the given set of template arguments.
662 ///
663 /// By default, this operation transforms all of the template arguments
664 /// in the input set using \c TransformTemplateArgument(), and appends
665 /// the transformed arguments to the output list.
666 ///
667 /// Note that this overload of \c TransformTemplateArguments() is merely
668 /// a convenience function. Subclasses that wish to override this behavior
669 /// should override the iterator-based member template version.
670 ///
671 /// \param Inputs The set of template arguments to be transformed.
672 ///
673 /// \param NumInputs The number of template arguments in \p Inputs.
674 ///
675 /// \param Outputs The set of transformed template arguments output by this
676 /// routine.
677 ///
678 /// Returns true if an error occurred.
680 unsigned NumInputs,
682 bool Uneval = false) {
683 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
684 Uneval);
685 }
686
687 /// Transform the given set of template arguments.
688 ///
689 /// By default, this operation transforms all of the template arguments
690 /// in the input set using \c TransformTemplateArgument(), and appends
691 /// the transformed arguments to the output list.
692 ///
693 /// \param First An iterator to the first template argument.
694 ///
695 /// \param Last An iterator one step past the last template argument.
696 ///
697 /// \param Outputs The set of transformed template arguments output by this
698 /// routine.
699 ///
700 /// Returns true if an error occurred.
701 template<typename InputIterator>
703 InputIterator Last,
705 bool Uneval = false);
706
707 template <typename InputIterator>
709 InputIterator Last,
711 bool Uneval = false);
712
713 /// Checks if the argument pack from \p In will need to be expanded and does
714 /// the necessary prework.
715 /// Whether the expansion is needed is captured in Info.Expand.
716 ///
717 /// - When the expansion is required, \p Out will be a template pattern that
718 /// would need to be expanded.
719 /// - When the expansion must not happen, \p Out will be a pack that must be
720 /// returned to the outputs directly.
721 ///
722 /// \return true iff the error occurred
725
726 /// Fakes up a TemplateArgumentLoc for a given TemplateArgument.
728 TemplateArgumentLoc &ArgLoc);
729
730 /// Fakes up a TypeSourceInfo for a type.
732 return SemaRef.Context.getTrivialTypeSourceInfo(T,
734 }
735
736#define ABSTRACT_TYPELOC(CLASS, PARENT)
737#define TYPELOC(CLASS, PARENT) \
738 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
739#include "clang/AST/TypeLocNodes.def"
740
743 bool SuppressObjCLifetime);
747 bool SuppressObjCLifetime);
748
749 template<typename Fn>
752 CXXRecordDecl *ThisContext,
753 Qualifiers ThisTypeQuals,
755
758 SmallVectorImpl<QualType> &Exceptions,
759 bool &Changed);
760
762
765 QualType ObjectType,
766 NamedDecl *FirstQualifierInScope,
767 bool AllowInjectedClassName);
768
770
771 /// Transforms the parameters of a function type into the
772 /// given vectors.
773 ///
774 /// The result vectors should be kept in sync; null entries in the
775 /// variables vector are acceptable.
776 ///
777 /// LastParamTransformed, if non-null, will be set to the index of the last
778 /// parameter on which transformation was started. In the event of an error,
779 /// this will contain the parameter which failed to instantiate.
780 ///
781 /// Return true on error.
784 const QualType *ParamTypes,
785 const FunctionProtoType::ExtParameterInfo *ParamInfos,
787 Sema::ExtParameterInfoBuilder &PInfos, unsigned *LastParamTransformed);
788
791 const QualType *ParamTypes,
792 const FunctionProtoType::ExtParameterInfo *ParamInfos,
795 return getDerived().TransformFunctionTypeParams(
796 Loc, Params, ParamTypes, ParamInfos, PTypes, PVars, PInfos, nullptr);
797 }
798
799 /// Transforms the parameters of a requires expresison into the given vectors.
800 ///
801 /// The result vectors should be kept in sync; null entries in the
802 /// variables vector are acceptable.
803 ///
804 /// Returns an unset ExprResult on success. Returns an ExprResult the 'not
805 /// satisfied' RequiresExpr if subsitution failed, OR an ExprError, both of
806 /// which are cases where transformation shouldn't continue.
808 SourceLocation KWLoc, SourceLocation RBraceLoc, const RequiresExpr *RE,
814 KWLoc, Params, /*ParamTypes=*/nullptr,
815 /*ParamInfos=*/nullptr, PTypes, &TransParams, PInfos))
816 return ExprError();
817
818 return ExprResult{};
819 }
820
821 /// Transforms a single function-type parameter. Return null
822 /// on error.
823 ///
824 /// \param indexAdjustment - A number to add to the parameter's
825 /// scope index; can be negative
827 int indexAdjustment,
828 UnsignedOrNone NumExpansions,
829 bool ExpectParameterPack);
830
831 /// Transform the body of a lambda-expression.
833 /// Alternative implementation of TransformLambdaBody that skips transforming
834 /// the body.
836
842
844
846
849
854
856
858 bool IsAddressOfOperand,
859 TypeSourceInfo **RecoveryTSI);
860
862 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
863 TypeSourceInfo **RecoveryTSI);
864
866 bool IsAddressOfOperand);
867
869
871
872// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
873// amount of stack usage with clang.
874#define STMT(Node, Parent) \
875 LLVM_ATTRIBUTE_NOINLINE \
876 StmtResult Transform##Node(Node *S);
877#define VALUESTMT(Node, Parent) \
878 LLVM_ATTRIBUTE_NOINLINE \
879 StmtResult Transform##Node(Node *S, StmtDiscardKind SDK);
880#define EXPR(Node, Parent) \
881 LLVM_ATTRIBUTE_NOINLINE \
882 ExprResult Transform##Node(Node *E);
883#define ABSTRACT_STMT(Stmt)
884#include "clang/AST/StmtNodes.inc"
885
886#define GEN_CLANG_CLAUSE_CLASS
887#define CLAUSE_CLASS(Enum, Str, Class) \
888 LLVM_ATTRIBUTE_NOINLINE \
889 OMPClause *Transform##Class(Class *S);
890#include "llvm/Frontend/OpenMP/OMP.inc"
891
892 /// Build a new qualified type given its unqualified type and type location.
893 ///
894 /// By default, this routine adds type qualifiers only to types that can
895 /// have qualifiers, and silently suppresses those qualifiers that are not
896 /// permitted. Subclasses may override this routine to provide different
897 /// behavior.
899
900 /// Build a new pointer type given its pointee type.
901 ///
902 /// By default, performs semantic analysis when building the pointer type.
903 /// Subclasses may override this routine to provide different behavior.
905
906 /// Build a new block pointer type given its pointee type.
907 ///
908 /// By default, performs semantic analysis when building the block pointer
909 /// type. Subclasses may override this routine to provide different behavior.
911
912 /// Build a new reference type given the type it references.
913 ///
914 /// By default, performs semantic analysis when building the
915 /// reference type. Subclasses may override this routine to provide
916 /// different behavior.
917 ///
918 /// \param LValue whether the type was written with an lvalue sigil
919 /// or an rvalue sigil.
921 bool LValue,
922 SourceLocation Sigil);
923
924 /// Build a new member pointer type given the pointee type and the
925 /// qualifier it refers into.
926 ///
927 /// By default, performs semantic analysis when building the member pointer
928 /// type. Subclasses may override this routine to provide different behavior.
930 const CXXScopeSpec &SS, CXXRecordDecl *Cls,
931 SourceLocation Sigil);
932
934 SourceLocation ProtocolLAngleLoc,
936 ArrayRef<SourceLocation> ProtocolLocs,
937 SourceLocation ProtocolRAngleLoc);
938
939 /// Build an Objective-C object type.
940 ///
941 /// By default, performs semantic analysis when building the object type.
942 /// Subclasses may override this routine to provide different behavior.
944 SourceLocation Loc,
945 SourceLocation TypeArgsLAngleLoc,
947 SourceLocation TypeArgsRAngleLoc,
948 SourceLocation ProtocolLAngleLoc,
950 ArrayRef<SourceLocation> ProtocolLocs,
951 SourceLocation ProtocolRAngleLoc);
952
953 /// Build a new Objective-C object pointer type given the pointee type.
954 ///
955 /// By default, directly builds the pointer type, with no additional semantic
956 /// analysis.
959
960 /// Build a new array type given the element type, size
961 /// modifier, size of the array (if known), size expression, and index type
962 /// qualifiers.
963 ///
964 /// By default, performs semantic analysis when building the array type.
965 /// Subclasses may override this routine to provide different behavior.
966 /// Also by default, all of the other Rebuild*Array
968 const llvm::APInt *Size, Expr *SizeExpr,
969 unsigned IndexTypeQuals, SourceRange BracketsRange);
970
971 /// Build a new constant array type given the element type, size
972 /// modifier, (known) size of the array, and index type qualifiers.
973 ///
974 /// By default, performs semantic analysis when building the array type.
975 /// Subclasses may override this routine to provide different behavior.
977 ArraySizeModifier SizeMod,
978 const llvm::APInt &Size, Expr *SizeExpr,
979 unsigned IndexTypeQuals,
980 SourceRange BracketsRange);
981
982 /// Build a new incomplete array type given the element type, size
983 /// modifier, and index type qualifiers.
984 ///
985 /// By default, performs semantic analysis when building the array type.
986 /// Subclasses may override this routine to provide different behavior.
988 ArraySizeModifier SizeMod,
989 unsigned IndexTypeQuals,
990 SourceRange BracketsRange);
991
992 /// Build a new variable-length array type given the element type,
993 /// size modifier, size expression, and index type qualifiers.
994 ///
995 /// By default, performs semantic analysis when building the array type.
996 /// Subclasses may override this routine to provide different behavior.
998 ArraySizeModifier SizeMod, Expr *SizeExpr,
999 unsigned IndexTypeQuals,
1000 SourceRange BracketsRange);
1001
1002 /// Build a new dependent-sized array type given the element type,
1003 /// size modifier, size expression, and index type qualifiers.
1004 ///
1005 /// By default, performs semantic analysis when building the array type.
1006 /// Subclasses may override this routine to provide different behavior.
1008 ArraySizeModifier SizeMod,
1009 Expr *SizeExpr,
1010 unsigned IndexTypeQuals,
1011 SourceRange BracketsRange);
1012
1013 /// Build a new vector type given the element type and
1014 /// number of elements.
1015 ///
1016 /// By default, performs semantic analysis when building the vector type.
1017 /// Subclasses may override this routine to provide different behavior.
1018 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
1019 VectorKind VecKind);
1020
1021 /// Build a new potentially dependently-sized extended vector type
1022 /// given the element type and number of elements.
1023 ///
1024 /// By default, performs semantic analysis when building the vector type.
1025 /// Subclasses may override this routine to provide different behavior.
1027 SourceLocation AttributeLoc, VectorKind);
1028
1029 /// Build a new extended vector type given the element type and
1030 /// number of elements.
1031 ///
1032 /// By default, performs semantic analysis when building the vector type.
1033 /// Subclasses may override this routine to provide different behavior.
1034 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
1035 SourceLocation AttributeLoc);
1036
1037 /// Build a new potentially dependently-sized extended vector type
1038 /// given the element type and number of elements.
1039 ///
1040 /// By default, performs semantic analysis when building the vector type.
1041 /// Subclasses may override this routine to provide different behavior.
1043 Expr *SizeExpr,
1044 SourceLocation AttributeLoc);
1045
1046 /// Build a new matrix type given the element type and dimensions.
1047 QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows,
1048 unsigned NumColumns,
1049 SourceLocation AttributeLoc);
1050
1051 /// Build a new matrix type given the type and dependently-defined
1052 /// dimensions.
1054 Expr *ColumnExpr,
1055 SourceLocation AttributeLoc);
1056
1057 /// Build a new DependentAddressSpaceType or return the pointee
1058 /// type variable with the correct address space (retrieved from
1059 /// AddrSpaceExpr) applied to it. The former will be returned in cases
1060 /// where the address space remains dependent.
1061 ///
1062 /// By default, performs semantic analysis when building the type with address
1063 /// space applied. Subclasses may override this routine to provide different
1064 /// behavior.
1066 Expr *AddrSpaceExpr,
1067 SourceLocation AttributeLoc);
1068
1069 /// Build a new function type.
1070 ///
1071 /// By default, performs semantic analysis when building the function type.
1072 /// Subclasses may override this routine to provide different behavior.
1074 MutableArrayRef<QualType> ParamTypes,
1076
1077 /// Build a new unprototyped function type.
1079
1080 /// Rebuild an unresolved typename type, given the decl that
1081 /// the UnresolvedUsingTypenameDecl was transformed to.
1083 NestedNameSpecifier Qualifier,
1084 SourceLocation NameLoc, Decl *D);
1085
1086 /// Build a new type found via an alias.
1089 QualType UnderlyingType) {
1090 return SemaRef.Context.getUsingType(Keyword, Qualifier, D, UnderlyingType);
1091 }
1092
1093 /// Build a new typedef type.
1095 NestedNameSpecifier Qualifier,
1097 return SemaRef.Context.getTypedefType(Keyword, Qualifier, Typedef);
1098 }
1099
1100 /// Build a new MacroDefined type.
1102 const IdentifierInfo *MacroII) {
1103 return SemaRef.Context.getMacroQualifiedType(T, MacroII);
1104 }
1105
1106 /// Build a new class/struct/union/enum type.
1108 NestedNameSpecifier Qualifier, TagDecl *Tag) {
1109 return SemaRef.Context.getTagType(Keyword, Qualifier, Tag,
1110 /*OwnsTag=*/false);
1111 }
1113 return SemaRef.Context.getCanonicalTagType(Tag);
1114 }
1115
1116 /// Build a new typeof(expr) type.
1117 ///
1118 /// By default, performs semantic analysis when building the typeof type.
1119 /// Subclasses may override this routine to provide different behavior.
1121 TypeOfKind Kind);
1122
1123 /// Build a new typeof(type) type.
1124 ///
1125 /// By default, builds a new TypeOfType with the given underlying type.
1127
1128 /// Build a new unary transform type.
1130 UnaryTransformType::UTTKind UKind,
1131 SourceLocation Loc);
1132
1133 /// Build a new C++11 decltype type.
1134 ///
1135 /// By default, performs semantic analysis when building the decltype type.
1136 /// Subclasses may override this routine to provide different behavior.
1138
1140 SourceLocation Loc, bool FullySubstituted,
1141 ArrayRef<QualType> Expansions = {});
1142
1143 /// Build a new C++11 auto type.
1144 ///
1145 /// By default, builds a new AutoType with the given deduced type.
1148 TemplateName TypeConstraintConcept,
1149 ArrayRef<TemplateArgument> TypeConstraintArgs) {
1150 return SemaRef.Context.getAutoType(
1151 DK, DeducedAsType, Keyword, TypeConstraintConcept, TypeConstraintArgs);
1152 }
1153
1154 /// By default, builds a new DeducedTemplateSpecializationType with the given
1155 /// deduced type.
1159 return SemaRef.Context.getDeducedTemplateSpecializationType(
1160 DK, DeducedAsType, Keyword, Template);
1161 }
1162
1163 /// Build a new template specialization type.
1164 ///
1165 /// By default, performs semantic analysis when building the template
1166 /// specialization type. Subclasses may override this routine to provide
1167 /// different behavior.
1170 SourceLocation TemplateLoc,
1172
1173 /// Build a new parenthesized type.
1174 ///
1175 /// By default, builds a new ParenType type from the inner type.
1176 /// Subclasses may override this routine to provide different behavior.
1178 return SemaRef.BuildParenType(InnerType);
1179 }
1180
1181 /// Build a new typename type that refers to an identifier.
1182 ///
1183 /// By default, performs semantic analysis when building the typename type
1184 /// (or elaborated type). Subclasses may override this routine to provide
1185 /// different behavior.
1187 SourceLocation KeywordLoc,
1188 NestedNameSpecifierLoc QualifierLoc,
1189 const IdentifierInfo *Id,
1190 SourceLocation IdLoc,
1191 bool DeducedTSTContext) {
1192 CXXScopeSpec SS;
1193 SS.Adopt(QualifierLoc);
1194
1195 if (QualifierLoc.getNestedNameSpecifier().isDependent()) {
1196 // If the name is still dependent, just build a new dependent name type.
1197 if (!SemaRef.computeDeclContext(SS))
1198 return SemaRef.Context.getDependentNameType(Keyword,
1199 QualifierLoc.getNestedNameSpecifier(),
1200 Id);
1201 }
1202
1205 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
1206 *Id, IdLoc, DeducedTSTContext);
1207 }
1208
1210
1211 // We had a dependent elaborated-type-specifier that has been transformed
1212 // into a non-dependent elaborated-type-specifier. Find the tag we're
1213 // referring to.
1215 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
1216 if (!DC)
1217 return QualType();
1218
1219 if (SemaRef.RequireCompleteDeclContext(SS, DC))
1220 return QualType();
1221
1222 TagDecl *Tag = nullptr;
1223 SemaRef.LookupQualifiedName(Result, DC);
1224 switch (Result.getResultKind()) {
1227 break;
1228
1230 Tag = Result.getAsSingle<TagDecl>();
1231 break;
1232
1235 llvm_unreachable("Tag lookup cannot find non-tags");
1236
1238 // Let the LookupResult structure handle ambiguities.
1239 return QualType();
1240 }
1241
1242 if (!Tag) {
1243 // Check where the name exists but isn't a tag type and use that to emit
1244 // better diagnostics.
1246 SemaRef.LookupQualifiedName(Result, DC);
1247 switch (Result.getResultKind()) {
1251 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
1252 NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind);
1253 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag)
1254 << SomeDecl << NTK << Kind;
1255 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1256 break;
1257 }
1258 default:
1259 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
1260 << Kind << Id << DC << QualifierLoc.getSourceRange();
1261 break;
1262 }
1263 return QualType();
1264 }
1265 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
1266 IdLoc, Id)) {
1267 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
1268 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1269 return QualType();
1270 }
1271 return getDerived().RebuildTagType(
1272 Keyword, QualifierLoc.getNestedNameSpecifier(), Tag);
1273 }
1274
1275 /// Build a new pack expansion type.
1276 ///
1277 /// By default, builds a new PackExpansionType type from the given pattern.
1278 /// Subclasses may override this routine to provide different behavior.
1280 SourceLocation EllipsisLoc,
1281 UnsignedOrNone NumExpansions) {
1282 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1283 NumExpansions);
1284 }
1285
1286 /// Build a new atomic type given its value type.
1287 ///
1288 /// By default, performs semantic analysis when building the atomic type.
1289 /// Subclasses may override this routine to provide different behavior.
1291
1292 /// Build a new pipe type given its value type.
1294 bool isReadPipe);
1295
1296 /// Build a bit-precise int given its value type.
1297 QualType RebuildBitIntType(bool IsUnsigned, unsigned NumBits,
1298 SourceLocation Loc);
1299
1300 /// Build a dependent bit-precise int given its value type.
1301 QualType RebuildDependentBitIntType(bool IsUnsigned, Expr *NumBitsExpr,
1302 SourceLocation Loc);
1303
1304 /// Build a new template name given a nested name specifier, a flag
1305 /// indicating whether the "template" keyword was provided, and the template
1306 /// that the template name refers to.
1307 ///
1308 /// By default, builds the new template name directly. Subclasses may override
1309 /// this routine to provide different behavior.
1311 TemplateName Name);
1312
1313 /// Build a new template name given a nested name specifier and the
1314 /// name that is referred to as a template.
1315 ///
1316 /// By default, performs semantic analysis to determine whether the name can
1317 /// be resolved to a specific template, then builds the appropriate kind of
1318 /// template name. Subclasses may override this routine to provide different
1319 /// behavior.
1321 SourceLocation TemplateKWLoc,
1322 const IdentifierInfo &Name,
1323 SourceLocation NameLoc, QualType ObjectType,
1324 bool AllowInjectedClassName);
1325
1326 /// Build a new template name given a nested name specifier and the
1327 /// overloaded operator name that is referred to as a template.
1328 ///
1329 /// By default, performs semantic analysis to determine whether the name can
1330 /// be resolved to a specific template, then builds the appropriate kind of
1331 /// template name. Subclasses may override this routine to provide different
1332 /// behavior.
1334 SourceLocation TemplateKWLoc,
1335 OverloadedOperatorKind Operator,
1336 SourceLocation NameLoc, QualType ObjectType,
1337 bool AllowInjectedClassName);
1338
1340 SourceLocation TemplateKWLoc,
1342 SourceLocation NameLoc, QualType ObjectType,
1343 bool AllowInjectedClassName);
1344
1345 /// Build a new template name given a template template parameter pack
1346 /// and the
1347 ///
1348 /// By default, performs semantic analysis to determine whether the name can
1349 /// be resolved to a specific template, then builds the appropriate kind of
1350 /// template name. Subclasses may override this routine to provide different
1351 /// behavior.
1353 Decl *AssociatedDecl, unsigned Index,
1354 bool Final) {
1356 ArgPack, AssociatedDecl, Index, Final);
1357 }
1358
1359 /// Build a new pack-index-template-name ([temp.names]).
1360 ///
1361 /// By default, performs semantic analysis to build the new template name.
1362 /// Subclasses may override this routine to provide different behavior.
1365 bool FullySubstituted,
1366 ArrayRef<TemplateName> Expansions = {}) {
1368 Pattern, IndexExpr, FullySubstituted, Expansions);
1369 }
1370
1371 /// Build a new compound statement.
1372 ///
1373 /// By default, performs semantic analysis to build the new statement.
1374 /// Subclasses may override this routine to provide different behavior.
1376 MultiStmtArg Statements,
1377 SourceLocation RBraceLoc,
1378 bool IsStmtExpr) {
1379 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
1380 IsStmtExpr);
1381 }
1382
1383 /// Build a new case statement.
1384 ///
1385 /// By default, performs semantic analysis to build the new statement.
1386 /// Subclasses may override this routine to provide different behavior.
1388 Expr *LHS,
1389 SourceLocation EllipsisLoc,
1390 Expr *RHS,
1391 SourceLocation ColonLoc) {
1392 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
1393 ColonLoc);
1394 }
1395
1396 /// Attach the body to a new case statement.
1397 ///
1398 /// By default, performs semantic analysis to build the new statement.
1399 /// Subclasses may override this routine to provide different behavior.
1401 getSema().ActOnCaseStmtBody(S, Body);
1402 return S;
1403 }
1404
1405 /// Build a new default statement.
1406 ///
1407 /// By default, performs semantic analysis to build the new statement.
1408 /// Subclasses may override this routine to provide different behavior.
1410 SourceLocation ColonLoc,
1411 Stmt *SubStmt) {
1412 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
1413 /*CurScope=*/nullptr);
1414 }
1415
1416 /// Build a new label statement.
1417 ///
1418 /// By default, performs semantic analysis to build the new statement.
1419 /// Subclasses may override this routine to provide different behavior.
1421 SourceLocation ColonLoc, Stmt *SubStmt) {
1422 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
1423 }
1424
1425 /// Build a new attributed statement.
1426 ///
1427 /// By default, performs semantic analysis to build the new statement.
1428 /// Subclasses may override this routine to provide different behavior.
1431 Stmt *SubStmt) {
1432 if (SemaRef.CheckRebuiltStmtAttributes(Attrs))
1433 return StmtError();
1434 return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
1435 }
1436
1437 /// Build a new "if" statement.
1438 ///
1439 /// By default, performs semantic analysis to build the new statement.
1440 /// Subclasses may override this routine to provide different behavior.
1442 SourceLocation LParenLoc, Sema::ConditionResult Cond,
1443 SourceLocation RParenLoc, Stmt *Init, Stmt *Then,
1444 SourceLocation ElseLoc, Stmt *Else) {
1445 return getSema().ActOnIfStmt(IfLoc, Kind, LParenLoc, Init, Cond, RParenLoc,
1446 Then, ElseLoc, Else);
1447 }
1448
1449 /// Start building a new switch statement.
1450 ///
1451 /// By default, performs semantic analysis to build the new statement.
1452 /// Subclasses may override this routine to provide different behavior.
1454 SourceLocation LParenLoc, Stmt *Init,
1456 SourceLocation RParenLoc) {
1457 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond,
1458 RParenLoc);
1459 }
1460
1461 /// Attach the body to the switch statement.
1462 ///
1463 /// By default, performs semantic analysis to build the new statement.
1464 /// Subclasses may override this routine to provide different behavior.
1466 Stmt *Switch, Stmt *Body) {
1467 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
1468 }
1469
1470 /// Build a new while statement.
1471 ///
1472 /// By default, performs semantic analysis to build the new statement.
1473 /// Subclasses may override this routine to provide different behavior.
1476 SourceLocation RParenLoc, Stmt *Body) {
1477 return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body);
1478 }
1479
1480 /// Build a new do-while statement.
1481 ///
1482 /// By default, performs semantic analysis to build the new statement.
1483 /// Subclasses may override this routine to provide different behavior.
1485 SourceLocation WhileLoc, SourceLocation LParenLoc,
1486 Expr *Cond, SourceLocation RParenLoc) {
1487 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1488 Cond, RParenLoc);
1489 }
1490
1491 /// Build a new for statement.
1492 ///
1493 /// By default, performs semantic analysis to build the new statement.
1494 /// Subclasses may override this routine to provide different behavior.
1497 Sema::FullExprArg Inc, SourceLocation RParenLoc,
1498 Stmt *Body) {
1499 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
1500 Inc, RParenLoc, Body);
1501 }
1502
1503 /// Build a new goto statement.
1504 ///
1505 /// By default, performs semantic analysis to build the new statement.
1506 /// Subclasses may override this routine to provide different behavior.
1508 LabelDecl *Label) {
1509 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
1510 }
1511
1512 /// Build a new indirect goto statement.
1513 ///
1514 /// By default, performs semantic analysis to build the new statement.
1515 /// Subclasses may override this routine to provide different behavior.
1517 SourceLocation StarLoc,
1518 Expr *Target) {
1519 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
1520 }
1521
1522 /// Build a new return statement.
1523 ///
1524 /// By default, performs semantic analysis to build the new statement.
1525 /// Subclasses may override this routine to provide different behavior.
1527 return getSema().BuildReturnStmt(ReturnLoc, Result);
1528 }
1529
1530 /// Build a new declaration statement.
1531 ///
1532 /// By default, performs semantic analysis to build the new statement.
1533 /// Subclasses may override this routine to provide different behavior.
1535 SourceLocation StartLoc, SourceLocation EndLoc) {
1537 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
1538 }
1539
1540 /// Build a new inline asm statement.
1541 ///
1542 /// By default, performs semantic analysis to build the new statement.
1543 /// Subclasses may override this routine to provide different behavior.
1545 bool IsVolatile, unsigned NumOutputs,
1546 unsigned NumInputs, IdentifierInfo **Names,
1547 MultiExprArg Constraints, MultiExprArg Exprs,
1548 Expr *AsmString, MultiExprArg Clobbers,
1549 unsigned NumLabels,
1550 SourceLocation RParenLoc) {
1551 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1552 NumInputs, Names, Constraints, Exprs,
1553 AsmString, Clobbers, NumLabels, RParenLoc);
1554 }
1555
1556 /// Build a new MS style inline asm statement.
1557 ///
1558 /// By default, performs semantic analysis to build the new statement.
1559 /// Subclasses may override this routine to provide different behavior.
1561 ArrayRef<Token> AsmToks,
1562 StringRef AsmString,
1563 unsigned NumOutputs, unsigned NumInputs,
1564 ArrayRef<StringRef> Constraints,
1565 ArrayRef<StringRef> Clobbers,
1566 ArrayRef<Expr*> Exprs,
1567 SourceLocation EndLoc) {
1568 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1569 NumOutputs, NumInputs,
1570 Constraints, Clobbers, Exprs, EndLoc);
1571 }
1572
1573 /// Build a new co_return statement.
1574 ///
1575 /// By default, performs semantic analysis to build the new statement.
1576 /// Subclasses may override this routine to provide different behavior.
1578 bool IsImplicit) {
1579 return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit);
1580 }
1581
1582 /// Build a new co_await expression.
1583 ///
1584 /// By default, performs semantic analysis to build the new expression.
1585 /// Subclasses may override this routine to provide different behavior.
1587 UnresolvedLookupExpr *OpCoawaitLookup,
1588 bool IsImplicit) {
1589 // This function rebuilds a coawait-expr given its operator.
1590 // For an explicit coawait-expr, the rebuild involves the full set
1591 // of transformations performed by BuildUnresolvedCoawaitExpr(),
1592 // including calling await_transform().
1593 // For an implicit coawait-expr, we need to rebuild the "operator
1594 // coawait" but not await_transform(), so use BuildResolvedCoawaitExpr().
1595 // This mirrors how the implicit CoawaitExpr is originally created
1596 // in Sema::ActOnCoroutineBodyStart().
1597 if (IsImplicit) {
1599 CoawaitLoc, Operand, OpCoawaitLookup);
1600 if (Suspend.isInvalid())
1601 return ExprError();
1602 return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Operand,
1603 Suspend.get(), true);
1604 }
1605
1606 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Operand,
1607 OpCoawaitLookup);
1608 }
1609
1610 /// Build a new co_await expression.
1611 ///
1612 /// By default, performs semantic analysis to build the new expression.
1613 /// Subclasses may override this routine to provide different behavior.
1615 Expr *Result,
1616 UnresolvedLookupExpr *Lookup) {
1617 return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup);
1618 }
1619
1620 /// Build a new co_yield expression.
1621 ///
1622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
1625 return getSema().BuildCoyieldExpr(CoyieldLoc, Result);
1626 }
1627
1631
1632 /// Build a new Objective-C \@try statement.
1633 ///
1634 /// By default, performs semantic analysis to build the new statement.
1635 /// Subclasses may override this routine to provide different behavior.
1637 Stmt *TryBody,
1638 MultiStmtArg CatchStmts,
1639 Stmt *Finally) {
1640 return getSema().ObjC().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
1641 Finally);
1642 }
1643
1644 /// Rebuild an Objective-C exception declaration.
1645 ///
1646 /// By default, performs semantic analysis to build the new declaration.
1647 /// Subclasses may override this routine to provide different behavior.
1649 TypeSourceInfo *TInfo, QualType T) {
1651 TInfo, T, ExceptionDecl->getInnerLocStart(),
1652 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
1653 }
1654
1655 /// Build a new Objective-C \@catch statement.
1656 ///
1657 /// By default, performs semantic analysis to build the new statement.
1658 /// Subclasses may override this routine to provide different behavior.
1660 SourceLocation RParenLoc,
1661 VarDecl *Var,
1662 Stmt *Body) {
1663 return getSema().ObjC().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, Var, Body);
1664 }
1665
1666 /// Build a new Objective-C \@finally statement.
1667 ///
1668 /// By default, performs semantic analysis to build the new statement.
1669 /// Subclasses may override this routine to provide different behavior.
1671 Stmt *Body) {
1672 return getSema().ObjC().ActOnObjCAtFinallyStmt(AtLoc, Body);
1673 }
1674
1675 /// Build a new Objective-C \@throw statement.
1676 ///
1677 /// By default, performs semantic analysis to build the new statement.
1678 /// Subclasses may override this routine to provide different behavior.
1680 Expr *Operand) {
1681 return getSema().ObjC().BuildObjCAtThrowStmt(AtLoc, Operand);
1682 }
1683
1684 /// Build a new OpenMP Canonical loop.
1685 ///
1686 /// Ensures that the outermost loop in @p LoopStmt is wrapped by a
1687 /// OMPCanonicalLoop.
1689 return getSema().OpenMP().ActOnOpenMPCanonicalLoop(LoopStmt);
1690 }
1691
1692 /// Build a new OpenMP executable directive.
1693 ///
1694 /// By default, performs semantic analysis to build the new statement.
1695 /// Subclasses may override this routine to provide different behavior.
1697 DeclarationNameInfo DirName,
1698 OpenMPDirectiveKind CancelRegion,
1699 ArrayRef<OMPClause *> Clauses,
1700 Stmt *AStmt, SourceLocation StartLoc,
1701 SourceLocation EndLoc) {
1702
1704 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
1705 }
1706
1707 /// Build a new OpenMP metadirective.
1708 ///
1709 /// By default, performs semantic analysis to build the new statement.
1710 /// Subclasses may override this routine to provide different behavior.
1712 SourceLocation EndLoc,
1713 ArrayRef<OMPTraitInfo *> TraitInfos,
1714 ArrayRef<Stmt *> Variants) {
1715 return getSema().OpenMP().ActOnOpenMPMetaDirective(StartLoc, EndLoc,
1716 TraitInfos, Variants);
1717 }
1718
1719 /// Build a new OpenMP informational directive.
1721 DeclarationNameInfo DirName,
1722 ArrayRef<OMPClause *> Clauses,
1723 Stmt *AStmt,
1724 SourceLocation StartLoc,
1725 SourceLocation EndLoc) {
1726
1728 Kind, DirName, Clauses, AStmt, StartLoc, EndLoc);
1729 }
1730
1731 /// Build a new OpenMP 'if' 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 *Condition, SourceLocation StartLoc,
1737 SourceLocation LParenLoc,
1738 SourceLocation NameModifierLoc,
1739 SourceLocation ColonLoc,
1740 SourceLocation EndLoc) {
1742 NameModifier, Condition, StartLoc, LParenLoc, NameModifierLoc, ColonLoc,
1743 EndLoc);
1744 }
1745
1746 /// Build a new OpenMP 'final' clause.
1747 ///
1748 /// By default, performs semantic analysis to build the new OpenMP clause.
1749 /// Subclasses may override this routine to provide different behavior.
1751 SourceLocation LParenLoc,
1752 SourceLocation EndLoc) {
1753 return getSema().OpenMP().ActOnOpenMPFinalClause(Condition, StartLoc,
1754 LParenLoc, EndLoc);
1755 }
1756
1757 /// Build a new OpenMP 'num_threads' clause.
1758 ///
1759 /// By default, performs semantic analysis to build the new OpenMP clause.
1760 /// Subclasses may override this routine to provide different behavior.
1762 ArrayRef<Expr *> VarList,
1763 OpenMPNumThreadsClauseModifier PrescriptivenessModifier,
1764 SourceLocation PrescriptivenessModifierLoc,
1765 OpenMPNumThreadsClauseModifier DimsModifier, Expr *DimsModifierExpr,
1766 SourceLocation DimsModifierLoc, SourceLocation StartLoc,
1767 SourceLocation LParenLoc, SourceLocation EndLoc) {
1769 VarList, PrescriptivenessModifier, PrescriptivenessModifierLoc,
1770 DimsModifier, DimsModifierExpr, DimsModifierLoc, StartLoc, LParenLoc,
1771 EndLoc);
1772 }
1773
1774 /// Build a new OpenMP 'safelen' clause.
1775 ///
1776 /// By default, performs semantic analysis to build the new OpenMP clause.
1777 /// Subclasses may override this routine to provide different behavior.
1779 SourceLocation LParenLoc,
1780 SourceLocation EndLoc) {
1781 return getSema().OpenMP().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc,
1782 EndLoc);
1783 }
1784
1785 /// Build a new OpenMP 'simdlen' clause.
1786 ///
1787 /// By default, performs semantic analysis to build the new OpenMP clause.
1788 /// Subclasses may override this routine to provide different behavior.
1790 SourceLocation LParenLoc,
1791 SourceLocation EndLoc) {
1792 return getSema().OpenMP().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc,
1793 EndLoc);
1794 }
1795
1797 SourceLocation StartLoc,
1798 SourceLocation LParenLoc,
1799 SourceLocation EndLoc) {
1800 return getSema().OpenMP().ActOnOpenMPSizesClause(Sizes, StartLoc, LParenLoc,
1801 EndLoc);
1802 }
1803
1805 SourceLocation StartLoc,
1806 SourceLocation LParenLoc,
1807 SourceLocation EndLoc,
1808 std::optional<unsigned> FillIdx,
1809 SourceLocation FillLoc) {
1810 unsigned FillCount = FillIdx ? 1 : 0;
1812 Counts, StartLoc, LParenLoc, EndLoc, FillIdx, FillLoc, FillCount);
1813 }
1814
1815 /// Build a new OpenMP 'permutation' clause.
1817 SourceLocation StartLoc,
1818 SourceLocation LParenLoc,
1819 SourceLocation EndLoc) {
1820 return getSema().OpenMP().ActOnOpenMPPermutationClause(PermExprs, StartLoc,
1821 LParenLoc, EndLoc);
1822 }
1823
1824 /// Build a new OpenMP 'full' clause.
1826 SourceLocation EndLoc) {
1827 return getSema().OpenMP().ActOnOpenMPFullClause(StartLoc, EndLoc);
1828 }
1829
1830 /// Build a new OpenMP 'partial' clause.
1832 SourceLocation LParenLoc,
1833 SourceLocation EndLoc) {
1834 return getSema().OpenMP().ActOnOpenMPPartialClause(Factor, StartLoc,
1835 LParenLoc, EndLoc);
1836 }
1837
1838 /// Build a new OpenMP 'depth' clause.
1840 SourceLocation LParenLoc,
1841 SourceLocation EndLoc) {
1842 return getSema().OpenMP().ActOnOpenMPDepthClause(Depth, StartLoc, LParenLoc,
1843 EndLoc);
1844 }
1845
1846 OMPClause *
1848 SourceLocation LParenLoc, SourceLocation FirstLoc,
1849 SourceLocation CountLoc, SourceLocation EndLoc) {
1851 First, Count, StartLoc, LParenLoc, FirstLoc, CountLoc, EndLoc);
1852 }
1853
1854 /// Build a new OpenMP 'allocator' clause.
1855 ///
1856 /// By default, performs semantic analysis to build the new OpenMP clause.
1857 /// Subclasses may override this routine to provide different behavior.
1859 SourceLocation LParenLoc,
1860 SourceLocation EndLoc) {
1861 return getSema().OpenMP().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc,
1862 EndLoc);
1863 }
1864
1865 /// Build a new OpenMP 'collapse' clause.
1866 ///
1867 /// By default, performs semantic analysis to build the new OpenMP clause.
1868 /// Subclasses may override this routine to provide different behavior.
1870 SourceLocation LParenLoc,
1871 SourceLocation EndLoc) {
1872 return getSema().OpenMP().ActOnOpenMPCollapseClause(Num, StartLoc,
1873 LParenLoc, EndLoc);
1874 }
1875
1876 /// Build a new OpenMP 'default' clause.
1877 ///
1878 /// By default, performs semantic analysis to build the new OpenMP clause.
1879 /// Subclasses may override this routine to provide different behavior.
1882 SourceLocation VCLoc,
1883 SourceLocation StartLoc,
1884 SourceLocation LParenLoc,
1885 SourceLocation EndLoc) {
1887 Kind, KindKwLoc, VCKind, VCLoc, StartLoc, LParenLoc, EndLoc);
1888 }
1889
1890 /// Build a new OpenMP 'proc_bind' clause.
1891 ///
1892 /// By default, performs semantic analysis to build the new OpenMP clause.
1893 /// Subclasses may override this routine to provide different behavior.
1895 SourceLocation KindKwLoc,
1896 SourceLocation StartLoc,
1897 SourceLocation LParenLoc,
1898 SourceLocation EndLoc) {
1900 Kind, KindKwLoc, StartLoc, LParenLoc, EndLoc);
1901 }
1903 SourceLocation StartLoc,
1904 SourceLocation LParenLoc,
1905 SourceLocation EndLoc) {
1907 ImpexTypeArg, StartLoc, LParenLoc, EndLoc);
1908 }
1909
1910 /// Build a new OpenMP 'schedule' clause.
1911 ///
1912 /// By default, performs semantic analysis to build the new OpenMP clause.
1913 /// Subclasses may override this routine to provide different behavior.
1916 OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc,
1917 SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc,
1918 SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) {
1920 M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc,
1921 CommaLoc, EndLoc);
1922 }
1923
1924 /// Build a new OpenMP 'ordered' clause.
1925 ///
1926 /// By default, performs semantic analysis to build the new OpenMP clause.
1927 /// Subclasses may override this routine to provide different behavior.
1929 SourceLocation EndLoc,
1930 SourceLocation LParenLoc, Expr *Num) {
1931 return getSema().OpenMP().ActOnOpenMPOrderedClause(StartLoc, EndLoc,
1932 LParenLoc, Num);
1933 }
1934
1935 /// Build a new OpenMP 'nowait' clause.
1936 ///
1937 /// By default, performs semantic analysis to build the new OpenMP clause.
1938 /// Subclasses may override this routine to provide different behavior.
1940 SourceLocation LParenLoc,
1941 SourceLocation EndLoc) {
1942 return getSema().OpenMP().ActOnOpenMPNowaitClause(StartLoc, EndLoc,
1943 LParenLoc, Condition);
1944 }
1945
1946 /// Build a new OpenMP 'private' clause.
1947 ///
1948 /// By default, performs semantic analysis to build the new OpenMP clause.
1949 /// Subclasses may override this routine to provide different behavior.
1951 SourceLocation StartLoc,
1952 SourceLocation LParenLoc,
1953 SourceLocation EndLoc) {
1954 return getSema().OpenMP().ActOnOpenMPPrivateClause(VarList, StartLoc,
1955 LParenLoc, EndLoc);
1956 }
1957
1958 /// Build a new OpenMP 'firstprivate' clause.
1959 ///
1960 /// By default, performs semantic analysis to build the new OpenMP clause.
1961 /// Subclasses may override this routine to provide different behavior.
1963 SourceLocation StartLoc,
1964 SourceLocation LParenLoc,
1965 SourceLocation EndLoc) {
1966 return getSema().OpenMP().ActOnOpenMPFirstprivateClause(VarList, StartLoc,
1967 LParenLoc, EndLoc);
1968 }
1969
1970 /// Build a new OpenMP 'lastprivate' clause.
1971 ///
1972 /// By default, performs semantic analysis to build the new OpenMP clause.
1973 /// Subclasses may override this routine to provide different behavior.
1976 SourceLocation LPKindLoc,
1977 SourceLocation ColonLoc,
1978 SourceLocation StartLoc,
1979 SourceLocation LParenLoc,
1980 SourceLocation EndLoc) {
1982 VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc);
1983 }
1984
1985 /// Build a new OpenMP 'shared' clause.
1986 ///
1987 /// By default, performs semantic analysis to build the new OpenMP clause.
1988 /// Subclasses may override this routine to provide different behavior.
1990 SourceLocation StartLoc,
1991 SourceLocation LParenLoc,
1992 SourceLocation EndLoc) {
1993 return getSema().OpenMP().ActOnOpenMPSharedClause(VarList, StartLoc,
1994 LParenLoc, EndLoc);
1995 }
1996
1997 /// Build a new OpenMP 'reduction' clause.
1998 ///
1999 /// By default, performs semantic analysis to build the new statement.
2000 /// Subclasses may override this routine to provide different behavior.
2003 OpenMPOriginalSharingModifier OriginalSharingModifier,
2004 SourceLocation StartLoc, SourceLocation LParenLoc,
2005 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2006 SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec,
2007 const DeclarationNameInfo &ReductionId,
2008 ArrayRef<Expr *> UnresolvedReductions) {
2010 VarList, {Modifier, OriginalSharingModifier}, StartLoc, LParenLoc,
2011 ModifierLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, ReductionId,
2012 UnresolvedReductions);
2013 }
2014
2015 /// Build a new OpenMP 'task_reduction' clause.
2016 ///
2017 /// By default, performs semantic analysis to build the new statement.
2018 /// Subclasses may override this routine to provide different behavior.
2020 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2021 SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc,
2022 CXXScopeSpec &ReductionIdScopeSpec,
2023 const DeclarationNameInfo &ReductionId,
2024 ArrayRef<Expr *> UnresolvedReductions) {
2026 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
2027 ReductionId, UnresolvedReductions);
2028 }
2029
2030 /// Build a new OpenMP 'in_reduction' clause.
2031 ///
2032 /// By default, performs semantic analysis to build the new statement.
2033 /// Subclasses may override this routine to provide different behavior.
2034 OMPClause *
2036 SourceLocation LParenLoc, SourceLocation ColonLoc,
2037 SourceLocation EndLoc,
2038 CXXScopeSpec &ReductionIdScopeSpec,
2039 const DeclarationNameInfo &ReductionId,
2040 ArrayRef<Expr *> UnresolvedReductions) {
2042 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
2043 ReductionId, UnresolvedReductions);
2044 }
2045
2046 /// Build a new OpenMP 'linear' clause.
2047 ///
2048 /// By default, performs semantic analysis to build the new OpenMP clause.
2049 /// Subclasses may override this routine to provide different behavior.
2051 ArrayRef<Expr *> VarList, Expr *Step, SourceLocation StartLoc,
2052 SourceLocation LParenLoc, OpenMPLinearClauseKind Modifier,
2053 SourceLocation ModifierLoc, SourceLocation ColonLoc,
2054 SourceLocation StepModifierLoc, SourceLocation EndLoc) {
2056 VarList, Step, StartLoc, LParenLoc, Modifier, ModifierLoc, ColonLoc,
2057 StepModifierLoc, EndLoc);
2058 }
2059
2060 /// Build a new OpenMP 'aligned' 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 ColonLoc,
2068 SourceLocation EndLoc) {
2070 VarList, Alignment, StartLoc, LParenLoc, ColonLoc, EndLoc);
2071 }
2072
2073 /// Build a new OpenMP 'copyin' clause.
2074 ///
2075 /// By default, performs semantic analysis to build the new OpenMP clause.
2076 /// Subclasses may override this routine to provide different behavior.
2078 SourceLocation StartLoc,
2079 SourceLocation LParenLoc,
2080 SourceLocation EndLoc) {
2081 return getSema().OpenMP().ActOnOpenMPCopyinClause(VarList, StartLoc,
2082 LParenLoc, EndLoc);
2083 }
2084
2085 /// Build a new OpenMP 'copyprivate' clause.
2086 ///
2087 /// By default, performs semantic analysis to build the new OpenMP clause.
2088 /// Subclasses may override this routine to provide different behavior.
2090 SourceLocation StartLoc,
2091 SourceLocation LParenLoc,
2092 SourceLocation EndLoc) {
2093 return getSema().OpenMP().ActOnOpenMPCopyprivateClause(VarList, StartLoc,
2094 LParenLoc, EndLoc);
2095 }
2096
2097 /// Build a new OpenMP 'flush' pseudo clause.
2098 ///
2099 /// By default, performs semantic analysis to build the new OpenMP clause.
2100 /// Subclasses may override this routine to provide different behavior.
2102 SourceLocation StartLoc,
2103 SourceLocation LParenLoc,
2104 SourceLocation EndLoc) {
2105 return getSema().OpenMP().ActOnOpenMPFlushClause(VarList, StartLoc,
2106 LParenLoc, EndLoc);
2107 }
2108
2109 /// Build a new OpenMP 'depobj' pseudo 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 SourceLocation LParenLoc,
2115 SourceLocation EndLoc) {
2116 return getSema().OpenMP().ActOnOpenMPDepobjClause(Depobj, StartLoc,
2117 LParenLoc, EndLoc);
2118 }
2119
2120 /// Build a new OpenMP 'depend' pseudo clause.
2121 ///
2122 /// By default, performs semantic analysis to build the new OpenMP clause.
2123 /// Subclasses may override this routine to provide different behavior.
2125 Expr *DepModifier, ArrayRef<Expr *> VarList,
2126 SourceLocation StartLoc,
2127 SourceLocation LParenLoc,
2128 SourceLocation EndLoc) {
2130 Data, DepModifier, VarList, StartLoc, LParenLoc, EndLoc);
2131 }
2132
2133 /// Build a new OpenMP 'device' clause.
2134 ///
2135 /// By default, performs semantic analysis to build the new statement.
2136 /// Subclasses may override this routine to provide different behavior.
2138 Expr *Device, SourceLocation StartLoc,
2139 SourceLocation LParenLoc,
2140 SourceLocation ModifierLoc,
2141 SourceLocation EndLoc) {
2143 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2144 }
2145
2146 /// Build a new OpenMP 'map' clause.
2147 ///
2148 /// By default, performs semantic analysis to build the new OpenMP clause.
2149 /// Subclasses may override this routine to provide different behavior.
2151 Expr *IteratorModifier, ArrayRef<OpenMPMapModifierKind> MapTypeModifiers,
2152 ArrayRef<SourceLocation> MapTypeModifiersLoc,
2153 CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId,
2154 OpenMPMapClauseKind MapType, bool IsMapTypeImplicit,
2155 SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
2156 const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) {
2158 IteratorModifier, MapTypeModifiers, MapTypeModifiersLoc,
2159 MapperIdScopeSpec, MapperId, MapType, IsMapTypeImplicit, MapLoc,
2160 ColonLoc, VarList, Locs,
2161 /*NoDiagnose=*/false, UnresolvedMappers);
2162 }
2163
2164 /// Build a new OpenMP 'allocate' clause.
2165 ///
2166 /// By default, performs semantic analysis to build the new OpenMP clause.
2167 /// Subclasses may override this routine to provide different behavior.
2168 OMPClause *
2169 RebuildOMPAllocateClause(Expr *Allocate, Expr *Alignment,
2170 OpenMPAllocateClauseModifier FirstModifier,
2171 SourceLocation FirstModifierLoc,
2172 OpenMPAllocateClauseModifier SecondModifier,
2173 SourceLocation SecondModifierLoc,
2174 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2175 SourceLocation LParenLoc, SourceLocation ColonLoc,
2176 SourceLocation EndLoc) {
2178 Allocate, Alignment, FirstModifier, FirstModifierLoc, SecondModifier,
2179 SecondModifierLoc, VarList, StartLoc, LParenLoc, ColonLoc, EndLoc);
2180 }
2181
2182 /// Build a new OpenMP 'num_teams' clause.
2183 ///
2184 /// By default, performs semantic analysis to build the new statement.
2185 /// Subclasses may override this routine to provide different behavior.
2188 Expr *ModifierExpr, SourceLocation ModifierLoc,
2189 OpenMPNumTeamsClauseModifier ModifierExtra, Expr *ModifierExtraExpr,
2190 SourceLocation ModifierExtraLoc, SourceLocation StartLoc,
2191 SourceLocation LParenLoc, SourceLocation EndLoc) {
2193 VarList, Modifier, ModifierExpr, ModifierLoc, ModifierExtra,
2194 ModifierExtraExpr, ModifierExtraLoc, StartLoc, LParenLoc, EndLoc);
2195 }
2196
2197 /// Build a new OpenMP 'thread_limit' clause.
2198 ///
2199 /// By default, performs semantic analysis to build the new statement.
2200 /// Subclasses may override this routine to provide different behavior.
2203 Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc,
2204 SourceLocation LParenLoc, SourceLocation EndLoc) {
2206 VarList, Modifier, ModifierExpr, ModifierLoc, StartLoc, LParenLoc,
2207 EndLoc);
2208 }
2209
2210 /// Build a new OpenMP 'priority' clause.
2211 ///
2212 /// By default, performs semantic analysis to build the new statement.
2213 /// Subclasses may override this routine to provide different behavior.
2215 SourceLocation LParenLoc,
2216 SourceLocation EndLoc) {
2217 return getSema().OpenMP().ActOnOpenMPPriorityClause(Priority, StartLoc,
2218 LParenLoc, EndLoc);
2219 }
2220
2221 /// Build a new OpenMP 'grainsize' clause.
2222 ///
2223 /// By default, performs semantic analysis to build the new statement.
2224 /// Subclasses may override this routine to provide different behavior.
2226 Expr *Device, SourceLocation StartLoc,
2227 SourceLocation LParenLoc,
2228 SourceLocation ModifierLoc,
2229 SourceLocation EndLoc) {
2231 Modifier, Device, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2232 }
2233
2234 /// Build a new OpenMP 'num_tasks' clause.
2235 ///
2236 /// By default, performs semantic analysis to build the new statement.
2237 /// Subclasses may override this routine to provide different behavior.
2239 Expr *NumTasks, SourceLocation StartLoc,
2240 SourceLocation LParenLoc,
2241 SourceLocation ModifierLoc,
2242 SourceLocation EndLoc) {
2244 Modifier, NumTasks, StartLoc, LParenLoc, ModifierLoc, EndLoc);
2245 }
2246
2247 /// Build a new OpenMP 'hint' clause.
2248 ///
2249 /// By default, performs semantic analysis to build the new statement.
2250 /// Subclasses may override this routine to provide different behavior.
2252 SourceLocation LParenLoc,
2253 SourceLocation EndLoc) {
2254 return getSema().OpenMP().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc,
2255 EndLoc);
2256 }
2257
2258 /// Build a new OpenMP 'detach' clause.
2259 ///
2260 /// By default, performs semantic analysis to build the new statement.
2261 /// Subclasses may override this routine to provide different behavior.
2263 SourceLocation LParenLoc,
2264 SourceLocation EndLoc) {
2265 return getSema().OpenMP().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc,
2266 EndLoc);
2267 }
2268
2269 /// Build a new OpenMP 'dist_schedule' clause.
2270 ///
2271 /// By default, performs semantic analysis to build the new OpenMP clause.
2272 /// Subclasses may override this routine to provide different behavior.
2273 OMPClause *
2275 Expr *ChunkSize, SourceLocation StartLoc,
2276 SourceLocation LParenLoc, SourceLocation KindLoc,
2277 SourceLocation CommaLoc, SourceLocation EndLoc) {
2279 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
2280 }
2281
2282 /// Build a new OpenMP 'to' clause.
2283 ///
2284 /// By default, performs semantic analysis to build the new statement.
2285 /// Subclasses may override this routine to provide different behavior.
2286 OMPClause *
2288 ArrayRef<SourceLocation> MotionModifiersLoc,
2289 Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
2290 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2291 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2292 ArrayRef<Expr *> UnresolvedMappers) {
2294 MotionModifiers, MotionModifiersLoc, IteratorModifier,
2295 MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs,
2296 UnresolvedMappers);
2297 }
2298
2299 /// Build a new OpenMP 'from' clause.
2300 ///
2301 /// By default, performs semantic analysis to build the new statement.
2302 /// Subclasses may override this routine to provide different behavior.
2303 OMPClause *
2305 ArrayRef<SourceLocation> MotionModifiersLoc,
2306 Expr *IteratorModifier, CXXScopeSpec &MapperIdScopeSpec,
2307 DeclarationNameInfo &MapperId, SourceLocation ColonLoc,
2308 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2309 ArrayRef<Expr *> UnresolvedMappers) {
2311 MotionModifiers, MotionModifiersLoc, IteratorModifier,
2312 MapperIdScopeSpec, MapperId, ColonLoc, VarList, Locs,
2313 UnresolvedMappers);
2314 }
2315
2316 /// Build a new OpenMP 'use_device_ptr' clause.
2317 ///
2318 /// By default, performs semantic analysis to build the new OpenMP clause.
2319 /// Subclasses may override this routine to provide different behavior.
2321 ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs,
2322 OpenMPUseDevicePtrFallbackModifier FallbackModifier,
2323 SourceLocation FallbackModifierLoc) {
2325 VarList, Locs, FallbackModifier, FallbackModifierLoc);
2326 }
2327
2328 /// Build a new OpenMP 'use_device_addr' clause.
2329 ///
2330 /// By default, performs semantic analysis to build the new OpenMP clause.
2331 /// Subclasses may override this routine to provide different behavior.
2336
2337 /// Build a new OpenMP 'is_device_ptr' clause.
2338 ///
2339 /// By default, performs semantic analysis to build the new OpenMP clause.
2340 /// Subclasses may override this routine to provide different behavior.
2342 const OMPVarListLocTy &Locs) {
2343 return getSema().OpenMP().ActOnOpenMPIsDevicePtrClause(VarList, Locs);
2344 }
2345
2346 /// Build a new OpenMP 'has_device_addr' clause.
2347 ///
2348 /// By default, performs semantic analysis to build the new OpenMP clause.
2349 /// Subclasses may override this routine to provide different behavior.
2354
2355 /// Build a new OpenMP 'defaultmap' clause.
2356 ///
2357 /// By default, performs semantic analysis to build the new OpenMP clause.
2358 /// Subclasses may override this routine to provide different behavior.
2361 SourceLocation StartLoc,
2362 SourceLocation LParenLoc,
2363 SourceLocation MLoc,
2364 SourceLocation KindLoc,
2365 SourceLocation EndLoc) {
2367 M, Kind, StartLoc, LParenLoc, MLoc, KindLoc, EndLoc);
2368 }
2369
2370 /// Build a new OpenMP 'nontemporal' clause.
2371 ///
2372 /// By default, performs semantic analysis to build the new OpenMP clause.
2373 /// Subclasses may override this routine to provide different behavior.
2375 SourceLocation StartLoc,
2376 SourceLocation LParenLoc,
2377 SourceLocation EndLoc) {
2378 return getSema().OpenMP().ActOnOpenMPNontemporalClause(VarList, StartLoc,
2379 LParenLoc, EndLoc);
2380 }
2381
2382 /// Build a new OpenMP 'inclusive' clause.
2383 ///
2384 /// By default, performs semantic analysis to build the new OpenMP clause.
2385 /// Subclasses may override this routine to provide different behavior.
2387 SourceLocation StartLoc,
2388 SourceLocation LParenLoc,
2389 SourceLocation EndLoc) {
2390 return getSema().OpenMP().ActOnOpenMPInclusiveClause(VarList, StartLoc,
2391 LParenLoc, EndLoc);
2392 }
2393
2394 /// Build a new OpenMP 'exclusive' clause.
2395 ///
2396 /// By default, performs semantic analysis to build the new OpenMP clause.
2397 /// Subclasses may override this routine to provide different behavior.
2399 SourceLocation StartLoc,
2400 SourceLocation LParenLoc,
2401 SourceLocation EndLoc) {
2402 return getSema().OpenMP().ActOnOpenMPExclusiveClause(VarList, StartLoc,
2403 LParenLoc, EndLoc);
2404 }
2405
2406 /// Build a new OpenMP 'uses_allocators' clause.
2407 ///
2408 /// By default, performs semantic analysis to build the new OpenMP clause.
2409 /// Subclasses may override this routine to provide different behavior.
2416
2417 /// Build a new OpenMP 'affinity' clause.
2418 ///
2419 /// By default, performs semantic analysis to build the new OpenMP clause.
2420 /// Subclasses may override this routine to provide different behavior.
2422 SourceLocation LParenLoc,
2423 SourceLocation ColonLoc,
2424 SourceLocation EndLoc, Expr *Modifier,
2425 ArrayRef<Expr *> Locators) {
2427 StartLoc, LParenLoc, ColonLoc, EndLoc, Modifier, Locators);
2428 }
2429
2430 /// Build a new OpenMP 'order' clause.
2431 ///
2432 /// By default, performs semantic analysis to build the new OpenMP clause.
2433 /// Subclasses may override this routine to provide different behavior.
2435 OpenMPOrderClauseKind Kind, SourceLocation KindKwLoc,
2436 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc,
2437 OpenMPOrderClauseModifier Modifier, SourceLocation ModifierKwLoc) {
2439 Modifier, Kind, StartLoc, LParenLoc, ModifierKwLoc, KindKwLoc, EndLoc);
2440 }
2441
2442 /// Build a new OpenMP 'init' clause.
2443 ///
2444 /// By default, performs semantic analysis to build the new OpenMP clause.
2445 /// Subclasses may override this routine to provide different behavior.
2447 SourceLocation StartLoc,
2448 SourceLocation LParenLoc,
2449 SourceLocation VarLoc,
2450 SourceLocation EndLoc) {
2452 InteropVar, InteropInfo, StartLoc, LParenLoc, VarLoc, EndLoc);
2453 }
2454
2455 /// Build a new OpenMP 'use' clause.
2456 ///
2457 /// By default, performs semantic analysis to build the new OpenMP clause.
2458 /// Subclasses may override this routine to provide different behavior.
2460 SourceLocation LParenLoc,
2461 SourceLocation VarLoc, SourceLocation EndLoc) {
2462 return getSema().OpenMP().ActOnOpenMPUseClause(InteropVar, StartLoc,
2463 LParenLoc, VarLoc, EndLoc);
2464 }
2465
2466 /// Build a new OpenMP 'destroy' clause.
2467 ///
2468 /// By default, performs semantic analysis to build the new OpenMP clause.
2469 /// Subclasses may override this routine to provide different behavior.
2471 SourceLocation LParenLoc,
2472 SourceLocation VarLoc,
2473 SourceLocation EndLoc) {
2475 InteropVar, StartLoc, LParenLoc, VarLoc, EndLoc);
2476 }
2477
2478 /// Build a new OpenMP 'novariants' clause.
2479 ///
2480 /// By default, performs semantic analysis to build the new OpenMP clause.
2481 /// Subclasses may override this routine to provide different behavior.
2483 SourceLocation StartLoc,
2484 SourceLocation LParenLoc,
2485 SourceLocation EndLoc) {
2487 LParenLoc, EndLoc);
2488 }
2489
2490 /// Build a new OpenMP 'nocontext' clause.
2491 ///
2492 /// By default, performs semantic analysis to build the new OpenMP clause.
2493 /// Subclasses may override this routine to provide different behavior.
2495 SourceLocation LParenLoc,
2496 SourceLocation EndLoc) {
2498 LParenLoc, EndLoc);
2499 }
2500
2501 /// Build a new OpenMP 'filter' clause.
2502 ///
2503 /// By default, performs semantic analysis to build the new OpenMP clause.
2504 /// Subclasses may override this routine to provide different behavior.
2506 SourceLocation LParenLoc,
2507 SourceLocation EndLoc) {
2508 return getSema().OpenMP().ActOnOpenMPFilterClause(ThreadID, StartLoc,
2509 LParenLoc, EndLoc);
2510 }
2511
2512 /// Build a new OpenMP 'bind' clause.
2513 ///
2514 /// By default, performs semantic analysis to build the new OpenMP clause.
2515 /// Subclasses may override this routine to provide different behavior.
2517 SourceLocation KindLoc,
2518 SourceLocation StartLoc,
2519 SourceLocation LParenLoc,
2520 SourceLocation EndLoc) {
2521 return getSema().OpenMP().ActOnOpenMPBindClause(Kind, KindLoc, StartLoc,
2522 LParenLoc, EndLoc);
2523 }
2524
2525 /// Build a new OpenMP 'ompx_dyn_cgroup_mem' clause.
2526 ///
2527 /// By default, performs semantic analysis to build the new OpenMP clause.
2528 /// Subclasses may override this routine to provide different behavior.
2530 SourceLocation LParenLoc,
2531 SourceLocation EndLoc) {
2532 return getSema().OpenMP().ActOnOpenMPXDynCGroupMemClause(Size, StartLoc,
2533 LParenLoc, EndLoc);
2534 }
2535
2536 /// Build a new OpenMP 'dyn_groupprivate' clause.
2537 ///
2538 /// By default, performs semantic analysis to build the new OpenMP clause.
2539 /// Subclasses may override this routine to provide different behavior.
2543 SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation M1Loc,
2544 SourceLocation M2Loc, SourceLocation EndLoc) {
2546 M1, M2, Size, StartLoc, LParenLoc, M1Loc, M2Loc, EndLoc);
2547 }
2548
2549 /// Build a new OpenMP 'ompx_attribute' clause.
2550 ///
2551 /// By default, performs semantic analysis to build the new OpenMP clause.
2552 /// Subclasses may override this routine to provide different behavior.
2554 SourceLocation StartLoc,
2555 SourceLocation LParenLoc,
2556 SourceLocation EndLoc) {
2557 return getSema().OpenMP().ActOnOpenMPXAttributeClause(Attrs, StartLoc,
2558 LParenLoc, EndLoc);
2559 }
2560
2561 /// Build a new OpenMP 'ompx_bare' clause.
2562 ///
2563 /// By default, performs semantic analysis to build the new OpenMP clause.
2564 /// Subclasses may override this routine to provide different behavior.
2566 SourceLocation EndLoc) {
2567 return getSema().OpenMP().ActOnOpenMPXBareClause(StartLoc, EndLoc);
2568 }
2569
2570 /// Build a new OpenMP 'align' clause.
2571 ///
2572 /// By default, performs semantic analysis to build the new OpenMP clause.
2573 /// Subclasses may override this routine to provide different behavior.
2575 SourceLocation LParenLoc,
2576 SourceLocation EndLoc) {
2577 return getSema().OpenMP().ActOnOpenMPAlignClause(A, StartLoc, LParenLoc,
2578 EndLoc);
2579 }
2580
2581 /// Build a new OpenMP 'at' clause.
2582 ///
2583 /// By default, performs semantic analysis to build the new OpenMP clause.
2584 /// Subclasses may override this routine to provide different behavior.
2586 SourceLocation StartLoc,
2587 SourceLocation LParenLoc,
2588 SourceLocation EndLoc) {
2589 return getSema().OpenMP().ActOnOpenMPAtClause(Kind, KwLoc, StartLoc,
2590 LParenLoc, EndLoc);
2591 }
2592
2593 /// Build a new OpenMP 'severity' clause.
2594 ///
2595 /// By default, performs semantic analysis to build the new OpenMP clause.
2596 /// Subclasses may override this routine to provide different behavior.
2598 SourceLocation KwLoc,
2599 SourceLocation StartLoc,
2600 SourceLocation LParenLoc,
2601 SourceLocation EndLoc) {
2602 return getSema().OpenMP().ActOnOpenMPSeverityClause(Kind, KwLoc, StartLoc,
2603 LParenLoc, EndLoc);
2604 }
2605
2606 /// Build a new OpenMP 'message' clause.
2607 ///
2608 /// By default, performs semantic analysis to build the new OpenMP clause.
2609 /// Subclasses may override this routine to provide different behavior.
2611 SourceLocation LParenLoc,
2612 SourceLocation EndLoc) {
2613 return getSema().OpenMP().ActOnOpenMPMessageClause(MS, StartLoc, LParenLoc,
2614 EndLoc);
2615 }
2616
2617 /// Build a new OpenMP 'doacross' clause.
2618 ///
2619 /// By default, performs semantic analysis to build the new OpenMP clause.
2620 /// Subclasses may override this routine to provide different behavior.
2621 OMPClause *
2623 SourceLocation DepLoc, SourceLocation ColonLoc,
2624 ArrayRef<Expr *> VarList, SourceLocation StartLoc,
2625 SourceLocation LParenLoc, SourceLocation EndLoc) {
2627 DepType, DepLoc, ColonLoc, VarList, StartLoc, LParenLoc, EndLoc);
2628 }
2629
2630 /// Build a new OpenMP 'holds' clause.
2632 SourceLocation LParenLoc,
2633 SourceLocation EndLoc) {
2634 return getSema().OpenMP().ActOnOpenMPHoldsClause(A, StartLoc, LParenLoc,
2635 EndLoc);
2636 }
2637
2638 /// Rebuild the operand to an Objective-C \@synchronized statement.
2639 ///
2640 /// By default, performs semantic analysis to build the new statement.
2641 /// Subclasses may override this routine to provide different behavior.
2646
2647 /// Build a new Objective-C \@synchronized statement.
2648 ///
2649 /// By default, performs semantic analysis to build the new statement.
2650 /// Subclasses may override this routine to provide different behavior.
2655
2656 /// Build a new Objective-C \@autoreleasepool statement.
2657 ///
2658 /// By default, performs semantic analysis to build the new statement.
2659 /// Subclasses may override this routine to provide different behavior.
2664
2665 /// Build a new Objective-C fast enumeration statement.
2666 ///
2667 /// By default, performs semantic analysis to build the new statement.
2668 /// Subclasses may override this routine to provide different behavior.
2670 Stmt *Element,
2671 Expr *Collection,
2672 SourceLocation RParenLoc,
2673 Stmt *Body) {
2675 ForLoc, Element, Collection, RParenLoc);
2676 if (ForEachStmt.isInvalid())
2677 return StmtError();
2678
2679 return getSema().ObjC().FinishObjCForCollectionStmt(ForEachStmt.get(),
2680 Body);
2681 }
2682
2683 /// Build a new C++ exception declaration.
2684 ///
2685 /// By default, performs semantic analysis to build the new decaration.
2686 /// Subclasses may override this routine to provide different behavior.
2689 SourceLocation StartLoc,
2690 SourceLocation IdLoc,
2691 IdentifierInfo *Id) {
2693 StartLoc, IdLoc, Id);
2694 if (Var)
2695 getSema().CurContext->addDecl(Var);
2696 return Var;
2697 }
2698
2699 /// Build a new C++ catch statement.
2700 ///
2701 /// By default, performs semantic analysis to build the new statement.
2702 /// Subclasses may override this routine to provide different behavior.
2704 VarDecl *ExceptionDecl,
2705 Stmt *Handler) {
2706 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
2707 Handler));
2708 }
2709
2710 /// Build a new C++ try statement.
2711 ///
2712 /// By default, performs semantic analysis to build the new statement.
2713 /// Subclasses may override this routine to provide different behavior.
2715 ArrayRef<Stmt *> Handlers) {
2716 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
2717 }
2718
2719 /// Build a new C++0x range-based for statement.
2720 ///
2721 /// By default, performs semantic analysis to build the new statement.
2722 /// Subclasses may override this routine to provide different behavior.
2724 SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *Init,
2725 SourceLocation ColonLoc, Stmt *Range, Stmt *Begin, Stmt *End, Expr *Cond,
2726 Expr *Inc, Stmt *LoopVar, SourceLocation RParenLoc,
2727 ArrayRef<MaterializeTemporaryExpr *> LifetimeExtendTemps) {
2728 // If we've just learned that the range is actually an Objective-C
2729 // collection, treat this as an Objective-C fast enumeration loop.
2730 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
2731 if (RangeStmt->isSingleDecl()) {
2732 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
2733 if (RangeVar->isInvalidDecl())
2734 return StmtError();
2735
2736 Expr *RangeExpr = RangeVar->getInit();
2737 if (!RangeExpr->isTypeDependent() &&
2738 RangeExpr->getType()->isObjCObjectPointerType()) {
2739 // FIXME: Support init-statements in Objective-C++20 ranged for
2740 // statement.
2741 if (Init) {
2742 return SemaRef.Diag(Init->getBeginLoc(),
2743 diag::err_objc_for_range_init_stmt)
2744 << Init->getSourceRange();
2745 }
2747 ForLoc, LoopVar, RangeExpr, RParenLoc);
2748 }
2749 }
2750 }
2751 }
2752
2754 ForLoc, CoawaitLoc, Init, ColonLoc, Range, Begin, End, Cond, Inc,
2755 LoopVar, RParenLoc, Sema::BFRK_Rebuild, LifetimeExtendTemps);
2756 }
2757
2758 /// Build a new C++0x range-based for statement.
2759 ///
2760 /// By default, performs semantic analysis to build the new statement.
2761 /// Subclasses may override this routine to provide different behavior.
2763 bool IsIfExists,
2764 NestedNameSpecifierLoc QualifierLoc,
2765 DeclarationNameInfo NameInfo,
2766 Stmt *Nested) {
2767 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
2768 QualifierLoc, NameInfo, Nested);
2769 }
2770
2771 /// Attach body to a C++0x range-based for statement.
2772 ///
2773 /// By default, performs semantic analysis to finish the new statement.
2774 /// Subclasses may override this routine to provide different behavior.
2776 return getSema().FinishCXXForRangeStmt(ForRange, Body);
2777 }
2778
2780 Stmt *TryBlock, Stmt *Handler) {
2781 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
2782 }
2783
2785 Stmt *Block) {
2786 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
2787 }
2788
2790 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
2791 }
2792
2794 SourceLocation LParen,
2795 SourceLocation RParen,
2796 TypeSourceInfo *TSI) {
2797 return getSema().SYCL().BuildUniqueStableNameExpr(OpLoc, LParen, RParen,
2798 TSI);
2799 }
2800
2801 /// Build a new predefined expression.
2802 ///
2803 /// By default, performs semantic analysis to build the new expression.
2804 /// Subclasses may override this routine to provide different behavior.
2808
2809 /// Build a new expression that references a declaration.
2810 ///
2811 /// By default, performs semantic analysis to build the new expression.
2812 /// Subclasses may override this routine to provide different behavior.
2814 LookupResult &R,
2815 bool RequiresADL) {
2816 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
2817 }
2818
2819
2820 /// Build a new expression that references a declaration.
2821 ///
2822 /// By default, performs semantic analysis to build the new expression.
2823 /// Subclasses may override this routine to provide different behavior.
2825 ValueDecl *VD,
2826 const DeclarationNameInfo &NameInfo,
2828 TemplateArgumentListInfo *TemplateArgs) {
2829 CXXScopeSpec SS;
2830 SS.Adopt(QualifierLoc);
2831 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found,
2832 TemplateArgs);
2833 }
2834
2835 /// Build a new expression in parentheses.
2836 ///
2837 /// By default, performs semantic analysis to build the new expression.
2838 /// Subclasses may override this routine to provide different behavior.
2840 SourceLocation RParen) {
2841 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
2842 }
2843
2844 /// Build a new pseudo-destructor expression.
2845 ///
2846 /// By default, performs semantic analysis to build the new expression.
2847 /// Subclasses may override this routine to provide different behavior.
2849 SourceLocation OperatorLoc,
2850 bool isArrow,
2851 CXXScopeSpec &SS,
2852 TypeSourceInfo *ScopeType,
2853 SourceLocation CCLoc,
2854 SourceLocation TildeLoc,
2855 PseudoDestructorTypeStorage Destroyed);
2856
2857 /// Build a new unary operator expression.
2858 ///
2859 /// By default, performs semantic analysis to build the new expression.
2860 /// Subclasses may override this routine to provide different behavior.
2863 Expr *SubExpr) {
2864 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
2865 }
2866
2867 /// Build a new builtin offsetof expression.
2868 ///
2869 /// By default, performs semantic analysis to build the new expression.
2870 /// Subclasses may override this routine to provide different behavior.
2872 TypeSourceInfo *Type, const Designation &Desig,
2873 SourceLocation RParenLoc) {
2874 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Desig, RParenLoc);
2875 }
2876
2877 /// Build a new sizeof, alignof or vec_step expression with a
2878 /// type argument.
2879 ///
2880 /// By default, performs semantic analysis to build the new expression.
2881 /// Subclasses may override this routine to provide different behavior.
2883 SourceLocation OpLoc,
2884 UnaryExprOrTypeTrait ExprKind,
2885 SourceRange R) {
2886 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
2887 }
2888
2889 /// Build a new sizeof, alignof or vec step expression with an
2890 /// expression argument.
2891 ///
2892 /// By default, performs semantic analysis to build the new expression.
2893 /// Subclasses may override this routine to provide different behavior.
2895 UnaryExprOrTypeTrait ExprKind,
2896 SourceRange R) {
2898 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
2899 if (Result.isInvalid())
2900 return ExprError();
2901
2902 return Result;
2903 }
2904
2905 /// Build a new array subscript expression.
2906 ///
2907 /// By default, performs semantic analysis to build the new expression.
2908 /// Subclasses may override this routine to provide different behavior.
2910 SourceLocation LBracketLoc,
2911 Expr *RHS,
2912 SourceLocation RBracketLoc) {
2913 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
2914 LBracketLoc, RHS,
2915 RBracketLoc);
2916 }
2917
2918 /// Build a new matrix single subscript expression.
2919 ///
2920 /// By default, performs semantic analysis to build the new expression.
2921 /// Subclasses may override this routine to provide different behavior.
2923 SourceLocation RBracketLoc) {
2925 RBracketLoc);
2926 }
2927
2928 /// Build a new matrix subscript expression.
2929 ///
2930 /// By default, performs semantic analysis to build the new expression.
2931 /// Subclasses may override this routine to provide different behavior.
2933 Expr *ColumnIdx,
2934 SourceLocation RBracketLoc) {
2935 return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx,
2936 RBracketLoc);
2937 }
2938
2939 /// Build a new array section expression.
2940 ///
2941 /// By default, performs semantic analysis to build the new expression.
2942 /// Subclasses may override this routine to provide different behavior.
2944 SourceLocation LBracketLoc,
2945 Expr *LowerBound,
2946 SourceLocation ColonLocFirst,
2947 SourceLocation ColonLocSecond,
2948 Expr *Length, Expr *Stride,
2949 SourceLocation RBracketLoc) {
2950 if (IsOMPArraySection)
2952 Base, LBracketLoc, LowerBound, ColonLocFirst, ColonLocSecond, Length,
2953 Stride, RBracketLoc);
2954
2955 assert(Stride == nullptr && !ColonLocSecond.isValid() &&
2956 "Stride/second colon not allowed for OpenACC");
2957
2959 Base, LBracketLoc, LowerBound, ColonLocFirst, Length, RBracketLoc);
2960 }
2961
2962 /// Build a new array shaping expression.
2963 ///
2964 /// By default, performs semantic analysis to build the new expression.
2965 /// Subclasses may override this routine to provide different behavior.
2967 SourceLocation RParenLoc,
2968 ArrayRef<Expr *> Dims,
2969 ArrayRef<SourceRange> BracketsRanges) {
2971 Base, LParenLoc, RParenLoc, Dims, BracketsRanges);
2972 }
2973
2974 /// Build a new iterator expression.
2975 ///
2976 /// By default, performs semantic analysis to build the new expression.
2977 /// Subclasses may override this routine to provide different behavior.
2980 SourceLocation RLoc,
2983 /*Scope=*/nullptr, IteratorKwLoc, LLoc, RLoc, Data);
2984 }
2985
2986 /// Build a new call expression.
2987 ///
2988 /// By default, performs semantic analysis to build the new expression.
2989 /// Subclasses may override this routine to provide different behavior.
2991 MultiExprArg Args,
2992 SourceLocation RParenLoc,
2993 Expr *ExecConfig = nullptr) {
2994 return getSema().ActOnCallExpr(
2995 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig);
2996 }
2997
2999 MultiExprArg Args,
3000 SourceLocation RParenLoc) {
3002 /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc);
3003 }
3004
3005 /// Build a new member access expression.
3006 ///
3007 /// By default, performs semantic analysis to build the new expression.
3008 /// Subclasses may override this routine to provide different behavior.
3010 bool isArrow,
3011 NestedNameSpecifierLoc QualifierLoc,
3012 SourceLocation TemplateKWLoc,
3013 const DeclarationNameInfo &MemberNameInfo,
3015 NamedDecl *FoundDecl,
3016 const TemplateArgumentListInfo *ExplicitTemplateArgs,
3017 NamedDecl *FirstQualifierInScope) {
3019 isArrow);
3020 if (!Member->getDeclName()) {
3021 // We have a reference to an unnamed field. This is always the
3022 // base of an anonymous struct/union member access, i.e. the
3023 // field is always of record type.
3024 assert(Member->getType()->isRecordType() &&
3025 "unnamed member not of record type?");
3026
3027 BaseResult =
3029 QualifierLoc.getNestedNameSpecifier(),
3030 FoundDecl, Member);
3031 if (BaseResult.isInvalid())
3032 return ExprError();
3033 Base = BaseResult.get();
3034
3035 // `TranformMaterializeTemporaryExpr()` removes materialized temporaries
3036 // from the AST, so we need to re-insert them if needed (since
3037 // `BuildFieldRefereneExpr()` doesn't do this).
3038 if (!isArrow && Base->isPRValue()) {
3040 if (BaseResult.isInvalid())
3041 return ExprError();
3042 Base = BaseResult.get();
3043 }
3044
3045 CXXScopeSpec EmptySS;
3047 Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member),
3048 DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()),
3049 MemberNameInfo);
3050 }
3051
3052 CXXScopeSpec SS;
3053 SS.Adopt(QualifierLoc);
3054
3055 Base = BaseResult.get();
3056 if (Base->containsErrors())
3057 return ExprError();
3058
3059 QualType BaseType = Base->getType();
3060
3061 if (isArrow && !BaseType->isPointerType())
3062 return ExprError();
3063
3064 // FIXME: this involves duplicating earlier analysis in a lot of
3065 // cases; we should avoid this when possible.
3066 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
3067 R.addDecl(FoundDecl);
3068 R.resolveKind();
3069
3070 if (getSema().isUnevaluatedContext() && Base->isImplicitCXXThis() &&
3072 if (auto *ThisClass = cast<CXXThisExpr>(Base)
3073 ->getType()
3074 ->getPointeeType()
3075 ->getAsCXXRecordDecl()) {
3076 auto *Class = cast<CXXRecordDecl>(Member->getDeclContext());
3077 // In unevaluated contexts, an expression supposed to be a member access
3078 // might reference a member in an unrelated class.
3079 if (!ThisClass->Equals(Class) && !ThisClass->isDerivedFrom(Class))
3080 return getSema().BuildDeclRefExpr(Member, Member->getType(),
3081 VK_LValue, Member->getLocation());
3082 }
3083 }
3084
3085 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
3086 SS, TemplateKWLoc,
3087 FirstQualifierInScope,
3088 R, ExplicitTemplateArgs,
3089 /*S*/nullptr);
3090 }
3091
3092 /// Build a new binary operator expression.
3093 ///
3094 /// By default, performs semantic analysis to build the new expression.
3095 /// Subclasses may override this routine to provide different behavior.
3097 Expr *LHS, Expr *RHS,
3098 bool ForFoldExpression = false) {
3099 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS,
3100 ForFoldExpression);
3101 }
3102
3103 /// Build a new rewritten operator expression.
3104 ///
3105 /// By default, performs semantic analysis to build the new expression.
3106 /// Subclasses may override this routine to provide different behavior.
3108 SourceLocation OpLoc, BinaryOperatorKind Opcode,
3109 const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) {
3110 return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS,
3111 RHS, /*RequiresADL*/false);
3112 }
3113
3114 /// Build a new conditional operator expression.
3115 ///
3116 /// By default, performs semantic analysis to build the new expression.
3117 /// Subclasses may override this routine to provide different behavior.
3119 SourceLocation QuestionLoc,
3120 Expr *LHS,
3121 SourceLocation ColonLoc,
3122 Expr *RHS) {
3123 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
3124 LHS, RHS);
3125 }
3126
3127 /// Build a new C-style cast expression.
3128 ///
3129 /// By default, performs semantic analysis to build the new expression.
3130 /// Subclasses may override this routine to provide different behavior.
3132 TypeSourceInfo *TInfo,
3133 SourceLocation RParenLoc,
3134 Expr *SubExpr) {
3135 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
3136 SubExpr);
3137 }
3138
3139 /// Build a new compound literal expression.
3140 ///
3141 /// By default, performs semantic analysis to build the new expression.
3142 /// Subclasses may override this routine to provide different behavior.
3144 TypeSourceInfo *TInfo,
3145 SourceLocation RParenLoc,
3146 Expr *Init) {
3147 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
3148 Init);
3149 }
3150
3151 /// Build a new extended vector or matrix element access expression.
3152 ///
3153 /// By default, performs semantic analysis to build the new expression.
3154 /// Subclasses may override this routine to provide different behavior.
3156 SourceLocation OpLoc,
3157 bool IsArrow,
3158 SourceLocation AccessorLoc,
3159 IdentifierInfo &Accessor) {
3160
3161 CXXScopeSpec SS;
3162 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
3164 Base, Base->getType(), OpLoc, IsArrow, SS, SourceLocation(),
3165 /*FirstQualifierInScope*/ nullptr, NameInfo,
3166 /* TemplateArgs */ nullptr,
3167 /*S*/ nullptr);
3168 }
3169
3170 /// Build a new initializer list expression.
3171 ///
3172 /// By default, performs semantic analysis to build the new expression.
3173 /// Subclasses may override this routine to provide different behavior.
3175 SourceLocation RBraceLoc, bool IsExplicit) {
3176 return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc, IsExplicit);
3177 }
3178
3179 /// Build a new designated initializer expression.
3180 ///
3181 /// By default, performs semantic analysis to build the new expression.
3182 /// Subclasses may override this routine to provide different behavior.
3184 MultiExprArg ArrayExprs,
3185 SourceLocation EqualOrColonLoc,
3186 bool GNUSyntax,
3187 Expr *Init) {
3189 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
3190 Init);
3191 if (Result.isInvalid())
3192 return ExprError();
3193
3194 return Result;
3195 }
3196
3197 /// Build a new value-initialized expression.
3198 ///
3199 /// By default, builds the implicit value initialization without performing
3200 /// any semantic analysis. Subclasses may override this routine to provide
3201 /// different behavior.
3205
3206 /// Build a new \c va_arg expression.
3207 ///
3208 /// By default, performs semantic analysis to build the new expression.
3209 /// Subclasses may override this routine to provide different behavior.
3211 Expr *SubExpr, TypeSourceInfo *TInfo,
3212 SourceLocation RParenLoc) {
3213 return getSema().BuildVAArgExpr(BuiltinLoc,
3214 SubExpr, TInfo,
3215 RParenLoc);
3216 }
3217
3218 /// Build a new expression list in parentheses.
3219 ///
3220 /// By default, performs semantic analysis to build the new expression.
3221 /// Subclasses may override this routine to provide different behavior.
3223 MultiExprArg SubExprs,
3224 SourceLocation RParenLoc) {
3225 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
3226 }
3227
3229 unsigned NumUserSpecifiedExprs,
3230 SourceLocation InitLoc,
3231 SourceLocation LParenLoc,
3232 SourceLocation RParenLoc) {
3233 return getSema().ActOnCXXParenListInitExpr(Args, T, NumUserSpecifiedExprs,
3234 InitLoc, LParenLoc, RParenLoc);
3235 }
3236
3237 /// Build a new address-of-label expression.
3238 ///
3239 /// By default, performs semantic analysis, using the name of the label
3240 /// rather than attempting to map the label statement itself.
3241 /// Subclasses may override this routine to provide different behavior.
3243 SourceLocation LabelLoc, LabelDecl *Label) {
3244 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
3245 }
3246
3247 /// Build a new GNU statement expression.
3248 ///
3249 /// By default, performs semantic analysis to build the new expression.
3250 /// Subclasses may override this routine to provide different behavior.
3252 SourceLocation RParenLoc, unsigned TemplateDepth) {
3253 return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc,
3254 TemplateDepth);
3255 }
3256
3257 /// Build a new __builtin_choose_expr expression.
3258 ///
3259 /// By default, performs semantic analysis to build the new expression.
3260 /// Subclasses may override this routine to provide different behavior.
3262 Expr *Cond, Expr *LHS, Expr *RHS,
3263 SourceLocation RParenLoc) {
3264 return SemaRef.ActOnChooseExpr(BuiltinLoc,
3265 Cond, LHS, RHS,
3266 RParenLoc);
3267 }
3268
3269 /// Build a new generic selection expression with an expression predicate.
3270 ///
3271 /// By default, performs semantic analysis to build the new expression.
3272 /// Subclasses may override this routine to provide different behavior.
3274 SourceLocation DefaultLoc,
3275 SourceLocation RParenLoc,
3276 Expr *ControllingExpr,
3278 ArrayRef<Expr *> Exprs) {
3279 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3280 /*PredicateIsExpr=*/true,
3281 ControllingExpr, Types, Exprs);
3282 }
3283
3284 /// Build a new generic selection expression with a type predicate.
3285 ///
3286 /// By default, performs semantic analysis to build the new expression.
3287 /// Subclasses may override this routine to provide different behavior.
3289 SourceLocation DefaultLoc,
3290 SourceLocation RParenLoc,
3291 TypeSourceInfo *ControllingType,
3293 ArrayRef<Expr *> Exprs) {
3294 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
3295 /*PredicateIsExpr=*/false,
3296 ControllingType, Types, Exprs);
3297 }
3298
3299 /// Build a new overloaded operator call expression.
3300 ///
3301 /// By default, performs semantic analysis to build the new expression.
3302 /// The semantic analysis provides the behavior of template instantiation,
3303 /// copying with transformations that turn what looks like an overloaded
3304 /// operator call into a use of a builtin operator, performing
3305 /// argument-dependent lookup, etc. Subclasses may override this routine to
3306 /// provide different behavior.
3308 SourceLocation OpLoc,
3309 SourceLocation CalleeLoc,
3310 bool RequiresADL,
3311 const UnresolvedSetImpl &Functions,
3312 Expr *First, Expr *Second);
3313
3314 /// Build a new C++ "named" cast expression, such as static_cast or
3315 /// reinterpret_cast.
3316 ///
3317 /// By default, this routine dispatches to one of the more-specific routines
3318 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
3319 /// Subclasses may override this routine to provide different behavior.
3322 SourceLocation LAngleLoc,
3323 TypeSourceInfo *TInfo,
3324 SourceLocation RAngleLoc,
3325 SourceLocation LParenLoc,
3326 Expr *SubExpr,
3327 SourceLocation RParenLoc) {
3328 switch (Class) {
3329 case Stmt::CXXStaticCastExprClass:
3330 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
3331 RAngleLoc, LParenLoc,
3332 SubExpr, RParenLoc);
3333
3334 case Stmt::CXXDynamicCastExprClass:
3335 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
3336 RAngleLoc, LParenLoc,
3337 SubExpr, RParenLoc);
3338
3339 case Stmt::CXXReinterpretCastExprClass:
3340 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
3341 RAngleLoc, LParenLoc,
3342 SubExpr,
3343 RParenLoc);
3344
3345 case Stmt::CXXConstCastExprClass:
3346 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
3347 RAngleLoc, LParenLoc,
3348 SubExpr, RParenLoc);
3349
3350 case Stmt::CXXAddrspaceCastExprClass:
3351 return getDerived().RebuildCXXAddrspaceCastExpr(
3352 OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc);
3353
3354 default:
3355 llvm_unreachable("Invalid C++ named cast");
3356 }
3357 }
3358
3359 /// Build a new C++ static_cast expression.
3360 ///
3361 /// By default, performs semantic analysis to build the new expression.
3362 /// Subclasses may override this routine to provide different behavior.
3364 SourceLocation LAngleLoc,
3365 TypeSourceInfo *TInfo,
3366 SourceLocation RAngleLoc,
3367 SourceLocation LParenLoc,
3368 Expr *SubExpr,
3369 SourceLocation RParenLoc) {
3370 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
3371 TInfo, SubExpr,
3372 SourceRange(LAngleLoc, RAngleLoc),
3373 SourceRange(LParenLoc, RParenLoc));
3374 }
3375
3376 /// Build a new C++ dynamic_cast expression.
3377 ///
3378 /// By default, performs semantic analysis to build the new expression.
3379 /// Subclasses may override this routine to provide different behavior.
3381 SourceLocation LAngleLoc,
3382 TypeSourceInfo *TInfo,
3383 SourceLocation RAngleLoc,
3384 SourceLocation LParenLoc,
3385 Expr *SubExpr,
3386 SourceLocation RParenLoc) {
3387 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
3388 TInfo, SubExpr,
3389 SourceRange(LAngleLoc, RAngleLoc),
3390 SourceRange(LParenLoc, RParenLoc));
3391 }
3392
3393 /// Build a new C++ reinterpret_cast expression.
3394 ///
3395 /// By default, performs semantic analysis to build the new expression.
3396 /// Subclasses may override this routine to provide different behavior.
3398 SourceLocation LAngleLoc,
3399 TypeSourceInfo *TInfo,
3400 SourceLocation RAngleLoc,
3401 SourceLocation LParenLoc,
3402 Expr *SubExpr,
3403 SourceLocation RParenLoc) {
3404 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
3405 TInfo, SubExpr,
3406 SourceRange(LAngleLoc, RAngleLoc),
3407 SourceRange(LParenLoc, RParenLoc));
3408 }
3409
3410 /// Build a new C++ const_cast expression.
3411 ///
3412 /// By default, performs semantic analysis to build the new expression.
3413 /// Subclasses may override this routine to provide different behavior.
3415 SourceLocation LAngleLoc,
3416 TypeSourceInfo *TInfo,
3417 SourceLocation RAngleLoc,
3418 SourceLocation LParenLoc,
3419 Expr *SubExpr,
3420 SourceLocation RParenLoc) {
3421 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
3422 TInfo, SubExpr,
3423 SourceRange(LAngleLoc, RAngleLoc),
3424 SourceRange(LParenLoc, RParenLoc));
3425 }
3426
3429 TypeSourceInfo *TInfo, SourceLocation RAngleLoc,
3430 SourceLocation LParenLoc, Expr *SubExpr,
3431 SourceLocation RParenLoc) {
3432 return getSema().BuildCXXNamedCast(
3433 OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr,
3434 SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc));
3435 }
3436
3437 /// Build a new C++ functional-style cast expression.
3438 ///
3439 /// By default, performs semantic analysis to build the new expression.
3440 /// Subclasses may override this routine to provide different behavior.
3442 SourceLocation LParenLoc,
3443 Expr *Sub,
3444 SourceLocation RParenLoc,
3445 bool ListInitialization) {
3446 // If Sub is a ParenListExpr, then Sub is the syntatic form of a
3447 // CXXParenListInitExpr. Pass its expanded arguments so that the
3448 // CXXParenListInitExpr can be rebuilt.
3449 if (auto *PLE = dyn_cast<ParenListExpr>(Sub))
3451 TInfo, LParenLoc, MultiExprArg(PLE->getExprs(), PLE->getNumExprs()),
3452 RParenLoc, ListInitialization);
3453
3454 if (auto *PLE = dyn_cast<CXXParenListInitExpr>(Sub))
3456 TInfo, LParenLoc, PLE->getUserSpecifiedInitExprs(), RParenLoc,
3457 ListInitialization);
3458
3459 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
3460 MultiExprArg(&Sub, 1), RParenLoc,
3461 ListInitialization);
3462 }
3463
3464 /// Build a new C++ __builtin_bit_cast expression.
3465 ///
3466 /// By default, performs semantic analysis to build the new expression.
3467 /// Subclasses may override this routine to provide different behavior.
3469 TypeSourceInfo *TSI, Expr *Sub,
3470 SourceLocation RParenLoc) {
3471 return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc);
3472 }
3473
3474 /// Build a new C++ typeid(type) expression.
3475 ///
3476 /// By default, performs semantic analysis to build the new expression.
3477 /// Subclasses may override this routine to provide different behavior.
3479 SourceLocation TypeidLoc,
3480 TypeSourceInfo *Operand,
3481 SourceLocation RParenLoc) {
3482 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3483 RParenLoc);
3484 }
3485
3486
3487 /// Build a new C++ typeid(expr) expression.
3488 ///
3489 /// By default, performs semantic analysis to build the new expression.
3490 /// Subclasses may override this routine to provide different behavior.
3492 SourceLocation TypeidLoc,
3493 Expr *Operand,
3494 SourceLocation RParenLoc) {
3495 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
3496 RParenLoc);
3497 }
3498
3499 /// Build a new C++ __uuidof(type) expression.
3500 ///
3501 /// By default, performs semantic analysis to build the new expression.
3502 /// Subclasses may override this routine to provide different behavior.
3504 TypeSourceInfo *Operand,
3505 SourceLocation RParenLoc) {
3506 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3507 }
3508
3509 /// Build a new C++ __uuidof(expr) expression.
3510 ///
3511 /// By default, performs semantic analysis to build the new expression.
3512 /// Subclasses may override this routine to provide different behavior.
3514 Expr *Operand, SourceLocation RParenLoc) {
3515 return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc);
3516 }
3517
3518 /// Build a new C++ "this" expression.
3519 ///
3520 /// By default, performs semantic analysis to build a new "this" expression.
3521 /// Subclasses may override this routine to provide different behavior.
3523 QualType ThisType,
3524 bool isImplicit) {
3525 if (getSema().CheckCXXThisType(ThisLoc, ThisType))
3526 return ExprError();
3527 return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit);
3528 }
3529
3530 /// Build a new C++ throw expression.
3531 ///
3532 /// By default, performs semantic analysis to build the new expression.
3533 /// Subclasses may override this routine to provide different behavior.
3535 bool IsThrownVariableInScope) {
3536 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
3537 }
3538
3539 /// Build a new C++ default-argument expression.
3540 ///
3541 /// By default, builds a new default-argument expression, which does not
3542 /// require any semantic analysis. Subclasses may override this routine to
3543 /// provide different behavior.
3545 Expr *RewrittenExpr) {
3546 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param,
3547 RewrittenExpr, getSema().CurContext);
3548 }
3549
3550 /// Build a new C++11 default-initialization expression.
3551 ///
3552 /// By default, builds a new default field initialization expression, which
3553 /// does not require any semantic analysis. Subclasses may override this
3554 /// routine to provide different behavior.
3556 Expr *RewrittenInit) {
3557 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field,
3558 getSema().CurContext, RewrittenInit);
3559 }
3560
3561 /// Build a new C++ zero-initialization expression.
3562 ///
3563 /// By default, performs semantic analysis to build the new expression.
3564 /// Subclasses may override this routine to provide different behavior.
3566 SourceLocation LParenLoc,
3567 SourceLocation RParenLoc) {
3568 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, {}, RParenLoc,
3569 /*ListInitialization=*/false);
3570 }
3571
3572 /// Build a new C++ "new" expression.
3573 ///
3574 /// By default, performs semantic analysis to build the new expression.
3575 /// Subclasses may override this routine to provide different behavior.
3577 SourceLocation PlacementLParen,
3578 MultiExprArg PlacementArgs,
3579 SourceLocation PlacementRParen,
3580 SourceRange TypeIdParens, QualType AllocatedType,
3581 TypeSourceInfo *AllocatedTypeInfo,
3582 std::optional<Expr *> ArraySize,
3583 SourceRange DirectInitRange, Expr *Initializer) {
3584 return getSema().BuildCXXNew(StartLoc, UseGlobal,
3585 PlacementLParen,
3586 PlacementArgs,
3587 PlacementRParen,
3588 TypeIdParens,
3589 AllocatedType,
3590 AllocatedTypeInfo,
3591 ArraySize,
3592 DirectInitRange,
3593 Initializer);
3594 }
3595
3596 /// Build a new C++ "delete" expression.
3597 ///
3598 /// By default, performs semantic analysis to build the new expression.
3599 /// Subclasses may override this routine to provide different behavior.
3601 bool IsGlobalDelete,
3602 bool IsArrayForm,
3603 Expr *Operand) {
3604 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
3605 Operand);
3606 }
3607
3608 /// Build a new type trait expression.
3609 ///
3610 /// By default, performs semantic analysis to build the new expression.
3611 /// Subclasses may override this routine to provide different behavior.
3613 SourceLocation StartLoc,
3615 SourceLocation RParenLoc) {
3616 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
3617 }
3618
3619 /// Build a new array type trait expression.
3620 ///
3621 /// By default, performs semantic analysis to build the new expression.
3622 /// Subclasses may override this routine to provide different behavior.
3623 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
3624 SourceLocation StartLoc,
3625 TypeSourceInfo *TSInfo,
3626 Expr *DimExpr,
3627 SourceLocation RParenLoc) {
3628 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
3629 }
3630
3631 /// Build a new expression trait expression.
3632 ///
3633 /// By default, performs semantic analysis to build the new expression.
3634 /// Subclasses may override this routine to provide different behavior.
3635 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
3636 SourceLocation StartLoc,
3637 Expr *Queried,
3638 SourceLocation RParenLoc) {
3639 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
3640 }
3641
3642 /// Build a new (previously unresolved) declaration reference
3643 /// expression.
3644 ///
3645 /// By default, performs semantic analysis to build the new expression.
3646 /// Subclasses may override this routine to provide different behavior.
3648 NestedNameSpecifierLoc QualifierLoc,
3649 SourceLocation TemplateKWLoc,
3650 const DeclarationNameInfo &NameInfo,
3651 const TemplateArgumentListInfo *TemplateArgs,
3652 bool IsAddressOfOperand,
3653 TypeSourceInfo **RecoveryTSI) {
3654 CXXScopeSpec SS;
3655 SS.Adopt(QualifierLoc);
3656
3657 if (TemplateArgs || TemplateKWLoc.isValid())
3659 SS, TemplateKWLoc, NameInfo, TemplateArgs, IsAddressOfOperand);
3660
3662 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
3663 }
3664
3665 /// Build a new template-id expression.
3666 ///
3667 /// By default, performs semantic analysis to build the new expression.
3668 /// Subclasses may override this routine to provide different behavior.
3670 SourceLocation TemplateKWLoc,
3671 LookupResult &R,
3672 bool RequiresADL,
3673 const TemplateArgumentListInfo *TemplateArgs) {
3674 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
3675 TemplateArgs);
3676 }
3677
3678 /// Build a new object-construction expression.
3679 ///
3680 /// By default, performs semantic analysis to build the new expression.
3681 /// Subclasses may override this routine to provide different behavior.
3684 bool IsElidable, MultiExprArg Args, bool HadMultipleCandidates,
3685 bool ListInitialization, bool StdInitListInitialization,
3686 bool RequiresZeroInit, CXXConstructionKind ConstructKind,
3687 SourceRange ParenRange) {
3688 // Reconstruct the constructor we originally found, which might be
3689 // different if this is a call to an inherited constructor.
3690 CXXConstructorDecl *FoundCtor = Constructor;
3691 if (Constructor->isInheritingConstructor())
3692 FoundCtor = Constructor->getInheritedConstructor().getConstructor();
3693
3694 SmallVector<Expr *, 8> ConvertedArgs;
3695 if (getSema().CompleteConstructorCall(FoundCtor, T, Args, Loc,
3696 ConvertedArgs))
3697 return ExprError();
3698
3700 IsElidable,
3701 ConvertedArgs,
3702 HadMultipleCandidates,
3703 ListInitialization,
3704 StdInitListInitialization,
3705 RequiresZeroInit, ConstructKind,
3706 ParenRange);
3707 }
3708
3709 /// Build a new implicit construction via inherited constructor
3710 /// expression.
3713 bool ConstructsVBase,
3714 bool InheritedFromVBase) {
3716 Loc, T, Constructor, ConstructsVBase, InheritedFromVBase);
3717 }
3718
3719 /// Build a new object-construction expression.
3720 ///
3721 /// By default, performs semantic analysis to build the new expression.
3722 /// Subclasses may override this routine to provide different behavior.
3724 SourceLocation LParenOrBraceLoc,
3725 MultiExprArg Args,
3726 SourceLocation RParenOrBraceLoc,
3727 bool ListInitialization) {
3729 TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization);
3730 }
3731
3732 /// Build a new object-construction expression.
3733 ///
3734 /// By default, performs semantic analysis to build the new expression.
3735 /// Subclasses may override this routine to provide different behavior.
3737 SourceLocation LParenLoc,
3738 MultiExprArg Args,
3739 SourceLocation RParenLoc,
3740 bool ListInitialization) {
3741 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args,
3742 RParenLoc, ListInitialization);
3743 }
3744
3745 /// Build a new member reference expression.
3746 ///
3747 /// By default, performs semantic analysis to build the new expression.
3748 /// Subclasses may override this routine to provide different behavior.
3750 QualType BaseType,
3751 bool IsArrow,
3752 SourceLocation OperatorLoc,
3753 NestedNameSpecifierLoc QualifierLoc,
3754 SourceLocation TemplateKWLoc,
3755 NamedDecl *FirstQualifierInScope,
3756 const DeclarationNameInfo &MemberNameInfo,
3757 const TemplateArgumentListInfo *TemplateArgs) {
3758 CXXScopeSpec SS;
3759 SS.Adopt(QualifierLoc);
3760
3761 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3762 OperatorLoc, IsArrow,
3763 SS, TemplateKWLoc,
3764 FirstQualifierInScope,
3765 MemberNameInfo,
3766 TemplateArgs, /*S*/nullptr);
3767 }
3768
3769 /// Build a new member reference expression.
3770 ///
3771 /// By default, performs semantic analysis to build the new expression.
3772 /// Subclasses may override this routine to provide different behavior.
3774 SourceLocation OperatorLoc,
3775 bool IsArrow,
3776 NestedNameSpecifierLoc QualifierLoc,
3777 SourceLocation TemplateKWLoc,
3778 NamedDecl *FirstQualifierInScope,
3779 LookupResult &R,
3780 const TemplateArgumentListInfo *TemplateArgs) {
3781 CXXScopeSpec SS;
3782 SS.Adopt(QualifierLoc);
3783
3784 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
3785 OperatorLoc, IsArrow,
3786 SS, TemplateKWLoc,
3787 FirstQualifierInScope,
3788 R, TemplateArgs, /*S*/nullptr);
3789 }
3790
3791 /// Build a new noexcept expression.
3792 ///
3793 /// By default, performs semantic analysis to build the new expression.
3794 /// Subclasses may override this routine to provide different behavior.
3796 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
3797 }
3798
3801
3802 /// Build a new expression to compute the length of a parameter pack.
3804 SourceLocation PackLoc,
3805 SourceLocation RParenLoc,
3806 UnsignedOrNone Length,
3807 ArrayRef<TemplateArgument> PartialArgs) {
3808 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
3809 RParenLoc, Length, PartialArgs);
3810 }
3811
3813 SourceLocation RSquareLoc,
3814 Expr *PackIdExpression, Expr *IndexExpr,
3815 ArrayRef<Expr *> ExpandedExprs,
3816 bool FullySubstituted = false) {
3817 return getSema().BuildPackIndexingExpr(PackIdExpression, EllipsisLoc,
3818 IndexExpr, RSquareLoc, ExpandedExprs,
3819 FullySubstituted);
3820 }
3821
3822 /// Build a new expression representing a call to a source location
3823 /// builtin.
3824 ///
3825 /// By default, performs semantic analysis to build the new expression.
3826 /// Subclasses may override this routine to provide different behavior.
3828 SourceLocation BuiltinLoc,
3829 SourceLocation RPLoc,
3830 DeclContext *ParentContext) {
3831 return getSema().BuildSourceLocExpr(Kind, ResultTy, BuiltinLoc, RPLoc,
3832 ParentContext);
3833 }
3834
3836 SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo,
3837 NamedDecl *FoundDecl, ConceptDecl *NamedConcept,
3839 CXXScopeSpec SS;
3840 SS.Adopt(NNS);
3841 ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc,
3842 ConceptNameInfo,
3843 FoundDecl,
3844 NamedConcept, TALI);
3845 if (Result.isInvalid())
3846 return ExprError();
3847 return Result;
3848 }
3849
3850 /// \brief Build a new requires expression.
3851 ///
3852 /// By default, performs semantic analysis to build the new expression.
3853 /// Subclasses may override this routine to provide different behavior.
3856 SourceLocation LParenLoc,
3857 ArrayRef<ParmVarDecl *> LocalParameters,
3858 SourceLocation RParenLoc,
3860 SourceLocation ClosingBraceLoc) {
3861 return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, LParenLoc,
3862 LocalParameters, RParenLoc, Requirements,
3863 ClosingBraceLoc);
3864 }
3865
3869 return SemaRef.BuildTypeRequirement(SubstDiag);
3870 }
3871
3873 return SemaRef.BuildTypeRequirement(T);
3874 }
3875
3878 concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple,
3879 SourceLocation NoexceptLoc,
3881 return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc,
3882 std::move(Ret));
3883 }
3884
3886 RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc,
3888 return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc,
3889 std::move(Ret));
3890 }
3891
3893 RebuildNestedRequirement(StringRef InvalidConstraintEntity,
3894 const ASTConstraintSatisfaction &Satisfaction) {
3895 return new (getSema().Context)
3896 concepts::NestedRequirement(InvalidConstraintEntity, &Satisfaction);
3897 }
3898
3900 return SemaRef.BuildNestedRequirement(Constraint);
3901 }
3902
3903 /// \brief Build a new Objective-C boxed expression.
3904 ///
3905 /// By default, performs semantic analysis to build the new expression.
3906 /// Subclasses may override this routine to provide different behavior.
3908 return getSema().ObjC().BuildObjCBoxedExpr(SR, ValueExpr);
3909 }
3910
3911 /// Build a new Objective-C array literal.
3912 ///
3913 /// By default, performs semantic analysis to build the new expression.
3914 /// Subclasses may override this routine to provide different behavior.
3916 Expr **Elements, unsigned NumElements) {
3918 Range, MultiExprArg(Elements, NumElements));
3919 }
3920
3922 Expr *Base, Expr *Key,
3923 ObjCMethodDecl *getterMethod,
3924 ObjCMethodDecl *setterMethod) {
3926 RB, Base, Key, getterMethod, setterMethod);
3927 }
3928
3929 /// Build a new Objective-C dictionary literal.
3930 ///
3931 /// By default, performs semantic analysis to build the new expression.
3932 /// Subclasses may override this routine to provide different behavior.
3937
3938 /// Build a new Objective-C \@encode expression.
3939 ///
3940 /// By default, performs semantic analysis to build the new expression.
3941 /// Subclasses may override this routine to provide different behavior.
3943 TypeSourceInfo *EncodeTypeInfo,
3944 SourceLocation RParenLoc) {
3945 return SemaRef.ObjC().BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
3946 RParenLoc);
3947 }
3948
3949 /// Build a new Objective-C class message.
3951 Selector Sel,
3952 ArrayRef<SourceLocation> SelectorLocs,
3954 SourceLocation LBracLoc,
3955 MultiExprArg Args,
3956 SourceLocation RBracLoc) {
3957 return SemaRef.ObjC().BuildClassMessage(
3958 ReceiverTypeInfo, ReceiverTypeInfo->getType(),
3959 /*SuperLoc=*/SourceLocation(), Sel, Method, LBracLoc, SelectorLocs,
3960 RBracLoc, Args);
3961 }
3962
3963 /// Build a new Objective-C instance message.
3965 Selector Sel,
3966 ArrayRef<SourceLocation> SelectorLocs,
3968 SourceLocation LBracLoc,
3969 MultiExprArg Args,
3970 SourceLocation RBracLoc) {
3971 return SemaRef.ObjC().BuildInstanceMessage(Receiver, Receiver->getType(),
3972 /*SuperLoc=*/SourceLocation(),
3973 Sel, Method, LBracLoc,
3974 SelectorLocs, RBracLoc, Args);
3975 }
3976
3977 /// Build a new Objective-C instance/class message to 'super'.
3979 Selector Sel,
3980 ArrayRef<SourceLocation> SelectorLocs,
3981 QualType SuperType,
3983 SourceLocation LBracLoc,
3984 MultiExprArg Args,
3985 SourceLocation RBracLoc) {
3986 return Method->isInstanceMethod()
3987 ? SemaRef.ObjC().BuildInstanceMessage(
3988 nullptr, SuperType, SuperLoc, Sel, Method, LBracLoc,
3989 SelectorLocs, RBracLoc, Args)
3990 : SemaRef.ObjC().BuildClassMessage(nullptr, SuperType, SuperLoc,
3991 Sel, Method, LBracLoc,
3992 SelectorLocs, RBracLoc, Args);
3993 }
3994
3995 /// Build a new Objective-C ivar reference expression.
3996 ///
3997 /// By default, performs semantic analysis to build the new expression.
3998 /// Subclasses may override this routine to provide different behavior.
4000 SourceLocation IvarLoc,
4001 bool IsArrow, bool IsFreeIvar) {
4002 CXXScopeSpec SS;
4003 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
4005 BaseArg, BaseArg->getType(),
4006 /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(),
4007 /*FirstQualifierInScope=*/nullptr, NameInfo,
4008 /*TemplateArgs=*/nullptr,
4009 /*S=*/nullptr);
4010 if (IsFreeIvar && Result.isUsable())
4011 cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar);
4012 return Result;
4013 }
4014
4015 /// Build a new Objective-C property reference expression.
4016 ///
4017 /// By default, performs semantic analysis to build the new expression.
4018 /// Subclasses may override this routine to provide different behavior.
4021 SourceLocation PropertyLoc) {
4022 CXXScopeSpec SS;
4023 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
4024 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
4025 /*FIXME:*/PropertyLoc,
4026 /*IsArrow=*/false,
4027 SS, SourceLocation(),
4028 /*FirstQualifierInScope=*/nullptr,
4029 NameInfo,
4030 /*TemplateArgs=*/nullptr,
4031 /*S=*/nullptr);
4032 }
4033
4034 /// Build a new Objective-C property reference expression.
4035 ///
4036 /// By default, performs semantic analysis to build the new expression.
4037 /// Subclasses may override this routine to provide different behavior.
4039 ObjCMethodDecl *Getter,
4040 ObjCMethodDecl *Setter,
4041 SourceLocation PropertyLoc) {
4042 // Since these expressions can only be value-dependent, we do not
4043 // need to perform semantic analysis again.
4044 return Owned(
4045 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
4047 PropertyLoc, Base));
4048 }
4049
4050 /// Build a new Objective-C "isa" expression.
4051 ///
4052 /// By default, performs semantic analysis to build the new expression.
4053 /// Subclasses may override this routine to provide different behavior.
4055 SourceLocation OpLoc, bool IsArrow) {
4056 CXXScopeSpec SS;
4057 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
4058 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
4059 OpLoc, IsArrow,
4060 SS, SourceLocation(),
4061 /*FirstQualifierInScope=*/nullptr,
4062 NameInfo,
4063 /*TemplateArgs=*/nullptr,
4064 /*S=*/nullptr);
4065 }
4066
4067 /// Build a new shuffle vector expression.
4068 ///
4069 /// By default, performs semantic analysis to build the new expression.
4070 /// Subclasses may override this routine to provide different behavior.
4072 MultiExprArg SubExprs,
4073 SourceLocation RParenLoc) {
4074 // Find the declaration for __builtin_shufflevector
4075 const IdentifierInfo &Name
4076 = SemaRef.Context.Idents.get("__builtin_shufflevector");
4077 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
4078 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
4079 assert(!Lookup.empty() && "No __builtin_shufflevector?");
4080
4081 // Build a reference to the __builtin_shufflevector builtin
4083 Expr *Callee = new (SemaRef.Context)
4084 DeclRefExpr(SemaRef.Context, Builtin, false,
4085 SemaRef.Context.BuiltinFnTy, VK_PRValue, BuiltinLoc);
4086 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
4087 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
4088 CK_BuiltinFnToFnPtr).get();
4089
4090 // Build the CallExpr
4091 ExprResult TheCall = CallExpr::Create(
4092 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
4093 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc,
4095
4096 // Type-check the __builtin_shufflevector expression.
4097 return SemaRef.BuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
4098 }
4099
4100 /// Build a new convert vector expression.
4102 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
4103 SourceLocation RParenLoc) {
4104 return SemaRef.ConvertVectorExpr(SrcExpr, DstTInfo, BuiltinLoc, RParenLoc);
4105 }
4106
4107 /// Build a new template argument pack expansion.
4108 ///
4109 /// By default, performs semantic analysis to build a new pack expansion
4110 /// for a template argument. Subclasses may override this routine to provide
4111 /// different behavior.
4113 SourceLocation EllipsisLoc,
4114 UnsignedOrNone NumExpansions) {
4115 switch (Pattern.getArgument().getKind()) {
4119 EllipsisLoc, NumExpansions);
4120 if (Result.isInvalid())
4121 return TemplateArgumentLoc();
4122
4124 /*IsCanonical=*/false),
4125 Result.get());
4126 }
4127
4129 return TemplateArgumentLoc(
4130 SemaRef.Context,
4132 NumExpansions),
4133 Pattern.getTemplateKWLoc(), Pattern.getTemplateQualifierLoc(),
4134 Pattern.getTemplateNameLoc(), EllipsisLoc);
4135
4143 llvm_unreachable("Pack expansion pattern has no parameter packs");
4144
4146 if (TypeSourceInfo *Expansion
4147 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
4148 EllipsisLoc,
4149 NumExpansions))
4150 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
4151 Expansion);
4152 break;
4153 }
4154
4155 return TemplateArgumentLoc();
4156 }
4157
4158 /// Build a new expression pack expansion.
4159 ///
4160 /// By default, performs semantic analysis to build a new pack expansion
4161 /// for an expression. Subclasses may override this routine to provide
4162 /// different behavior.
4164 UnsignedOrNone NumExpansions) {
4165 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
4166 }
4167
4168 /// Build a new C++1z fold-expression.
4169 ///
4170 /// By default, performs semantic analysis in order to build a new fold
4171 /// expression.
4173 SourceLocation LParenLoc, Expr *LHS,
4174 BinaryOperatorKind Operator,
4175 SourceLocation EllipsisLoc, Expr *RHS,
4176 SourceLocation RParenLoc,
4177 UnsignedOrNone NumExpansions) {
4178 return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator,
4179 EllipsisLoc, RHS, RParenLoc,
4180 NumExpansions);
4181 }
4182
4184 LambdaScopeInfo *LSI) {
4185 for (ParmVarDecl *PVD : LSI->CallOperator->parameters()) {
4186 if (Expr *Init = PVD->getInit())
4188 Init->containsUnexpandedParameterPack();
4189 else if (PVD->hasUninstantiatedDefaultArg())
4191 PVD->getUninstantiatedDefaultArg()
4192 ->containsUnexpandedParameterPack();
4193 }
4194 return getSema().BuildLambdaExpr(StartLoc, EndLoc);
4195 }
4196
4197 /// Build an empty C++1z fold-expression with the given operator.
4198 ///
4199 /// By default, produces the fallback value for the fold-expression, or
4200 /// produce an error if there is no fallback value.
4202 BinaryOperatorKind Operator) {
4203 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
4204 }
4205
4206 /// Build a new atomic operation expression.
4207 ///
4208 /// By default, performs semantic analysis to build the new expression.
4209 /// Subclasses may override this routine to provide different behavior.
4212 SourceLocation RParenLoc) {
4213 // Use this for all of the locations, since we don't know the difference
4214 // between the call and the expr at this point.
4215 SourceRange Range{BuiltinLoc, RParenLoc};
4216 return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op,
4218 }
4219
4221 ArrayRef<Expr *> SubExprs, QualType Type) {
4222 return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type);
4223 }
4224
4226 SourceLocation BeginLoc,
4227 SourceLocation DirLoc,
4228 SourceLocation EndLoc,
4230 StmtResult StrBlock) {
4232 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4233 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, StrBlock);
4234 }
4235
4246
4248 SourceLocation BeginLoc,
4249 SourceLocation DirLoc,
4250 SourceLocation EndLoc,
4252 StmtResult Loop) {
4254 K, BeginLoc, DirLoc, SourceLocation{}, SourceLocation{}, {},
4255 OpenACCAtomicKind::None, SourceLocation{}, EndLoc, Clauses, Loop);
4256 }
4257
4259 SourceLocation DirLoc,
4260 SourceLocation EndLoc,
4262 StmtResult StrBlock) {
4264 OpenACCDirectiveKind::Data, BeginLoc, DirLoc, SourceLocation{},
4266 Clauses, StrBlock);
4267 }
4268
4278
4288
4290 SourceLocation DirLoc,
4291 SourceLocation EndLoc,
4293 StmtResult StrBlock) {
4297 Clauses, StrBlock);
4298 }
4299
4301 SourceLocation DirLoc,
4302 SourceLocation EndLoc,
4303 ArrayRef<OpenACCClause *> Clauses) {
4305 OpenACCDirectiveKind::Init, BeginLoc, DirLoc, SourceLocation{},
4307 Clauses, {});
4308 }
4309
4319
4321 SourceLocation DirLoc,
4322 SourceLocation EndLoc,
4323 ArrayRef<OpenACCClause *> Clauses) {
4325 OpenACCDirectiveKind::Set, BeginLoc, DirLoc, SourceLocation{},
4327 Clauses, {});
4328 }
4329
4331 SourceLocation DirLoc,
4332 SourceLocation EndLoc,
4333 ArrayRef<OpenACCClause *> Clauses) {
4335 OpenACCDirectiveKind::Update, BeginLoc, DirLoc, SourceLocation{},
4337 Clauses, {});
4338 }
4339
4341 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4342 Expr *DevNumExpr, SourceLocation QueuesLoc, ArrayRef<Expr *> QueueIdExprs,
4343 SourceLocation RParenLoc, SourceLocation EndLoc,
4344 ArrayRef<OpenACCClause *> Clauses) {
4346 Exprs.push_back(DevNumExpr);
4347 llvm::append_range(Exprs, QueueIdExprs);
4349 OpenACCDirectiveKind::Wait, BeginLoc, DirLoc, LParenLoc, QueuesLoc,
4350 Exprs, OpenACCAtomicKind::None, RParenLoc, EndLoc, Clauses, {});
4351 }
4352
4354 SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation LParenLoc,
4355 SourceLocation ReadOnlyLoc, ArrayRef<Expr *> VarList,
4356 SourceLocation RParenLoc, SourceLocation EndLoc) {
4358 OpenACCDirectiveKind::Cache, BeginLoc, DirLoc, LParenLoc, ReadOnlyLoc,
4359 VarList, OpenACCAtomicKind::None, RParenLoc, EndLoc, {}, {});
4360 }
4361
4363 SourceLocation DirLoc,
4364 OpenACCAtomicKind AtKind,
4365 SourceLocation EndLoc,
4367 StmtResult AssociatedStmt) {
4369 OpenACCDirectiveKind::Atomic, BeginLoc, DirLoc, SourceLocation{},
4370 SourceLocation{}, {}, AtKind, SourceLocation{}, EndLoc, Clauses,
4371 AssociatedStmt);
4372 }
4373
4377
4379 RebuildSubstNonTypeTemplateParmExpr(Decl *AssociatedDecl, unsigned Index,
4380 QualType ParamType, SourceLocation Loc,
4381 TemplateArgument Arg,
4382 UnsignedOrNone PackIndex, bool Final) {
4384 AssociatedDecl, Index, ParamType, Loc, Arg, PackIndex, Final);
4385 }
4386
4388 SourceLocation StartLoc,
4389 SourceLocation LParenLoc,
4390 SourceLocation EndLoc) {
4391 return getSema().OpenMP().ActOnOpenMPTransparentClause(ImpexType, StartLoc,
4392 LParenLoc, EndLoc);
4393 }
4394
4395private:
4396 QualType TransformTypeInObjectScope(TypeLocBuilder &TLB, TypeLoc TL,
4397 QualType ObjectType,
4398 NamedDecl *FirstQualifierInScope);
4399
4400 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
4401 QualType ObjectType,
4402 NamedDecl *FirstQualifierInScope) {
4403 if (getDerived().AlreadyTransformed(TSInfo->getType()))
4404 return TSInfo;
4405
4406 TypeLocBuilder TLB;
4407 QualType T = TransformTypeInObjectScope(TLB, TSInfo->getTypeLoc(),
4408 ObjectType, FirstQualifierInScope);
4409 if (T.isNull())
4410 return nullptr;
4411 return TLB.getTypeSourceInfo(SemaRef.Context, T);
4412 }
4413
4414 QualType TransformDependentNameType(TypeLocBuilder &TLB,
4415 DependentNameTypeLoc TL,
4416 bool DeducibleTSTContext,
4417 QualType ObjectType = QualType(),
4418 NamedDecl *UnqualLookup = nullptr);
4419
4421 TransformOpenACCClauseList(OpenACCDirectiveKind DirKind,
4423
4424 OpenACCClause *
4425 TransformOpenACCClause(ArrayRef<const OpenACCClause *> ExistingClauses,
4426 OpenACCDirectiveKind DirKind,
4427 const OpenACCClause *OldClause);
4428};
4429
4430template <typename Derived>
4432 if (!S)
4433 return S;
4434
4435 switch (S->getStmtClass()) {
4436 case Stmt::NoStmtClass: break;
4437
4438 // Transform individual statement nodes
4439 // Pass SDK into statements that can produce a value
4440#define STMT(Node, Parent) \
4441 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
4442#define VALUESTMT(Node, Parent) \
4443 case Stmt::Node##Class: \
4444 return getDerived().Transform##Node(cast<Node>(S), SDK);
4445#define ABSTRACT_STMT(Node)
4446#define EXPR(Node, Parent)
4447#include "clang/AST/StmtNodes.inc"
4448
4449 // Transform expressions by calling TransformExpr.
4450#define STMT(Node, Parent)
4451#define ABSTRACT_STMT(Stmt)
4452#define EXPR(Node, Parent) case Stmt::Node##Class:
4453#include "clang/AST/StmtNodes.inc"
4454 {
4455 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
4456
4458 E = getSema().ActOnStmtExprResult(E);
4459 return getSema().ActOnExprStmt(E, SDK == StmtDiscardKind::Discarded);
4460 }
4461 }
4462
4463 return S;
4464}
4465
4466template<typename Derived>
4468 if (!S)
4469 return S;
4470
4471 switch (S->getClauseKind()) {
4472 default: break;
4473 // Transform individual clause nodes
4474#define GEN_CLANG_CLAUSE_CLASS
4475#define CLAUSE_CLASS(Enum, Str, Class) \
4476 case Enum: \
4477 return getDerived().Transform##Class(cast<Class>(S));
4478#include "llvm/Frontend/OpenMP/OMP.inc"
4479 }
4480
4481 return S;
4482}
4483
4484
4485template<typename Derived>
4487 if (!E)
4488 return E;
4489
4490 switch (E->getStmtClass()) {
4491 case Stmt::NoStmtClass: break;
4492#define STMT(Node, Parent) case Stmt::Node##Class: break;
4493#define ABSTRACT_STMT(Stmt)
4494#define EXPR(Node, Parent) \
4495 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
4496#include "clang/AST/StmtNodes.inc"
4497 }
4498
4499 return E;
4500}
4501
4502template<typename Derived>
4504 bool NotCopyInit) {
4505 // Initializers are instantiated like expressions, except that various outer
4506 // layers are stripped.
4507 if (!Init)
4508 return Init;
4509
4510 if (auto *FE = dyn_cast<FullExpr>(Init))
4511 Init = FE->getSubExpr();
4512
4513 if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) {
4514 OpaqueValueExpr *OVE = AIL->getCommonExpr();
4515 Init = OVE->getSourceExpr();
4516 }
4517
4518 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
4519 Init = MTE->getSubExpr();
4520
4521 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
4522 Init = Binder->getSubExpr();
4523
4524 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
4525 Init = ICE->getSubExprAsWritten();
4526
4527 if (CXXStdInitializerListExpr *ILE =
4528 dyn_cast<CXXStdInitializerListExpr>(Init))
4529 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
4530
4531 // If this is copy-initialization, we only need to reconstruct
4532 // InitListExprs. Other forms of copy-initialization will be a no-op if
4533 // the initializer is already the right type.
4534 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
4535 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
4536 return getDerived().TransformExpr(Init);
4537
4538 // Revert value-initialization back to empty parens.
4539 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
4540 SourceRange Parens = VIE->getSourceRange();
4541 return getDerived().RebuildParenListExpr(Parens.getBegin(), {},
4542 Parens.getEnd());
4543 }
4544
4545 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
4547 return getDerived().RebuildParenListExpr(SourceLocation(), {},
4548 SourceLocation());
4549
4550 // Revert initialization by constructor back to a parenthesized or braced list
4551 // of expressions. Any other form of initializer can just be reused directly.
4552 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
4553 return getDerived().TransformExpr(Init);
4554
4555 // If the initialization implicitly converted an initializer list to a
4556 // std::initializer_list object, unwrap the std::initializer_list too.
4557 if (Construct && Construct->isStdInitListInitialization())
4558 return TransformInitializer(Construct->getArg(0), NotCopyInit);
4559
4560 // Enter a list-init context if this was list initialization.
4563 Construct->isListInitialization());
4564
4565 getSema().currentEvaluationContext().InLifetimeExtendingContext =
4566 getSema().parentEvaluationContext().InLifetimeExtendingContext;
4567 getSema().currentEvaluationContext().RebuildDefaultArgOrDefaultInit =
4568 getSema().parentEvaluationContext().RebuildDefaultArgOrDefaultInit;
4569 SmallVector<Expr*, 8> NewArgs;
4570 bool ArgChanged = false;
4571 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
4572 /*IsCall*/true, NewArgs, &ArgChanged))
4573 return ExprError();
4574
4575 // If this was list initialization, revert to syntactic list form.
4576 if (Construct->isListInitialization())
4577 return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs,
4578 Construct->getEndLoc(),
4579 /*IsExplicit=*/true);
4580
4581 // Build a ParenListExpr to represent anything else.
4583 if (Parens.isInvalid()) {
4584 // This was a variable declaration's initialization for which no initializer
4585 // was specified.
4586 assert(NewArgs.empty() &&
4587 "no parens or braces but have direct init with arguments?");
4588 return ExprEmpty();
4589 }
4590 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
4591 Parens.getEnd());
4592}
4593
4594template<typename Derived>
4596 unsigned NumInputs,
4597 bool IsCall,
4598 SmallVectorImpl<Expr *> &Outputs,
4599 bool *ArgChanged) {
4600 for (unsigned I = 0; I != NumInputs; ++I) {
4601 // If requested, drop call arguments that need to be dropped.
4602 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
4603 if (ArgChanged)
4604 *ArgChanged = true;
4605
4606 break;
4607 }
4608
4609 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
4610 Expr *Pattern = Expansion->getPattern();
4611
4613 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4614 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4615
4616 // Determine whether the set of unexpanded parameter packs can and should
4617 // be expanded.
4618 bool Expand = true;
4619 bool RetainExpansion = false;
4620 UnsignedOrNone OrigNumExpansions = Expansion->getNumExpansions();
4621 UnsignedOrNone NumExpansions = OrigNumExpansions;
4623 Expansion->getEllipsisLoc(), Pattern->getSourceRange(),
4624 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
4625 RetainExpansion, NumExpansions))
4626 return true;
4627
4628 if (!Expand) {
4629 // The transform has determined that we should perform a simple
4630 // transformation on the pack expansion, producing another pack
4631 // expansion.
4632 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
4633 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
4634 if (OutPattern.isInvalid())
4635 return true;
4636
4637 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
4638 Expansion->getEllipsisLoc(),
4639 NumExpansions);
4640 if (Out.isInvalid())
4641 return true;
4642
4643 if (ArgChanged)
4644 *ArgChanged = true;
4645 Outputs.push_back(Out.get());
4646 continue;
4647 }
4648
4649 // Record right away that the argument was changed. This needs
4650 // to happen even if the array expands to nothing.
4651 if (ArgChanged) *ArgChanged = true;
4652
4653 // The transform has determined that we should perform an elementwise
4654 // expansion of the pattern. Do so.
4655 for (unsigned I = 0; I != *NumExpansions; ++I) {
4656 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
4657 ExprResult Out = getDerived().TransformExpr(Pattern);
4658 if (Out.isInvalid())
4659 return true;
4660
4661 if (Out.get()->containsUnexpandedParameterPack()) {
4662 Out = getDerived().RebuildPackExpansion(
4663 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4664 if (Out.isInvalid())
4665 return true;
4666 }
4667
4668 Outputs.push_back(Out.get());
4669 }
4670
4671 // If we're supposed to retain a pack expansion, do so by temporarily
4672 // forgetting the partially-substituted parameter pack.
4673 if (RetainExpansion) {
4674 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4675
4676 ExprResult Out = getDerived().TransformExpr(Pattern);
4677 if (Out.isInvalid())
4678 return true;
4679
4680 Out = getDerived().RebuildPackExpansion(
4681 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
4682 if (Out.isInvalid())
4683 return true;
4684
4685 Outputs.push_back(Out.get());
4686 }
4687
4688 continue;
4689 }
4690
4692 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
4693 : getDerived().TransformExpr(Inputs[I]);
4694 if (Result.isInvalid())
4695 return true;
4696
4697 if (Result.get() != Inputs[I] && ArgChanged)
4698 *ArgChanged = true;
4699
4700 Outputs.push_back(Result.get());
4701 }
4702
4703 return false;
4704}
4705
4706template <typename Derived>
4709
4712 /*LambdaContextDecl=*/nullptr,
4714 /*ShouldEnter=*/Kind == Sema::ConditionKind::ConstexprIf);
4715
4716 if (Var) {
4717 VarDecl *ConditionVar = cast_or_null<VarDecl>(
4719
4720 if (!ConditionVar)
4721 return Sema::ConditionError();
4722
4723 return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind);
4724 }
4725
4726 if (Expr) {
4727 ExprResult CondExpr = getDerived().TransformExpr(Expr);
4728
4729 if (CondExpr.isInvalid())
4730 return Sema::ConditionError();
4731
4732 return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind,
4733 /*MissingOK=*/true);
4734 }
4735
4736 return Sema::ConditionResult();
4737}
4738
4739template <typename Derived>
4741 NestedNameSpecifierLoc NNS, QualType ObjectType,
4742 NamedDecl *FirstQualifierInScope) {
4744
4745 auto insertNNS = [&Qualifiers](NestedNameSpecifierLoc NNS) {
4746 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
4747 Qualifier = Qualifier.getAsNamespaceAndPrefix().Prefix)
4748 Qualifiers.push_back(Qualifier);
4749 };
4750 insertNNS(NNS);
4751
4752 CXXScopeSpec SS;
4753 while (!Qualifiers.empty()) {
4754 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
4756
4757 switch (QNNS.getKind()) {
4759 llvm_unreachable("unexpected null nested name specifier");
4760
4763 Q.getLocalBeginLoc(), const_cast<NamespaceBaseDecl *>(
4765 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
4766 break;
4767 }
4768
4770 // There is no meaningful transformation that one could perform on the
4771 // global scope.
4772 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
4773 break;
4774
4776 CXXRecordDecl *RD = cast_or_null<CXXRecordDecl>(
4778 SS.MakeMicrosoftSuper(SemaRef.Context, RD, Q.getBeginLoc(),
4779 Q.getEndLoc());
4780 break;
4781 }
4782
4784 assert(SS.isEmpty());
4785 TypeLoc TL = Q.castAsTypeLoc();
4786
4787 if (auto DNT = TL.getAs<DependentNameTypeLoc>()) {
4788 NestedNameSpecifierLoc QualifierLoc = DNT.getQualifierLoc();
4789 if (QualifierLoc) {
4790 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4791 QualifierLoc, ObjectType, FirstQualifierInScope);
4792 if (!QualifierLoc)
4793 return NestedNameSpecifierLoc();
4794 ObjectType = QualType();
4795 FirstQualifierInScope = nullptr;
4796 }
4797 SS.Adopt(QualifierLoc);
4799 const_cast<IdentifierInfo *>(DNT.getTypePtr()->getIdentifier()),
4800 DNT.getNameLoc(), Q.getLocalEndLoc(), ObjectType);
4801 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo,
4802 false, SS,
4803 FirstQualifierInScope, false))
4804 return NestedNameSpecifierLoc();
4805 return SS.getWithLocInContext(SemaRef.Context);
4806 }
4807
4808 QualType T = TL.getType();
4809 TypeLocBuilder TLB;
4811 T = TransformTypeInObjectScope(TLB, TL, ObjectType,
4812 FirstQualifierInScope);
4813 if (T.isNull())
4814 return NestedNameSpecifierLoc();
4815 TL = TLB.getTypeLocInContext(SemaRef.Context, T);
4816 }
4817
4818 if (T->isDependentType() || T->isRecordType() ||
4819 (SemaRef.getLangOpts().CPlusPlus11 && T->isEnumeralType())) {
4820 if (T->isEnumeralType())
4821 SemaRef.Diag(TL.getBeginLoc(),
4822 diag::warn_cxx98_compat_enum_nested_name_spec);
4823 SS.Make(SemaRef.Context, TL, Q.getLocalEndLoc());
4824 break;
4825 }
4826 // If the nested-name-specifier is an invalid type def, don't emit an
4827 // error because a previous error should have already been emitted.
4829 if (!TTL || !TTL.getDecl()->isInvalidDecl()) {
4830 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
4831 << T << SS.getRange();
4832 }
4833 return NestedNameSpecifierLoc();
4834 }
4835 }
4836 }
4837
4838 // Don't rebuild the nested-name-specifier if we don't have to.
4839 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
4841 return NNS;
4842
4843 // If we can re-use the source-location data from the original
4844 // nested-name-specifier, do so.
4845 if (SS.location_size() == NNS.getDataLength() &&
4846 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
4848
4849 // Allocate new nested-name-specifier location information.
4850 return SS.getWithLocInContext(SemaRef.Context);
4851}
4852
4853template<typename Derived>
4857 DeclarationName Name = NameInfo.getName();
4858 if (!Name)
4859 return DeclarationNameInfo();
4860
4861 switch (Name.getNameKind()) {
4869 return NameInfo;
4870
4872 TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate();
4873 TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>(
4874 getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate));
4875 if (!NewTemplate)
4876 return DeclarationNameInfo();
4877
4878 DeclarationNameInfo NewNameInfo(NameInfo);
4879 NewNameInfo.setName(
4880 SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate));
4881 return NewNameInfo;
4882 }
4883
4887 TypeSourceInfo *NewTInfo;
4888 CanQualType NewCanTy;
4889 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
4890 NewTInfo = getDerived().TransformType(OldTInfo);
4891 if (!NewTInfo)
4892 return DeclarationNameInfo();
4893 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
4894 }
4895 else {
4896 NewTInfo = nullptr;
4897 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
4898 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
4899 if (NewT.isNull())
4900 return DeclarationNameInfo();
4901 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
4902 }
4903
4904 DeclarationName NewName
4905 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
4906 NewCanTy);
4907 DeclarationNameInfo NewNameInfo(NameInfo);
4908 NewNameInfo.setName(NewName);
4909 NewNameInfo.setNamedTypeInfo(NewTInfo);
4910 return NewNameInfo;
4911 }
4912 }
4913
4914 llvm_unreachable("Unknown name kind.");
4915}
4916
4917template <typename Derived>
4919 CXXScopeSpec &SS, SourceLocation TemplateKWLoc,
4921 QualType ObjectType, bool AllowInjectedClassName) {
4922 if (const IdentifierInfo *II = IO.getIdentifier())
4923 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, *II, NameLoc,
4924 ObjectType, AllowInjectedClassName);
4925 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, IO.getOperator(),
4926 NameLoc, ObjectType,
4927 AllowInjectedClassName);
4928}
4929
4930template <typename Derived>
4932 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKWLoc,
4933 TemplateName Name, SourceLocation NameLoc, QualType ObjectType,
4934 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
4936 TemplateName UnderlyingName = QTN->getUnderlyingTemplate();
4937
4938 if (QualifierLoc) {
4939 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4940 QualifierLoc, ObjectType, FirstQualifierInScope);
4941 if (!QualifierLoc)
4942 return TemplateName();
4943 }
4944
4945 NestedNameSpecifierLoc UnderlyingQualifier;
4946 TemplateName NewUnderlyingName = getDerived().TransformTemplateName(
4947 UnderlyingQualifier, TemplateKWLoc, UnderlyingName, NameLoc, ObjectType,
4948 FirstQualifierInScope, AllowInjectedClassName);
4949 if (NewUnderlyingName.isNull())
4950 return TemplateName();
4951 assert(!UnderlyingQualifier && "unexpected qualifier");
4952
4953 if (!getDerived().AlwaysRebuild() &&
4954 QualifierLoc.getNestedNameSpecifier() == QTN->getQualifier() &&
4955 NewUnderlyingName == UnderlyingName)
4956 return Name;
4957 CXXScopeSpec SS;
4958 SS.Adopt(QualifierLoc);
4959 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
4960 NewUnderlyingName);
4961 }
4962
4964 if (QualifierLoc) {
4965 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
4966 QualifierLoc, ObjectType, FirstQualifierInScope);
4967 if (!QualifierLoc)
4968 return TemplateName();
4969 // The qualifier-in-scope and object type only apply to the leftmost
4970 // entity.
4971 ObjectType = QualType();
4972 }
4973
4974 if (!getDerived().AlwaysRebuild() &&
4975 QualifierLoc.getNestedNameSpecifier() == DTN->getQualifier() &&
4976 ObjectType.isNull())
4977 return Name;
4978
4979 CXXScopeSpec SS;
4980 SS.Adopt(QualifierLoc);
4981 return getDerived().RebuildTemplateName(SS, TemplateKWLoc, DTN->getName(),
4982 NameLoc, ObjectType,
4983 AllowInjectedClassName);
4984 }
4985
4988 assert(!QualifierLoc && "Unexpected qualified SubstTemplateTemplateParm");
4989
4990 NestedNameSpecifierLoc ReplacementQualifierLoc;
4991 TemplateName ReplacementName = S->getReplacement();
4992 if (NestedNameSpecifier Qualifier = ReplacementName.getQualifier()) {
4994 Builder.MakeTrivial(SemaRef.Context, Qualifier, NameLoc);
4995 ReplacementQualifierLoc = Builder.getWithLocInContext(SemaRef.Context);
4996 }
4997
4998 TemplateName NewName = getDerived().TransformTemplateName(
4999 ReplacementQualifierLoc, TemplateKWLoc, ReplacementName, NameLoc,
5000 ObjectType, FirstQualifierInScope, AllowInjectedClassName);
5001 if (NewName.isNull())
5002 return TemplateName();
5003 Decl *AssociatedDecl =
5004 getDerived().TransformDecl(NameLoc, S->getAssociatedDecl());
5005 if (!getDerived().AlwaysRebuild() && NewName == S->getReplacement() &&
5006 AssociatedDecl == S->getAssociatedDecl())
5007 return Name;
5008 return SemaRef.Context.getSubstTemplateTemplateParm(
5009 NewName, AssociatedDecl, S->getIndex(), S->getPackIndex(),
5010 S->getFinal());
5011 }
5012
5014 assert(!QualifierLoc && "Unexpected qualified pack-index-template-name");
5015
5016 ExprResult IndexExpr;
5017 {
5018 EnterExpressionEvaluationContext ConstantContext(
5020 IndexExpr = getDerived().TransformExpr(PI->getIndexExpr());
5021 if (IndexExpr.isInvalid())
5022 return TemplateName();
5023 }
5024
5025 auto TransformOne = [&](TemplateName N) {
5026 NestedNameSpecifierLoc NoQualifier;
5027 return getDerived().TransformTemplateName(
5028 NoQualifier, TemplateKWLoc, N, NameLoc, ObjectType,
5029 FirstQualifierInScope, AllowInjectedClassName);
5030 };
5031
5032 TemplateName Pattern = PI->getPattern();
5033 SmallVector<TemplateName, 4> SubstitutedNames;
5034 ArrayRef<TemplateName> Names = PI->getExpansions();
5035
5036 bool NotYetExpanded = Names.empty();
5037 bool FullySubstituted = true;
5038
5039 if (Names.empty() && !PI->expandsToEmptyPack())
5040 Names = ArrayRef(&Pattern, 1);
5041
5042 for (TemplateName N : Names) {
5043 if (!N.containsUnexpandedParameterPack()) {
5044 TemplateName Transformed = TransformOne(N);
5045 if (Transformed.isNull())
5046 return TemplateName();
5047 SubstitutedNames.push_back(Transformed);
5048 continue;
5049 }
5050
5052 getSema().collectUnexpandedParameterPacks(N, Unexpanded);
5053 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5054
5055 bool ShouldExpand = true;
5056 bool RetainExpansion = false;
5057 UnsignedOrNone NumExpansions = std::nullopt;
5059 NameLoc, SourceRange(), Unexpanded,
5060 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
5061 RetainExpansion, NumExpansions))
5062 return TemplateName();
5063
5064 if (!ShouldExpand) {
5065 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
5066 TemplateName Pack = TransformOne(N);
5067 if (Pack.isNull())
5068 return TemplateName();
5069 if (NotYetExpanded) {
5070 FullySubstituted = false;
5071 return getDerived().RebuildPackIndexingTemplateName(
5072 Pack, IndexExpr.get(), FullySubstituted);
5073 }
5074 SubstitutedNames.push_back(Pack);
5075 continue;
5076 }
5077
5078 for (unsigned I = 0; I != *NumExpansions; ++I) {
5079 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5080 TemplateName Out = TransformOne(N);
5081 if (Out.isNull())
5082 return TemplateName();
5083 SubstitutedNames.push_back(Out);
5084 FullySubstituted &= !Out.containsUnexpandedParameterPack();
5085 }
5086
5087 // If we're supposed to retain a pack expansion, do so by temporarily
5088 // forgetting the partially-substituted parameter pack.
5089 if (RetainExpansion) {
5090 FullySubstituted = false;
5091 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5092 TemplateName Out = TransformOne(N);
5093 if (Out.isNull())
5094 return TemplateName();
5095 SubstitutedNames.push_back(Out);
5096 }
5097 }
5098
5099 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
5100 TemplateName NewPattern = TransformOne(Pattern);
5101 if (NewPattern.isNull())
5102 return TemplateName();
5103
5104 return getDerived().RebuildPackIndexingTemplateName(
5105 NewPattern, IndexExpr.get(), FullySubstituted, SubstitutedNames);
5106 }
5107
5108 assert(!Name.getAsDeducedTemplateName() &&
5109 "DeducedTemplateName should not escape partial ordering");
5110
5111 // FIXME: Preserve UsingTemplateName.
5112 if (auto *Template = Name.getAsTemplateDecl()) {
5113 assert(!QualifierLoc && "Unexpected qualifier");
5114 return TemplateName(cast_or_null<TemplateDecl>(
5115 getDerived().TransformDecl(NameLoc, Template)));
5116 }
5117
5120 assert(!QualifierLoc &&
5121 "Unexpected qualified SubstTemplateTemplateParmPack");
5122 return getDerived().RebuildTemplateName(
5123 SubstPack->getArgumentPack(), SubstPack->getAssociatedDecl(),
5124 SubstPack->getIndex(), SubstPack->getFinal());
5125 }
5126
5127 // These should be getting filtered out before they reach the AST.
5128 llvm_unreachable("overloaded function decl survived to here");
5129}
5130
5131template <typename Derived>
5134 SourceLocation NameLoc) {
5135 NestedNameSpecifierLoc QualifierLoc;
5136 return getDerived().TransformTemplateName(
5137 QualifierLoc, /*TemplateKWLoc=*/SourceLocation(), Name, NameLoc);
5138}
5139
5140template <typename Derived>
5142 NestedNameSpecifierLoc &QualifierLoc, SourceLocation TemplateKeywordLoc,
5143 TemplateName Name, SourceLocation NameLoc) {
5144 TemplateName TN = getDerived().TransformTemplateName(
5145 QualifierLoc, TemplateKeywordLoc, Name, NameLoc);
5146 if (TN.isNull())
5147 return TemplateArgument();
5148 return TemplateArgument(TN);
5149}
5150
5151template<typename Derived>
5153 const TemplateArgument &Arg,
5154 TemplateArgumentLoc &Output) {
5155 Output = getSema().getTrivialTemplateArgumentLoc(
5156 Arg, QualType(), getDerived().getBaseLocation());
5157}
5158
5159template <typename Derived>
5161 const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
5162 bool Uneval) {
5163 const TemplateArgument &Arg = Input.getArgument();
5164 switch (Arg.getKind()) {
5167 llvm_unreachable("Unexpected TemplateArgument");
5168
5173 // Transform a resolved template argument straight to a resolved template
5174 // argument. We get here when substituting into an already-substituted
5175 // template type argument during concept satisfaction checking.
5177 QualType NewT = getDerived().TransformType(T);
5178 if (NewT.isNull())
5179 return true;
5180
5182 ? Arg.getAsDecl()
5183 : nullptr;
5184 ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl(
5186 : nullptr;
5187 if (D && !NewD)
5188 return true;
5189
5190 if (NewT == T && D == NewD)
5191 Output = Input;
5192 else if (Arg.getKind() == TemplateArgument::Integral)
5193 Output = TemplateArgumentLoc(
5194 TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT),
5196 else if (Arg.getKind() == TemplateArgument::NullPtr)
5197 Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true),
5199 else if (Arg.getKind() == TemplateArgument::Declaration)
5200 Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT),
5203 Output = TemplateArgumentLoc(
5204 TemplateArgument(getSema().Context, NewT, Arg.getAsStructuralValue()),
5206 else
5207 llvm_unreachable("unexpected template argument kind");
5208
5209 return false;
5210 }
5211
5213 TypeSourceInfo *TSI = Input.getTypeSourceInfo();
5214 if (!TSI)
5216
5217 TSI = getDerived().TransformType(TSI);
5218 if (!TSI)
5219 return true;
5220
5221 Output = TemplateArgumentLoc(TemplateArgument(TSI->getType()), TSI);
5222 return false;
5223 }
5224
5226 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
5227
5228 TemplateArgument Out = getDerived().TransformNamedTemplateTemplateArgument(
5229 QualifierLoc, Input.getTemplateKWLoc(), Arg.getAsTemplate(),
5230 Input.getTemplateNameLoc());
5231 if (Out.isNull())
5232 return true;
5233 Output = TemplateArgumentLoc(SemaRef.Context, Out, Input.getTemplateKWLoc(),
5234 QualifierLoc, Input.getTemplateNameLoc());
5235 return false;
5236 }
5237
5239 llvm_unreachable("Caller should expand pack expansions");
5240
5242 // Template argument expressions are constant expressions.
5244 getSema(),
5247 Sema::ReuseLambdaContextDecl, /*ExprContext=*/
5249
5250 Expr *InputExpr = Input.getSourceExpression();
5251 if (!InputExpr)
5252 InputExpr = Input.getArgument().getAsExpr();
5253
5254 ExprResult E = getDerived().TransformExpr(InputExpr);
5255 E = SemaRef.ActOnConstantExpression(E);
5256 if (E.isInvalid())
5257 return true;
5258 Output = TemplateArgumentLoc(
5259 TemplateArgument(E.get(), /*IsCanonical=*/false), E.get());
5260 return false;
5261 }
5262 }
5263
5264 // Work around bogus GCC warning
5265 return true;
5266}
5267
5268/// Iterator adaptor that invents template argument location information
5269/// for each of the template arguments in its underlying iterator.
5270template<typename Derived, typename InputIterator>
5273 InputIterator Iter;
5274
5275public:
5278 typedef typename std::iterator_traits<InputIterator>::difference_type
5280 typedef std::input_iterator_tag iterator_category;
5281
5282 class pointer {
5284
5285 public:
5286 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
5287
5288 const TemplateArgumentLoc *operator->() const { return &Arg; }
5289 };
5290
5292 InputIterator Iter)
5293 : Self(Self), Iter(Iter) { }
5294
5296 ++Iter;
5297 return *this;
5298 }
5299
5302 ++(*this);
5303 return Old;
5304 }
5305
5308 Self.InventTemplateArgumentLoc(*Iter, Result);
5309 return Result;
5310 }
5311
5312 pointer operator->() const { return pointer(**this); }
5313
5316 return X.Iter == Y.Iter;
5317 }
5318
5321 return X.Iter != Y.Iter;
5322 }
5323};
5324
5325template<typename Derived>
5326template<typename InputIterator>
5328 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5329 bool Uneval) {
5330 for (TemplateArgumentLoc In : llvm::make_range(First, Last)) {
5332 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5333 // Unpack argument packs, which we translate them into separate
5334 // arguments.
5335 // FIXME: We could do much better if we could guarantee that the
5336 // TemplateArgumentLocInfo for the pack expansion would be usable for
5337 // all of the template arguments in the argument pack.
5338 typedef TemplateArgumentLocInventIterator<Derived,
5340 PackLocIterator;
5341
5342 TemplateArgumentListInfo *PackOutput = &Outputs;
5343
5345 PackLocIterator(*this, In.getArgument().pack_begin()),
5346 PackLocIterator(*this, In.getArgument().pack_end()), *PackOutput,
5347 Uneval))
5348 return true;
5349
5350 continue;
5351 }
5352
5353 if (In.getArgument().isPackExpansion()) {
5354 UnexpandedInfo Info;
5355 TemplateArgumentLoc Prepared;
5356 if (getDerived().PreparePackForExpansion(In, Uneval, Prepared, Info))
5357 return true;
5358 if (!Info.Expand) {
5359 Outputs.addArgument(Prepared);
5360 continue;
5361 }
5362
5363 // The transform has determined that we should perform an elementwise
5364 // expansion of the pattern. Do so.
5365 std::optional<ForgetSubstitutionRAII> ForgetSubst;
5367 ForgetSubst.emplace(getDerived());
5368 for (unsigned I = 0; I != *Info.NumExpansions; ++I) {
5369 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
5370
5372 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5373 return true;
5374
5375 if (Out.getArgument().containsUnexpandedParameterPack()) {
5376 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5377 Info.OrigNumExpansions);
5378 if (Out.getArgument().isNull())
5379 return true;
5380 }
5381
5382 Outputs.addArgument(Out);
5383 }
5384
5385 // If we're supposed to retain a pack expansion, do so by temporarily
5386 // forgetting the partially-substituted parameter pack.
5387 if (Info.RetainExpansion) {
5388 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
5389
5391 if (getDerived().TransformTemplateArgument(Prepared, Out, Uneval))
5392 return true;
5393
5394 Out = getDerived().RebuildPackExpansion(Out, Info.Ellipsis,
5395 Info.OrigNumExpansions);
5396 if (Out.getArgument().isNull())
5397 return true;
5398
5399 Outputs.addArgument(Out);
5400 }
5401
5402 continue;
5403 }
5404
5405 // The simple case:
5406 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5407 return true;
5408
5409 Outputs.addArgument(Out);
5410 }
5411
5412 return false;
5413}
5414
5415template <typename Derived>
5416template <typename InputIterator>
5418 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
5419 bool Uneval) {
5420
5421 // [C++26][temp.constr.normal]
5422 // any non-dependent concept template argument
5423 // is substituted into the constraint-expression of C.
5424 auto isNonDependentConceptArgument = [](const TemplateArgument &Arg) {
5425 return !Arg.isDependent() && Arg.isConceptOrConceptTemplateParameter();
5426 };
5427
5428 for (; First != Last; ++First) {
5431
5432 if (In.getArgument().getKind() == TemplateArgument::Pack) {
5433 typedef TemplateArgumentLocInventIterator<Derived,
5435 PackLocIterator;
5437 PackLocIterator(*this, In.getArgument().pack_begin()),
5438 PackLocIterator(*this, In.getArgument().pack_end()), Outputs,
5439 Uneval))
5440 return true;
5441 continue;
5442 }
5443
5444 if (!isNonDependentConceptArgument(In.getArgument())) {
5445 Outputs.addArgument(In);
5446 continue;
5447 }
5448
5449 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
5450 return true;
5451
5452 Outputs.addArgument(Out);
5453 }
5454
5455 return false;
5456}
5457
5458// FIXME: Find ways to reduce code duplication for pack expansions.
5459template <typename Derived>
5461 bool Uneval,
5463 UnexpandedInfo &Info) {
5464 auto ComputeInfo = [this](TemplateArgumentLoc Arg,
5465 bool IsLateExpansionAttempt, UnexpandedInfo &Info,
5466 TemplateArgumentLoc &Pattern) {
5467 assert(Arg.getArgument().isPackExpansion());
5468 // We have a pack expansion, for which we will be substituting into the
5469 // pattern.
5470 Pattern = getSema().getTemplateArgumentPackExpansionPattern(
5471 Arg, Info.Ellipsis, Info.OrigNumExpansions);
5473 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
5474 if (IsLateExpansionAttempt) {
5475 // Request expansion only when there is an opportunity to expand a pack
5476 // that required a substituion first.
5477 bool SawPackTypes =
5478 llvm::any_of(Unexpanded, [](UnexpandedParameterPack P) {
5480 });
5481 if (!SawPackTypes) {
5482 Info.Expand = false;
5483 return false;
5484 }
5485 }
5486 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5487
5488 // Determine whether the set of unexpanded parameter packs can and
5489 // should be expanded.
5490 Info.Expand = true;
5491 Info.RetainExpansion = false;
5492 Info.NumExpansions = Info.OrigNumExpansions;
5493 return getDerived().TryExpandParameterPacks(
5494 Info.Ellipsis, Pattern.getSourceRange(), Unexpanded,
5495 /*FailOnPackProducingTemplates=*/false, Info.Expand,
5496 Info.RetainExpansion, Info.NumExpansions);
5497 };
5498
5499 TemplateArgumentLoc Pattern;
5500 if (ComputeInfo(In, false, Info, Pattern))
5501 return true;
5502
5503 if (Info.Expand) {
5504 Out = Pattern;
5505 return false;
5506 }
5507
5508 // The transform has determined that we should perform a simple
5509 // transformation on the pack expansion, producing another pack
5510 // expansion.
5511 TemplateArgumentLoc OutPattern;
5512 std::optional<Sema::ArgPackSubstIndexRAII> SubstIndex(
5513 std::in_place, getSema(), std::nullopt);
5514 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
5515 return true;
5516
5517 Out = getDerived().RebuildPackExpansion(OutPattern, Info.Ellipsis,
5518 Info.NumExpansions);
5519 if (Out.getArgument().isNull())
5520 return true;
5521 SubstIndex.reset();
5522
5523 if (!OutPattern.getArgument().containsUnexpandedParameterPack())
5524 return false;
5525
5526 // Some packs will learn their length after substitution, e.g.
5527 // __builtin_dedup_pack<T,int> has size 1 or 2, depending on the substitution
5528 // value of `T`.
5529 //
5530 // We only expand after we know sizes of all packs, check if this is the case
5531 // or not. However, we avoid a full template substitution and only do
5532 // expanstions after this point.
5533
5534 // E.g. when substituting template arguments of tuple with {T -> int} in the
5535 // following example:
5536 // template <class T>
5537 // struct TupleWithInt {
5538 // using type = std::tuple<__builtin_dedup_pack<T, int>...>;
5539 // };
5540 // TupleWithInt<int>::type y;
5541 // At this point we will see the `__builtin_dedup_pack<int, int>` with a known
5542 // length and run `ComputeInfo()` to provide the necessary information to our
5543 // caller.
5544 //
5545 // Note that we may still have situations where builtin is not going to be
5546 // expanded. For example:
5547 // template <class T>
5548 // struct Foo {
5549 // template <class U> using tuple_with_t =
5550 // std::tuple<__builtin_dedup_pack<T, U, int>...>; using type =
5551 // tuple_with_t<short>;
5552 // }
5553 // Because the substitution into `type` happens in dependent context, `type`
5554 // will be `tuple<builtin_dedup_pack<T, short, int>...>` after substitution
5555 // and the caller will not be able to expand it.
5556 ForgetSubstitutionRAII ForgetSubst(getDerived());
5557 if (ComputeInfo(Out, true, Info, OutPattern))
5558 return true;
5559 if (!Info.Expand)
5560 return false;
5561 Out = OutPattern;
5562 Info.ExpandUnderForgetSubstitions = true;
5563 return false;
5564}
5565
5566//===----------------------------------------------------------------------===//
5567// Type transformation
5568//===----------------------------------------------------------------------===//
5569
5570template<typename Derived>
5573 return T;
5574
5575 // Temporary workaround. All of these transformations should
5576 // eventually turn into transformations on TypeLocs.
5577 TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo(
5579
5580 TypeSourceInfo *NewTSI = getDerived().TransformType(TSI);
5581
5582 if (!NewTSI)
5583 return QualType();
5584
5585 return NewTSI->getType();
5586}
5587
5588template <typename Derived>
5590 // Refine the base location to the type's location.
5591 TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(),
5594 return TSI;
5595
5596 TypeLocBuilder TLB;
5597
5598 TypeLoc TL = TSI->getTypeLoc();
5599 TLB.reserve(TL.getFullDataSize());
5600
5601 QualType Result = getDerived().TransformType(TLB, TL);
5602 if (Result.isNull())
5603 return nullptr;
5604
5605 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5606}
5607
5608template<typename Derived>
5611 switch (T.getTypeLocClass()) {
5612#define ABSTRACT_TYPELOC(CLASS, PARENT)
5613#define TYPELOC(CLASS, PARENT) \
5614 case TypeLoc::CLASS: \
5615 return getDerived().Transform##CLASS##Type(TLB, \
5616 T.castAs<CLASS##TypeLoc>());
5617#include "clang/AST/TypeLocNodes.def"
5618 }
5619
5620 llvm_unreachable("unhandled type loc!");
5621}
5622
5623template<typename Derived>
5626 return TransformType(T);
5627
5629 return T;
5630 TypeSourceInfo *TSI = getSema().Context.getTrivialTypeSourceInfo(
5632 TypeSourceInfo *NewTSI = getDerived().TransformTypeWithDeducedTST(TSI);
5633 return NewTSI ? NewTSI->getType() : QualType();
5634}
5635
5636template <typename Derived>
5639 if (!isa<DependentNameType>(TSI->getType()))
5640 return TransformType(TSI);
5641
5642 // Refine the base location to the type's location.
5643 TemporaryBase Rebase(*this, TSI->getTypeLoc().getBeginLoc(),
5646 return TSI;
5647
5648 TypeLocBuilder TLB;
5649
5650 TypeLoc TL = TSI->getTypeLoc();
5651 TLB.reserve(TL.getFullDataSize());
5652
5653 auto QTL = TL.getAs<QualifiedTypeLoc>();
5654 if (QTL)
5655 TL = QTL.getUnqualifiedLoc();
5656
5657 auto DNTL = TL.castAs<DependentNameTypeLoc>();
5658
5659 QualType Result = getDerived().TransformDependentNameType(
5660 TLB, DNTL, /*DeducedTSTContext*/true);
5661 if (Result.isNull())
5662 return nullptr;
5663
5664 if (QTL) {
5665 Result = getDerived().RebuildQualifiedType(Result, QTL);
5666 if (Result.isNull())
5667 return nullptr;
5669 }
5670
5671 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
5672}
5673
5674template<typename Derived>
5679 TypeLoc UnqualTL = T.getUnqualifiedLoc();
5680 auto SuppressObjCLifetime =
5681 T.getType().getLocalQualifiers().hasObjCLifetime();
5682 if (auto TTP = UnqualTL.getAs<TemplateTypeParmTypeLoc>()) {
5683 Result = getDerived().TransformTemplateTypeParmType(TLB, TTP,
5684 SuppressObjCLifetime);
5685 } else if (auto STTP = UnqualTL.getAs<SubstTemplateTypeParmPackTypeLoc>()) {
5686 Result = getDerived().TransformSubstTemplateTypeParmPackType(
5687 TLB, STTP, SuppressObjCLifetime);
5688 } else {
5689 Result = getDerived().TransformType(TLB, UnqualTL);
5690 }
5691
5692 if (Result.isNull())
5693 return QualType();
5694
5695 Result = getDerived().RebuildQualifiedType(Result, T);
5696
5697 if (Result.isNull())
5698 return QualType();
5699
5700 // RebuildQualifiedType might have updated the type, but not in a way
5701 // that invalidates the TypeLoc. (There's no location information for
5702 // qualifiers.)
5704
5705 return Result;
5706}
5707
5708template <typename Derived>
5710 QualifiedTypeLoc TL) {
5711
5712 SourceLocation Loc = TL.getBeginLoc();
5713 Qualifiers Quals = TL.getType().getLocalQualifiers();
5714
5715 if ((T.getAddressSpace() != LangAS::Default &&
5716 Quals.getAddressSpace() != LangAS::Default) &&
5717 T.getAddressSpace() != Quals.getAddressSpace()) {
5718 SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst)
5719 << TL.getType() << T;
5720 return QualType();
5721 }
5722
5723 PointerAuthQualifier LocalPointerAuth = Quals.getPointerAuth();
5724 if (LocalPointerAuth.isPresent()) {
5725 if (T.getPointerAuth().isPresent()) {
5726 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_redundant) << TL.getType();
5727 return QualType();
5728 }
5729 if (!T->isDependentType()) {
5730 if (!T->isSignableType(SemaRef.getASTContext())) {
5731 SemaRef.Diag(Loc, diag::err_ptrauth_qualifier_invalid_target) << T;
5732 return QualType();
5733 }
5734 }
5735 }
5736 // C++ [dcl.fct]p7:
5737 // [When] adding cv-qualifications on top of the function type [...] the
5738 // cv-qualifiers are ignored.
5739 if (T->isFunctionType()) {
5740 T = SemaRef.getASTContext().getAddrSpaceQualType(T,
5741 Quals.getAddressSpace());
5742 return T;
5743 }
5744
5745 // C++ [dcl.ref]p1:
5746 // when the cv-qualifiers are introduced through the use of a typedef-name
5747 // or decltype-specifier [...] the cv-qualifiers are ignored.
5748 // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be
5749 // applied to a reference type.
5750 if (T->isReferenceType()) {
5751 // The only qualifier that applies to a reference type is restrict.
5752 if (!Quals.hasRestrict())
5753 return T;
5755 }
5756
5757 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
5758 // resulting type.
5759 if (Quals.hasObjCLifetime()) {
5760 if (!T->isObjCLifetimeType() && !T->isDependentType())
5761 Quals.removeObjCLifetime();
5762 else if (T.getObjCLifetime()) {
5763 // Objective-C ARC:
5764 // A lifetime qualifier applied to a substituted template parameter
5765 // overrides the lifetime qualifier from the template argument.
5766 const AutoType *AutoTy;
5767 if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) {
5768 // 'auto' types behave the same way as template parameters.
5769 QualType Deduced = AutoTy->getDeducedType();
5770 Qualifiers Qs = Deduced.getQualifiers();
5771 Qs.removeObjCLifetime();
5772 Deduced =
5773 SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs);
5774 T = SemaRef.Context.getAutoType(AutoTy->getDeducedKind(), Deduced,
5775 AutoTy->getKeyword(),
5776 AutoTy->getTypeConstraintConcept(),
5777 AutoTy->getTypeConstraintArguments());
5778 } else {
5779 // Otherwise, complain about the addition of a qualifier to an
5780 // already-qualified type.
5781 // FIXME: Why is this check not in Sema::BuildQualifiedType?
5782 SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T;
5783 Quals.removeObjCLifetime();
5784 }
5785 }
5786 }
5787
5788 return SemaRef.BuildQualifiedType(T, Loc, Quals);
5789}
5790
5791template <typename Derived>
5792QualType TreeTransform<Derived>::TransformTypeInObjectScope(
5793 TypeLocBuilder &TLB, TypeLoc TL, QualType ObjectType,
5794 NamedDecl *FirstQualifierInScope) {
5795 assert(!getDerived().AlreadyTransformed(TL.getType()));
5796
5797 switch (TL.getTypeLocClass()) {
5798 case TypeLoc::TemplateSpecialization:
5799 return getDerived().TransformTemplateSpecializationType(
5800 TLB, TL.castAs<TemplateSpecializationTypeLoc>(), ObjectType,
5801 FirstQualifierInScope, /*AllowInjectedClassName=*/true);
5802 case TypeLoc::DependentName:
5803 return getDerived().TransformDependentNameType(
5804 TLB, TL.castAs<DependentNameTypeLoc>(), /*DeducedTSTContext=*/false,
5805 ObjectType, FirstQualifierInScope);
5806 default:
5807 // Any dependent canonical type can appear here, through type alias
5808 // templates.
5809 return getDerived().TransformType(TLB, TL);
5810 }
5811}
5812
5813template <class TyLoc> static inline
5815 TyLoc NewT = TLB.push<TyLoc>(T.getType());
5816 NewT.setNameLoc(T.getNameLoc());
5817 return T.getType();
5818}
5819
5820template<typename Derived>
5821QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
5822 BuiltinTypeLoc T) {
5823 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
5824 NewT.setBuiltinLoc(T.getBuiltinLoc());
5825 if (T.needsExtraLocalData())
5826 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
5827 return T.getType();
5828}
5829
5830template<typename Derived>
5832 ComplexTypeLoc T) {
5833 // FIXME: recurse?
5834 return TransformTypeSpecType(TLB, T);
5835}
5836
5837template <typename Derived>
5839 AdjustedTypeLoc TL) {
5840 // Adjustments applied during transformation are handled elsewhere.
5841 return getDerived().TransformType(TLB, TL.getOriginalLoc());
5842}
5843
5844template<typename Derived>
5846 DecayedTypeLoc TL) {
5847 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
5848 if (OriginalType.isNull())
5849 return QualType();
5850
5851 QualType Result = TL.getType();
5852 if (getDerived().AlwaysRebuild() ||
5853 OriginalType != TL.getOriginalLoc().getType())
5854 Result = SemaRef.Context.getDecayedType(OriginalType);
5855 TLB.push<DecayedTypeLoc>(Result);
5856 // Nothing to set for DecayedTypeLoc.
5857 return Result;
5858}
5859
5860template <typename Derived>
5864 QualType OriginalType = getDerived().TransformType(TLB, TL.getElementLoc());
5865 if (OriginalType.isNull())
5866 return QualType();
5867
5868 QualType Result = TL.getType();
5869 if (getDerived().AlwaysRebuild() ||
5870 OriginalType != TL.getElementLoc().getType())
5871 Result = SemaRef.Context.getArrayParameterType(OriginalType);
5872 TLB.push<ArrayParameterTypeLoc>(Result);
5873 // Nothing to set for ArrayParameterTypeLoc.
5874 return Result;
5875}
5876
5877template<typename Derived>
5879 PointerTypeLoc TL) {
5880 QualType PointeeType
5881 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5882 if (PointeeType.isNull())
5883 return QualType();
5884
5885 QualType Result = TL.getType();
5886 if (PointeeType->getAs<ObjCObjectType>()) {
5887 // A dependent pointer type 'T *' has is being transformed such
5888 // that an Objective-C class type is being replaced for 'T'. The
5889 // resulting pointer type is an ObjCObjectPointerType, not a
5890 // PointerType.
5891 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
5892
5894 NewT.setStarLoc(TL.getStarLoc());
5895 return Result;
5896 }
5897
5898 if (getDerived().AlwaysRebuild() ||
5899 PointeeType != TL.getPointeeLoc().getType()) {
5900 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
5901 if (Result.isNull())
5902 return QualType();
5903 }
5904
5905 // Objective-C ARC can add lifetime qualifiers to the type that we're
5906 // pointing to.
5907 TLB.TypeWasModifiedSafely(Result->getPointeeType());
5908
5909 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
5910 NewT.setSigilLoc(TL.getSigilLoc());
5911 return Result;
5912}
5913
5914template<typename Derived>
5918 QualType PointeeType
5919 = getDerived().TransformType(TLB, TL.getPointeeLoc());
5920 if (PointeeType.isNull())
5921 return QualType();
5922
5923 QualType Result = TL.getType();
5924 if (getDerived().AlwaysRebuild() ||
5925 PointeeType != TL.getPointeeLoc().getType()) {
5926 Result = getDerived().RebuildBlockPointerType(PointeeType,
5927 TL.getSigilLoc());
5928 if (Result.isNull())
5929 return QualType();
5930 }
5931
5933 NewT.setSigilLoc(TL.getSigilLoc());
5934 return Result;
5935}
5936
5937/// Transforms a reference type. Note that somewhat paradoxically we
5938/// don't care whether the type itself is an l-value type or an r-value
5939/// type; we only care if the type was *written* as an l-value type
5940/// or an r-value type.
5941template<typename Derived>
5944 ReferenceTypeLoc TL) {
5945 const ReferenceType *T = TL.getTypePtr();
5946
5947 // Note that this works with the pointee-as-written.
5948 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5949 if (PointeeType.isNull())
5950 return QualType();
5951
5952 QualType Result = TL.getType();
5953 if (getDerived().AlwaysRebuild() ||
5954 PointeeType != T->getPointeeTypeAsWritten()) {
5955 Result = getDerived().RebuildReferenceType(PointeeType,
5956 T->isSpelledAsLValue(),
5957 TL.getSigilLoc());
5958 if (Result.isNull())
5959 return QualType();
5960 }
5961
5962 // Objective-C ARC can add lifetime qualifiers to the type that we're
5963 // referring to.
5966
5967 // r-value references can be rebuilt as l-value references.
5968 ReferenceTypeLoc NewTL;
5970 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
5971 else
5972 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
5973 NewTL.setSigilLoc(TL.getSigilLoc());
5974
5975 return Result;
5976}
5977
5978template<typename Derived>
5982 return TransformReferenceType(TLB, TL);
5983}
5984
5985template<typename Derived>
5986QualType
5987TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
5988 RValueReferenceTypeLoc TL) {
5989 return TransformReferenceType(TLB, TL);
5990}
5991
5992template<typename Derived>
5996 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5997 if (PointeeType.isNull())
5998 return QualType();
5999
6000 const MemberPointerType *T = TL.getTypePtr();
6001
6002 NestedNameSpecifierLoc OldQualifierLoc = TL.getQualifierLoc();
6003 NestedNameSpecifierLoc NewQualifierLoc =
6004 getDerived().TransformNestedNameSpecifierLoc(OldQualifierLoc);
6005 if (!NewQualifierLoc)
6006 return QualType();
6007
6008 CXXRecordDecl *OldCls = T->getMostRecentCXXRecordDecl(), *NewCls = nullptr;
6009 if (OldCls) {
6010 NewCls = cast_or_null<CXXRecordDecl>(
6011 getDerived().TransformDecl(TL.getStarLoc(), OldCls));
6012 if (!NewCls)
6013 return QualType();
6014 }
6015
6016 QualType Result = TL.getType();
6017 if (getDerived().AlwaysRebuild() || PointeeType != T->getPointeeType() ||
6018 NewQualifierLoc.getNestedNameSpecifier() !=
6019 OldQualifierLoc.getNestedNameSpecifier() ||
6020 NewCls != OldCls) {
6021 CXXScopeSpec SS;
6022 SS.Adopt(NewQualifierLoc);
6023 Result = getDerived().RebuildMemberPointerType(PointeeType, SS, NewCls,
6024 TL.getStarLoc());
6025 if (Result.isNull())
6026 return QualType();
6027 }
6028
6029 // If we had to adjust the pointee type when building a member pointer, make
6030 // sure to push TypeLoc info for it.
6031 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
6032 if (MPT && PointeeType != MPT->getPointeeType()) {
6033 assert(isa<AdjustedType>(MPT->getPointeeType()));
6034 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
6035 }
6036
6038 NewTL.setSigilLoc(TL.getSigilLoc());
6039 NewTL.setQualifierLoc(NewQualifierLoc);
6040
6041 return Result;
6042}
6043
6044template<typename Derived>
6048 const ConstantArrayType *T = TL.getTypePtr();
6049 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6050 if (ElementType.isNull())
6051 return QualType();
6052
6053 // Prefer the expression from the TypeLoc; the other may have been uniqued.
6054 Expr *OldSize = TL.getSizeExpr();
6055 if (!OldSize)
6056 OldSize = const_cast<Expr*>(T->getSizeExpr());
6057 Expr *NewSize = nullptr;
6058 if (OldSize) {
6061 NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>();
6062 NewSize = SemaRef.ActOnConstantExpression(NewSize).get();
6063 }
6064
6065 QualType Result = TL.getType();
6066 if (getDerived().AlwaysRebuild() ||
6067 ElementType != T->getElementType() ||
6068 (T->getSizeExpr() && NewSize != OldSize)) {
6069 Result = getDerived().RebuildConstantArrayType(ElementType,
6070 T->getSizeModifier(),
6071 T->getSize(), NewSize,
6072 T->getIndexTypeCVRQualifiers(),
6073 TL.getBracketsRange());
6074 if (Result.isNull())
6075 return QualType();
6076 }
6077
6078 // We might have either a ConstantArrayType or a VariableArrayType now:
6079 // a ConstantArrayType is allowed to have an element type which is a
6080 // VariableArrayType if the type is dependent. Fortunately, all array
6081 // types have the same location layout.
6082 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6083 NewTL.setLBracketLoc(TL.getLBracketLoc());
6084 NewTL.setRBracketLoc(TL.getRBracketLoc());
6085 NewTL.setSizeExpr(NewSize);
6086
6087 return Result;
6088}
6089
6090template<typename Derived>
6092 TypeLocBuilder &TLB,
6094 const IncompleteArrayType *T = TL.getTypePtr();
6095 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6096 if (ElementType.isNull())
6097 return QualType();
6098
6099 QualType Result = TL.getType();
6100 if (getDerived().AlwaysRebuild() ||
6101 ElementType != T->getElementType()) {
6102 Result = getDerived().RebuildIncompleteArrayType(ElementType,
6103 T->getSizeModifier(),
6104 T->getIndexTypeCVRQualifiers(),
6105 TL.getBracketsRange());
6106 if (Result.isNull())
6107 return QualType();
6108 }
6109
6111 NewTL.setLBracketLoc(TL.getLBracketLoc());
6112 NewTL.setRBracketLoc(TL.getRBracketLoc());
6113 NewTL.setSizeExpr(nullptr);
6114
6115 return Result;
6116}
6117
6118template<typename Derived>
6122 const VariableArrayType *T = TL.getTypePtr();
6123 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6124 if (ElementType.isNull())
6125 return QualType();
6126
6127 ExprResult SizeResult;
6128 {
6131 SizeResult = getDerived().TransformExpr(T->getSizeExpr());
6132 }
6133 if (SizeResult.isInvalid())
6134 return QualType();
6135 SizeResult =
6136 SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false);
6137 if (SizeResult.isInvalid())
6138 return QualType();
6139
6140 Expr *Size = SizeResult.get();
6141
6142 QualType Result = TL.getType();
6143 if (getDerived().AlwaysRebuild() ||
6144 ElementType != T->getElementType() ||
6145 Size != T->getSizeExpr()) {
6146 Result = getDerived().RebuildVariableArrayType(ElementType,
6147 T->getSizeModifier(),
6148 Size,
6149 T->getIndexTypeCVRQualifiers(),
6150 TL.getBracketsRange());
6151 if (Result.isNull())
6152 return QualType();
6153 }
6154
6155 // We might have constant size array now, but fortunately it has the same
6156 // location layout.
6157 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6158 NewTL.setLBracketLoc(TL.getLBracketLoc());
6159 NewTL.setRBracketLoc(TL.getRBracketLoc());
6160 NewTL.setSizeExpr(Size);
6161
6162 return Result;
6163}
6164
6165template<typename Derived>
6169 const DependentSizedArrayType *T = TL.getTypePtr();
6170 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6171 if (ElementType.isNull())
6172 return QualType();
6173
6174 // Array bounds are constant expressions.
6177
6178 // If we have a VLA then it won't be a constant.
6179 SemaRef.ExprEvalContexts.back().InConditionallyConstantEvaluateContext = true;
6180
6181 // Prefer the expression from the TypeLoc; the other may have been uniqued.
6182 Expr *origSize = TL.getSizeExpr();
6183 if (!origSize) origSize = T->getSizeExpr();
6184
6185 ExprResult sizeResult
6186 = getDerived().TransformExpr(origSize);
6187 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
6188 if (sizeResult.isInvalid())
6189 return QualType();
6190
6191 Expr *size = sizeResult.get();
6192
6193 QualType Result = TL.getType();
6194 if (getDerived().AlwaysRebuild() ||
6195 ElementType != T->getElementType() ||
6196 size != origSize) {
6197 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
6198 T->getSizeModifier(),
6199 size,
6200 T->getIndexTypeCVRQualifiers(),
6201 TL.getBracketsRange());
6202 if (Result.isNull())
6203 return QualType();
6204 }
6205
6206 // We might have any sort of array type now, but fortunately they
6207 // all have the same location layout.
6208 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
6209 NewTL.setLBracketLoc(TL.getLBracketLoc());
6210 NewTL.setRBracketLoc(TL.getRBracketLoc());
6211 NewTL.setSizeExpr(size);
6212
6213 return Result;
6214}
6215
6216template <typename Derived>
6219 const DependentVectorType *T = TL.getTypePtr();
6220 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6221 if (ElementType.isNull())
6222 return QualType();
6223
6226
6227 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
6228 Size = SemaRef.ActOnConstantExpression(Size);
6229 if (Size.isInvalid())
6230 return QualType();
6231
6232 QualType Result = TL.getType();
6233 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6234 Size.get() != T->getSizeExpr()) {
6235 Result = getDerived().RebuildDependentVectorType(
6236 ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind());
6237 if (Result.isNull())
6238 return QualType();
6239 }
6240
6241 // Result might be dependent or not.
6244 TLB.push<DependentVectorTypeLoc>(Result);
6245 NewTL.setNameLoc(TL.getNameLoc());
6246 } else {
6247 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6248 NewTL.setNameLoc(TL.getNameLoc());
6249 }
6250
6251 return Result;
6252}
6253
6254template<typename Derived>
6256 TypeLocBuilder &TLB,
6258 const DependentSizedExtVectorType *T = TL.getTypePtr();
6259
6260 // FIXME: ext vector locs should be nested
6261 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6262 if (ElementType.isNull())
6263 return QualType();
6264
6265 // Vector sizes are constant expressions.
6268
6269 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
6270 Size = SemaRef.ActOnConstantExpression(Size);
6271 if (Size.isInvalid())
6272 return QualType();
6273
6274 QualType Result = TL.getType();
6275 if (getDerived().AlwaysRebuild() ||
6276 ElementType != T->getElementType() ||
6277 Size.get() != T->getSizeExpr()) {
6278 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
6279 Size.get(),
6280 T->getAttributeLoc());
6281 if (Result.isNull())
6282 return QualType();
6283 }
6284
6285 // Result might be dependent or not.
6289 NewTL.setNameLoc(TL.getNameLoc());
6290 } else {
6291 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6292 NewTL.setNameLoc(TL.getNameLoc());
6293 }
6294
6295 return Result;
6296}
6297
6298template <typename Derived>
6302 const ConstantMatrixType *T = TL.getTypePtr();
6303 QualType ElementType = getDerived().TransformType(T->getElementType());
6304 if (ElementType.isNull())
6305 return QualType();
6306
6307 QualType Result = TL.getType();
6308 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) {
6309 Result = getDerived().RebuildConstantMatrixType(
6310 ElementType, T->getNumRows(), T->getNumColumns(), TL.getAttrNameLoc());
6311 if (Result.isNull())
6312 return QualType();
6313 }
6314
6316 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6317 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6318 NewTL.setAttrRowOperand(TL.getAttrRowOperand());
6319 NewTL.setAttrColumnOperand(TL.getAttrColumnOperand());
6320
6321 return Result;
6322}
6323
6324template <typename Derived>
6327 const DependentSizedMatrixType *T = TL.getTypePtr();
6328
6329 QualType ElementType = getDerived().TransformType(T->getElementType());
6330 if (ElementType.isNull()) {
6331 return QualType();
6332 }
6333
6334 // Matrix dimensions are constant expressions.
6337
6338 Expr *origRows = TL.getAttrRowOperand();
6339 if (!origRows)
6340 origRows = T->getRowExpr();
6341 Expr *origColumns = TL.getAttrColumnOperand();
6342 if (!origColumns)
6343 origColumns = T->getColumnExpr();
6344
6345 ExprResult rowResult = getDerived().TransformExpr(origRows);
6346 rowResult = SemaRef.ActOnConstantExpression(rowResult);
6347 if (rowResult.isInvalid())
6348 return QualType();
6349
6350 ExprResult columnResult = getDerived().TransformExpr(origColumns);
6351 columnResult = SemaRef.ActOnConstantExpression(columnResult);
6352 if (columnResult.isInvalid())
6353 return QualType();
6354
6355 Expr *rows = rowResult.get();
6356 Expr *columns = columnResult.get();
6357
6358 QualType Result = TL.getType();
6359 if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() ||
6360 rows != origRows || columns != origColumns) {
6361 Result = getDerived().RebuildDependentSizedMatrixType(
6362 ElementType, rows, columns, T->getAttributeLoc());
6363
6364 if (Result.isNull())
6365 return QualType();
6366 }
6367
6368 // We might have any sort of matrix type now, but fortunately they
6369 // all have the same location layout.
6370 MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result);
6371 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6372 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6373 NewTL.setAttrRowOperand(rows);
6374 NewTL.setAttrColumnOperand(columns);
6375 return Result;
6376}
6377
6378template <typename Derived>
6381 const DependentAddressSpaceType *T = TL.getTypePtr();
6382
6384 getDerived().TransformType(TLB, TL.getPointeeTypeLoc());
6385
6386 if (pointeeType.isNull())
6387 return QualType();
6388
6389 // Address spaces are constant expressions.
6392
6393 ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr());
6394 AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace);
6395 if (AddrSpace.isInvalid())
6396 return QualType();
6397
6398 QualType Result = TL.getType();
6399 if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() ||
6400 AddrSpace.get() != T->getAddrSpaceExpr()) {
6401 Result = getDerived().RebuildDependentAddressSpaceType(
6402 pointeeType, AddrSpace.get(), T->getAttributeLoc());
6403 if (Result.isNull())
6404 return QualType();
6405 }
6406
6407 // Result might be dependent or not.
6411
6412 NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
6413 NewTL.setAttrExprOperand(TL.getAttrExprOperand());
6414 NewTL.setAttrNameLoc(TL.getAttrNameLoc());
6415
6416 } else {
6417 TLB.TypeWasModifiedSafely(Result);
6418 }
6419
6420 return Result;
6421}
6422
6423template <typename Derived>
6425 VectorTypeLoc TL) {
6426 const VectorType *T = TL.getTypePtr();
6427 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6428 if (ElementType.isNull())
6429 return QualType();
6430
6431 QualType Result = TL.getType();
6432 if (getDerived().AlwaysRebuild() ||
6433 ElementType != T->getElementType()) {
6434 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
6435 T->getVectorKind());
6436 if (Result.isNull())
6437 return QualType();
6438 }
6439
6440 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
6441 NewTL.setNameLoc(TL.getNameLoc());
6442
6443 return Result;
6444}
6445
6446template<typename Derived>
6448 ExtVectorTypeLoc TL) {
6449 const VectorType *T = TL.getTypePtr();
6450 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
6451 if (ElementType.isNull())
6452 return QualType();
6453
6454 QualType Result = TL.getType();
6455 if (getDerived().AlwaysRebuild() ||
6456 ElementType != T->getElementType()) {
6457 Result = getDerived().RebuildExtVectorType(ElementType,
6458 T->getNumElements(),
6459 /*FIXME*/ SourceLocation());
6460 if (Result.isNull())
6461 return QualType();
6462 }
6463
6464 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
6465 NewTL.setNameLoc(TL.getNameLoc());
6466
6467 return Result;
6468}
6469
6470template <typename Derived>
6472 ParmVarDecl *OldParm, int indexAdjustment, UnsignedOrNone NumExpansions,
6473 bool ExpectParameterPack) {
6474 TypeSourceInfo *OldTSI = OldParm->getTypeSourceInfo();
6475 TypeSourceInfo *NewTSI = nullptr;
6476
6477 if (NumExpansions && isa<PackExpansionType>(OldTSI->getType())) {
6478 // If we're substituting into a pack expansion type and we know the
6479 // length we want to expand to, just substitute for the pattern.
6480 TypeLoc OldTL = OldTSI->getTypeLoc();
6481 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
6482
6483 TypeLocBuilder TLB;
6484 TypeLoc NewTL = OldTSI->getTypeLoc();
6485 TLB.reserve(NewTL.getFullDataSize());
6486
6487 QualType Result = getDerived().TransformType(TLB,
6488 OldExpansionTL.getPatternLoc());
6489 if (Result.isNull())
6490 return nullptr;
6491
6493 OldExpansionTL.getPatternLoc().getSourceRange(),
6494 OldExpansionTL.getEllipsisLoc(),
6495 NumExpansions);
6496 if (Result.isNull())
6497 return nullptr;
6498
6499 PackExpansionTypeLoc NewExpansionTL
6500 = TLB.push<PackExpansionTypeLoc>(Result);
6501 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
6502 NewTSI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
6503 } else
6504 NewTSI = getDerived().TransformType(OldTSI);
6505 if (!NewTSI)
6506 return nullptr;
6507
6508 if (NewTSI == OldTSI && indexAdjustment == 0)
6509 return OldParm;
6510
6512 SemaRef.Context, OldParm->getDeclContext(), OldParm->getInnerLocStart(),
6513 OldParm->getLocation(), OldParm->getIdentifier(), NewTSI->getType(),
6514 NewTSI, OldParm->getStorageClass(),
6515 /* DefArg */ nullptr);
6516 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
6517 OldParm->getFunctionScopeIndex() + indexAdjustment);
6518 getDerived().transformedLocalDecl(OldParm, {newParm});
6519 return newParm;
6520}
6521
6522template <typename Derived>
6525 const QualType *ParamTypes,
6526 const FunctionProtoType::ExtParameterInfo *ParamInfos,
6527 SmallVectorImpl<QualType> &OutParamTypes,
6530 unsigned *LastParamTransformed) {
6531 int indexAdjustment = 0;
6532
6533 unsigned NumParams = Params.size();
6534 for (unsigned i = 0; i != NumParams; ++i) {
6535 if (LastParamTransformed)
6536 *LastParamTransformed = i;
6537 if (ParmVarDecl *OldParm = Params[i]) {
6538 assert(OldParm->getFunctionScopeIndex() == i);
6539
6540 UnsignedOrNone NumExpansions = std::nullopt;
6541 ParmVarDecl *NewParm = nullptr;
6542 if (OldParm->isParameterPack()) {
6543 // We have a function parameter pack that may need to be expanded.
6545
6546 // Find the parameter packs that could be expanded.
6547 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
6549 TypeLoc Pattern = ExpansionTL.getPatternLoc();
6550 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
6551
6552 // Determine whether we should expand the parameter packs.
6553 bool ShouldExpand = false;
6554 bool RetainExpansion = false;
6555 UnsignedOrNone OrigNumExpansions = std::nullopt;
6556 if (Unexpanded.size() > 0) {
6557 OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions();
6558 NumExpansions = OrigNumExpansions;
6560 ExpansionTL.getEllipsisLoc(), Pattern.getSourceRange(),
6561 Unexpanded, /*FailOnPackProducingTemplates=*/true,
6562 ShouldExpand, RetainExpansion, NumExpansions)) {
6563 return true;
6564 }
6565 } else {
6566#ifndef NDEBUG
6567 const AutoType *AT =
6568 Pattern.getType().getTypePtr()->getContainedAutoType();
6569 assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) &&
6570 "Could not find parameter packs or undeduced auto type!");
6571#endif
6572 }
6573
6574 if (ShouldExpand) {
6575 // Expand the function parameter pack into multiple, separate
6576 // parameters.
6577 getDerived().ExpandingFunctionParameterPack(OldParm);
6578 for (unsigned I = 0; I != *NumExpansions; ++I) {
6579 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6580 ParmVarDecl *NewParm
6581 = getDerived().TransformFunctionTypeParam(OldParm,
6582 indexAdjustment++,
6583 OrigNumExpansions,
6584 /*ExpectParameterPack=*/false);
6585 if (!NewParm)
6586 return true;
6587
6588 if (ParamInfos)
6589 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6590 OutParamTypes.push_back(NewParm->getType());
6591 if (PVars)
6592 PVars->push_back(NewParm);
6593 }
6594
6595 // If we're supposed to retain a pack expansion, do so by temporarily
6596 // forgetting the partially-substituted parameter pack.
6597 if (RetainExpansion) {
6598 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6599 ParmVarDecl *NewParm
6600 = getDerived().TransformFunctionTypeParam(OldParm,
6601 indexAdjustment++,
6602 OrigNumExpansions,
6603 /*ExpectParameterPack=*/false);
6604 if (!NewParm)
6605 return true;
6606
6607 if (ParamInfos)
6608 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6609 OutParamTypes.push_back(NewParm->getType());
6610 if (PVars)
6611 PVars->push_back(NewParm);
6612 }
6613
6614 // The next parameter should have the same adjustment as the
6615 // last thing we pushed, but we post-incremented indexAdjustment
6616 // on every push. Also, if we push nothing, the adjustment should
6617 // go down by one.
6618 indexAdjustment--;
6619
6620 // We're done with the pack expansion.
6621 continue;
6622 }
6623
6624 // We'll substitute the parameter now without expanding the pack
6625 // expansion.
6626 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6627 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
6628 indexAdjustment,
6629 NumExpansions,
6630 /*ExpectParameterPack=*/true);
6631 assert(NewParm->isParameterPack() &&
6632 "Parameter pack no longer a parameter pack after "
6633 "transformation.");
6634 } else {
6635 NewParm = getDerived().TransformFunctionTypeParam(
6636 OldParm, indexAdjustment, std::nullopt,
6637 /*ExpectParameterPack=*/false);
6638 }
6639
6640 if (!NewParm)
6641 return true;
6642
6643 if (ParamInfos)
6644 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6645 OutParamTypes.push_back(NewParm->getType());
6646 if (PVars)
6647 PVars->push_back(NewParm);
6648 continue;
6649 }
6650
6651 // Deal with the possibility that we don't have a parameter
6652 // declaration for this parameter.
6653 assert(ParamTypes);
6654 QualType OldType = ParamTypes[i];
6655 bool IsPackExpansion = false;
6656 UnsignedOrNone NumExpansions = std::nullopt;
6657 QualType NewType;
6658 if (const PackExpansionType *Expansion
6659 = dyn_cast<PackExpansionType>(OldType)) {
6660 // We have a function parameter pack that may need to be expanded.
6661 QualType Pattern = Expansion->getPattern();
6663 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
6664
6665 // Determine whether we should expand the parameter packs.
6666 bool ShouldExpand = false;
6667 bool RetainExpansion = false;
6669 Loc, SourceRange(), Unexpanded,
6670 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
6671 RetainExpansion, NumExpansions)) {
6672 return true;
6673 }
6674
6675 if (ShouldExpand) {
6676 // Expand the function parameter pack into multiple, separate
6677 // parameters.
6678 for (unsigned I = 0; I != *NumExpansions; ++I) {
6679 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
6680 QualType NewType = getDerived().TransformType(Pattern);
6681 if (NewType.isNull())
6682 return true;
6683
6684 if (NewType->containsUnexpandedParameterPack()) {
6685 NewType = getSema().getASTContext().getPackExpansionType(
6686 NewType, std::nullopt);
6687
6688 if (NewType.isNull())
6689 return true;
6690 }
6691
6692 if (ParamInfos)
6693 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6694 OutParamTypes.push_back(NewType);
6695 if (PVars)
6696 PVars->push_back(nullptr);
6697 }
6698
6699 // We're done with the pack expansion.
6700 continue;
6701 }
6702
6703 // If we're supposed to retain a pack expansion, do so by temporarily
6704 // forgetting the partially-substituted parameter pack.
6705 if (RetainExpansion) {
6706 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
6707 QualType NewType = getDerived().TransformType(Pattern);
6708 if (NewType.isNull())
6709 return true;
6710
6711 if (ParamInfos)
6712 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6713 OutParamTypes.push_back(NewType);
6714 if (PVars)
6715 PVars->push_back(nullptr);
6716 }
6717
6718 // We'll substitute the parameter now without expanding the pack
6719 // expansion.
6720 OldType = Expansion->getPattern();
6721 IsPackExpansion = true;
6722 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6723 NewType = getDerived().TransformType(OldType);
6724 } else {
6725 NewType = getDerived().TransformType(OldType);
6726 }
6727
6728 if (NewType.isNull())
6729 return true;
6730
6731 if (IsPackExpansion)
6732 NewType = getSema().Context.getPackExpansionType(NewType,
6733 NumExpansions);
6734
6735 if (ParamInfos)
6736 PInfos.set(OutParamTypes.size(), ParamInfos[i]);
6737 OutParamTypes.push_back(NewType);
6738 if (PVars)
6739 PVars->push_back(nullptr);
6740 }
6741
6742#ifndef NDEBUG
6743 if (PVars) {
6744 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
6745 if (ParmVarDecl *parm = (*PVars)[i])
6746 assert(parm->getFunctionScopeIndex() == i);
6747 }
6748#endif
6749
6750 return false;
6751}
6752
6753template<typename Derived>
6757 SmallVector<QualType, 4> ExceptionStorage;
6758 return getDerived().TransformFunctionProtoType(
6759 TLB, TL, nullptr, Qualifiers(),
6760 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
6761 return getDerived().TransformExceptionSpec(TL.getBeginLoc(), ESI,
6762 ExceptionStorage, Changed);
6763 });
6764}
6765
6766template<typename Derived> template<typename Fn>
6768 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
6769 Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) {
6770
6771 // Transform the parameters and return type.
6772 //
6773 // We are required to instantiate the params and return type in source order.
6774 // When the function has a trailing return type, we instantiate the
6775 // parameters before the return type, since the return type can then refer
6776 // to the parameters themselves (via decltype, sizeof, etc.).
6777 //
6778 SmallVector<QualType, 4> ParamTypes;
6780 Sema::ExtParameterInfoBuilder ExtParamInfos;
6781 const FunctionProtoType *T = TL.getTypePtr();
6782
6783 QualType ResultType;
6784
6785 if (T->hasTrailingReturn()) {
6787 TL.getBeginLoc(), TL.getParams(),
6789 T->getExtParameterInfosOrNull(),
6790 ParamTypes, &ParamDecls, ExtParamInfos))
6791 return QualType();
6792
6793 {
6794 // C++11 [expr.prim.general]p3:
6795 // If a declaration declares a member function or member function
6796 // template of a class X, the expression this is a prvalue of type
6797 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
6798 // and the end of the function-definition, member-declarator, or
6799 // declarator.
6800 auto *RD = dyn_cast<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6801 Sema::CXXThisScopeRAII ThisScope(
6802 SemaRef, !ThisContext && RD ? RD : ThisContext, ThisTypeQuals);
6803
6804 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6805 if (ResultType.isNull())
6806 return QualType();
6807 }
6808 }
6809 else {
6810 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
6811 if (ResultType.isNull())
6812 return QualType();
6813
6815 TL.getBeginLoc(), TL.getParams(),
6817 T->getExtParameterInfosOrNull(),
6818 ParamTypes, &ParamDecls, ExtParamInfos))
6819 return QualType();
6820 }
6821
6822 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
6823
6824 bool EPIChanged = false;
6825 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
6826 return QualType();
6827
6828 // Handle extended parameter information.
6829 if (auto NewExtParamInfos =
6830 ExtParamInfos.getPointerOrNull(ParamTypes.size())) {
6831 if (!EPI.ExtParameterInfos ||
6833 llvm::ArrayRef(NewExtParamInfos, ParamTypes.size())) {
6834 EPIChanged = true;
6835 }
6836 EPI.ExtParameterInfos = NewExtParamInfos;
6837 } else if (EPI.ExtParameterInfos) {
6838 EPIChanged = true;
6839 EPI.ExtParameterInfos = nullptr;
6840 }
6841
6842 // Transform any function effects with unevaluated conditions.
6843 // Hold this set in a local for the rest of this function, since EPI
6844 // may need to hold a FunctionEffectsRef pointing into it.
6845 std::optional<FunctionEffectSet> NewFX;
6846 if (ArrayRef FXConds = EPI.FunctionEffects.conditions(); !FXConds.empty()) {
6847 NewFX.emplace();
6850
6851 for (const FunctionEffectWithCondition &PrevEC : EPI.FunctionEffects) {
6852 FunctionEffectWithCondition NewEC = PrevEC;
6853 if (Expr *CondExpr = PrevEC.Cond.getCondition()) {
6854 ExprResult NewExpr = getDerived().TransformExpr(CondExpr);
6855 if (NewExpr.isInvalid())
6856 return QualType();
6857 std::optional<FunctionEffectMode> Mode =
6858 SemaRef.ActOnEffectExpression(NewExpr.get(), PrevEC.Effect.name());
6859 if (!Mode)
6860 return QualType();
6861
6862 // The condition expression has been transformed, and re-evaluated.
6863 // It may or may not have become constant.
6864 switch (*Mode) {
6866 NewEC.Cond = {};
6867 break;
6869 NewEC.Effect = FunctionEffect(PrevEC.Effect.oppositeKind());
6870 NewEC.Cond = {};
6871 break;
6873 NewEC.Cond = EffectConditionExpr(NewExpr.get());
6874 break;
6876 llvm_unreachable(
6877 "FunctionEffectMode::None shouldn't be possible here");
6878 }
6879 }
6880 if (!SemaRef.diagnoseConflictingFunctionEffect(*NewFX, NewEC,
6881 TL.getBeginLoc())) {
6883 NewFX->insert(NewEC, Errs);
6884 assert(Errs.empty());
6885 }
6886 }
6887 EPI.FunctionEffects = *NewFX;
6888 EPIChanged = true;
6889 }
6890
6891 QualType Result = TL.getType();
6892 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
6893 T->getParamTypes() != llvm::ArrayRef(ParamTypes) || EPIChanged) {
6894 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
6895 if (Result.isNull())
6896 return QualType();
6897 }
6898
6901 NewTL.setLParenLoc(TL.getLParenLoc());
6902 NewTL.setRParenLoc(TL.getRParenLoc());
6905 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
6906 NewTL.setParam(i, ParamDecls[i]);
6907
6908 return Result;
6909}
6910
6911template<typename Derived>
6914 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
6915 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
6916
6917 // Instantiate a dynamic noexcept expression, if any.
6918 if (isComputedNoexcept(ESI.Type)) {
6919 // Update this scrope because ContextDecl in Sema will be used in
6920 // TransformExpr.
6921 auto *Method = dyn_cast_if_present<CXXMethodDecl>(ESI.SourceTemplate);
6922 Sema::CXXThisScopeRAII ThisScope(
6923 SemaRef, Method ? Method->getParent() : nullptr,
6924 Method ? Method->getMethodQualifiers() : Qualifiers{},
6925 Method != nullptr);
6928 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
6929 if (NoexceptExpr.isInvalid())
6930 return true;
6931
6933 NoexceptExpr =
6934 getSema().ActOnNoexceptSpec(NoexceptExpr.get(), EST);
6935 if (NoexceptExpr.isInvalid())
6936 return true;
6937
6938 if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type)
6939 Changed = true;
6940 ESI.NoexceptExpr = NoexceptExpr.get();
6941 ESI.Type = EST;
6942 }
6943
6944 if (ESI.Type != EST_Dynamic)
6945 return false;
6946
6947 // Instantiate a dynamic exception specification's type.
6948 for (QualType T : ESI.Exceptions) {
6949 if (const PackExpansionType *PackExpansion =
6950 T->getAs<PackExpansionType>()) {
6951 Changed = true;
6952
6953 // We have a pack expansion. Instantiate it.
6955 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
6956 Unexpanded);
6957 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
6958
6959 // Determine whether the set of unexpanded parameter packs can and
6960 // should
6961 // be expanded.
6962 bool Expand = false;
6963 bool RetainExpansion = false;
6964 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
6965 // FIXME: Track the location of the ellipsis (and track source location
6966 // information for the types in the exception specification in general).
6968 Loc, SourceRange(), Unexpanded,
6969 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
6970 NumExpansions))
6971 return true;
6972
6973 if (!Expand) {
6974 // We can't expand this pack expansion into separate arguments yet;
6975 // just substitute into the pattern and create a new pack expansion
6976 // type.
6977 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
6978 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6979 if (U.isNull())
6980 return true;
6981
6982 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
6983 Exceptions.push_back(U);
6984 continue;
6985 }
6986
6987 // Substitute into the pack expansion pattern for each slice of the
6988 // pack.
6989 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
6990 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
6991
6992 QualType U = getDerived().TransformType(PackExpansion->getPattern());
6993 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
6994 return true;
6995
6996 Exceptions.push_back(U);
6997 }
6998 } else {
6999 QualType U = getDerived().TransformType(T);
7000 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
7001 return true;
7002 if (T != U)
7003 Changed = true;
7004
7005 Exceptions.push_back(U);
7006 }
7007 }
7008
7009 ESI.Exceptions = Exceptions;
7010 if (ESI.Exceptions.empty())
7011 ESI.Type = EST_DynamicNone;
7012 return false;
7013}
7014
7015template<typename Derived>
7017 TypeLocBuilder &TLB,
7019 const FunctionNoProtoType *T = TL.getTypePtr();
7020 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
7021 if (ResultType.isNull())
7022 return QualType();
7023
7024 QualType Result = TL.getType();
7025 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
7026 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
7027
7030 NewTL.setLParenLoc(TL.getLParenLoc());
7031 NewTL.setRParenLoc(TL.getRParenLoc());
7033
7034 return Result;
7035}
7036
7037template <typename Derived>
7038QualType TreeTransform<Derived>::TransformUnresolvedUsingType(
7039 TypeLocBuilder &TLB, UnresolvedUsingTypeLoc TL) {
7040
7041 const UnresolvedUsingType *T = TL.getTypePtr();
7042 bool Changed = false;
7043
7044 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7045 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
7046 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7047 if (!QualifierLoc)
7048 return QualType();
7049 Changed |= QualifierLoc != OldQualifierLoc;
7050 }
7051
7052 auto *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
7053 if (!D)
7054 return QualType();
7055 Changed |= D != T->getDecl();
7056
7057 QualType Result = TL.getType();
7058 if (getDerived().AlwaysRebuild() || Changed) {
7059 Result = getDerived().RebuildUnresolvedUsingType(
7060 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TL.getNameLoc(),
7061 D);
7062 if (Result.isNull())
7063 return QualType();
7064 }
7065
7067 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7068 QualifierLoc, TL.getNameLoc());
7069 else
7070 TLB.push<UnresolvedUsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7071 QualifierLoc, TL.getNameLoc());
7072 return Result;
7073}
7074
7075template <typename Derived>
7077 UsingTypeLoc TL) {
7078 const UsingType *T = TL.getTypePtr();
7079 bool Changed = false;
7080
7081 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7082 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
7083 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7084 if (!QualifierLoc)
7085 return QualType();
7086 Changed |= QualifierLoc != OldQualifierLoc;
7087 }
7088
7089 auto *D = cast_or_null<UsingShadowDecl>(
7090 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
7091 if (!D)
7092 return QualType();
7093 Changed |= D != T->getDecl();
7094
7095 QualType UnderlyingType = getDerived().TransformType(T->desugar());
7096 if (UnderlyingType.isNull())
7097 return QualType();
7098 Changed |= UnderlyingType != T->desugar();
7099
7100 QualType Result = TL.getType();
7101 if (getDerived().AlwaysRebuild() || Changed) {
7102 Result = getDerived().RebuildUsingType(
7103 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), D,
7104 UnderlyingType);
7105 if (Result.isNull())
7106 return QualType();
7107 }
7108 TLB.push<UsingTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(), QualifierLoc,
7109 TL.getNameLoc());
7110 return Result;
7111}
7112
7113template<typename Derived>
7115 TypedefTypeLoc TL) {
7116 const TypedefType *T = TL.getTypePtr();
7117 bool Changed = false;
7118
7119 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7120 if (NestedNameSpecifierLoc OldQualifierLoc = QualifierLoc) {
7121 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7122 if (!QualifierLoc)
7123 return QualType();
7124 Changed |= QualifierLoc != OldQualifierLoc;
7125 }
7126
7127 auto *Typedef = cast_or_null<TypedefNameDecl>(
7128 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
7129 if (!Typedef)
7130 return QualType();
7131 Changed |= Typedef != T->getDecl();
7132
7133 // FIXME: Transform the UnderlyingType if different from decl.
7134
7135 QualType Result = TL.getType();
7136 if (getDerived().AlwaysRebuild() || Changed) {
7137 Result = getDerived().RebuildTypedefType(
7138 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), Typedef);
7139 if (Result.isNull())
7140 return QualType();
7141 }
7142
7143 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
7144 QualifierLoc, TL.getNameLoc());
7145 return Result;
7146}
7147
7148template<typename Derived>
7150 TypeOfExprTypeLoc TL) {
7151 // typeof expressions are not potentially evaluated contexts
7155
7156 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
7157 if (E.isInvalid())
7158 return QualType();
7159
7160 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
7161 if (E.isInvalid())
7162 return QualType();
7163
7164 QualType Result = TL.getType();
7166 if (getDerived().AlwaysRebuild() || E.get() != TL.getUnderlyingExpr()) {
7167 Result =
7168 getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc(), Kind);
7169 if (Result.isNull())
7170 return QualType();
7171 }
7172
7173 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
7174 NewTL.setTypeofLoc(TL.getTypeofLoc());
7175 NewTL.setLParenLoc(TL.getLParenLoc());
7176 NewTL.setRParenLoc(TL.getRParenLoc());
7177
7178 return Result;
7179}
7180
7181template<typename Derived>
7183 TypeOfTypeLoc TL) {
7184 TypeSourceInfo* Old_Under_TI = TL.getUnmodifiedTInfo();
7185 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
7186 if (!New_Under_TI)
7187 return QualType();
7188
7189 QualType Result = TL.getType();
7190 TypeOfKind Kind = Result->castAs<TypeOfType>()->getKind();
7191 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
7192 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType(), Kind);
7193 if (Result.isNull())
7194 return QualType();
7195 }
7196
7197 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
7198 NewTL.setTypeofLoc(TL.getTypeofLoc());
7199 NewTL.setLParenLoc(TL.getLParenLoc());
7200 NewTL.setRParenLoc(TL.getRParenLoc());
7201 NewTL.setUnmodifiedTInfo(New_Under_TI);
7202
7203 return Result;
7204}
7205
7206template<typename Derived>
7208 DecltypeTypeLoc TL) {
7209 const DecltypeType *T = TL.getTypePtr();
7210
7211 // decltype expressions are not potentially evaluated contexts
7215
7216 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
7217 if (E.isInvalid())
7218 return QualType();
7219
7220 E = getSema().ActOnDecltypeExpression(E.get());
7221 if (E.isInvalid())
7222 return QualType();
7223
7224 QualType Result = TL.getType();
7225 if (getDerived().AlwaysRebuild() ||
7226 E.get() != T->getUnderlyingExpr()) {
7227 Result = getDerived().RebuildDecltypeType(E.get(), TL.getDecltypeLoc());
7228 if (Result.isNull())
7229 return QualType();
7230 }
7231 else E.get();
7232
7233 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
7234 NewTL.setDecltypeLoc(TL.getDecltypeLoc());
7235 NewTL.setRParenLoc(TL.getRParenLoc());
7236 return Result;
7237}
7238
7239template <typename Derived>
7243 // Transform the index
7244 ExprResult IndexExpr;
7245 {
7246 EnterExpressionEvaluationContext ConstantContext(
7248
7249 IndexExpr = getDerived().TransformExpr(TL.getIndexExpr());
7250 if (IndexExpr.isInvalid())
7251 return QualType();
7252 }
7253 QualType Pattern = TL.getPattern();
7254
7255 const PackIndexingType *PIT = TL.getTypePtr();
7256 SmallVector<QualType, 5> SubtitutedTypes;
7257 llvm::ArrayRef<QualType> Types = PIT->getExpansions();
7258
7259 bool NotYetExpanded = Types.empty();
7260 bool FullySubstituted = true;
7261
7262 if (Types.empty() && !PIT->expandsToEmptyPack())
7263 Types = llvm::ArrayRef<QualType>(&Pattern, 1);
7264
7265 for (QualType T : Types) {
7266 if (!T->containsUnexpandedParameterPack()) {
7267 QualType Transformed = getDerived().TransformType(T);
7268 if (Transformed.isNull())
7269 return QualType();
7270 SubtitutedTypes.push_back(Transformed);
7271 continue;
7272 }
7273
7275 getSema().collectUnexpandedParameterPacks(T, Unexpanded);
7276 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
7277 // Determine whether the set of unexpanded parameter packs can and should
7278 // be expanded.
7279 bool ShouldExpand = true;
7280 bool RetainExpansion = false;
7281 UnsignedOrNone NumExpansions = std::nullopt;
7282 if (getDerived().TryExpandParameterPacks(
7283 TL.getEllipsisLoc(), SourceRange(), Unexpanded,
7284 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
7285 RetainExpansion, NumExpansions))
7286 return QualType();
7287 if (!ShouldExpand) {
7288 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7289 // FIXME: should we keep TypeLoc for individual expansions in
7290 // PackIndexingTypeLoc?
7291 TypeSourceInfo *TI =
7292 SemaRef.getASTContext().getTrivialTypeSourceInfo(T, TL.getBeginLoc());
7293 QualType Pack = getDerived().TransformType(TLB, TI->getTypeLoc());
7294 if (Pack.isNull())
7295 return QualType();
7296 if (NotYetExpanded) {
7297 FullySubstituted = false;
7298 QualType Out = getDerived().RebuildPackIndexingType(
7299 Pack, IndexExpr.get(), TL.getBeginLoc(), FullySubstituted);
7300 if (Out.isNull())
7301 return QualType();
7302
7304 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7305 return Out;
7306 }
7307 SubtitutedTypes.push_back(Pack);
7308 continue;
7309 }
7310 for (unsigned I = 0; I != *NumExpansions; ++I) {
7311 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
7312 QualType Out = getDerived().TransformType(T);
7313 if (Out.isNull())
7314 return QualType();
7315 SubtitutedTypes.push_back(Out);
7316 FullySubstituted &= !Out->containsUnexpandedParameterPack();
7317 }
7318 // If we're supposed to retain a pack expansion, do so by temporarily
7319 // forgetting the partially-substituted parameter pack.
7320 if (RetainExpansion) {
7321 FullySubstituted = false;
7322 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
7323 QualType Out = getDerived().TransformType(T);
7324 if (Out.isNull())
7325 return QualType();
7326 SubtitutedTypes.push_back(Out);
7327 }
7328 }
7329
7330 // A pack indexing type can appear in a larger pack expansion,
7331 // e.g. `Pack...[pack_of_indexes]...`
7332 // so we need to temporarily disable substitution of pack elements
7333 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
7334 QualType Result = getDerived().TransformType(TLB, TL.getPatternLoc());
7335
7336 QualType Out = getDerived().RebuildPackIndexingType(
7337 Result, IndexExpr.get(), TL.getBeginLoc(), FullySubstituted,
7338 SubtitutedTypes);
7339 if (Out.isNull())
7340 return Out;
7341
7343 Loc.setEllipsisLoc(TL.getEllipsisLoc());
7344 return Out;
7345}
7346
7347template<typename Derived>
7349 TypeLocBuilder &TLB,
7351 QualType Result = TL.getType();
7352 TypeSourceInfo *NewBaseTSI = TL.getUnderlyingTInfo();
7353 if (Result->isDependentType()) {
7354 const UnaryTransformType *T = TL.getTypePtr();
7355
7356 NewBaseTSI = getDerived().TransformType(TL.getUnderlyingTInfo());
7357 if (!NewBaseTSI)
7358 return QualType();
7359 QualType NewBase = NewBaseTSI->getType();
7360
7361 Result = getDerived().RebuildUnaryTransformType(NewBase,
7362 T->getUTTKind(),
7363 TL.getKWLoc());
7364 if (Result.isNull())
7365 return QualType();
7366 }
7367
7369 NewTL.setKWLoc(TL.getKWLoc());
7370 NewTL.setParensRange(TL.getParensRange());
7371 NewTL.setUnderlyingTInfo(NewBaseTSI);
7372 return Result;
7373}
7374
7375template<typename Derived>
7378 const DeducedTemplateSpecializationType *T = TL.getTypePtr();
7379
7380 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7381 TemplateName TemplateName = getDerived().TransformTemplateName(
7382 QualifierLoc, /*TemplateKELoc=*/SourceLocation(), T->getTemplateName(),
7383 TL.getTemplateNameLoc());
7384 if (TemplateName.isNull())
7385 return QualType();
7386
7387 QualType OldDeduced = T->getDeducedType();
7388 QualType NewDeduced;
7389 if (!OldDeduced.isNull()) {
7390 NewDeduced = getDerived().TransformType(OldDeduced);
7391 if (NewDeduced.isNull())
7392 return QualType();
7393 }
7394
7395 QualType Result = getDerived().RebuildDeducedTemplateSpecializationType(
7396 NewDeduced.isNull() ? DeducedKind::Undeduced : DeducedKind::Deduced,
7397 NewDeduced, T->getKeyword(), TemplateName);
7398 if (Result.isNull())
7399 return QualType();
7400
7401 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
7402 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
7403 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
7404 NewTL.setQualifierLoc(QualifierLoc);
7405 return Result;
7406}
7407
7408template <typename Derived>
7410 TagTypeLoc TL) {
7411 const TagType *T = TL.getTypePtr();
7412
7413 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7414 if (QualifierLoc) {
7415 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
7416 if (!QualifierLoc)
7417 return QualType();
7418 }
7419
7420 auto *TD = cast_or_null<TagDecl>(
7421 getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()));
7422 if (!TD)
7423 return QualType();
7424
7425 QualType Result = TL.getType();
7426 if (getDerived().AlwaysRebuild() || QualifierLoc != TL.getQualifierLoc() ||
7427 TD != T->getDecl()) {
7428 if (T->isCanonicalUnqualified())
7429 Result = getDerived().RebuildCanonicalTagType(TD);
7430 else
7431 Result = getDerived().RebuildTagType(
7432 T->getKeyword(), QualifierLoc.getNestedNameSpecifier(), TD);
7433 if (Result.isNull())
7434 return QualType();
7435 }
7436
7437 TagTypeLoc NewTL = TLB.push<TagTypeLoc>(Result);
7439 NewTL.setQualifierLoc(QualifierLoc);
7440 NewTL.setNameLoc(TL.getNameLoc());
7441
7442 return Result;
7443}
7444
7445template <typename Derived>
7447 EnumTypeLoc TL) {
7448 return getDerived().TransformTagType(TLB, TL);
7449}
7450
7451template <typename Derived>
7452QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
7453 RecordTypeLoc TL) {
7454 return getDerived().TransformTagType(TLB, TL);
7455}
7456
7457template<typename Derived>
7459 TypeLocBuilder &TLB,
7461 return getDerived().TransformTagType(TLB, TL);
7462}
7463
7464template<typename Derived>
7466 TypeLocBuilder &TLB,
7468 return getDerived().TransformTemplateTypeParmType(
7469 TLB, TL,
7470 /*SuppressObjCLifetime=*/false);
7471}
7472
7473template <typename Derived>
7475 TypeLocBuilder &TLB, TemplateTypeParmTypeLoc TL, bool) {
7476 return TransformTypeSpecType(TLB, TL);
7477}
7478
7479template<typename Derived>
7480QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
7481 TypeLocBuilder &TLB,
7482 SubstTemplateTypeParmTypeLoc TL) {
7483 const SubstTemplateTypeParmType *T = TL.getTypePtr();
7484
7485 Decl *NewReplaced =
7486 getDerived().TransformDecl(TL.getNameLoc(), T->getAssociatedDecl());
7487
7488 // Substitute into the replacement type, which itself might involve something
7489 // that needs to be transformed. This only tends to occur with default
7490 // template arguments of template template parameters.
7491 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
7492 QualType Replacement = getDerived().TransformType(T->getReplacementType());
7493 if (Replacement.isNull())
7494 return QualType();
7495
7496 QualType Result = SemaRef.Context.getSubstTemplateTypeParmType(
7497 Replacement, NewReplaced, T->getIndex(), T->getPackIndex(),
7498 T->getFinal());
7499
7500 // Propagate type-source information.
7501 SubstTemplateTypeParmTypeLoc NewTL
7502 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
7503 NewTL.setNameLoc(TL.getNameLoc());
7504 return Result;
7505
7506}
7507template <typename Derived>
7510 return TransformTypeSpecType(TLB, TL);
7511}
7512
7513template<typename Derived>
7515 TypeLocBuilder &TLB,
7517 return getDerived().TransformSubstTemplateTypeParmPackType(
7518 TLB, TL, /*SuppressObjCLifetime=*/false);
7519}
7520
7521template <typename Derived>
7524 return TransformTypeSpecType(TLB, TL);
7525}
7526
7527template<typename Derived>
7528QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
7529 AtomicTypeLoc TL) {
7530 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7531 if (ValueType.isNull())
7532 return QualType();
7533
7534 QualType Result = TL.getType();
7535 if (getDerived().AlwaysRebuild() ||
7536 ValueType != TL.getValueLoc().getType()) {
7537 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
7538 if (Result.isNull())
7539 return QualType();
7540 }
7541
7542 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
7543 NewTL.setKWLoc(TL.getKWLoc());
7544 NewTL.setLParenLoc(TL.getLParenLoc());
7545 NewTL.setRParenLoc(TL.getRParenLoc());
7546
7547 return Result;
7548}
7549
7550template <typename Derived>
7552 PipeTypeLoc TL) {
7553 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
7554 if (ValueType.isNull())
7555 return QualType();
7556
7557 QualType Result = TL.getType();
7558 if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) {
7559 const PipeType *PT = Result->castAs<PipeType>();
7560 bool isReadPipe = PT->isReadOnly();
7561 Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe);
7562 if (Result.isNull())
7563 return QualType();
7564 }
7565
7566 PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result);
7567 NewTL.setKWLoc(TL.getKWLoc());
7568
7569 return Result;
7570}
7571
7572template <typename Derived>
7574 BitIntTypeLoc TL) {
7575 const BitIntType *EIT = TL.getTypePtr();
7576 QualType Result = TL.getType();
7577
7578 if (getDerived().AlwaysRebuild()) {
7579 Result = getDerived().RebuildBitIntType(EIT->isUnsigned(),
7580 EIT->getNumBits(), TL.getNameLoc());
7581 if (Result.isNull())
7582 return QualType();
7583 }
7584
7585 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7586 NewTL.setNameLoc(TL.getNameLoc());
7587 return Result;
7588}
7589
7590template <typename Derived>
7593 const DependentBitIntType *EIT = TL.getTypePtr();
7594
7597 ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr());
7598 BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr);
7599
7600 if (BitsExpr.isInvalid())
7601 return QualType();
7602
7603 QualType Result = TL.getType();
7604
7605 if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) {
7606 Result = getDerived().RebuildDependentBitIntType(
7607 EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc());
7608
7609 if (Result.isNull())
7610 return QualType();
7611 }
7612
7615 NewTL.setNameLoc(TL.getNameLoc());
7616 } else {
7617 BitIntTypeLoc NewTL = TLB.push<BitIntTypeLoc>(Result);
7618 NewTL.setNameLoc(TL.getNameLoc());
7619 }
7620 return Result;
7621}
7622
7623template <typename Derived>
7626 llvm_unreachable("This type does not need to be transformed.");
7627}
7628
7629 /// Simple iterator that traverses the template arguments in a
7630 /// container that provides a \c getArgLoc() member function.
7631 ///
7632 /// This iterator is intended to be used with the iterator form of
7633 /// \c TreeTransform<Derived>::TransformTemplateArguments().
7634 template<typename ArgLocContainer>
7636 ArgLocContainer *Container;
7637 unsigned Index;
7638
7639 public:
7642 typedef int difference_type;
7643 typedef std::input_iterator_tag iterator_category;
7644
7645 class pointer {
7647
7648 public:
7649 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
7650
7652 return &Arg;
7653 }
7654 };
7655
7656
7658
7659 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
7660 unsigned Index)
7661 : Container(&Container), Index(Index) { }
7662
7664 ++Index;
7665 return *this;
7666 }
7667
7670 ++(*this);
7671 return Old;
7672 }
7673
7675 return Container->getArgLoc(Index);
7676 }
7677
7679 return pointer(Container->getArgLoc(Index));
7680 }
7681
7684 return X.Container == Y.Container && X.Index == Y.Index;
7685 }
7686
7689 return !(X == Y);
7690 }
7691 };
7692
7693template<typename Derived>
7694QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
7695 AutoTypeLoc TL) {
7696 const AutoType *T = TL.getTypePtr();
7697 QualType OldDeduced = T->getDeducedType();
7698 QualType NewDeduced;
7699 if (!OldDeduced.isNull()) {
7700 NewDeduced = getDerived().TransformType(OldDeduced);
7701 if (NewDeduced.isNull())
7702 return QualType();
7703 }
7704
7705 TemplateName NewCD;
7706 TemplateArgumentListInfo NewTemplateArgs;
7707 NestedNameSpecifierLoc NewNestedNameSpec;
7708 if (T->isConstrained()) {
7709 assert(TL.getConceptReference());
7710 NewCD = getDerived().TransformConceptTemplateName(
7711 T->getTypeConstraintConcept(), TL.getConceptNameLoc());
7712 if (NewCD.isNull())
7713 return QualType();
7714
7715 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7716 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7718 if (getDerived().TransformTemplateArguments(
7719 ArgIterator(TL, 0), ArgIterator(TL, TL.getNumArgs()),
7720 NewTemplateArgs))
7721 return QualType();
7722
7723 if (TL.getNestedNameSpecifierLoc()) {
7724 NewNestedNameSpec
7725 = getDerived().TransformNestedNameSpecifierLoc(
7726 TL.getNestedNameSpecifierLoc());
7727 if (!NewNestedNameSpec)
7728 return QualType();
7729 }
7730 }
7731
7732 QualType Result = TL.getType();
7733 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
7734 T->isDependentType() || T->isConstrained()) {
7735 // FIXME: Maybe don't rebuild if all template arguments are the same.
7737 NewArgList.reserve(NewTemplateArgs.size());
7738 for (const auto &ArgLoc : NewTemplateArgs.arguments())
7739 NewArgList.push_back(ArgLoc.getArgument());
7740 Result = getDerived().RebuildAutoType(
7741 NewDeduced.isNull() ? DeducedKind::Undeduced : DeducedKind::Deduced,
7742 NewDeduced, T->getKeyword(), NewCD, NewArgList);
7743 if (Result.isNull())
7744 return QualType();
7745 }
7746
7747 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
7748 NewTL.setNameLoc(TL.getNameLoc());
7749 NewTL.setRParenLoc(TL.getRParenLoc());
7750 NewTL.setConceptReference(nullptr);
7751
7752 if (T->isConstrained()) {
7753 DeclarationName ConceptName =
7754 SemaRef.Context
7755 .getNameForTemplate(TL.getTypePtr()->getTypeConstraintConcept(),
7756 TL.getConceptNameLoc())
7757 .getName();
7759 DeclarationNameInfo(ConceptName, TL.getConceptNameLoc(), ConceptName);
7760 auto *CR = ConceptReference::Create(
7761 SemaRef.Context, NewNestedNameSpec, TL.getTemplateKWLoc(), DNI,
7762 TL.getFoundDecl(), TL.getTypePtr()->getTypeConstraintConcept(),
7763 ASTTemplateArgumentListInfo::Create(SemaRef.Context, NewTemplateArgs));
7764 NewTL.setConceptReference(CR);
7765 }
7766
7767 return Result;
7768}
7769
7770template <typename Derived>
7773 return getDerived().TransformTemplateSpecializationType(
7774 TLB, TL, /*ObjectType=*/QualType(), /*FirstQualifierInScope=*/nullptr,
7775 /*AllowInjectedClassName=*/false);
7776}
7777
7778template <typename Derived>
7781 NamedDecl *FirstQualifierInScope, bool AllowInjectedClassName) {
7782 const TemplateSpecializationType *T = TL.getTypePtr();
7783
7784 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
7785 TemplateName Template = getDerived().TransformTemplateName(
7786 QualifierLoc, TL.getTemplateKeywordLoc(), T->getTemplateName(),
7787 TL.getTemplateNameLoc(), ObjectType, FirstQualifierInScope,
7788 AllowInjectedClassName);
7789 if (Template.isNull())
7790 return QualType();
7791
7792 TemplateArgumentListInfo NewTemplateArgs;
7793 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
7794 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
7796 ArgIterator;
7797 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
7798 ArgIterator(TL, TL.getNumArgs()),
7799 NewTemplateArgs))
7800 return QualType();
7801
7802 // This needs to be rebuilt if either the arguments changed, or if the
7803 // original template changed. If the template changed, and even if the
7804 // arguments didn't change, these arguments might not correspond to their
7805 // respective parameters, therefore needing conversions.
7806 QualType Result = getDerived().RebuildTemplateSpecializationType(
7807 TL.getTypePtr()->getKeyword(), Template, TL.getTemplateNameLoc(),
7808 NewTemplateArgs);
7809
7810 if (!Result.isNull()) {
7812 TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getTemplateKeywordLoc(),
7813 TL.getTemplateNameLoc(), NewTemplateArgs);
7814 }
7815
7816 return Result;
7817}
7818
7819template <typename Derived>
7821 AttributedTypeLoc TL) {
7822 const AttributedType *oldType = TL.getTypePtr();
7823 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
7824 if (modifiedType.isNull())
7825 return QualType();
7826
7827 // HLSL: re-validate matrix-layout markers after substitution. If the
7828 // post-substitution type is no longer a matrix, diagnose now.
7829 if (SemaRef.getLangOpts().HLSL &&
7831 oldType->getAttrKind(), modifiedType,
7832 TL.getAttr() ? TL.getAttr()->getLocation()
7833 : TL.getModifiedLoc().getBeginLoc()))
7834 return QualType();
7835
7836 // oldAttr can be null if we started with a QualType rather than a TypeLoc.
7837 const Attr *oldAttr = TL.getAttr();
7838 const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr;
7839 if (oldAttr && !newAttr)
7840 return QualType();
7841
7842 QualType result = TL.getType();
7843
7844 // FIXME: dependent operand expressions?
7845 if (getDerived().AlwaysRebuild() ||
7846 modifiedType != oldType->getModifiedType()) {
7847 // If the equivalent type is equal to the modified type, we don't want to
7848 // transform it as well because:
7849 //
7850 // 1. The transformation would yield the same result and is therefore
7851 // superfluous, and
7852 //
7853 // 2. Transforming the same type twice can cause problems, e.g. if it
7854 // is a FunctionProtoType, we may end up instantiating the function
7855 // parameters twice, which causes an assertion since the parameters
7856 // are already bound to their counterparts in the template for this
7857 // instantiation.
7858 //
7859 QualType equivalentType = modifiedType;
7860 if (TL.getModifiedLoc().getType() != TL.getEquivalentTypeLoc().getType()) {
7861 TypeLocBuilder AuxiliaryTLB;
7862 AuxiliaryTLB.reserve(TL.getFullDataSize());
7863 equivalentType =
7864 getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
7865 if (equivalentType.isNull())
7866 return QualType();
7867 }
7868
7869 if (SemaRef.getLangOpts().HLSL) {
7870 if (oldType->getAttrKind() == attr::HLSLRowMajor)
7871 equivalentType = SemaRef.Context.getMatrixTypeWithLayout(
7872 equivalentType, MatrixType::LayoutKind::RowMajor);
7873 else if (oldType->getAttrKind() == attr::HLSLColumnMajor)
7874 equivalentType = SemaRef.Context.getMatrixTypeWithLayout(
7875 equivalentType, MatrixType::LayoutKind::ColumnMajor);
7876 }
7877
7878 // Check whether we can add nullability; it is only represented as
7879 // type sugar, and therefore cannot be diagnosed in any other way.
7880 if (auto nullability = oldType->getImmediateNullability()) {
7881 if (!modifiedType->canHaveNullability()) {
7882 SemaRef.Diag((TL.getAttr() ? TL.getAttr()->getLocation()
7883 : TL.getModifiedLoc().getBeginLoc()),
7884 diag::err_nullability_nonpointer)
7885 << DiagNullabilityKind(*nullability, false) << modifiedType;
7886 return QualType();
7887 }
7888 }
7889
7890 result = SemaRef.Context.getAttributedType(TL.getAttrKind(),
7891 modifiedType,
7892 equivalentType,
7893 TL.getAttr());
7894 }
7895
7896 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
7897 newTL.setAttr(newAttr);
7898 return result;
7899}
7900
7901template <typename Derived>
7904 const CountAttributedType *OldTy = TL.getTypePtr();
7905 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7906 if (InnerTy.isNull())
7907 return QualType();
7908
7909 Expr *OldCount = TL.getCountExpr();
7910 Expr *NewCount = nullptr;
7911 if (OldCount) {
7912 ExprResult CountResult = getDerived().TransformExpr(OldCount);
7913 if (CountResult.isInvalid())
7914 return QualType();
7915 NewCount = CountResult.get();
7916 }
7917
7918 QualType Result = TL.getType();
7919 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->desugar() ||
7920 OldCount != NewCount) {
7921 // Currently, CountAttributedType can only wrap incomplete array types.
7923 InnerTy, NewCount, OldTy->isCountInBytes(), OldTy->isOrNull());
7924 }
7925
7926 TLB.push<CountAttributedTypeLoc>(Result);
7927 return Result;
7928}
7929
7930template <typename Derived>
7934 const LateParsedAttrType *OldTy = TL.getTypePtr();
7935 QualType InnerTy = getDerived().TransformType(TLB, TL.getInnerLoc());
7936 if (InnerTy.isNull())
7937 return QualType();
7938
7939 QualType Result = TL.getType();
7940 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->getWrappedType()) {
7942 InnerTy, OldTy->getLateParsedAttribute());
7943 }
7944
7946 newTL.setAttrNameLoc(TL.getAttrNameLoc());
7947 return Result;
7948}
7949
7950template <typename Derived>
7953 // The BTFTagAttributedType is available for C only.
7954 llvm_unreachable("Unexpected TreeTransform for BTFTagAttributedType");
7955}
7956
7957template <typename Derived>
7960 const OverflowBehaviorType *OldTy = TL.getTypePtr();
7961 QualType InnerTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7962 if (InnerTy.isNull())
7963 return QualType();
7964
7965 QualType Result = TL.getType();
7966 if (getDerived().AlwaysRebuild() || InnerTy != OldTy->getUnderlyingType()) {
7967 Result = SemaRef.Context.getOverflowBehaviorType(OldTy->getBehaviorKind(),
7968 InnerTy);
7969 if (Result.isNull())
7970 return QualType();
7971 }
7972
7974 NewTL.initializeLocal(SemaRef.Context, TL.getAttrLoc());
7975 return Result;
7976}
7977
7978template <typename Derived>
7981
7982 const HLSLAttributedResourceType *oldType = TL.getTypePtr();
7983
7984 QualType WrappedTy = getDerived().TransformType(TLB, TL.getWrappedLoc());
7985 if (WrappedTy.isNull())
7986 return QualType();
7987
7988 QualType ContainedTy = QualType();
7989 QualType OldContainedTy = oldType->getContainedType();
7990 TypeSourceInfo *ContainedTSI = nullptr;
7991 if (!OldContainedTy.isNull()) {
7992 TypeSourceInfo *oldContainedTSI = TL.getContainedTypeSourceInfo();
7993 if (!oldContainedTSI)
7994 oldContainedTSI = getSema().getASTContext().getTrivialTypeSourceInfo(
7995 OldContainedTy, SourceLocation());
7996 ContainedTSI = getDerived().TransformType(oldContainedTSI);
7997 if (!ContainedTSI)
7998 return QualType();
7999 ContainedTy = ContainedTSI->getType();
8000 }
8001
8002 HLSLAttributedResourceType::Attributes Attrs = oldType->getAttrs();
8003 if (Attrs.SampleCountExpr) {
8004 ExprResult SampleCountResult =
8005 getDerived().TransformExpr(Attrs.SampleCountExpr);
8006 if (SampleCountResult.isInvalid())
8007 return QualType();
8008 Attrs.SampleCountExpr = SampleCountResult.get();
8009 }
8010
8011 QualType Result = TL.getType();
8012 if (getDerived().AlwaysRebuild() || WrappedTy != oldType->getWrappedType() ||
8013 ContainedTy != oldType->getContainedType() ||
8014 Attrs.SampleCountExpr != oldType->getSampleCountExpr()) {
8015 Result = SemaRef.Context.getHLSLAttributedResourceType(WrappedTy,
8016 ContainedTy, Attrs);
8017 }
8018
8021 NewTL.setSourceRange(TL.getLocalSourceRange());
8022 NewTL.setContainedTypeSourceInfo(ContainedTSI);
8023 return Result;
8024}
8025
8026template <typename Derived>
8029 // No transformations needed.
8030 return TL.getType();
8031}
8032
8033template<typename Derived>
8036 ParenTypeLoc TL) {
8037 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
8038 if (Inner.isNull())
8039 return QualType();
8040
8041 QualType Result = TL.getType();
8042 if (getDerived().AlwaysRebuild() ||
8043 Inner != TL.getInnerLoc().getType()) {
8044 Result = getDerived().RebuildParenType(Inner);
8045 if (Result.isNull())
8046 return QualType();
8047 }
8048
8049 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
8050 NewTL.setLParenLoc(TL.getLParenLoc());
8051 NewTL.setRParenLoc(TL.getRParenLoc());
8052 return Result;
8053}
8054
8055template <typename Derived>
8059 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
8060 if (Inner.isNull())
8061 return QualType();
8062
8063 QualType Result = TL.getType();
8064 if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) {
8065 Result =
8066 getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier());
8067 if (Result.isNull())
8068 return QualType();
8069 }
8070
8072 NewTL.setExpansionLoc(TL.getExpansionLoc());
8073 return Result;
8074}
8075
8076template<typename Derived>
8077QualType TreeTransform<Derived>::TransformDependentNameType(
8079 return TransformDependentNameType(TLB, TL, false);
8080}
8081
8082template <typename Derived>
8083QualType TreeTransform<Derived>::TransformDependentNameType(
8084 TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext,
8085 QualType ObjectType, NamedDecl *UnqualLookup) {
8086 const DependentNameType *T = TL.getTypePtr();
8087
8088 NestedNameSpecifierLoc QualifierLoc = TL.getQualifierLoc();
8089 if (QualifierLoc) {
8090 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(
8091 QualifierLoc, ObjectType, UnqualLookup);
8092 if (!QualifierLoc)
8093 return QualType();
8094 } else {
8095 assert((ObjectType.isNull() && !UnqualLookup) &&
8096 "must be transformed by TransformNestedNameSpecifierLoc");
8097 }
8098
8100 = getDerived().RebuildDependentNameType(T->getKeyword(),
8101 TL.getElaboratedKeywordLoc(),
8102 QualifierLoc,
8103 T->getIdentifier(),
8104 TL.getNameLoc(),
8105 DeducedTSTContext);
8106 if (Result.isNull())
8107 return QualType();
8108
8109 if (isa<TagType>(Result)) {
8110 auto NewTL = TLB.push<TagTypeLoc>(Result);
8111 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
8112 NewTL.setQualifierLoc(QualifierLoc);
8113 NewTL.setNameLoc(TL.getNameLoc());
8115 auto NewTL = TLB.push<DeducedTemplateSpecializationTypeLoc>(Result);
8116 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
8117 NewTL.setTemplateNameLoc(TL.getNameLoc());
8118 NewTL.setQualifierLoc(QualifierLoc);
8119 } else if (isa<TypedefType>(Result)) {
8120 TLB.push<TypedefTypeLoc>(Result).set(TL.getElaboratedKeywordLoc(),
8121 QualifierLoc, TL.getNameLoc());
8122 } else if (isa<UnresolvedUsingType>(Result)) {
8123 auto NewTL = TLB.push<UnresolvedUsingTypeLoc>(Result);
8124 NewTL.set(TL.getElaboratedKeywordLoc(), QualifierLoc, TL.getNameLoc());
8125 } else {
8126 auto NewTL = TLB.push<DependentNameTypeLoc>(Result);
8127 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
8128 NewTL.setQualifierLoc(QualifierLoc);
8129 NewTL.setNameLoc(TL.getNameLoc());
8130 }
8131 return Result;
8132}
8133
8134template<typename Derived>
8137 QualType Pattern
8138 = getDerived().TransformType(TLB, TL.getPatternLoc());
8139 if (Pattern.isNull())
8140 return QualType();
8141
8142 QualType Result = TL.getType();
8143 if (getDerived().AlwaysRebuild() ||
8144 Pattern != TL.getPatternLoc().getType()) {
8145 Result = getDerived().RebuildPackExpansionType(Pattern,
8146 TL.getPatternLoc().getSourceRange(),
8147 TL.getEllipsisLoc(),
8148 TL.getTypePtr()->getNumExpansions());
8149 if (Result.isNull())
8150 return QualType();
8151 }
8152
8154 NewT.setEllipsisLoc(TL.getEllipsisLoc());
8155 return Result;
8156}
8157
8158template<typename Derived>
8162 // ObjCInterfaceType is never dependent.
8163 TLB.pushFullCopy(TL);
8164 return TL.getType();
8165}
8166
8167template<typename Derived>
8171 const ObjCTypeParamType *T = TL.getTypePtr();
8172 ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>(
8173 getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl()));
8174 if (!OTP)
8175 return QualType();
8176
8177 QualType Result = TL.getType();
8178 if (getDerived().AlwaysRebuild() ||
8179 OTP != T->getDecl()) {
8180 Result = getDerived().RebuildObjCTypeParamType(
8181 OTP, TL.getProtocolLAngleLoc(),
8182 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
8183 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
8184 if (Result.isNull())
8185 return QualType();
8186 }
8187
8189 if (TL.getNumProtocols()) {
8190 NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8191 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8192 NewTL.setProtocolLoc(i, TL.getProtocolLoc(i));
8193 NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8194 }
8195 return Result;
8196}
8197
8198template<typename Derived>
8201 ObjCObjectTypeLoc TL) {
8202 // Transform base type.
8203 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
8204 if (BaseType.isNull())
8205 return QualType();
8206
8207 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
8208
8209 // Transform type arguments.
8210 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
8211 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
8212 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
8213 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
8214 QualType TypeArg = TypeArgInfo->getType();
8215 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
8216 AnyChanged = true;
8217
8218 // We have a pack expansion. Instantiate it.
8219 const auto *PackExpansion = PackExpansionLoc.getType()
8220 ->castAs<PackExpansionType>();
8222 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
8223 Unexpanded);
8224 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
8225
8226 // Determine whether the set of unexpanded parameter packs can
8227 // and should be expanded.
8228 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
8229 bool Expand = false;
8230 bool RetainExpansion = false;
8231 UnsignedOrNone NumExpansions = PackExpansion->getNumExpansions();
8232 if (getDerived().TryExpandParameterPacks(
8233 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
8234 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
8235 RetainExpansion, NumExpansions))
8236 return QualType();
8237
8238 if (!Expand) {
8239 // We can't expand this pack expansion into separate arguments yet;
8240 // just substitute into the pattern and create a new pack expansion
8241 // type.
8242 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
8243
8244 TypeLocBuilder TypeArgBuilder;
8245 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
8246 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
8247 PatternLoc);
8248 if (NewPatternType.isNull())
8249 return QualType();
8250
8251 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
8252 NewPatternType, NumExpansions);
8253 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
8254 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
8255 NewTypeArgInfos.push_back(
8256 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
8257 continue;
8258 }
8259
8260 // Substitute into the pack expansion pattern for each slice of the
8261 // pack.
8262 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
8263 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), ArgIdx);
8264
8265 TypeLocBuilder TypeArgBuilder;
8266 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
8267
8268 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
8269 PatternLoc);
8270 if (NewTypeArg.isNull())
8271 return QualType();
8272
8273 NewTypeArgInfos.push_back(
8274 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8275 }
8276
8277 continue;
8278 }
8279
8280 TypeLocBuilder TypeArgBuilder;
8281 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
8282 QualType NewTypeArg =
8283 getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
8284 if (NewTypeArg.isNull())
8285 return QualType();
8286
8287 // If nothing changed, just keep the old TypeSourceInfo.
8288 if (NewTypeArg == TypeArg) {
8289 NewTypeArgInfos.push_back(TypeArgInfo);
8290 continue;
8291 }
8292
8293 NewTypeArgInfos.push_back(
8294 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
8295 AnyChanged = true;
8296 }
8297
8298 QualType Result = TL.getType();
8299 if (getDerived().AlwaysRebuild() || AnyChanged) {
8300 // Rebuild the type.
8301 Result = getDerived().RebuildObjCObjectType(
8302 BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos,
8303 TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(),
8304 llvm::ArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()),
8305 TL.getProtocolLocs(), TL.getProtocolRAngleLoc());
8306
8307 if (Result.isNull())
8308 return QualType();
8309 }
8310
8311 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
8312 NewT.setHasBaseTypeAsWritten(true);
8313 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
8314 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
8315 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
8316 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
8317 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
8318 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
8319 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
8320 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
8321 return Result;
8322}
8323
8324template<typename Derived>
8328 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
8329 if (PointeeType.isNull())
8330 return QualType();
8331
8332 QualType Result = TL.getType();
8333 if (getDerived().AlwaysRebuild() ||
8334 PointeeType != TL.getPointeeLoc().getType()) {
8335 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
8336 TL.getStarLoc());
8337 if (Result.isNull())
8338 return QualType();
8339 }
8340
8342 NewT.setStarLoc(TL.getStarLoc());
8343 return Result;
8344}
8345
8346//===----------------------------------------------------------------------===//
8347// Statement transformation
8348//===----------------------------------------------------------------------===//
8349template<typename Derived>
8352 return S;
8353}
8354
8355template<typename Derived>
8358 return getDerived().TransformCompoundStmt(S, false);
8359}
8360
8361template<typename Derived>
8364 bool IsStmtExpr) {
8365 Sema::CompoundScopeRAII CompoundScope(getSema());
8366 Sema::FPFeaturesStateRAII FPSave(getSema());
8367 if (S->hasStoredFPFeatures())
8368 getSema().resetFPOptions(
8369 S->getStoredFPFeatures().applyOverrides(getSema().getLangOpts()));
8370
8371 bool SubStmtInvalid = false;
8372 bool SubStmtChanged = false;
8373 SmallVector<Stmt*, 8> Statements;
8374 for (auto *B : S->body()) {
8375 StmtResult Result = getDerived().TransformStmt(
8376 B, IsStmtExpr && B == S->body_back() ? StmtDiscardKind::StmtExprResult
8377 : StmtDiscardKind::Discarded);
8378
8379 if (Result.isInvalid()) {
8380 // Immediately fail if this was a DeclStmt, since it's very
8381 // likely that this will cause problems for future statements.
8382 if (isa<DeclStmt>(B))
8383 return StmtError();
8384
8385 // Otherwise, just keep processing substatements and fail later.
8386 SubStmtInvalid = true;
8387 continue;
8388 }
8389
8390 SubStmtChanged = SubStmtChanged || Result.get() != B;
8391 Statements.push_back(Result.getAs<Stmt>());
8392 }
8393
8394 if (SubStmtInvalid)
8395 return StmtError();
8396
8397 if (!getDerived().AlwaysRebuild() &&
8398 !SubStmtChanged)
8399 return S;
8400
8401 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
8402 Statements,
8403 S->getRBracLoc(),
8404 IsStmtExpr);
8405}
8406
8407template<typename Derived>
8410 ExprResult LHS, RHS;
8411 {
8414
8415 // Transform the left-hand case value.
8416 LHS = getDerived().TransformExpr(S->getLHS());
8417 LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS);
8418 if (LHS.isInvalid())
8419 return StmtError();
8420
8421 // Transform the right-hand case value (for the GNU case-range extension).
8422 RHS = getDerived().TransformExpr(S->getRHS());
8423 RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS);
8424 if (RHS.isInvalid())
8425 return StmtError();
8426 }
8427
8428 // Build the case statement.
8429 // Case statements are always rebuilt so that they will attached to their
8430 // transformed switch statement.
8431 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
8432 LHS.get(),
8433 S->getEllipsisLoc(),
8434 RHS.get(),
8435 S->getColonLoc());
8436 if (Case.isInvalid())
8437 return StmtError();
8438
8439 // Transform the statement following the case
8440 StmtResult SubStmt =
8441 getDerived().TransformStmt(S->getSubStmt());
8442 if (SubStmt.isInvalid())
8443 return StmtError();
8444
8445 // Attach the body to the case statement
8446 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
8447}
8448
8449template <typename Derived>
8451 // Transform the statement following the default case
8452 StmtResult SubStmt =
8453 getDerived().TransformStmt(S->getSubStmt());
8454 if (SubStmt.isInvalid())
8455 return StmtError();
8456
8457 // Default statements are always rebuilt
8458 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
8459 SubStmt.get());
8460}
8461
8462template<typename Derived>
8465 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8466 if (SubStmt.isInvalid())
8467 return StmtError();
8468
8469 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
8470 S->getDecl());
8471 if (!LD)
8472 return StmtError();
8473
8474 // If we're transforming "in-place" (we're not creating new local
8475 // declarations), assume we're replacing the old label statement
8476 // and clear out the reference to it.
8477 if (LD == S->getDecl())
8478 S->getDecl()->setStmt(nullptr);
8479
8480 // FIXME: Pass the real colon location in.
8481 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
8483 SubStmt.get());
8484}
8485
8486template <typename Derived>
8488 if (!R)
8489 return R;
8490
8491 switch (R->getKind()) {
8492// Transform attributes by calling TransformXXXAttr.
8493#define ATTR(X) \
8494 case attr::X: \
8495 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
8496#include "clang/Basic/AttrList.inc"
8497 }
8498 return R;
8499}
8500
8501template <typename Derived>
8503 const Stmt *InstS,
8504 const Attr *R) {
8505 if (!R)
8506 return R;
8507
8508 switch (R->getKind()) {
8509// Transform attributes by calling TransformStmtXXXAttr.
8510#define ATTR(X) \
8511 case attr::X: \
8512 return getDerived().TransformStmt##X##Attr(OrigS, InstS, cast<X##Attr>(R));
8513#include "clang/Basic/AttrList.inc"
8514 }
8515 return TransformAttr(R);
8516}
8517
8518template <typename Derived>
8521 StmtDiscardKind SDK) {
8522 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK);
8523 if (SubStmt.isInvalid())
8524 return StmtError();
8525
8526 bool AttrsChanged = false;
8528
8529 // Visit attributes and keep track if any are transformed.
8530 for (const auto *I : S->getAttrs()) {
8531 const Attr *R =
8532 getDerived().TransformStmtAttr(S->getSubStmt(), SubStmt.get(), I);
8533 AttrsChanged |= (I != R);
8534 if (R)
8535 Attrs.push_back(R);
8536 }
8537
8538 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
8539 return S;
8540
8541 // If transforming the attributes failed for all of the attributes in the
8542 // statement, don't make an AttributedStmt without attributes.
8543 if (Attrs.empty())
8544 return SubStmt;
8545
8546 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
8547 SubStmt.get());
8548}
8549
8550template<typename Derived>
8553 // Transform the initialization statement
8554 StmtResult Init = getDerived().TransformStmt(S->getInit());
8555 if (Init.isInvalid())
8556 return StmtError();
8557
8559 if (!S->isConsteval()) {
8560 // Transform the condition
8561 Cond = getDerived().TransformCondition(
8562 S->getIfLoc(), S->getConditionVariable(), S->getCond(),
8563 S->isConstexpr() ? Sema::ConditionKind::ConstexprIf
8565 if (Cond.isInvalid())
8566 return StmtError();
8567 }
8568
8569 // If this is a constexpr if, determine which arm we should instantiate.
8570 std::optional<bool> ConstexprConditionValue;
8571 if (S->isConstexpr())
8572 ConstexprConditionValue = Cond.getKnownValue();
8573
8574 // Transform the "then" branch.
8575 StmtResult Then;
8576 if (!ConstexprConditionValue || *ConstexprConditionValue) {
8580 S->isNonNegatedConsteval());
8581
8582 Then = getDerived().TransformStmt(S->getThen());
8583 if (Then.isInvalid())
8584 return StmtError();
8585 } else {
8586 // Discarded branch is replaced with empty CompoundStmt so we can keep
8587 // proper source location for start and end of original branch, so
8588 // subsequent transformations like CoverageMapping work properly
8589 Then = new (getSema().Context)
8590 CompoundStmt(S->getThen()->getBeginLoc(), S->getThen()->getEndLoc());
8591 }
8592
8593 // Transform the "else" branch.
8594 StmtResult Else;
8595 if (!ConstexprConditionValue || !*ConstexprConditionValue) {
8599 S->isNegatedConsteval());
8600
8601 Else = getDerived().TransformStmt(S->getElse());
8602 if (Else.isInvalid())
8603 return StmtError();
8604 } else if (S->getElse() && ConstexprConditionValue &&
8605 *ConstexprConditionValue) {
8606 // Same thing here as with <then> branch, we are discarding it, we can't
8607 // replace it with NULL nor NullStmt as we need to keep for source location
8608 // range, for CoverageMapping
8609 Else = new (getSema().Context)
8610 CompoundStmt(S->getElse()->getBeginLoc(), S->getElse()->getEndLoc());
8611 }
8612
8613 if (!getDerived().AlwaysRebuild() &&
8614 Init.get() == S->getInit() &&
8615 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8616 Then.get() == S->getThen() &&
8617 Else.get() == S->getElse())
8618 return S;
8619
8620 return getDerived().RebuildIfStmt(
8621 S->getIfLoc(), S->getStatementKind(), S->getLParenLoc(), Cond,
8622 S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get());
8623}
8624
8625template<typename Derived>
8628 // Transform the initialization statement
8629 StmtResult Init = getDerived().TransformStmt(S->getInit());
8630 if (Init.isInvalid())
8631 return StmtError();
8632
8633 // Transform the condition.
8634 Sema::ConditionResult Cond = getDerived().TransformCondition(
8635 S->getSwitchLoc(), S->getConditionVariable(), S->getCond(),
8637 if (Cond.isInvalid())
8638 return StmtError();
8639
8640 // Rebuild the switch statement.
8642 getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(),
8643 Init.get(), Cond, S->getRParenLoc());
8644 if (Switch.isInvalid())
8645 return StmtError();
8646
8647 // Transform the body of the switch statement.
8648 StmtResult Body = getDerived().TransformStmt(S->getBody());
8649
8650 // Complete the switch statement.
8651 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
8652 Body.get());
8653}
8654
8655template<typename Derived>
8658 // Transform the condition
8659 Sema::ConditionResult Cond = getDerived().TransformCondition(
8660 S->getWhileLoc(), S->getConditionVariable(), S->getCond(),
8662 if (Cond.isInvalid())
8663 return StmtError();
8664
8665 // OpenACC Restricts a while-loop inside of certain construct/clause
8666 // combinations, so diagnose that here in OpenACC mode.
8668 SemaRef.OpenACC().ActOnWhileStmt(S->getBeginLoc());
8669
8670 // Transform the body
8671 StmtResult Body = getDerived().TransformStmt(S->getBody());
8672 if (Body.isInvalid())
8673 return StmtError();
8674
8675 if (!getDerived().AlwaysRebuild() &&
8676 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8677 Body.get() == S->getBody())
8678 return Owned(S);
8679
8680 return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(),
8681 Cond, S->getRParenLoc(), Body.get());
8682}
8683
8684template<typename Derived>
8687 // OpenACC Restricts a do-loop inside of certain construct/clause
8688 // combinations, so diagnose that here in OpenACC mode.
8690 SemaRef.OpenACC().ActOnDoStmt(S->getBeginLoc());
8691
8692 // Transform the body
8693 StmtResult Body = getDerived().TransformStmt(S->getBody());
8694 if (Body.isInvalid())
8695 return StmtError();
8696
8697 // Transform the condition
8698 ExprResult Cond = getDerived().TransformExpr(S->getCond());
8699 if (Cond.isInvalid())
8700 return StmtError();
8701
8702 if (!getDerived().AlwaysRebuild() &&
8703 Cond.get() == S->getCond() &&
8704 Body.get() == S->getBody())
8705 return S;
8706
8707 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
8708 /*FIXME:*/S->getWhileLoc(), Cond.get(),
8709 S->getRParenLoc());
8710}
8711
8712template<typename Derived>
8715 if (getSema().getLangOpts().getOpenMPVersion())
8716 getSema().OpenMP().startOpenMPLoop();
8717
8718 // Transform the initialization statement
8719 StmtResult Init = getDerived().TransformStmt(S->getInit());
8720 if (Init.isInvalid())
8721 return StmtError();
8722
8723 // In OpenMP loop region loop control variable must be captured and be
8724 // private. Perform analysis of first part (if any).
8725 if (getSema().getLangOpts().getOpenMPVersion() && Init.isUsable())
8726 getSema().OpenMP().ActOnOpenMPLoopInitialization(S->getForLoc(),
8727 Init.get());
8728
8729 // Transform the condition
8730 Sema::ConditionResult Cond = getDerived().TransformCondition(
8731 S->getForLoc(), S->getConditionVariable(), S->getCond(),
8733 if (Cond.isInvalid())
8734 return StmtError();
8735
8736 // Transform the increment
8737 ExprResult Inc = getDerived().TransformExpr(S->getInc());
8738 if (Inc.isInvalid())
8739 return StmtError();
8740
8741 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
8742 if (S->getInc() && !FullInc.get())
8743 return StmtError();
8744
8745 // OpenACC Restricts a for-loop inside of certain construct/clause
8746 // combinations, so diagnose that here in OpenACC mode.
8748 SemaRef.OpenACC().ActOnForStmtBegin(
8749 S->getBeginLoc(), S->getInit(), Init.get(), S->getCond(),
8750 Cond.get().second, S->getInc(), Inc.get());
8751
8752 // Transform the body
8753 StmtResult Body = getDerived().TransformStmt(S->getBody());
8754 if (Body.isInvalid())
8755 return StmtError();
8756
8757 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
8758
8759 if (!getDerived().AlwaysRebuild() &&
8760 Init.get() == S->getInit() &&
8761 Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) &&
8762 Inc.get() == S->getInc() &&
8763 Body.get() == S->getBody())
8764 return S;
8765
8766 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
8767 Init.get(), Cond, FullInc,
8768 S->getRParenLoc(), Body.get());
8769}
8770
8771template<typename Derived>
8774 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
8775 S->getLabel());
8776 if (!LD)
8777 return StmtError();
8778
8779 // Goto statements must always be rebuilt, to resolve the label.
8780 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
8781 cast<LabelDecl>(LD));
8782}
8783
8784template<typename Derived>
8787 ExprResult Target = getDerived().TransformExpr(S->getTarget());
8788 if (Target.isInvalid())
8789 return StmtError();
8790 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
8791
8792 if (!getDerived().AlwaysRebuild() &&
8793 Target.get() == S->getTarget())
8794 return S;
8795
8796 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
8797 Target.get());
8798}
8799
8800template<typename Derived>
8803 if (!S->isNamed())
8804 return S;
8805
8806 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8807 S->getLabelDecl());
8808 if (!LD)
8809 return StmtError();
8810
8811 return new (SemaRef.Context)
8812 ContinueStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8813}
8814
8815template<typename Derived>
8818 if (!S->isNamed())
8819 return S;
8820
8821 Decl *LD = getDerived().TransformDecl(S->getLabelDecl()->getLocation(),
8822 S->getLabelDecl());
8823 if (!LD)
8824 return StmtError();
8825
8826 return new (SemaRef.Context)
8827 BreakStmt(S->getKwLoc(), S->getLabelLoc(), cast<LabelDecl>(LD));
8828}
8829
8830template <typename Derived>
8832 StmtResult Result = getDerived().TransformStmt(S->getBody());
8833 if (!Result.isUsable())
8834 return StmtError();
8835 return DeferStmt::Create(getSema().Context, S->getDeferLoc(), Result.get());
8836}
8837
8838template<typename Derived>
8841 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
8842 /*NotCopyInit*/false);
8843 if (Result.isInvalid())
8844 return StmtError();
8845
8846 // FIXME: We always rebuild the return statement because there is no way
8847 // to tell whether the return type of the function has changed.
8848 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
8849}
8850
8851template<typename Derived>
8854 bool DeclChanged = false;
8856 LambdaScopeInfo *LSI = getSema().getCurLambda();
8857 for (auto *D : S->decls()) {
8858 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
8859 if (!Transformed)
8860 return StmtError();
8861
8862 if (Transformed != D)
8863 DeclChanged = true;
8864
8865 if (LSI) {
8866 if (auto *TD = dyn_cast<TypeDecl>(Transformed)) {
8867 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
8868 LSI->ContainsUnexpandedParameterPack |=
8869 TN->getUnderlyingType()->containsUnexpandedParameterPack();
8870 } else {
8871 LSI->ContainsUnexpandedParameterPack |=
8872 getSema()
8873 .getASTContext()
8874 .getTypeDeclType(TD)
8875 ->containsUnexpandedParameterPack();
8876 }
8877 }
8878 if (auto *VD = dyn_cast<VarDecl>(Transformed))
8879 LSI->ContainsUnexpandedParameterPack |=
8880 VD->getType()->containsUnexpandedParameterPack();
8881 }
8882
8883 Decls.push_back(Transformed);
8884 }
8885
8886 if (!getDerived().AlwaysRebuild() && !DeclChanged)
8887 return S;
8888
8889 return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc());
8890}
8891
8892template<typename Derived>
8895
8896 SmallVector<Expr*, 8> Constraints;
8899
8900 SmallVector<Expr*, 8> Clobbers;
8901
8902 bool ExprsChanged = false;
8903
8904 auto RebuildString = [&](Expr *E) {
8905 ExprResult Result = getDerived().TransformExpr(E);
8906 if (!Result.isUsable())
8907 return Result;
8908 if (Result.get() != E) {
8909 ExprsChanged = true;
8910 Result = SemaRef.ActOnGCCAsmStmtString(Result.get(), /*ForLabel=*/false);
8911 }
8912 return Result;
8913 };
8914
8915 // Go through the outputs.
8916 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
8917 Names.push_back(S->getOutputIdentifier(I));
8918
8919 ExprResult Result = RebuildString(S->getOutputConstraintExpr(I));
8920 if (Result.isInvalid())
8921 return StmtError();
8922
8923 Constraints.push_back(Result.get());
8924
8925 // Transform the output expr.
8926 Expr *OutputExpr = S->getOutputExpr(I);
8927 Result = getDerived().TransformExpr(OutputExpr);
8928 if (Result.isInvalid())
8929 return StmtError();
8930
8931 ExprsChanged |= Result.get() != OutputExpr;
8932
8933 Exprs.push_back(Result.get());
8934 }
8935
8936 // Go through the inputs.
8937 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
8938 Names.push_back(S->getInputIdentifier(I));
8939
8940 ExprResult Result = RebuildString(S->getInputConstraintExpr(I));
8941 if (Result.isInvalid())
8942 return StmtError();
8943
8944 Constraints.push_back(Result.get());
8945
8946 // Transform the input expr.
8947 Expr *InputExpr = S->getInputExpr(I);
8948 Result = getDerived().TransformExpr(InputExpr);
8949 if (Result.isInvalid())
8950 return StmtError();
8951
8952 ExprsChanged |= Result.get() != InputExpr;
8953
8954 Exprs.push_back(Result.get());
8955 }
8956
8957 // Go through the Labels.
8958 for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) {
8959 Names.push_back(S->getLabelIdentifier(I));
8960
8961 ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I));
8962 if (Result.isInvalid())
8963 return StmtError();
8964 ExprsChanged |= Result.get() != S->getLabelExpr(I);
8965 Exprs.push_back(Result.get());
8966 }
8967
8968 // Go through the clobbers.
8969 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) {
8970 ExprResult Result = RebuildString(S->getClobberExpr(I));
8971 if (Result.isInvalid())
8972 return StmtError();
8973 Clobbers.push_back(Result.get());
8974 }
8975
8976 ExprResult AsmString = RebuildString(S->getAsmStringExpr());
8977 if (AsmString.isInvalid())
8978 return StmtError();
8979
8980 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
8981 return S;
8982
8983 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
8984 S->isVolatile(), S->getNumOutputs(),
8985 S->getNumInputs(), Names.data(),
8986 Constraints, Exprs, AsmString.get(),
8987 Clobbers, S->getNumLabels(),
8988 S->getRParenLoc());
8989}
8990
8991template<typename Derived>
8994 ArrayRef<Token> AsmToks = llvm::ArrayRef(S->getAsmToks(), S->getNumAsmToks());
8995
8996 bool HadError = false, HadChange = false;
8997
8998 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
8999 SmallVector<Expr*, 8> TransformedExprs;
9000 TransformedExprs.reserve(SrcExprs.size());
9001 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
9002 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
9003 if (!Result.isUsable()) {
9004 HadError = true;
9005 } else {
9006 HadChange |= (Result.get() != SrcExprs[i]);
9007 TransformedExprs.push_back(Result.get());
9008 }
9009 }
9010
9011 if (HadError) return StmtError();
9012 if (!HadChange && !getDerived().AlwaysRebuild())
9013 return Owned(S);
9014
9015 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
9016 AsmToks, S->getAsmString(),
9017 S->getNumOutputs(), S->getNumInputs(),
9018 S->getAllConstraints(), S->getClobbers(),
9019 TransformedExprs, S->getEndLoc());
9020}
9021
9022// C++ Coroutines
9023template<typename Derived>
9026 auto *ScopeInfo = SemaRef.getCurFunction();
9027 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
9028 assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise &&
9029 ScopeInfo->NeedsCoroutineSuspends &&
9030 ScopeInfo->CoroutineSuspends.first == nullptr &&
9031 ScopeInfo->CoroutineSuspends.second == nullptr &&
9032 "expected clean scope info");
9033
9034 // Set that we have (possibly-invalid) suspend points before we do anything
9035 // that may fail.
9036 ScopeInfo->setNeedsCoroutineSuspends(false);
9037
9038 // We re-build the coroutine promise object (and the coroutine parameters its
9039 // type and constructor depend on) based on the types used in our current
9040 // function. We must do so, and set it on the current FunctionScopeInfo,
9041 // before attempting to transform the other parts of the coroutine body
9042 // statement, such as the implicit suspend statements (because those
9043 // statements reference the FunctionScopeInfo::CoroutinePromise).
9044 if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation()))
9045 return StmtError();
9046 auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation());
9047 if (!Promise)
9048 return StmtError();
9049 getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise});
9050 ScopeInfo->CoroutinePromise = Promise;
9051
9052 // Transform the implicit coroutine statements constructed using dependent
9053 // types during the previous parse: initial and final suspensions, the return
9054 // object, and others. We also transform the coroutine function's body.
9055 StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt());
9056 if (InitSuspend.isInvalid())
9057 return StmtError();
9058 StmtResult FinalSuspend =
9059 getDerived().TransformStmt(S->getFinalSuspendStmt());
9060 if (FinalSuspend.isInvalid() ||
9061 !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get()))
9062 return StmtError();
9063 ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get());
9064 assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get()));
9065
9066 StmtResult BodyRes = getDerived().TransformStmt(S->getBody());
9067 if (BodyRes.isInvalid())
9068 return StmtError();
9069
9070 CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get());
9071 if (Builder.isInvalid())
9072 return StmtError();
9073
9074 Expr *ReturnObject = S->getReturnValueInit();
9075 assert(ReturnObject && "the return object is expected to be valid");
9076 ExprResult Res = getDerived().TransformInitializer(ReturnObject,
9077 /*NoCopyInit*/ false);
9078 if (Res.isInvalid())
9079 return StmtError();
9080 Builder.ReturnValue = Res.get();
9081
9082 // If during the previous parse the coroutine still had a dependent promise
9083 // statement, we may need to build some implicit coroutine statements
9084 // (such as exception and fallthrough handlers) for the first time.
9085 if (S->hasDependentPromiseType()) {
9086 // We can only build these statements, however, if the current promise type
9087 // is not dependent.
9088 if (!Promise->getType()->isDependentType()) {
9089 assert(!S->getFallthroughHandler() && !S->getExceptionHandler() &&
9090 !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() &&
9091 "these nodes should not have been built yet");
9092 if (!Builder.buildDependentStatements())
9093 return StmtError();
9094 }
9095 } else {
9096 if (auto *OnFallthrough = S->getFallthroughHandler()) {
9097 StmtResult Res = getDerived().TransformStmt(OnFallthrough);
9098 if (Res.isInvalid())
9099 return StmtError();
9100 Builder.OnFallthrough = Res.get();
9101 }
9102
9103 if (auto *OnException = S->getExceptionHandler()) {
9104 StmtResult Res = getDerived().TransformStmt(OnException);
9105 if (Res.isInvalid())
9106 return StmtError();
9107 Builder.OnException = Res.get();
9108 }
9109
9110 if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) {
9111 StmtResult Res = getDerived().TransformStmt(OnAllocFailure);
9112 if (Res.isInvalid())
9113 return StmtError();
9114 Builder.ReturnStmtOnAllocFailure = Res.get();
9115 }
9116
9117 // Transform any additional statements we may have already built
9118 assert(S->getAllocate() && S->getDeallocate() &&
9119 "allocation and deallocation calls must already be built");
9120 ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate());
9121 if (AllocRes.isInvalid())
9122 return StmtError();
9123 Builder.Allocate = AllocRes.get();
9124
9125 ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate());
9126 if (DeallocRes.isInvalid())
9127 return StmtError();
9128 Builder.Deallocate = DeallocRes.get();
9129
9130 if (auto *ResultDecl = S->getResultDecl()) {
9131 StmtResult Res = getDerived().TransformStmt(ResultDecl);
9132 if (Res.isInvalid())
9133 return StmtError();
9134 Builder.ResultDecl = Res.get();
9135 }
9136
9137 if (auto *ReturnStmt = S->getReturnStmt()) {
9138 StmtResult Res = getDerived().TransformStmt(ReturnStmt);
9139 if (Res.isInvalid())
9140 return StmtError();
9141 Builder.ReturnStmt = Res.get();
9142 }
9143 }
9144
9145 return getDerived().RebuildCoroutineBodyStmt(Builder);
9146}
9147
9148template<typename Derived>
9151 ExprResult Result = getDerived().TransformInitializer(S->getOperand(),
9152 /*NotCopyInit*/false);
9153 if (Result.isInvalid())
9154 return StmtError();
9155
9156 // Always rebuild; we don't know if this needs to be injected into a new
9157 // context or if the promise type has changed.
9158 return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(),
9159 S->isImplicit());
9160}
9161
9162template <typename Derived>
9164 ExprResult Operand = getDerived().TransformInitializer(E->getOperand(),
9165 /*NotCopyInit*/ false);
9166 if (Operand.isInvalid())
9167 return ExprError();
9168
9169 // Rebuild the common-expr from the operand rather than transforming it
9170 // separately.
9171
9172 // FIXME: getCurScope() should not be used during template instantiation.
9173 // We should pick up the set of unqualified lookup results for operator
9174 // co_await during the initial parse.
9175 ExprResult Lookup = getSema().BuildOperatorCoawaitLookupExpr(
9176 getSema().getCurScope(), E->getKeywordLoc());
9177
9178 // Always rebuild; we don't know if this needs to be injected into a new
9179 // context or if the promise type has changed.
9180 return getDerived().RebuildCoawaitExpr(
9181 E->getKeywordLoc(), Operand.get(),
9182 cast<UnresolvedLookupExpr>(Lookup.get()), E->isImplicit());
9183}
9184
9185template <typename Derived>
9188 ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(),
9189 /*NotCopyInit*/ false);
9190 if (OperandResult.isInvalid())
9191 return ExprError();
9192
9193 ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr(
9194 E->getOperatorCoawaitLookup());
9195
9196 if (LookupResult.isInvalid())
9197 return ExprError();
9198
9199 // Always rebuild; we don't know if this needs to be injected into a new
9200 // context or if the promise type has changed.
9201 return getDerived().RebuildDependentCoawaitExpr(
9202 E->getKeywordLoc(), OperandResult.get(),
9204}
9205
9206template<typename Derived>
9209 ExprResult Result = getDerived().TransformInitializer(E->getOperand(),
9210 /*NotCopyInit*/false);
9211 if (Result.isInvalid())
9212 return ExprError();
9213
9214 // Always rebuild; we don't know if this needs to be injected into a new
9215 // context or if the promise type has changed.
9216 return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get());
9217}
9218
9219// Objective-C Statements.
9220
9221template<typename Derived>
9224 // Transform the body of the @try.
9225 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
9226 if (TryBody.isInvalid())
9227 return StmtError();
9228
9229 // Transform the @catch statements (if present).
9230 bool AnyCatchChanged = false;
9231 SmallVector<Stmt*, 8> CatchStmts;
9232 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
9233 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
9234 if (Catch.isInvalid())
9235 return StmtError();
9236 if (Catch.get() != S->getCatchStmt(I))
9237 AnyCatchChanged = true;
9238 CatchStmts.push_back(Catch.get());
9239 }
9240
9241 // Transform the @finally statement (if present).
9242 StmtResult Finally;
9243 if (S->getFinallyStmt()) {
9244 Finally = getDerived().TransformStmt(S->getFinallyStmt());
9245 if (Finally.isInvalid())
9246 return StmtError();
9247 }
9248
9249 // If nothing changed, just retain this statement.
9250 if (!getDerived().AlwaysRebuild() &&
9251 TryBody.get() == S->getTryBody() &&
9252 !AnyCatchChanged &&
9253 Finally.get() == S->getFinallyStmt())
9254 return S;
9255
9256 // Build a new statement.
9257 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
9258 CatchStmts, Finally.get());
9259}
9260
9261template<typename Derived>
9264 // Transform the @catch parameter, if there is one.
9265 VarDecl *Var = nullptr;
9266 if (VarDecl *FromVar = S->getCatchParamDecl()) {
9267 TypeSourceInfo *TSInfo = nullptr;
9268 if (FromVar->getTypeSourceInfo()) {
9269 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
9270 if (!TSInfo)
9271 return StmtError();
9272 }
9273
9274 QualType T;
9275 if (TSInfo)
9276 T = TSInfo->getType();
9277 else {
9278 T = getDerived().TransformType(FromVar->getType());
9279 if (T.isNull())
9280 return StmtError();
9281 }
9282
9283 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
9284 if (!Var)
9285 return StmtError();
9286 }
9287
9288 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
9289 if (Body.isInvalid())
9290 return StmtError();
9291
9292 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
9293 S->getRParenLoc(),
9294 Var, Body.get());
9295}
9296
9297template<typename Derived>
9300 // Transform the body.
9301 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
9302 if (Body.isInvalid())
9303 return StmtError();
9304
9305 // If nothing changed, just retain this statement.
9306 if (!getDerived().AlwaysRebuild() &&
9307 Body.get() == S->getFinallyBody())
9308 return S;
9309
9310 // Build a new statement.
9311 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
9312 Body.get());
9313}
9314
9315template<typename Derived>
9319 if (S->getThrowExpr()) {
9320 Operand = getDerived().TransformExpr(S->getThrowExpr());
9321 if (Operand.isInvalid())
9322 return StmtError();
9323 }
9324
9325 if (!getDerived().AlwaysRebuild() &&
9326 Operand.get() == S->getThrowExpr())
9327 return S;
9328
9329 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
9330}
9331
9332template<typename Derived>
9336 // Transform the object we are locking.
9337 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
9338 if (Object.isInvalid())
9339 return StmtError();
9340 Object =
9341 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
9342 Object.get());
9343 if (Object.isInvalid())
9344 return StmtError();
9345
9346 // Transform the body.
9347 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
9348 if (Body.isInvalid())
9349 return StmtError();
9350
9351 // If nothing change, just retain the current statement.
9352 if (!getDerived().AlwaysRebuild() &&
9353 Object.get() == S->getSynchExpr() &&
9354 Body.get() == S->getSynchBody())
9355 return S;
9356
9357 // Build a new statement.
9358 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
9359 Object.get(), Body.get());
9360}
9361
9362template<typename Derived>
9366 // Transform the body.
9367 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
9368 if (Body.isInvalid())
9369 return StmtError();
9370
9371 // If nothing changed, just retain this statement.
9372 if (!getDerived().AlwaysRebuild() &&
9373 Body.get() == S->getSubStmt())
9374 return S;
9375
9376 // Build a new statement.
9377 return getDerived().RebuildObjCAutoreleasePoolStmt(
9378 S->getAtLoc(), Body.get());
9379}
9380
9381template<typename Derived>
9385 // Transform the element statement.
9386 StmtResult Element = getDerived().TransformStmt(
9387 S->getElement(), StmtDiscardKind::NotDiscarded);
9388 if (Element.isInvalid())
9389 return StmtError();
9390
9391 // Transform the collection expression.
9392 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
9393 if (Collection.isInvalid())
9394 return StmtError();
9395
9396 // Transform the body.
9397 StmtResult Body = getDerived().TransformStmt(S->getBody());
9398 if (Body.isInvalid())
9399 return StmtError();
9400
9401 // If nothing changed, just retain this statement.
9402 if (!getDerived().AlwaysRebuild() &&
9403 Element.get() == S->getElement() &&
9404 Collection.get() == S->getCollection() &&
9405 Body.get() == S->getBody())
9406 return S;
9407
9408 // Build a new statement.
9409 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
9410 Element.get(),
9411 Collection.get(),
9412 S->getRParenLoc(),
9413 Body.get());
9414}
9415
9416template <typename Derived>
9418 // Transform the exception declaration, if any.
9419 VarDecl *Var = nullptr;
9420 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
9421 TypeSourceInfo *T =
9422 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
9423 if (!T)
9424 return StmtError();
9425
9426 Var = getDerived().RebuildExceptionDecl(
9427 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
9428 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
9429 if (!Var || Var->isInvalidDecl())
9430 return StmtError();
9431 }
9432
9433 // Transform the actual exception handler.
9434 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
9435 if (Handler.isInvalid())
9436 return StmtError();
9437
9438 if (!getDerived().AlwaysRebuild() && !Var &&
9439 Handler.get() == S->getHandlerBlock())
9440 return S;
9441
9442 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
9443}
9444
9445template <typename Derived>
9447 // Transform the try block itself.
9448 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9449 if (TryBlock.isInvalid())
9450 return StmtError();
9451
9452 // Transform the handlers.
9453 bool HandlerChanged = false;
9454 SmallVector<Stmt *, 8> Handlers;
9455 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
9456 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
9457 if (Handler.isInvalid())
9458 return StmtError();
9459
9460 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
9461 Handlers.push_back(Handler.getAs<Stmt>());
9462 }
9463
9464 getSema().DiagnoseExceptionUse(S->getTryLoc(), /* IsTry= */ true);
9465
9466 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9467 !HandlerChanged)
9468 return S;
9469
9470 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
9471 Handlers);
9472}
9473
9474template<typename Derived>
9477 EnterExpressionEvaluationContext ForRangeInitContext(
9479 /*LambdaContextDecl=*/nullptr,
9481 getSema().getLangOpts().CPlusPlus23);
9482
9483 // P2718R0 - Lifetime extension in range-based for loops.
9484 if (getSema().getLangOpts().CPlusPlus23) {
9485 auto &LastRecord = getSema().currentEvaluationContext();
9486 LastRecord.InLifetimeExtendingContext = true;
9487 LastRecord.RebuildDefaultArgOrDefaultInit = true;
9488 }
9490 S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult();
9491 if (Init.isInvalid())
9492 return StmtError();
9493
9494 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
9495 if (Range.isInvalid())
9496 return StmtError();
9497
9498 // Before c++23, ForRangeLifetimeExtendTemps should be empty.
9499 assert(getSema().getLangOpts().CPlusPlus23 ||
9500 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps.empty());
9501 auto ForRangeLifetimeExtendTemps =
9502 getSema().ExprEvalContexts.back().ForRangeLifetimeExtendTemps;
9503
9504 StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt());
9505 if (Begin.isInvalid())
9506 return StmtError();
9507 StmtResult End = getDerived().TransformStmt(S->getEndStmt());
9508 if (End.isInvalid())
9509 return StmtError();
9510
9511 ExprResult Cond = getDerived().TransformExpr(S->getCond());
9512 if (Cond.isInvalid())
9513 return StmtError();
9514 if (Cond.get())
9515 Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get());
9516 if (Cond.isInvalid())
9517 return StmtError();
9518 if (Cond.get())
9519 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
9520
9521 ExprResult Inc = getDerived().TransformExpr(S->getInc());
9522 if (Inc.isInvalid())
9523 return StmtError();
9524 if (Inc.get())
9525 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
9526
9527 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
9528 if (LoopVar.isInvalid())
9529 return StmtError();
9530
9531 StmtResult NewStmt = S;
9532 if (getDerived().AlwaysRebuild() ||
9533 Init.get() != S->getInit() ||
9534 Range.get() != S->getRangeStmt() ||
9535 Begin.get() != S->getBeginStmt() ||
9536 End.get() != S->getEndStmt() ||
9537 Cond.get() != S->getCond() ||
9538 Inc.get() != S->getInc() ||
9539 LoopVar.get() != S->getLoopVarStmt()) {
9540 NewStmt = getDerived().RebuildCXXForRangeStmt(
9541 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9542 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9543 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9544 if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) {
9545 // Might not have attached any initializer to the loop variable.
9546 getSema().ActOnInitializerError(
9547 cast<DeclStmt>(LoopVar.get())->getSingleDecl());
9548 return StmtError();
9549 }
9550 }
9551
9552 // OpenACC Restricts a while-loop inside of certain construct/clause
9553 // combinations, so diagnose that here in OpenACC mode.
9555 SemaRef.OpenACC().ActOnRangeForStmtBegin(S->getBeginLoc(), S, NewStmt.get());
9556
9557 StmtResult Body = getDerived().TransformStmt(S->getBody());
9558 if (Body.isInvalid())
9559 return StmtError();
9560
9561 SemaRef.OpenACC().ActOnForStmtEnd(S->getBeginLoc(), Body);
9562
9563 // Body has changed but we didn't rebuild the for-range statement. Rebuild
9564 // it now so we have a new statement to attach the body to.
9565 if (Body.get() != S->getBody() && NewStmt.get() == S) {
9566 NewStmt = getDerived().RebuildCXXForRangeStmt(
9567 S->getForLoc(), S->getCoawaitLoc(), Init.get(), S->getColonLoc(),
9568 Range.get(), Begin.get(), End.get(), Cond.get(), Inc.get(),
9569 LoopVar.get(), S->getRParenLoc(), ForRangeLifetimeExtendTemps);
9570 if (NewStmt.isInvalid())
9571 return StmtError();
9572 }
9573
9574 if (NewStmt.get() == S)
9575 return S;
9576
9577 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
9578}
9579
9580template <typename Derived>
9583 assert(SemaRef.CurContext->isExpansionStmt());
9584
9585 Decl *ESD =
9586 getDerived().TransformDecl(S->getDecl()->getLocation(), S->getDecl());
9587 if (!ESD || ESD->isInvalidDecl())
9588 return StmtError();
9590
9591 // This is required because some parts of an expansion statement (e.g. the
9592 // init-statement) are not in a dependent context and must thus be transformed
9593 // in the parent context.
9594 auto TransformStmtInParentContext = [&](Stmt *SubStmt) -> StmtResult {
9595 Sema::ContextRAII CtxGuard(SemaRef, SemaRef.CurContext->getParent(),
9596 /*NewThis=*/false);
9597 return getDerived().TransformStmt(SubStmt);
9598 };
9599
9600 Stmt *Init = S->getInit();
9601 if (Init) {
9602 StmtResult SR = TransformStmtInParentContext(Init);
9603 if (SR.isInvalid())
9604 return StmtError();
9605 Init = SR.get();
9606 }
9607
9608 // Collect lifetime-extended temporaries in case this ends up being a
9609 // destructuring or iterating expansion statement.
9610 //
9611 // CWG 3140: Additionally, for iterating expansions statements, we need to
9612 // apply lifetime extension to the initializer of the range.
9613 ExprResult ExpansionInitializer;
9616 if (S->isDependent() || S->isIterating()) {
9618 SemaRef, SemaRef.currentEvaluationContext().Context);
9621
9622 if (S->isDependent()) {
9623 // The expansion initializer should not be in the context of the expansion
9624 // statement because it isn't instantiated when the expansion statement is
9625 // expanded.
9626 Sema::ContextRAII CtxGuard(SemaRef, SemaRef.CurContext->getParent(),
9627 /*NewThis=*/false);
9628 ExpansionInitializer =
9629 getDerived().TransformExpr(S->getExpansionInitializer());
9630 if (ExpansionInitializer.isInvalid())
9631 return StmtError();
9632 } else if (S->isIterating()) {
9633 Range = TransformStmtInParentContext(S->getRangeVarStmt());
9634 if (Range.isInvalid())
9635 return StmtError();
9636 }
9637
9638 ExpansionInitializer =
9639 SemaRef.MaybeCreateExprWithCleanups(ExpansionInitializer);
9640
9641 LifetimeExtendTemps =
9643 }
9644
9645 CXXExpansionStmtPattern *NewPattern = nullptr;
9646 if (S->isEnumerating()) {
9647 StmtResult ExpansionVar =
9648 getDerived().TransformStmt(S->getExpansionVarStmt());
9649 if (ExpansionVar.isInvalid())
9650 return StmtError();
9651
9653 SemaRef.Context, NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9654 S->getLParenLoc(), S->getColonLoc(), S->getRParenLoc());
9655 } else if (S->isIterating()) {
9656 StmtResult Begin = TransformStmtInParentContext(S->getBeginVarStmt());
9657 StmtResult Iter = TransformStmtInParentContext(S->getIterVarStmt());
9658 if (Begin.isInvalid() || Iter.isInvalid())
9659 return StmtError();
9660
9661 // The expansion variable is part of the pattern only and never ends
9662 // up in the instantiations, so keep it in the expansion statement's
9663 // DeclContext.
9664 StmtResult ExpansionVar =
9665 getDerived().TransformStmt(S->getExpansionVarStmt());
9666 if (ExpansionVar.isInvalid())
9667 return StmtError();
9668
9670 SemaRef.Context, NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9671 Range.getAs<DeclStmt>(), Begin.getAs<DeclStmt>(),
9672 Iter.getAs<DeclStmt>(), S->getLParenLoc(), S->getColonLoc(),
9673 S->getRParenLoc());
9674
9676 NewPattern->getRangeVar(), LifetimeExtendTemps);
9677 } else if (S->isDependent()) {
9678 StmtResult ExpansionVar =
9679 getDerived().TransformStmt(S->getExpansionVarStmt());
9680 if (ExpansionVar.isInvalid())
9681 return StmtError();
9682
9684 NewESD, Init, ExpansionVar.getAs<DeclStmt>(),
9685 ExpansionInitializer.get(), S->getLParenLoc(), S->getColonLoc(),
9686 S->getRParenLoc(), LifetimeExtendTemps);
9687
9688 if (Res.isInvalid())
9689 return StmtError();
9690
9691 NewPattern = cast<CXXExpansionStmtPattern>(Res.get());
9692 } else {
9693 // The only time we instantiate an expansion statement is if its expansion
9694 // size is dependent (otherwise, we only instantiate the expansions and
9695 // leave the underlying CXXExpansionStmtPattern as-is). Since destructuring
9696 // expansion statements never have a dependent size, we should never get
9697 // here.
9698 llvm_unreachable("destructuring pattern should never be instantiated");
9699 }
9700
9701 StmtResult Body = getDerived().TransformStmt(S->getBody());
9702 if (Body.isInvalid())
9703 return StmtError();
9704
9705 return SemaRef.FinishCXXExpansionStmt(NewPattern, Body.get());
9706}
9707
9708template <typename Derived>
9711 bool SubStmtChanged = false;
9712 auto TransformStmts = [&](SmallVectorImpl<Stmt *> &NewStmts,
9713 ArrayRef<Stmt *> OldStmts) {
9714 for (Stmt *OldDS : OldStmts) {
9715 StmtResult NewDS = getDerived().TransformStmt(OldDS);
9716 if (NewDS.isInvalid())
9717 return true;
9718
9719 SubStmtChanged |= NewDS.get() != OldDS;
9720 NewStmts.push_back(NewDS.get());
9721 }
9722
9723 return false;
9724 };
9725
9726 Decl *ESD =
9727 getDerived().TransformDecl(S->getParent()->getLocation(), S->getParent());
9728 if (!ESD || ESD->isInvalidDecl())
9729 return StmtError();
9731
9732 SmallVector<Stmt *> PreambleStmts;
9733 SmallVector<Stmt *> Instantiations;
9734
9735 // Apply lifetime extension to the preamble statements if this was a
9736 // destructuring expansion statement.
9737 {
9739 SemaRef, SemaRef.currentEvaluationContext().Context);
9742 if (TransformStmts(PreambleStmts, S->getPreambleStmts()))
9743 return StmtError();
9744
9745 if (S->shouldApplyLifetimeExtensionToPreamble()) {
9746 auto *VD =
9747 cast<VarDecl>(cast<DeclStmt>(PreambleStmts.front())->getSingleDecl());
9750 }
9751 }
9752
9753 if (TransformStmts(Instantiations, S->getInstantiations()))
9754 return StmtError();
9755
9756 if (!getDerived().AlwaysRebuild() && !SubStmtChanged)
9757 return S;
9758
9760 SemaRef.Context, NewESD, Instantiations, PreambleStmts,
9761 S->shouldApplyLifetimeExtensionToPreamble());
9762}
9763
9764template <typename Derived>
9767 ExprResult Range = getDerived().TransformExpr(E->getRangeExpr());
9768 ExprResult Idx = getDerived().TransformExpr(E->getIndexExpr());
9769 if (Range.isInvalid() || Idx.isInvalid())
9770 return ExprError();
9771
9772 if (!getDerived().AlwaysRebuild() && Range.get() == E->getRangeExpr() &&
9773 Idx.get() == E->getIndexExpr())
9774 return E;
9775
9776 return SemaRef.BuildCXXExpansionSelectExpr(Range.getAs<InitListExpr>(),
9777 Idx.get());
9778}
9779
9780template<typename Derived>
9784 // Transform the nested-name-specifier, if any.
9785 NestedNameSpecifierLoc QualifierLoc;
9786 if (S->getQualifierLoc()) {
9787 QualifierLoc
9788 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
9789 if (!QualifierLoc)
9790 return StmtError();
9791 }
9792
9793 // Transform the declaration name.
9794 DeclarationNameInfo NameInfo = S->getNameInfo();
9795 if (NameInfo.getName()) {
9796 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
9797 if (!NameInfo.getName())
9798 return StmtError();
9799 }
9800
9801 // Check whether anything changed.
9802 if (!getDerived().AlwaysRebuild() &&
9803 QualifierLoc == S->getQualifierLoc() &&
9804 NameInfo.getName() == S->getNameInfo().getName())
9805 return S;
9806
9807 // Determine whether this name exists, if we can.
9808 CXXScopeSpec SS;
9809 SS.Adopt(QualifierLoc);
9810 bool Dependent = false;
9811 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
9813 if (S->isIfExists())
9814 break;
9815
9816 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9817
9819 if (S->isIfNotExists())
9820 break;
9821
9822 return new (getSema().Context) NullStmt(S->getKeywordLoc());
9823
9825 Dependent = true;
9826 break;
9827
9829 return StmtError();
9830 }
9831
9832 // We need to continue with the instantiation, so do so now.
9833 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
9834 if (SubStmt.isInvalid())
9835 return StmtError();
9836
9837 // If we have resolved the name, just transform to the substatement.
9838 if (!Dependent)
9839 return SubStmt;
9840
9841 // The name is still dependent, so build a dependent expression again.
9842 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
9843 S->isIfExists(),
9844 QualifierLoc,
9845 NameInfo,
9846 SubStmt.get());
9847}
9848
9849template<typename Derived>
9852 NestedNameSpecifierLoc QualifierLoc;
9853 if (E->getQualifierLoc()) {
9854 QualifierLoc
9855 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9856 if (!QualifierLoc)
9857 return ExprError();
9858 }
9859
9860 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
9861 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
9862 if (!PD)
9863 return ExprError();
9864
9865 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
9866 if (Base.isInvalid())
9867 return ExprError();
9868
9869 return new (SemaRef.getASTContext())
9870 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
9872 QualifierLoc, E->getMemberLoc());
9873}
9874
9875template <typename Derived>
9878 auto BaseRes = getDerived().TransformExpr(E->getBase());
9879 if (BaseRes.isInvalid())
9880 return ExprError();
9881 auto IdxRes = getDerived().TransformExpr(E->getIdx());
9882 if (IdxRes.isInvalid())
9883 return ExprError();
9884
9885 if (!getDerived().AlwaysRebuild() &&
9886 BaseRes.get() == E->getBase() &&
9887 IdxRes.get() == E->getIdx())
9888 return E;
9889
9890 return getDerived().RebuildArraySubscriptExpr(
9891 BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc());
9892}
9893
9894template <typename Derived>
9896 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
9897 if (TryBlock.isInvalid())
9898 return StmtError();
9899
9900 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
9901 if (Handler.isInvalid())
9902 return StmtError();
9903
9904 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
9905 Handler.get() == S->getHandler())
9906 return S;
9907
9908 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
9909 TryBlock.get(), Handler.get());
9910}
9911
9912template <typename Derived>
9914 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9915 if (Block.isInvalid())
9916 return StmtError();
9917
9918 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
9919}
9920
9921template <typename Derived>
9923 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
9924 if (FilterExpr.isInvalid())
9925 return StmtError();
9926
9927 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
9928 if (Block.isInvalid())
9929 return StmtError();
9930
9931 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
9932 Block.get());
9933}
9934
9935template <typename Derived>
9937 if (isa<SEHFinallyStmt>(Handler))
9938 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
9939 else
9940 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
9941}
9942
9943template<typename Derived>
9946 return S;
9947}
9948
9949//===----------------------------------------------------------------------===//
9950// OpenMP directive transformation
9951//===----------------------------------------------------------------------===//
9952
9953template <typename Derived>
9954StmtResult
9955TreeTransform<Derived>::TransformOMPCanonicalLoop(OMPCanonicalLoop *L) {
9956 // OMPCanonicalLoops are eliminated during transformation, since they will be
9957 // recomputed by semantic analysis of the associated OMPLoopBasedDirective
9958 // after transformation.
9959 return getDerived().TransformStmt(L->getLoopStmt());
9960}
9961
9962template <typename Derived>
9965
9966 // Transform the clauses
9968 ArrayRef<OMPClause *> Clauses = D->clauses();
9969 TClauses.reserve(Clauses.size());
9970 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
9971 I != E; ++I) {
9972 if (*I) {
9973 getDerived().getSema().OpenMP().StartOpenMPClause((*I)->getClauseKind());
9974 OMPClause *Clause = getDerived().TransformOMPClause(*I);
9975 getDerived().getSema().OpenMP().EndOpenMPClause();
9976 if (Clause)
9977 TClauses.push_back(Clause);
9978 } else {
9979 TClauses.push_back(nullptr);
9980 }
9981 }
9982 StmtResult AssociatedStmt;
9983 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
9984 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
9985 D->getDirectiveKind(),
9986 /*CurScope=*/nullptr);
9987 StmtResult Body;
9988 {
9989 Sema::CompoundScopeRAII CompoundScope(getSema());
9990 Stmt *CS;
9991 if (D->getDirectiveKind() == OMPD_atomic ||
9992 D->getDirectiveKind() == OMPD_critical ||
9993 D->getDirectiveKind() == OMPD_section ||
9994 D->getDirectiveKind() == OMPD_master)
9995 CS = D->getAssociatedStmt();
9996 else
9997 CS = D->getRawStmt();
9998 Body = getDerived().TransformStmt(CS);
9999 if (Body.isUsable() && isOpenMPLoopDirective(D->getDirectiveKind()) &&
10000 getSema().getLangOpts().OpenMPIRBuilder)
10001 Body = getDerived().RebuildOMPCanonicalLoop(Body.get());
10002 }
10003 AssociatedStmt =
10004 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
10005 if (AssociatedStmt.isInvalid()) {
10006 return StmtError();
10007 }
10008 }
10009 if (TClauses.size() != Clauses.size()) {
10010 return StmtError();
10011 }
10012
10013 // Transform directive name for 'omp critical' directive.
10014 DeclarationNameInfo DirName;
10015 if (D->getDirectiveKind() == OMPD_critical) {
10016 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
10017 DirName = getDerived().TransformDeclarationNameInfo(DirName);
10018 }
10019 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
10020 if (D->getDirectiveKind() == OMPD_cancellation_point) {
10021 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
10022 } else if (D->getDirectiveKind() == OMPD_cancel) {
10023 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
10024 }
10025
10026 return getDerived().RebuildOMPExecutableDirective(
10027 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
10028 AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc());
10029}
10030
10031/// This is mostly the same as above, but allows 'informational' class
10032/// directives when rebuilding the stmt. It still takes an
10033/// OMPExecutableDirective-type argument because we're reusing that as the
10034/// superclass for the 'assume' directive at present, instead of defining a
10035/// mostly-identical OMPInformationalDirective parent class.
10036template <typename Derived>
10039
10040 // Transform the clauses
10042 ArrayRef<OMPClause *> Clauses = D->clauses();
10043 TClauses.reserve(Clauses.size());
10044 for (OMPClause *C : Clauses) {
10045 if (C) {
10046 getDerived().getSema().OpenMP().StartOpenMPClause(C->getClauseKind());
10047 OMPClause *Clause = getDerived().TransformOMPClause(C);
10048 getDerived().getSema().OpenMP().EndOpenMPClause();
10049 if (Clause)
10050 TClauses.push_back(Clause);
10051 } else {
10052 TClauses.push_back(nullptr);
10053 }
10054 }
10055 StmtResult AssociatedStmt;
10056 if (D->hasAssociatedStmt() && D->getAssociatedStmt()) {
10057 getDerived().getSema().OpenMP().ActOnOpenMPRegionStart(
10058 D->getDirectiveKind(),
10059 /*CurScope=*/nullptr);
10060 StmtResult Body;
10061 {
10062 Sema::CompoundScopeRAII CompoundScope(getSema());
10063 assert(D->getDirectiveKind() == OMPD_assume &&
10064 "Unexpected informational directive");
10065 Stmt *CS = D->getAssociatedStmt();
10066 Body = getDerived().TransformStmt(CS);
10067 }
10068 AssociatedStmt =
10069 getDerived().getSema().OpenMP().ActOnOpenMPRegionEnd(Body, TClauses);
10070 if (AssociatedStmt.isInvalid())
10071 return StmtError();
10072 }
10073 if (TClauses.size() != Clauses.size())
10074 return StmtError();
10075
10076 DeclarationNameInfo DirName;
10077
10078 return getDerived().RebuildOMPInformationalDirective(
10079 D->getDirectiveKind(), DirName, TClauses, AssociatedStmt.get(),
10080 D->getBeginLoc(), D->getEndLoc());
10081}
10082
10083template <typename Derived>
10086 // Every variant is a complete directive (or the plain associated statement),
10087 // so it is transformed on its own.
10088 SmallVector<Stmt *, 4> Variants;
10089 for (Stmt *V : D->variants()) {
10090 StmtResult NewV = getDerived().TransformStmt(V);
10091 if (NewV.isInvalid())
10092 return StmtError();
10093 Variants.push_back(NewV.get());
10094 }
10095
10096 // Copy the trait infos and transform their score and condition expressions.
10097 // The implicit 'otherwise' trait info is added back by Sema.
10098 ArrayRef<OMPTraitInfo *> OldTraitInfos = D->traitInfos();
10099 if (D->hasImplicitOtherwise())
10100 OldTraitInfos = OldTraitInfos.drop_back();
10102 for (const OMPTraitInfo *OldTI : OldTraitInfos) {
10103 OMPTraitInfo &TI = getSema().getASTContext().getNewOMPTraitInfo();
10104 TI = *OldTI;
10105 auto TransformScoreOrCondition = [&](Expr *&E, bool IsScore) {
10106 if (!E)
10107 return false;
10108 EnterExpressionEvaluationContext Ctx(
10109 getSema(),
10112 ExprResult ER = getDerived().TransformExpr(E);
10113 if (!ER.isUsable())
10114 return true;
10115 E = ER.get();
10116 return false;
10117 };
10118 if (TI.anyScoreOrCondition(TransformScoreOrCondition))
10119 return StmtError();
10120 TraitInfos.push_back(&TI);
10121 }
10122
10123 return getDerived().RebuildOMPMetaDirective(D->getBeginLoc(), D->getEndLoc(),
10124 TraitInfos, Variants);
10125}
10126
10127template <typename Derived>
10130 DeclarationNameInfo DirName;
10131 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10132 OMPD_parallel, DirName, nullptr, D->getBeginLoc());
10133 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10134 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10135 return Res;
10136}
10137
10138template <typename Derived>
10141 DeclarationNameInfo DirName;
10142 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10143 OMPD_simd, DirName, nullptr, D->getBeginLoc());
10144 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10145 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10146 return Res;
10147}
10148
10149template <typename Derived>
10152 DeclarationNameInfo DirName;
10153 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10154 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10155 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10156 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10157 return Res;
10158}
10159
10160template <typename Derived>
10163 DeclarationNameInfo DirName;
10164 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10165 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10166 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10167 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10168 return Res;
10169}
10170
10171template <typename Derived>
10174 DeclarationNameInfo DirName;
10175 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10176 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10177 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10178 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10179 return Res;
10180}
10181
10182template <typename Derived>
10185 DeclarationNameInfo DirName;
10186 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10187 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10188 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10189 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10190 return Res;
10191}
10192
10193template <typename Derived>
10195 OMPInterchangeDirective *D) {
10196 DeclarationNameInfo DirName;
10197 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10198 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10199 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10200 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10201 return Res;
10202}
10203
10204template <typename Derived>
10207 DeclarationNameInfo DirName;
10208 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10209 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10210 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10211 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10212 return Res;
10213}
10214
10215template <typename Derived>
10218 DeclarationNameInfo DirName;
10219 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10220 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10221 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10222 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10223 return Res;
10224}
10225
10226template <typename Derived>
10229 DeclarationNameInfo DirName;
10230 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10231 D->getDirectiveKind(), DirName, nullptr, D->getBeginLoc());
10232 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10233 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10234 return Res;
10235}
10236
10237template <typename Derived>
10240 DeclarationNameInfo DirName;
10241 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10242 OMPD_for, DirName, nullptr, D->getBeginLoc());
10243 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10244 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10245 return Res;
10246}
10247
10248template <typename Derived>
10251 DeclarationNameInfo DirName;
10252 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10253 OMPD_for_simd, DirName, nullptr, D->getBeginLoc());
10254 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10255 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10256 return Res;
10257}
10258
10259template <typename Derived>
10262 DeclarationNameInfo DirName;
10263 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10264 OMPD_sections, DirName, nullptr, D->getBeginLoc());
10265 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10266 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10267 return Res;
10268}
10269
10270template <typename Derived>
10273 DeclarationNameInfo DirName;
10274 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10275 OMPD_section, DirName, nullptr, D->getBeginLoc());
10276 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10277 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10278 return Res;
10279}
10280
10281template <typename Derived>
10284 DeclarationNameInfo DirName;
10285 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10286 OMPD_scope, DirName, nullptr, D->getBeginLoc());
10287 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10288 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10289 return Res;
10290}
10291
10292template <typename Derived>
10295 DeclarationNameInfo DirName;
10296 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10297 OMPD_single, DirName, nullptr, D->getBeginLoc());
10298 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10299 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10300 return Res;
10301}
10302
10303template <typename Derived>
10306 DeclarationNameInfo DirName;
10307 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10308 OMPD_master, DirName, nullptr, D->getBeginLoc());
10309 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10310 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10311 return Res;
10312}
10313
10314template <typename Derived>
10317 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10318 OMPD_critical, D->getDirectiveName(), 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 OMPParallelForDirective *D) {
10327 DeclarationNameInfo DirName;
10328 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10329 OMPD_parallel_for, 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 OMPParallelForSimdDirective *D) {
10338 DeclarationNameInfo DirName;
10339 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10340 OMPD_parallel_for_simd, 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 OMPParallelMasterDirective *D) {
10349 DeclarationNameInfo DirName;
10350 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10351 OMPD_parallel_master, 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>
10359 OMPParallelMaskedDirective *D) {
10360 DeclarationNameInfo DirName;
10361 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10362 OMPD_parallel_masked, 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 OMPParallelSectionsDirective *D) {
10371 DeclarationNameInfo DirName;
10372 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10373 OMPD_parallel_sections, 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_task, 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>
10392 OMPTaskyieldDirective *D) {
10393 DeclarationNameInfo DirName;
10394 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10395 OMPD_taskyield, 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>
10404 DeclarationNameInfo DirName;
10405 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10406 OMPD_barrier, 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>
10415 DeclarationNameInfo DirName;
10416 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10417 OMPD_taskwait, 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>
10426 DeclarationNameInfo DirName;
10427 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10428 OMPD_assume, DirName, nullptr, D->getBeginLoc());
10429 StmtResult Res = getDerived().TransformOMPInformationalDirective(D);
10430 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10431 return Res;
10432}
10433
10434template <typename Derived>
10437 DeclarationNameInfo DirName;
10438 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10439 OMPD_error, 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 OMPTaskgroupDirective *D) {
10448 DeclarationNameInfo DirName;
10449 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10450 OMPD_taskgroup, 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>
10459 DeclarationNameInfo DirName;
10460 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10461 OMPD_flush, 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>
10470 DeclarationNameInfo DirName;
10471 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10472 OMPD_depobj, 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 DeclarationNameInfo DirName;
10482 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10483 OMPD_scan, DirName, nullptr, D->getBeginLoc());
10484 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10485 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10486 return Res;
10487}
10488
10489template <typename Derived>
10491 OMPOrderedStandaloneDirective *D) {
10492 DeclarationNameInfo DirName;
10493 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10494 OMPD_ordered_standalone, DirName, nullptr, D->getBeginLoc());
10495 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10496 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10497 return Res;
10498}
10499
10500template <typename Derived>
10502 OMPOrderedBlockAssocDirective *D) {
10503 DeclarationNameInfo DirName;
10504 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10505 OMPD_ordered_blockassoc, DirName, nullptr, D->getBeginLoc());
10506 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10507 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10508 return Res;
10509}
10510
10511template <typename Derived>
10514 DeclarationNameInfo DirName;
10515 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10516 OMPD_atomic, DirName, nullptr, D->getBeginLoc());
10517 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10518 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10519 return Res;
10520}
10521
10522template <typename Derived>
10525 DeclarationNameInfo DirName;
10526 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10527 OMPD_target, DirName, nullptr, D->getBeginLoc());
10528 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10529 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10530 return Res;
10531}
10532
10533template <typename Derived>
10535 OMPTargetDataDirective *D) {
10536 DeclarationNameInfo DirName;
10537 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10538 OMPD_target_data, DirName, nullptr, D->getBeginLoc());
10539 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10540 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10541 return Res;
10542}
10543
10544template <typename Derived>
10546 OMPTargetEnterDataDirective *D) {
10547 DeclarationNameInfo DirName;
10548 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10549 OMPD_target_enter_data, DirName, nullptr, D->getBeginLoc());
10550 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10551 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10552 return Res;
10553}
10554
10555template <typename Derived>
10557 OMPTargetExitDataDirective *D) {
10558 DeclarationNameInfo DirName;
10559 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10560 OMPD_target_exit_data, DirName, nullptr, D->getBeginLoc());
10561 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10562 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10563 return Res;
10564}
10565
10566template <typename Derived>
10568 OMPTargetParallelDirective *D) {
10569 DeclarationNameInfo DirName;
10570 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10571 OMPD_target_parallel, DirName, nullptr, D->getBeginLoc());
10572 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10573 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10574 return Res;
10575}
10576
10577template <typename Derived>
10579 OMPTargetParallelForDirective *D) {
10580 DeclarationNameInfo DirName;
10581 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10582 OMPD_target_parallel_for, DirName, nullptr, D->getBeginLoc());
10583 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10584 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10585 return Res;
10586}
10587
10588template <typename Derived>
10590 OMPTargetUpdateDirective *D) {
10591 DeclarationNameInfo DirName;
10592 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10593 OMPD_target_update, DirName, nullptr, D->getBeginLoc());
10594 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10595 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10596 return Res;
10597}
10598
10599template <typename Derived>
10602 DeclarationNameInfo DirName;
10603 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10604 OMPD_teams, DirName, nullptr, D->getBeginLoc());
10605 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10606 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10607 return Res;
10608}
10609
10610template <typename Derived>
10612 OMPCancellationPointDirective *D) {
10613 DeclarationNameInfo DirName;
10614 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10615 OMPD_cancellation_point, DirName, nullptr, D->getBeginLoc());
10616 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10617 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10618 return Res;
10619}
10620
10621template <typename Derived>
10624 DeclarationNameInfo DirName;
10625 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10626 OMPD_cancel, DirName, nullptr, D->getBeginLoc());
10627 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10628 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10629 return Res;
10630}
10631
10632template <typename Derived>
10635 DeclarationNameInfo DirName;
10636 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10637 OMPD_taskloop, DirName, nullptr, D->getBeginLoc());
10638 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10639 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10640 return Res;
10641}
10642
10643template <typename Derived>
10645 OMPTaskLoopSimdDirective *D) {
10646 DeclarationNameInfo DirName;
10647 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10648 OMPD_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10649 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10650 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10651 return Res;
10652}
10653
10654template <typename Derived>
10656 OMPMasterTaskLoopDirective *D) {
10657 DeclarationNameInfo DirName;
10658 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10659 OMPD_master_taskloop, DirName, nullptr, D->getBeginLoc());
10660 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10661 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10662 return Res;
10663}
10664
10665template <typename Derived>
10667 OMPMaskedTaskLoopDirective *D) {
10668 DeclarationNameInfo DirName;
10669 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10670 OMPD_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10671 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10672 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10673 return Res;
10674}
10675
10676template <typename Derived>
10678 OMPMasterTaskLoopSimdDirective *D) {
10679 DeclarationNameInfo DirName;
10680 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10681 OMPD_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10682 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10683 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10684 return Res;
10685}
10686
10687template <typename Derived>
10689 OMPMaskedTaskLoopSimdDirective *D) {
10690 DeclarationNameInfo DirName;
10691 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10692 OMPD_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10693 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10694 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10695 return Res;
10696}
10697
10698template <typename Derived>
10700 OMPParallelMasterTaskLoopDirective *D) {
10701 DeclarationNameInfo DirName;
10702 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10703 OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc());
10704 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10705 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10706 return Res;
10707}
10708
10709template <typename Derived>
10711 OMPParallelMaskedTaskLoopDirective *D) {
10712 DeclarationNameInfo DirName;
10713 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10714 OMPD_parallel_masked_taskloop, DirName, nullptr, D->getBeginLoc());
10715 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10716 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10717 return Res;
10718}
10719
10720template <typename Derived>
10723 OMPParallelMasterTaskLoopSimdDirective *D) {
10724 DeclarationNameInfo DirName;
10725 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10726 OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10727 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10728 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10729 return Res;
10730}
10731
10732template <typename Derived>
10735 OMPParallelMaskedTaskLoopSimdDirective *D) {
10736 DeclarationNameInfo DirName;
10737 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10738 OMPD_parallel_masked_taskloop_simd, DirName, nullptr, D->getBeginLoc());
10739 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10740 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10741 return Res;
10742}
10743
10744template <typename Derived>
10746 OMPDistributeDirective *D) {
10747 DeclarationNameInfo DirName;
10748 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10749 OMPD_distribute, DirName, nullptr, D->getBeginLoc());
10750 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10751 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10752 return Res;
10753}
10754
10755template <typename Derived>
10757 OMPDistributeParallelForDirective *D) {
10758 DeclarationNameInfo DirName;
10759 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10760 OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10761 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10762 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10763 return Res;
10764}
10765
10766template <typename Derived>
10769 OMPDistributeParallelForSimdDirective *D) {
10770 DeclarationNameInfo DirName;
10771 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10772 OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10773 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10774 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10775 return Res;
10776}
10777
10778template <typename Derived>
10780 OMPDistributeSimdDirective *D) {
10781 DeclarationNameInfo DirName;
10782 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10783 OMPD_distribute_simd, DirName, nullptr, D->getBeginLoc());
10784 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10785 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10786 return Res;
10787}
10788
10789template <typename Derived>
10791 OMPTargetParallelForSimdDirective *D) {
10792 DeclarationNameInfo DirName;
10793 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10794 OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc());
10795 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10796 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10797 return Res;
10798}
10799
10800template <typename Derived>
10802 OMPTargetSimdDirective *D) {
10803 DeclarationNameInfo DirName;
10804 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10805 OMPD_target_simd, DirName, nullptr, D->getBeginLoc());
10806 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10807 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10808 return Res;
10809}
10810
10811template <typename Derived>
10813 OMPTeamsDistributeDirective *D) {
10814 DeclarationNameInfo DirName;
10815 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10816 OMPD_teams_distribute, DirName, nullptr, D->getBeginLoc());
10817 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10818 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10819 return Res;
10820}
10821
10822template <typename Derived>
10824 OMPTeamsDistributeSimdDirective *D) {
10825 DeclarationNameInfo DirName;
10826 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10827 OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10828 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10829 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10830 return Res;
10831}
10832
10833template <typename Derived>
10835 OMPTeamsDistributeParallelForSimdDirective *D) {
10836 DeclarationNameInfo DirName;
10837 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10838 OMPD_teams_distribute_parallel_for_simd, DirName, nullptr,
10839 D->getBeginLoc());
10840 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10841 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10842 return Res;
10843}
10844
10845template <typename Derived>
10847 OMPTeamsDistributeParallelForDirective *D) {
10848 DeclarationNameInfo DirName;
10849 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10850 OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc());
10851 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10852 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10853 return Res;
10854}
10855
10856template <typename Derived>
10858 OMPTargetTeamsDirective *D) {
10859 DeclarationNameInfo DirName;
10860 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10861 OMPD_target_teams, DirName, nullptr, D->getBeginLoc());
10862 auto Res = getDerived().TransformOMPExecutableDirective(D);
10863 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10864 return Res;
10865}
10866
10867template <typename Derived>
10869 OMPTargetTeamsDistributeDirective *D) {
10870 DeclarationNameInfo DirName;
10871 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10872 OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc());
10873 auto Res = getDerived().TransformOMPExecutableDirective(D);
10874 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10875 return Res;
10876}
10877
10878template <typename Derived>
10881 OMPTargetTeamsDistributeParallelForDirective *D) {
10882 DeclarationNameInfo DirName;
10883 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10884 OMPD_target_teams_distribute_parallel_for, DirName, nullptr,
10885 D->getBeginLoc());
10886 auto Res = getDerived().TransformOMPExecutableDirective(D);
10887 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10888 return Res;
10889}
10890
10891template <typename Derived>
10894 OMPTargetTeamsDistributeParallelForSimdDirective *D) {
10895 DeclarationNameInfo DirName;
10896 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10897 OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr,
10898 D->getBeginLoc());
10899 auto Res = getDerived().TransformOMPExecutableDirective(D);
10900 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10901 return Res;
10902}
10903
10904template <typename Derived>
10907 OMPTargetTeamsDistributeSimdDirective *D) {
10908 DeclarationNameInfo DirName;
10909 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10910 OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc());
10911 auto Res = getDerived().TransformOMPExecutableDirective(D);
10912 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10913 return Res;
10914}
10915
10916template <typename Derived>
10919 DeclarationNameInfo DirName;
10920 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10921 OMPD_interop, DirName, nullptr, D->getBeginLoc());
10922 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10923 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10924 return Res;
10925}
10926
10927template <typename Derived>
10930 DeclarationNameInfo DirName;
10931 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10932 OMPD_dispatch, DirName, nullptr, D->getBeginLoc());
10933 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10934 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10935 return Res;
10936}
10937
10938template <typename Derived>
10941 DeclarationNameInfo DirName;
10942 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10943 OMPD_masked, DirName, nullptr, D->getBeginLoc());
10944 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10945 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10946 return Res;
10947}
10948
10949template <typename Derived>
10951 OMPGenericLoopDirective *D) {
10952 DeclarationNameInfo DirName;
10953 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10954 OMPD_loop, DirName, nullptr, D->getBeginLoc());
10955 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10956 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10957 return Res;
10958}
10959
10960template <typename Derived>
10962 OMPTeamsGenericLoopDirective *D) {
10963 DeclarationNameInfo DirName;
10964 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10965 OMPD_teams_loop, DirName, nullptr, D->getBeginLoc());
10966 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10967 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10968 return Res;
10969}
10970
10971template <typename Derived>
10973 OMPTargetTeamsGenericLoopDirective *D) {
10974 DeclarationNameInfo DirName;
10975 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10976 OMPD_target_teams_loop, DirName, nullptr, D->getBeginLoc());
10977 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10978 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10979 return Res;
10980}
10981
10982template <typename Derived>
10984 OMPParallelGenericLoopDirective *D) {
10985 DeclarationNameInfo DirName;
10986 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10987 OMPD_parallel_loop, DirName, nullptr, D->getBeginLoc());
10988 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
10989 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
10990 return Res;
10991}
10992
10993template <typename Derived>
10996 OMPTargetParallelGenericLoopDirective *D) {
10997 DeclarationNameInfo DirName;
10998 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
10999 OMPD_target_parallel_loop, DirName, nullptr, D->getBeginLoc());
11000 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
11001 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
11002 return Res;
11003}
11004
11005template <typename Derived>
11007 OMPTargetGenericLoopDirective *D) {
11008 DeclarationNameInfo DirName;
11009 getDerived().getSema().OpenMP().StartOpenMPDSABlock(
11010 OMPD_target_loop, DirName, nullptr, D->getBeginLoc());
11011 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
11012 getDerived().getSema().OpenMP().EndOpenMPDSABlock(Res.get());
11013 return Res;
11014}
11015
11016//===----------------------------------------------------------------------===//
11017// OpenMP clause transformation
11018//===----------------------------------------------------------------------===//
11019template <typename Derived>
11021 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11022 if (Cond.isInvalid())
11023 return nullptr;
11024 return getDerived().RebuildOMPIfClause(
11025 C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(),
11026 C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc());
11027}
11028
11029template <typename Derived>
11031 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11032 if (Cond.isInvalid())
11033 return nullptr;
11034 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(),
11035 C->getLParenLoc(), C->getEndLoc());
11036}
11037
11038template <typename Derived>
11039OMPClause *
11042 Vars.reserve(C->varlist_size());
11043 for (auto *VE : C->varlist()) {
11044 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11045 if (EVar.isInvalid())
11046 return nullptr;
11047 Vars.push_back(EVar.get());
11048 }
11049 Expr *DimsModifierExpr = C->getDimsModifierExpr();
11050 if (DimsModifierExpr) {
11051 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(DimsModifierExpr));
11052 if (EVar.isInvalid())
11053 return nullptr;
11054 DimsModifierExpr = EVar.get();
11055 }
11056 return getDerived().RebuildOMPNumThreadsClause(
11057 Vars, C->getPrescriptivenessModifier(),
11058 C->getPrescriptivenessModifierLoc(), C->getDimsModifier(),
11059 DimsModifierExpr, C->getDimsModifierLoc(), C->getBeginLoc(),
11060 C->getLParenLoc(), C->getEndLoc());
11061}
11062
11063template <typename Derived>
11064OMPClause *
11066 ExprResult E = getDerived().TransformExpr(C->getSafelen());
11067 if (E.isInvalid())
11068 return nullptr;
11069 return getDerived().RebuildOMPSafelenClause(
11070 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11071}
11072
11073template <typename Derived>
11074OMPClause *
11076 ExprResult E = getDerived().TransformExpr(C->getAllocator());
11077 if (E.isInvalid())
11078 return nullptr;
11079 return getDerived().RebuildOMPAllocatorClause(
11080 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11081}
11082
11083template <typename Derived>
11084OMPClause *
11086 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
11087 if (E.isInvalid())
11088 return nullptr;
11089 return getDerived().RebuildOMPSimdlenClause(
11090 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11091}
11092
11093template <typename Derived>
11095 SmallVector<Expr *, 4> TransformedSizes;
11096 TransformedSizes.reserve(C->getNumSizes());
11097 bool Changed = false;
11098 for (Expr *E : C->getSizesRefs()) {
11099 if (!E) {
11100 TransformedSizes.push_back(nullptr);
11101 continue;
11102 }
11103
11104 ExprResult T = getDerived().TransformExpr(E);
11105 if (T.isInvalid())
11106 return nullptr;
11107 if (E != T.get())
11108 Changed = true;
11109 TransformedSizes.push_back(T.get());
11110 }
11111
11112 if (!Changed && !getDerived().AlwaysRebuild())
11113 return C;
11114 return RebuildOMPSizesClause(TransformedSizes, C->getBeginLoc(),
11115 C->getLParenLoc(), C->getEndLoc());
11116}
11117
11118template <typename Derived>
11119OMPClause *
11121 SmallVector<Expr *, 4> TransformedCounts;
11122 TransformedCounts.reserve(C->getNumCounts());
11123 for (Expr *E : C->getCountsRefs()) {
11124 if (!E) {
11125 TransformedCounts.push_back(nullptr);
11126 continue;
11127 }
11128
11129 ExprResult T = getDerived().TransformExpr(E);
11130 if (T.isInvalid())
11131 return nullptr;
11132 TransformedCounts.push_back(T.get());
11133 }
11134
11135 return RebuildOMPCountsClause(TransformedCounts, C->getBeginLoc(),
11136 C->getLParenLoc(), C->getEndLoc(),
11137 C->getOmpFillIndex(), C->getOmpFillLoc());
11138}
11139
11140template <typename Derived>
11141OMPClause *
11143 SmallVector<Expr *> TransformedArgs;
11144 TransformedArgs.reserve(C->getNumLoops());
11145 bool Changed = false;
11146 for (Expr *E : C->getArgsRefs()) {
11147 if (!E) {
11148 TransformedArgs.push_back(nullptr);
11149 continue;
11150 }
11151
11152 ExprResult T = getDerived().TransformExpr(E);
11153 if (T.isInvalid())
11154 return nullptr;
11155 if (E != T.get())
11156 Changed = true;
11157 TransformedArgs.push_back(T.get());
11158 }
11159
11160 if (!Changed && !getDerived().AlwaysRebuild())
11161 return C;
11162 return RebuildOMPPermutationClause(TransformedArgs, C->getBeginLoc(),
11163 C->getLParenLoc(), C->getEndLoc());
11164}
11165
11166template <typename Derived>
11168 if (!getDerived().AlwaysRebuild())
11169 return C;
11170 return RebuildOMPFullClause(C->getBeginLoc(), C->getEndLoc());
11171}
11172
11173template <typename Derived>
11174OMPClause *
11176 ExprResult T = getDerived().TransformExpr(C->getFactor());
11177 if (T.isInvalid())
11178 return nullptr;
11179 Expr *Factor = T.get();
11180 bool Changed = Factor != C->getFactor();
11181
11182 if (!Changed && !getDerived().AlwaysRebuild())
11183 return C;
11184 return RebuildOMPPartialClause(Factor, C->getBeginLoc(), C->getLParenLoc(),
11185 C->getEndLoc());
11186}
11187
11188template <typename Derived>
11190 ExprResult T = getDerived().TransformExpr(C->getDepth());
11191 if (T.isInvalid())
11192 return nullptr;
11193 Expr *Depth = T.get();
11194 bool Changed = Depth != C->getDepth();
11195
11196 if (!Changed && !getDerived().AlwaysRebuild())
11197 return C;
11198 return RebuildOMPDepthClause(Depth, C->getBeginLoc(), C->getLParenLoc(),
11199 C->getEndLoc());
11200}
11201
11202template <typename Derived>
11203OMPClause *
11205 ExprResult F = getDerived().TransformExpr(C->getFirst());
11206 if (F.isInvalid())
11207 return nullptr;
11208
11209 ExprResult Cn = getDerived().TransformExpr(C->getCount());
11210 if (Cn.isInvalid())
11211 return nullptr;
11212
11213 Expr *First = F.get();
11214 Expr *Count = Cn.get();
11215
11216 bool Changed = (First != C->getFirst()) || (Count != C->getCount());
11217
11218 // If no changes and AlwaysRebuild() is false, return the original clause
11219 if (!Changed && !getDerived().AlwaysRebuild())
11220 return C;
11221
11222 return RebuildOMPLoopRangeClause(First, Count, C->getBeginLoc(),
11223 C->getLParenLoc(), C->getFirstLoc(),
11224 C->getCountLoc(), C->getEndLoc());
11225}
11226
11227template <typename Derived>
11228OMPClause *
11230 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
11231 if (E.isInvalid())
11232 return nullptr;
11233 return getDerived().RebuildOMPCollapseClause(
11234 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11235}
11236
11237template <typename Derived>
11238OMPClause *
11240 return getDerived().RebuildOMPDefaultClause(
11241 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getDefaultVC(),
11242 C->getDefaultVCLoc(), C->getBeginLoc(), C->getLParenLoc(),
11243 C->getEndLoc());
11244}
11245
11246template <typename Derived>
11247OMPClause *
11249 // No need to rebuild this clause, no template-dependent parameters.
11250 return C;
11251}
11252
11253template <typename Derived>
11254OMPClause *
11256 Expr *Impex = C->getImpexType();
11257 ExprResult TransformedImpex = getDerived().TransformExpr(Impex);
11258
11259 if (TransformedImpex.isInvalid())
11260 return nullptr;
11261
11262 return getDerived().RebuildOMPTransparentClause(
11263 TransformedImpex.get(), C->getBeginLoc(), C->getLParenLoc(),
11264 C->getEndLoc());
11265}
11266
11267template <typename Derived>
11268OMPClause *
11270 return getDerived().RebuildOMPProcBindClause(
11271 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(),
11272 C->getLParenLoc(), C->getEndLoc());
11273}
11274
11275template <typename Derived>
11276OMPClause *
11278 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
11279 if (E.isInvalid())
11280 return nullptr;
11281 return getDerived().RebuildOMPScheduleClause(
11282 C->getFirstScheduleModifier(), C->getSecondScheduleModifier(),
11283 C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11284 C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(),
11285 C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
11286}
11287
11288template <typename Derived>
11289OMPClause *
11291 ExprResult E;
11292 if (auto *Num = C->getNumForLoops()) {
11293 E = getDerived().TransformExpr(Num);
11294 if (E.isInvalid())
11295 return nullptr;
11296 }
11297 return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(),
11298 C->getLParenLoc(), E.get());
11299}
11300
11301template <typename Derived>
11302OMPClause *
11304 ExprResult E;
11305 if (Expr *Evt = C->getEventHandler()) {
11306 E = getDerived().TransformExpr(Evt);
11307 if (E.isInvalid())
11308 return nullptr;
11309 }
11310 return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(),
11311 C->getLParenLoc(), C->getEndLoc());
11312}
11313
11314template <typename Derived>
11315OMPClause *
11317 ExprResult Cond;
11318 if (auto *Condition = C->getCondition()) {
11319 Cond = getDerived().TransformExpr(Condition);
11320 if (Cond.isInvalid())
11321 return nullptr;
11322 }
11323 return getDerived().RebuildOMPNowaitClause(Cond.get(), C->getBeginLoc(),
11324 C->getLParenLoc(), C->getEndLoc());
11325}
11326
11327template <typename Derived>
11328OMPClause *
11330 // No need to rebuild this clause, no template-dependent parameters.
11331 return C;
11332}
11333
11334template <typename Derived>
11335OMPClause *
11337 // No need to rebuild this clause, no template-dependent parameters.
11338 return C;
11339}
11340
11341template <typename Derived>
11343 // No need to rebuild this clause, no template-dependent parameters.
11344 return C;
11345}
11346
11347template <typename Derived>
11349 // No need to rebuild this clause, no template-dependent parameters.
11350 return C;
11351}
11352
11353template <typename Derived>
11354OMPClause *
11356 // No need to rebuild this clause, no template-dependent parameters.
11357 return C;
11358}
11359
11360template <typename Derived>
11362 OMPUpdateDependObjectsClause *C) {
11363 // No need to rebuild this clause, no template-dependent parameters.
11364 return C;
11365}
11366
11367template <typename Derived>
11368OMPClause *
11370 // No need to rebuild this clause, no template-dependent parameters.
11371 return C;
11372}
11373
11374template <typename Derived>
11375OMPClause *
11377 // No need to rebuild this clause, no template-dependent parameters.
11378 return C;
11379}
11380
11381template <typename Derived>
11383 // No need to rebuild this clause, no template-dependent parameters.
11384 return C;
11385}
11386
11387template <typename Derived>
11388OMPClause *
11390 return C;
11391}
11392
11393template <typename Derived>
11395 ExprResult E = getDerived().TransformExpr(C->getExpr());
11396 if (E.isInvalid())
11397 return nullptr;
11398 return getDerived().RebuildOMPHoldsClause(E.get(), C->getBeginLoc(),
11399 C->getLParenLoc(), C->getEndLoc());
11400}
11401
11402template <typename Derived>
11403OMPClause *
11405 return C;
11406}
11407
11408template <typename Derived>
11409OMPClause *
11411 return C;
11412}
11413template <typename Derived>
11415 OMPNoOpenMPRoutinesClause *C) {
11416 return C;
11417}
11418template <typename Derived>
11420 OMPNoOpenMPConstructsClause *C) {
11421 return C;
11422}
11423template <typename Derived>
11425 OMPNoParallelismClause *C) {
11426 return C;
11427}
11428
11429template <typename Derived>
11430OMPClause *
11432 // No need to rebuild this clause, no template-dependent parameters.
11433 return C;
11434}
11435
11436template <typename Derived>
11437OMPClause *
11439 // No need to rebuild this clause, no template-dependent parameters.
11440 return C;
11441}
11442
11443template <typename Derived>
11444OMPClause *
11446 // No need to rebuild this clause, no template-dependent parameters.
11447 return C;
11448}
11449
11450template <typename Derived>
11451OMPClause *
11453 // No need to rebuild this clause, no template-dependent parameters.
11454 return C;
11455}
11456
11457template <typename Derived>
11458OMPClause *
11460 // No need to rebuild this clause, no template-dependent parameters.
11461 return C;
11462}
11463
11464template <typename Derived>
11466 // No need to rebuild this clause, no template-dependent parameters.
11467 return C;
11468}
11469
11470template <typename Derived>
11471OMPClause *
11473 // No need to rebuild this clause, no template-dependent parameters.
11474 return C;
11475}
11476
11477template <typename Derived>
11479 // No need to rebuild this clause, no template-dependent parameters.
11480 return C;
11481}
11482
11483template <typename Derived>
11484OMPClause *
11486 // No need to rebuild this clause, no template-dependent parameters.
11487 return C;
11488}
11489
11490template <typename Derived>
11492 ExprResult IVR = getDerived().TransformExpr(C->getInteropVar());
11493 if (IVR.isInvalid())
11494 return nullptr;
11495
11496 OMPInteropInfo InteropInfo(C->getIsTarget(), C->getIsTargetSync());
11497 for (OMPInitClause::PrefView P : C->prefs()) {
11498 Expr *NewFr = nullptr;
11499 if (P.Fr) {
11500 ExprResult ER = getDerived().TransformExpr(P.Fr);
11501 if (ER.isInvalid())
11502 return nullptr;
11503 NewFr = ER.get();
11504 }
11505 SmallVector<Expr *, 2> NewAttrs;
11506 NewAttrs.reserve(P.Attrs.size());
11507 for (Expr *A : P.Attrs) {
11508 ExprResult ER = getDerived().TransformExpr(A);
11509 if (ER.isInvalid())
11510 return nullptr;
11511 NewAttrs.push_back(ER.get());
11512 }
11513 InteropInfo.Prefs.emplace_back(NewFr, std::move(NewAttrs));
11514 }
11515 InteropInfo.HasPreferAttrs = C->hasPreferAttrs();
11516 return getDerived().RebuildOMPInitClause(IVR.get(), InteropInfo,
11517 C->getBeginLoc(), C->getLParenLoc(),
11518 C->getVarLoc(), C->getEndLoc());
11519}
11520
11521template <typename Derived>
11523 ExprResult ER = getDerived().TransformExpr(C->getInteropVar());
11524 if (ER.isInvalid())
11525 return nullptr;
11526 return getDerived().RebuildOMPUseClause(ER.get(), C->getBeginLoc(),
11527 C->getLParenLoc(), C->getVarLoc(),
11528 C->getEndLoc());
11529}
11530
11531template <typename Derived>
11532OMPClause *
11534 ExprResult ER;
11535 if (Expr *IV = C->getInteropVar()) {
11536 ER = getDerived().TransformExpr(IV);
11537 if (ER.isInvalid())
11538 return nullptr;
11539 }
11540 return getDerived().RebuildOMPDestroyClause(ER.get(), C->getBeginLoc(),
11541 C->getLParenLoc(), C->getVarLoc(),
11542 C->getEndLoc());
11543}
11544
11545template <typename Derived>
11546OMPClause *
11548 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11549 if (Cond.isInvalid())
11550 return nullptr;
11551 return getDerived().RebuildOMPNovariantsClause(
11552 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11553}
11554
11555template <typename Derived>
11556OMPClause *
11558 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
11559 if (Cond.isInvalid())
11560 return nullptr;
11561 return getDerived().RebuildOMPNocontextClause(
11562 Cond.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11563}
11564
11565template <typename Derived>
11566OMPClause *
11568 ExprResult ThreadID = getDerived().TransformExpr(C->getThreadID());
11569 if (ThreadID.isInvalid())
11570 return nullptr;
11571 return getDerived().RebuildOMPFilterClause(ThreadID.get(), C->getBeginLoc(),
11572 C->getLParenLoc(), C->getEndLoc());
11573}
11574
11575template <typename Derived>
11577 ExprResult E = getDerived().TransformExpr(C->getAlignment());
11578 if (E.isInvalid())
11579 return nullptr;
11580 return getDerived().RebuildOMPAlignClause(E.get(), C->getBeginLoc(),
11581 C->getLParenLoc(), C->getEndLoc());
11582}
11583
11584template <typename Derived>
11586 OMPUnifiedAddressClause *C) {
11587 llvm_unreachable("unified_address clause cannot appear in dependent context");
11588}
11589
11590template <typename Derived>
11592 OMPUnifiedSharedMemoryClause *C) {
11593 llvm_unreachable(
11594 "unified_shared_memory clause cannot appear in dependent context");
11595}
11596
11597template <typename Derived>
11599 OMPReverseOffloadClause *C) {
11600 llvm_unreachable("reverse_offload clause cannot appear in dependent context");
11601}
11602
11603template <typename Derived>
11605 OMPDynamicAllocatorsClause *C) {
11606 llvm_unreachable(
11607 "dynamic_allocators clause cannot appear in dependent context");
11608}
11609
11610template <typename Derived>
11612 OMPAtomicDefaultMemOrderClause *C) {
11613 llvm_unreachable(
11614 "atomic_default_mem_order clause cannot appear in dependent context");
11615}
11616
11617template <typename Derived>
11618OMPClause *
11620 llvm_unreachable("self_maps clause cannot appear in dependent context");
11621}
11622
11623template <typename Derived>
11625 return getDerived().RebuildOMPAtClause(C->getAtKind(), C->getAtKindKwLoc(),
11626 C->getBeginLoc(), C->getLParenLoc(),
11627 C->getEndLoc());
11628}
11629
11630template <typename Derived>
11631OMPClause *
11633 return getDerived().RebuildOMPSeverityClause(
11634 C->getSeverityKind(), C->getSeverityKindKwLoc(), C->getBeginLoc(),
11635 C->getLParenLoc(), C->getEndLoc());
11636}
11637
11638template <typename Derived>
11639OMPClause *
11641 ExprResult E = getDerived().TransformExpr(C->getMessageString());
11642 if (E.isInvalid())
11643 return nullptr;
11644 return getDerived().RebuildOMPMessageClause(
11645 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11646}
11647
11648template <typename Derived>
11649OMPClause *
11652 Vars.reserve(C->varlist_size());
11653 for (auto *VE : C->varlist()) {
11654 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11655 if (EVar.isInvalid())
11656 return nullptr;
11657 Vars.push_back(EVar.get());
11658 }
11659 return getDerived().RebuildOMPPrivateClause(
11660 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11661}
11662
11663template <typename Derived>
11665 OMPFirstprivateClause *C) {
11667 Vars.reserve(C->varlist_size());
11668 for (auto *VE : C->varlist()) {
11669 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11670 if (EVar.isInvalid())
11671 return nullptr;
11672 Vars.push_back(EVar.get());
11673 }
11674 return getDerived().RebuildOMPFirstprivateClause(
11675 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11676}
11677
11678template <typename Derived>
11679OMPClause *
11682 Vars.reserve(C->varlist_size());
11683 for (auto *VE : C->varlist()) {
11684 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11685 if (EVar.isInvalid())
11686 return nullptr;
11687 Vars.push_back(EVar.get());
11688 }
11689 return getDerived().RebuildOMPLastprivateClause(
11690 Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(),
11691 C->getLParenLoc(), C->getEndLoc());
11692}
11693
11694template <typename Derived>
11695OMPClause *
11698 Vars.reserve(C->varlist_size());
11699 for (auto *VE : C->varlist()) {
11700 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11701 if (EVar.isInvalid())
11702 return nullptr;
11703 Vars.push_back(EVar.get());
11704 }
11705 return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(),
11706 C->getLParenLoc(), C->getEndLoc());
11707}
11708
11709template <typename Derived>
11710OMPClause *
11713 Vars.reserve(C->varlist_size());
11714 for (auto *VE : C->varlist()) {
11715 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11716 if (EVar.isInvalid())
11717 return nullptr;
11718 Vars.push_back(EVar.get());
11719 }
11720 CXXScopeSpec ReductionIdScopeSpec;
11721 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11722
11723 DeclarationNameInfo NameInfo = C->getNameInfo();
11724 if (NameInfo.getName()) {
11725 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11726 if (!NameInfo.getName())
11727 return nullptr;
11728 }
11729 // Build a list of all UDR decls with the same names ranged by the Scopes.
11730 // The Scope boundary is a duplication of the previous decl.
11731 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11732 for (auto *E : C->reduction_ops()) {
11733 // Transform all the decls.
11734 if (E) {
11735 auto *ULE = cast<UnresolvedLookupExpr>(E);
11736 UnresolvedSet<8> Decls;
11737 for (auto *D : ULE->decls()) {
11738 NamedDecl *InstD =
11739 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11740 Decls.addDecl(InstD, InstD->getAccess());
11741 }
11742 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11743 SemaRef.Context, /*NamingClass=*/nullptr,
11744 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11745 /*ADL=*/true, Decls.begin(), Decls.end(),
11746 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11747 } else
11748 UnresolvedReductions.push_back(nullptr);
11749 }
11750 return getDerived().RebuildOMPReductionClause(
11751 Vars, C->getModifier(), C->getOriginalSharingModifier(), C->getBeginLoc(),
11752 C->getLParenLoc(), C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(),
11753 ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11754}
11755
11756template <typename Derived>
11758 OMPTaskReductionClause *C) {
11760 Vars.reserve(C->varlist_size());
11761 for (auto *VE : C->varlist()) {
11762 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11763 if (EVar.isInvalid())
11764 return nullptr;
11765 Vars.push_back(EVar.get());
11766 }
11767 CXXScopeSpec ReductionIdScopeSpec;
11768 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11769
11770 DeclarationNameInfo NameInfo = C->getNameInfo();
11771 if (NameInfo.getName()) {
11772 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11773 if (!NameInfo.getName())
11774 return nullptr;
11775 }
11776 // Build a list of all UDR decls with the same names ranged by the Scopes.
11777 // The Scope boundary is a duplication of the previous decl.
11778 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11779 for (auto *E : C->reduction_ops()) {
11780 // Transform all the decls.
11781 if (E) {
11782 auto *ULE = cast<UnresolvedLookupExpr>(E);
11783 UnresolvedSet<8> Decls;
11784 for (auto *D : ULE->decls()) {
11785 NamedDecl *InstD =
11786 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11787 Decls.addDecl(InstD, InstD->getAccess());
11788 }
11789 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11790 SemaRef.Context, /*NamingClass=*/nullptr,
11791 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11792 /*ADL=*/true, Decls.begin(), Decls.end(),
11793 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11794 } else
11795 UnresolvedReductions.push_back(nullptr);
11796 }
11797 return getDerived().RebuildOMPTaskReductionClause(
11798 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11799 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11800}
11801
11802template <typename Derived>
11803OMPClause *
11806 Vars.reserve(C->varlist_size());
11807 for (auto *VE : C->varlist()) {
11808 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11809 if (EVar.isInvalid())
11810 return nullptr;
11811 Vars.push_back(EVar.get());
11812 }
11813 CXXScopeSpec ReductionIdScopeSpec;
11814 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
11815
11816 DeclarationNameInfo NameInfo = C->getNameInfo();
11817 if (NameInfo.getName()) {
11818 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
11819 if (!NameInfo.getName())
11820 return nullptr;
11821 }
11822 // Build a list of all UDR decls with the same names ranged by the Scopes.
11823 // The Scope boundary is a duplication of the previous decl.
11824 llvm::SmallVector<Expr *, 16> UnresolvedReductions;
11825 for (auto *E : C->reduction_ops()) {
11826 // Transform all the decls.
11827 if (E) {
11828 auto *ULE = cast<UnresolvedLookupExpr>(E);
11829 UnresolvedSet<8> Decls;
11830 for (auto *D : ULE->decls()) {
11831 NamedDecl *InstD =
11832 cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D));
11833 Decls.addDecl(InstD, InstD->getAccess());
11834 }
11835 UnresolvedReductions.push_back(UnresolvedLookupExpr::Create(
11836 SemaRef.Context, /*NamingClass=*/nullptr,
11837 ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo,
11838 /*ADL=*/true, Decls.begin(), Decls.end(),
11839 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
11840 } else
11841 UnresolvedReductions.push_back(nullptr);
11842 }
11843 return getDerived().RebuildOMPInReductionClause(
11844 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(),
11845 C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions);
11846}
11847
11848template <typename Derived>
11849OMPClause *
11852 Vars.reserve(C->varlist_size());
11853 for (auto *VE : C->varlist()) {
11854 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11855 if (EVar.isInvalid())
11856 return nullptr;
11857 Vars.push_back(EVar.get());
11858 }
11859 ExprResult Step = getDerived().TransformExpr(C->getStep());
11860 if (Step.isInvalid())
11861 return nullptr;
11862 return getDerived().RebuildOMPLinearClause(
11863 Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(),
11864 C->getModifierLoc(), C->getColonLoc(), C->getStepModifierLoc(),
11865 C->getEndLoc());
11866}
11867
11868template <typename Derived>
11869OMPClause *
11872 Vars.reserve(C->varlist_size());
11873 for (auto *VE : C->varlist()) {
11874 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11875 if (EVar.isInvalid())
11876 return nullptr;
11877 Vars.push_back(EVar.get());
11878 }
11879 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
11880 if (Alignment.isInvalid())
11881 return nullptr;
11882 return getDerived().RebuildOMPAlignedClause(
11883 Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(),
11884 C->getColonLoc(), C->getEndLoc());
11885}
11886
11887template <typename Derived>
11888OMPClause *
11891 Vars.reserve(C->varlist_size());
11892 for (auto *VE : C->varlist()) {
11893 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11894 if (EVar.isInvalid())
11895 return nullptr;
11896 Vars.push_back(EVar.get());
11897 }
11898 return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(),
11899 C->getLParenLoc(), C->getEndLoc());
11900}
11901
11902template <typename Derived>
11903OMPClause *
11906 Vars.reserve(C->varlist_size());
11907 for (auto *VE : C->varlist()) {
11908 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11909 if (EVar.isInvalid())
11910 return nullptr;
11911 Vars.push_back(EVar.get());
11912 }
11913 return getDerived().RebuildOMPCopyprivateClause(
11914 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11915}
11916
11917template <typename Derived>
11920 Vars.reserve(C->varlist_size());
11921 for (auto *VE : C->varlist()) {
11922 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11923 if (EVar.isInvalid())
11924 return nullptr;
11925 Vars.push_back(EVar.get());
11926 }
11927 return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(),
11928 C->getLParenLoc(), C->getEndLoc());
11929}
11930
11931template <typename Derived>
11932OMPClause *
11934 ExprResult E = getDerived().TransformExpr(C->getDepobj());
11935 if (E.isInvalid())
11936 return nullptr;
11937 return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(),
11938 C->getLParenLoc(), C->getEndLoc());
11939}
11940
11941template <typename Derived>
11942OMPClause *
11945 Expr *DepModifier = C->getModifier();
11946 if (DepModifier) {
11947 ExprResult DepModRes = getDerived().TransformExpr(DepModifier);
11948 if (DepModRes.isInvalid())
11949 return nullptr;
11950 DepModifier = DepModRes.get();
11951 }
11952 Vars.reserve(C->varlist_size());
11953 for (auto *VE : C->varlist()) {
11954 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
11955 if (EVar.isInvalid())
11956 return nullptr;
11957 Vars.push_back(EVar.get());
11958 }
11959 return getDerived().RebuildOMPDependClause(
11960 {C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(),
11961 C->getOmpAllMemoryLoc()},
11962 DepModifier, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
11963}
11964
11965template <typename Derived>
11966OMPClause *
11968 ExprResult E = getDerived().TransformExpr(C->getDevice());
11969 if (E.isInvalid())
11970 return nullptr;
11971 return getDerived().RebuildOMPDeviceClause(
11972 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
11973 C->getModifierLoc(), C->getEndLoc());
11974}
11975
11976template <typename Derived, class T>
11979 llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec,
11980 DeclarationNameInfo &MapperIdInfo,
11981 llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) {
11982 // Transform expressions in the list.
11983 Vars.reserve(C->varlist_size());
11984 for (auto *VE : C->varlist()) {
11985 ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE));
11986 if (EVar.isInvalid())
11987 return true;
11988 Vars.push_back(EVar.get());
11989 }
11990 // Transform mapper scope specifier and identifier.
11991 NestedNameSpecifierLoc QualifierLoc;
11992 if (C->getMapperQualifierLoc()) {
11993 QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc(
11994 C->getMapperQualifierLoc());
11995 if (!QualifierLoc)
11996 return true;
11997 }
11998 MapperIdScopeSpec.Adopt(QualifierLoc);
11999 MapperIdInfo = C->getMapperIdInfo();
12000 if (MapperIdInfo.getName()) {
12001 MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo);
12002 if (!MapperIdInfo.getName())
12003 return true;
12004 }
12005 // Build a list of all candidate OMPDeclareMapperDecls, which is provided by
12006 // the previous user-defined mapper lookup in dependent environment.
12007 for (auto *E : C->mapperlists()) {
12008 // Transform all the decls.
12009 if (E) {
12010 auto *ULE = cast<UnresolvedLookupExpr>(E);
12011 UnresolvedSet<8> Decls;
12012 for (auto *D : ULE->decls()) {
12013 NamedDecl *InstD =
12014 cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D));
12015 Decls.addDecl(InstD, InstD->getAccess());
12016 }
12017 UnresolvedMappers.push_back(UnresolvedLookupExpr::Create(
12018 TT.getSema().Context, /*NamingClass=*/nullptr,
12019 MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context),
12020 MapperIdInfo, /*ADL=*/true, Decls.begin(), Decls.end(),
12021 /*KnownDependent=*/false, /*KnownInstantiationDependent=*/false));
12022 } else {
12023 UnresolvedMappers.push_back(nullptr);
12024 }
12025 }
12026 return false;
12027}
12028
12029template <typename Derived>
12030OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) {
12031 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12033 Expr *IteratorModifier = C->getIteratorModifier();
12034 if (IteratorModifier) {
12035 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
12036 if (MapModRes.isInvalid())
12037 return nullptr;
12038 IteratorModifier = MapModRes.get();
12039 }
12040 CXXScopeSpec MapperIdScopeSpec;
12041 DeclarationNameInfo MapperIdInfo;
12042 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
12044 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
12045 return nullptr;
12046 return getDerived().RebuildOMPMapClause(
12047 IteratorModifier, C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(),
12048 MapperIdScopeSpec, MapperIdInfo, C->getMapType(), C->isImplicitMapType(),
12049 C->getMapLoc(), C->getColonLoc(), Vars, Locs, UnresolvedMappers);
12050}
12051
12052template <typename Derived>
12053OMPClause *
12055 Expr *Allocator = C->getAllocator();
12056 if (Allocator) {
12057 ExprResult AllocatorRes = getDerived().TransformExpr(Allocator);
12058 if (AllocatorRes.isInvalid())
12059 return nullptr;
12060 Allocator = AllocatorRes.get();
12061 }
12062 Expr *Alignment = C->getAlignment();
12063 if (Alignment) {
12064 ExprResult AlignmentRes = getDerived().TransformExpr(Alignment);
12065 if (AlignmentRes.isInvalid())
12066 return nullptr;
12067 Alignment = AlignmentRes.get();
12068 }
12070 Vars.reserve(C->varlist_size());
12071 for (auto *VE : C->varlist()) {
12072 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12073 if (EVar.isInvalid())
12074 return nullptr;
12075 Vars.push_back(EVar.get());
12076 }
12077 return getDerived().RebuildOMPAllocateClause(
12078 Allocator, Alignment, C->getFirstAllocateModifier(),
12079 C->getFirstAllocateModifierLoc(), C->getSecondAllocateModifier(),
12080 C->getSecondAllocateModifierLoc(), Vars, C->getBeginLoc(),
12081 C->getLParenLoc(), C->getColonLoc(), C->getEndLoc());
12082}
12083
12084template <typename Derived>
12085OMPClause *
12088 Vars.reserve(C->varlist_size());
12089 for (auto *VE : C->varlist()) {
12090 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12091 if (EVar.isInvalid())
12092 return nullptr;
12093 Vars.push_back(EVar.get());
12094 }
12095 Expr *ModifierExpr = C->getModifierExpr();
12096 if (ModifierExpr) {
12097 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(ModifierExpr));
12098 if (EVar.isInvalid())
12099 return nullptr;
12100 ModifierExpr = EVar.get();
12101 }
12102 return getDerived().RebuildOMPNumTeamsClause(
12103 Vars, C->getModifier(), ModifierExpr, C->getModifierLoc(),
12104 OMPC_NUMTEAMS_unknown, nullptr, SourceLocation(), C->getBeginLoc(),
12105 C->getLParenLoc(), C->getEndLoc());
12106}
12107
12108template <typename Derived>
12109OMPClause *
12112 Vars.reserve(C->varlist_size());
12113 for (auto *VE : C->varlist()) {
12114 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12115 if (EVar.isInvalid())
12116 return nullptr;
12117 Vars.push_back(EVar.get());
12118 }
12119 Expr *ModifierExpr = C->getModifierExpr();
12120 if (ModifierExpr) {
12121 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(ModifierExpr));
12122 if (EVar.isInvalid())
12123 return nullptr;
12124 ModifierExpr = EVar.get();
12125 }
12126 return getDerived().RebuildOMPThreadLimitClause(
12127 Vars, C->getModifier(), ModifierExpr, C->getModifierLoc(),
12128 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12129}
12130
12131template <typename Derived>
12132OMPClause *
12134 ExprResult E = getDerived().TransformExpr(C->getPriority());
12135 if (E.isInvalid())
12136 return nullptr;
12137 return getDerived().RebuildOMPPriorityClause(
12138 E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12139}
12140
12141template <typename Derived>
12142OMPClause *
12144 ExprResult E = getDerived().TransformExpr(C->getGrainsize());
12145 if (E.isInvalid())
12146 return nullptr;
12147 return getDerived().RebuildOMPGrainsizeClause(
12148 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
12149 C->getModifierLoc(), C->getEndLoc());
12150}
12151
12152template <typename Derived>
12153OMPClause *
12155 ExprResult E = getDerived().TransformExpr(C->getNumTasks());
12156 if (E.isInvalid())
12157 return nullptr;
12158 return getDerived().RebuildOMPNumTasksClause(
12159 C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
12160 C->getModifierLoc(), C->getEndLoc());
12161}
12162
12163template <typename Derived>
12165 ExprResult E = getDerived().TransformExpr(C->getHint());
12166 if (E.isInvalid())
12167 return nullptr;
12168 return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(),
12169 C->getLParenLoc(), C->getEndLoc());
12170}
12171
12172template <typename Derived>
12174 OMPDistScheduleClause *C) {
12175 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
12176 if (E.isInvalid())
12177 return nullptr;
12178 return getDerived().RebuildOMPDistScheduleClause(
12179 C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(),
12180 C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc());
12181}
12182
12183template <typename Derived>
12184OMPClause *
12186 // Rebuild Defaultmap Clause since we need to invoke the checking of
12187 // defaultmap(none:variable-category) after template initialization.
12188 return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(),
12189 C->getDefaultmapKind(),
12190 C->getBeginLoc(),
12191 C->getLParenLoc(),
12192 C->getDefaultmapModifierLoc(),
12193 C->getDefaultmapKindLoc(),
12194 C->getEndLoc());
12195}
12196
12197template <typename Derived>
12199 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12201 Expr *IteratorModifier = C->getIteratorModifier();
12202 if (IteratorModifier) {
12203 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
12204 if (MapModRes.isInvalid())
12205 return nullptr;
12206 IteratorModifier = MapModRes.get();
12207 }
12208 CXXScopeSpec MapperIdScopeSpec;
12209 DeclarationNameInfo MapperIdInfo;
12210 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
12212 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
12213 return nullptr;
12214 return getDerived().RebuildOMPToClause(
12215 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
12216 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
12217 UnresolvedMappers);
12218}
12219
12220template <typename Derived>
12222 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12224 Expr *IteratorModifier = C->getIteratorModifier();
12225 if (IteratorModifier) {
12226 ExprResult MapModRes = getDerived().TransformExpr(IteratorModifier);
12227 if (MapModRes.isInvalid())
12228 return nullptr;
12229 IteratorModifier = MapModRes.get();
12230 }
12231 CXXScopeSpec MapperIdScopeSpec;
12232 DeclarationNameInfo MapperIdInfo;
12233 llvm::SmallVector<Expr *, 16> UnresolvedMappers;
12235 *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers))
12236 return nullptr;
12237 return getDerived().RebuildOMPFromClause(
12238 C->getMotionModifiers(), C->getMotionModifiersLoc(), IteratorModifier,
12239 MapperIdScopeSpec, MapperIdInfo, C->getColonLoc(), Vars, Locs,
12240 UnresolvedMappers);
12241}
12242
12243template <typename Derived>
12245 OMPUseDevicePtrClause *C) {
12247 Vars.reserve(C->varlist_size());
12248 for (auto *VE : C->varlist()) {
12249 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12250 if (EVar.isInvalid())
12251 return nullptr;
12252 Vars.push_back(EVar.get());
12253 }
12254 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12255 return getDerived().RebuildOMPUseDevicePtrClause(
12256 Vars, Locs, C->getFallbackModifier(), C->getFallbackModifierLoc());
12257}
12258
12259template <typename Derived>
12261 OMPUseDeviceAddrClause *C) {
12263 Vars.reserve(C->varlist_size());
12264 for (auto *VE : C->varlist()) {
12265 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12266 if (EVar.isInvalid())
12267 return nullptr;
12268 Vars.push_back(EVar.get());
12269 }
12270 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12271 return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs);
12272}
12273
12274template <typename Derived>
12275OMPClause *
12278 Vars.reserve(C->varlist_size());
12279 for (auto *VE : C->varlist()) {
12280 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12281 if (EVar.isInvalid())
12282 return nullptr;
12283 Vars.push_back(EVar.get());
12284 }
12285 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12286 return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs);
12287}
12288
12289template <typename Derived>
12291 OMPHasDeviceAddrClause *C) {
12293 Vars.reserve(C->varlist_size());
12294 for (auto *VE : C->varlist()) {
12295 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12296 if (EVar.isInvalid())
12297 return nullptr;
12298 Vars.push_back(EVar.get());
12299 }
12300 OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12301 return getDerived().RebuildOMPHasDeviceAddrClause(Vars, Locs);
12302}
12303
12304template <typename Derived>
12305OMPClause *
12308 Vars.reserve(C->varlist_size());
12309 for (auto *VE : C->varlist()) {
12310 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12311 if (EVar.isInvalid())
12312 return nullptr;
12313 Vars.push_back(EVar.get());
12314 }
12315 return getDerived().RebuildOMPNontemporalClause(
12316 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12317}
12318
12319template <typename Derived>
12320OMPClause *
12323 Vars.reserve(C->varlist_size());
12324 for (auto *VE : C->varlist()) {
12325 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12326 if (EVar.isInvalid())
12327 return nullptr;
12328 Vars.push_back(EVar.get());
12329 }
12330 return getDerived().RebuildOMPInclusiveClause(
12331 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12332}
12333
12334template <typename Derived>
12335OMPClause *
12338 Vars.reserve(C->varlist_size());
12339 for (auto *VE : C->varlist()) {
12340 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12341 if (EVar.isInvalid())
12342 return nullptr;
12343 Vars.push_back(EVar.get());
12344 }
12345 return getDerived().RebuildOMPExclusiveClause(
12346 Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12347}
12348
12349template <typename Derived>
12351 OMPUsesAllocatorsClause *C) {
12353 Data.reserve(C->getNumberOfAllocators());
12354 for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) {
12355 OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I);
12356 ExprResult Allocator = getDerived().TransformExpr(D.Allocator);
12357 if (Allocator.isInvalid())
12358 continue;
12359 ExprResult AllocatorTraits;
12360 if (Expr *AT = D.AllocatorTraits) {
12361 AllocatorTraits = getDerived().TransformExpr(AT);
12362 if (AllocatorTraits.isInvalid())
12363 continue;
12364 }
12365 SemaOpenMP::UsesAllocatorsData &NewD = Data.emplace_back();
12366 NewD.Allocator = Allocator.get();
12367 NewD.AllocatorTraits = AllocatorTraits.get();
12368 NewD.LParenLoc = D.LParenLoc;
12369 NewD.RParenLoc = D.RParenLoc;
12370 }
12371 return getDerived().RebuildOMPUsesAllocatorsClause(
12372 Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12373}
12374
12375template <typename Derived>
12376OMPClause *
12378 SmallVector<Expr *, 4> Locators;
12379 Locators.reserve(C->varlist_size());
12380 ExprResult ModifierRes;
12381 if (Expr *Modifier = C->getModifier()) {
12382 ModifierRes = getDerived().TransformExpr(Modifier);
12383 if (ModifierRes.isInvalid())
12384 return nullptr;
12385 }
12386 for (Expr *E : C->varlist()) {
12387 ExprResult Locator = getDerived().TransformExpr(E);
12388 if (Locator.isInvalid())
12389 continue;
12390 Locators.push_back(Locator.get());
12391 }
12392 return getDerived().RebuildOMPAffinityClause(
12393 C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(),
12394 ModifierRes.get(), Locators);
12395}
12396
12397template <typename Derived>
12399 return getDerived().RebuildOMPOrderClause(
12400 C->getKind(), C->getKindKwLoc(), C->getBeginLoc(), C->getLParenLoc(),
12401 C->getEndLoc(), C->getModifier(), C->getModifierKwLoc());
12402}
12403
12404template <typename Derived>
12406 return getDerived().RebuildOMPBindClause(
12407 C->getBindKind(), C->getBindKindLoc(), C->getBeginLoc(),
12408 C->getLParenLoc(), C->getEndLoc());
12409}
12410
12411template <typename Derived>
12413 OMPXDynCGroupMemClause *C) {
12414 ExprResult Size = getDerived().TransformExpr(C->getSize());
12415 if (Size.isInvalid())
12416 return nullptr;
12417 return getDerived().RebuildOMPXDynCGroupMemClause(
12418 Size.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12419}
12420
12421template <typename Derived>
12423 OMPDynGroupprivateClause *C) {
12424 ExprResult Size = getDerived().TransformExpr(C->getSize());
12425 if (Size.isInvalid())
12426 return nullptr;
12427 return getDerived().RebuildOMPDynGroupprivateClause(
12428 C->getDynGroupprivateModifier(), C->getDynGroupprivateFallbackModifier(),
12429 Size.get(), C->getBeginLoc(), C->getLParenLoc(),
12430 C->getDynGroupprivateModifierLoc(),
12431 C->getDynGroupprivateFallbackModifierLoc(), C->getEndLoc());
12432}
12433
12434template <typename Derived>
12435OMPClause *
12438 Vars.reserve(C->varlist_size());
12439 for (auto *VE : C->varlist()) {
12440 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
12441 if (EVar.isInvalid())
12442 return nullptr;
12443 Vars.push_back(EVar.get());
12444 }
12445 return getDerived().RebuildOMPDoacrossClause(
12446 C->getDependenceType(), C->getDependenceLoc(), C->getColonLoc(), Vars,
12447 C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12448}
12449
12450template <typename Derived>
12451OMPClause *
12454 for (auto *A : C->getAttrs())
12455 NewAttrs.push_back(getDerived().TransformAttr(A));
12456 return getDerived().RebuildOMPXAttributeClause(
12457 NewAttrs, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc());
12458}
12459
12460template <typename Derived>
12462 return getDerived().RebuildOMPXBareClause(C->getBeginLoc(), C->getEndLoc());
12463}
12464
12465//===----------------------------------------------------------------------===//
12466// OpenACC transformation
12467//===----------------------------------------------------------------------===//
12468namespace {
12469template <typename Derived>
12470class OpenACCClauseTransform final
12471 : public OpenACCClauseVisitor<OpenACCClauseTransform<Derived>> {
12472 TreeTransform<Derived> &Self;
12473 ArrayRef<const OpenACCClause *> ExistingClauses;
12474 SemaOpenACC::OpenACCParsedClause &ParsedClause;
12475 OpenACCClause *NewClause = nullptr;
12476
12477 ExprResult VisitVar(Expr *VarRef) {
12478 ExprResult Res = Self.TransformExpr(VarRef);
12479
12480 if (!Res.isUsable())
12481 return Res;
12482
12483 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12484 ParsedClause.getClauseKind(),
12485 Res.get());
12486
12487 return Res;
12488 }
12489
12490 llvm::SmallVector<Expr *> VisitVarList(ArrayRef<Expr *> VarList) {
12491 llvm::SmallVector<Expr *> InstantiatedVarList;
12492 for (Expr *CurVar : VarList) {
12493 ExprResult VarRef = VisitVar(CurVar);
12494
12495 if (VarRef.isUsable())
12496 InstantiatedVarList.push_back(VarRef.get());
12497 }
12498
12499 return InstantiatedVarList;
12500 }
12501
12502public:
12503 OpenACCClauseTransform(TreeTransform<Derived> &Self,
12504 ArrayRef<const OpenACCClause *> ExistingClauses,
12505 SemaOpenACC::OpenACCParsedClause &PC)
12506 : Self(Self), ExistingClauses(ExistingClauses), ParsedClause(PC) {}
12507
12508 OpenACCClause *CreatedClause() const { return NewClause; }
12509
12510#define VISIT_CLAUSE(CLAUSE_NAME) \
12511 void Visit##CLAUSE_NAME##Clause(const OpenACC##CLAUSE_NAME##Clause &Clause);
12512#include "clang/Basic/OpenACCClauses.def"
12513};
12514
12515template <typename Derived>
12516void OpenACCClauseTransform<Derived>::VisitDefaultClause(
12517 const OpenACCDefaultClause &C) {
12518 ParsedClause.setDefaultDetails(C.getDefaultClauseKind());
12519
12520 NewClause = OpenACCDefaultClause::Create(
12521 Self.getSema().getASTContext(), ParsedClause.getDefaultClauseKind(),
12522 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12523 ParsedClause.getEndLoc());
12524}
12525
12526template <typename Derived>
12527void OpenACCClauseTransform<Derived>::VisitIfClause(const OpenACCIfClause &C) {
12528 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12529 assert(Cond && "If constructed with invalid Condition");
12530 Sema::ConditionResult Res = Self.TransformCondition(
12531 Cond->getExprLoc(), /*Var=*/nullptr, Cond, Sema::ConditionKind::Boolean);
12532
12533 if (Res.isInvalid() || !Res.get().second)
12534 return;
12535
12536 ParsedClause.setConditionDetails(Res.get().second);
12537
12538 NewClause = OpenACCIfClause::Create(
12539 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12540 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12541 ParsedClause.getEndLoc());
12542}
12543
12544template <typename Derived>
12545void OpenACCClauseTransform<Derived>::VisitSelfClause(
12546 const OpenACCSelfClause &C) {
12547
12548 // If this is an 'update' 'self' clause, this is actually a var list instead.
12549 if (ParsedClause.getDirectiveKind() == OpenACCDirectiveKind::Update) {
12550 llvm::SmallVector<Expr *> InstantiatedVarList;
12551 for (Expr *CurVar : C.getVarList()) {
12552 ExprResult Res = Self.TransformExpr(CurVar);
12553
12554 if (!Res.isUsable())
12555 continue;
12556
12557 Res = Self.getSema().OpenACC().ActOnVar(ParsedClause.getDirectiveKind(),
12558 ParsedClause.getClauseKind(),
12559 Res.get());
12560
12561 if (Res.isUsable())
12562 InstantiatedVarList.push_back(Res.get());
12563 }
12564
12565 ParsedClause.setVarListDetails(InstantiatedVarList,
12567
12568 NewClause = OpenACCSelfClause::Create(
12569 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12570 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12571 ParsedClause.getEndLoc());
12572 } else {
12573
12574 if (C.hasConditionExpr()) {
12575 Expr *Cond = const_cast<Expr *>(C.getConditionExpr());
12577 Self.TransformCondition(Cond->getExprLoc(), /*Var=*/nullptr, Cond,
12579
12580 if (Res.isInvalid() || !Res.get().second)
12581 return;
12582
12583 ParsedClause.setConditionDetails(Res.get().second);
12584 }
12585
12586 NewClause = OpenACCSelfClause::Create(
12587 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12588 ParsedClause.getLParenLoc(), ParsedClause.getConditionExpr(),
12589 ParsedClause.getEndLoc());
12590 }
12591}
12592
12593template <typename Derived>
12594void OpenACCClauseTransform<Derived>::VisitNumGangsClause(
12595 const OpenACCNumGangsClause &C) {
12596 llvm::SmallVector<Expr *> InstantiatedIntExprs;
12597
12598 for (Expr *CurIntExpr : C.getIntExprs()) {
12599 ExprResult Res = Self.TransformExpr(CurIntExpr);
12600
12601 if (!Res.isUsable())
12602 return;
12603
12604 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12605 C.getClauseKind(),
12606 C.getBeginLoc(), Res.get());
12607 if (!Res.isUsable())
12608 return;
12609
12610 InstantiatedIntExprs.push_back(Res.get());
12611 }
12612
12613 ParsedClause.setIntExprDetails(InstantiatedIntExprs);
12615 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12616 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
12617 ParsedClause.getEndLoc());
12618}
12619
12620template <typename Derived>
12621void OpenACCClauseTransform<Derived>::VisitPrivateClause(
12622 const OpenACCPrivateClause &C) {
12623 llvm::SmallVector<Expr *> InstantiatedVarList;
12625
12626 for (const auto [RefExpr, InitRecipe] :
12627 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12628 ExprResult VarRef = VisitVar(RefExpr);
12629
12630 if (VarRef.isUsable()) {
12631 InstantiatedVarList.push_back(VarRef.get());
12632
12633 // We only have to create a new one if it is dependent, and Sema won't
12634 // make one of these unless the type is non-dependent.
12635 if (InitRecipe.isSet())
12636 InitRecipes.push_back(InitRecipe);
12637 else
12638 InitRecipes.push_back(
12639 Self.getSema().OpenACC().CreatePrivateInitRecipe(VarRef.get()));
12640 }
12641 }
12642 ParsedClause.setVarListDetails(InstantiatedVarList,
12644
12645 NewClause = OpenACCPrivateClause::Create(
12646 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12647 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12648 ParsedClause.getEndLoc());
12649}
12650
12651template <typename Derived>
12652void OpenACCClauseTransform<Derived>::VisitHostClause(
12653 const OpenACCHostClause &C) {
12654 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12656
12657 NewClause = OpenACCHostClause::Create(
12658 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12659 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12660 ParsedClause.getEndLoc());
12661}
12662
12663template <typename Derived>
12664void OpenACCClauseTransform<Derived>::VisitDeviceClause(
12665 const OpenACCDeviceClause &C) {
12666 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12668
12669 NewClause = OpenACCDeviceClause::Create(
12670 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12671 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12672 ParsedClause.getEndLoc());
12673}
12674
12675template <typename Derived>
12676void OpenACCClauseTransform<Derived>::VisitFirstPrivateClause(
12678 llvm::SmallVector<Expr *> InstantiatedVarList;
12680
12681 for (const auto [RefExpr, InitRecipe] :
12682 llvm::zip(C.getVarList(), C.getInitRecipes())) {
12683 ExprResult VarRef = VisitVar(RefExpr);
12684
12685 if (VarRef.isUsable()) {
12686 InstantiatedVarList.push_back(VarRef.get());
12687
12688 // We only have to create a new one if it is dependent, and Sema won't
12689 // make one of these unless the type is non-dependent.
12690 if (InitRecipe.isSet())
12691 InitRecipes.push_back(InitRecipe);
12692 else
12693 InitRecipes.push_back(
12694 Self.getSema().OpenACC().CreateFirstPrivateInitRecipe(
12695 VarRef.get()));
12696 }
12697 }
12698 ParsedClause.setVarListDetails(InstantiatedVarList,
12700
12702 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12703 ParsedClause.getLParenLoc(), ParsedClause.getVarList(), InitRecipes,
12704 ParsedClause.getEndLoc());
12705}
12706
12707template <typename Derived>
12708void OpenACCClauseTransform<Derived>::VisitNoCreateClause(
12709 const OpenACCNoCreateClause &C) {
12710 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12712
12714 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12715 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12716 ParsedClause.getEndLoc());
12717}
12718
12719template <typename Derived>
12720void OpenACCClauseTransform<Derived>::VisitPresentClause(
12721 const OpenACCPresentClause &C) {
12722 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12724
12725 NewClause = OpenACCPresentClause::Create(
12726 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12727 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12728 ParsedClause.getEndLoc());
12729}
12730
12731template <typename Derived>
12732void OpenACCClauseTransform<Derived>::VisitCopyClause(
12733 const OpenACCCopyClause &C) {
12734 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12735 C.getModifierList());
12736
12737 NewClause = OpenACCCopyClause::Create(
12738 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12739 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12740 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12741 ParsedClause.getEndLoc());
12742}
12743
12744template <typename Derived>
12745void OpenACCClauseTransform<Derived>::VisitLinkClause(
12746 const OpenACCLinkClause &C) {
12747 llvm_unreachable("link clause not valid unless a decl transform");
12748}
12749
12750template <typename Derived>
12751void OpenACCClauseTransform<Derived>::VisitDeviceResidentClause(
12753 llvm_unreachable("device_resident clause not valid unless a decl transform");
12754}
12755template <typename Derived>
12756void OpenACCClauseTransform<Derived>::VisitNoHostClause(
12757 const OpenACCNoHostClause &C) {
12758 llvm_unreachable("nohost clause not valid unless a decl transform");
12759}
12760template <typename Derived>
12761void OpenACCClauseTransform<Derived>::VisitBindClause(
12762 const OpenACCBindClause &C) {
12763 llvm_unreachable("bind clause not valid unless a decl transform");
12764}
12765
12766template <typename Derived>
12767void OpenACCClauseTransform<Derived>::VisitCopyInClause(
12768 const OpenACCCopyInClause &C) {
12769 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12770 C.getModifierList());
12771
12772 NewClause = OpenACCCopyInClause::Create(
12773 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12774 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12775 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12776 ParsedClause.getEndLoc());
12777}
12778
12779template <typename Derived>
12780void OpenACCClauseTransform<Derived>::VisitCopyOutClause(
12781 const OpenACCCopyOutClause &C) {
12782 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12783 C.getModifierList());
12784
12785 NewClause = OpenACCCopyOutClause::Create(
12786 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12787 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12788 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12789 ParsedClause.getEndLoc());
12790}
12791
12792template <typename Derived>
12793void OpenACCClauseTransform<Derived>::VisitCreateClause(
12794 const OpenACCCreateClause &C) {
12795 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12796 C.getModifierList());
12797
12798 NewClause = OpenACCCreateClause::Create(
12799 Self.getSema().getASTContext(), ParsedClause.getClauseKind(),
12800 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
12801 ParsedClause.getModifierList(), ParsedClause.getVarList(),
12802 ParsedClause.getEndLoc());
12803}
12804template <typename Derived>
12805void OpenACCClauseTransform<Derived>::VisitAttachClause(
12806 const OpenACCAttachClause &C) {
12807 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12808
12809 // Ensure each var is a pointer type.
12810 llvm::erase_if(VarList, [&](Expr *E) {
12811 return Self.getSema().OpenACC().CheckVarIsPointerType(
12813 });
12814
12815 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12816 NewClause = OpenACCAttachClause::Create(
12817 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12818 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12819 ParsedClause.getEndLoc());
12820}
12821
12822template <typename Derived>
12823void OpenACCClauseTransform<Derived>::VisitDetachClause(
12824 const OpenACCDetachClause &C) {
12825 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12826
12827 // Ensure each var is a pointer type.
12828 llvm::erase_if(VarList, [&](Expr *E) {
12829 return Self.getSema().OpenACC().CheckVarIsPointerType(
12831 });
12832
12833 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12834 NewClause = OpenACCDetachClause::Create(
12835 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12836 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12837 ParsedClause.getEndLoc());
12838}
12839
12840template <typename Derived>
12841void OpenACCClauseTransform<Derived>::VisitDeleteClause(
12842 const OpenACCDeleteClause &C) {
12843 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12845 NewClause = OpenACCDeleteClause::Create(
12846 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12847 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12848 ParsedClause.getEndLoc());
12849}
12850
12851template <typename Derived>
12852void OpenACCClauseTransform<Derived>::VisitUseDeviceClause(
12853 const OpenACCUseDeviceClause &C) {
12854 ParsedClause.setVarListDetails(VisitVarList(C.getVarList()),
12857 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12858 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12859 ParsedClause.getEndLoc());
12860}
12861
12862template <typename Derived>
12863void OpenACCClauseTransform<Derived>::VisitDevicePtrClause(
12864 const OpenACCDevicePtrClause &C) {
12865 llvm::SmallVector<Expr *> VarList = VisitVarList(C.getVarList());
12866
12867 // Ensure each var is a pointer type.
12868 llvm::erase_if(VarList, [&](Expr *E) {
12869 return Self.getSema().OpenACC().CheckVarIsPointerType(
12871 });
12872
12873 ParsedClause.setVarListDetails(VarList, OpenACCModifierKind::Invalid);
12875 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12876 ParsedClause.getLParenLoc(), ParsedClause.getVarList(),
12877 ParsedClause.getEndLoc());
12878}
12879
12880template <typename Derived>
12881void OpenACCClauseTransform<Derived>::VisitNumWorkersClause(
12882 const OpenACCNumWorkersClause &C) {
12883 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12884 assert(IntExpr && "num_workers clause constructed with invalid int expr");
12885
12886 ExprResult Res = Self.TransformExpr(IntExpr);
12887 if (!Res.isUsable())
12888 return;
12889
12890 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12891 C.getClauseKind(),
12892 C.getBeginLoc(), Res.get());
12893 if (!Res.isUsable())
12894 return;
12895
12896 ParsedClause.setIntExprDetails(Res.get());
12898 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12899 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12900 ParsedClause.getEndLoc());
12901}
12902
12903template <typename Derived>
12904void OpenACCClauseTransform<Derived>::VisitDeviceNumClause (
12905 const OpenACCDeviceNumClause &C) {
12906 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12907 assert(IntExpr && "device_num clause constructed with invalid int expr");
12908
12909 ExprResult Res = Self.TransformExpr(IntExpr);
12910 if (!Res.isUsable())
12911 return;
12912
12913 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12914 C.getClauseKind(),
12915 C.getBeginLoc(), Res.get());
12916 if (!Res.isUsable())
12917 return;
12918
12919 ParsedClause.setIntExprDetails(Res.get());
12921 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12922 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12923 ParsedClause.getEndLoc());
12924}
12925
12926template <typename Derived>
12927void OpenACCClauseTransform<Derived>::VisitDefaultAsyncClause(
12929 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12930 assert(IntExpr && "default_async clause constructed with invalid int expr");
12931
12932 ExprResult Res = Self.TransformExpr(IntExpr);
12933 if (!Res.isUsable())
12934 return;
12935
12936 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12937 C.getClauseKind(),
12938 C.getBeginLoc(), Res.get());
12939 if (!Res.isUsable())
12940 return;
12941
12942 ParsedClause.setIntExprDetails(Res.get());
12944 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12945 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12946 ParsedClause.getEndLoc());
12947}
12948
12949template <typename Derived>
12950void OpenACCClauseTransform<Derived>::VisitVectorLengthClause(
12952 Expr *IntExpr = const_cast<Expr *>(C.getIntExpr());
12953 assert(IntExpr && "vector_length clause constructed with invalid int expr");
12954
12955 ExprResult Res = Self.TransformExpr(IntExpr);
12956 if (!Res.isUsable())
12957 return;
12958
12959 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12960 C.getClauseKind(),
12961 C.getBeginLoc(), Res.get());
12962 if (!Res.isUsable())
12963 return;
12964
12965 ParsedClause.setIntExprDetails(Res.get());
12967 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12968 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs()[0],
12969 ParsedClause.getEndLoc());
12970}
12971
12972template <typename Derived>
12973void OpenACCClauseTransform<Derived>::VisitAsyncClause(
12974 const OpenACCAsyncClause &C) {
12975 if (C.hasIntExpr()) {
12976 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
12977 if (!Res.isUsable())
12978 return;
12979
12980 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
12981 C.getClauseKind(),
12982 C.getBeginLoc(), Res.get());
12983 if (!Res.isUsable())
12984 return;
12985 ParsedClause.setIntExprDetails(Res.get());
12986 }
12987
12988 NewClause = OpenACCAsyncClause::Create(
12989 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
12990 ParsedClause.getLParenLoc(),
12991 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
12992 : nullptr,
12993 ParsedClause.getEndLoc());
12994}
12995
12996template <typename Derived>
12997void OpenACCClauseTransform<Derived>::VisitWorkerClause(
12998 const OpenACCWorkerClause &C) {
12999 if (C.hasIntExpr()) {
13000 // restrictions on this expression are all "does it exist in certain
13001 // situations" that are not possible to be dependent, so the only check we
13002 // have is that it transforms, and is an int expression.
13003 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
13004 if (!Res.isUsable())
13005 return;
13006
13007 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13008 C.getClauseKind(),
13009 C.getBeginLoc(), Res.get());
13010 if (!Res.isUsable())
13011 return;
13012 ParsedClause.setIntExprDetails(Res.get());
13013 }
13014
13015 NewClause = OpenACCWorkerClause::Create(
13016 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13017 ParsedClause.getLParenLoc(),
13018 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
13019 : nullptr,
13020 ParsedClause.getEndLoc());
13021}
13022
13023template <typename Derived>
13024void OpenACCClauseTransform<Derived>::VisitVectorClause(
13025 const OpenACCVectorClause &C) {
13026 if (C.hasIntExpr()) {
13027 // restrictions on this expression are all "does it exist in certain
13028 // situations" that are not possible to be dependent, so the only check we
13029 // have is that it transforms, and is an int expression.
13030 ExprResult Res = Self.TransformExpr(const_cast<Expr *>(C.getIntExpr()));
13031 if (!Res.isUsable())
13032 return;
13033
13034 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13035 C.getClauseKind(),
13036 C.getBeginLoc(), Res.get());
13037 if (!Res.isUsable())
13038 return;
13039 ParsedClause.setIntExprDetails(Res.get());
13040 }
13041
13042 NewClause = OpenACCVectorClause::Create(
13043 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13044 ParsedClause.getLParenLoc(),
13045 ParsedClause.getNumIntExprs() != 0 ? ParsedClause.getIntExprs()[0]
13046 : nullptr,
13047 ParsedClause.getEndLoc());
13048}
13049
13050template <typename Derived>
13051void OpenACCClauseTransform<Derived>::VisitWaitClause(
13052 const OpenACCWaitClause &C) {
13053 if (C.hasExprs()) {
13054 Expr *DevNumExpr = nullptr;
13055 llvm::SmallVector<Expr *> InstantiatedQueueIdExprs;
13056
13057 // Instantiate devnum expr if it exists.
13058 if (C.getDevNumExpr()) {
13059 ExprResult Res = Self.TransformExpr(C.getDevNumExpr());
13060 if (!Res.isUsable())
13061 return;
13062 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13063 C.getClauseKind(),
13064 C.getBeginLoc(), Res.get());
13065 if (!Res.isUsable())
13066 return;
13067
13068 DevNumExpr = Res.get();
13069 }
13070
13071 // Instantiate queue ids.
13072 for (Expr *CurQueueIdExpr : C.getQueueIdExprs()) {
13073 ExprResult Res = Self.TransformExpr(CurQueueIdExpr);
13074 if (!Res.isUsable())
13075 return;
13076 Res = Self.getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Invalid,
13077 C.getClauseKind(),
13078 C.getBeginLoc(), Res.get());
13079 if (!Res.isUsable())
13080 return;
13081
13082 InstantiatedQueueIdExprs.push_back(Res.get());
13083 }
13084
13085 ParsedClause.setWaitDetails(DevNumExpr, C.getQueuesLoc(),
13086 std::move(InstantiatedQueueIdExprs));
13087 }
13088
13089 NewClause = OpenACCWaitClause::Create(
13090 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13091 ParsedClause.getLParenLoc(), ParsedClause.getDevNumExpr(),
13092 ParsedClause.getQueuesLoc(), ParsedClause.getQueueIdExprs(),
13093 ParsedClause.getEndLoc());
13094}
13095
13096template <typename Derived>
13097void OpenACCClauseTransform<Derived>::VisitDeviceTypeClause(
13098 const OpenACCDeviceTypeClause &C) {
13099 // Nothing to transform here, just create a new version of 'C'.
13101 Self.getSema().getASTContext(), C.getClauseKind(),
13102 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
13103 C.getArchitectures(), ParsedClause.getEndLoc());
13104}
13105
13106template <typename Derived>
13107void OpenACCClauseTransform<Derived>::VisitAutoClause(
13108 const OpenACCAutoClause &C) {
13109 // Nothing to do, so just create a new node.
13110 NewClause = OpenACCAutoClause::Create(Self.getSema().getASTContext(),
13111 ParsedClause.getBeginLoc(),
13112 ParsedClause.getEndLoc());
13113}
13114
13115template <typename Derived>
13116void OpenACCClauseTransform<Derived>::VisitIndependentClause(
13117 const OpenACCIndependentClause &C) {
13118 NewClause = OpenACCIndependentClause::Create(Self.getSema().getASTContext(),
13119 ParsedClause.getBeginLoc(),
13120 ParsedClause.getEndLoc());
13121}
13122
13123template <typename Derived>
13124void OpenACCClauseTransform<Derived>::VisitSeqClause(
13125 const OpenACCSeqClause &C) {
13126 NewClause = OpenACCSeqClause::Create(Self.getSema().getASTContext(),
13127 ParsedClause.getBeginLoc(),
13128 ParsedClause.getEndLoc());
13129}
13130template <typename Derived>
13131void OpenACCClauseTransform<Derived>::VisitFinalizeClause(
13132 const OpenACCFinalizeClause &C) {
13133 NewClause = OpenACCFinalizeClause::Create(Self.getSema().getASTContext(),
13134 ParsedClause.getBeginLoc(),
13135 ParsedClause.getEndLoc());
13136}
13137
13138template <typename Derived>
13139void OpenACCClauseTransform<Derived>::VisitIfPresentClause(
13140 const OpenACCIfPresentClause &C) {
13141 NewClause = OpenACCIfPresentClause::Create(Self.getSema().getASTContext(),
13142 ParsedClause.getBeginLoc(),
13143 ParsedClause.getEndLoc());
13144}
13145
13146template <typename Derived>
13147void OpenACCClauseTransform<Derived>::VisitReductionClause(
13148 const OpenACCReductionClause &C) {
13149 SmallVector<Expr *> TransformedVars = VisitVarList(C.getVarList());
13150 SmallVector<Expr *> ValidVars;
13152
13153 for (const auto [Var, OrigRecipe] :
13154 llvm::zip(TransformedVars, C.getRecipes())) {
13155 ExprResult Res = Self.getSema().OpenACC().CheckReductionVar(
13156 ParsedClause.getDirectiveKind(), C.getReductionOp(), Var);
13157 if (Res.isUsable()) {
13158 ValidVars.push_back(Res.get());
13159
13160 if (OrigRecipe.isSet())
13161 Recipes.emplace_back(OrigRecipe.AllocaDecl, OrigRecipe.CombinerRecipes);
13162 else
13163 Recipes.push_back(Self.getSema().OpenACC().CreateReductionInitRecipe(
13164 C.getReductionOp(), Res.get()));
13165 }
13166 }
13167
13168 NewClause = Self.getSema().OpenACC().CheckReductionClause(
13169 ExistingClauses, ParsedClause.getDirectiveKind(),
13170 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
13171 C.getReductionOp(), ValidVars, Recipes, ParsedClause.getEndLoc());
13172}
13173
13174template <typename Derived>
13175void OpenACCClauseTransform<Derived>::VisitCollapseClause(
13176 const OpenACCCollapseClause &C) {
13177 Expr *LoopCount = const_cast<Expr *>(C.getLoopCount());
13178 assert(LoopCount && "collapse clause constructed with invalid loop count");
13179
13180 ExprResult NewLoopCount = Self.TransformExpr(LoopCount);
13181
13182 if (!NewLoopCount.isUsable())
13183 return;
13184
13185 NewLoopCount = Self.getSema().OpenACC().ActOnIntExpr(
13186 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
13187 NewLoopCount.get()->getBeginLoc(), NewLoopCount.get());
13188
13189 // FIXME: It isn't clear whether this is properly tested here, we should
13190 // probably see if we can come up with a test for this.
13191 if (!NewLoopCount.isUsable())
13192 return;
13193
13194 NewLoopCount =
13195 Self.getSema().OpenACC().CheckCollapseLoopCount(NewLoopCount.get());
13196
13197 // FIXME: It isn't clear whether this is properly tested here, we should
13198 // probably see if we can come up with a test for this.
13199 if (!NewLoopCount.isUsable())
13200 return;
13201
13202 ParsedClause.setCollapseDetails(C.hasForce(), NewLoopCount.get());
13204 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13205 ParsedClause.getLParenLoc(), ParsedClause.isForce(),
13206 ParsedClause.getLoopCount(), ParsedClause.getEndLoc());
13207}
13208
13209template <typename Derived>
13210void OpenACCClauseTransform<Derived>::VisitTileClause(
13211 const OpenACCTileClause &C) {
13212
13213 llvm::SmallVector<Expr *> TransformedExprs;
13214
13215 for (Expr *E : C.getSizeExprs()) {
13216 ExprResult NewSizeExpr = Self.TransformExpr(E);
13217
13218 if (!NewSizeExpr.isUsable())
13219 return;
13220
13221 NewSizeExpr = Self.getSema().OpenACC().ActOnIntExpr(
13222 OpenACCDirectiveKind::Invalid, ParsedClause.getClauseKind(),
13223 NewSizeExpr.get()->getBeginLoc(), NewSizeExpr.get());
13224
13225 // FIXME: It isn't clear whether this is properly tested here, we should
13226 // probably see if we can come up with a test for this.
13227 if (!NewSizeExpr.isUsable())
13228 return;
13229
13230 NewSizeExpr = Self.getSema().OpenACC().CheckTileSizeExpr(NewSizeExpr.get());
13231
13232 if (!NewSizeExpr.isUsable())
13233 return;
13234 TransformedExprs.push_back(NewSizeExpr.get());
13235 }
13236
13237 ParsedClause.setIntExprDetails(TransformedExprs);
13238 NewClause = OpenACCTileClause::Create(
13239 Self.getSema().getASTContext(), ParsedClause.getBeginLoc(),
13240 ParsedClause.getLParenLoc(), ParsedClause.getIntExprs(),
13241 ParsedClause.getEndLoc());
13242}
13243template <typename Derived>
13244void OpenACCClauseTransform<Derived>::VisitGangClause(
13245 const OpenACCGangClause &C) {
13246 llvm::SmallVector<OpenACCGangKind> TransformedGangKinds;
13247 llvm::SmallVector<Expr *> TransformedIntExprs;
13248
13249 for (unsigned I = 0; I < C.getNumExprs(); ++I) {
13250 ExprResult ER = Self.TransformExpr(const_cast<Expr *>(C.getExpr(I).second));
13251 if (!ER.isUsable())
13252 continue;
13253
13254 ER = Self.getSema().OpenACC().CheckGangExpr(ExistingClauses,
13255 ParsedClause.getDirectiveKind(),
13256 C.getExpr(I).first, ER.get());
13257 if (!ER.isUsable())
13258 continue;
13259 TransformedGangKinds.push_back(C.getExpr(I).first);
13260 TransformedIntExprs.push_back(ER.get());
13261 }
13262
13263 NewClause = Self.getSema().OpenACC().CheckGangClause(
13264 ParsedClause.getDirectiveKind(), ExistingClauses,
13265 ParsedClause.getBeginLoc(), ParsedClause.getLParenLoc(),
13266 TransformedGangKinds, TransformedIntExprs, ParsedClause.getEndLoc());
13267}
13268} // namespace
13269template <typename Derived>
13270OpenACCClause *TreeTransform<Derived>::TransformOpenACCClause(
13271 ArrayRef<const OpenACCClause *> ExistingClauses,
13272 OpenACCDirectiveKind DirKind, const OpenACCClause *OldClause) {
13273
13275 DirKind, OldClause->getClauseKind(), OldClause->getBeginLoc());
13276 ParsedClause.setEndLoc(OldClause->getEndLoc());
13277
13278 if (const auto *WithParms = dyn_cast<OpenACCClauseWithParams>(OldClause))
13279 ParsedClause.setLParenLoc(WithParms->getLParenLoc());
13280
13281 OpenACCClauseTransform<Derived> Transform{*this, ExistingClauses,
13282 ParsedClause};
13283 Transform.Visit(OldClause);
13284
13285 return Transform.CreatedClause();
13286}
13287
13288template <typename Derived>
13290TreeTransform<Derived>::TransformOpenACCClauseList(
13292 llvm::SmallVector<OpenACCClause *> TransformedClauses;
13293 for (const auto *Clause : OldClauses) {
13294 if (OpenACCClause *TransformedClause = getDerived().TransformOpenACCClause(
13295 TransformedClauses, DirKind, Clause))
13296 TransformedClauses.push_back(TransformedClause);
13297 }
13298 return TransformedClauses;
13299}
13300
13301template <typename Derived>
13304 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13305
13306 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13307 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13308 C->clauses());
13309
13310 if (getSema().OpenACC().ActOnStartStmtDirective(
13311 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13312 return StmtError();
13313
13314 // Transform Structured Block.
13315 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13316 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13317 C->clauses(), TransformedClauses);
13318 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13319 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13320 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13321
13322 return getDerived().RebuildOpenACCComputeConstruct(
13323 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13324 C->getEndLoc(), TransformedClauses, StrBlock);
13325}
13326
13327template <typename Derived>
13330
13331 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13332
13333 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13334 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13335 C->clauses());
13336
13337 if (getSema().OpenACC().ActOnStartStmtDirective(
13338 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13339 return StmtError();
13340
13341 // Transform Loop.
13342 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13343 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13344 C->clauses(), TransformedClauses);
13345 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13346 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13347 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13348
13349 return getDerived().RebuildOpenACCLoopConstruct(
13350 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13351 TransformedClauses, Loop);
13352}
13353
13354template <typename Derived>
13356 OpenACCCombinedConstruct *C) {
13357 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13358
13359 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13360 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13361 C->clauses());
13362
13363 if (getSema().OpenACC().ActOnStartStmtDirective(
13364 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13365 return StmtError();
13366
13367 // Transform Loop.
13368 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13369 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13370 C->clauses(), TransformedClauses);
13371 StmtResult Loop = getDerived().TransformStmt(C->getLoop());
13372 Loop = getSema().OpenACC().ActOnAssociatedStmt(
13373 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, Loop);
13374
13375 return getDerived().RebuildOpenACCCombinedConstruct(
13376 C->getDirectiveKind(), C->getBeginLoc(), C->getDirectiveLoc(),
13377 C->getEndLoc(), TransformedClauses, Loop);
13378}
13379
13380template <typename Derived>
13383 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13384
13385 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13386 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13387 C->clauses());
13388 if (getSema().OpenACC().ActOnStartStmtDirective(
13389 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13390 return StmtError();
13391
13392 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13393 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13394 C->clauses(), TransformedClauses);
13395 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13396 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13397 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13398
13399 return getDerived().RebuildOpenACCDataConstruct(
13400 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13401 TransformedClauses, StrBlock);
13402}
13403
13404template <typename Derived>
13406 OpenACCEnterDataConstruct *C) {
13407 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13408
13409 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13410 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13411 C->clauses());
13412 if (getSema().OpenACC().ActOnStartStmtDirective(
13413 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13414 return StmtError();
13415
13416 return getDerived().RebuildOpenACCEnterDataConstruct(
13417 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13418 TransformedClauses);
13419}
13420
13421template <typename Derived>
13423 OpenACCExitDataConstruct *C) {
13424 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13425
13426 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13427 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13428 C->clauses());
13429 if (getSema().OpenACC().ActOnStartStmtDirective(
13430 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13431 return StmtError();
13432
13433 return getDerived().RebuildOpenACCExitDataConstruct(
13434 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13435 TransformedClauses);
13436}
13437
13438template <typename Derived>
13440 OpenACCHostDataConstruct *C) {
13441 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13442
13443 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13444 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13445 C->clauses());
13446 if (getSema().OpenACC().ActOnStartStmtDirective(
13447 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13448 return StmtError();
13449
13450 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13451 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(),
13452 C->clauses(), TransformedClauses);
13453 StmtResult StrBlock = getDerived().TransformStmt(C->getStructuredBlock());
13454 StrBlock = getSema().OpenACC().ActOnAssociatedStmt(
13455 C->getBeginLoc(), C->getDirectiveKind(), TransformedClauses, StrBlock);
13456
13457 return getDerived().RebuildOpenACCHostDataConstruct(
13458 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13459 TransformedClauses, StrBlock);
13460}
13461
13462template <typename Derived>
13465 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13466
13467 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13468 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13469 C->clauses());
13470 if (getSema().OpenACC().ActOnStartStmtDirective(
13471 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13472 return StmtError();
13473
13474 return getDerived().RebuildOpenACCInitConstruct(
13475 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13476 TransformedClauses);
13477}
13478
13479template <typename Derived>
13481 OpenACCShutdownConstruct *C) {
13482 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13483
13484 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13485 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13486 C->clauses());
13487 if (getSema().OpenACC().ActOnStartStmtDirective(
13488 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13489 return StmtError();
13490
13491 return getDerived().RebuildOpenACCShutdownConstruct(
13492 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13493 TransformedClauses);
13494}
13495template <typename Derived>
13498 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13499
13500 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13501 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13502 C->clauses());
13503 if (getSema().OpenACC().ActOnStartStmtDirective(
13504 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13505 return StmtError();
13506
13507 return getDerived().RebuildOpenACCSetConstruct(
13508 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13509 TransformedClauses);
13510}
13511
13512template <typename Derived>
13514 OpenACCUpdateConstruct *C) {
13515 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13516
13517 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13518 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13519 C->clauses());
13520 if (getSema().OpenACC().ActOnStartStmtDirective(
13521 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13522 return StmtError();
13523
13524 return getDerived().RebuildOpenACCUpdateConstruct(
13525 C->getBeginLoc(), C->getDirectiveLoc(), C->getEndLoc(),
13526 TransformedClauses);
13527}
13528
13529template <typename Derived>
13532 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13533
13534 ExprResult DevNumExpr;
13535 if (C->hasDevNumExpr()) {
13536 DevNumExpr = getDerived().TransformExpr(C->getDevNumExpr());
13537
13538 if (DevNumExpr.isUsable())
13539 DevNumExpr = getSema().OpenACC().ActOnIntExpr(
13541 C->getBeginLoc(), DevNumExpr.get());
13542 }
13543
13544 llvm::SmallVector<Expr *> QueueIdExprs;
13545
13546 for (Expr *QE : C->getQueueIdExprs()) {
13547 assert(QE && "Null queue id expr?");
13548 ExprResult NewEQ = getDerived().TransformExpr(QE);
13549
13550 if (!NewEQ.isUsable())
13551 break;
13552 NewEQ = getSema().OpenACC().ActOnIntExpr(OpenACCDirectiveKind::Wait,
13554 C->getBeginLoc(), NewEQ.get());
13555 if (NewEQ.isUsable())
13556 QueueIdExprs.push_back(NewEQ.get());
13557 }
13558
13559 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13560 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13561 C->clauses());
13562
13563 if (getSema().OpenACC().ActOnStartStmtDirective(
13564 C->getDirectiveKind(), C->getBeginLoc(), TransformedClauses))
13565 return StmtError();
13566
13567 return getDerived().RebuildOpenACCWaitConstruct(
13568 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13569 DevNumExpr.isUsable() ? DevNumExpr.get() : nullptr, C->getQueuesLoc(),
13570 QueueIdExprs, C->getRParenLoc(), C->getEndLoc(), TransformedClauses);
13571}
13572template <typename Derived>
13574 OpenACCCacheConstruct *C) {
13575 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13576
13577 llvm::SmallVector<Expr *> TransformedVarList;
13578 for (Expr *Var : C->getVarList()) {
13579 assert(Var && "Null var listexpr?");
13580
13581 ExprResult NewVar = getDerived().TransformExpr(Var);
13582
13583 if (!NewVar.isUsable())
13584 break;
13585
13586 NewVar = getSema().OpenACC().ActOnVar(
13587 C->getDirectiveKind(), OpenACCClauseKind::Invalid, NewVar.get());
13588 if (!NewVar.isUsable())
13589 break;
13590
13591 TransformedVarList.push_back(NewVar.get());
13592 }
13593
13594 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13595 C->getBeginLoc(), {}))
13596 return StmtError();
13597
13598 return getDerived().RebuildOpenACCCacheConstruct(
13599 C->getBeginLoc(), C->getDirectiveLoc(), C->getLParenLoc(),
13600 C->getReadOnlyLoc(), TransformedVarList, C->getRParenLoc(),
13601 C->getEndLoc());
13602}
13603
13604template <typename Derived>
13606 OpenACCAtomicConstruct *C) {
13607 getSema().OpenACC().ActOnConstruct(C->getDirectiveKind(), C->getBeginLoc());
13608
13609 llvm::SmallVector<OpenACCClause *> TransformedClauses =
13610 getDerived().TransformOpenACCClauseList(C->getDirectiveKind(),
13611 C->clauses());
13612
13613 if (getSema().OpenACC().ActOnStartStmtDirective(C->getDirectiveKind(),
13614 C->getBeginLoc(), {}))
13615 return StmtError();
13616
13617 // Transform Associated Stmt.
13618 SemaOpenACC::AssociatedStmtRAII AssocStmtRAII(
13619 getSema().OpenACC(), C->getDirectiveKind(), C->getDirectiveLoc(), {}, {});
13620
13621 StmtResult AssocStmt = getDerived().TransformStmt(C->getAssociatedStmt());
13622 AssocStmt = getSema().OpenACC().ActOnAssociatedStmt(
13623 C->getBeginLoc(), C->getDirectiveKind(), C->getAtomicKind(), {},
13624 AssocStmt);
13625
13626 return getDerived().RebuildOpenACCAtomicConstruct(
13627 C->getBeginLoc(), C->getDirectiveLoc(), C->getAtomicKind(),
13628 C->getEndLoc(), TransformedClauses, AssocStmt);
13629}
13630
13631template <typename Derived>
13634 if (getDerived().AlwaysRebuild())
13635 return getDerived().RebuildOpenACCAsteriskSizeExpr(E->getLocation());
13636 // Nothing can ever change, so there is never anything to transform.
13637 return E;
13638}
13639
13640//===----------------------------------------------------------------------===//
13641// Expression transformation
13642//===----------------------------------------------------------------------===//
13643template<typename Derived>
13646 return TransformExpr(E->getSubExpr());
13647}
13648
13649template <typename Derived>
13652 if (!E->isTypeDependent())
13653 return E;
13654
13655 TypeSourceInfo *NewT = getDerived().TransformType(E->getTypeSourceInfo());
13656
13657 if (!NewT)
13658 return ExprError();
13659
13660 if (!getDerived().AlwaysRebuild() && E->getTypeSourceInfo() == NewT)
13661 return E;
13662
13663 return getDerived().RebuildSYCLUniqueStableNameExpr(
13664 E->getLocation(), E->getLParenLocation(), E->getRParenLocation(), NewT);
13665}
13666
13667template <typename Derived>
13670 auto *FD = cast<FunctionDecl>(SemaRef.CurContext);
13671 const auto *SKEPAttr = FD->template getAttr<SYCLKernelEntryPointAttr>();
13672 if (!SKEPAttr || SKEPAttr->isInvalidAttr())
13673 return StmtError();
13674
13675 ExprResult IdExpr = getDerived().TransformExpr(S->getKernelLaunchIdExpr());
13676 if (IdExpr.isInvalid())
13677 return StmtError();
13678
13679 StmtResult Body = getDerived().TransformStmt(S->getOriginalStmt());
13680 if (Body.isInvalid())
13681 return StmtError();
13682
13684 cast<FunctionDecl>(SemaRef.CurContext), cast<CompoundStmt>(Body.get()),
13685 IdExpr.get());
13686 if (SR.isInvalid())
13687 return StmtError();
13688
13689 return SR;
13690}
13691
13692template <typename Derived>
13694 // TODO(reflection): Implement its transform
13695
13696 switch (E->getKind()) {
13697 case ReflectionKind::Type: {
13698 TypeSourceInfo *NewT = getDerived().TransformType(
13699 const_cast<TypeSourceInfo *>(E->getTypeSourceInfo()));
13700 if (!NewT)
13701 return ExprError();
13702 return SemaRef.BuildCXXReflectExpr(E->getOperatorLoc(), NewT);
13703 }
13705 llvm_unreachable("A null reflection should not reach here");
13706 }
13707
13708 assert(false && "unknown or unimplemented reflection entities");
13709 return ExprError();
13710}
13711
13712template<typename Derived>
13715 if (!E->isTypeDependent())
13716 return E;
13717
13718 return getDerived().RebuildPredefinedExpr(E->getLocation(),
13719 E->getIdentKind());
13720}
13721
13722template<typename Derived>
13725 NestedNameSpecifierLoc QualifierLoc;
13726 if (E->getQualifierLoc()) {
13727 QualifierLoc
13728 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
13729 if (!QualifierLoc)
13730 return ExprError();
13731 }
13732
13733 ValueDecl *ND
13734 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
13735 E->getDecl()));
13736 if (!ND || ND->isInvalidDecl())
13737 return ExprError();
13738
13739 NamedDecl *Found = ND;
13740 if (E->getFoundDecl() != E->getDecl()) {
13741 Found = cast_or_null<NamedDecl>(
13742 getDerived().TransformDecl(E->getLocation(), E->getFoundDecl()));
13743 if (!Found)
13744 return ExprError();
13745 }
13746
13747 DeclarationNameInfo NameInfo = E->getNameInfo();
13748 if (NameInfo.getName()) {
13749 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
13750 if (!NameInfo.getName())
13751 return ExprError();
13752 }
13753
13754 if (!getDerived().AlwaysRebuild() &&
13755 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter() &&
13756 QualifierLoc == E->getQualifierLoc() && ND == E->getDecl() &&
13757 Found == E->getFoundDecl() &&
13758 NameInfo.getName() == E->getDecl()->getDeclName() &&
13759 !E->hasExplicitTemplateArgs()) {
13760
13761 // Mark it referenced in the new context regardless.
13762 // FIXME: this is a bit instantiation-specific.
13763 SemaRef.MarkDeclRefReferenced(E);
13764
13765 return E;
13766 }
13767
13768 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
13769 if (E->hasExplicitTemplateArgs()) {
13770 TemplateArgs = &TransArgs;
13771 TransArgs.setLAngleLoc(E->getLAngleLoc());
13772 TransArgs.setRAngleLoc(E->getRAngleLoc());
13773 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
13774 E->getNumTemplateArgs(),
13775 TransArgs))
13776 return ExprError();
13777 }
13778
13779 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
13780 Found, TemplateArgs);
13781}
13782
13783template<typename Derived>
13786 return E;
13787}
13788
13789template <typename Derived>
13791 FixedPointLiteral *E) {
13792 return E;
13793}
13794
13795template<typename Derived>
13798 return E;
13799}
13800
13801template<typename Derived>
13804 return E;
13805}
13806
13807template<typename Derived>
13810 return E;
13811}
13812
13813template<typename Derived>
13816 return E;
13817}
13818
13819template<typename Derived>
13822 return getDerived().TransformCallExpr(E);
13823}
13824
13825template<typename Derived>
13828 ExprResult ControllingExpr;
13829 TypeSourceInfo *ControllingType = nullptr;
13830 if (E->isExprPredicate())
13831 ControllingExpr = getDerived().TransformExpr(E->getControllingExpr());
13832 else
13833 ControllingType = getDerived().TransformType(E->getControllingType());
13834
13835 if (ControllingExpr.isInvalid() && !ControllingType)
13836 return ExprError();
13837
13838 SmallVector<Expr *, 4> AssocExprs;
13840 for (const GenericSelectionExpr::Association Assoc : E->associations()) {
13841 TypeSourceInfo *TSI = Assoc.getTypeSourceInfo();
13842 if (TSI) {
13843 TypeSourceInfo *AssocType = getDerived().TransformType(TSI);
13844 if (!AssocType)
13845 return ExprError();
13846 AssocTypes.push_back(AssocType);
13847 } else {
13848 AssocTypes.push_back(nullptr);
13849 }
13850
13851 ExprResult AssocExpr =
13852 getDerived().TransformExpr(Assoc.getAssociationExpr());
13853 if (AssocExpr.isInvalid())
13854 return ExprError();
13855 AssocExprs.push_back(AssocExpr.get());
13856 }
13857
13858 if (!ControllingType)
13859 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
13860 E->getDefaultLoc(),
13861 E->getRParenLoc(),
13862 ControllingExpr.get(),
13863 AssocTypes,
13864 AssocExprs);
13865 return getDerived().RebuildGenericSelectionExpr(
13866 E->getGenericLoc(), E->getDefaultLoc(), E->getRParenLoc(),
13867 ControllingType, AssocTypes, AssocExprs);
13868}
13869
13870template<typename Derived>
13873 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
13874 if (SubExpr.isInvalid())
13875 return ExprError();
13876
13877 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13878 return E;
13879
13880 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
13881 E->getRParen());
13882}
13883
13884/// The operand of a unary address-of operator has special rules: it's
13885/// allowed to refer to a non-static member of a class even if there's no 'this'
13886/// object available.
13887template<typename Derived>
13890 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
13891 return getDerived().TransformDependentScopeDeclRefExpr(
13892 DRE, /*IsAddressOfOperand=*/true, nullptr);
13893 else if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(E))
13894 return getDerived().TransformUnresolvedLookupExpr(
13895 ULE, /*IsAddressOfOperand=*/true);
13896 else
13897 return getDerived().TransformExpr(E);
13898}
13899
13900template<typename Derived>
13903 ExprResult SubExpr;
13904 if (E->getOpcode() == UO_AddrOf)
13905 SubExpr = TransformAddressOfOperand(E->getSubExpr());
13906 else
13907 SubExpr = TransformExpr(E->getSubExpr());
13908 if (SubExpr.isInvalid())
13909 return ExprError();
13910
13911 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
13912 return E;
13913
13914 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
13915 E->getOpcode(),
13916 SubExpr.get());
13917}
13918
13919template<typename Derived>
13921TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
13922 // Transform the type.
13923 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
13924 if (!Type)
13925 return ExprError();
13926
13927 // Transform all of the components into a Designation similar to what the
13928 // parser builds.
13929 // FIXME: It would be slightly more efficient in the non-dependent case to
13930 // just map FieldDecls, rather than requiring the rebuilder to look for
13931 // the fields again. However, __builtin_offsetof is rare enough in
13932 // template code that we don't care.
13933 bool ExprChanged = false;
13934 Designation Desig;
13935 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
13936 const OffsetOfNode &ON = E->getComponent(I);
13937 switch (ON.getKind()) {
13938 case OffsetOfNode::Array: {
13939 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
13940 ExprResult Index = getDerived().TransformExpr(FromIndex);
13941 if (Index.isInvalid())
13942 return ExprError();
13943
13944 ExprChanged = ExprChanged || Index.get() != FromIndex;
13945 Designator AD =
13946 Designator::CreateArrayDesignator(Index.get(), ON.getBeginLoc());
13947 AD.setRBracketLoc(ON.getEndLoc());
13948 Desig.AddDesignator(AD);
13949 break;
13950 }
13951
13954 const IdentifierInfo *Name = ON.getFieldName();
13955 if (!Name)
13956 continue;
13957 // The leading designator has no '.'; subsequent ones do.
13958 SourceLocation DotLoc =
13959 Desig.empty() ? SourceLocation() : ON.getBeginLoc();
13960 Desig.AddDesignator(
13961 Designator::CreateFieldDesignator(Name, DotLoc, ON.getEndLoc()));
13962 break;
13963 }
13964
13965 case OffsetOfNode::Base:
13966 // Will be recomputed during the rebuild.
13967 continue;
13968 }
13969 }
13970
13971 // If nothing changed, retain the existing expression.
13972 if (!getDerived().AlwaysRebuild() &&
13973 Type == E->getTypeSourceInfo() &&
13974 !ExprChanged)
13975 return E;
13976
13977 // Build a new offsetof expression.
13978 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, Desig,
13979 E->getRParenLoc());
13980}
13981
13982template<typename Derived>
13985 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
13986 "opaque value expression requires transformation");
13987 return E;
13988}
13989
13990template <typename Derived>
13993 bool Changed = false;
13994 for (Expr *C : E->subExpressions()) {
13995 ExprResult NewC = getDerived().TransformExpr(C);
13996 if (NewC.isInvalid())
13997 return ExprError();
13998 Children.push_back(NewC.get());
13999
14000 Changed |= NewC.get() != C;
14001 }
14002 if (!getDerived().AlwaysRebuild() && !Changed)
14003 return E;
14004 return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(),
14005 Children, E->getType());
14006}
14007
14008template<typename Derived>
14011 // Rebuild the syntactic form. The original syntactic form has
14012 // opaque-value expressions in it, so strip those away and rebuild
14013 // the result. This is a really awful way of doing this, but the
14014 // better solution (rebuilding the semantic expressions and
14015 // rebinding OVEs as necessary) doesn't work; we'd need
14016 // TreeTransform to not strip away implicit conversions.
14017 Expr *newSyntacticForm = SemaRef.PseudoObject().recreateSyntacticForm(E);
14018 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
14019 if (result.isInvalid()) return ExprError();
14020
14021 // If that gives us a pseudo-object result back, the pseudo-object
14022 // expression must have been an lvalue-to-rvalue conversion which we
14023 // should reapply.
14024 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
14025 result = SemaRef.PseudoObject().checkRValue(result.get());
14026
14027 return result;
14028}
14029
14030template<typename Derived>
14034 if (E->isArgumentType()) {
14035 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
14036
14037 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
14038 if (!NewT)
14039 return ExprError();
14040
14041 if (!getDerived().AlwaysRebuild() && OldT == NewT)
14042 return E;
14043
14044 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
14045 E->getKind(),
14046 E->getSourceRange());
14047 }
14048
14049 // C++0x [expr.sizeof]p1:
14050 // The operand is either an expression, which is an unevaluated operand
14051 // [...]
14055
14056 // Try to recover if we have something like sizeof(T::X) where X is a type.
14057 // Notably, there must be *exactly* one set of parens if X is a type.
14058 TypeSourceInfo *RecoveryTSI = nullptr;
14059 ExprResult SubExpr;
14060 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
14061 if (auto *DRE =
14062 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
14063 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
14064 PE, DRE, false, &RecoveryTSI);
14065 else
14066 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
14067
14068 if (RecoveryTSI) {
14069 return getDerived().RebuildUnaryExprOrTypeTrait(
14070 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
14071 } else if (SubExpr.isInvalid())
14072 return ExprError();
14073
14074 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
14075 return E;
14076
14077 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
14078 E->getOperatorLoc(),
14079 E->getKind(),
14080 E->getSourceRange());
14081}
14082
14083template<typename Derived>
14086 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14087 if (LHS.isInvalid())
14088 return ExprError();
14089
14090 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14091 if (RHS.isInvalid())
14092 return ExprError();
14093
14094
14095 if (!getDerived().AlwaysRebuild() &&
14096 LHS.get() == E->getLHS() &&
14097 RHS.get() == E->getRHS())
14098 return E;
14099
14100 return getDerived().RebuildArraySubscriptExpr(
14101 LHS.get(),
14102 /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc());
14103}
14104
14105template <typename Derived>
14108 ExprResult Base = getDerived().TransformExpr(E->getBase());
14109 if (Base.isInvalid())
14110 return ExprError();
14111
14112 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
14113 if (RowIdx.isInvalid())
14114 return ExprError();
14115
14116 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
14117 RowIdx.get() == E->getRowIdx())
14118 return E;
14119
14120 return getDerived().RebuildMatrixSingleSubscriptExpr(Base.get(), RowIdx.get(),
14121 E->getRBracketLoc());
14122}
14123
14124template <typename Derived>
14127 ExprResult Base = getDerived().TransformExpr(E->getBase());
14128 if (Base.isInvalid())
14129 return ExprError();
14130
14131 ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx());
14132 if (RowIdx.isInvalid())
14133 return ExprError();
14134
14135 ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx());
14136 if (ColumnIdx.isInvalid())
14137 return ExprError();
14138
14139 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
14140 RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx())
14141 return E;
14142
14143 return getDerived().RebuildMatrixSubscriptExpr(
14144 Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc());
14145}
14146
14147template <typename Derived>
14150 ExprResult Base = getDerived().TransformExpr(E->getBase());
14151 if (Base.isInvalid())
14152 return ExprError();
14153
14154 ExprResult LowerBound;
14155 if (E->getLowerBound()) {
14156 LowerBound = getDerived().TransformExpr(E->getLowerBound());
14157 if (LowerBound.isInvalid())
14158 return ExprError();
14159 }
14160
14161 ExprResult Length;
14162 if (E->getLength()) {
14163 Length = getDerived().TransformExpr(E->getLength());
14164 if (Length.isInvalid())
14165 return ExprError();
14166 }
14167
14168 ExprResult Stride;
14169 if (E->isOMPArraySection()) {
14170 if (Expr *Str = E->getStride()) {
14171 Stride = getDerived().TransformExpr(Str);
14172 if (Stride.isInvalid())
14173 return ExprError();
14174 }
14175 }
14176
14177 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
14178 LowerBound.get() == E->getLowerBound() &&
14179 Length.get() == E->getLength() &&
14180 (E->isOpenACCArraySection() || Stride.get() == E->getStride()))
14181 return E;
14182
14183 return getDerived().RebuildArraySectionExpr(
14184 E->isOMPArraySection(), Base.get(), E->getBase()->getEndLoc(),
14185 LowerBound.get(), E->getColonLocFirst(),
14186 E->isOMPArraySection() ? E->getColonLocSecond() : SourceLocation{},
14187 Length.get(), Stride.get(), E->getRBracketLoc());
14188}
14189
14190template <typename Derived>
14193 ExprResult Base = getDerived().TransformExpr(E->getBase());
14194 if (Base.isInvalid())
14195 return ExprError();
14196
14198 bool ErrorFound = false;
14199 for (Expr *Dim : E->getDimensions()) {
14200 ExprResult DimRes = getDerived().TransformExpr(Dim);
14201 if (DimRes.isInvalid()) {
14202 ErrorFound = true;
14203 continue;
14204 }
14205 Dims.push_back(DimRes.get());
14206 }
14207
14208 if (ErrorFound)
14209 return ExprError();
14210 return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(),
14211 E->getRParenLoc(), Dims,
14212 E->getBracketsRanges());
14213}
14214
14215template <typename Derived>
14218 unsigned NumIterators = E->numOfIterators();
14220
14221 bool ErrorFound = false;
14222 bool NeedToRebuild = getDerived().AlwaysRebuild();
14223 for (unsigned I = 0; I < NumIterators; ++I) {
14224 auto *D = cast<VarDecl>(E->getIteratorDecl(I));
14225 Data[I].DeclIdent = D->getIdentifier();
14226 Data[I].DeclIdentLoc = D->getLocation();
14227 if (D->getLocation() == D->getBeginLoc()) {
14228 assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) &&
14229 "Implicit type must be int.");
14230 } else {
14231 TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo());
14232 QualType DeclTy = getDerived().TransformType(D->getType());
14233 Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI);
14234 }
14235 OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I);
14236 ExprResult Begin = getDerived().TransformExpr(Range.Begin);
14237 ExprResult End = getDerived().TransformExpr(Range.End);
14238 ExprResult Step = getDerived().TransformExpr(Range.Step);
14239 ErrorFound = ErrorFound ||
14240 !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() &&
14241 !Data[I].Type.get().isNull())) ||
14242 Begin.isInvalid() || End.isInvalid() || Step.isInvalid();
14243 if (ErrorFound)
14244 continue;
14245 Data[I].Range.Begin = Begin.get();
14246 Data[I].Range.End = End.get();
14247 Data[I].Range.Step = Step.get();
14248 Data[I].AssignLoc = E->getAssignLoc(I);
14249 Data[I].ColonLoc = E->getColonLoc(I);
14250 Data[I].SecColonLoc = E->getSecondColonLoc(I);
14251 NeedToRebuild =
14252 NeedToRebuild ||
14253 (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() !=
14254 D->getType().getTypePtrOrNull()) ||
14255 Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End ||
14256 Range.Step != Data[I].Range.Step;
14257 }
14258 if (ErrorFound)
14259 return ExprError();
14260 if (!NeedToRebuild)
14261 return E;
14262
14263 ExprResult Res = getDerived().RebuildOMPIteratorExpr(
14264 E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data);
14265 if (!Res.isUsable())
14266 return Res;
14267 auto *IE = cast<OMPIteratorExpr>(Res.get());
14268 for (unsigned I = 0; I < NumIterators; ++I)
14269 getDerived().transformedLocalDecl(E->getIteratorDecl(I),
14270 IE->getIteratorDecl(I));
14271 return Res;
14272}
14273
14274template<typename Derived>
14277 // Transform the callee.
14278 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
14279 if (Callee.isInvalid())
14280 return ExprError();
14281
14282 // Transform arguments.
14283 bool ArgChanged = false;
14285 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
14286 &ArgChanged))
14287 return ExprError();
14288
14289 if (!getDerived().AlwaysRebuild() &&
14290 Callee.get() == E->getCallee() &&
14291 !ArgChanged)
14292 return SemaRef.MaybeBindToTemporary(E);
14293
14294 // FIXME: Wrong source location information for the '('.
14295 SourceLocation FakeLParenLoc
14296 = ((Expr *)Callee.get())->getSourceRange().getBegin();
14297
14298 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14299 if (E->hasStoredFPFeatures()) {
14300 FPOptionsOverride NewOverrides = E->getFPFeatures();
14301 getSema().CurFPFeatures =
14302 NewOverrides.applyOverrides(getSema().getLangOpts());
14303 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14304 }
14305
14306 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
14307 Args,
14308 E->getRParenLoc());
14309}
14310
14311template<typename Derived>
14314 ExprResult Base = getDerived().TransformExpr(E->getBase());
14315 if (Base.isInvalid())
14316 return ExprError();
14317
14318 NestedNameSpecifierLoc QualifierLoc;
14319 if (E->hasQualifier()) {
14320 QualifierLoc
14321 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
14322
14323 if (!QualifierLoc)
14324 return ExprError();
14325 }
14326 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
14327
14329 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
14330 E->getMemberDecl()));
14331 if (!Member)
14332 return ExprError();
14333
14334 NamedDecl *FoundDecl = E->getFoundDecl();
14335 if (FoundDecl == E->getMemberDecl()) {
14336 FoundDecl = Member;
14337 } else {
14338 FoundDecl = cast_or_null<NamedDecl>(
14339 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
14340 if (!FoundDecl)
14341 return ExprError();
14342 }
14343
14344 if (!getDerived().AlwaysRebuild() &&
14345 Base.get() == E->getBase() &&
14346 QualifierLoc == E->getQualifierLoc() &&
14347 Member == E->getMemberDecl() &&
14348 FoundDecl == E->getFoundDecl() &&
14349 !E->hasExplicitTemplateArgs()) {
14350
14351 // Skip for member expression of (this->f), rebuilt thisi->f is needed
14352 // for Openmp where the field need to be privatizized in the case.
14353 if (!(isa<CXXThisExpr>(E->getBase()) &&
14354 getSema().OpenMP().isOpenMPRebuildMemberExpr(
14356 // Mark it referenced in the new context regardless.
14357 // FIXME: this is a bit instantiation-specific.
14358 SemaRef.MarkMemberReferenced(E);
14359 return E;
14360 }
14361 }
14362
14363 TemplateArgumentListInfo TransArgs;
14364 if (E->hasExplicitTemplateArgs()) {
14365 TransArgs.setLAngleLoc(E->getLAngleLoc());
14366 TransArgs.setRAngleLoc(E->getRAngleLoc());
14367 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
14368 E->getNumTemplateArgs(),
14369 TransArgs))
14370 return ExprError();
14371 }
14372
14373 // FIXME: Bogus source location for the operator
14374 SourceLocation FakeOperatorLoc =
14375 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
14376
14377 // FIXME: to do this check properly, we will need to preserve the
14378 // first-qualifier-in-scope here, just in case we had a dependent
14379 // base (and therefore couldn't do the check) and a
14380 // nested-name-qualifier (and therefore could do the lookup).
14381 NamedDecl *FirstQualifierInScope = nullptr;
14382 DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo();
14383 if (MemberNameInfo.getName()) {
14384 MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo);
14385 if (!MemberNameInfo.getName())
14386 return ExprError();
14387 }
14388
14389 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
14390 E->isArrow(),
14391 QualifierLoc,
14392 TemplateKWLoc,
14393 MemberNameInfo,
14394 Member,
14395 FoundDecl,
14396 (E->hasExplicitTemplateArgs()
14397 ? &TransArgs : nullptr),
14398 FirstQualifierInScope);
14399}
14400
14401template<typename Derived>
14404 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14405 if (LHS.isInvalid())
14406 return ExprError();
14407
14408 ExprResult RHS =
14409 getDerived().TransformInitializer(E->getRHS(), /*NotCopyInit=*/false);
14410 if (RHS.isInvalid())
14411 return ExprError();
14412
14413 if (!getDerived().AlwaysRebuild() &&
14414 LHS.get() == E->getLHS() &&
14415 RHS.get() == E->getRHS())
14416 return E;
14417
14418 if (E->isCompoundAssignmentOp())
14419 // FPFeatures has already been established from trailing storage
14420 return getDerived().RebuildBinaryOperator(
14421 E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get());
14422 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14423 FPOptionsOverride NewOverrides(E->getFPFeatures());
14424 getSema().CurFPFeatures =
14425 NewOverrides.applyOverrides(getSema().getLangOpts());
14426 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14427 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
14428 LHS.get(), RHS.get());
14429}
14430
14431template <typename Derived>
14434 CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm();
14435
14436 ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS));
14437 if (LHS.isInvalid())
14438 return ExprError();
14439
14440 ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS));
14441 if (RHS.isInvalid())
14442 return ExprError();
14443
14444 // Extract the already-resolved callee declarations so that we can restrict
14445 // ourselves to using them as the unqualified lookup results when rebuilding.
14446 UnresolvedSet<2> UnqualLookups;
14447 bool ChangedAnyLookups = false;
14448 Expr *PossibleBinOps[] = {E->getSemanticForm(),
14449 const_cast<Expr *>(Decomp.InnerBinOp)};
14450 for (Expr *PossibleBinOp : PossibleBinOps) {
14451 auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit());
14452 if (!Op)
14453 continue;
14454 auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit());
14455 if (!Callee || isa<CXXMethodDecl>(Callee->getDecl()))
14456 continue;
14457
14458 // Transform the callee in case we built a call to a local extern
14459 // declaration.
14460 NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl(
14461 E->getOperatorLoc(), Callee->getFoundDecl()));
14462 if (!Found)
14463 return ExprError();
14464 if (Found != Callee->getFoundDecl())
14465 ChangedAnyLookups = true;
14466 UnqualLookups.addDecl(Found);
14467 }
14468
14469 if (!getDerived().AlwaysRebuild() && !ChangedAnyLookups &&
14470 LHS.get() == Decomp.LHS && RHS.get() == Decomp.RHS) {
14471 // Mark all functions used in the rewrite as referenced. Note that when
14472 // a < b is rewritten to (a <=> b) < 0, both the <=> and the < might be
14473 // function calls, and/or there might be a user-defined conversion sequence
14474 // applied to the operands of the <.
14475 // FIXME: this is a bit instantiation-specific.
14476 const Expr *StopAt[] = {Decomp.LHS, Decomp.RHS};
14477 SemaRef.MarkDeclarationsReferencedInExpr(E, false, StopAt);
14478 return E;
14479 }
14480
14481 return getDerived().RebuildCXXRewrittenBinaryOperator(
14482 E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get());
14483}
14484
14485template<typename Derived>
14489 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14490 FPOptionsOverride NewOverrides(E->getFPFeatures());
14491 getSema().CurFPFeatures =
14492 NewOverrides.applyOverrides(getSema().getLangOpts());
14493 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14494 return getDerived().TransformBinaryOperator(E);
14495}
14496
14497template<typename Derived>
14500 // Just rebuild the common and RHS expressions and see whether we
14501 // get any changes.
14502
14503 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
14504 if (commonExpr.isInvalid())
14505 return ExprError();
14506
14507 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
14508 if (rhs.isInvalid())
14509 return ExprError();
14510
14511 if (!getDerived().AlwaysRebuild() &&
14512 commonExpr.get() == e->getCommon() &&
14513 rhs.get() == e->getFalseExpr())
14514 return e;
14515
14516 return getDerived().RebuildConditionalOperator(commonExpr.get(),
14517 e->getQuestionLoc(),
14518 nullptr,
14519 e->getColonLoc(),
14520 rhs.get());
14521}
14522
14523template<typename Derived>
14526 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14527 if (Cond.isInvalid())
14528 return ExprError();
14529
14530 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14531 if (LHS.isInvalid())
14532 return ExprError();
14533
14534 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14535 if (RHS.isInvalid())
14536 return ExprError();
14537
14538 if (!getDerived().AlwaysRebuild() &&
14539 Cond.get() == E->getCond() &&
14540 LHS.get() == E->getLHS() &&
14541 RHS.get() == E->getRHS())
14542 return E;
14543
14544 return getDerived().RebuildConditionalOperator(Cond.get(),
14545 E->getQuestionLoc(),
14546 LHS.get(),
14547 E->getColonLoc(),
14548 RHS.get());
14549}
14550
14551template<typename Derived>
14554 // Implicit casts are eliminated during transformation, since they
14555 // will be recomputed by semantic analysis after transformation.
14556 return getDerived().TransformExpr(E->getSubExprAsWritten());
14557}
14558
14559template<typename Derived>
14562 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
14563 if (!Type)
14564 return ExprError();
14565
14566 ExprResult SubExpr
14567 = getDerived().TransformExpr(E->getSubExprAsWritten());
14568 if (SubExpr.isInvalid())
14569 return ExprError();
14570
14571 if (!getDerived().AlwaysRebuild() &&
14572 Type == E->getTypeInfoAsWritten() &&
14573 SubExpr.get() == E->getSubExpr())
14574 return E;
14575
14576 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
14577 Type,
14578 E->getRParenLoc(),
14579 SubExpr.get());
14580}
14581
14582template<typename Derived>
14585 TypeSourceInfo *OldT = E->getTypeSourceInfo();
14586 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
14587 if (!NewT)
14588 return ExprError();
14589
14590 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
14591 if (Init.isInvalid())
14592 return ExprError();
14593
14594 if (!getDerived().AlwaysRebuild() &&
14595 OldT == NewT &&
14596 Init.get() == E->getInitializer())
14597 return SemaRef.MaybeBindToTemporary(E);
14598
14599 // Note: the expression type doesn't necessarily match the
14600 // type-as-written, but that's okay, because it should always be
14601 // derivable from the initializer.
14602
14603 return getDerived().RebuildCompoundLiteralExpr(
14604 E->getLParenLoc(), NewT,
14605 /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get());
14606}
14607
14608template<typename Derived>
14611 ExprResult Base = getDerived().TransformExpr(E->getBase());
14612 if (Base.isInvalid())
14613 return ExprError();
14614
14615 if (!getDerived().AlwaysRebuild() &&
14616 Base.get() == E->getBase())
14617 return E;
14618
14619 // FIXME: Bad source location
14620 SourceLocation FakeOperatorLoc =
14621 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14622 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14623 Base.get(), FakeOperatorLoc, E->isArrow(), E->getAccessorLoc(),
14624 E->getAccessor());
14625}
14626
14627template <typename Derived>
14630 ExprResult Base = getDerived().TransformExpr(E->getBase());
14631 if (Base.isInvalid())
14632 return ExprError();
14633
14634 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase())
14635 return E;
14636
14637 // FIXME: Bad source location
14638 SourceLocation FakeOperatorLoc =
14639 SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc());
14640 return getDerived().RebuildExtVectorOrMatrixElementExpr(
14641 Base.get(), FakeOperatorLoc, /*isArrow*/ false, E->getAccessorLoc(),
14642 E->getAccessor());
14643}
14644
14645template<typename Derived>
14648 if (InitListExpr *Syntactic = E->getSyntacticForm())
14649 E = Syntactic;
14650
14651 bool InitChanged = false;
14652
14655
14657 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
14658 Inits, &InitChanged))
14659 return ExprError();
14660
14661 if (!getDerived().AlwaysRebuild() && !InitChanged) {
14662 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
14663 // in some cases. We can't reuse it in general, because the syntactic and
14664 // semantic forms are linked, and we can't know that semantic form will
14665 // match even if the syntactic form does.
14666 }
14667
14668 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
14669 E->getRBraceLoc(), E->isExplicit());
14670}
14671
14672template<typename Derived>
14675 Designation Desig;
14676
14677 // transform the initializer value
14678 ExprResult Init = getDerived().TransformExpr(E->getInit());
14679 if (Init.isInvalid())
14680 return ExprError();
14681
14682 // transform the designators.
14683 SmallVector<Expr*, 4> ArrayExprs;
14684 bool ExprChanged = false;
14685 for (const DesignatedInitExpr::Designator &D : E->designators()) {
14686 if (D.isFieldDesignator()) {
14687 if (D.getFieldDecl()) {
14688 FieldDecl *Field = cast_or_null<FieldDecl>(
14689 getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl()));
14690 if (Field != D.getFieldDecl())
14691 // Rebuild the expression when the transformed FieldDecl is
14692 // different to the already assigned FieldDecl.
14693 ExprChanged = true;
14694 if (Field->isAnonymousStructOrUnion())
14695 continue;
14696 } else {
14697 // Ensure that the designator expression is rebuilt when there isn't
14698 // a resolved FieldDecl in the designator as we don't want to assign
14699 // a FieldDecl to a pattern designator that will be instantiated again.
14700 ExprChanged = true;
14701 }
14702 Desig.AddDesignator(Designator::CreateFieldDesignator(
14703 D.getFieldName(), D.getDotLoc(), D.getFieldLoc()));
14704 continue;
14705 }
14706
14707 if (D.isArrayDesignator()) {
14708 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D));
14709 if (Index.isInvalid())
14710 return ExprError();
14711
14712 Desig.AddDesignator(
14713 Designator::CreateArrayDesignator(Index.get(), D.getLBracketLoc()));
14714
14715 ExprChanged = ExprChanged || Index.get() != E->getArrayIndex(D);
14716 ArrayExprs.push_back(Index.get());
14717 continue;
14718 }
14719
14720 assert(D.isArrayRangeDesignator() && "New kind of designator?");
14721 ExprResult Start
14722 = getDerived().TransformExpr(E->getArrayRangeStart(D));
14723 if (Start.isInvalid())
14724 return ExprError();
14725
14726 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D));
14727 if (End.isInvalid())
14728 return ExprError();
14729
14730 Desig.AddDesignator(Designator::CreateArrayRangeDesignator(
14731 Start.get(), End.get(), D.getLBracketLoc(), D.getEllipsisLoc()));
14732
14733 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) ||
14734 End.get() != E->getArrayRangeEnd(D);
14735
14736 ArrayExprs.push_back(Start.get());
14737 ArrayExprs.push_back(End.get());
14738 }
14739
14740 if (!getDerived().AlwaysRebuild() &&
14741 Init.get() == E->getInit() &&
14742 !ExprChanged)
14743 return E;
14744
14745 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
14746 E->getEqualOrColonLoc(),
14747 E->usesGNUSyntax(), Init.get());
14748}
14749
14750// Seems that if TransformInitListExpr() only works on the syntactic form of an
14751// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
14752template<typename Derived>
14756 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
14757 "initializer");
14758 return ExprError();
14759}
14760
14761template<typename Derived>
14764 NoInitExpr *E) {
14765 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
14766 return ExprError();
14767}
14768
14769template<typename Derived>
14772 llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer");
14773 return ExprError();
14774}
14775
14776template<typename Derived>
14779 llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer");
14780 return ExprError();
14781}
14782
14783template<typename Derived>
14787 TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName());
14788
14789 // FIXME: Will we ever have proper type location here? Will we actually
14790 // need to transform the type?
14791 QualType T = getDerived().TransformType(E->getType());
14792 if (T.isNull())
14793 return ExprError();
14794
14795 if (!getDerived().AlwaysRebuild() &&
14796 T == E->getType())
14797 return E;
14798
14799 return getDerived().RebuildImplicitValueInitExpr(T);
14800}
14801
14802template<typename Derived>
14805 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
14806 if (!TInfo)
14807 return ExprError();
14808
14809 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
14810 if (SubExpr.isInvalid())
14811 return ExprError();
14812
14813 if (!getDerived().AlwaysRebuild() &&
14814 TInfo == E->getWrittenTypeInfo() &&
14815 SubExpr.get() == E->getSubExpr())
14816 return E;
14817
14818 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
14819 TInfo, E->getRParenLoc());
14820}
14821
14822template<typename Derived>
14825 bool ArgumentChanged = false;
14827 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
14828 &ArgumentChanged))
14829 return ExprError();
14830
14831 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
14832 Inits,
14833 E->getRParenLoc());
14834}
14835
14836/// Transform an address-of-label expression.
14837///
14838/// By default, the transformation of an address-of-label expression always
14839/// rebuilds the expression, so that the label identifier can be resolved to
14840/// the corresponding label statement by semantic analysis.
14841template<typename Derived>
14844 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
14845 E->getLabel());
14846 if (!LD)
14847 return ExprError();
14848
14849 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
14850 cast<LabelDecl>(LD));
14851}
14852
14853template<typename Derived>
14856 SemaRef.ActOnStartStmtExpr();
14857 StmtResult SubStmt
14858 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
14859 if (SubStmt.isInvalid()) {
14860 SemaRef.ActOnStmtExprError();
14861 return ExprError();
14862 }
14863
14864 unsigned OldDepth = E->getTemplateDepth();
14865 unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth);
14866
14867 if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth &&
14868 SubStmt.get() == E->getSubStmt()) {
14869 // Calling this an 'error' is unintuitive, but it does the right thing.
14870 SemaRef.ActOnStmtExprError();
14871 return SemaRef.MaybeBindToTemporary(E);
14872 }
14873
14874 return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(),
14875 E->getRParenLoc(), NewDepth);
14876}
14877
14878template<typename Derived>
14881 ExprResult Cond = getDerived().TransformExpr(E->getCond());
14882 if (Cond.isInvalid())
14883 return ExprError();
14884
14885 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
14886 if (LHS.isInvalid())
14887 return ExprError();
14888
14889 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
14890 if (RHS.isInvalid())
14891 return ExprError();
14892
14893 if (!getDerived().AlwaysRebuild() &&
14894 Cond.get() == E->getCond() &&
14895 LHS.get() == E->getLHS() &&
14896 RHS.get() == E->getRHS())
14897 return E;
14898
14899 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
14900 Cond.get(), LHS.get(), RHS.get(),
14901 E->getRParenLoc());
14902}
14903
14904template<typename Derived>
14907 return E;
14908}
14909
14910template<typename Derived>
14913 switch (E->getOperator()) {
14914 case OO_New:
14915 case OO_Delete:
14916 case OO_Array_New:
14917 case OO_Array_Delete:
14918 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
14919
14920 case OO_Subscript:
14921 case OO_Call: {
14922 // This is a call to an object's operator().
14923 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
14924
14925 // Transform the object itself.
14926 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
14927 if (Object.isInvalid())
14928 return ExprError();
14929
14930 // FIXME: Poor location information. Also, if the location for the end of
14931 // the token is within a macro expansion, getLocForEndOfToken() will return
14932 // an invalid source location. If that happens and we have an otherwise
14933 // valid end location, use the valid one instead of the invalid one.
14934 SourceLocation EndLoc = static_cast<Expr *>(Object.get())->getEndLoc();
14935 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(EndLoc);
14936 if (FakeLParenLoc.isInvalid() && EndLoc.isValid())
14937 FakeLParenLoc = EndLoc;
14938
14939 // Transform the call arguments.
14941 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
14942 Args))
14943 return ExprError();
14944
14945 if (E->getOperator() == OO_Subscript)
14946 return getDerived().RebuildCxxSubscriptExpr(Object.get(), FakeLParenLoc,
14947 Args, E->getEndLoc());
14948
14949 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args,
14950 E->getEndLoc());
14951 }
14952
14953#define OVERLOADED_OPERATOR(Name, Spelling, Token, Unary, Binary, MemberOnly) \
14954 case OO_##Name: \
14955 break;
14956
14957#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
14958#include "clang/Basic/OperatorKinds.def"
14959
14960 case OO_Conditional:
14961 llvm_unreachable("conditional operator is not actually overloadable");
14962
14963 case OO_None:
14965 llvm_unreachable("not an overloaded operator?");
14966 }
14967
14969 if (E->getNumArgs() == 1 && E->getOperator() == OO_Amp)
14970 First = getDerived().TransformAddressOfOperand(E->getArg(0));
14971 else
14972 First = getDerived().TransformExpr(E->getArg(0));
14973 if (First.isInvalid())
14974 return ExprError();
14975
14976 ExprResult Second;
14977 if (E->getNumArgs() == 2) {
14978 Second =
14979 getDerived().TransformInitializer(E->getArg(1), /*NotCopyInit=*/false);
14980 if (Second.isInvalid())
14981 return ExprError();
14982 }
14983
14984 Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
14985 FPOptionsOverride NewOverrides(E->getFPFeatures());
14986 getSema().CurFPFeatures =
14987 NewOverrides.applyOverrides(getSema().getLangOpts());
14988 getSema().FpPragmaStack.CurrentValue = NewOverrides;
14989
14990 Expr *Callee = E->getCallee();
14991 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
14992 LookupResult R(SemaRef, ULE->getName(), ULE->getNameLoc(),
14994 if (getDerived().TransformOverloadExprDecls(ULE, ULE->requiresADL(), R))
14995 return ExprError();
14996
14997 return getDerived().RebuildCXXOperatorCallExpr(
14998 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
14999 ULE->requiresADL(), R.asUnresolvedSet(), First.get(), Second.get());
15000 }
15001
15002 UnresolvedSet<1> Functions;
15003 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Callee))
15004 Callee = ICE->getSubExprAsWritten();
15005 NamedDecl *DR = cast<DeclRefExpr>(Callee)->getDecl();
15006 ValueDecl *VD = cast_or_null<ValueDecl>(
15007 getDerived().TransformDecl(DR->getLocation(), DR));
15008 if (!VD)
15009 return ExprError();
15010
15011 if (!isa<CXXMethodDecl>(VD))
15012 Functions.addDecl(VD);
15013
15014 return getDerived().RebuildCXXOperatorCallExpr(
15015 E->getOperator(), E->getOperatorLoc(), Callee->getBeginLoc(),
15016 /*RequiresADL=*/false, Functions, First.get(), Second.get());
15017}
15018
15019template<typename Derived>
15022 return getDerived().TransformCallExpr(E);
15023}
15024
15025template <typename Derived>
15027 bool NeedRebuildFunc = SourceLocExpr::MayBeDependent(E->getIdentKind()) &&
15028 getSema().CurContext != E->getParentContext();
15029
15030 if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc)
15031 return E;
15032
15033 return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getType(),
15034 E->getBeginLoc(), E->getEndLoc(),
15035 getSema().CurContext);
15036}
15037
15038template <typename Derived>
15040 return E;
15041}
15042
15043template<typename Derived>
15046 // Transform the callee.
15047 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
15048 if (Callee.isInvalid())
15049 return ExprError();
15050
15051 // Transform exec config.
15052 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
15053 if (EC.isInvalid())
15054 return ExprError();
15055
15056 // Transform arguments.
15057 bool ArgChanged = false;
15059 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
15060 &ArgChanged))
15061 return ExprError();
15062
15063 if (!getDerived().AlwaysRebuild() &&
15064 Callee.get() == E->getCallee() &&
15065 !ArgChanged)
15066 return SemaRef.MaybeBindToTemporary(E);
15067
15068 // FIXME: Wrong source location information for the '('.
15069 SourceLocation FakeLParenLoc
15070 = ((Expr *)Callee.get())->getSourceRange().getBegin();
15071 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
15072 Args,
15073 E->getRParenLoc(), EC.get());
15074}
15075
15076template<typename Derived>
15079 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
15080 if (!Type)
15081 return ExprError();
15082
15083 ExprResult SubExpr
15084 = getDerived().TransformExpr(E->getSubExprAsWritten());
15085 if (SubExpr.isInvalid())
15086 return ExprError();
15087
15088 if (!getDerived().AlwaysRebuild() &&
15089 Type == E->getTypeInfoAsWritten() &&
15090 SubExpr.get() == E->getSubExpr())
15091 return E;
15092 return getDerived().RebuildCXXNamedCastExpr(
15095 // FIXME. this should be '(' location
15096 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
15097}
15098
15099template<typename Derived>
15102 TypeSourceInfo *TSI =
15103 getDerived().TransformType(BCE->getTypeInfoAsWritten());
15104 if (!TSI)
15105 return ExprError();
15106
15107 ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr());
15108 if (Sub.isInvalid())
15109 return ExprError();
15110
15111 return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI,
15112 Sub.get(), BCE->getEndLoc());
15113}
15114
15115template<typename Derived>
15117TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
15118 return getDerived().TransformCXXNamedCastExpr(E);
15119}
15120
15121template<typename Derived>
15124 return getDerived().TransformCXXNamedCastExpr(E);
15125}
15126
15127template<typename Derived>
15131 return getDerived().TransformCXXNamedCastExpr(E);
15132}
15133
15134template<typename Derived>
15137 return getDerived().TransformCXXNamedCastExpr(E);
15138}
15139
15140template<typename Derived>
15143 return getDerived().TransformCXXNamedCastExpr(E);
15144}
15145
15146template<typename Derived>
15151 getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten());
15152 if (!Type)
15153 return ExprError();
15154
15155 ExprResult SubExpr
15156 = getDerived().TransformExpr(E->getSubExprAsWritten());
15157 if (SubExpr.isInvalid())
15158 return ExprError();
15159
15160 if (!getDerived().AlwaysRebuild() &&
15161 Type == E->getTypeInfoAsWritten() &&
15162 SubExpr.get() == E->getSubExpr())
15163 return E;
15164
15165 return getDerived().RebuildCXXFunctionalCastExpr(Type,
15166 E->getLParenLoc(),
15167 SubExpr.get(),
15168 E->getRParenLoc(),
15169 E->isListInitialization());
15170}
15171
15172template<typename Derived>
15175 if (E->isTypeOperand()) {
15176 TypeSourceInfo *TInfo
15177 = getDerived().TransformType(E->getTypeOperandSourceInfo());
15178 if (!TInfo)
15179 return ExprError();
15180
15181 if (!getDerived().AlwaysRebuild() &&
15182 TInfo == E->getTypeOperandSourceInfo())
15183 return E;
15184
15185 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
15186 TInfo, E->getEndLoc());
15187 }
15188
15189 // Typeid's operand is an unevaluated context, unless it's a polymorphic
15190 // type. We must not unilaterally enter unevaluated context here, as then
15191 // semantic processing can re-transform an already transformed operand.
15192 Expr *Op = E->getExprOperand();
15194 if (E->isGLValue()) {
15195 QualType OpType = Op->getType();
15196 if (auto *RD = OpType->getAsCXXRecordDecl()) {
15197 if (SemaRef.RequireCompleteType(E->getBeginLoc(), OpType,
15198 diag::err_incomplete_typeid))
15199 return ExprError();
15200
15201 if (RD->isPolymorphic())
15202 EvalCtx = SemaRef.ExprEvalContexts.back().Context;
15203 }
15204 }
15205
15208
15209 ExprResult SubExpr = getDerived().TransformExpr(Op);
15210 if (SubExpr.isInvalid())
15211 return ExprError();
15212
15213 if (!getDerived().AlwaysRebuild() &&
15214 SubExpr.get() == E->getExprOperand())
15215 return E;
15216
15217 return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(),
15218 SubExpr.get(), E->getEndLoc());
15219}
15220
15221template<typename Derived>
15224 if (E->isTypeOperand()) {
15225 TypeSourceInfo *TInfo
15226 = getDerived().TransformType(E->getTypeOperandSourceInfo());
15227 if (!TInfo)
15228 return ExprError();
15229
15230 if (!getDerived().AlwaysRebuild() &&
15231 TInfo == E->getTypeOperandSourceInfo())
15232 return E;
15233
15234 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
15235 TInfo, E->getEndLoc());
15236 }
15237
15240
15241 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
15242 if (SubExpr.isInvalid())
15243 return ExprError();
15244
15245 if (!getDerived().AlwaysRebuild() &&
15246 SubExpr.get() == E->getExprOperand())
15247 return E;
15248
15249 return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(),
15250 SubExpr.get(), E->getEndLoc());
15251}
15252
15253template<typename Derived>
15256 return E;
15257}
15258
15259template<typename Derived>
15263 return E;
15264}
15265
15266template<typename Derived>
15269
15270 // In lambdas, the qualifiers of the type depends of where in
15271 // the call operator `this` appear, and we do not have a good way to
15272 // rebuild this information, so we transform the type.
15273 //
15274 // In other contexts, the type of `this` may be overrided
15275 // for type deduction, so we need to recompute it.
15276 //
15277 // Always recompute the type if we're in the body of a lambda, and
15278 // 'this' is dependent on a lambda's explicit object parameter; we
15279 // also need to always rebuild the expression in this case to clear
15280 // the flag.
15281 QualType T = [&]() {
15282 auto &S = getSema();
15283 if (E->isCapturedByCopyInLambdaWithExplicitObjectParameter())
15284 return S.getCurrentThisType();
15285 if (S.getCurLambda())
15286 return getDerived().TransformType(E->getType());
15287 return S.getCurrentThisType();
15288 }();
15289
15290 if (!getDerived().AlwaysRebuild() && T == E->getType() &&
15291 !E->isCapturedByCopyInLambdaWithExplicitObjectParameter()) {
15292 // Mark it referenced in the new context regardless.
15293 // FIXME: this is a bit instantiation-specific.
15294 getSema().MarkThisReferenced(E);
15295 return E;
15296 }
15297
15298 return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit());
15299}
15300
15301template<typename Derived>
15304 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
15305 if (SubExpr.isInvalid())
15306 return ExprError();
15307
15308 getSema().DiagnoseExceptionUse(E->getThrowLoc(), /* IsTry= */ false);
15309
15310 if (!getDerived().AlwaysRebuild() &&
15311 SubExpr.get() == E->getSubExpr())
15312 return E;
15313
15314 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
15315 E->isThrownVariableInScope());
15316}
15317
15318template<typename Derived>
15321 ParmVarDecl *Param = cast_or_null<ParmVarDecl>(
15322 getDerived().TransformDecl(E->getBeginLoc(), E->getParam()));
15323 if (!Param)
15324 return ExprError();
15325
15326 ExprResult InitRes;
15327 if (E->hasRewrittenInit()) {
15328 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
15329 if (InitRes.isInvalid())
15330 return ExprError();
15331 }
15332
15333 if (!getDerived().AlwaysRebuild() && Param == E->getParam() &&
15334 E->getUsedContext() == SemaRef.CurContext &&
15335 InitRes.get() == E->getRewrittenExpr())
15336 return E;
15337
15338 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param,
15339 InitRes.get());
15340}
15341
15342template<typename Derived>
15345 FieldDecl *Field = cast_or_null<FieldDecl>(
15346 getDerived().TransformDecl(E->getBeginLoc(), E->getField()));
15347 if (!Field)
15348 return ExprError();
15349
15350 ExprResult InitRes;
15351 if (E->hasRewrittenInit()) {
15352 // The initializer can refer to `this` and to other members, so it has to
15353 // be transformed in the scope of the field's class.
15354 Sema::CXXThisScopeRAII ThisScope(SemaRef, Field->getParent(), Qualifiers());
15355 InitRes = getDerived().TransformExpr(E->getRewrittenExpr());
15356 if (InitRes.isInvalid())
15357 return ExprError();
15358 }
15359
15360 if (!getDerived().AlwaysRebuild() && Field == E->getField() &&
15361 E->getUsedContext() == SemaRef.CurContext &&
15362 InitRes.get() == E->getExpr())
15363 return E;
15364
15365 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field,
15366 InitRes.get());
15367}
15368
15369template<typename Derived>
15373 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
15374 if (!T)
15375 return ExprError();
15376
15377 if (!getDerived().AlwaysRebuild() &&
15378 T == E->getTypeSourceInfo())
15379 return E;
15380
15381 return getDerived().RebuildCXXScalarValueInitExpr(T,
15382 /*FIXME:*/T->getTypeLoc().getEndLoc(),
15383 E->getRParenLoc());
15384}
15385
15386template<typename Derived>
15389 // Transform the type that we're allocating
15390 TypeSourceInfo *AllocTypeInfo =
15391 getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo());
15392 if (!AllocTypeInfo)
15393 return ExprError();
15394
15395 // Transform the size of the array we're allocating (if any).
15396 std::optional<Expr *> ArraySize;
15397 if (E->isArray()) {
15398 ExprResult NewArraySize;
15399 if (std::optional<Expr *> OldArraySize = E->getArraySize()) {
15400 NewArraySize = getDerived().TransformExpr(*OldArraySize);
15401 if (NewArraySize.isInvalid())
15402 return ExprError();
15403 }
15404 ArraySize = NewArraySize.get();
15405 }
15406
15407 // Transform the placement arguments (if any).
15408 bool ArgumentChanged = false;
15409 SmallVector<Expr*, 8> PlacementArgs;
15410 if (getDerived().TransformExprs(E->getPlacementArgs(),
15411 E->getNumPlacementArgs(), true,
15412 PlacementArgs, &ArgumentChanged))
15413 return ExprError();
15414
15415 // Transform the initializer (if any).
15416 Expr *OldInit = E->getInitializer();
15417 ExprResult NewInit;
15418 if (OldInit)
15419 NewInit = getDerived().TransformInitializer(OldInit, true);
15420 if (NewInit.isInvalid())
15421 return ExprError();
15422
15423 // Transform new operator and delete operator.
15424 FunctionDecl *OperatorNew = nullptr;
15425 if (E->getOperatorNew()) {
15426 OperatorNew = cast_or_null<FunctionDecl>(
15427 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew()));
15428 if (!OperatorNew)
15429 return ExprError();
15430 }
15431
15432 FunctionDecl *OperatorDelete = nullptr;
15433 if (E->getOperatorDelete()) {
15434 OperatorDelete = cast_or_null<FunctionDecl>(
15435 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15436 if (!OperatorDelete)
15437 return ExprError();
15438 }
15439
15440 if (!getDerived().AlwaysRebuild() &&
15441 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
15442 ArraySize == E->getArraySize() &&
15443 NewInit.get() == OldInit &&
15444 OperatorNew == E->getOperatorNew() &&
15445 OperatorDelete == E->getOperatorDelete() &&
15446 !ArgumentChanged) {
15447 // Mark any declarations we need as referenced.
15448 // FIXME: instantiation-specific.
15449 if (OperatorNew)
15450 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew);
15451 if (OperatorDelete)
15452 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15453
15454 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
15455 QualType ElementType
15456 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
15457 if (CXXRecordDecl *Record = ElementType->getAsCXXRecordDecl()) {
15459 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor);
15460 }
15461 }
15462
15463 return E;
15464 }
15465
15466 QualType AllocType = AllocTypeInfo->getType();
15467 if (!ArraySize) {
15468 // If no array size was specified, but the new expression was
15469 // instantiated with an array type (e.g., "new T" where T is
15470 // instantiated with "int[4]"), extract the outer bound from the
15471 // array type as our array size. We do this with constant and
15472 // dependently-sized array types.
15473 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
15474 if (!ArrayT) {
15475 // Do nothing
15476 } else if (const ConstantArrayType *ConsArrayT
15477 = dyn_cast<ConstantArrayType>(ArrayT)) {
15478 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
15479 SemaRef.Context.getSizeType(),
15480 /*FIXME:*/ E->getBeginLoc());
15481 AllocType = ConsArrayT->getElementType();
15482 } else if (const DependentSizedArrayType *DepArrayT
15483 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
15484 if (DepArrayT->getSizeExpr()) {
15485 ArraySize = DepArrayT->getSizeExpr();
15486 AllocType = DepArrayT->getElementType();
15487 }
15488 }
15489 }
15490
15491 return getDerived().RebuildCXXNewExpr(
15492 E->getBeginLoc(), E->isGlobalNew(),
15493 /*FIXME:*/ E->getBeginLoc(), PlacementArgs,
15494 /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType,
15495 AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get());
15496}
15497
15498template<typename Derived>
15501 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
15502 if (Operand.isInvalid())
15503 return ExprError();
15504
15505 // Transform the delete operator, if known.
15506 FunctionDecl *OperatorDelete = nullptr;
15507 if (E->getOperatorDelete()) {
15508 OperatorDelete = cast_or_null<FunctionDecl>(
15509 getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete()));
15510 if (!OperatorDelete)
15511 return ExprError();
15512 }
15513
15514 if (!getDerived().AlwaysRebuild() &&
15515 Operand.get() == E->getArgument() &&
15516 OperatorDelete == E->getOperatorDelete()) {
15517 // Mark any declarations we need as referenced.
15518 // FIXME: instantiation-specific.
15519 if (OperatorDelete)
15520 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete);
15521
15522 if (!E->getArgument()->isTypeDependent()) {
15524 E->getDestroyedType());
15525 if (auto *Record = Destroyed->getAsCXXRecordDecl())
15526 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
15527 SemaRef.LookupDestructor(Record));
15528 }
15529
15530 return E;
15531 }
15532
15533 return getDerived().RebuildCXXDeleteExpr(
15534 E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get());
15535}
15536
15537template<typename Derived>
15541 ExprResult Base = getDerived().TransformExpr(E->getBase());
15542 if (Base.isInvalid())
15543 return ExprError();
15544
15545 ParsedType ObjectTypePtr;
15546 bool MayBePseudoDestructor = false;
15547 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
15548 E->getOperatorLoc(),
15549 E->isArrow()? tok::arrow : tok::period,
15550 ObjectTypePtr,
15551 MayBePseudoDestructor);
15552 if (Base.isInvalid())
15553 return ExprError();
15554
15555 QualType ObjectType = ObjectTypePtr.get();
15556 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
15557 if (QualifierLoc) {
15558 QualifierLoc
15559 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
15560 if (!QualifierLoc)
15561 return ExprError();
15562 }
15563 CXXScopeSpec SS;
15564 SS.Adopt(QualifierLoc);
15565
15567 if (E->getDestroyedTypeInfo()) {
15568 TypeSourceInfo *DestroyedTypeInfo = getDerived().TransformTypeInObjectScope(
15569 E->getDestroyedTypeInfo(), ObjectType,
15570 /*FirstQualifierInScope=*/nullptr);
15571 if (!DestroyedTypeInfo)
15572 return ExprError();
15573 Destroyed = DestroyedTypeInfo;
15574 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
15575 // We aren't likely to be able to resolve the identifier down to a type
15576 // now anyway, so just retain the identifier.
15577 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
15578 E->getDestroyedTypeLoc());
15579 } else {
15580 // Look for a destructor known with the given name.
15581 ParsedType T = SemaRef.getDestructorName(
15582 *E->getDestroyedTypeIdentifier(), E->getDestroyedTypeLoc(),
15583 /*Scope=*/nullptr, SS, ObjectTypePtr, false);
15584 if (!T)
15585 return ExprError();
15586
15587 Destroyed
15589 E->getDestroyedTypeLoc());
15590 }
15591
15592 TypeSourceInfo *ScopeTypeInfo = nullptr;
15593 if (E->getScopeTypeInfo()) {
15594 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
15595 E->getScopeTypeInfo(), ObjectType, nullptr);
15596 if (!ScopeTypeInfo)
15597 return ExprError();
15598 }
15599
15600 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
15601 E->getOperatorLoc(),
15602 E->isArrow(),
15603 SS,
15604 ScopeTypeInfo,
15605 E->getColonColonLoc(),
15606 E->getTildeLoc(),
15607 Destroyed);
15608}
15609
15610template <typename Derived>
15612 bool RequiresADL,
15613 LookupResult &R) {
15614 // Transform all the decls.
15615 bool AllEmptyPacks = true;
15616 for (auto *OldD : Old->decls()) {
15617 Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD);
15618 if (!InstD) {
15619 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
15620 // This can happen because of dependent hiding.
15621 if (isa<UsingShadowDecl>(OldD))
15622 continue;
15623 else {
15624 R.clear();
15625 return true;
15626 }
15627 }
15628
15629 // Expand using pack declarations.
15630 NamedDecl *SingleDecl = cast<NamedDecl>(InstD);
15631 ArrayRef<NamedDecl*> Decls = SingleDecl;
15632 if (auto *UPD = dyn_cast<UsingPackDecl>(InstD))
15633 Decls = UPD->expansions();
15634
15635 // Expand using declarations.
15636 for (auto *D : Decls) {
15637 if (auto *UD = dyn_cast<UsingDecl>(D)) {
15638 for (auto *SD : UD->shadows())
15639 R.addDecl(SD);
15640 } else {
15641 R.addDecl(D);
15642 }
15643 }
15644
15645 AllEmptyPacks &= Decls.empty();
15646 }
15647
15648 // C++ [temp.res]/8.4.2:
15649 // The program is ill-formed, no diagnostic required, if [...] lookup for
15650 // a name in the template definition found a using-declaration, but the
15651 // lookup in the corresponding scope in the instantiation odoes not find
15652 // any declarations because the using-declaration was a pack expansion and
15653 // the corresponding pack is empty
15654 if (AllEmptyPacks && !RequiresADL) {
15655 getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty)
15656 << isa<UnresolvedMemberExpr>(Old) << Old->getName();
15657 return true;
15658 }
15659
15660 // Resolve a kind, but don't do any further analysis. If it's
15661 // ambiguous, the callee needs to deal with it.
15662 R.resolveKind();
15663
15664 if (Old->hasTemplateKeyword() && !R.empty()) {
15665 NamedDecl *FoundDecl = R.getRepresentativeDecl()->getUnderlyingDecl();
15666 getSema().FilterAcceptableTemplateNames(R,
15667 /*AllowFunctionTemplates=*/true,
15668 /*AllowDependent=*/true);
15669 if (R.empty()) {
15670 // If a 'template' keyword was used, a lookup that finds only non-template
15671 // names is an error.
15672 getSema().Diag(R.getNameLoc(),
15673 diag::err_template_kw_refers_to_non_template)
15674 << R.getLookupName() << Old->getQualifierLoc().getSourceRange()
15675 << Old->hasTemplateKeyword() << Old->getTemplateKeywordLoc();
15676 getSema().Diag(FoundDecl->getLocation(),
15677 diag::note_template_kw_refers_to_non_template)
15678 << R.getLookupName();
15679 return true;
15680 }
15681 }
15682
15683 return false;
15684}
15685
15686template <typename Derived>
15691
15692template <typename Derived>
15695 bool IsAddressOfOperand) {
15696 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
15698
15699 // Transform the declaration set.
15700 if (TransformOverloadExprDecls(Old, Old->requiresADL(), R))
15701 return ExprError();
15702
15703 // Rebuild the nested-name qualifier, if present.
15704 CXXScopeSpec SS;
15705 if (Old->getQualifierLoc()) {
15706 NestedNameSpecifierLoc QualifierLoc
15707 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
15708 if (!QualifierLoc)
15709 return ExprError();
15710
15711 SS.Adopt(QualifierLoc);
15712 }
15713
15714 if (Old->getNamingClass()) {
15715 CXXRecordDecl *NamingClass
15716 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
15717 Old->getNameLoc(),
15718 Old->getNamingClass()));
15719 if (!NamingClass) {
15720 R.clear();
15721 return ExprError();
15722 }
15723
15724 R.setNamingClass(NamingClass);
15725 }
15726
15727 // Rebuild the template arguments, if any.
15728 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
15729 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
15730 if (Old->hasExplicitTemplateArgs() &&
15731 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15732 Old->getNumTemplateArgs(),
15733 TransArgs)) {
15734 R.clear();
15735 return ExprError();
15736 }
15737
15738 // An UnresolvedLookupExpr can refer to a class member. This occurs e.g. when
15739 // a non-static data member is named in an unevaluated operand, or when
15740 // a member is named in a dependent class scope function template explicit
15741 // specialization that is neither declared static nor with an explicit object
15742 // parameter.
15743 if (SemaRef.isPotentialImplicitMemberAccess(SS, R, IsAddressOfOperand))
15744 return SemaRef.BuildPossibleImplicitMemberExpr(
15745 SS, TemplateKWLoc, R,
15746 Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr,
15747 /*S=*/nullptr);
15748
15749 // If we have neither explicit template arguments, nor the template keyword,
15750 // it's a normal declaration name or member reference.
15751 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
15752 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
15753
15754 // If we have template arguments, then rebuild the template-id expression.
15755 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
15756 Old->requiresADL(), &TransArgs);
15757}
15758
15759template<typename Derived>
15762 bool ArgChanged = false;
15764 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
15765 TypeSourceInfo *From = E->getArg(I);
15766 TypeLoc FromTL = From->getTypeLoc();
15767 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
15768 TypeLocBuilder TLB;
15769 TLB.reserve(FromTL.getFullDataSize());
15770 QualType To = getDerived().TransformType(TLB, FromTL);
15771 if (To.isNull())
15772 return ExprError();
15773
15774 if (To == From->getType())
15775 Args.push_back(From);
15776 else {
15777 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15778 ArgChanged = true;
15779 }
15780 continue;
15781 }
15782
15783 ArgChanged = true;
15784
15785 // We have a pack expansion. Instantiate it.
15786 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
15787 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
15789 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
15790
15791 // Determine whether the set of unexpanded parameter packs can and should
15792 // be expanded.
15793 bool Expand = true;
15794 bool RetainExpansion = false;
15795 UnsignedOrNone OrigNumExpansions =
15796 ExpansionTL.getTypePtr()->getNumExpansions();
15797 UnsignedOrNone NumExpansions = OrigNumExpansions;
15798 if (getDerived().TryExpandParameterPacks(
15799 ExpansionTL.getEllipsisLoc(), PatternTL.getSourceRange(),
15800 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
15801 RetainExpansion, NumExpansions))
15802 return ExprError();
15803
15804 if (!Expand) {
15805 // The transform has determined that we should perform a simple
15806 // transformation on the pack expansion, producing another pack
15807 // expansion.
15808 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
15809
15810 TypeLocBuilder TLB;
15811 TLB.reserve(From->getTypeLoc().getFullDataSize());
15812
15813 QualType To = getDerived().TransformType(TLB, PatternTL);
15814 if (To.isNull())
15815 return ExprError();
15816
15817 To = getDerived().RebuildPackExpansionType(To,
15818 PatternTL.getSourceRange(),
15819 ExpansionTL.getEllipsisLoc(),
15820 NumExpansions);
15821 if (To.isNull())
15822 return ExprError();
15823
15824 PackExpansionTypeLoc ToExpansionTL
15825 = TLB.push<PackExpansionTypeLoc>(To);
15826 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15827 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15828 continue;
15829 }
15830
15831 // Expand the pack expansion by substituting for each argument in the
15832 // pack(s).
15833 for (unsigned I = 0; I != *NumExpansions; ++I) {
15834 Sema::ArgPackSubstIndexRAII SubstIndex(SemaRef, I);
15835 TypeLocBuilder TLB;
15836 TLB.reserve(PatternTL.getFullDataSize());
15837 QualType To = getDerived().TransformType(TLB, PatternTL);
15838 if (To.isNull())
15839 return ExprError();
15840
15841 if (To->containsUnexpandedParameterPack()) {
15842 To = getDerived().RebuildPackExpansionType(To,
15843 PatternTL.getSourceRange(),
15844 ExpansionTL.getEllipsisLoc(),
15845 NumExpansions);
15846 if (To.isNull())
15847 return ExprError();
15848
15849 PackExpansionTypeLoc ToExpansionTL
15850 = TLB.push<PackExpansionTypeLoc>(To);
15851 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15852 }
15853
15854 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15855 }
15856
15857 if (!RetainExpansion)
15858 continue;
15859
15860 // If we're supposed to retain a pack expansion, do so by temporarily
15861 // forgetting the partially-substituted parameter pack.
15862 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
15863
15864 TypeLocBuilder TLB;
15865 TLB.reserve(From->getTypeLoc().getFullDataSize());
15866
15867 QualType To = getDerived().TransformType(TLB, PatternTL);
15868 if (To.isNull())
15869 return ExprError();
15870
15871 To = getDerived().RebuildPackExpansionType(To,
15872 PatternTL.getSourceRange(),
15873 ExpansionTL.getEllipsisLoc(),
15874 NumExpansions);
15875 if (To.isNull())
15876 return ExprError();
15877
15878 PackExpansionTypeLoc ToExpansionTL
15879 = TLB.push<PackExpansionTypeLoc>(To);
15880 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
15881 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
15882 }
15883
15884 if (!getDerived().AlwaysRebuild() && !ArgChanged)
15885 return E;
15886
15887 return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args,
15888 E->getEndLoc());
15889}
15890
15891template<typename Derived>
15895 const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten();
15896 TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc);
15897 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
15898 Old->NumTemplateArgs, TransArgs))
15899 return ExprError();
15900
15901 return getDerived().RebuildConceptSpecializationExpr(
15902 E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(),
15903 E->getConceptNameInfo(), E->getFoundDecl(), E->getConceptDecl(),
15904 &TransArgs);
15905}
15906
15907template<typename Derived>
15910 SmallVector<ParmVarDecl*, 4> TransParams;
15911 SmallVector<QualType, 4> TransParamTypes;
15912 Sema::ExtParameterInfoBuilder ExtParamInfos;
15913
15914 // C++2a [expr.prim.req]p2
15915 // Expressions appearing within a requirement-body are unevaluated operands.
15919
15921 getSema().Context, getSema().CurContext,
15922 E->getBody()->getBeginLoc());
15923
15924 Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false);
15925
15926 ExprResult TypeParamResult = getDerived().TransformRequiresTypeParams(
15927 E->getRequiresKWLoc(), E->getRBraceLoc(), E, Body,
15928 E->getLocalParameters(), TransParamTypes, TransParams, ExtParamInfos);
15929
15930 for (ParmVarDecl *Param : TransParams)
15931 if (Param)
15932 Param->setDeclContext(Body);
15933
15934 // On failure to transform, TransformRequiresTypeParams returns an expression
15935 // in the event that the transformation of the type params failed in some way.
15936 // It is expected that this will result in a 'not satisfied' Requires clause
15937 // when instantiating.
15938 if (!TypeParamResult.isUnset())
15939 return TypeParamResult;
15940
15942 if (getDerived().TransformRequiresExprRequirements(E->getRequirements(),
15943 TransReqs))
15944 return ExprError();
15945
15946 for (concepts::Requirement *Req : TransReqs) {
15947 if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) {
15948 if (ER->getReturnTypeRequirement().isTypeConstraint()) {
15949 ER->getReturnTypeRequirement()
15950 .getTypeConstraintTemplateParameterList()->getParam(0)
15951 ->setDeclContext(Body);
15952 }
15953 }
15954 }
15955
15956 return getDerived().RebuildRequiresExpr(
15957 E->getRequiresKWLoc(), Body, E->getLParenLoc(), TransParams,
15958 E->getRParenLoc(), TransReqs, E->getRBraceLoc());
15959}
15960
15961template<typename Derived>
15965 for (concepts::Requirement *Req : Reqs) {
15966 concepts::Requirement *TransReq = nullptr;
15967 if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req))
15968 TransReq = getDerived().TransformTypeRequirement(TypeReq);
15969 else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req))
15970 TransReq = getDerived().TransformExprRequirement(ExprReq);
15971 else
15972 TransReq = getDerived().TransformNestedRequirement(
15974 if (!TransReq)
15975 return true;
15976 Transformed.push_back(TransReq);
15977 }
15978 return false;
15979}
15980
15981template<typename Derived>
15985 if (Req->isSubstitutionFailure()) {
15986 if (getDerived().AlwaysRebuild())
15987 return getDerived().RebuildTypeRequirement(
15989 return Req;
15990 }
15991 TypeSourceInfo *TransType = getDerived().TransformType(Req->getType());
15992 if (!TransType)
15993 return nullptr;
15994 return getDerived().RebuildTypeRequirement(TransType);
15995}
15996
15997template<typename Derived>
16000 llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr;
16001 if (Req->isExprSubstitutionFailure())
16002 TransExpr = Req->getExprSubstitutionDiagnostic();
16003 else {
16004 ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr());
16005 if (TransExprRes.isUsable() && TransExprRes.get()->hasPlaceholderType())
16006 TransExprRes = SemaRef.CheckPlaceholderExpr(TransExprRes.get());
16007 if (TransExprRes.isInvalid())
16008 return nullptr;
16009 TransExpr = TransExprRes.get();
16010 }
16011
16012 std::optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq;
16013 const auto &RetReq = Req->getReturnTypeRequirement();
16014 if (RetReq.isEmpty())
16015 TransRetReq.emplace();
16016 else if (RetReq.isSubstitutionFailure())
16017 TransRetReq.emplace(RetReq.getSubstitutionDiagnostic());
16018 else if (RetReq.isTypeConstraint()) {
16019 TemplateParameterList *OrigTPL =
16020 RetReq.getTypeConstraintTemplateParameterList();
16022 getDerived().TransformTemplateParameterList(OrigTPL);
16023 if (!TPL)
16024 return nullptr;
16025 TransRetReq.emplace(TPL);
16026 }
16027 assert(TransRetReq && "All code paths leading here must set TransRetReq");
16028 if (Expr *E = dyn_cast<Expr *>(TransExpr))
16029 return getDerived().RebuildExprRequirement(E, Req->isSimple(),
16030 Req->getNoexceptLoc(),
16031 std::move(*TransRetReq));
16032 return getDerived().RebuildExprRequirement(
16034 Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq));
16035}
16036
16037template<typename Derived>
16041 if (Req->hasInvalidConstraint()) {
16042 if (getDerived().AlwaysRebuild())
16043 return getDerived().RebuildNestedRequirement(
16045 return Req;
16046 }
16047 ExprResult TransConstraint =
16048 getDerived().TransformExpr(Req->getConstraintExpr());
16049 if (TransConstraint.isInvalid())
16050 return nullptr;
16051 return getDerived().RebuildNestedRequirement(TransConstraint.get());
16052}
16053
16054template<typename Derived>
16057 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
16058 if (!T)
16059 return ExprError();
16060
16061 if (!getDerived().AlwaysRebuild() &&
16063 return E;
16064
16065 ExprResult SubExpr;
16066 {
16069 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
16070 if (SubExpr.isInvalid())
16071 return ExprError();
16072 }
16073
16074 return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T,
16075 SubExpr.get(), E->getEndLoc());
16076}
16077
16078template<typename Derived>
16081 ExprResult SubExpr;
16082 {
16085 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
16086 if (SubExpr.isInvalid())
16087 return ExprError();
16088
16089 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
16090 return E;
16091 }
16092
16093 return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(),
16094 SubExpr.get(), E->getEndLoc());
16095}
16096
16097template <typename Derived>
16099 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
16100 TypeSourceInfo **RecoveryTSI) {
16101 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
16102 DRE, AddrTaken, RecoveryTSI);
16103
16104 // Propagate both errors and recovered types, which return ExprEmpty.
16105 if (!NewDRE.isUsable())
16106 return NewDRE;
16107
16108 // We got an expr, wrap it up in parens.
16109 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
16110 return PE;
16111 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
16112 PE->getRParen());
16113}
16114
16115template <typename Derived>
16121
16122template <typename Derived>
16124 DependentScopeDeclRefExpr *E, bool IsAddressOfOperand,
16125 TypeSourceInfo **RecoveryTSI) {
16126 assert(E->getQualifierLoc());
16127 NestedNameSpecifierLoc QualifierLoc =
16128 getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
16129 if (!QualifierLoc)
16130 return ExprError();
16131 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
16132
16133 // TODO: If this is a conversion-function-id, verify that the
16134 // destination type name (if present) resolves the same way after
16135 // instantiation as it did in the local scope.
16136
16137 DeclarationNameInfo NameInfo =
16138 getDerived().TransformDeclarationNameInfo(E->getNameInfo());
16139 if (!NameInfo.getName())
16140 return ExprError();
16141
16142 if (!E->hasExplicitTemplateArgs()) {
16143 if (!getDerived().AlwaysRebuild() && QualifierLoc == E->getQualifierLoc() &&
16144 // Note: it is sufficient to compare the Name component of NameInfo:
16145 // if name has not changed, DNLoc has not changed either.
16146 NameInfo.getName() == E->getDeclName())
16147 return E;
16148
16149 return getDerived().RebuildDependentScopeDeclRefExpr(
16150 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
16151 IsAddressOfOperand, RecoveryTSI);
16152 }
16153
16154 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16155 if (getDerived().TransformTemplateArguments(
16156 E->getTemplateArgs(), E->getNumTemplateArgs(), TransArgs))
16157 return ExprError();
16158
16159 return getDerived().RebuildDependentScopeDeclRefExpr(
16160 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
16161 RecoveryTSI);
16162}
16163
16164template<typename Derived>
16167 // CXXConstructExprs other than for list-initialization and
16168 // CXXTemporaryObjectExpr are always implicit, so when we have
16169 // a 1-argument construction we just transform that argument.
16170 if (getDerived().AllowSkippingCXXConstructExpr() &&
16171 ((E->getNumArgs() == 1 ||
16172 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
16173 (!getDerived().DropCallArgument(E->getArg(0))) &&
16174 !E->isListInitialization()))
16175 return getDerived().TransformInitializer(E->getArg(0),
16176 /*DirectInit*/ false);
16177
16178 TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName());
16179
16180 QualType T = getDerived().TransformType(E->getType());
16181 if (T.isNull())
16182 return ExprError();
16183
16184 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
16185 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
16186 if (!Constructor)
16187 return ExprError();
16188
16189 bool ArgumentChanged = false;
16191 {
16194 E->isListInitialization());
16195 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
16196 &ArgumentChanged))
16197 return ExprError();
16198 }
16199
16200 if (!getDerived().AlwaysRebuild() &&
16201 T == E->getType() &&
16202 Constructor == E->getConstructor() &&
16203 !ArgumentChanged) {
16204 // Mark the constructor as referenced.
16205 // FIXME: Instantiation-specific
16206 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
16207 return E;
16208 }
16209
16210 return getDerived().RebuildCXXConstructExpr(
16211 T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args,
16212 E->hadMultipleCandidates(), E->isListInitialization(),
16213 E->isStdInitListInitialization(), E->requiresZeroInitialization(),
16214 E->getConstructionKind(), E->getParenOrBraceRange());
16215}
16216
16217template<typename Derived>
16220 QualType T = getDerived().TransformType(E->getType());
16221 if (T.isNull())
16222 return ExprError();
16223
16224 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
16225 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
16226 if (!Constructor)
16227 return ExprError();
16228
16229 if (!getDerived().AlwaysRebuild() &&
16230 T == E->getType() &&
16231 Constructor == E->getConstructor()) {
16232 // Mark the constructor as referenced.
16233 // FIXME: Instantiation-specific
16234 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
16235 return E;
16236 }
16237
16238 return getDerived().RebuildCXXInheritedCtorInitExpr(
16239 T, E->getLocation(), Constructor,
16240 E->constructsVBase(), E->inheritedFromVBase());
16241}
16242
16243/// Transform a C++ temporary-binding expression.
16244///
16245/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
16246/// transform the subexpression and return that.
16247template<typename Derived>
16250 if (auto *Dtor = E->getTemporary()->getDestructor())
16251 SemaRef.MarkFunctionReferenced(E->getBeginLoc(),
16252 const_cast<CXXDestructorDecl *>(Dtor));
16253 return getDerived().TransformExpr(E->getSubExpr());
16254}
16255
16256/// Transform a C++ expression that contains cleanups that should
16257/// be run after the expression is evaluated.
16258///
16259/// Since ExprWithCleanups nodes are implicitly generated, we
16260/// just transform the subexpression and return that.
16261template<typename Derived>
16264 return getDerived().TransformExpr(E->getSubExpr());
16265}
16266
16267template<typename Derived>
16271 TypeSourceInfo *T =
16272 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
16273 if (!T)
16274 return ExprError();
16275
16276 CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>(
16277 getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor()));
16278 if (!Constructor)
16279 return ExprError();
16280
16281 bool ArgumentChanged = false;
16283 Args.reserve(E->getNumArgs());
16284 {
16287 E->isListInitialization());
16288 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
16289 &ArgumentChanged))
16290 return ExprError();
16291
16292 if (E->isListInitialization() && !E->isStdInitListInitialization()) {
16293 ExprResult Res = RebuildInitList(E->getBeginLoc(), Args, E->getEndLoc(),
16294 /*IsExplicit=*/true);
16295 if (Res.isInvalid())
16296 return ExprError();
16297 Args = {Res.get()};
16298 }
16299 }
16300
16301 if (!getDerived().AlwaysRebuild() &&
16302 T == E->getTypeSourceInfo() &&
16303 Constructor == E->getConstructor() &&
16304 !ArgumentChanged) {
16305 // FIXME: Instantiation-specific
16306 SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor);
16307 return SemaRef.MaybeBindToTemporary(E);
16308 }
16309
16310 SourceLocation LParenLoc = T->getTypeLoc().getEndLoc();
16311 return getDerived().RebuildCXXTemporaryObjectExpr(
16312 T, LParenLoc, Args, E->getEndLoc(), E->isListInitialization());
16313}
16314
16315template<typename Derived>
16318 // Transform any init-capture expressions before entering the scope of the
16319 // lambda body, because they are not semantically within that scope.
16320 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
16321 struct TransformedInitCapture {
16322 // The location of the ... if the result is retaining a pack expansion.
16323 SourceLocation EllipsisLoc;
16324 // Zero or more expansions of the init-capture.
16325 SmallVector<InitCaptureInfoTy, 4> Expansions;
16326 };
16328 InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin());
16329 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16330 CEnd = E->capture_end();
16331 C != CEnd; ++C) {
16332 if (!E->isInitCapture(C))
16333 continue;
16334
16335 TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()];
16336 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16337
16338 auto SubstInitCapture = [&](SourceLocation EllipsisLoc,
16339 UnsignedOrNone NumExpansions) {
16340 ExprResult NewExprInitResult = getDerived().TransformInitializer(
16341 OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit);
16342
16343 if (NewExprInitResult.isInvalid()) {
16344 Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType()));
16345 return;
16346 }
16347 Expr *NewExprInit = NewExprInitResult.get();
16348
16349 QualType NewInitCaptureType =
16350 getSema().buildLambdaInitCaptureInitialization(
16351 C->getLocation(), C->getCaptureKind() == LCK_ByRef,
16352 EllipsisLoc, NumExpansions, OldVD->getIdentifier(),
16353 cast<VarDecl>(C->getCapturedVar())->getInitStyle() !=
16355 NewExprInit);
16356 Result.Expansions.push_back(
16357 InitCaptureInfoTy(NewExprInit, NewInitCaptureType));
16358 };
16359
16360 // If this is an init-capture pack, consider expanding the pack now.
16361 if (OldVD->isParameterPack()) {
16362 PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo()
16363 ->getTypeLoc()
16366 SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded);
16367
16368 // Determine whether the set of unexpanded parameter packs can and should
16369 // be expanded.
16370 bool Expand = true;
16371 bool RetainExpansion = false;
16372 UnsignedOrNone OrigNumExpansions =
16373 ExpansionTL.getTypePtr()->getNumExpansions();
16374 UnsignedOrNone NumExpansions = OrigNumExpansions;
16375 if (getDerived().TryExpandParameterPacks(
16376 ExpansionTL.getEllipsisLoc(), OldVD->getInit()->getSourceRange(),
16377 Unexpanded, /*FailOnPackProducingTemplates=*/true, Expand,
16378 RetainExpansion, NumExpansions))
16379 return ExprError();
16380 assert(!RetainExpansion && "Should not need to retain expansion after a "
16381 "capture since it cannot be extended");
16382 if (Expand) {
16383 for (unsigned I = 0; I != *NumExpansions; ++I) {
16384 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16385 SubstInitCapture(SourceLocation(), std::nullopt);
16386 }
16387 } else {
16388 SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions);
16389 Result.EllipsisLoc = ExpansionTL.getEllipsisLoc();
16390 }
16391 } else {
16392 SubstInitCapture(SourceLocation(), std::nullopt);
16393 }
16394 }
16395
16396 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
16397 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
16398
16399 // Create the local class that will describe the lambda.
16400
16401 // FIXME: DependencyKind below is wrong when substituting inside a templated
16402 // context that isn't a DeclContext (such as a variable template), or when
16403 // substituting an unevaluated lambda inside of a function's parameter's type
16404 // - as parameter types are not instantiated from within a function's DC. We
16405 // use evaluation contexts to distinguish the function parameter case.
16408 DeclContext *DC = getSema().CurContext;
16409 // A RequiresExprBodyDecl is not interesting for dependencies.
16410 // For the following case,
16411 //
16412 // template <typename>
16413 // concept C = requires { [] {}; };
16414 //
16415 // template <class F>
16416 // struct Widget;
16417 //
16418 // template <C F>
16419 // struct Widget<F> {};
16420 //
16421 // While we are substituting Widget<F>, the parent of DC would be
16422 // the template specialization itself. Thus, the lambda expression
16423 // will be deemed as dependent even if there are no dependent template
16424 // arguments.
16425 // (A ClassTemplateSpecializationDecl is always a dependent context.)
16426 while (DC->isRequiresExprBody() || isa<CXXExpansionStmtDecl>(DC))
16427 DC = DC->getParent();
16428 if ((getSema().isUnevaluatedContext() ||
16429 getSema().isConstantEvaluatedContext()) &&
16430 !(dyn_cast_or_null<CXXRecordDecl>(DC->getParent()) &&
16431 cast<CXXRecordDecl>(DC->getParent())->isGenericLambda()) &&
16432 (DC->isFileContext() || !DC->getParent()->isDependentContext()))
16433 DependencyKind = CXXRecordDecl::LDK_NeverDependent;
16434
16435 CXXRecordDecl *OldClass = E->getLambdaClass();
16436 CXXRecordDecl *Class = getSema().createLambdaClosureType(
16437 E->getIntroducerRange(), /*Info=*/nullptr, DependencyKind,
16438 E->getCaptureDefault());
16439 getDerived().transformedLocalDecl(OldClass, {Class});
16440
16441 CXXMethodDecl *NewCallOperator =
16442 getSema().CreateLambdaCallOperator(E->getIntroducerRange(), Class);
16443
16444 // Enter the scope of the lambda.
16445 getSema().buildLambdaScope(LSI, NewCallOperator, E->getIntroducerRange(),
16446 E->getCaptureDefault(), E->getCaptureDefaultLoc(),
16447 E->hasExplicitParameters(), E->isMutable());
16448
16449 // Introduce the context of the call operator.
16450 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
16451 /*NewThisContext*/false);
16452
16453 bool Invalid = false;
16454
16455 // Transform captures.
16456 for (LambdaExpr::capture_iterator C = E->capture_begin(),
16457 CEnd = E->capture_end();
16458 C != CEnd; ++C) {
16459 // When we hit the first implicit capture, tell Sema that we've finished
16460 // the list of explicit captures.
16461 if (C->isImplicit())
16462 break;
16463
16464 // Capturing 'this' is trivial.
16465 if (C->capturesThis()) {
16466 // If this is a lambda that is part of a default member initialiser
16467 // and which we're instantiating outside the class that 'this' is
16468 // supposed to refer to, adjust the type of 'this' accordingly.
16469 //
16470 // Otherwise, leave the type of 'this' as-is.
16471 Sema::CXXThisScopeRAII ThisScope(
16472 getSema(),
16473 dyn_cast_if_present<CXXRecordDecl>(
16474 getSema().getFunctionLevelDeclContext()),
16475 Qualifiers());
16476 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16477 /*BuildAndDiagnose*/ true, nullptr,
16478 C->getCaptureKind() == LCK_StarThis);
16479 continue;
16480 }
16481 // Captured expression will be recaptured during captured variables
16482 // rebuilding.
16483 if (C->capturesVLAType())
16484 continue;
16485
16486 // Rebuild init-captures, including the implied field declaration.
16487 if (E->isInitCapture(C)) {
16488 TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()];
16489
16490 auto *OldVD = cast<VarDecl>(C->getCapturedVar());
16492
16493 for (InitCaptureInfoTy &Info : NewC.Expansions) {
16494 ExprResult Init = Info.first;
16495 QualType InitQualType = Info.second;
16496 if (Init.isInvalid() || InitQualType.isNull()) {
16497 Invalid = true;
16498 break;
16499 }
16500 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
16501 OldVD->getLocation(), InitQualType, NewC.EllipsisLoc,
16502 OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get(),
16503 getSema().CurContext);
16504 if (!NewVD) {
16505 Invalid = true;
16506 break;
16507 }
16508 NewVDs.push_back(NewVD);
16509 getSema().addInitCapture(LSI, NewVD, C->getCaptureKind() == LCK_ByRef);
16510 // Cases we want to tackle:
16511 // ([C(Pack)] {}, ...)
16512 // But rule out cases e.g.
16513 // [...C = Pack()] {}
16514 if (NewC.EllipsisLoc.isInvalid())
16515 LSI->ContainsUnexpandedParameterPack |=
16516 Init.get()->containsUnexpandedParameterPack();
16517 }
16518
16519 if (Invalid)
16520 break;
16521
16522 getDerived().transformedLocalDecl(OldVD, NewVDs);
16523 continue;
16524 }
16525
16526 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16527
16528 // Determine the capture kind for Sema.
16530 : C->getCaptureKind() == LCK_ByCopy
16533 SourceLocation EllipsisLoc;
16534 if (C->isPackExpansion()) {
16535 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
16536 bool ShouldExpand = false;
16537 bool RetainExpansion = false;
16538 UnsignedOrNone NumExpansions = std::nullopt;
16539 if (getDerived().TryExpandParameterPacks(
16540 C->getEllipsisLoc(), C->getLocation(), Unexpanded,
16541 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
16542 RetainExpansion, NumExpansions)) {
16543 Invalid = true;
16544 continue;
16545 }
16546
16547 if (ShouldExpand) {
16548 // The transform has determined that we should perform an expansion;
16549 // transform and capture each of the arguments.
16550 // expansion of the pattern. Do so.
16551 auto *Pack = cast<ValueDecl>(C->getCapturedVar());
16552 for (unsigned I = 0; I != *NumExpansions; ++I) {
16553 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
16554 ValueDecl *CapturedVar = cast_if_present<ValueDecl>(
16555 getDerived().TransformDecl(C->getLocation(), Pack));
16556 if (!CapturedVar) {
16557 Invalid = true;
16558 continue;
16559 }
16560
16561 // Capture the transformed variable.
16562 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
16563 }
16564
16565 // FIXME: Retain a pack expansion if RetainExpansion is true.
16566
16567 continue;
16568 }
16569
16570 EllipsisLoc = C->getEllipsisLoc();
16571 }
16572
16573 // Transform the captured variable.
16574 auto *CapturedVar = cast_or_null<ValueDecl>(
16575 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16576 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
16577 Invalid = true;
16578 continue;
16579 }
16580
16581 // This is not an init-capture; however it contains an unexpanded pack e.g.
16582 // ([Pack] {}(), ...)
16583 if (auto *VD = dyn_cast<VarDecl>(CapturedVar); VD && !C->isPackExpansion())
16584 LSI->ContainsUnexpandedParameterPack |= VD->isParameterPack();
16585
16586 // Capture the transformed variable.
16587 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
16588 EllipsisLoc);
16589 }
16590 getSema().finishLambdaExplicitCaptures(LSI);
16591
16592 // Transform the template parameters, and add them to the current
16593 // instantiation scope. The null case is handled correctly.
16594 auto TPL = getDerived().TransformTemplateParameterList(
16595 E->getTemplateParameterList());
16596 LSI->GLTemplateParameterList = TPL;
16597 if (TPL) {
16598 getSema().AddTemplateParametersToLambdaCallOperator(NewCallOperator, Class,
16599 TPL);
16600 LSI->ContainsUnexpandedParameterPack |=
16601 TPL->containsUnexpandedParameterPack();
16602 }
16603
16604 TypeLocBuilder NewCallOpTLBuilder;
16605 TypeLoc OldCallOpTypeLoc =
16606 E->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
16607 QualType NewCallOpType =
16608 getDerived().TransformType(NewCallOpTLBuilder, OldCallOpTypeLoc);
16609 if (NewCallOpType.isNull())
16610 return ExprError();
16611 LSI->ContainsUnexpandedParameterPack |=
16612 NewCallOpType->containsUnexpandedParameterPack();
16613 TypeSourceInfo *NewCallOpTSI =
16614 NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, NewCallOpType);
16615
16616 // The type may be an AttributedType or some other kind of sugar;
16617 // get the actual underlying FunctionProtoType.
16618 auto FPTL = NewCallOpTSI->getTypeLoc().getAsAdjusted<FunctionProtoTypeLoc>();
16619 assert(FPTL && "Not a FunctionProtoType?");
16620
16621 AssociatedConstraint TRC = E->getCallOperator()->getTrailingRequiresClause();
16622 if (TRC) {
16623 ExprResult E = getDerived().TransformLambdaConstraint(
16624 const_cast<Expr *>(TRC.ConstraintExpr));
16625 if (E.isInvalid())
16626 return E;
16627 TRC.ConstraintExpr = E.get();
16628 }
16629
16630 LSI->BeforeCompoundStatement = false;
16631 getSema().CompleteLambdaCallOperator(
16632 NewCallOperator, E->getCallOperator()->getLocation(),
16633 E->getCallOperator()->getInnerLocStart(), TRC, NewCallOpTSI,
16634 E->getCallOperator()->getConstexprKind(),
16635 E->getCallOperator()->getStorageClass(), FPTL.getParams(),
16636 E->hasExplicitResultType());
16637
16638 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
16639 getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator});
16640
16641 {
16642 // Number the lambda for linkage purposes if necessary.
16643 Sema::ContextRAII ManglingContext(getSema(), Class->getDeclContext());
16644
16645 std::optional<CXXRecordDecl::LambdaNumbering> Numbering;
16646 if (getDerived().ReplacingOriginal()) {
16647 Numbering = OldClass->getLambdaNumbering();
16648 }
16649
16650 getSema().handleLambdaNumbering(Class, NewCallOperator, Numbering);
16651 }
16652
16653 // FIXME: Sema's lambda-building mechanism expects us to push an expression
16654 // evaluation context even if we're not transforming the function body.
16655 getSema().PushExpressionEvaluationContextForFunction(
16657 E->getCallOperator());
16658
16659 StmtResult Body;
16660 {
16661 Sema::NonSFINAEContext _(getSema());
16664 C.PointOfInstantiation = E->getBody()->getBeginLoc();
16665 getSema().pushCodeSynthesisContext(C);
16666
16667 // Instantiate the body of the lambda expression.
16668 Body = Invalid ? StmtError()
16669 : getDerived().TransformLambdaBody(E, E->getBody());
16670
16671 getSema().popCodeSynthesisContext();
16672 }
16673
16674 // ActOnLambda* will pop the function scope for us.
16675 FuncScopeCleanup.disable();
16676
16677 if (Body.isInvalid()) {
16678 SavedContext.pop();
16679 getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr,
16680 /*IsInstantiation=*/true);
16681 return ExprError();
16682 }
16683
16684 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
16685 /*IsInstantiation=*/true,
16686 /*RetainFunctionScopeInfo=*/true);
16687 SavedContext.pop();
16688
16689 // Recompute the dependency of the lambda so that we can defer the lambda call
16690 // construction until after we have all the necessary template arguments. For
16691 // example, given
16692 //
16693 // template <class> struct S {
16694 // template <class U>
16695 // using Type = decltype([](U){}(42.0));
16696 // };
16697 // void foo() {
16698 // using T = S<int>::Type<float>;
16699 // ^~~~~~
16700 // }
16701 //
16702 // We would end up here from instantiating S<int> when ensuring its
16703 // completeness. That would transform the lambda call expression regardless of
16704 // the absence of the corresponding argument for U.
16705 //
16706 // Going ahead with unsubstituted type U makes things worse: we would soon
16707 // compare the argument type (which is float) against the parameter U
16708 // somewhere in Sema::BuildCallExpr. Then we would quickly run into a bogus
16709 // error suggesting unmatched types 'U' and 'float'!
16710 //
16711 // That said, everything will be fine if we defer that semantic checking.
16712 // Fortunately, we have such a mechanism that bypasses it if the CallExpr is
16713 // dependent. Since the CallExpr's dependency boils down to the lambda's
16714 // dependency in this case, we can harness that by recomputing the dependency
16715 // from the instantiation arguments.
16716 //
16717 // FIXME: Creating the type of a lambda requires us to have a dependency
16718 // value, which happens before its substitution. We update its dependency
16719 // *after* the substitution in case we can't decide the dependency
16720 // so early, e.g. because we want to see if any of the *substituted*
16721 // parameters are dependent.
16722 DependencyKind = getDerived().ComputeLambdaDependency(LSI);
16723 Class->setLambdaDependencyKind(DependencyKind);
16724
16725 return getDerived().RebuildLambdaExpr(E->getBeginLoc(),
16726 Body.get()->getEndLoc(), LSI);
16727}
16728
16729template<typename Derived>
16734
16735template<typename Derived>
16738 // Transform captures.
16740 CEnd = E->capture_end();
16741 C != CEnd; ++C) {
16742 // When we hit the first implicit capture, tell Sema that we've finished
16743 // the list of explicit captures.
16744 if (!C->isImplicit())
16745 continue;
16746
16747 // Capturing 'this' is trivial.
16748 if (C->capturesThis()) {
16749 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(),
16750 /*BuildAndDiagnose*/ true, nullptr,
16751 C->getCaptureKind() == LCK_StarThis);
16752 continue;
16753 }
16754 // Captured expression will be recaptured during captured variables
16755 // rebuilding.
16756 if (C->capturesVLAType())
16757 continue;
16758
16759 assert(C->capturesVariable() && "unexpected kind of lambda capture");
16760 assert(!E->isInitCapture(C) && "implicit init-capture?");
16761
16762 // Transform the captured variable.
16763 VarDecl *CapturedVar = cast_or_null<VarDecl>(
16764 getDerived().TransformDecl(C->getLocation(), C->getCapturedVar()));
16765 if (!CapturedVar || CapturedVar->isInvalidDecl())
16766 return StmtError();
16767
16768 // Capture the transformed variable.
16769 getSema().tryCaptureVariable(CapturedVar, C->getLocation());
16770 }
16771
16772 return S;
16773}
16774
16775template<typename Derived>
16779 TypeSourceInfo *T =
16780 getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo());
16781 if (!T)
16782 return ExprError();
16783
16784 bool ArgumentChanged = false;
16786 Args.reserve(E->getNumArgs());
16787 {
16791 if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args,
16792 &ArgumentChanged))
16793 return ExprError();
16794 }
16795
16796 if (!getDerived().AlwaysRebuild() &&
16797 T == E->getTypeSourceInfo() &&
16798 !ArgumentChanged)
16799 return E;
16800
16801 // FIXME: we're faking the locations of the commas
16802 return getDerived().RebuildCXXUnresolvedConstructExpr(
16803 T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization());
16804}
16805
16806template <typename Derived>
16809
16810 TemplateName Name = getDerived().TransformConceptTemplateName(
16811 E->getTemplateName(), E->getNameLoc());
16812 if (Name.isNull())
16813 return ExprError();
16814
16815 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16816 if (getDerived().TransformTemplateArguments(
16817 E->template_arguments().data(), E->getNumTemplateArgs(), TransArgs))
16818 return ExprError();
16819
16820 TemplateDecl *TD = Name.getAsTemplateDecl();
16821 if (!TD)
16822 return SemaRef.CheckVarOrConceptTemplateTemplateId(E->getNameInfo(), Name,
16823 &TransArgs);
16824
16825 CXXScopeSpec SS;
16826
16827 LookupResult R(SemaRef, E->getNameInfo(), Sema::LookupOrdinaryName);
16828 R.addDecl(TD);
16829 R.resolveKind();
16830 return getDerived().RebuildTemplateIdExpr(
16831 SS, /*Template Keyword=*/SourceLocation(), R,
16832 /*RequiresADL=*/false, &TransArgs);
16833}
16834
16835template<typename Derived>
16839 // Transform the base of the expression.
16840 ExprResult Base((Expr*) nullptr);
16841 Expr *OldBase;
16842 QualType BaseType;
16843 QualType ObjectType;
16844 if (!E->isImplicitAccess()) {
16845 OldBase = E->getBase();
16846 Base = getDerived().TransformExpr(OldBase);
16847 if (Base.isInvalid())
16848 return ExprError();
16849
16850 // Start the member reference and compute the object's type.
16851 ParsedType ObjectTy;
16852 bool MayBePseudoDestructor = false;
16853 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
16854 E->getOperatorLoc(),
16855 E->isArrow()? tok::arrow : tok::period,
16856 ObjectTy,
16857 MayBePseudoDestructor);
16858 if (Base.isInvalid())
16859 return ExprError();
16860
16861 ObjectType = ObjectTy.get();
16862 BaseType = ((Expr*) Base.get())->getType();
16863 } else {
16864 OldBase = nullptr;
16865 BaseType = getDerived().TransformType(E->getBaseType());
16866 ObjectType = BaseType->castAs<PointerType>()->getPointeeType();
16867 }
16868
16869 // Transform the first part of the nested-name-specifier that qualifies
16870 // the member name.
16871 NamedDecl *FirstQualifierInScope
16872 = getDerived().TransformFirstQualifierInScope(
16873 E->getFirstQualifierFoundInScope(),
16874 E->getQualifierLoc().getBeginLoc());
16875
16876 NestedNameSpecifierLoc QualifierLoc;
16877 if (E->getQualifier()) {
16878 QualifierLoc
16879 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
16880 ObjectType,
16881 FirstQualifierInScope);
16882 if (!QualifierLoc)
16883 return ExprError();
16884 }
16885
16886 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
16887
16888 // TODO: If this is a conversion-function-id, verify that the
16889 // destination type name (if present) resolves the same way after
16890 // instantiation as it did in the local scope.
16891
16892 DeclarationNameInfo NameInfo
16893 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
16894 if (!NameInfo.getName())
16895 return ExprError();
16896
16897 if (!E->hasExplicitTemplateArgs()) {
16898 // This is a reference to a member without an explicitly-specified
16899 // template argument list. Optimize for this common case.
16900 if (!getDerived().AlwaysRebuild() &&
16901 Base.get() == OldBase &&
16902 BaseType == E->getBaseType() &&
16903 QualifierLoc == E->getQualifierLoc() &&
16904 NameInfo.getName() == E->getMember() &&
16905 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
16906 return E;
16907
16908 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16909 BaseType,
16910 E->isArrow(),
16911 E->getOperatorLoc(),
16912 QualifierLoc,
16913 TemplateKWLoc,
16914 FirstQualifierInScope,
16915 NameInfo,
16916 /*TemplateArgs*/nullptr);
16917 }
16918
16919 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
16920 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
16921 E->getNumTemplateArgs(),
16922 TransArgs))
16923 return ExprError();
16924
16925 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
16926 BaseType,
16927 E->isArrow(),
16928 E->getOperatorLoc(),
16929 QualifierLoc,
16930 TemplateKWLoc,
16931 FirstQualifierInScope,
16932 NameInfo,
16933 &TransArgs);
16934}
16935
16936template <typename Derived>
16938 UnresolvedMemberExpr *Old) {
16939 // Transform the base of the expression.
16940 ExprResult Base((Expr *)nullptr);
16941 QualType BaseType;
16942 if (!Old->isImplicitAccess()) {
16943 Base = getDerived().TransformExpr(Old->getBase());
16944 if (Base.isInvalid())
16945 return ExprError();
16946 Base =
16947 getSema().PerformMemberExprBaseConversion(Base.get(), Old->isArrow());
16948 if (Base.isInvalid())
16949 return ExprError();
16950 BaseType = Base.get()->getType();
16951 } else {
16952 BaseType = getDerived().TransformType(Old->getBaseType());
16953 }
16954
16955 NestedNameSpecifierLoc QualifierLoc;
16956 if (Old->getQualifierLoc()) {
16957 QualifierLoc =
16958 getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
16959 if (!QualifierLoc)
16960 return ExprError();
16961 }
16962
16963 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
16964
16965 LookupResult R(SemaRef, Old->getMemberNameInfo(), Sema::LookupOrdinaryName);
16966
16967 // Transform the declaration set.
16968 if (TransformOverloadExprDecls(Old, /*RequiresADL*/ false, R))
16969 return ExprError();
16970
16971 // Determine the naming class.
16972 if (Old->getNamingClass()) {
16973 CXXRecordDecl *NamingClass = cast_or_null<CXXRecordDecl>(
16974 getDerived().TransformDecl(Old->getMemberLoc(), Old->getNamingClass()));
16975 if (!NamingClass)
16976 return ExprError();
16977
16978 R.setNamingClass(NamingClass);
16979 }
16980
16981 TemplateArgumentListInfo TransArgs;
16982 if (Old->hasExplicitTemplateArgs()) {
16983 TransArgs.setLAngleLoc(Old->getLAngleLoc());
16984 TransArgs.setRAngleLoc(Old->getRAngleLoc());
16985 if (getDerived().TransformTemplateArguments(
16986 Old->getTemplateArgs(), Old->getNumTemplateArgs(), TransArgs))
16987 return ExprError();
16988 }
16989
16990 // FIXME: to do this check properly, we will need to preserve the
16991 // first-qualifier-in-scope here, just in case we had a dependent
16992 // base (and therefore couldn't do the check) and a
16993 // nested-name-qualifier (and therefore could do the lookup).
16994 NamedDecl *FirstQualifierInScope = nullptr;
16995
16996 return getDerived().RebuildUnresolvedMemberExpr(
16997 Base.get(), BaseType, Old->getOperatorLoc(), Old->isArrow(), QualifierLoc,
16998 TemplateKWLoc, FirstQualifierInScope, R,
16999 (Old->hasExplicitTemplateArgs() ? &TransArgs : nullptr));
17000}
17001
17002template<typename Derived>
17007 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
17008 if (SubExpr.isInvalid())
17009 return ExprError();
17010
17011 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
17012 return E;
17013
17014 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
17015}
17016
17017template<typename Derived>
17020 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
17021 if (Pattern.isInvalid())
17022 return ExprError();
17023
17024 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
17025 return E;
17026
17027 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
17028 E->getNumExpansions());
17029}
17030
17031template <typename Derived>
17033 ArrayRef<TemplateArgument> PackArgs) {
17035 for (const TemplateArgument &Arg : PackArgs) {
17036 if (!Arg.isPackExpansion()) {
17037 Result = *Result + 1;
17038 continue;
17039 }
17040
17041 TemplateArgumentLoc ArgLoc;
17042 InventTemplateArgumentLoc(Arg, ArgLoc);
17043
17044 // Find the pattern of the pack expansion.
17045 SourceLocation Ellipsis;
17046 UnsignedOrNone OrigNumExpansions = std::nullopt;
17047 TemplateArgumentLoc Pattern =
17048 getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis,
17049 OrigNumExpansions);
17050
17051 // Substitute under the pack expansion. Do not expand the pack (yet).
17052 TemplateArgumentLoc OutPattern;
17053 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17054 if (getDerived().TransformTemplateArgument(Pattern, OutPattern,
17055 /*Uneval*/ true))
17056 return 1u;
17057
17058 // See if we can determine the number of arguments from the result.
17059 UnsignedOrNone NumExpansions =
17060 getSema().getFullyPackExpandedSize(OutPattern.getArgument());
17061 if (!NumExpansions) {
17062 // No: we must be in an alias template expansion, and we're going to
17063 // need to actually expand the packs.
17064 Result = std::nullopt;
17065 break;
17066 }
17067
17068 Result = *Result + *NumExpansions;
17069 }
17070 return Result;
17071}
17072
17073template<typename Derived>
17076 // If E is not value-dependent, then nothing will change when we transform it.
17077 // Note: This is an instantiation-centric view.
17078 if (!E->isValueDependent())
17079 return E;
17080
17083
17085 TemplateArgument ArgStorage;
17086
17087 // Find the argument list to transform.
17088 if (E->isPartiallySubstituted()) {
17089 PackArgs = E->getPartialArguments();
17090 } else if (E->isValueDependent()) {
17091 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
17092 bool ShouldExpand = false;
17093 bool RetainExpansion = false;
17094 UnsignedOrNone NumExpansions = std::nullopt;
17095 if (getDerived().TryExpandParameterPacks(
17096 E->getOperatorLoc(), E->getPackLoc(), Unexpanded,
17097 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
17098 RetainExpansion, NumExpansions))
17099 return ExprError();
17100
17101 // If we need to expand the pack, build a template argument from it and
17102 // expand that.
17103 if (ShouldExpand) {
17104 auto *Pack = E->getPack();
17105 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
17106 ArgStorage = getSema().Context.getPackExpansionType(
17107 getSema().Context.getTypeDeclType(TTPD), std::nullopt);
17108 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
17109 ArgStorage = TemplateArgument(TemplateName(TTPD), std::nullopt);
17110 } else {
17111 auto *VD = cast<ValueDecl>(Pack);
17112 ExprResult DRE = getSema().BuildDeclRefExpr(
17113 VD, VD->getType().getNonLValueExprType(getSema().Context),
17114 VD->getType()->isReferenceType() ? VK_LValue : VK_PRValue,
17115 E->getPackLoc());
17116 if (DRE.isInvalid())
17117 return ExprError();
17118 ArgStorage = TemplateArgument(
17119 new (getSema().Context)
17120 PackExpansionExpr(DRE.get(), E->getPackLoc(), std::nullopt),
17121 /*IsCanonical=*/false);
17122 }
17123 PackArgs = ArgStorage;
17124 }
17125 }
17126
17127 // If we're not expanding the pack, just transform the decl.
17128 if (!PackArgs.size()) {
17129 auto *Pack = cast_or_null<NamedDecl>(
17130 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
17131 if (!Pack)
17132 return ExprError();
17133 return getDerived().RebuildSizeOfPackExpr(
17134 E->getOperatorLoc(), Pack, E->getPackLoc(), E->getRParenLoc(),
17135 std::nullopt, {});
17136 }
17137
17138 // Try to compute the result without performing a partial substitution.
17140 getDerived().ComputeSizeOfPackExprWithoutSubstitution(PackArgs);
17141
17142 // Common case: we could determine the number of expansions without
17143 // substituting.
17144 if (Result)
17145 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
17146 E->getPackLoc(),
17147 E->getRParenLoc(), *Result, {});
17148
17149 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
17150 E->getPackLoc());
17151 {
17152 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
17154 Derived, const TemplateArgument*> PackLocIterator;
17155 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
17156 PackLocIterator(*this, PackArgs.end()),
17157 TransformedPackArgs, /*Uneval*/true))
17158 return ExprError();
17159 }
17160
17161 // Check whether we managed to fully-expand the pack.
17162 // FIXME: Is it possible for us to do so and not hit the early exit path?
17164 bool PartialSubstitution = false;
17165 for (auto &Loc : TransformedPackArgs.arguments()) {
17166 Args.push_back(Loc.getArgument());
17167 if (Loc.getArgument().isPackExpansion())
17168 PartialSubstitution = true;
17169 }
17170
17171 if (PartialSubstitution)
17172 return getDerived().RebuildSizeOfPackExpr(
17173 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
17174 std::nullopt, Args);
17175
17176 return getDerived().RebuildSizeOfPackExpr(
17177 E->getOperatorLoc(), E->getPack(), E->getPackLoc(), E->getRParenLoc(),
17178 /*Length=*/static_cast<unsigned>(Args.size()),
17179 /*PartialArgs=*/{});
17180}
17181
17182template <typename Derived>
17185 if (!E->isValueDependent())
17186 return E;
17187
17188 // Transform the index
17189 ExprResult IndexExpr;
17190 {
17191 EnterExpressionEvaluationContext ConstantContext(
17193 IndexExpr = getDerived().TransformExpr(E->getIndexExpr());
17194 if (IndexExpr.isInvalid())
17195 return ExprError();
17196 }
17197
17198 SmallVector<Expr *, 5> ExpandedExprs;
17199 bool FullySubstituted = true;
17200 if (!E->expandsToEmptyPack() && E->getExpressions().empty()) {
17201 Expr *Pattern = E->getPackIdExpression();
17203 getSema().collectUnexpandedParameterPacks(E->getPackIdExpression(),
17204 Unexpanded);
17205 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17206
17207 // Determine whether the set of unexpanded parameter packs can and should
17208 // be expanded.
17209 bool ShouldExpand = true;
17210 bool RetainExpansion = false;
17211 UnsignedOrNone OrigNumExpansions = std::nullopt,
17212 NumExpansions = std::nullopt;
17213 if (getDerived().TryExpandParameterPacks(
17214 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
17215 /*FailOnPackProducingTemplates=*/true, ShouldExpand,
17216 RetainExpansion, NumExpansions))
17217 return true;
17218 if (!ShouldExpand) {
17219 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17220 ExprResult Pack = getDerived().TransformExpr(Pattern);
17221 if (Pack.isInvalid())
17222 return ExprError();
17223 return getDerived().RebuildPackIndexingExpr(
17224 E->getEllipsisLoc(), E->getRSquareLoc(), Pack.get(), IndexExpr.get(),
17225 {}, /*FullySubstituted=*/false);
17226 }
17227 for (unsigned I = 0; I != *NumExpansions; ++I) {
17228 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
17229 ExprResult Out = getDerived().TransformExpr(Pattern);
17230 if (Out.isInvalid())
17231 return true;
17232 if (Out.get()->containsUnexpandedParameterPack()) {
17233 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
17234 OrigNumExpansions);
17235 if (Out.isInvalid())
17236 return true;
17237 FullySubstituted = false;
17238 }
17239 ExpandedExprs.push_back(Out.get());
17240 }
17241 // If we're supposed to retain a pack expansion, do so by temporarily
17242 // forgetting the partially-substituted parameter pack.
17243 if (RetainExpansion) {
17244 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17245
17246 ExprResult Out = getDerived().TransformExpr(Pattern);
17247 if (Out.isInvalid())
17248 return true;
17249
17250 Out = getDerived().RebuildPackExpansion(Out.get(), E->getEllipsisLoc(),
17251 OrigNumExpansions);
17252 if (Out.isInvalid())
17253 return true;
17254 FullySubstituted = false;
17255 ExpandedExprs.push_back(Out.get());
17256 }
17257 } else if (!E->expandsToEmptyPack()) {
17258 if (getDerived().TransformExprs(E->getExpressions().data(),
17259 E->getExpressions().size(), false,
17260 ExpandedExprs))
17261 return ExprError();
17262 }
17263
17264 return getDerived().RebuildPackIndexingExpr(
17265 E->getEllipsisLoc(), E->getRSquareLoc(), E->getPackIdExpression(),
17266 IndexExpr.get(), ExpandedExprs, FullySubstituted);
17267}
17268
17269template <typename Derived>
17272 if (!getSema().ArgPackSubstIndex)
17273 // We aren't expanding the parameter pack, so just return ourselves.
17274 return E;
17275
17276 TemplateArgument Pack = E->getArgumentPack();
17278 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
17279 E->getAssociatedDecl(), E->getParameterPack()->getPosition(),
17280 E->getParameterPack()->getType(), E->getParameterPackLocation(), Arg,
17281 SemaRef.getPackIndex(Pack), E->getFinal());
17282}
17283
17284template <typename Derived>
17287 Expr *OrigReplacement = E->getReplacement()->IgnoreImplicitAsWritten();
17288
17289 // Insert a constant-evaluated context for the transform.
17290 // Otherwise, when a normalized constraint places the replacement inside
17291 // an unevaluated operand (e.g. decltype), entities it refers to are not
17292 // odr-used, and the constant evaluation performed by CheckTemplateArgument
17293 // below can spuriously fail for otherwise valid replacements,
17294 // e.g. when a call materializes a function parameter of class type whose
17295 // special members were never instantiated.
17296 EnterExpressionEvaluationContext ConstantEvaluated(
17300
17301 ExprResult Replacement = getDerived().TransformExpr(OrigReplacement);
17302 if (Replacement.isInvalid())
17303 return true;
17304
17305 Decl *AssociatedDecl =
17306 getDerived().TransformDecl(E->getNameLoc(), E->getAssociatedDecl());
17307 if (!AssociatedDecl)
17308 return true;
17309
17310 QualType ParamType = TransformType(E->getParameterType());
17311 if (ParamType.isNull())
17312 return true;
17313
17314 if (Replacement.get() == OrigReplacement &&
17315 AssociatedDecl == E->getAssociatedDecl() &&
17316 ParamType == E->getParameterType())
17317 return E;
17318
17319 if (Replacement.get() != OrigReplacement ||
17320 ParamType != E->getParameterType()) {
17321 auto *Param = cast<NonTypeTemplateParmDecl>(std::get<0>(
17322 getReplacedTemplateParameter(AssociatedDecl, E->getIndex())));
17323 // When transforming the replacement expression previously, all Sema
17324 // specific annotations, such as implicit casts, are discarded. Calling the
17325 // corresponding sema action is necessary to recover those. Otherwise,
17326 // equivalency of the result would be lost.
17327 TemplateArgument SugaredConverted, CanonicalConverted;
17328 Replacement = SemaRef.CheckTemplateArgument(
17329 Param, ParamType, Replacement.get(), SugaredConverted,
17330 CanonicalConverted,
17331 /*StrictCheck=*/false, Sema::CTAK_Specified);
17332 if (Replacement.isInvalid())
17333 return true;
17334 } else {
17335 // Otherwise, the same expression would have been produced.
17336 Replacement = E->getReplacement();
17337 }
17338
17339 return getDerived().RebuildSubstNonTypeTemplateParmExpr(
17340 AssociatedDecl, E->getIndex(), ParamType, E->getNameLoc(),
17341 TemplateArgument(Replacement.get(), /*IsCanonical=*/false),
17342 E->getPackIndex(), E->getFinal());
17343}
17344
17345template<typename Derived>
17348 // Default behavior is to do nothing with this transformation.
17349 return E;
17350}
17351
17352template<typename Derived>
17356 return getDerived().TransformExpr(E->getSubExpr());
17357}
17358
17359template<typename Derived>
17362 UnresolvedLookupExpr *Callee = nullptr;
17363 if (Expr *OldCallee = E->getCallee()) {
17364 ExprResult CalleeResult = getDerived().TransformExpr(OldCallee);
17365 if (CalleeResult.isInvalid())
17366 return ExprError();
17367 Callee = cast<UnresolvedLookupExpr>(CalleeResult.get());
17368 }
17369
17370 Expr *Pattern = E->getPattern();
17371
17373 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
17374 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17375
17376 // Determine whether the set of unexpanded parameter packs can and should
17377 // be expanded.
17378 bool Expand = true;
17379 bool RetainExpansion = false;
17380 UnsignedOrNone OrigNumExpansions = E->getNumExpansions(),
17381 NumExpansions = OrigNumExpansions;
17382 if (getDerived().TryExpandParameterPacks(
17383 E->getEllipsisLoc(), Pattern->getSourceRange(), Unexpanded,
17384 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17385 NumExpansions))
17386 return true;
17387
17388 if (!Expand) {
17389 // Do not expand any packs here, just transform and rebuild a fold
17390 // expression.
17391 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17392
17393 ExprResult LHS =
17394 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
17395 if (LHS.isInvalid())
17396 return true;
17397
17398 ExprResult RHS =
17399 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
17400 if (RHS.isInvalid())
17401 return true;
17402
17403 if (!getDerived().AlwaysRebuild() &&
17404 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
17405 return E;
17406
17407 return getDerived().RebuildCXXFoldExpr(
17408 Callee, E->getBeginLoc(), LHS.get(), E->getOperator(),
17409 E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions);
17410 }
17411
17412 // Formally a fold expression expands to nested parenthesized expressions.
17413 // Enforce this limit to avoid creating trees so deep we can't safely traverse
17414 // them.
17415 if (NumExpansions && SemaRef.getLangOpts().BracketDepth < *NumExpansions) {
17416 SemaRef.Diag(E->getEllipsisLoc(),
17417 clang::diag::err_fold_expression_limit_exceeded)
17418 << *NumExpansions << SemaRef.getLangOpts().BracketDepth
17419 << E->getSourceRange();
17420 SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth);
17421 return ExprError();
17422 }
17423
17424 // The transform has determined that we should perform an elementwise
17425 // expansion of the pattern. Do so.
17426 ExprResult Result = getDerived().TransformExpr(E->getInit());
17427 if (Result.isInvalid())
17428 return true;
17429 bool LeftFold = E->isLeftFold();
17430
17431 // If we're retaining an expansion for a right fold, it is the innermost
17432 // component and takes the init (if any).
17433 if (!LeftFold && RetainExpansion) {
17434 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17435
17436 ExprResult Out = getDerived().TransformExpr(Pattern);
17437 if (Out.isInvalid())
17438 return true;
17439
17440 Result = getDerived().RebuildCXXFoldExpr(
17441 Callee, E->getBeginLoc(), Out.get(), E->getOperator(),
17442 E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions);
17443 if (Result.isInvalid())
17444 return true;
17445 }
17446
17447 bool WarnedOnComparison = false;
17448 for (unsigned I = 0; I != *NumExpansions; ++I) {
17449 Sema::ArgPackSubstIndexRAII SubstIndex(
17450 getSema(), LeftFold ? I : *NumExpansions - I - 1);
17451 ExprResult Out = getDerived().TransformExpr(Pattern);
17452 if (Out.isInvalid())
17453 return true;
17454
17455 if (Out.get()->containsUnexpandedParameterPack()) {
17456 // We still have a pack; retain a pack expansion for this slice.
17457 Result = getDerived().RebuildCXXFoldExpr(
17458 Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(),
17459 E->getOperator(), E->getEllipsisLoc(),
17460 LeftFold ? Out.get() : Result.get(), E->getEndLoc(),
17461 OrigNumExpansions);
17462 } else if (Result.isUsable()) {
17463 // We've got down to a single element; build a binary operator.
17464 Expr *LHS = LeftFold ? Result.get() : Out.get();
17465 Expr *RHS = LeftFold ? Out.get() : Result.get();
17466 if (Callee) {
17467 UnresolvedSet<16> Functions;
17468 Functions.append(Callee->decls_begin(), Callee->decls_end());
17469 Result = getDerived().RebuildCXXOperatorCallExpr(
17470 BinaryOperator::getOverloadedOperator(E->getOperator()),
17471 E->getEllipsisLoc(), Callee->getBeginLoc(), Callee->requiresADL(),
17472 Functions, LHS, RHS);
17473 } else {
17474 Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(),
17475 E->getOperator(), LHS, RHS,
17476 /*ForFoldExpresion=*/true);
17477 if (!WarnedOnComparison && Result.isUsable()) {
17478 if (auto *BO = dyn_cast<BinaryOperator>(Result.get());
17479 BO && BO->isComparisonOp()) {
17480 WarnedOnComparison = true;
17481 SemaRef.Diag(BO->getBeginLoc(),
17482 diag::warn_comparison_in_fold_expression)
17483 << BO->getOpcodeStr();
17484 }
17485 }
17486 }
17487 } else
17488 Result = Out;
17489
17490 if (Result.isInvalid())
17491 return true;
17492 }
17493
17494 // If we're retaining an expansion for a left fold, it is the outermost
17495 // component and takes the complete expansion so far as its init (if any).
17496 if (LeftFold && RetainExpansion) {
17497 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
17498
17499 ExprResult Out = getDerived().TransformExpr(Pattern);
17500 if (Out.isInvalid())
17501 return true;
17502
17503 Result = getDerived().RebuildCXXFoldExpr(
17504 Callee, E->getBeginLoc(), Result.get(), E->getOperator(),
17505 E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions);
17506 if (Result.isInvalid())
17507 return true;
17508 }
17509
17510 if (ParenExpr *PE = dyn_cast_or_null<ParenExpr>(Result.get()))
17511 PE->setIsProducedByFoldExpansion();
17512
17513 // If we had no init and an empty pack, and we're not retaining an expansion,
17514 // then produce a fallback value or error.
17515 if (Result.isUnset())
17516 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
17517 E->getOperator());
17518 return Result;
17519}
17520
17521template <typename Derived>
17524 SmallVector<Expr *, 4> TransformedInits;
17525 ArrayRef<Expr *> InitExprs = E->getInitExprs();
17526
17527 QualType T = getDerived().TransformType(E->getType());
17528
17529 bool ArgChanged = false;
17530
17531 if (getDerived().TransformExprs(InitExprs.data(), InitExprs.size(), true,
17532 TransformedInits, &ArgChanged))
17533 return ExprError();
17534
17535 if (!getDerived().AlwaysRebuild() && !ArgChanged && T == E->getType())
17536 return E;
17537
17538 return getDerived().RebuildCXXParenListInitExpr(
17539 TransformedInits, T, E->getUserSpecifiedInitExprs().size(),
17540 E->getInitLoc(), E->getBeginLoc(), E->getEndLoc());
17541}
17542
17543template<typename Derived>
17547 return getDerived().TransformExpr(E->getSubExpr());
17548}
17549
17550template<typename Derived>
17553 return SemaRef.MaybeBindToTemporary(E);
17554}
17555
17556template<typename Derived>
17559 return E;
17560}
17561
17562template<typename Derived>
17565 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
17566 if (SubExpr.isInvalid())
17567 return ExprError();
17568
17569 if (!getDerived().AlwaysRebuild() &&
17570 SubExpr.get() == E->getSubExpr())
17571 return E;
17572
17573 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
17574}
17575
17576template<typename Derived>
17579 // Transform each of the elements.
17580 SmallVector<Expr *, 8> Elements;
17581 bool ArgChanged = false;
17582 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
17583 /*IsCall=*/false, Elements, &ArgChanged))
17584 return ExprError();
17585
17586 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17587 return SemaRef.MaybeBindToTemporary(E);
17588
17589 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
17590 Elements.data(),
17591 Elements.size());
17592}
17593
17594template<typename Derived>
17598 // Transform each of the elements.
17600 bool ArgChanged = false;
17601 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
17602 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
17603
17604 if (OrigElement.isPackExpansion()) {
17605 // This key/value element is a pack expansion.
17607 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
17608 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
17609 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
17610
17611 // Determine whether the set of unexpanded parameter packs can
17612 // and should be expanded.
17613 bool Expand = true;
17614 bool RetainExpansion = false;
17615 UnsignedOrNone OrigNumExpansions = OrigElement.NumExpansions;
17616 UnsignedOrNone NumExpansions = OrigNumExpansions;
17617 SourceRange PatternRange(OrigElement.Key->getBeginLoc(),
17618 OrigElement.Value->getEndLoc());
17619 if (getDerived().TryExpandParameterPacks(
17620 OrigElement.EllipsisLoc, PatternRange, Unexpanded,
17621 /*FailOnPackProducingTemplates=*/true, Expand, RetainExpansion,
17622 NumExpansions))
17623 return ExprError();
17624
17625 if (!Expand) {
17626 // The transform has determined that we should perform a simple
17627 // transformation on the pack expansion, producing another pack
17628 // expansion.
17629 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), std::nullopt);
17630 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17631 if (Key.isInvalid())
17632 return ExprError();
17633
17634 if (Key.get() != OrigElement.Key)
17635 ArgChanged = true;
17636
17637 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17638 if (Value.isInvalid())
17639 return ExprError();
17640
17641 if (Value.get() != OrigElement.Value)
17642 ArgChanged = true;
17643
17644 ObjCDictionaryElement Expansion = {
17645 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
17646 };
17647 Elements.push_back(Expansion);
17648 continue;
17649 }
17650
17651 // Record right away that the argument was changed. This needs
17652 // to happen even if the array expands to nothing.
17653 ArgChanged = true;
17654
17655 // The transform has determined that we should perform an elementwise
17656 // expansion of the pattern. Do so.
17657 for (unsigned I = 0; I != *NumExpansions; ++I) {
17658 Sema::ArgPackSubstIndexRAII SubstIndex(getSema(), I);
17659 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17660 if (Key.isInvalid())
17661 return ExprError();
17662
17663 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
17664 if (Value.isInvalid())
17665 return ExprError();
17666
17667 ObjCDictionaryElement Element = {
17668 Key.get(), Value.get(), SourceLocation(), NumExpansions
17669 };
17670
17671 // If any unexpanded parameter packs remain, we still have a
17672 // pack expansion.
17673 // FIXME: Can this really happen?
17674 if (Key.get()->containsUnexpandedParameterPack() ||
17675 Value.get()->containsUnexpandedParameterPack())
17676 Element.EllipsisLoc = OrigElement.EllipsisLoc;
17677
17678 Elements.push_back(Element);
17679 }
17680
17681 // FIXME: Retain a pack expansion if RetainExpansion is true.
17682
17683 // We've finished with this pack expansion.
17684 continue;
17685 }
17686
17687 // Transform and check key.
17688 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
17689 if (Key.isInvalid())
17690 return ExprError();
17691
17692 if (Key.get() != OrigElement.Key)
17693 ArgChanged = true;
17694
17695 // Transform and check value.
17697 = getDerived().TransformExpr(OrigElement.Value);
17698 if (Value.isInvalid())
17699 return ExprError();
17700
17701 if (Value.get() != OrigElement.Value)
17702 ArgChanged = true;
17703
17704 ObjCDictionaryElement Element = {Key.get(), Value.get(), SourceLocation(),
17705 std::nullopt};
17706 Elements.push_back(Element);
17707 }
17708
17709 if (!getDerived().AlwaysRebuild() && !ArgChanged)
17710 return SemaRef.MaybeBindToTemporary(E);
17711
17712 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
17713 Elements);
17714}
17715
17716template<typename Derived>
17719 TypeSourceInfo *EncodedTypeInfo
17720 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
17721 if (!EncodedTypeInfo)
17722 return ExprError();
17723
17724 if (!getDerived().AlwaysRebuild() &&
17725 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
17726 return E;
17727
17728 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
17729 EncodedTypeInfo,
17730 E->getRParenLoc());
17731}
17732
17733template<typename Derived>
17736 // This is a kind of implicit conversion, and it needs to get dropped
17737 // and recomputed for the same general reasons that ImplicitCastExprs
17738 // do, as well a more specific one: this expression is only valid when
17739 // it appears *immediately* as an argument expression.
17740 return getDerived().TransformExpr(E->getSubExpr());
17741}
17742
17743template<typename Derived>
17746 TypeSourceInfo *TSInfo
17747 = getDerived().TransformType(E->getTypeInfoAsWritten());
17748 if (!TSInfo)
17749 return ExprError();
17750
17751 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
17752 if (Result.isInvalid())
17753 return ExprError();
17754
17755 if (!getDerived().AlwaysRebuild() &&
17756 TSInfo == E->getTypeInfoAsWritten() &&
17757 Result.get() == E->getSubExpr())
17758 return E;
17759
17760 return SemaRef.ObjC().BuildObjCBridgedCast(
17761 E->getLParenLoc(), E->getBridgeKind(), E->getBridgeKeywordLoc(), TSInfo,
17762 Result.get());
17763}
17764
17765template <typename Derived>
17768 return E;
17769}
17770
17771template<typename Derived>
17774 // Transform arguments.
17775 bool ArgChanged = false;
17777 Args.reserve(E->getNumArgs());
17778 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
17779 &ArgChanged))
17780 return ExprError();
17781
17782 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
17783 // Class message: transform the receiver type.
17784 TypeSourceInfo *ReceiverTypeInfo
17785 = getDerived().TransformType(E->getClassReceiverTypeInfo());
17786 if (!ReceiverTypeInfo)
17787 return ExprError();
17788
17789 // If nothing changed, just retain the existing message send.
17790 if (!getDerived().AlwaysRebuild() &&
17791 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
17792 return SemaRef.MaybeBindToTemporary(E);
17793
17794 // Build a new class message send.
17796 E->getSelectorLocs(SelLocs);
17797 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
17798 E->getSelector(),
17799 SelLocs,
17800 E->getMethodDecl(),
17801 E->getLeftLoc(),
17802 Args,
17803 E->getRightLoc());
17804 }
17805 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
17806 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
17807 if (!E->getMethodDecl())
17808 return ExprError();
17809
17810 // Build a new class message send to 'super'.
17812 E->getSelectorLocs(SelLocs);
17813 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
17814 E->getSelector(),
17815 SelLocs,
17816 E->getReceiverType(),
17817 E->getMethodDecl(),
17818 E->getLeftLoc(),
17819 Args,
17820 E->getRightLoc());
17821 }
17822
17823 // Instance message: transform the receiver
17824 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
17825 "Only class and instance messages may be instantiated");
17826 ExprResult Receiver
17827 = getDerived().TransformExpr(E->getInstanceReceiver());
17828 if (Receiver.isInvalid())
17829 return ExprError();
17830
17831 // If nothing changed, just retain the existing message send.
17832 if (!getDerived().AlwaysRebuild() &&
17833 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
17834 return SemaRef.MaybeBindToTemporary(E);
17835
17836 // Build a new instance message send.
17838 E->getSelectorLocs(SelLocs);
17839 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
17840 E->getSelector(),
17841 SelLocs,
17842 E->getMethodDecl(),
17843 E->getLeftLoc(),
17844 Args,
17845 E->getRightLoc());
17846}
17847
17848template<typename Derived>
17851 return E;
17852}
17853
17854template<typename Derived>
17857 return E;
17858}
17859
17860template<typename Derived>
17863 // Transform the base expression.
17864 ExprResult Base = getDerived().TransformExpr(E->getBase());
17865 if (Base.isInvalid())
17866 return ExprError();
17867
17868 // We don't need to transform the ivar; it will never change.
17869
17870 // If nothing changed, just retain the existing expression.
17871 if (!getDerived().AlwaysRebuild() &&
17872 Base.get() == E->getBase())
17873 return E;
17874
17875 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
17876 E->getLocation(),
17877 E->isArrow(), E->isFreeIvar());
17878}
17879
17880template<typename Derived>
17883 // 'super' and types never change. Property never changes. Just
17884 // retain the existing expression.
17885 if (!E->isObjectReceiver())
17886 return E;
17887
17888 // Transform the base expression.
17889 ExprResult Base = getDerived().TransformExpr(E->getBase());
17890 if (Base.isInvalid())
17891 return ExprError();
17892
17893 // We don't need to transform the property; it will never change.
17894
17895 // If nothing changed, just retain the existing expression.
17896 if (!getDerived().AlwaysRebuild() &&
17897 Base.get() == E->getBase())
17898 return E;
17899
17900 if (E->isExplicitProperty())
17901 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17902 E->getExplicitProperty(),
17903 E->getLocation());
17904
17905 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
17906 SemaRef.Context.PseudoObjectTy,
17907 E->getImplicitPropertyGetter(),
17908 E->getImplicitPropertySetter(),
17909 E->getLocation());
17910}
17911
17912template<typename Derived>
17915 // Transform the base expression.
17916 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
17917 if (Base.isInvalid())
17918 return ExprError();
17919
17920 // Transform the key expression.
17921 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
17922 if (Key.isInvalid())
17923 return ExprError();
17924
17925 // If nothing changed, just retain the existing expression.
17926 if (!getDerived().AlwaysRebuild() &&
17927 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
17928 return E;
17929
17930 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
17931 Base.get(), Key.get(),
17932 E->getAtIndexMethodDecl(),
17933 E->setAtIndexMethodDecl());
17934}
17935
17936template<typename Derived>
17939 // Transform the base expression.
17940 ExprResult Base = getDerived().TransformExpr(E->getBase());
17941 if (Base.isInvalid())
17942 return ExprError();
17943
17944 // If nothing changed, just retain the existing expression.
17945 if (!getDerived().AlwaysRebuild() &&
17946 Base.get() == E->getBase())
17947 return E;
17948
17949 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
17950 E->getOpLoc(),
17951 E->isArrow());
17952}
17953
17954template<typename Derived>
17957 bool ArgumentChanged = false;
17958 SmallVector<Expr*, 8> SubExprs;
17959 SubExprs.reserve(E->getNumSubExprs());
17960 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
17961 SubExprs, &ArgumentChanged))
17962 return ExprError();
17963
17964 if (!getDerived().AlwaysRebuild() &&
17965 !ArgumentChanged)
17966 return E;
17967
17968 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
17969 SubExprs,
17970 E->getRParenLoc());
17971}
17972
17973template<typename Derived>
17976 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
17977 if (SrcExpr.isInvalid())
17978 return ExprError();
17979
17980 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
17981 if (!Type)
17982 return ExprError();
17983
17984 if (!getDerived().AlwaysRebuild() &&
17985 Type == E->getTypeSourceInfo() &&
17986 SrcExpr.get() == E->getSrcExpr())
17987 return E;
17988
17989 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
17990 SrcExpr.get(), Type,
17991 E->getRParenLoc());
17992}
17993
17994template<typename Derived>
17997 BlockDecl *oldBlock = E->getBlockDecl();
17998
17999 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
18000 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
18001
18002 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
18003 blockScope->TheDecl->setBlockMissingReturnType(
18004 oldBlock->blockMissingReturnType());
18005
18007 SmallVector<QualType, 4> paramTypes;
18008
18009 const FunctionProtoType *exprFunctionType = E->getFunctionType();
18010
18011 // Parameter substitution.
18012 Sema::ExtParameterInfoBuilder extParamInfos;
18013 if (getDerived().TransformFunctionTypeParams(
18014 E->getCaretLocation(), oldBlock->parameters(), nullptr,
18015 exprFunctionType->getExtParameterInfosOrNull(), paramTypes, &params,
18016 extParamInfos)) {
18017 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
18018 return ExprError();
18019 }
18020
18021 QualType exprResultType =
18022 getDerived().TransformType(exprFunctionType->getReturnType());
18023
18024 auto epi = exprFunctionType->getExtProtoInfo();
18025 epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size());
18026
18028 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi);
18029 blockScope->FunctionType = functionType;
18030
18031 // Set the parameters on the block decl.
18032 if (!params.empty())
18033 blockScope->TheDecl->setParams(params);
18034
18035 if (!oldBlock->blockMissingReturnType()) {
18036 blockScope->HasImplicitReturnType = false;
18037 blockScope->ReturnType = exprResultType;
18038 }
18039
18040 // Transform the body
18041 StmtResult body = getDerived().TransformStmt(E->getBody());
18042 if (body.isInvalid()) {
18043 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
18044 return ExprError();
18045 }
18046
18047#ifndef NDEBUG
18048 // In builds with assertions, make sure that we captured everything we
18049 // captured before.
18050 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
18051 for (const auto &I : oldBlock->captures()) {
18052 VarDecl *oldCapture = I.getVariable();
18053
18054 // Ignore parameter packs.
18055 if (oldCapture->isParameterPack())
18056 continue;
18057
18058 VarDecl *newCapture =
18059 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
18060 oldCapture));
18061 assert(blockScope->CaptureMap.count(newCapture));
18062 }
18063 }
18064#endif
18065
18066 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
18067 /*Scope=*/nullptr);
18068}
18069
18070template<typename Derived>
18073 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
18074 if (SrcExpr.isInvalid())
18075 return ExprError();
18076
18077 QualType Type = getDerived().TransformType(E->getType());
18078
18079 return SemaRef.BuildAsTypeExpr(SrcExpr.get(), Type, E->getBuiltinLoc(),
18080 E->getRParenLoc());
18081}
18082
18083template<typename Derived>
18086 bool ArgumentChanged = false;
18087 SmallVector<Expr*, 8> SubExprs;
18088 SubExprs.reserve(E->getNumSubExprs());
18089 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
18090 SubExprs, &ArgumentChanged))
18091 return ExprError();
18092
18093 if (!getDerived().AlwaysRebuild() &&
18094 !ArgumentChanged)
18095 return E;
18096
18097 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
18098 E->getOp(), E->getRParenLoc());
18099}
18100
18101//===----------------------------------------------------------------------===//
18102// Type reconstruction
18103//===----------------------------------------------------------------------===//
18104
18105template<typename Derived>
18108 return SemaRef.BuildPointerType(PointeeType, Star,
18110}
18111
18112template<typename Derived>
18115 return SemaRef.BuildBlockPointerType(PointeeType, Star,
18117}
18118
18119template<typename Derived>
18122 bool WrittenAsLValue,
18123 SourceLocation Sigil) {
18124 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
18125 Sigil, getDerived().getBaseEntity());
18126}
18127
18128template <typename Derived>
18130 QualType PointeeType, const CXXScopeSpec &SS, CXXRecordDecl *Cls,
18131 SourceLocation Sigil) {
18132 return SemaRef.BuildMemberPointerType(PointeeType, SS, Cls, Sigil,
18134}
18135
18136template<typename Derived>
18138 const ObjCTypeParamDecl *Decl,
18139 SourceLocation ProtocolLAngleLoc,
18141 ArrayRef<SourceLocation> ProtocolLocs,
18142 SourceLocation ProtocolRAngleLoc) {
18143 return SemaRef.ObjC().BuildObjCTypeParamType(
18144 Decl, ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
18145 /*FailOnError=*/true);
18146}
18147
18148template<typename Derived>
18150 QualType BaseType,
18151 SourceLocation Loc,
18152 SourceLocation TypeArgsLAngleLoc,
18154 SourceLocation TypeArgsRAngleLoc,
18155 SourceLocation ProtocolLAngleLoc,
18157 ArrayRef<SourceLocation> ProtocolLocs,
18158 SourceLocation ProtocolRAngleLoc) {
18159 return SemaRef.ObjC().BuildObjCObjectType(
18160 BaseType, Loc, TypeArgsLAngleLoc, TypeArgs, TypeArgsRAngleLoc,
18161 ProtocolLAngleLoc, Protocols, ProtocolLocs, ProtocolRAngleLoc,
18162 /*FailOnError=*/true,
18163 /*Rebuilding=*/true);
18164}
18165
18166template<typename Derived>
18168 QualType PointeeType,
18170 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
18171}
18172
18173template <typename Derived>
18175 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt *Size,
18176 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
18177 if (SizeExpr || !Size)
18178 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
18179 IndexTypeQuals, BracketsRange,
18181
18182 QualType Types[] = {
18183 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
18184 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
18185 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
18186 };
18187 QualType SizeType;
18188 for (const auto &T : Types)
18189 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(T)) {
18190 SizeType = T;
18191 break;
18192 }
18193
18194 // Note that we can return a VariableArrayType here in the case where
18195 // the element type was a dependent VariableArrayType.
18196 IntegerLiteral *ArraySize
18197 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
18198 /*FIXME*/BracketsRange.getBegin());
18199 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
18200 IndexTypeQuals, BracketsRange,
18202}
18203
18204template <typename Derived>
18206 QualType ElementType, ArraySizeModifier SizeMod, const llvm::APInt &Size,
18207 Expr *SizeExpr, unsigned IndexTypeQuals, SourceRange BracketsRange) {
18208 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr,
18209 IndexTypeQuals, BracketsRange);
18210}
18211
18212template <typename Derived>
18214 QualType ElementType, ArraySizeModifier SizeMod, unsigned IndexTypeQuals,
18215 SourceRange BracketsRange) {
18216 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
18217 IndexTypeQuals, BracketsRange);
18218}
18219
18220template <typename Derived>
18222 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
18223 unsigned IndexTypeQuals, SourceRange BracketsRange) {
18224 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
18225 SizeExpr,
18226 IndexTypeQuals, BracketsRange);
18227}
18228
18229template <typename Derived>
18231 QualType ElementType, ArraySizeModifier SizeMod, Expr *SizeExpr,
18232 unsigned IndexTypeQuals, SourceRange BracketsRange) {
18233 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
18234 SizeExpr,
18235 IndexTypeQuals, BracketsRange);
18236}
18237
18238template <typename Derived>
18240 QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) {
18241 return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr,
18242 AttributeLoc);
18243}
18244
18245template <typename Derived>
18247 unsigned NumElements,
18248 VectorKind VecKind) {
18249 // FIXME: semantic checking!
18250 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
18251}
18252
18253template <typename Derived>
18255 QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc,
18256 VectorKind VecKind) {
18257 return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc);
18258}
18259
18260template<typename Derived>
18262 unsigned NumElements,
18263 SourceLocation AttributeLoc) {
18264 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
18265 NumElements, true);
18266 IntegerLiteral *VectorSize
18267 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
18268 AttributeLoc);
18269 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
18270}
18271
18272template<typename Derived>
18275 Expr *SizeExpr,
18276 SourceLocation AttributeLoc) {
18277 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
18278}
18279
18280template <typename Derived>
18282 QualType ElementType, unsigned NumRows, unsigned NumColumns,
18283 SourceLocation AttributeLoc) {
18284 ASTContext &Ctx = SemaRef.Context;
18285 QualType SizeTy = Ctx.getSizeType();
18286 unsigned SizeWidth = Ctx.getIntWidth(SizeTy);
18288 Ctx, llvm::APInt(SizeWidth, NumRows), SizeTy, AttributeLoc);
18290 Ctx, llvm::APInt(SizeWidth, NumColumns), SizeTy, AttributeLoc);
18291 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
18292 AttributeLoc);
18293}
18294
18295template <typename Derived>
18297 QualType ElementType, Expr *RowExpr, Expr *ColumnExpr,
18298 SourceLocation AttributeLoc) {
18299 return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr,
18300 AttributeLoc);
18301}
18302
18303template <typename Derived>
18307 return SemaRef.BuildFunctionType(T, ParamTypes,
18310 EPI);
18311}
18312
18313template<typename Derived>
18315 return SemaRef.Context.getFunctionNoProtoType(T);
18316}
18317
18318template <typename Derived>
18321 SourceLocation NameLoc, Decl *D) {
18322 assert(D && "no decl found");
18323 if (D->isInvalidDecl()) return QualType();
18324
18325 // FIXME: Doesn't account for ObjCInterfaceDecl!
18326 if (auto *UPD = dyn_cast<UsingPackDecl>(D)) {
18327 // A valid resolved using typename pack expansion decl can have multiple
18328 // UsingDecls, but they must each have exactly one type, and it must be
18329 // the same type in every case. But we must have at least one expansion!
18330 if (UPD->expansions().empty()) {
18331 getSema().Diag(NameLoc, diag::err_using_pack_expansion_empty)
18332 << UPD->isCXXClassMember() << UPD;
18333 return QualType();
18334 }
18335
18336 // We might still have some unresolved types. Try to pick a resolved type
18337 // if we can. The final instantiation will check that the remaining
18338 // unresolved types instantiate to the type we pick.
18339 QualType FallbackT;
18340 QualType T;
18341 for (auto *E : UPD->expansions()) {
18342 QualType ThisT =
18343 RebuildUnresolvedUsingType(Keyword, Qualifier, NameLoc, E);
18344 if (ThisT.isNull())
18345 continue;
18346 if (ThisT->getAs<UnresolvedUsingType>())
18347 FallbackT = ThisT;
18348 else if (T.isNull())
18349 T = ThisT;
18350 else
18351 assert(getSema().Context.hasSameType(ThisT, T) &&
18352 "mismatched resolved types in using pack expansion");
18353 }
18354 return T.isNull() ? FallbackT : T;
18355 }
18356 if (auto *Using = dyn_cast<UsingDecl>(D)) {
18357 assert(Using->hasTypename() &&
18358 "UnresolvedUsingTypenameDecl transformed to non-typename using");
18359
18360 // A valid resolved using typename decl points to exactly one type decl.
18361 assert(++Using->shadow_begin() == Using->shadow_end());
18362
18363 UsingShadowDecl *Shadow = *Using->shadow_begin();
18364 if (SemaRef.DiagnoseUseOfDecl(Shadow->getTargetDecl(), NameLoc))
18365 return QualType();
18366 return SemaRef.Context.getUsingType(Keyword, Qualifier, Shadow);
18367 }
18369 "UnresolvedUsingTypenameDecl transformed to non-using decl");
18370 return SemaRef.Context.getUnresolvedUsingType(
18372}
18373
18374template <typename Derived>
18376 TypeOfKind Kind) {
18377 return SemaRef.BuildTypeofExprType(E, Kind);
18378}
18379
18380template<typename Derived>
18382 TypeOfKind Kind) {
18383 return SemaRef.Context.getTypeOfType(Underlying, Kind);
18384}
18385
18386template <typename Derived>
18388 return SemaRef.BuildDecltypeType(E);
18389}
18390
18391template <typename Derived>
18393 QualType Pattern, Expr *IndexExpr, SourceLocation Loc,
18394 bool FullySubstituted, ArrayRef<QualType> Expansions) {
18395 return SemaRef.BuildPackIndexingType(Pattern, IndexExpr, Loc,
18396 FullySubstituted, Expansions);
18397}
18398
18399template<typename Derived>
18401 UnaryTransformType::UTTKind UKind,
18402 SourceLocation Loc) {
18403 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
18404}
18405
18406template <typename Derived>
18409 SourceLocation TemplateNameLoc, TemplateArgumentListInfo &TemplateArgs) {
18410 return SemaRef.CheckTemplateIdType(
18411 Keyword, Template, TemplateNameLoc, TemplateArgs,
18412 /*Scope=*/nullptr, /*ForNestedNameSpecifier=*/false);
18413}
18414
18415template<typename Derived>
18417 SourceLocation KWLoc) {
18418 return SemaRef.BuildAtomicType(ValueType, KWLoc);
18419}
18420
18421template<typename Derived>
18423 SourceLocation KWLoc,
18424 bool isReadPipe) {
18425 return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc)
18426 : SemaRef.BuildWritePipeType(ValueType, KWLoc);
18427}
18428
18429template <typename Derived>
18431 unsigned NumBits,
18432 SourceLocation Loc) {
18433 llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
18434 NumBits, true);
18435 IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP,
18436 SemaRef.Context.IntTy, Loc);
18437 return SemaRef.BuildBitIntType(IsUnsigned, Bits, Loc);
18438}
18439
18440template <typename Derived>
18442 bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) {
18443 return SemaRef.BuildBitIntType(IsUnsigned, NumBitsExpr, Loc);
18444}
18445
18446template <typename Derived>
18448 bool TemplateKW,
18449 TemplateName Name) {
18450 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
18451 Name);
18452}
18453
18454template <typename Derived>
18456 CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const IdentifierInfo &Name,
18457 SourceLocation NameLoc, QualType ObjectType, bool AllowInjectedClassName) {
18459 TemplateName.setIdentifier(&Name, NameLoc);
18461 getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc,
18462 TemplateName, ParsedType::make(ObjectType),
18463 /*EnteringContext=*/false, Template,
18464 AllowInjectedClassName);
18465 return Template.get();
18466}
18467
18468template<typename Derived>
18471 SourceLocation TemplateKWLoc,
18472 OverloadedOperatorKind Operator,
18473 SourceLocation NameLoc,
18474 QualType ObjectType,
18475 bool AllowInjectedClassName) {
18476 UnqualifiedId Name;
18477 // FIXME: Bogus location information.
18478 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
18479 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
18481 getSema().ActOnTemplateName(
18482 /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType),
18483 /*EnteringContext=*/false, Template, AllowInjectedClassName);
18484 return Template.get();
18485}
18486
18487template <typename Derived>
18490 bool RequiresADL, const UnresolvedSetImpl &Functions, Expr *First,
18491 Expr *Second) {
18492 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
18493
18494 if (First->getObjectKind() == OK_ObjCProperty) {
18497 return SemaRef.PseudoObject().checkAssignment(/*Scope=*/nullptr, OpLoc,
18498 Opc, First, Second);
18499 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
18500 if (Result.isInvalid())
18501 return ExprError();
18502 First = Result.get();
18503 }
18504
18505 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
18506 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
18507 if (Result.isInvalid())
18508 return ExprError();
18509 Second = Result.get();
18510 }
18511
18512 // Determine whether this should be a builtin operation.
18513 if (Op == OO_Subscript) {
18514 if (!First->getType()->isOverloadableType() &&
18515 !Second->getType()->isOverloadableType())
18516 return getSema().CreateBuiltinArraySubscriptExpr(First, CalleeLoc, Second,
18517 OpLoc);
18518 } else if (Op == OO_Arrow) {
18519 // It is possible that the type refers to a RecoveryExpr created earlier
18520 // in the tree transformation.
18521 if (First->getType()->isDependentType())
18522 return ExprError();
18523 // -> is never a builtin operation.
18524 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
18525 } else if (Second == nullptr || isPostIncDec) {
18526 if (!First->getType()->isOverloadableType() ||
18527 (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) {
18528 // The argument is not of overloadable type, or this is an expression
18529 // of the form &Class::member, so try to create a built-in unary
18530 // operation.
18532 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18533
18534 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
18535 }
18536 } else {
18537 if (!First->isTypeDependent() && !Second->isTypeDependent() &&
18538 !First->getType()->isOverloadableType() &&
18539 !Second->getType()->isOverloadableType()) {
18540 // Neither of the arguments is type-dependent or has an overloadable
18541 // type, so try to create a built-in binary operation.
18544 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
18545 if (Result.isInvalid())
18546 return ExprError();
18547
18548 return Result;
18549 }
18550 }
18551
18552 // Create the overloaded operator invocation for unary operators.
18553 if (!Second || isPostIncDec) {
18555 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
18556 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First,
18557 RequiresADL);
18558 }
18559
18560 // Create the overloaded operator invocation for binary operators.
18562 ExprResult Result = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions,
18563 First, Second, RequiresADL);
18564 if (Result.isInvalid())
18565 return ExprError();
18566
18567 return Result;
18568}
18569
18570template<typename Derived>
18573 SourceLocation OperatorLoc,
18574 bool isArrow,
18575 CXXScopeSpec &SS,
18576 TypeSourceInfo *ScopeType,
18577 SourceLocation CCLoc,
18578 SourceLocation TildeLoc,
18579 PseudoDestructorTypeStorage Destroyed) {
18580 QualType CanonicalBaseType = Base->getType().getCanonicalType();
18581 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
18582 (!isArrow && !isa<RecordType>(CanonicalBaseType)) ||
18583 (isArrow && isa<PointerType>(CanonicalBaseType) &&
18584 !cast<PointerType>(CanonicalBaseType)
18585 ->getPointeeType()
18586 ->getAsCanonical<RecordType>())) {
18587 // This pseudo-destructor expression is still a pseudo-destructor.
18588 return SemaRef.BuildPseudoDestructorExpr(
18589 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
18590 CCLoc, TildeLoc, Destroyed);
18591 }
18592
18593 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
18594 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
18595 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
18596 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
18597 NameInfo.setNamedTypeInfo(DestroyedType);
18598
18599 // The scope type is now known to be a valid nested name specifier
18600 // component. Tack it on to the nested name specifier.
18601 if (ScopeType) {
18602 if (!isa<TagType>(ScopeType->getType().getCanonicalType())) {
18603 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
18604 diag::err_expected_class_or_namespace)
18605 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
18606 return ExprError();
18607 }
18608 SS.clear();
18609 SS.Make(SemaRef.Context, ScopeType->getTypeLoc(), CCLoc);
18610 }
18611
18612 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
18613 return getSema().BuildMemberReferenceExpr(
18614 Base, Base->getType(), OperatorLoc, isArrow, SS, TemplateKWLoc,
18615 /*FIXME: FirstQualifier*/ nullptr, NameInfo,
18616 /*TemplateArgs*/ nullptr,
18617 /*S*/ nullptr);
18618}
18619
18620template<typename Derived>
18623 SourceLocation Loc = S->getBeginLoc();
18624 CapturedDecl *CD = S->getCapturedDecl();
18625 unsigned NumParams = CD->getNumParams();
18626 unsigned ContextParamPos = CD->getContextParamPosition();
18628 for (unsigned I = 0; I < NumParams; ++I) {
18629 if (I != ContextParamPos) {
18630 Params.push_back(
18631 std::make_pair(
18632 CD->getParam(I)->getName(),
18633 getDerived().TransformType(CD->getParam(I)->getType())));
18634 } else {
18635 Params.push_back(std::make_pair(StringRef(), QualType()));
18636 }
18637 }
18638 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
18639 S->getCapturedRegionKind(), Params);
18640 StmtResult Body;
18641 {
18642 Sema::CompoundScopeRAII CompoundScope(getSema());
18643 Body = getDerived().TransformStmt(S->getCapturedStmt());
18644 }
18645
18646 if (Body.isInvalid()) {
18647 getSema().ActOnCapturedRegionError();
18648 return StmtError();
18649 }
18650
18651 return getSema().ActOnCapturedRegionEnd(Body.get());
18652}
18653
18654template <typename Derived>
18657 // SYCLKernelCallStmt nodes are inserted upon completion of a (non-template)
18658 // function definition or instantiation of a function template specialization
18659 // and will therefore never appear in a dependent context.
18660 llvm_unreachable("SYCL kernel call statement cannot appear in dependent "
18661 "context");
18662}
18663
18664template <typename Derived>
18666 // We can transform the base expression and allow argument resolution to fill
18667 // in the rest.
18668 return getDerived().TransformExpr(E->getArgLValue());
18669}
18670
18671} // end namespace clang
18672
18673#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
#define V(N, I)
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)
DeclarationNameInfo getDirectiveName() const
Return name of the directive.
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.
bool hasImplicitOtherwise() const
ArrayRef< OMPTraitInfo * > traitInfos() const
ArrayRef< Stmt * > variants() const
bool anyScoreOrCondition(llvm::function_ref< bool(Expr *&, bool)> Cond)
The result of a constraint satisfaction check, containing the necessary information to diagnose an un...
Definition ASTConcept.h:75
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:245
unsigned getIntWidth(QualType T) const
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 getLateParsedAttrType(QualType Wrapped, LateParsedTypeAttribute *LateParsedAttr) const
Return a placeholder type for a late-parsed type attribute.
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>.
DeclarationNameInfo getNameForTemplate(TemplateName Name, SourceLocation NameLoc) const
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)
QualType getMatrixTypeWithLayout(QualType T, MatrixType::LayoutKind Layout) const
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:4619
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition Expr.h:6107
Represents a loop initializing the elements of an array.
Definition Expr.h:6054
Wrapper for source info for array parameter types.
Definition TypeLoc.h:1864
This class represents BOTH the OpenMP Array Section and OpenACC 'subarray', with a boolean differenti...
Definition Expr.h:7305
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition Expr.h:2790
Wrapper for source info for arrays.
Definition TypeLoc.h:1808
void setLBracketLoc(SourceLocation Loc)
Definition TypeLoc.h:1814
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition ExprCXX.h:3011
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:3049
ArrayTypeTrait getTrait() const
Definition ExprCXX.h:3051
Expr * getDimensionExpression() const
Definition ExprCXX.h:3061
TypeSourceInfo * getQueriedTypeSourceInfo() const
Definition ExprCXX.h:3057
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:3048
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3820
AsTypeExpr - Clang builtin function __builtin_astype [OpenCL 6.2.4.2] This AST node provides support ...
Definition Expr.h:6819
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition Expr.h:7014
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2704
Attr - This represents one attribute.
Definition Attr.h:47
Represents an attribute applied to a statement.
Definition Stmt.h:2214
Stmt * getSubStmt()
Definition Stmt.h:2250
SourceLocation getAttrLoc() const
Definition Stmt.h:2245
ArrayRef< const Attr * > getAttrs() const
Definition Stmt.h:2246
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:4522
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:4107
static OverloadedOperatorKind getOverloadedOperator(Opcode Opc)
Retrieve the overloaded operator kind that corresponds to the given binary opcode.
Definition Expr.cpp:2217
static bool isAssignmentOp(Opcode Opc)
Definition Expr.h:4243
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO)
Retrieve the binary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:2179
A fixed int type of a specified bitwidth.
Definition TypeBase.h:8436
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition Decl.h:4858
void setIsVariadic(bool value)
Definition Decl.h:4934
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
Definition Expr.h:6758
Wrapper for source info for block pointers.
Definition TypeLoc.h:1557
BreakStmt - This represents a break.
Definition Stmt.h:3148
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition ExprCXX.h:5530
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.h:5549
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.h:5548
CStyleCastExpr - An explicit cast in C (C99 6.5.4) or a C-style cast in C++ (C++ [expr....
Definition Expr.h:4038
Represents a call to a CUDA kernel function.
Definition ExprCXX.h:239
A C++ addrspace_cast expression (currently only enabled for OpenCL).
Definition ExprCXX.h:609
Represents binding an expression to a temporary.
Definition ExprCXX.h:1498
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition ExprCXX.h:728
CXXCatchStmt - This represents a C++ catch block.
Definition StmtCXX.h:29
A C++ const_cast expression (C++ [expr.const.cast]).
Definition ExprCXX.h:571
Represents a call to a C++ constructor.
Definition ExprCXX.h:1553
SourceRange getParenOrBraceRange() const
Definition ExprCXX.h:1734
Expr * getArg(unsigned Arg)
Return the specified argument.
Definition ExprCXX.h:1696
bool isStdInitListInitialization() const
Whether this constructor call was written as list-initialization, but was interpreted as forming a st...
Definition ExprCXX.h:1646
SourceLocation getEndLoc() const LLVM_READONLY
Definition ExprCXX.cpp:611
SourceLocation getBeginLoc() const LLVM_READONLY
Definition ExprCXX.cpp:605
bool isListInitialization() const
Whether this constructor call was written as list-initialization.
Definition ExprCXX.h:1635
unsigned getNumArgs() const
Return the number of arguments to the constructor call.
Definition ExprCXX.h:1693
Represents a C++ constructor within a class.
Definition DeclCXX.h:2645
A default argument (C++ [dcl.fct.default]).
Definition ExprCXX.h:1275
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition ExprCXX.cpp:1071
A use of a default initializer in a constructor or in aggregate initialization.
Definition ExprCXX.h:1382
static CXXDefaultInitExpr * Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field, DeclContext *UsedContext, Expr *RewrittenInitExpr)
Field is the non-static data member whose default initializer is used by this expression.
Definition ExprCXX.cpp:1125
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition ExprCXX.h:2631
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition ExprCXX.h:3924
Represents a C++ destructor within a class.
Definition DeclCXX.h:2924
A C++ dynamic_cast expression (C++ [expr.dynamic.cast]).
Definition ExprCXX.h:486
Helper that selects an expression from an InitListExpr depending on the current expansion index.
Definition ExprCXX.h:5622
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:5086
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:1836
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition ExprCXX.h:1756
Represents a call to a member function that may be written either with member call syntax (e....
Definition ExprCXX.h:184
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2153
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition ExprCXX.h:380
SourceLocation getOperatorLoc() const
Retrieve the location of the cast operator keyword, e.g., static_cast.
Definition ExprCXX.h:411
SourceRange getAngleBrackets() const LLVM_READONLY
Definition ExprCXX.h:418
SourceLocation getRParenLoc() const
Retrieve the location of the closing parenthesis.
Definition ExprCXX.h:414
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition ExprCXX.h:2360
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition ExprCXX.h:4363
The null pointer literal (C++11 [lex.nullptr])
Definition ExprCXX.h:773
A call to an overloaded operator written using operator syntax.
Definition ExprCXX.h:86
Represents a list-initialization with parenthesis.
Definition ExprCXX.h:5195
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition ExprCXX.h:2750
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
unsigned getLambdaDependencyKind() const
Definition DeclCXX.h:1879
Represents a C++26 reflect expression [expr.reflect].
Definition ExprCXX.h:5562
A C++ reinterpret_cast expression (C++ [expr.reinterpret.cast]).
Definition ExprCXX.h:531
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:291
An expression "T()" which creates an rvalue of a non-class type T.
Definition ExprCXX.h:2201
Represents a C++ nested-name-specifier or a global scope specifier.
Definition DeclSpec.h:77
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:210
SourceRange getRange() const
Definition DeclSpec.h:83
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:98
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:214
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:182
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:805
Represents a C++ functional cast expression that builds a temporary object.
Definition ExprCXX.h:1904
Represents the this expression in C++.
Definition ExprCXX.h:1159
A C++ throw-expression (C++ [except.throw]).
Definition ExprCXX.h:1213
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:853
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition ExprCXX.h:3798
SourceLocation getLParenLoc() const
Retrieve the location of the left parentheses ('(') that precedes the argument list.
Definition ExprCXX.h:3842
bool isListInitialization() const
Determine whether this expression models list-initialization.
Definition ExprCXX.h:3853
TypeSourceInfo * getTypeSourceInfo() const
Retrieve the type source information for the type being constructed.
Definition ExprCXX.h:3836
SourceLocation getRParenLoc() const
Retrieve the location of the right parentheses (')') that follows the argument list.
Definition ExprCXX.h:3847
unsigned getNumArgs() const
Retrieve the number of arguments.
Definition ExprCXX.h:3856
A Microsoft C++ __uuidof expression, which gets the _GUID that corresponds to the supplied type or ex...
Definition ExprCXX.h:1073
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:3012
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:1549
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition Decl.h:5130
unsigned getNumParams() const
Definition Decl.h:5168
unsigned getContextParamPosition() const
Definition Decl.h:5197
ImplicitParamDecl * getParam(unsigned i) const
Definition Decl.h:5170
This captures a statement into a function.
Definition Stmt.h:3950
CapturedDecl * getCapturedDecl()
Retrieve the outlined function declaration.
Definition Stmt.cpp:1493
Stmt * getCapturedStmt()
Retrieve the statement being captured.
Definition Stmt.h:4054
SourceLocation getBeginLoc() const LLVM_READONLY
Definition Stmt.h:4145
CapturedRegionKind getCapturedRegionKind() const
Retrieve the captured region kind.
Definition Stmt.cpp:1508
CaseStmt - Represent a case statement.
Definition Stmt.h:1931
Expr * getSubExprAsWritten()
Retrieve the cast subexpression as it was written in the source code, looking through any implicit ca...
Definition Expr.cpp:2016
Expr * getSubExpr()
Definition Expr.h:3795
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition Expr.h:4917
Represents a 'co_await' expression.
Definition ExprCXX.h:5423
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4369
CompoundLiteralExpr - [C99 6.5.2.5].
Definition Expr.h:3674
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition Stmt.h:1751
FPOptionsOverride getStoredFPFeatures() const
Get FPOptionsOverride from trailing storage.
Definition Stmt.h:1801
body_range body()
Definition Stmt.h:1814
SourceLocation getLBracLoc() const
Definition Stmt.h:1868
bool hasStoredFPFeatures() const
Definition Stmt.h:1798
Stmt * body_back()
Definition Stmt.h:1819
SourceLocation getRBracLoc() const
Definition Stmt.h:1869
Declaration of a C++20 concept.
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, TemplateName 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:4460
Represents the canonical version of C arrays with a specified constant size.
Definition TypeBase.h:3858
An expression that occurs in a constant context and the result of evaluating the expression.
Definition Expr.h:1127
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4622
ContinueStmt - This represents a continue.
Definition Stmt.h:3132
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition Expr.h:4788
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:3509
Represents a 'co_yield' expression.
Definition ExprCXX.h:5504
Wrapper for source info for pointers decayed from arrays and functions.
Definition TypeLoc.h:1505
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:1467
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition DeclBase.h:2108
DeclContextLookupResult lookup_result
Definition DeclBase.h:2609
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:2217
A reference to a declared variable, function, enum, etc.
Definition Expr.h:1315
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition Stmt.h:1642
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool isInvalidDecl() const
Definition DeclBase.h:597
SourceLocation getLocation() const
Definition DeclBase.h:448
DeclContext * getDeclContext()
Definition DeclBase.h:457
AccessSpecifier getAccess() const
Definition DeclBase.h:516
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:824
TypeSourceInfo * getTypeSourceInfo() const
Definition Decl.h:811
Information about one declarator, including the parsed type information and the identifier.
Definition DeclSpec.h:1996
void setDecltypeLoc(SourceLocation Loc)
Definition TypeLoc.h:2319
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2544
DeferStmt - This represents a deferred statement.
Definition Stmt.h:3249
static DeferStmt * Create(ASTContext &Context, SourceLocation DeferLoc, Stmt *Body)
Definition Stmt.cpp:1552
void setAttrOperandParensRange(SourceRange range)
Definition TypeLoc.h:2029
Represents an extended address space qualifier where the input address space value is dependent.
Definition TypeBase.h:4159
Represents a 'co_await' expression while the type of the promise is dependent.
Definition ExprCXX.h:5455
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition TypeLoc.h:2612
A qualified reference to a name whose declaration cannot yet be resolved.
Definition ExprCXX.h:3564
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3638
NestedNameSpecifierLoc getQualifierLoc() const
Retrieve the nested-name-specifier that qualifies the name, with source location information.
Definition ExprCXX.h:3612
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3630
bool hasExplicitTemplateArgs() const
Determines whether this lookup had explicit template arguments.
Definition ExprCXX.h:3648
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3622
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3665
DeclarationName getDeclName() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3603
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3658
const DeclarationNameInfo & getNameInfo() const
Retrieve the name that this expression refers to.
Definition ExprCXX.h:3600
Represents an array type in C++ whose size is a value-dependent expression.
Definition TypeBase.h:4109
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2127
Represents an extended vector type where either the type or size is dependent.
Definition TypeBase.h:4199
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition TypeBase.h:4714
A template-id naming a variable template or a concept through a template template parameter.
Definition ExprCXX.h:3480
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2099
Represents a vector type where either the type or size is dependent.
Definition TypeBase.h:4457
Represents a single C99 designator.
Definition Expr.h:5680
Represents a C99 designated initializer expression.
Definition Expr.h:5637
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:913
DoStmt - This represents a 'do/while' stmt.
Definition Stmt.h:2843
Wrap a function effect's condition expression in another struct so that FunctionProtoType's TrailingO...
Definition TypeBase.h:5268
Expr * getCondition() const
Definition TypeBase.h:5275
void set(SourceLocation ElaboratedKeywordLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation NameLoc)
Definition TypeLoc.h:744
Represents a reference to emded data.
Definition Expr.h:5204
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:4019
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition ExprCXX.h:3715
This represents one expression.
Definition Expr.h:114
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition Expr.h:179
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition Expr.h:196
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition Expr.h:456
Expr * IgnoreImplicitAsWritten() LLVM_READONLY
Skip past any implicit AST nodes which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3121
bool isDefaultArgument() const
Determine whether this expression is a default function argument.
Definition Expr.cpp:3253
QualType getType() const
Definition Expr.h:146
bool hasPlaceholderType() const
Returns whether this expression has a placeholder type.
Definition Expr.h:528
static ExprValueKind getValueKindForType(QualType T)
getValueKindForType - Given a formal return or parameter type, give its value kind.
Definition Expr.h:439
An expression trait intrinsic.
Definition ExprCXX.h:3084
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
Definition Expr.h:6696
Represents difference between two FPOptions values.
FPOptions applyOverrides(FPOptions Base)
Represents a member of a struct/union/class.
Definition Decl.h:3341
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition Stmt.h:2899
Represents a function declaration or definition.
Definition Decl.h:2082
ArrayRef< ParmVarDecl * > parameters() const
Definition Decl.h:2947
SmallVector< Conflict > Conflicts
Definition TypeBase.h:5516
Represents an abstract function effect, using just an enumeration describing its kind.
Definition TypeBase.h:5161
StringRef name() const
The description printed in diagnostics, e.g. 'nonblocking'.
Definition Type.cpp:5943
Kind oppositeKind() const
Return the opposite kind, for effects which have opposites.
Definition Type.cpp:5929
ArrayRef< EffectConditionExpr > conditions() const
Definition TypeBase.h:5382
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition TypeBase.h:5126
Represents a reference to a function parameter pack, init-capture pack, or binding pack that has been...
Definition ExprCXX.h:4895
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5548
param_type_iterator param_type_begin() const
Definition TypeBase.h:5992
unsigned getNumParams() const
Definition TypeLoc.h:1747
SourceLocation getLocalRangeEnd() const
Definition TypeLoc.h:1699
void setLocalRangeBegin(SourceLocation L)
Definition TypeLoc.h:1695
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1711
SourceRange getExceptionSpecRange() const
Definition TypeLoc.h:1727
void setParam(unsigned i, ParmVarDecl *VD)
Definition TypeLoc.h:1754
ArrayRef< ParmVarDecl * > getParams() const
Definition TypeLoc.h:1738
void setRParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1719
void setLocalRangeEnd(SourceLocation L)
Definition TypeLoc.h:1703
void setExceptionSpecRange(SourceRange R)
Definition TypeLoc.h:1733
TypeLoc getReturnLoc() const
Definition TypeLoc.h:1756
SourceLocation getLocalRangeBegin() const
Definition TypeLoc.h:1691
SourceLocation getLParenLoc() const
Definition TypeLoc.h:1707
SourceLocation getRParenLoc() const
Definition TypeLoc.h:1715
Interesting information about a specific parameter that can't simply be reflected in parameter's type...
Definition TypeBase.h:4770
This represents a GCC inline-assembly statement extension.
Definition Stmt.h:3459
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition Expr.h:4992
Represents a C11 generic selection.
Definition Expr.h:6268
AssociationTy< false > Association
Definition Expr.h:6501
GotoStmt - This represents a direct goto.
Definition Stmt.h:2980
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:7483
One of these records is kept for each identifier that is lexed.
IfStmt - This represents an if/then/else.
Definition Stmt.h:2270
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition Expr.h:1776
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition Expr.h:3922
Represents an implicitly-generated value initialization of an object of a given type.
Definition Expr.h:6143
Represents a C array with an unspecified size.
Definition TypeBase.h:4007
IndirectGotoStmt - This represents an indirect goto.
Definition Stmt.h:3019
const TypeClass * getTypePtr() const
Definition TypeLoc.h:526
Describes an C or C++ initializer list.
Definition Expr.h:5377
InitListExpr * getSyntacticForm() const
Definition Expr.h:5558
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:985
Represents the declaration of a label.
Definition Decl.h:526
LabelStmt - Represents a label, which has a substatement.
Definition Stmt.h:2157
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition ExprCXX.h:1973
capture_iterator capture_begin() const
Retrieve an iterator pointing to the first lambda capture.
Definition ExprCXX.cpp:1395
bool isInitCapture(const LambdaCapture *Capture) const
Determine whether one of this lambda's captures is an init-capture.
Definition ExprCXX.cpp:1390
capture_iterator capture_end() const
Retrieve an iterator pointing past the end of the sequence of lambda captures.
Definition ExprCXX.cpp:1399
const LambdaCapture * capture_iterator
An iterator that walks over the captures of the lambda, both implicit and explicit.
Definition ExprCXX.h:2038
void setAttrNameLoc(SourceLocation Loc)
Definition TypeLoc.h:1373
Represents a placeholder type for late-parsed type attributes.
Definition TypeBase.h:3577
Represents the results of name lookup.
Definition Lookup.h:147
This represents a Microsoft inline-assembly statement extension.
Definition Stmt.h:3678
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:4414
A member reference to an MSPropertyDecl.
Definition ExprCXX.h:941
MS property subscript expression.
Definition ExprCXX.h:1011
void setExpansionLoc(SourceLocation Loc)
Definition TypeLoc.h:1414
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition ExprCXX.h:4974
MatrixSingleSubscriptExpr - Matrix single subscript expression for the MatrixType extension when you ...
Definition Expr.h:2864
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
Definition Expr.h:2934
void setAttrNameLoc(SourceLocation loc)
Definition TypeLoc.h:2156
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition Expr.h:3433
Wrapper for source info for member pointers.
Definition TypeLoc.h:1575
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3751
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:276
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:297
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition Decl.h:303
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition Decl.h:342
Represents C++ namespaces and their aliases.
Definition Decl.h:575
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:5963
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition Stmt.h:1714
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 the 'depth' clause on the 'pragma omp flatten' (and 'pragma omp fuse') loop-transform...
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:219
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:1735
ObjCBoolLiteralExpr - Objective-C Boolean Literal.
Definition ExprObjC.h:118
ObjCBoxedExpr - used for generalized expression boxing.
Definition ExprObjC.h:158
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition ExprObjC.h:1675
ObjCDictionaryLiteral - AST node to represent objective-c dictionary literals; as in:"name" : NSUserN...
Definition ExprObjC.h:341
ObjCEncodeExpr, used for @encode in Objective-C.
Definition ExprObjC.h:440
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:1614
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:1530
ObjCIvarDecl - Represents an ObjC instance variable.
Definition DeclObjC.h:1958
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition ExprObjC.h:581
An expression that sends a message to the given Objective-C object or class.
Definition ExprObjC.h:972
@ SuperInstance
The receiver is the instance of the superclass object.
Definition ExprObjC.h:986
@ Instance
The receiver is an object instance.
Definition ExprObjC.h:980
@ SuperClass
The receiver is a superclass.
Definition ExprObjC.h:983
@ Class
The receiver is a class.
Definition ExprObjC.h:977
ObjCMethodDecl - Represents an instance or class method declaration.
Definition DeclObjC.h:140
Wraps an ObjCPointerType with source location information.
Definition TypeLoc.h:1617
void setStarLoc(SourceLocation Loc)
Definition TypeLoc.h:1623
void setHasBaseTypeAsWritten(bool HasBaseType)
Definition TypeLoc.h:1258
Represents one property declaration in an Objective-C interface.
Definition DeclObjC.h:734
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
Definition ExprObjC.h:649
ObjCProtocolExpr used for protocol expression in Objective-C.
Definition ExprObjC.h:537
ObjCSelectorExpr used for @selector in Objective-C.
Definition ExprObjC.h:485
ObjCStringLiteral, used for Objective-C string literals i.e.
Definition ExprObjC.h:83
ObjCSubscriptRefExpr - used for array and dictionary subscripting.
Definition ExprObjC.h:871
Represents the declaration of an Objective-C type parameter.
Definition DeclObjC.h:581
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:2495
@ Identifier
A field in a dependent type, known only by its name.
Definition Expr.h:2499
@ Field
A field.
Definition Expr.h:2497
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition Expr.h:2502
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:1223
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
Definition Expr.h:1273
This expression type represents an asterisk in an OpenACC Size-Expr, used in the 'tile' and 'gang' cl...
Definition Expr.h:2159
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:3143
bool hasExplicitTemplateArgs() const
Determines whether this expression had explicit template arguments.
Definition ExprCXX.h:3295
SourceLocation getLAngleLoc() const
Retrieve the location of the left angle bracket starting the explicit template argument list followin...
Definition ExprCXX.h:3277
SourceLocation getNameLoc() const
Gets the location of the name.
Definition ExprCXX.h:3256
SourceLocation getTemplateKeywordLoc() const
Retrieve the location of the template keyword preceding this name, if any.
Definition ExprCXX.h:3269
NestedNameSpecifierLoc getQualifierLoc() const
Fetches the nested-name qualifier with source-location information, if one was given.
Definition ExprCXX.h:3265
TemplateArgumentLoc const * getTemplateArgs() const
Definition ExprCXX.h:3307
llvm::iterator_range< decls_iterator > decls() const
Definition ExprCXX.h:3242
unsigned getNumTemplateArgs() const
Definition ExprCXX.h:3313
DeclarationName getName() const
Gets the name looked up.
Definition ExprCXX.h:3253
SourceLocation getRAngleLoc() const
Retrieve the location of the right angle bracket ending the explicit template argument list following...
Definition ExprCXX.h:3285
bool hasTemplateKeyword() const
Determines whether the name was preceded by the template keyword.
Definition ExprCXX.h:3292
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition ExprCXX.h:4417
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2664
SourceLocation getEllipsisLoc() const
Definition TypeLoc.h:2660
TypeLoc getPatternLoc() const
Definition TypeLoc.h:2676
A structure for storing a pack-index-template-name ([temp.names]).
void setEllipsisLoc(SourceLocation Loc)
Definition TypeLoc.h:2347
ParenExpr - This represents a parenthesized expression, e.g.
Definition Expr.h:2251
SourceLocation getLParen() const
Get the location of the left parentheses '('.
Definition Expr.h:2276
SourceLocation getRParen() const
Get the location of the right parentheses ')'.
Definition Expr.h:2280
void setLParenLoc(SourceLocation Loc)
Definition TypeLoc.h:1442
Represents a parameter to a function.
Definition Decl.h:1832
unsigned getFunctionScopeIndex() const
Returns the index of this parameter in its prototype or method scope.
Definition Decl.h:1892
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition Decl.h:1865
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:2963
unsigned getFunctionScopeDepth() const
Definition Decl.h:1882
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2756
PipeType - OpenCL20.
Definition TypeBase.h:8407
bool isReadOnly() const
Definition TypeBase.h:8432
Pointer-authentication qualifiers.
Definition TypeBase.h:153
void setSigilLoc(SourceLocation Loc)
Definition TypeLoc.h:1521
TypeLoc getPointeeLoc() const
Definition TypeLoc.h:1525
SourceLocation getSigilLoc() const
Definition TypeLoc.h:1517
Wrapper for source info for pointers.
Definition TypeLoc.h:1544
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3403
[C99 6.4.2.2] - A predefined identifier such as func.
Definition Expr.h:2074
Stores the type being destroyed by a pseudo-destructor expression.
Definition ExprCXX.h:2699
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition Expr.h:6890
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition TypeBase.h:8610
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:332
void removeObjCLifetime()
Definition TypeBase.h:552
bool hasRestrict() const
Definition TypeBase.h:478
static Qualifiers fromCVRMask(unsigned CVR)
Definition TypeBase.h:436
PointerAuthQualifier getPointerAuth() const
Definition TypeBase.h:604
bool hasObjCLifetime() const
Definition TypeBase.h:545
bool empty() const
Definition TypeBase.h:648
LangAS getAddressSpace() const
Definition TypeBase.h:572
Frontend produces RecoveryExprs on semantic errors that prevent creating other well-formed expression...
Definition Expr.h:7589
Base for LValueReferenceType and RValueReferenceType.
Definition TypeBase.h:3678
QualType getPointeeTypeAsWritten() const
Definition TypeBase.h:3694
Represents the body of a requires-expression.
Definition DeclCXX.h:2122
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:3173
static SEHFinallyStmt * Create(const ASTContext &C, SourceLocation FinallyLoc, Stmt *Block)
Definition Stmt.cpp:1361
Represents a __leave statement.
Definition Stmt.h:3911
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 * 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 * ActOnOpenMPNumThreadsClause(ArrayRef< Expr * > VarList, OpenMPNumThreadsClauseModifier SimpleModifier, SourceLocation SimpleModifierLoc, OpenMPNumThreadsClauseModifier ComplexModifier, Expr *ComplexModifierExpr, SourceLocation ComplexModifierLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_threads' clause.
OMPClause * ActOnOpenMPInReductionClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, const DeclarationNameInfo &ReductionId, ArrayRef< Expr * > UnresolvedReductions={})
Called on well-formed 'in_reduction' clause.
OMPClause * ActOnOpenMPFlushClause(ArrayRef< Expr * > VarList, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'flush' pseudo clause.
StmtResult ActOnOpenMPExecutableDirective(OpenMPDirectiveKind Kind, const DeclarationNameInfo &DirName, OpenMPDirectiveKind CancelRegion, ArrayRef< OMPClause * > Clauses, Stmt *AStmt, SourceLocation StartLoc, SourceLocation EndLoc)
OMPClause * ActOnOpenMPMessageClause(Expr *MS, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'message' clause.
OMPClause * ActOnOpenMPThreadLimitClause(ArrayRef< Expr * > VarList, OpenMPThreadLimitClauseModifier Modifier, Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'thread_limit' 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.
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.
OMPClause * ActOnOpenMPNumTeamsClause(ArrayRef< Expr * > VarList, OpenMPNumTeamsClauseModifier Modifier, Expr *ModifierExpr, SourceLocation ModifierLoc, OpenMPNumTeamsClauseModifier ModifierExtra, Expr *ModifierExtraExpr, SourceLocation ModifierExtraLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'num_teams' clause.
ExprResult ActOnOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, SourceLocation RParenLoc, ArrayRef< Expr * > Dims, ArrayRef< SourceRange > Brackets)
OMPClause * ActOnOpenMPAtClause(OpenMPAtClauseKind Kind, SourceLocation KindLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'at' clause.
OMPClause * ActOnOpenMPInitClause(Expr *InteropVar, OMPInteropInfo &InteropInfo, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation VarLoc, SourceLocation EndLoc)
Called on well-formed 'init' clause.
OMPClause * ActOnOpenMPUseDeviceAddrClause(ArrayRef< Expr * > VarList, const OMPVarListLocTy &Locs)
Called on well-formed 'use_device_addr' clause.
StmtResult ActOnOpenMPMetaDirective(SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef< OMPTraitInfo * > TraitInfos, ArrayRef< Stmt * > Variants)
Called for metadirectives with user conditions that require runtime selection.
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.
OMPClause * ActOnOpenMPDepthClause(Expr *DepthExpr, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Called on well-formed 'depth' 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:786
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:13936
RAII object used to temporarily allow the C++ 'this' expression to be used, with the given qualifiers...
Definition Sema.h:8644
A RAII object to enter scope of a compound statement.
Definition Sema.h:1340
std::optional< bool > getKnownValue() const
Definition Sema.h:8019
A RAII object to temporarily push a declaration context.
Definition Sema.h:3651
A helper class for building up ExtParameterInfos.
Definition Sema.h:13305
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:13324
void set(unsigned index, FunctionProtoType::ExtParameterInfo info)
Set the ExtParameterInfo for the parameter at the given index,.
Definition Sema.h:13312
Records and restores the CurFPFeatures state on entry/exit of compound statements.
Definition Sema.h:14353
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:862
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:9541
@ LookupMemberName
Member name lookup, which finds the names of class/struct/union members.
Definition Sema.h:9549
@ LookupTagName
Tag name lookup, which finds the names of enums, classes, structs, and unions.
Definition Sema.h:9544
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:1570
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:8035
@ Switch
An integral condition for a 'switch' statement.
Definition Sema.h:8037
@ ConstexprIf
A constant boolean condition from 'if constexpr'.
Definition Sema.h:8036
const ExpressionEvaluationContextRecord & currentEvaluationContext() const
Definition Sema.h:7116
ExprResult BuildBuiltinBitCastExpr(SourceLocation KWLoc, TypeSourceInfo *TSI, Expr *Operand, SourceLocation RParenLoc)
Definition SemaCast.cpp:440
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:526
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)
TemplateName BuildPackIndexingTemplateName(TemplateName Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< TemplateName > Expansions={})
ExprResult BuildResolvedCoawaitExpr(SourceLocation KwLoc, Expr *Operand, Expr *Awaiter, bool IsImplicit=false)
SemaSYCL & SYCL()
Definition Sema.h:1595
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:12234
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:1331
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:931
SemaObjC & ObjC()
Definition Sema.h:1555
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:934
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:927
StmtResult ActOnWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, ConditionResult Cond, SourceLocation RParenLoc, Stmt *Body)
SemaOpenACC & OpenACC()
Definition Sema.h:1560
@ ReuseLambdaContextDecl
Definition Sema.h:7207
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:1520
ExprResult BuildCXXReflectExpr(SourceLocation OperatorLoc, TypeSourceInfo *TSI)
ExprResult BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc)
TemplateArgument getPackSubstitutedTemplateArgument(TemplateArgument Arg) const
Definition Sema.h:12036
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:1366
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:12031
ExprResult BuildDeclarationNameExpr(const CXXScopeSpec &SS, LookupResult &R, bool NeedsADL, bool AcceptInvalidDecl=false)
sema::BlockScopeInfo * getCurBlock()
Retrieve the current block, if any.
Definition Sema.cpp:2694
void ApplyForRangeOrExpansionStatementLifetimeExtension(VarDecl *RangeVar, ArrayRef< MaterializeTemporaryExpr * > Temporaries)
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition Sema.h:1483
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 CheckVarOrConceptTemplateTemplateId(const DeclarationNameInfo &NameInfo, TemplateName Template, const TemplateArgumentListInfo *TemplateArgs)
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:6917
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Definition Sema.h:6927
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
Definition Sema.h:6896
@ ImmediateFunctionContext
In addition of being constant evaluated, the current expression occurs in an immediate function conte...
Definition Sema.h:6922
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:8513
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 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:11285
void ActOnCaseStmtBody(Stmt *CaseStmt, Stmt *SubStmt)
ActOnCaseStmtBody - This installs a statement as the body of a case.
Definition SemaStmt.cpp:626
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:339
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)
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:1323
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
static ConditionResult ConditionError()
Definition Sema.h:8021
StmtResult ActOnCompoundStmt(SourceLocation L, SourceLocation R, ArrayRef< Stmt * > Elts, bool isStmtExpr)
Definition SemaStmt.cpp:457
SemaPseudoObject & PseudoObject()
Definition Sema.h:1580
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:1322
StmtResult ActOnDefaultStmt(SourceLocation DefaultLoc, SourceLocation ColonLoc, Stmt *SubStmt, Scope *CurScope)
Definition SemaStmt.cpp:631
ExprResult HandleExprEvaluationContextForTypeof(Expr *E)
StmtResult ActOnCaseStmt(SourceLocation CaseLoc, ExprResult LHS, SourceLocation DotDotDotLoc, ExprResult RHS, SourceLocation ColonLoc)
Definition SemaStmt.cpp:592
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:8857
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:4712
Represents an expression that computes the length of a parameter pack.
Definition ExprCXX.h:4495
SourceLocation getPackLoc() const
Determine the location of the parameter pack.
Definition ExprCXX.h:4557
bool isPartiallySubstituted() const
Determine whether this represents a partially-substituted sizeof... expression, such as is produced f...
Definition ExprCXX.h:4580
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, UnsignedOrNone Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition ExprCXX.cpp:1739
ArrayRef< TemplateArgument > getPartialArguments() const
Get.
Definition ExprCXX.h:4585
SourceLocation getOperatorLoc() const
Determine the location of the 'sizeof' keyword.
Definition ExprCXX.h:4554
SourceLocation getRParenLoc() const
Determine the location of the right parenthesis.
Definition ExprCXX.h:4560
NamedDecl * getPack() const
Retrieve the parameter pack.
Definition ExprCXX.h:4563
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition Expr.h:5095
static bool MayBeDependent(SourceLocIdentKind Kind)
Definition Expr.h:5155
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:4664
Stmt - This represents one statement.
Definition Stmt.h:85
SourceLocation getEndLoc() const LLVM_READONLY
Definition Stmt.cpp:367
@ NoStmtClass
Definition Stmt.h:88
StmtClass getStmtClass() const
Definition Stmt.h:1504
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:1844
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:4718
Represents a reference to a non-type template parameter pack that has been substituted with a non-tem...
Definition ExprCXX.h:4808
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:2520
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3900
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.
PackIndexingTemplateStorage * getAsPackIndexingTemplate() const
Retrieve the pack-index-template-name storage, if any.
Stores a list of template parameters for a TemplateDecl and its derived classes.
SourceLocation getLAngleLoc() const
Definition TypeLoc.h:1938
SourceLocation getRAngleLoc() const
Definition TypeLoc.h:1953
SourceLocation getTemplateNameLoc() const
Definition TypeLoc.h:1936
SourceLocation getTemplateKeywordLoc() const
Definition TypeLoc.h:1932
NestedNameSpecifierLoc getQualifierLoc() const
Definition TypeLoc.h:1922
SourceLocation getElaboratedKeywordLoc() const
Definition TypeLoc.h:1918
Wrapper for template type parameters.
Definition TypeLoc.h:881
The top declaration context.
Definition Decl.h:107
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.
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.
ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, FieldDecl *Field, Expr *RewrittenInit)
Build a new C++11 default-initialization expression.
OMPClause * RebuildOMPNumTeamsClause(ArrayRef< Expr * > VarList, OpenMPNumTeamsClauseModifier Modifier, Expr *ModifierExpr, SourceLocation ModifierLoc, OpenMPNumTeamsClauseModifier ModifierExtra, Expr *ModifierExtraExpr, SourceLocation ModifierExtraLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_teams' clause.
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)
TemplateName RebuildPackIndexingTemplateName(TemplateName Pattern, Expr *IndexExpr, bool FullySubstituted, ArrayRef< TemplateName > Expansions={})
Build a new pack-index-template-name ([temp.names]).
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)
QualType RebuildPackIndexingType(QualType Pattern, Expr *IndexExpr, SourceLocation Loc, bool FullySubstituted, ArrayRef< QualType > Expansions={})
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.
TemplateName TransformConceptTemplateName(TemplateName Name, SourceLocation NameLoc)
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...
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.
QualType RebuildAutoType(DeducedKind DK, QualType DeducedAsType, AutoTypeKeyword Keyword, TemplateName TypeConstraintConcept, ArrayRef< TemplateArgument > TypeConstraintArgs)
Build a new C++11 auto type.
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.
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)
OMPClause * RebuildOMPDepthClause(Expr *Depth, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'depth' clause.
StmtResult RebuildOpenACCLoopConstruct(SourceLocation BeginLoc, SourceLocation DirLoc, SourceLocation EndLoc, ArrayRef< OpenACCClause * > Clauses, StmtResult Loop)
ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr)
Build a new C++ default-argument expression.
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.
OMPClause * RebuildOMPThreadLimitClause(ArrayRef< Expr * > VarList, OpenMPThreadLimitClauseModifier Modifier, Expr *ModifierExpr, SourceLocation ModifierLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'thread_limit' clause.
ExprResult RebuildParenListExpr(SourceLocation LParenLoc, MultiExprArg SubExprs, SourceLocation RParenLoc)
Build a new expression list in parentheses.
OMPClause * RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'allocator' clause.
OMPClause * RebuildOMPNumThreadsClause(ArrayRef< Expr * > VarList, OpenMPNumThreadsClauseModifier PrescriptivenessModifier, SourceLocation PrescriptivenessModifierLoc, OpenMPNumThreadsClauseModifier DimsModifier, Expr *DimsModifierExpr, SourceLocation DimsModifierLoc, SourceLocation StartLoc, SourceLocation LParenLoc, SourceLocation EndLoc)
Build a new OpenMP 'num_threads' 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)
StmtResult RebuildOMPMetaDirective(SourceLocation StartLoc, SourceLocation EndLoc, ArrayRef< OMPTraitInfo * > TraitInfos, ArrayRef< Stmt * > Variants)
Build a new OpenMP metadirective.
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.
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.
QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, unsigned NumColumns, SourceLocation AttributeLoc)
Build a new matrix type given the element type and dimensions.
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.
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.
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:2766
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:6458
A container of type source information.
Definition TypeBase.h:8549
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:8560
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:2901
The base class of the type hierarchy.
Definition TypeBase.h:1879
bool containsUnexpandedParameterPack() const
Whether this type is or contains an unexpanded parameter pack, used to support C++0x variadic templat...
Definition TypeBase.h:2469
bool isOverloadableType() const
Determines whether this is a type for which one can define an overloaded operator.
Definition TypeBase.h:9354
bool isObjCObjectPointerType() const
Definition TypeBase.h:8994
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9431
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3745
Wrapper for source info for typedefs.
Definition TypeLoc.h:777
void setTypeofLoc(SourceLocation Loc)
Definition TypeLoc.h:2231
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition Expr.h:2694
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2313
SourceLocation getOperatorLoc() const
getOperatorLoc - Return the location of the operator.
Definition Expr.h:2358
Expr * getSubExpr() const
Definition Expr.h:2354
Opcode getOpcode() const
Definition Expr.h:2349
static Opcode getOverloadedOpcode(OverloadedOperatorKind OO, bool Postfix)
Retrieve the unary opcode that corresponds to the given overloaded operator.
Definition Expr.cpp:1447
void setKWLoc(SourceLocation Loc)
Definition TypeLoc.h:2375
Represents a C++ unqualified-id that has been parsed.
Definition DeclSpec.h:1110
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:3373
CXXRecordDecl * getNamingClass()
Gets the 'naming class' (in the sense of C++0x [class.access.base]p5) of the lookup.
Definition ExprCXX.h:3447
bool requiresADL() const
True if this declaration should be extended by argument-dependent lookup.
Definition ExprCXX.h:3442
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:464
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition ExprCXX.h:4180
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:6263
A call to a literal operator (C++11 [over.literal]) written as a user-defined literal (C++11 [lit....
Definition ExprCXX.h:645
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition DeclCXX.h:3446
NamedDecl * getTargetDecl() const
Gets the underlying declaration which has been brought into the local scope.
Definition DeclCXX.h:3510
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:5026
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:714
QualType getType() const
Definition Decl.h:725
bool isParameterPack() const
Determine whether this value is actually a function parameter pack, init-capture pack,...
Definition Decl.cpp:5729
Value()=default
Represents a variable declaration or definition.
Definition Decl.h:934
@ CInit
C-style initialization with assignment.
Definition Decl.h:939
@ CallInit
Call-style initialization (C++98)
Definition Decl.h:942
StorageClass getStorageClass() const
Returns the storage class as written in the source.
Definition Decl.h:1176
Represents a C array with a specified size that is not an integer-constant-expression.
Definition TypeBase.h:4064
void setNameLoc(SourceLocation Loc)
Definition TypeLoc.h:2076
Represents a GCC generic vector type.
Definition TypeBase.h:4398
WhileStmt - This represents a 'while' stmt.
Definition Stmt.h:2708
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
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:960
Top level wrappers for InstallAPI frontend operations.
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
@ CPlusPlus23
OpenACCAtomicKind
OpenMPDefaultClauseVariableCategory
OpenMP variable-category for 'default' clause.
AutoTypeKeyword
Which keyword(s) were used to create an AutoType.
Definition TypeBase.h:1838
QualType pointeeType(QualType T)
OpenMPDefaultmapClauseModifier
OpenMP modifiers for 'defaultmap' clause.
OpenMPOrderClauseModifier
OpenMP modifiers for 'order' clause.
TryCaptureKind
Definition Sema.h:646
@ 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:1545
@ 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:165
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:597
OpenMPReductionClauseModifier
OpenMP modifiers for 'reduction' clause.
std::pair< llvm::PointerUnion< const TemplateTypeParmType *, NamedDecl *, const TemplateSpecializationType *, const SubstBuiltinTemplatePackType * >, SourceLocation > UnexpandedParameterPack
Definition Sema.h:242
@ 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:919
OpenMPScheduleClauseModifier
OpenMP modifiers for 'schedule' clause.
Definition OpenMPKinds.h:39
OpenMPNumTeamsClauseModifier
@ OMPC_NUMTEAMS_unknown
OpenACCComputeConstruct(OpenACCDirectiveKind K, SourceLocation Start, SourceLocation DirectiveLoc, SourceLocation End, ArrayRef< const OpenACCClause * > Clauses, Stmt *StructuredBlock)
OpenMPDistScheduleClauseKind
OpenMP attributes for 'dist_schedule' clause.
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
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:912
@ Result
The result type of a method or function.
Definition TypeBase.h:906
OpenMPBindClauseKind
OpenMP bindings for the 'bind' clause.
ArraySizeModifier
Capture whether this is a normal array (e.g.
Definition TypeBase.h:3817
OptionalUnsigned< unsigned > UnsignedOrNone
const FunctionProtoType * T
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:6171
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:555
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:1811
@ Deduced
The normal deduced case.
Definition TypeBase.h:1818
@ Undeduced
Not deduced yet. This is for example an 'auto' which was just parsed.
Definition TypeBase.h:1813
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:139
@ VK_LValue
An l-value expression is a reference to an object with independent storage.
Definition Specifiers.h:143
OpenMPThreadLimitClauseModifier
@ Dependent
The name is a dependent name, so the results will differ from one instantiation to the next.
Definition Sema.h:805
@ Exists
The symbol exists.
Definition Sema.h:798
@ Error
An error occurred.
Definition Sema.h:808
@ DoesNotExist
The symbol does not exist.
Definition Sema.h:801
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:844
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:5082
ElaboratedTypeKeyword
The elaboration keyword that precedes a qualified type name or introduces an elaborated-type-specifie...
Definition TypeBase.h:6146
@ None
No keyword precedes the qualified type name.
Definition TypeBase.h:6167
@ Class
The "class" keyword introduces the elaborated-type-specifier.
Definition TypeBase.h:6157
@ Typename
The "typename" keyword precedes the qualified type name, e.g., typename T::type.
Definition TypeBase.h:6164
ActionResult< Expr * > ExprResult
Definition Ownership.h:249
OpenMPOrderClauseKind
OpenMP attributes for 'order' clause.
@ Parens
New-expression has a C++98 paren-delimited initializer.
Definition ExprCXX.h:2250
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:2058
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.
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:5285
Holds information about the various types of exception specification.
Definition TypeBase.h:5605
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition TypeBase.h:5621
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition TypeBase.h:5607
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition TypeBase.h:5610
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition TypeBase.h:5613
Extra information about a function prototype.
Definition TypeBase.h:5633
const ExtParameterInfo * ExtParameterInfos
Definition TypeBase.h:5638
static TagTypeKind getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword)
Converts an elaborated type keyword into a TagTypeKind.
Definition Type.cpp:3535
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:294
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:13385
@ LambdaExpressionSubstitution
We are substituting into a lambda expression.
Definition Sema.h:13416
bool InLifetimeExtendingContext
Whether we are currently in a context in which all temporaries must be lifetime-extended,...
Definition Sema.h:7038
SmallVector< MaterializeTemporaryExpr *, 8 > ForRangeLifetimeExtendTemps
P2718R0 - Lifetime extension in range-based for loops.
Definition Sema.h:7006
bool RebuildDefaultArgOrDefaultInit
Whether we should rebuild CXXDefaultArgExpr and CXXDefaultInitExpr.
Definition Sema.h:7044
ExpressionEvaluationContext Context
The expression evaluation context.
Definition Sema.h:6954
An RAII helper that pops function a function scope on exit.
Definition Sema.h:1355
Keeps information about an identifier in a nested-name-spec.
Definition Sema.h:3452
Location information for a TemplateArgument.
UnsignedOrNone OrigNumExpansions
SourceLocation Ellipsis
UnsignedOrNone NumExpansions